2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file TocWidget.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
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
#include "TocWidget.h"
|
|
|
|
|
2009-04-03 17:00:09 +00:00
|
|
|
#include "GuiApplication.h"
|
2008-05-30 11:33:24 +00:00
|
|
|
#include "GuiView.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
2008-05-30 11:33:24 +00:00
|
|
|
#include "TocModel.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-06-17 15:44:14 +00:00
|
|
|
#include "Buffer.h"
|
2009-09-05 15:09:45 +00:00
|
|
|
#include "BufferView.h"
|
2009-04-08 21:40:42 +00:00
|
|
|
#include "CutAndPaste.h"
|
2008-05-02 12:09:51 +00:00
|
|
|
#include "FuncRequest.h"
|
2009-04-11 11:43:13 +00:00
|
|
|
#include "FuncStatus.h"
|
2010-02-09 16:11:13 +00:00
|
|
|
#include "LyX.h"
|
2009-04-08 21:06:58 +00:00
|
|
|
#include "Menus.h"
|
2009-04-08 21:40:42 +00:00
|
|
|
#include "TocBackend.h"
|
|
|
|
|
|
|
|
#include "insets/InsetCommand.h"
|
|
|
|
#include "insets/InsetRef.h"
|
2008-05-02 12:09:51 +00:00
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2008-06-11 18:13:14 +00:00
|
|
|
#include "support/lassert.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
#include <QHeaderView>
|
2009-04-08 21:06:58 +00:00
|
|
|
#include <QMenu>
|
2008-03-04 12:39:03 +00:00
|
|
|
#include <QTimer>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
using namespace std;
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
2007-05-04 17:46:03 +00:00
|
|
|
namespace frontend {
|
2007-03-12 14:23:44 +00:00
|
|
|
|
2008-05-30 11:33:24 +00:00
|
|
|
TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
|
2008-10-02 15:00:43 +00:00
|
|
|
: QWidget(parent), depth_(0), persistent_(false), gui_view_(gui_view)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2009-04-03 17:00:09 +00:00
|
|
|
moveOutTB->setIcon(QIcon(getPixmap("images/", "promote", "png")));
|
|
|
|
moveInTB->setIcon(QIcon(getPixmap("images/", "demote", "png")));
|
|
|
|
moveUpTB->setIcon(QIcon(getPixmap("images/", "up", "png")));
|
|
|
|
moveDownTB->setIcon(QIcon(getPixmap("images/", "down", "png")));
|
|
|
|
updateTB->setIcon(QIcon(getPixmap("images/", "reload", "png")));
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
// avoid flickering
|
|
|
|
tocTV->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
tocTV->showColumn(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
// hide the pointless QHeader for now
|
|
|
|
// in the future, new columns may appear
|
|
|
|
// like labels, bookmarks, etc...
|
|
|
|
// tocTV->header()->hide();
|
|
|
|
tocTV->header()->setVisible(false);
|
2007-05-04 17:46:03 +00:00
|
|
|
|
|
|
|
// Only one item selected at a time.
|
|
|
|
tocTV->setSelectionMode(QAbstractItemView::SingleSelection);
|
2008-06-17 15:10:03 +00:00
|
|
|
|
|
|
|
// The toc types combo won't change its model.
|
|
|
|
typeCO->setModel(gui_view_.tocModels().nameModel());
|
2008-07-29 10:33:02 +00:00
|
|
|
|
|
|
|
// Make sure the buttons are disabled when first shown without a loaded
|
|
|
|
// Buffer.
|
|
|
|
enableControls(false);
|
2008-10-27 14:54:53 +00:00
|
|
|
|
2009-04-08 21:06:58 +00:00
|
|
|
// make us responsible for the context menu of the tabbar
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
|
|
|
|
this, SLOT(showContextMenu(const QPoint &)));
|
|
|
|
connect(tocTV, SIGNAL(customContextMenuRequested(const QPoint &)),
|
|
|
|
this, SLOT(showContextMenu(const QPoint &)));
|
2010-02-13 08:30:16 +00:00
|
|
|
connect(filterLE, SIGNAL(textEdited(QString)),
|
|
|
|
this, SLOT(filterContents()));
|
2009-04-08 21:06:58 +00:00
|
|
|
|
2008-10-27 14:54:53 +00:00
|
|
|
init(QString());
|
2006-03-31 13:17:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-19 14:48:22 +00:00
|
|
|
|
2009-04-08 21:06:58 +00:00
|
|
|
void TocWidget::showContextMenu(const QPoint & pos)
|
|
|
|
{
|
|
|
|
std::string name = "context-toc-" + fromqstr(current_type_);
|
|
|
|
QMenu * menu = guiApp->menus().menu(toqstr(name), gui_view_);
|
|
|
|
if (!menu)
|
|
|
|
return;
|
|
|
|
menu->exec(mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-11 11:43:13 +00:00
|
|
|
Inset * TocWidget::itemInset() const
|
2009-04-08 21:06:58 +00:00
|
|
|
{
|
2009-04-09 18:51:07 +00:00
|
|
|
QModelIndex const & index = tocTV->currentIndex();
|
|
|
|
TocItem const & item =
|
|
|
|
gui_view_.tocModels().currentItem(current_type_, index);
|
|
|
|
DocIterator const & dit = item.dit();
|
|
|
|
|
|
|
|
Inset * inset = 0;
|
2009-04-10 00:42:24 +00:00
|
|
|
if (current_type_ == "label"
|
|
|
|
|| current_type_ == "graphics"
|
2009-04-18 18:53:39 +00:00
|
|
|
|| current_type_ == "citation"
|
|
|
|
|| current_type_ == "child")
|
2009-04-09 18:51:07 +00:00
|
|
|
inset = dit.nextInset();
|
|
|
|
|
2009-04-18 18:53:39 +00:00
|
|
|
else if (current_type_ == "branch"
|
2009-06-11 21:13:41 +00:00
|
|
|
|| current_type_ == "index"
|
2009-05-01 17:55:26 +00:00
|
|
|
|| current_type_ == "change")
|
2009-04-10 00:42:24 +00:00
|
|
|
inset = &dit.inset();
|
|
|
|
|
2009-04-18 18:53:39 +00:00
|
|
|
else if (current_type_ == "table"
|
|
|
|
|| current_type_ == "listing"
|
|
|
|
|| current_type_ == "figure") {
|
2009-04-10 00:42:24 +00:00
|
|
|
DocIterator tmp_dit(dit);
|
|
|
|
tmp_dit.pop_back();
|
|
|
|
inset = &tmp_dit.inset();
|
|
|
|
}
|
2009-04-11 11:43:13 +00:00
|
|
|
return inset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TocWidget::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
|
|
|
Inset * inset = itemInset();
|
|
|
|
FuncRequest tmpcmd(cmd);
|
2009-05-01 17:55:26 +00:00
|
|
|
|
2009-05-20 23:58:29 +00:00
|
|
|
QModelIndex const & index = tocTV->currentIndex();
|
|
|
|
TocItem const & item =
|
|
|
|
gui_view_.tocModels().currentItem(current_type_, index);
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action())
|
2009-05-01 17:55:26 +00:00
|
|
|
{
|
|
|
|
case LFUN_CHANGE_ACCEPT:
|
|
|
|
case LFUN_CHANGE_REJECT:
|
2009-05-03 16:06:00 +00:00
|
|
|
case LFUN_OUTLINE_UP:
|
|
|
|
case LFUN_OUTLINE_DOWN:
|
|
|
|
case LFUN_OUTLINE_IN:
|
|
|
|
case LFUN_OUTLINE_OUT:
|
2009-05-03 19:16:00 +00:00
|
|
|
case LFUN_SECTION_SELECT:
|
2009-05-01 17:55:26 +00:00
|
|
|
status.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
|
2009-05-20 23:58:29 +00:00
|
|
|
case LFUN_LABEL_COPY_AS_REF: {
|
|
|
|
// For labels in math, we need to supply the label as a string
|
|
|
|
FuncRequest label_copy(LFUN_LABEL_COPY_AS_REF, item.asString());
|
|
|
|
if (inset)
|
|
|
|
return inset->getStatus(cur, label_copy, status);
|
|
|
|
}
|
|
|
|
|
2009-05-01 17:55:26 +00:00
|
|
|
default:
|
|
|
|
if (inset)
|
|
|
|
return inset->getStatus(cur, tmpcmd, status);
|
|
|
|
}
|
|
|
|
|
2009-04-11 11:43:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd)
|
|
|
|
{
|
|
|
|
Inset * inset = itemInset();
|
2009-04-09 23:36:34 +00:00
|
|
|
FuncRequest tmpcmd(cmd);
|
2009-05-01 17:55:26 +00:00
|
|
|
|
|
|
|
QModelIndex const & index = tocTV->currentIndex();
|
|
|
|
TocItem const & item =
|
|
|
|
gui_view_.tocModels().currentItem(current_type_, index);
|
|
|
|
|
2009-10-03 19:12:21 +00:00
|
|
|
// Start an undo group.
|
|
|
|
cur.beginUndoGroup();
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action())
|
2009-05-01 17:55:26 +00:00
|
|
|
{
|
|
|
|
case LFUN_CHANGE_ACCEPT:
|
|
|
|
case LFUN_CHANGE_REJECT:
|
2009-05-03 19:16:00 +00:00
|
|
|
case LFUN_SECTION_SELECT:
|
2009-05-01 17:55:26 +00:00
|
|
|
dispatch(item.action());
|
|
|
|
cur.dispatch(tmpcmd);
|
|
|
|
break;
|
2009-05-20 23:58:29 +00:00
|
|
|
|
|
|
|
case LFUN_LABEL_COPY_AS_REF: {
|
|
|
|
// For labels in math, we need to supply the label as a string
|
|
|
|
FuncRequest label_copy(LFUN_LABEL_COPY_AS_REF, item.asString());
|
|
|
|
if (inset)
|
|
|
|
inset->dispatch(cur, label_copy);
|
|
|
|
break;
|
|
|
|
}
|
2009-05-03 16:06:00 +00:00
|
|
|
|
|
|
|
case LFUN_OUTLINE_UP:
|
|
|
|
case LFUN_OUTLINE_DOWN:
|
|
|
|
case LFUN_OUTLINE_IN:
|
|
|
|
case LFUN_OUTLINE_OUT:
|
2010-04-09 19:00:42 +00:00
|
|
|
outline(cmd.action());
|
2009-05-03 16:06:00 +00:00
|
|
|
break;
|
2009-05-01 17:55:26 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
if (inset)
|
|
|
|
inset->dispatch(cur, tmpcmd);
|
|
|
|
}
|
2009-10-03 19:12:21 +00:00
|
|
|
cur.endUndoGroup();
|
2009-04-08 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-17 17:03:53 +00:00
|
|
|
void TocWidget::on_tocTV_activated(QModelIndex const & index)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2008-05-17 17:03:53 +00:00
|
|
|
goTo(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-08 17:39:14 +00:00
|
|
|
void TocWidget::on_tocTV_pressed(QModelIndex const & index)
|
2008-05-17 17:03:53 +00:00
|
|
|
{
|
2009-04-08 17:39:14 +00:00
|
|
|
Qt::MouseButtons const button = QApplication::mouseButtons();
|
|
|
|
if (button & Qt::LeftButton) {
|
|
|
|
goTo(index);
|
|
|
|
gui_view_.setFocus();
|
|
|
|
}
|
2008-05-17 17:03:53 +00:00
|
|
|
}
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2008-05-17 17:03:53 +00:00
|
|
|
|
|
|
|
void TocWidget::goTo(QModelIndex const & index)
|
|
|
|
{
|
|
|
|
LYXERR(Debug::GUI, "goto " << index.row()
|
|
|
|
<< ", " << index.column());
|
|
|
|
|
2008-06-17 15:10:03 +00:00
|
|
|
gui_view_.tocModels().goTo(current_type_, index);
|
2006-04-18 09:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-04 17:46:03 +00:00
|
|
|
void TocWidget::on_updateTB_clicked()
|
2006-03-31 13:17:44 +00:00
|
|
|
{
|
2007-05-10 16:25:11 +00:00
|
|
|
// The backend update can take some time so we disable
|
|
|
|
// the controls while waiting.
|
|
|
|
enableControls(false);
|
2008-05-30 11:33:24 +00:00
|
|
|
gui_view_.tocModels().updateBackend();
|
2006-11-17 17:19:43 +00:00
|
|
|
}
|
|
|
|
|
2008-06-12 16:46:46 +00:00
|
|
|
|
2008-09-28 17:14:29 +00:00
|
|
|
void TocWidget::on_sortCB_stateChanged(int state)
|
|
|
|
{
|
|
|
|
gui_view_.tocModels().sort(current_type_, state == Qt::Checked);
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
2009-07-24 13:58:02 +00:00
|
|
|
|
2008-10-02 15:00:43 +00:00
|
|
|
void TocWidget::on_persistentCB_stateChanged(int state)
|
|
|
|
{
|
|
|
|
persistent_ = state == Qt::Checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-17 17:19:43 +00:00
|
|
|
/* FIXME (Ugras 17/11/06):
|
2008-06-12 16:46:46 +00:00
|
|
|
I have implemented a indexDepth function to get the model indices. In my
|
2006-11-17 17:19:43 +00:00
|
|
|
opinion, somebody should derive a new qvariant class for tocModelItem
|
2008-06-12 16:46:46 +00:00
|
|
|
which saves the string data and depth information. That will save the
|
|
|
|
depth calculation. */
|
|
|
|
|
|
|
|
static int indexDepth(QModelIndex const & index, int depth = -1)
|
2006-12-30 21:51:05 +00:00
|
|
|
{
|
2006-11-17 17:19:43 +00:00
|
|
|
++depth;
|
2008-06-12 16:46:46 +00:00
|
|
|
return index.parent() == QModelIndex()
|
|
|
|
? depth : indexDepth(index.parent(), depth);
|
2006-03-31 13:17:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::on_depthSL_valueChanged(int depth)
|
2006-03-31 13:17:44 +00:00
|
|
|
{
|
|
|
|
if (depth == depth_)
|
|
|
|
return;
|
2006-11-25 22:16:22 +00:00
|
|
|
setTreeDepth(depth);
|
2008-05-30 12:13:42 +00:00
|
|
|
gui_view_.setFocus();
|
2006-11-25 22:16:22 +00:00
|
|
|
}
|
|
|
|
|
2006-03-31 13:17:44 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::setTreeDepth(int depth)
|
2006-11-25 22:16:22 +00:00
|
|
|
{
|
2007-03-12 14:23:44 +00:00
|
|
|
depth_ = depth;
|
2008-06-17 15:10:03 +00:00
|
|
|
if (!tocTV->model())
|
|
|
|
return;
|
2006-12-30 10:35:17 +00:00
|
|
|
|
2009-02-10 08:32:34 +00:00
|
|
|
#if QT_VERSION >= 0x040300
|
|
|
|
// this should be faster than our own code below
|
|
|
|
if (depth == 0)
|
|
|
|
tocTV->collapseAll();
|
|
|
|
else
|
|
|
|
tocTV->expandToDepth(depth - 1);
|
|
|
|
#else
|
2007-05-28 22:27:45 +00:00
|
|
|
// expanding and then collapsing is probably better,
|
2006-12-30 10:35:17 +00:00
|
|
|
// but my qt 4.1.2 doesn't have expandAll()..
|
2007-05-28 22:27:45 +00:00
|
|
|
//tocTV->expandAll();
|
2007-03-16 14:14:55 +00:00
|
|
|
QModelIndexList indices = tocTV->model()->match(
|
2008-09-08 01:18:33 +00:00
|
|
|
tocTV->model()->index(0, 0),
|
2007-05-28 22:27:45 +00:00
|
|
|
Qt::DisplayRole, "*", -1,
|
2007-08-19 09:44:34 +00:00
|
|
|
Qt::MatchFlags(Qt::MatchWildcard|Qt::MatchRecursive));
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2006-12-30 10:35:17 +00:00
|
|
|
int size = indices.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
QModelIndex index = indices[i];
|
2008-06-12 16:46:46 +00:00
|
|
|
tocTV->setExpanded(index, indexDepth(index) < depth_);
|
2006-11-17 17:19:43 +00:00
|
|
|
}
|
2009-02-10 08:32:34 +00:00
|
|
|
#endif
|
2006-03-31 13:17:44 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:33:24 +00:00
|
|
|
|
2008-06-17 15:10:03 +00:00
|
|
|
void TocWidget::on_typeCO_currentIndexChanged(int index)
|
2006-03-31 13:17:44 +00:00
|
|
|
{
|
2008-06-17 15:10:03 +00:00
|
|
|
current_type_ = typeCO->itemData(index).toString();
|
2008-06-11 18:13:14 +00:00
|
|
|
updateView();
|
2010-03-08 19:52:48 +00:00
|
|
|
if (typeCO->hasFocus())
|
|
|
|
gui_view_.setFocus();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2010-02-26 19:51:06 +00:00
|
|
|
void TocWidget::outline(FuncCode func_code)
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2007-03-12 14:23:44 +00:00
|
|
|
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
|
2008-05-30 11:59:57 +00:00
|
|
|
if (list.isEmpty())
|
|
|
|
return;
|
|
|
|
enableControls(false);
|
|
|
|
goTo(list[0]);
|
2010-02-26 19:51:06 +00:00
|
|
|
dispatch(FuncRequest(func_code));
|
2008-05-30 11:59:57 +00:00
|
|
|
enableControls(true);
|
2008-05-30 12:13:42 +00:00
|
|
|
gui_view_.setFocus();
|
2008-05-30 11:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TocWidget::on_moveUpTB_clicked()
|
|
|
|
{
|
|
|
|
outline(LFUN_OUTLINE_UP);
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-05-04 17:46:03 +00:00
|
|
|
void TocWidget::on_moveDownTB_clicked()
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2008-05-30 11:59:57 +00:00
|
|
|
outline(LFUN_OUTLINE_DOWN);
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-05-04 17:46:03 +00:00
|
|
|
void TocWidget::on_moveInTB_clicked()
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2008-05-30 11:59:57 +00:00
|
|
|
outline(LFUN_OUTLINE_IN);
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-05-04 17:46:03 +00:00
|
|
|
void TocWidget::on_moveOutTB_clicked()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-05-30 11:59:57 +00:00
|
|
|
outline(LFUN_OUTLINE_OUT);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::select(QModelIndex const & index)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-04-19 14:48:22 +00:00
|
|
|
if (!index.isValid()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "TocWidget::select(): QModelIndex is invalid!");
|
2006-04-19 14:48:22 +00:00
|
|
|
return;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2006-04-19 14:48:22 +00:00
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
tocTV->scrollTo(index);
|
2008-05-17 17:03:53 +00:00
|
|
|
tocTV->clearSelection();
|
|
|
|
tocTV->setCurrentIndex(index);
|
2006-04-18 09:57:47 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
|
2007-04-17 10:27:53 +00:00
|
|
|
void TocWidget::enableControls(bool enable)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2007-05-04 17:46:03 +00:00
|
|
|
updateTB->setEnabled(enable);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2010-02-26 19:48:20 +00:00
|
|
|
if (!canOutline())
|
2006-04-18 09:57:47 +00:00
|
|
|
enable = false;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-05-04 17:46:03 +00:00
|
|
|
moveUpTB->setEnabled(enable);
|
|
|
|
moveDownTB->setEnabled(enable);
|
|
|
|
moveInTB->setEnabled(enable);
|
|
|
|
moveOutTB->setEnabled(enable);
|
2006-04-18 09:57:47 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2007-09-08 17:28:14 +00:00
|
|
|
void TocWidget::updateView()
|
2006-04-22 18:48:28 +00:00
|
|
|
{
|
2009-09-06 13:07:24 +00:00
|
|
|
if (!gui_view_.documentBufferView()) {
|
2008-06-17 15:44:14 +00:00
|
|
|
enableControls(false);
|
|
|
|
typeCO->setEnabled(false);
|
|
|
|
tocTV->setModel(0);
|
|
|
|
tocTV->setEnabled(false);
|
2009-05-01 16:03:06 +00:00
|
|
|
depthSL->setMaximum(0);
|
|
|
|
depthSL->setValue(0);
|
|
|
|
persistentCB->setEnabled(false);
|
|
|
|
sortCB->setEnabled(false);
|
|
|
|
depthSL->setEnabled(false);
|
2008-06-17 15:44:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-02-26 19:48:20 +00:00
|
|
|
bool const is_sortable = isSortable();
|
|
|
|
sortCB->setEnabled(is_sortable);
|
2009-05-01 16:03:06 +00:00
|
|
|
depthSL->setEnabled(true);
|
2008-06-17 15:44:14 +00:00
|
|
|
typeCO->setEnabled(true);
|
2008-09-30 07:18:24 +00:00
|
|
|
tocTV->setEnabled(false);
|
|
|
|
tocTV->setUpdatesEnabled(false);
|
2008-06-17 15:44:14 +00:00
|
|
|
|
2010-03-08 20:48:48 +00:00
|
|
|
QAbstractItemModel * toc_model =
|
|
|
|
gui_view_.tocModels().model(current_type_);
|
2008-06-17 15:44:14 +00:00
|
|
|
if (tocTV->model() != toc_model) {
|
|
|
|
tocTV->setModel(toc_model);
|
|
|
|
tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
2009-01-07 14:49:40 +00:00
|
|
|
if (persistent_)
|
|
|
|
setTreeDepth(depth_);
|
2008-06-17 15:44:14 +00:00
|
|
|
}
|
2008-09-28 17:14:29 +00:00
|
|
|
|
|
|
|
sortCB->blockSignals(true);
|
2010-02-26 19:48:20 +00:00
|
|
|
sortCB->setChecked(is_sortable
|
2009-07-24 13:58:02 +00:00
|
|
|
&& gui_view_.tocModels().isSorted(current_type_));
|
2008-09-28 17:14:29 +00:00
|
|
|
sortCB->blockSignals(false);
|
|
|
|
|
2010-02-26 19:48:20 +00:00
|
|
|
bool const can_navigate_ = canNavigate();
|
2009-05-01 16:03:06 +00:00
|
|
|
persistentCB->setEnabled(can_navigate_);
|
2008-10-02 15:00:43 +00:00
|
|
|
|
2008-06-17 15:44:14 +00:00
|
|
|
bool controls_enabled = toc_model && toc_model->rowCount() > 0
|
2009-09-05 15:09:45 +00:00
|
|
|
&& !gui_view_.documentBufferView()->buffer().isReadonly();
|
2008-06-17 15:44:14 +00:00
|
|
|
enableControls(controls_enabled);
|
2008-09-12 02:11:07 +00:00
|
|
|
|
2008-06-17 15:44:14 +00:00
|
|
|
depthSL->setMaximum(gui_view_.tocModels().depth(current_type_));
|
|
|
|
depthSL->setValue(depth_);
|
2009-05-01 16:03:06 +00:00
|
|
|
if (!persistent_ && can_navigate_)
|
2009-01-07 14:49:40 +00:00
|
|
|
setTreeDepth(depth_);
|
2009-05-01 16:03:06 +00:00
|
|
|
if (can_navigate_) {
|
|
|
|
persistentCB->setChecked(persistent_);
|
2008-06-19 13:35:19 +00:00
|
|
|
select(gui_view_.tocModels().currentIndex(current_type_));
|
2009-05-01 16:03:06 +00:00
|
|
|
}
|
2010-02-13 08:30:16 +00:00
|
|
|
filterContents();
|
2008-09-30 07:18:24 +00:00
|
|
|
tocTV->setEnabled(true);
|
|
|
|
tocTV->setUpdatesEnabled(true);
|
2008-06-17 15:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-13 08:30:16 +00:00
|
|
|
void TocWidget::filterContents()
|
|
|
|
{
|
2010-03-08 12:42:18 +00:00
|
|
|
if (!tocTV->model())
|
|
|
|
return;
|
|
|
|
|
2010-02-13 08:30:16 +00:00
|
|
|
QModelIndexList indices = tocTV->model()->match(
|
|
|
|
tocTV->model()->index(0, 0),
|
|
|
|
Qt::DisplayRole, "*", -1,
|
|
|
|
Qt::MatchFlags(Qt::MatchWildcard|Qt::MatchRecursive));
|
|
|
|
|
|
|
|
int size = indices.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
QModelIndex index = indices[i];
|
|
|
|
bool const matches =
|
|
|
|
index.data().toString().contains(
|
|
|
|
filterLE->text(), Qt::CaseSensitive);
|
|
|
|
tocTV->setRowHidden(index.row(), index.parent(), !matches);
|
|
|
|
}
|
|
|
|
// recursively unhide parents of unhidden children
|
|
|
|
for (int i = size - 1; i >= 0; i--) {
|
|
|
|
QModelIndex index = indices[i];
|
|
|
|
if (!tocTV->isRowHidden(index.row(), index.parent())
|
|
|
|
&& index.parent() != QModelIndex())
|
|
|
|
tocTV->setRowHidden(index.parent().row(),
|
|
|
|
index.parent().parent(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-17 15:10:03 +00:00
|
|
|
static QString decodeType(QString const & str)
|
|
|
|
{
|
|
|
|
QString type = str;
|
|
|
|
if (type.contains("tableofcontents")) {
|
|
|
|
type = "tableofcontents";
|
|
|
|
} else if (type.contains("floatlist")) {
|
|
|
|
if (type.contains("\"figure"))
|
|
|
|
type = "figure";
|
|
|
|
else if (type.contains("\"table"))
|
|
|
|
type = "table";
|
|
|
|
else if (type.contains("\"algorithm"))
|
|
|
|
type = "algorithm";
|
|
|
|
}
|
|
|
|
return type;
|
2006-04-22 18:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-02 12:09:51 +00:00
|
|
|
void TocWidget::init(QString const & str)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2008-06-17 15:10:03 +00:00
|
|
|
int new_index;
|
|
|
|
if (str.isEmpty())
|
|
|
|
new_index = typeCO->findData(current_type_);
|
|
|
|
else
|
|
|
|
new_index = typeCO->findData(decodeType(str));
|
|
|
|
|
|
|
|
// If everything else fails, settle on the table of contents which is
|
|
|
|
// guaranted to exist.
|
|
|
|
if (new_index == -1) {
|
|
|
|
current_type_ = "tableofcontents";
|
|
|
|
new_index = typeCO->findData(current_type_);
|
2008-10-28 06:46:27 +00:00
|
|
|
} else {
|
|
|
|
current_type_ = typeCO->itemData(new_index).toString();
|
2008-02-12 15:33:01 +00:00
|
|
|
}
|
|
|
|
|
2008-06-17 15:49:14 +00:00
|
|
|
typeCO->blockSignals(true);
|
2008-06-17 15:10:03 +00:00
|
|
|
typeCO->setCurrentIndex(new_index);
|
2007-05-10 16:25:11 +00:00
|
|
|
typeCO->blockSignals(false);
|
2007-03-16 14:14:55 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_TocWidget.cpp"
|