X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiToc.cpp;h=9711bb68f6c8be99d9c71f82dc97f4dc35c32ab0;hb=8e7d7e42952f0119db1c192386a63d1d9ede3b7f;hp=4a909b9f851f38ef3db4ada120b836aeea19483e;hpb=9e3823945a9b5d02485f1d7c1609930f1869eec2;p=lyx.git diff --git a/src/frontends/qt4/GuiToc.cpp b/src/frontends/qt4/GuiToc.cpp index 4a909b9f85..9711bb68f6 100644 --- a/src/frontends/qt4/GuiToc.cpp +++ b/src/frontends/qt4/GuiToc.cpp @@ -5,6 +5,7 @@ * * \author John Levon * \author Abdelrazak Younes + * \author Angus Leeming * * Full author contact details are available in file CREDITS. */ @@ -12,133 +13,103 @@ #include #include "GuiToc.h" - -#include "TocModel.h" +#include "GuiView.h" +#include "DockView.h" +#include "TocWidget.h" #include "qt_helpers.h" -#include "debug.h" - -#include "ControlToc.h" - -#include +#include "Buffer.h" +#include "BufferView.h" +#include "BufferParams.h" +#include "FuncRequest.h" -using std::endl; +#include "support/debug.h" +#include "support/gettext.h" +#include "support/lassert.h" -using std::pair; -using std::vector; -using std::string; +using namespace std; namespace lyx { namespace frontend { - -GuiToc::GuiToc(Dialog & dialog) - : ControlToc(dialog) +GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags) + : DockView(parent, "toc", qt_("Outline"), area, flags), is_closing_(false) { -#ifdef Q_WS_MACX - // On Mac show as a drawer at the right - //setView(new DockView( - // *dialog, qtoc, &gui_view, _("Outline"), Qt::RightDockWidgetArea, Qt::Drawer)); -#else - //setView(new DockView( -// *dialog, qtoc, &gui_view, _("Outline"))); -#endif + widget_ = new TocWidget(parent, this); + setWidget(widget_); + setFocusProxy(widget_); } -bool GuiToc::canOutline(int type) const +GuiToc::~GuiToc() { - if (type < 0) - return false; - - return canOutline(type); + delete widget_; } -int GuiToc::getTocDepth(int type) +void GuiToc::updateView() { - if (type < 0) - return 0; - return toc_models_[type]->modelDepth(); + widget_->updateView(); + return; } -QStandardItemModel * GuiToc::tocModel(int type) +bool GuiToc::initialiseParams(string const & data) { - if (type < 0) - return 0; - - if (toc_models_.empty()) { - LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl; - return 0; - } - - LYXERR(Debug::GUI) - << "GuiToc: type " << type - << " toc_models_.size() " << toc_models_.size() - << endl; - - BOOST_ASSERT(type >= 0 && type < int(toc_models_.size())); - return toc_models_[type]; + widget_->init(toqstr(data)); + return true; } -QModelIndex const GuiToc::getCurrentIndex(int type) const +void GuiToc::dispatchParams() { - if (type < 0) - return QModelIndex(); - - // FIXME: The TocBackend infrastructure is not ready for LOF and LOT - // This is because a proper ParConstIterator is not constructed in - // InsetCaption::addToToc() - if(!canOutline(type)) - return QModelIndex(); - - return toc_models_[type]->modelIndex(getCurrentTocItem(type)); } -void GuiToc::goTo(int type, QModelIndex const & index) +void GuiToc::enableView(bool enable) { - if (type < 0 || !index.isValid() - || index.model() != toc_models_[type]) { - LYXERR(Debug::GUI) - << "GuiToc::goTo(): QModelIndex is invalid!" - << endl; - return; - } + if (!enable) + // In the opposite case, updateView() will be called anyway. + widget_->updateView(); +} - BOOST_ASSERT(type >= 0 && type < int(toc_models_.size())); - TocIterator const it = toc_models_[type]->tocIterator(index); +void GuiToc::closeEvent(QCloseEvent * /*event*/) +{ + is_closing_ = true; + ((GuiView *)parent())->updateToolbars(); + is_closing_ = false; +} - LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl; - ControlToc::goTo(*it); +void GuiToc::doDispatch(Cursor & cur, FuncRequest const & cmd) +{ + widget_->doDispatch(cur, cmd); } -bool GuiToc::initialiseParams(std::string const & data) +bool GuiToc::getStatus(Cursor & cur, FuncRequest const & cmd, + FuncStatus & status) const { - if (!ControlToc::initialiseParams(data)) - return false; - updateView(); - modelReset(); - return true; + return widget_->getStatus(cur, cmd, status); } -void GuiToc::updateView() +Dialog * createGuiToc(GuiView & lv) { - toc_models_.clear(); - TocList::const_iterator it = tocs().begin(); - TocList::const_iterator end = tocs().end(); - for (; it != end; ++it) - toc_models_.push_back(new TocModel(it->second)); + GuiToc * toc; +#ifdef Q_WS_MACX + // On Mac show at the right and floating + toc = new GuiToc(lv, Qt::RightDockWidgetArea); + toc->setFloating(true); +#else + toc = new GuiToc(lv); +#endif + return toc; } } // namespace frontend } // namespace lyx -#include "GuiToc_moc.cpp" +#include "moc_GuiToc.cpp"