*
* \author John Levon
* \author Abdelrazak Younes
+ * \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#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 <algorithm>
+#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, QObject * parent)
- : QObject(parent), ControlToc(dialog)
+GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
+ : DockView(parent, "toc", qt_("Outline"), area, flags)
{
+ widget_ = new TocWidget(parent.tocModels(), &parent);
+ setWidget(widget_);
}
-bool GuiToc::canOutline(int type) const
+GuiToc::~GuiToc()
{
- if (type < 0)
- return false;
-
- return ControlToc::canOutline(type);
+ delete widget_;
}
-int GuiToc::getTocDepth(int type)
-{
- if (type < 0)
- return 0;
- return toc_models_[type]->modelDepth();
-}
-
-
-QStandardItemModel * GuiToc::tocModel(int type)
+void GuiToc::updateView()
{
- 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_->updateView();
}
-QModelIndex const GuiToc::getCurrentIndex(int type) const
+bool GuiToc::initialiseParams(string const & data)
{
- 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));
+ widget_->init(toqstr(data));
+ return true;
}
-void GuiToc::goTo(int type, QModelIndex const & index)
+void GuiToc::dispatchParams()
{
- 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;
-
- ControlToc::goTo(*it);
}
-bool GuiToc::initialiseParams(std::string const & data)
+void GuiToc::enableView(bool enable)
{
- if (!ControlToc::initialiseParams(data))
- return false;
- updateView();
- modelReset();
- return true;
+ widget_->setEnabled(enable);
}
-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));
+ GuiView & guiview = static_cast<GuiView &>(lv);
+#ifdef Q_WS_MACX
+ // On Mac show as a drawer at the right
+ return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
+#else
+ return new GuiToc(guiview);
+#endif
}