+2002-01-20 John Levon <moz@compsoc.man.ac.uk>
+
+ * Makefile.am:
+ * Dialogs.C:
+ * QToc.h:
+ * QToc.C:
+ * QTocDialog.h:
+ * QTocDialog.C:
+ * ui/QTocDialog.ui: resuscitate TOC dialog
+
2002-01-20 John Levon <moz@compsoc.man.ac.uk>
* QCitation.h:
#include "QTabularCreateDialog.h"
#include "QTexinfoDialog.h"
#include "QThesaurusDialog.h"
+#include "QTocDialog.h"
#include "QURLDialog.h"
#include "QVCLogDialog.h"
#include "QSpellchecker.h"
#include "QTabularCreate.h"
#include "QTexinfo.h"
+#include "QToc.h"
#include "QThesaurus.h"
#include "QURL.h"
#include "QVCLog.h"
#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"
#include "xforms/FormPreferences.h"
#include "xforms/FormShowFile.h"
#include "xforms/FormTabular.h"
-#include "xforms/FormToc.h"
-#include "xforms/form_toc.h"
#include "GUI.h"
add(new GUITabularCreate<QTabularCreate, Qt2BC>(*lv, *this));
add(new GUITexinfo<QTexinfo, Qt2BC>(*lv, *this));
add(new GUIThesaurus<QThesaurus, Qt2BC>(*lv, *this));
+ add(new GUIToc<QToc, Qt2BC>(*lv, *this));
add(new GUIUrl<QURL, Qt2BC>(*lv, *this));
add(new GUIVCLog<QVCLog, Qt2BC>(*lv, *this));
// dialogs not yet converted
- add(new GUIERT<FormERT, xformsBC>(*lv, *this));
add(new GUIFloat<FormFloat, xformsBC>(*lv, *this));
add(new GUIShowFile<FormShowFile, xformsBC>(*lv, *this));
- add(new GUIToc<FormToc, xformsBC>(*lv, *this));
// dialogs not yet MVCd
add(new FormDocument(lv, this));
../xforms/FormBase.lo \
../xforms/FormBaseDeprecated.lo \
../xforms/FormBrowser.lo \
- ../xforms/FormERT.lo \
../xforms/FormFloat.lo \
../xforms/FormMathsBitmap.lo \
../xforms/FormMathsDeco.lo \
../xforms/FormTabular.lo \
../xforms/FormDocument.lo \
../xforms/FormInset.lo \
- ../xforms/FormToc.lo \
../xforms/MathsSymbols.lo \
../xforms/Menubar_pimpl.lo \
../xforms/RadioButtonGroup.lo \
../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 \
#include <config.h>
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
#include <stack>
#include <qslider.h>
+#include <qlistview.h>
+#include <qpushbutton.h>
+#include <qcombobox.h>
+
#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 <qlistview.h>
-#include <qcombobox.h>
-
+#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<ControlToc, Qt2DB<QTocDialog> > 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<string> const & choice = controller().getTypes();
+ string const & type = toc::getType(controller().params().getCmdName());
+
+ for (vector<string>::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<Buffer::TocItem> > 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);
// 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
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;
}
}
-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 <Buffer::TocItem>::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);
}
#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<ControlToc, Qt2DB<QTocDialog> >
+{
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 <Buffer::TocItem> toclist;
+ Buffer::SingleList toclist;
/// depth of list shown
- int depth;
+ int depth_;
};
#endif // QTOC_H
*/
#include <config.h>
-#include <debug.h>
#include "QTocDialog.h"
#include "Dialogs.h"
#include "QToc.h"
#include <qlistview.h>
+#include <qpushbutton.h>
-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()));
}
}
-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());
}
void QTocDialog::closeEvent(QCloseEvent * e)
{
- form_->close();
+ form_->slotWMHide();
e->accept();
}
{ 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();
<rect>
<x>0</x>
<y>0</y>
- <width>369</width>
+ <width>361</width>
<height>313</height>
</rect>
</property>
<name>spacing</name>
<number>6</number>
</property>
+ <widget>
+ <class>QLayoutWidget</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>Layout3</cstring>
+ </property>
+ <hbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>0</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget>
+ <class>QLabel</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>typeLA</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>&Type</string>
+ </property>
+ <property>
+ <name>buddy</name>
+ <cstring>typeCO</cstring>
+ </property>
+ </widget>
+ <widget>
+ <class>QComboBox</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>typeCO</cstring>
+ </property>
+ <property stdset="1">
+ <name>sizePolicy</name>
+ <sizepolicy>
+ <hsizetype>3</hsizetype>
+ <vsizetype>0</vsizetype>
+ </sizepolicy>
+ </property>
+ </widget>
+ <spacer>
+ <property>
+ <name>name</name>
+ <cstring>Spacer3</cstring>
+ </property>
+ <property stdset="1">
+ <name>orientation</name>
+ <enum>Horizontal</enum>
+ </property>
+ <property stdset="1">
+ <name>sizeType</name>
+ <enum>Expanding</enum>
+ </property>
+ <property>
+ <name>sizeHint</name>
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </hbox>
+ </widget>
<widget>
<class>QListView</class>
<column>
<property>
<name>text</name>
- <string>Table Of Contents</string>
+ <string>Contents list</string>
</property>
<property>
<name>clickable</name>
<name>name</name>
<cstring>depthSL</cstring>
</property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Horizontal</enum>
- </property>
<property stdset="1">
<name>maxValue</name>
<number>5</number>
<name>pageStep</name>
<number>1</number>
</property>
+ <property stdset="1">
+ <name>orientation</name>
+ <enum>Horizontal</enum>
+ </property>
</widget>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
- <cstring>Layout39</cstring>
+ <cstring>Layout2</cstring>
</property>
<hbox>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
+ <widget>
+ <class>QPushButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>updatePB</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>&Update</string>
+ </property>
+ </widget>
<spacer>
<property>
<name>name</name>
- <cstring>Spacer11</cstring>
+ <cstring>Spacer2</cstring>
</property>
<property stdset="1">
<name>orientation</name>
</size>
</property>
</spacer>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>typeLA</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>&Type</string>
- </property>
- <property>
- <name>buddy</name>
- <cstring>typeCO</cstring>
- </property>
- </widget>
- <widget>
- <class>QComboBox</class>
- <item>
- <property>
- <name>text</name>
- <string>Table of Contents</string>
- </property>
- </item>
- <item>
- <property>
- <name>text</name>
- <string>List of Figures</string>
- </property>
- </item>
- <item>
- <property>
- <name>text</name>
- <string>List of Tables</string>
- </property>
- </item>
- <item>
- <property>
- <name>text</name>
- <string>List of Algorithms</string>
- </property>
- </item>
- <property stdset="1">
- <name>name</name>
- <cstring>typeCO</cstring>
- </property>
- </widget>
- <widget>
- <class>QPushButton</class>
- <property stdset="1">
- <name>name</name>
- <cstring>updatePB</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>&Update</string>
- </property>
- </widget>
<widget>
<class>QPushButton</class>
<property stdset="1">
<receiver>QTocDialogBase</receiver>
<slot>update_adaptor()</slot>
</connection>
- <connection>
- <sender>closePB</sender>
- <signal>clicked()</signal>
- <receiver>QTocDialogBase</receiver>
- <slot>close_adaptor()</slot>
- </connection>
<connection>
<sender>depthSL</sender>
<signal>valueChanged(int)</signal>