2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiToc.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
2007-10-06 20:35:44 +00:00
|
|
|
* \author Angus Leeming
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiToc.h"
|
2007-10-06 20:35:44 +00:00
|
|
|
#include "GuiView.h"
|
|
|
|
#include "DockView.h"
|
|
|
|
#include "TocWidget.h"
|
2007-10-07 18:58:47 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "insets/InsetCommand.h"
|
2007-03-12 14:23:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
#include "TocModel.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "FloatList.h"
|
|
|
|
#include "FuncRequest.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2007-10-06 20:35:44 +00:00
|
|
|
|
|
|
|
#include "support/convert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
|
2008-02-12 07:47:16 +00:00
|
|
|
: DockView(parent, "toc", qt_("Outline"), area, flags)
|
2007-10-08 20:14:58 +00:00
|
|
|
{
|
2008-02-28 16:14:26 +00:00
|
|
|
widget_ = new TocWidget(*this, &parent);
|
2007-10-08 20:14:58 +00:00
|
|
|
setWidget(widget_);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2007-10-09 09:29:27 +00:00
|
|
|
GuiToc::~GuiToc()
|
|
|
|
{
|
2007-12-02 18:39:05 +00:00
|
|
|
clearTocModels();
|
2007-10-09 09:29:27 +00:00
|
|
|
delete widget_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-02 18:39:05 +00:00
|
|
|
void GuiToc::clearTocModels()
|
|
|
|
{
|
|
|
|
const unsigned int size = toc_models_.size();
|
|
|
|
for (unsigned int i = 0; i < size; ++i) {
|
|
|
|
delete toc_models_[i];
|
|
|
|
}
|
|
|
|
toc_models_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
int GuiToc::getTocDepth(int type)
|
2006-11-25 22:16:22 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
if (type < 0)
|
2007-03-12 17:03:42 +00:00
|
|
|
return 0;
|
2007-03-16 14:14:55 +00:00
|
|
|
return toc_models_[type]->modelDepth();
|
2006-11-25 22:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
QStandardItemModel * GuiToc::tocModel(int type)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
if (type < 0)
|
|
|
|
return 0;
|
|
|
|
|
2007-01-03 22:03:26 +00:00
|
|
|
if (toc_models_.empty()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "GuiToc::tocModel(): no types available ");
|
2006-12-30 14:50:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "GuiToc: type " << type
|
|
|
|
<< " toc_models_.size() " << toc_models_.size());
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
|
|
|
|
return toc_models_[type];
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
QModelIndex GuiToc::currentIndex(int type) const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
if (type < 0)
|
2007-03-12 17:03:42 +00:00
|
|
|
return QModelIndex();
|
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
return toc_models_[type]->modelIndex(currentTocItem(type));
|
2006-04-19 14:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiToc::goTo(int type, QModelIndex const & index)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
if (type < 0 || !index.isValid()
|
2007-03-16 14:14:55 +00:00
|
|
|
|| index.model() != toc_models_[type]) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "GuiToc::goTo(): QModelIndex is invalid!");
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-04-22 18:48:28 +00:00
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
|
2007-03-12 17:03:42 +00:00
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
TocIterator const it = toc_models_[type]->tocIterator(index);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "GuiToc::goTo " << to_utf8(it->str()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
string const tmp = convert<string>(it->id());
|
2007-11-26 22:45:17 +00:00
|
|
|
dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
|
2007-10-06 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::updateView()
|
|
|
|
{
|
2007-10-09 08:06:36 +00:00
|
|
|
widget_->updateView();
|
2007-10-06 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TocList const & GuiToc::tocs() const
|
|
|
|
{
|
2007-10-20 10:03:45 +00:00
|
|
|
return buffer().masterBuffer()->tocBackend().tocs();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
bool GuiToc::initialiseParams(string const & data)
|
2007-04-03 13:07:38 +00:00
|
|
|
{
|
2008-02-12 07:47:16 +00:00
|
|
|
LYXERR(Debug::GUI, data);
|
|
|
|
QString str = QString::fromUtf8(data.c_str());
|
2008-03-06 19:39:52 +00:00
|
|
|
QString new_type;
|
2008-02-12 15:33:01 +00:00
|
|
|
if (str.contains("tableofcontents"))
|
|
|
|
new_type = "tableofcontents";
|
|
|
|
else if (str.contains("floatlist")) {
|
2008-02-12 09:32:40 +00:00
|
|
|
if (str.contains("\"figure"))
|
2008-02-12 07:47:16 +00:00
|
|
|
new_type = "figure";
|
2008-02-12 09:32:40 +00:00
|
|
|
else if (str.contains("\"table"))
|
2008-02-12 07:47:16 +00:00
|
|
|
new_type = "table";
|
2008-02-12 09:32:40 +00:00
|
|
|
else if (str.contains("\"algorithm"))
|
2008-02-12 08:58:32 +00:00
|
|
|
new_type = "algorithm";
|
2008-02-12 07:47:16 +00:00
|
|
|
}
|
2007-10-06 20:35:44 +00:00
|
|
|
|
|
|
|
types_.clear();
|
|
|
|
type_names_.clear();
|
2007-12-02 18:39:05 +00:00
|
|
|
clearTocModels();
|
2007-10-20 10:03:45 +00:00
|
|
|
TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
|
2007-10-06 20:35:44 +00:00
|
|
|
TocList::const_iterator it = tocs.begin();
|
|
|
|
TocList::const_iterator end = tocs.end();
|
|
|
|
for (; it != end; ++it) {
|
2008-03-06 19:39:52 +00:00
|
|
|
types_.push_back(toqstr(it->first));
|
|
|
|
type_names_.push_back(toqstr(guiName(it->first)));
|
2007-10-09 08:06:36 +00:00
|
|
|
toc_models_.push_back(new TocModel(it->second));
|
2007-10-06 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
2008-02-12 07:47:16 +00:00
|
|
|
int selected_type = -1;
|
2008-03-06 19:39:52 +00:00
|
|
|
for (int i = 0; i != types_.size(); ++i) {
|
2008-02-12 07:47:16 +00:00
|
|
|
if (new_type == types_[i]) {
|
|
|
|
selected_type = i;
|
2007-10-06 20:35:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-12 07:47:16 +00:00
|
|
|
widget_->updateGui(selected_type);
|
|
|
|
|
2007-04-03 13:07:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
bool GuiToc::canOutline(int type) const
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2007-10-06 20:35:44 +00:00
|
|
|
return types_[type] == "tableofcontents";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::outlineUp()
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_OUTLINE_UP));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::outlineDown()
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::outlineIn()
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_OUTLINE_IN));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::outlineOut()
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_OUTLINE_OUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::updateBackend()
|
|
|
|
{
|
2007-10-20 10:03:45 +00:00
|
|
|
buffer().masterBuffer()->tocBackend().update();
|
2007-10-06 20:35:44 +00:00
|
|
|
buffer().structureChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TocIterator GuiToc::currentTocItem(int type) const
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(bufferview());
|
|
|
|
ParConstIterator it(bufferview()->cursor());
|
2008-03-06 19:39:52 +00:00
|
|
|
return buffer().masterBuffer()->tocBackend().item(fromqstr(types_[type]), it);
|
2007-10-06 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring GuiToc::guiName(string const & type) const
|
|
|
|
{
|
|
|
|
if (type == "tableofcontents")
|
|
|
|
return _("Table of Contents");
|
2008-02-15 08:09:35 +00:00
|
|
|
if (type == "equation")
|
|
|
|
return _("List of Equations");
|
2008-02-11 13:06:01 +00:00
|
|
|
if (type == "footnote")
|
|
|
|
return _("List of Foot notes");
|
2008-02-13 13:33:56 +00:00
|
|
|
if (type == "listing")
|
|
|
|
return _("List of Listings");
|
2008-02-13 13:19:39 +00:00
|
|
|
if (type == "index")
|
|
|
|
return _("List of Indexes");
|
2008-02-13 13:33:56 +00:00
|
|
|
if (type == "marginalnote")
|
|
|
|
return _("List of Marginal notes");
|
2008-02-11 13:06:01 +00:00
|
|
|
if (type == "note")
|
|
|
|
return _("List of Notes");
|
2008-03-04 17:47:47 +00:00
|
|
|
if (type == "citation")
|
|
|
|
return _("List of Citations");
|
2008-02-27 15:23:22 +00:00
|
|
|
if (type == "label")
|
|
|
|
return _("Labels and References");
|
2008-02-11 13:06:01 +00:00
|
|
|
|
2008-02-28 01:42:02 +00:00
|
|
|
FloatList const & floats = buffer().params().documentClass().floats();
|
2007-10-06 20:35:44 +00:00
|
|
|
if (floats.typeExist(type))
|
|
|
|
return _(floats.getType(type).listName());
|
|
|
|
|
|
|
|
return _(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 18:58:47 +00:00
|
|
|
void GuiToc::dispatchParams()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiToc(GuiView & lv)
|
2007-10-06 20:35:44 +00:00
|
|
|
{
|
2007-11-05 13:52:37 +00:00
|
|
|
GuiView & guiview = static_cast<GuiView &>(lv);
|
2007-10-06 20:35:44 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
// On Mac show as a drawer at the right
|
2007-10-08 20:14:58 +00:00
|
|
|
return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
|
2007-10-06 20:35:44 +00:00
|
|
|
#else
|
2007-10-08 20:14:58 +00:00
|
|
|
return new GuiToc(guiview);
|
2007-10-06 20:35:44 +00:00
|
|
|
#endif
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-03-12 14:23:44 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiToc_moc.cpp"
|