]> git.lyx.org Git - features.git/commitdiff
John's cleanup KDE-TOC patch
authorJürgen Vigna <jug@sad.it>
Wed, 13 Sep 2000 09:49:50 +0000 (09:49 +0000)
committerJürgen Vigna <jug@sad.it>
Wed, 13 Sep 2000 09:49:50 +0000 (09:49 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1013 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/frontends/kde/FormToc.C
src/frontends/kde/FormToc.h
src/frontends/kde/formtocdialog.C
src/frontends/kde/formtocdialog.h

index c9f1d6914244961d7efc7e28c24540f6a8114f23..22941a94cce84b7e2d9f3ceb6052dd71961e3f65 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2000-09-13  John Levon  <moz@compsoc.man.ac.uk>
+
+        * src/frontends/kde/formtocdialog.C
+        * src/frontends/kde/formtocdialog.h
+        * src/frontends/kde/FormToc.C
+        * src/frontends/kde/FormToc.h: change to make TOC hierarchical properly
+
 2000-09-11  John Levon  <moz@compsoc.man.ac.uk>
 
        * src/frontends/kde/FormCitation.C: fix thinko
index c6364863479ee0dcb31b826581b5f05444632d65..76ca0454195e045fa71d1f767cff6489cc0278cb 100644 (file)
@@ -15,6 +15,8 @@
 
 #include <config.h>
 
+#include <stack>
 #include "formtocdialog.h"
  
 #include "Dialogs.h"
@@ -28,6 +30,7 @@
 
 using std::vector;
 using std::pair;
+using std::stack;
  
 FormToc::FormToc(LyXView *v, Dialogs *d)
        : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0),
@@ -93,17 +96,58 @@ void FormToc::updateToc()
 
        dialog_->tree->clear();
 
-        
-       // FIXME: should do hierarchically. at each point we need to know
-       // id of item we've just inserted, id of most recent sibling, and
-       // id of parent
+       dialog_->tree->setUpdatesEnabled(false);
+
+       int depth = 0; 
+       stack< pair< QListViewItem *, QListViewItem *> > istack;
+       QListViewItem *last = 0;
+       QListViewItem *parent = 0;
+       QListViewItem *item;
+       // Yes, it is this ugly. Two reasons - root items must have a QListView parent,
+       // rather than QListViewItem; and the TOC can move in and out an arbitrary number
+       // of levels
  
-       dialog_->tree->setAutoUpdate(false);
        for (vector< Buffer::TocItem >::const_iterator iter = toclist.begin();
                iter != toclist.end(); ++iter) {
-               dialog_->tree->insertItem((string(4*(*iter).depth,' ')+(*iter).str).c_str(), 0, -1, false);
+               if (iter->depth == depth) {
+                       // insert it after the last one we processed
+                       if (!parent)
+                               item = (last) ? (new QListViewItem(dialog_->tree,last)) : (new QListViewItem(dialog_->tree));
+                       else
+                               item = (last) ? (new QListViewItem(parent,last)) : (new QListViewItem(parent));
+               } else if (iter->depth > depth) {
+                       int diff = iter->depth - depth;
+                       // first save old parent and last
+                       while (diff--)
+                               istack.push(pair< QListViewItem *, QListViewItem * >(parent,last));
+                       item = (last) ? (new QListViewItem(last)) : (new QListViewItem(dialog_->tree));
+                       parent = last;
+               } else {
+                       int diff = depth - iter->depth;
+                       pair< QListViewItem *, QListViewItem * > top;
+                       // restore context
+                       while (diff--) {
+                               top = istack.top();
+                               istack.pop();
+                       }
+                       parent = top.first;
+                       last = top.second;
+                       // insert it after the last one we processed
+                       if (!parent)
+                               item = (last) ? (new QListViewItem(dialog_->tree,last)) : (new QListViewItem(dialog_->tree));
+                       else
+                               item = (last) ? (new QListViewItem(parent,last)) : (new QListViewItem(parent));
+               }
+               lyxerr[Debug::GUI] << "Table of contents" << endl << "Added item " << iter->str.c_str() 
+                       << " at depth " << iter->depth << ", previous sibling \"" << (last ? last->text(0) : "0") 
+                       << "\", parent \"" << (parent ? parent->text(0) : "0") << "\"" << endl;
+               item->setText(0,iter->str.c_str());
+               depth = iter->depth;
+               last = item;
        }
-       dialog_->tree->setAutoUpdate(true);
+
+       dialog_->tree->setUpdatesEnabled(true);
        dialog_->tree->update();
 }
  
@@ -113,15 +157,19 @@ void FormToc::setType(Buffer::TocType toctype)
        switch (type) {
                case Buffer::TOC_TOC:
                        dialog_->setCaption(_("Table of Contents"));
+                       dialog_->tree->setColumnText(0,_("Table of Contents")); 
                        break; 
                case Buffer::TOC_LOF:
                        dialog_->setCaption(_("List of Figures"));
+                       dialog_->tree->setColumnText(0,_("List of Figures")); 
                        break; 
                case Buffer::TOC_LOT:
                        dialog_->setCaption(_("List of Tables"));
+                       dialog_->tree->setColumnText(0,_("List of Tables")); 
                        break; 
                case Buffer::TOC_LOA:
                        dialog_->setCaption(_("List of Algorithms"));
+                       dialog_->tree->setColumnText(0,_("List of Algorithms")); 
                        break; 
        }
 }
@@ -145,22 +193,19 @@ void FormToc::update()
        updateToc();
 }
  
-void FormToc::highlight(int index)
+void FormToc::select(const char *text)
 {
        if (!lv_->view()->available())
                return;
  
-       // FIXME: frontStrip can go once it's hierarchical
-       string tmp(frontStrip(dialog_->tree->itemAt(index)->getText(),' '));
        vector <Buffer::TocItem>::const_iterator iter = toclist.begin();
        for (; iter != toclist.end(); ++iter) {
-               if (iter->str==tmp)
+               if (iter->str==text)
                        break;
-       } 
+       }
        
        if (iter==toclist.end()) {
-               lyxerr[Debug::GUI] << "Couldn't find highlighted TOC entry : " << tmp << endl;
+               lyxerr[Debug::GUI] << "Couldn't find highlighted TOC entry : " << text << endl;
                return;
        }
 
index 04575180fef4d3a5a5ca9b151152cca5f8f23262..15cd6984c4a2359fade40f435b898226908867ae 100644 (file)
@@ -34,10 +34,10 @@ public:
        ~FormToc();
        //@}
 
-       /// Highlighted an item
-       void highlight(int index);
+       /// Selected a tree item
+       void select(const char *);
        /// Choose which type
-       void set_type(Buffer::TocType type);
+       void set_type(Buffer::TocType);
        /// Update the dialog.
        void update();
        /// close the connections
index 45b73f02c8c32801941ffe08eddf544e3942157a..8c9116245ad7e485f137d80305dcd5a9c77444b5 100644 (file)
@@ -30,8 +30,11 @@ FormTocDialog::FormTocDialog(FormToc *form, QWidget *parent, const char *name, b
        menu->insertItem(_("List of Algorithms"));
        menu->setMinimumSize(menu->sizeHint()); 
  
-       tree = new KTreeList(this,"tree");
+       tree = new QListView(this);
        tree->setMinimumHeight(200);
+       tree->setRootIsDecorated(true); 
+       tree->setSorting(-1); 
+       tree->addColumn("Table of Contents");
 
         buttonUpdate = new QPushButton(this);
         buttonUpdate->setMinimumSize(buttonUpdate->sizeHint());
@@ -66,7 +69,7 @@ FormTocDialog::FormTocDialog(FormToc *form, QWidget *parent, const char *name, b
 
        // connections
 
-       connect(tree, SIGNAL(highlighted(int)), this, SLOT(highlight_adaptor(int)));
+       connect(tree, SIGNAL(selectionChanged(QListViewItem *)), this, SLOT(select_adaptor(QListViewItem *)));
        connect(menu, SIGNAL(activated(int)), this, SLOT(activate_adaptor(int))); 
        connect(buttonUpdate, SIGNAL(clicked()), this, SLOT(update_adaptor())); 
        connect(buttonClose, SIGNAL(clicked()), this, SLOT(close_adaptor()));
index 3cd196df0f5e389ac2de8a3c645ad64575592f03..f00b479f4435e1478c12866a3ee71697e7286f5d 100644 (file)
@@ -24,8 +24,7 @@
 #include <qlayout.h>
 #include <qpushbutton.h>
 #include <qcombobox.h>
-
-#include <ktreelist.h>
+#include <qlistview.h>
  
 #include "FormToc.h"
 
@@ -39,7 +38,7 @@ public:
        // widgets
  
        QComboBox *menu;
-       KTreeList *tree;
+       QListView *tree;
        QPushButton *buttonUpdate;
        QPushButton *buttonClose;
 
@@ -56,9 +55,9 @@ private:
        QHBoxLayout *buttonLayout;
  
 private slots:
-       /// adaptor to FormToc::highlight
-       void highlight_adaptor(int index) {
-               form_->highlight(index);
+       /// adaptor to FormToc::select
+       void select_adaptor(QListViewItem *item) {
+               form_->select(item->text(0));
        }
 
        /// adaptor to FormToc::update