/**
* \file QToc.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
*/
#include <config.h>
-#include <stack>
+#ifdef __GNUG__
+#pragma implementation
+#endif
-#include <qslider.h>
-#include "QTocDialog.h"
-#include "QtLyXView.h"
+#include <stack>
-#include "Dialogs.h"
-#include "BufferView.h"
-#include "QToc.h"
+#include "LyXView.h"
#include "gettext.h"
-#include "buffer.h"
#include "support/lstrings.h"
-#include "lyxfunc.h"
#include "debug.h"
+#include "ControlToc.h"
+#include "QToc.h"
+#include "QTocDialog.h"
+#include "Qt2BC.h"
+
+#include <qslider.h>
#include <qlistview.h>
+#include <qpushbutton.h>
#include <qcombobox.h>
-using std::vector;
+using std::endl;
using std::pair;
using std::stack;
-using std::endl;
-using SigC::slot;
+using std::vector;
+typedef Qt2CB<ControlToc, Qt2DB<QTocDialog> > base_class;
+
+QToc::QToc()
+ : base_class(_("Table of contents")), depth_(1)
+{}
-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()
+void QToc::build_dialog()
{
- delete dialog_;
+ dialog_.reset(new QTocDialog(this));
+
+ // Manage the cancel/close button
+ bc().setCancel(dialog_->closePB);
}
-void QToc::showTOC(InsetCommand * const inset)
+void QToc::updateType()
{
- // FIXME: when could inset be 0 here ?
- if (inset == 0)
- return;
+ dialog_->typeCO->clear();
+
+ vector<string> const & choice = controller().getTypes();
+ string const & type = toc::getType(controller().params().getCmdName());
- inset_ = inset;
- //FIXME ih_ = inset_->hide.connect(slot(this,&QToc::hide));
- params = inset->params();
-
- show();
+ 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::createTOC(string const & arg)
+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;
- }
+ char const * str = dialog_->typeCO->currentText().latin1();
+ string type (str ? str : "");
-#if 0
- vector< vector<Buffer::TocItem> > tmp =
- lv_->view()->buffer()->getTocList();
+ toc::Toc 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);
int curdepth = 0;
- stack< pair< QListViewItem *, QListViewItem *> > istack;
- QListViewItem *last = 0;
- QListViewItem *parent = 0;
- QListViewItem *item;
+ 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
+ // 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
- for (vector< Buffer::TocItem >::const_iterator iter = toclist.begin();
- iter != toclist.end(); ++iter) {
+ for (toc::Toc::const_iterator iter = toclist.begin();
+ iter != toclist.end(); ++iter) {
if (iter->depth == curdepth) {
// insert it after the last one we processed
if (!parent)
- item = (last) ? (new QListViewItem(dialog_->tocLV,last)) : (new QListViewItem(dialog_->tocLV));
+ item = (last ? new QListViewItem(dialog_->tocLV,last) : new QListViewItem(dialog_->tocLV));
else
- item = (last) ? (new QListViewItem(parent,last)) : (new QListViewItem(parent));
+ item = (last ? new QListViewItem(parent,last) : new QListViewItem(parent));
} else if (iter->depth > curdepth) {
int diff = iter->depth - curdepth;
// first save old parent and last
while (diff--)
istack.push(pair< QListViewItem *, QListViewItem * >(parent,last));
- item = (last) ? (new QListViewItem(last)) : (new QListViewItem(dialog_->tocLV));
+ item = (last ? new QListViewItem(last) : new QListViewItem(dialog_->tocLV));
parent = last;
} else {
int diff = curdepth - iter->depth;
- pair< QListViewItem *, QListViewItem * > top;
+ pair<QListViewItem *, QListViewItem * > top;
// restore context
while (diff--) {
top = istack.top();
last = top.second;
// insert it after the last one we processed
if (!parent)
- item = (last) ? (new QListViewItem(dialog_->tocLV,last)) : (new QListViewItem(dialog_->tocLV));
+ item = (last ? new QListViewItem(dialog_->tocLV,last) : new QListViewItem(dialog_->tocLV));
else
- item = (last) ? (new QListViewItem(parent,last)) : (new QListViewItem(parent));
+ 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;
+
+ lyxerr[Debug::GUI]
+ << "Table of contents\n"
+ << "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)
+void QToc::select(string const & text)
{
- 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)
-{
- if (!lv_->view()->available())
- return;
+ toc::Toc::const_iterator iter = toclist.begin();
- vector <Buffer::TocItem>::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;
- return;
- }
-
- lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tostr(iter->par->id()).c_str());
-}
-
-void QToc::set_type(Buffer::TocType toctype)
-{
- if (toctype==type)
+ if (iter == toclist.end()) {
+ lyxerr[Debug::GUI] << "Couldn't find highlighted TOC entry : "
+ << text << endl;
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);
}
-void QToc::hide()
+void QToc::set_depth(int depth)
{
- dialog_->hide();
- close();
+ if (depth != depth_)
+ updateToc(depth);
}