Argh, I accidentally sent an old version which won't compile.
Sorry ! New one attached
I should get some sleep :/
thanks
john
On Wed, 13 Sep 2000, John Levon wrote:
2000-09-13 John Levon <[EMAIL PROTECTED]>
* 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
? a
? formtoc.diff
Index: FormToc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/kde/FormToc.C,v
retrieving revision 1.1
diff -u -r1.1 FormToc.C
--- FormToc.C 2000/09/12 15:13:18 1.1
+++ FormToc.C 2000/09/13 07:05:21
@@ -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),
@@ -92,18 +95,59 @@
toclist = tmp[type];
dialog_->tree->clear();
+
+ dialog_->tree->setUpdatesEnabled(false);
-
- // 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
+ 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 @@
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 @@
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: FormToc.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/kde/FormToc.h,v
retrieving revision 1.1
diff -u -r1.1 FormToc.h
--- FormToc.h 2000/09/12 15:13:18 1.1
+++ FormToc.h 2000/09/13 07:05:21
@@ -34,10 +34,10 @@
~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: formtocdialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/kde/formtocdialog.C,v
retrieving revision 1.1
diff -u -r1.1 formtocdialog.C
--- formtocdialog.C 2000/09/12 15:13:18 1.1
+++ formtocdialog.C 2000/09/13 07:05:21
@@ -30,8 +30,11 @@
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 @@
// 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: formtocdialog.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/kde/formtocdialog.h,v
retrieving revision 1.1
diff -u -r1.1 formtocdialog.h
--- formtocdialog.h 2000/09/12 15:13:18 1.1
+++ formtocdialog.h 2000/09/13 07:05:21
@@ -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 @@
// widgets
QComboBox *menu;
- KTreeList *tree;
+ QListView *tree;
QPushButton *buttonUpdate;
QPushButton *buttonClose;
@@ -56,9 +55,9 @@
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