From 41fa514da8bc9d31e59553239944a14d0f6f55e5 Mon Sep 17 00:00:00 2001 From: John Levon Date: Sun, 20 Jan 2002 18:38:52 +0000 Subject: [PATCH] TOC dialog is back git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3426 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 10 ++ src/frontends/qt2/Dialogs.C | 9 +- src/frontends/qt2/Makefile.am | 4 - src/frontends/qt2/QToc.C | 245 ++++++++--------------------- src/frontends/qt2/QToc.h | 87 +++++----- src/frontends/qt2/QTocDialog.C | 46 ++---- src/frontends/qt2/QTocDialog.h | 3 +- src/frontends/qt2/ui/QTocDialog.ui | 157 +++++++++--------- 8 files changed, 217 insertions(+), 344 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index b6dfacae06..21410f2242 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,13 @@ +2002-01-20 John Levon + + * Makefile.am: + * Dialogs.C: + * QToc.h: + * QToc.C: + * QTocDialog.h: + * QTocDialog.C: + * ui/QTocDialog.ui: resuscitate TOC dialog + 2002-01-20 John Levon * QCitation.h: diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 50baf9a918..ba778ff425 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -33,6 +33,7 @@ #include "QTabularCreateDialog.h" #include "QTexinfoDialog.h" #include "QThesaurusDialog.h" +#include "QTocDialog.h" #include "QURLDialog.h" #include "QVCLogDialog.h" @@ -57,6 +58,7 @@ #include "QSpellchecker.h" #include "QTabularCreate.h" #include "QTexinfo.h" +#include "QToc.h" #include "QThesaurus.h" #include "QURL.h" #include "QVCLog.h" @@ -71,8 +73,6 @@ #include "xforms/FormBrowser.h" #include "xforms/form_browser.h" #include "xforms/FormDocument.h" -#include "xforms/FormERT.h" -#include "xforms/form_ert.h" #include "xforms/FormFloat.h" #include "xforms/form_float.h" #include "xforms/FormMathsPanel.h" @@ -80,8 +80,6 @@ #include "xforms/FormPreferences.h" #include "xforms/FormShowFile.h" #include "xforms/FormTabular.h" -#include "xforms/FormToc.h" -#include "xforms/form_toc.h" #include "GUI.h" @@ -113,14 +111,13 @@ Dialogs::Dialogs(LyXView * lv) add(new GUITabularCreate(*lv, *this)); add(new GUITexinfo(*lv, *this)); add(new GUIThesaurus(*lv, *this)); + add(new GUIToc(*lv, *this)); add(new GUIUrl(*lv, *this)); add(new GUIVCLog(*lv, *this)); // dialogs not yet converted - add(new GUIERT(*lv, *this)); add(new GUIFloat(*lv, *this)); add(new GUIShowFile(*lv, *this)); - add(new GUIToc(*lv, *this)); // dialogs not yet MVCd add(new FormDocument(lv, this)); diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index a6f1ad4034..6921ab6bf7 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -26,7 +26,6 @@ libqt2_la_LIBADD = \ ../xforms/FormBase.lo \ ../xforms/FormBaseDeprecated.lo \ ../xforms/FormBrowser.lo \ - ../xforms/FormERT.lo \ ../xforms/FormFloat.lo \ ../xforms/FormMathsBitmap.lo \ ../xforms/FormMathsDeco.lo \ @@ -41,7 +40,6 @@ libqt2_la_LIBADD = \ ../xforms/FormTabular.lo \ ../xforms/FormDocument.lo \ ../xforms/FormInset.lo \ - ../xforms/FormToc.lo \ ../xforms/MathsSymbols.lo \ ../xforms/Menubar_pimpl.lo \ ../xforms/RadioButtonGroup.lo \ @@ -49,11 +47,9 @@ libqt2_la_LIBADD = \ ../xforms/bmtable.lo \ ../xforms/form_browser.lo \ ../xforms/form_document.lo \ - ../xforms/form_ert.lo \ ../xforms/form_float.lo \ ../xforms/form_preferences.lo \ ../xforms/form_tabular.lo \ - ../xforms/form_toc.lo \ ../xforms/form_maths_deco.lo \ ../xforms/form_maths_delim.lo \ ../xforms/form_maths_matrix.lo \ diff --git a/src/frontends/qt2/QToc.C b/src/frontends/qt2/QToc.C index 4a3ac167d3..84acd10baf 100644 --- a/src/frontends/qt2/QToc.C +++ b/src/frontends/qt2/QToc.C @@ -8,99 +8,87 @@ #include +#ifdef __GNUG__ +#pragma implementation +#endif + #include #include +#include +#include +#include + #include "QTocDialog.h" -#include "QtLyXView.h" - -#include "Dialogs.h" -#include "BufferView.h" #include "QToc.h" +#include "Qt2BC.h" #include "gettext.h" -#include "buffer.h" #include "support/lstrings.h" -#include "lyxfunc.h" #include "debug.h" -#include -#include - +#include "QtLyXView.h" + using std::vector; -using std::pair; -using std::stack; -using std::endl; -using SigC::slot; - - -QToc::QToc(LyXView *v, Dialogs *d) - : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0), - /*toclist(0),*/ depth(1) -{ - d->showTOC.connect(slot(this, &QToc::showTOC)); - d->createTOC.connect(slot(this, &QToc::createTOC)); -} - -QToc::~QToc() -{ - delete dialog_; -} - - -void QToc::showTOC(InsetCommand * const inset) +typedef Qt2CB > base_class; + +QToc::QToc(ControlToc & c) + : base_class(c, _("Table of contents")) +{} + + +void QToc::build_dialog() { - // FIXME: when could inset be 0 here ? - if (inset == 0) - return; + dialog_.reset(new QTocDialog(this)); - inset_ = inset; - //FIXME ih_ = inset_->hide.connect(slot(this,&QToc::hide)); - params = inset->params(); - - show(); + // Manage the cancel/close button + bc().setCancel(dialog_->closePB); } -void QToc::createTOC(string const & arg) +void QToc::updateType() +{ + dialog_->typeCO->clear(); + + vector const & choice = controller().getTypes(); + string const & type = toc::getType(controller().params().getCmdName()); + + for (vector::const_iterator it = choice.begin(); + it != choice.end(); ++it) { + dialog_->typeCO->insertItem(it->c_str()); + if (*it == type) { + dialog_->typeCO->setCurrentItem(it - choice.begin()); + dialog_->setCaption(type.c_str()); + } + } +} + + +void QToc::update_contents() { - if (inset_) - close(); - - params.setFromString(arg); - show(); + updateType(); + updateToc(depth_); } - + void QToc::updateToc(int newdepth) { - if (!lv_->view()->available()) { - //toclist.clear(); - dialog_->tocLV->clear(); - return; - } - -#if 0 - vector< vector > tmp = - lv_->view()->buffer()->getTocList(); - + string const type = dialog_->typeCO->currentText().latin1(); + + Buffer::SingleList const & contents = controller().getContents(type); + // Check if all elements are the same. - if (newdepth==depth && toclist.size() == tmp[type].size()) { - unsigned int i = 0; - for (; i < toclist.size(); ++i) { - if (toclist[i] != tmp[type][i]) - break; - } - if (i >= toclist.size()) - return; + if (newdepth == depth_ && toclist == contents) { + return; } - depth=newdepth; + dialog_->tocLV->clear(); + + depth_ = newdepth; - toclist = tmp[type]; + toclist = contents; - dialog_->tocLV->clear(); - if (toclist.empty()) + if (toclist.empty()) return; dialog_->tocLV->setUpdatesEnabled(false); @@ -115,7 +103,7 @@ void QToc::updateToc(int newdepth) // rather than QListViewItem; and the TOC can move in and out an arbitrary number // of levels - for (vector< Buffer::TocItem >::const_iterator iter = toclist.begin(); + for (Buffer::SingleList::const_iterator iter = toclist.begin(); iter != toclist.end(); ++iter) { if (iter->depth == curdepth) { // insert it after the last one we processed @@ -146,11 +134,12 @@ void QToc::updateToc(int newdepth) 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).latin1() : "0") << "\", parent \"" << (parent ? parent->text(0).latin1() : "0") << "\"" << endl; item->setText(0,iter->str.c_str()); - item->setOpen(iter->depth < depth); + item->setOpen(iter->depth < depth_); curdepth = iter->depth; last = item; } @@ -160,123 +149,27 @@ void QToc::updateToc(int newdepth) } -void QToc::setType(Buffer::TocType toctype) -{ - type = toctype; - switch (type) { - case Buffer::TOC_TOC: - dialog_->setCaption(_("Table of Contents")); - dialog_->tocLV->setColumnText(0,_("Table of Contents")); - dialog_->depthSL->setEnabled(true); - break; - case Buffer::TOC_LOF: - dialog_->setCaption(_("List of Figures")); - dialog_->tocLV->setColumnText(0,_("List of Figures")); - dialog_->depthSL->setEnabled(false); - break; - case Buffer::TOC_LOT: - dialog_->setCaption(_("List of Tables")); - dialog_->tocLV->setColumnText(0,_("List of Tables")); - dialog_->depthSL->setEnabled(false); - break; - case Buffer::TOC_LOA: - dialog_->setCaption(_("List of Algorithms")); - dialog_->tocLV->setColumnText(0,_("List of Algorithms")); - dialog_->depthSL->setEnabled(false); - break; - } -} - - -void QToc::set_depth(int newdepth) -{ - if (newdepth!=depth) - updateToc(newdepth); -#endif -} - - -void QToc::update() -{ -#if 0 - if (params.getCmdName()=="tableofcontents") { - setType(Buffer::TOC_TOC); - dialog_->typeCO->setCurrentItem(0); - } else if (params.getCmdName()=="listoffigures") { - setType(Buffer::TOC_LOF); - dialog_->typeCO->setCurrentItem(1); - } else if (params.getCmdName()=="listoftables") { - setType(Buffer::TOC_LOT); - dialog_->typeCO->setCurrentItem(2); - } else { - setType(Buffer::TOC_LOA); - dialog_->typeCO->setCurrentItem(3); - } - - updateToc(depth); -} - - -void QToc::select(const char *text) +void QToc::select(string const & text) { - if (!lv_->view()->available()) - return; - - vector ::const_iterator iter = toclist.begin(); + Buffer::SingleList::const_iterator iter = toclist.begin(); + for (; iter != toclist.end(); ++iter) { - if (iter->str==text) + if (iter->str == text) break; } - if (iter==toclist.end()) { - lyxerr[Debug::GUI] << "Couldn't find highlighted TOC entry : " << text << endl; + if (iter == toclist.end()) { + lyxerr[Debug::GUI] << "Couldn't find highlighted TOC entry : " + << text << endl; return; } - lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tostr(iter->par->id()).c_str()); -} - - -void QToc::set_type(Buffer::TocType toctype) -{ - if (toctype==type) - return; - - setType(toctype); - updateToc(depth); -#endif -} - - -void QToc::show() -{ - if (!dialog_) - dialog_ = new QTocDialog(this, 0, _("LyX: Table of Contents"), false); - - if (!dialog_->isVisible()) { - h_ = d_->hideBufferDependent.connect(slot(this, &QToc::hide)); - //u_ = d_->updateBufferDependent.connect(slot(this, &QToc::update)); - } - - dialog_->raise(); - dialog_->setActiveWindow(); - - update(); - dialog_->show(); -} - - -void QToc::close() -{ - h_.disconnect(); - u_.disconnect(); - ih_.disconnect(); - inset_ = 0; + controller().Goto(iter->par->id()); } -void QToc::hide() +void QToc::set_depth(int depth) { - dialog_->hide(); - close(); + if (depth != depth_) + updateToc(depth); } diff --git a/src/frontends/qt2/QToc.h b/src/frontends/qt2/QToc.h index 62edfb5a08..dda236452f 100644 --- a/src/frontends/qt2/QToc.h +++ b/src/frontends/qt2/QToc.h @@ -11,68 +11,51 @@ #ifndef QTOC_H #define QTOC_H -#include "DialogBase.h" -#include "LString.h" -#include "boost/utility.hpp" -#include "insets/insetcommand.h" -#include "buffer.h" +#ifdef __GNUG__ +#pragma interface +#endif -class Dialogs; +#include "Qt2Base.h" + +#include "ControlToc.h" + +class ControlToc; class QTocDialog; -class QToc : public DialogBase { +class QToc : + public Qt2CB > +{ public: - QToc(LyXView *, Dialogs *); - ~QToc(); - - // Build the dialog - virtual void build(); - /// Update the dialog before showing it. - virtual void update(); - /// close the connections - virtual void close(); + QToc(ControlToc &); + friend class QTocDialog; + private: - /// Create the dialog if necessary, update it and display it. - void show(); - /// Hide the dialog. - void hide(); - - /// create a Toc inset - void createTOC(string const &); - /// view a Toc inset - void showTOC(InsetCommand * const); - - /// update the Toc - void updateToc(int); - - /// Real GUI implementation. - QTocDialog * dialog_; - - /// the LyXView we belong to - LyXView * lv_; - - /** Which Dialogs do we belong to? - Used so we can get at the signals we have to connect to. - */ - Dialogs * d_; - /// pointer to the inset if any - InsetCommand * inset_; - /// insets params - InsetCommandParams params; - - /// Hide connection. - SigC::Connection h_; - /// Update connection. - SigC::Connection u_; - /// Inset hide connection. - SigC::Connection ih_; + /// update the listview + void updateToc(int newdepth); + + /// update the float types + void updateType(); + + /// select an entry + void select(string const & text); + + /// set the depth + void set_depth(int depth); + + virtual void apply() {}; + + /// update dialog + virtual void update_contents(); + + /// build dialog + virtual void build_dialog(); /// the toc list - //std::vector toclist; + Buffer::SingleList toclist; /// depth of list shown - int depth; + int depth_; }; #endif // QTOC_H diff --git a/src/frontends/qt2/QTocDialog.C b/src/frontends/qt2/QTocDialog.C index f434c95135..a2a4e73a76 100644 --- a/src/frontends/qt2/QTocDialog.C +++ b/src/frontends/qt2/QTocDialog.C @@ -7,17 +7,19 @@ */ #include -#include #include "QTocDialog.h" #include "Dialogs.h" #include "QToc.h" #include +#include -QTocDialog::QTocDialog(QToc * form, QWidget * parent, const char * name, bool modal, WFlags fl) - : QTocDialogBase(parent, name, modal, fl), +QTocDialog::QTocDialog(QToc * form) + : QTocDialogBase(0, 0, false, 0), form_(form) { + connect(closePB, SIGNAL(clicked()), + form, SLOT(slotClose())); } @@ -26,43 +28,21 @@ QTocDialog::~QTocDialog() } -void QTocDialog::activate_adaptor(int index) +void QTocDialog::activate_adaptor(int) { - switch (index) { - case 0: - //form_->set_type(Buffer::TOC_TOC); - break; - case 1: - //form_->set_type(Buffer::TOC_LOF); - break; - case 2: - //form_->set_type(Buffer::TOC_LOT); - break; - case 3: - //form_->set_type(Buffer::TOC_LOA); - break; - default: - lyxerr[Debug::GUI] << "Unknown TOC combo selection." << std::endl; - break; - } + form_->updateToc(form_->depth_); } -void QTocDialog::close_adaptor() -{ - form_->close(); - hide(); -} - - -void QTocDialog::depth_adaptor(int /*depth*/) + +void QTocDialog::depth_adaptor(int depth) { - //form_->set_depth(depth); + form_->set_depth(depth); } -void QTocDialog::select_adaptor(QListViewItem * /*item*/) +void QTocDialog::select_adaptor(QListViewItem * item) { - //form_->select(item->text(0)); + form_->select(item->text(0).latin1()); } @@ -74,6 +54,6 @@ void QTocDialog::update_adaptor() void QTocDialog::closeEvent(QCloseEvent * e) { - form_->close(); + form_->slotWMHide(); e->accept(); } diff --git a/src/frontends/qt2/QTocDialog.h b/src/frontends/qt2/QTocDialog.h index b01da871a9..f678e81c1c 100644 --- a/src/frontends/qt2/QTocDialog.h +++ b/src/frontends/qt2/QTocDialog.h @@ -17,12 +17,11 @@ class QTocDialog : public QTocDialogBase { Q_OBJECT public: - QTocDialog(QToc * form, QWidget * parent = 0, const char * name = 0, bool modal = FALSE, WFlags fl = 0); + QTocDialog(QToc * form); ~QTocDialog(); public slots: void activate_adaptor(int); - void close_adaptor(); void depth_adaptor(int); void select_adaptor(QListViewItem *); void update_adaptor(); diff --git a/src/frontends/qt2/ui/QTocDialog.ui b/src/frontends/qt2/ui/QTocDialog.ui index 65c8a4d463..4b921d6371 100644 --- a/src/frontends/qt2/ui/QTocDialog.ui +++ b/src/frontends/qt2/ui/QTocDialog.ui @@ -13,7 +13,7 @@ 0 0 - 369 + 361 313 @@ -30,12 +30,79 @@ spacing 6 + + QLayoutWidget + + name + Layout3 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + typeLA + + + text + &Type + + + buddy + typeCO + + + + QComboBox + + name + typeCO + + + sizePolicy + + 3 + 0 + + + + + + name + Spacer3 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QListView text - Table Of Contents + Contents list clickable @@ -57,10 +124,6 @@ name depthSL - - orientation - Horizontal - maxValue 5 @@ -69,12 +132,16 @@ pageStep 1 + + orientation + Horizontal + QLayoutWidget name - Layout39 + Layout2 @@ -85,10 +152,21 @@ spacing 6 + + QPushButton + + name + updatePB + + + text + &Update + + name - Spacer11 + Spacer2 orientation @@ -106,63 +184,6 @@ - - QLabel - - name - typeLA - - - text - &Type - - - buddy - typeCO - - - - QComboBox - - - text - Table of Contents - - - - - text - List of Figures - - - - - text - List of Tables - - - - - text - List of Algorithms - - - - name - typeCO - - - - QPushButton - - name - updatePB - - - text - &Update - - QPushButton @@ -201,12 +222,6 @@ QTocDialogBase update_adaptor() - - closePB - clicked() - QTocDialogBase - close_adaptor() - depthSL valueChanged(int) -- 2.39.2