From: Jürgen Vigna Date: Wed, 13 Sep 2000 09:49:50 +0000 (+0000) Subject: John's cleanup KDE-TOC patch X-Git-Tag: 1.6.10~21999 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=832393b8f8a790059938f748541a6747500ba92d;p=features.git John's cleanup KDE-TOC patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1013 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index c9f1d69142..22941a94cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2000-09-13 John Levon + + * 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 * src/frontends/kde/FormCitation.C: fix thinko diff --git a/src/frontends/kde/FormToc.C b/src/frontends/kde/FormToc.C index c636486347..76ca045419 100644 --- a/src/frontends/kde/FormToc.C +++ b/src/frontends/kde/FormToc.C @@ -15,6 +15,8 @@ #include +#include + #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 ::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; } diff --git a/src/frontends/kde/FormToc.h b/src/frontends/kde/FormToc.h index 04575180fe..15cd6984c4 100644 --- a/src/frontends/kde/FormToc.h +++ b/src/frontends/kde/FormToc.h @@ -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 diff --git a/src/frontends/kde/formtocdialog.C b/src/frontends/kde/formtocdialog.C index 45b73f02c8..8c9116245a 100644 --- a/src/frontends/kde/formtocdialog.C +++ b/src/frontends/kde/formtocdialog.C @@ -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())); diff --git a/src/frontends/kde/formtocdialog.h b/src/frontends/kde/formtocdialog.h index 3cd196df0f..f00b479f44 100644 --- a/src/frontends/kde/formtocdialog.h +++ b/src/frontends/kde/formtocdialog.h @@ -24,8 +24,7 @@ #include #include #include - -#include +#include #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