X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiToc.cpp;h=9711bb68f6c8be99d9c71f82dc97f4dc35c32ab0;hb=8e7d7e42952f0119db1c192386a63d1d9ede3b7f;hp=cf1d54362ab4e83aea8dd2b6ad3647e449a81d14;hpb=e117f67786032e6951ba08bb8a1e69cc2f89bfbc;p=lyx.git diff --git a/src/frontends/qt4/GuiToc.cpp b/src/frontends/qt4/GuiToc.cpp index cf1d54362a..9711bb68f6 100644 --- a/src/frontends/qt4/GuiToc.cpp +++ b/src/frontends/qt4/GuiToc.cpp @@ -16,226 +16,100 @@ #include "GuiView.h" #include "DockView.h" #include "TocWidget.h" - -#include "TocModel.h" #include "qt_helpers.h" #include "Buffer.h" #include "BufferView.h" #include "BufferParams.h" -#include "debug.h" -#include "FloatList.h" #include "FuncRequest.h" -#include "gettext.h" - -#include "frontends/LyXView.h" - -#include "support/convert.h" -#include - -using std::endl; -using std::string; +#include "support/debug.h" +#include "support/gettext.h" +#include "support/lassert.h" +using namespace std; namespace lyx { namespace frontend { -GuiToc::GuiToc(Dialog & dialog) - : ControlCommand(dialog, "toc") -{ -} - - -int GuiToc::getTocDepth(int type) -{ - if (type < 0) - return 0; - return toc_models_[type]->modelDepth(); -} - - -QStandardItemModel * GuiToc::tocModel(int type) +GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags) + : DockView(parent, "toc", qt_("Outline"), area, flags), is_closing_(false) { - 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_ = new TocWidget(parent, this); + setWidget(widget_); + setFocusProxy(widget_); } -QModelIndex GuiToc::currentIndex(int type) const +GuiToc::~GuiToc() { - 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(currentTocItem(type)); -} - - -void GuiToc::goTo(int type, QModelIndex const & index) -{ - if (type < 0 || !index.isValid() - || index.model() != toc_models_[type]) { - LYXERR(Debug::GUI) - << "GuiToc::goTo(): QModelIndex is invalid!" - << endl; - return; - } - - BOOST_ASSERT(type >= 0 && type < int(toc_models_.size())); - - TocIterator const it = toc_models_[type]->tocIterator(index); - - LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl; - - string const tmp = convert(it->id()); - lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp)); + delete widget_; } void GuiToc::updateView() { - 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)); -} - - -TocList const & GuiToc::tocs() const -{ - return buffer().getMasterBuffer()->tocBackend().tocs(); + widget_->updateView(); + return; } bool GuiToc::initialiseParams(string const & data) { - if (!ControlCommand::initialiseParams(data)) - return false; - - updateView(); - modelReset(); - - types_.clear(); - type_names_.clear(); - TocList const & tocs = buffer().getMasterBuffer()-> - tocBackend().tocs(); - TocList::const_iterator it = tocs.begin(); - TocList::const_iterator end = tocs.end(); - for (; it != end; ++it) { - types_.push_back(it->first); - type_names_.push_back(guiName(it->first)); - } - - string selected_type ; - if(params()["type"].empty()) //Then plain toc... - selected_type = params().getCmdName(); - else - selected_type = to_ascii(params()["type"]); - selected_type_ = -1; - for (size_t i = 0; i != types_.size(); ++i) { - if (selected_type == types_[i]) { - selected_type_ = i; - break; - } - } - + widget_->init(toqstr(data)); return true; } -bool GuiToc::canOutline(int type) const -{ - return types_[type] == "tableofcontents"; -} - - -void GuiToc::outlineUp() -{ - dispatch(FuncRequest(LFUN_OUTLINE_UP)); -} - - -void GuiToc::outlineDown() +void GuiToc::dispatchParams() { - dispatch(FuncRequest(LFUN_OUTLINE_DOWN)); } -void GuiToc::outlineIn() +void GuiToc::enableView(bool enable) { - dispatch(FuncRequest(LFUN_OUTLINE_IN)); + if (!enable) + // In the opposite case, updateView() will be called anyway. + widget_->updateView(); } -void GuiToc::outlineOut() +void GuiToc::closeEvent(QCloseEvent * /*event*/) { - dispatch(FuncRequest(LFUN_OUTLINE_OUT)); + is_closing_ = true; + ((GuiView *)parent())->updateToolbars(); + is_closing_ = false; } -void GuiToc::updateBackend() +void GuiToc::doDispatch(Cursor & cur, FuncRequest const & cmd) { - buffer().getMasterBuffer()->tocBackend().update(); - buffer().structureChanged(); + widget_->doDispatch(cur, cmd); } -TocIterator GuiToc::currentTocItem(int type) const +bool GuiToc::getStatus(Cursor & cur, FuncRequest const & cmd, + FuncStatus & status) const { - BOOST_ASSERT(bufferview()); - ParConstIterator it(bufferview()->cursor()); - Buffer const * master = buffer().getMasterBuffer(); - return master->tocBackend().item(types_[type], it); -} - - -docstring GuiToc::guiName(string const & type) const -{ - if (type == "tableofcontents") - return _("Table of Contents"); - - FloatList const & floats = buffer().params().getTextClass().floats(); - if (floats.typeExist(type)) - return _(floats.getType(type).listName()); - - return _(type); + return widget_->getStatus(cur, cmd, status); } -Dialog * createGuiToc(LyXView & lv) +Dialog * createGuiToc(GuiView & lv) { - GuiViewBase & guiview = static_cast(lv); + GuiToc * toc; #ifdef Q_WS_MACX - // On Mac show as a drawer at the right - return new DockView(guiview, "toc", - Qt::RightDockWidgetArea, Qt::Drawer); + // On Mac show at the right and floating + toc = new GuiToc(lv, Qt::RightDockWidgetArea); + toc->setFloating(true); #else - return new DockView(guiview, "toc"); + toc = new GuiToc(lv); #endif + return toc; } } // namespace frontend } // namespace lyx -#include "GuiToc_moc.cpp" +#include "moc_GuiToc.cpp"