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>
|
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)
|
2016-04-29 21:48:53 +00:00
|
|
|
: QWidget(parent), depth_(0), persistent_(false), gui_view_(gui_view),
|
|
|
|
update_timer_short_(new QTimer(this)),
|
|
|
|
update_timer_long_(new QTimer(this))
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2015-03-28 22:18:22 +00:00
|
|
|
moveOutTB->setIcon(QIcon(getPixmap("images/", "outline-out", "svgz,png")));
|
|
|
|
moveInTB->setIcon(QIcon(getPixmap("images/", "outline-in", "svgz,png")));
|
|
|
|
moveUpTB->setIcon(QIcon(getPixmap("images/", "outline-up", "svgz,png")));
|
|
|
|
moveDownTB->setIcon(QIcon(getPixmap("images/", "outline-down", "svgz,png")));
|
2015-03-12 23:47:21 +00:00
|
|
|
updateTB->setIcon(QIcon(getPixmap("images/", "reload", "svgz,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);
|
2010-04-26 10:03:09 +00:00
|
|
|
setFocusProxy(tocTV);
|
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 &)));
|
2016-04-29 21:29:27 +00:00
|
|
|
connect(filterLE, SIGNAL(textEdited(QString)),
|
2010-02-13 08:30:16 +00:00
|
|
|
this, SLOT(filterContents()));
|
2009-04-08 21:06:58 +00:00
|
|
|
|
2016-04-29 21:48:53 +00:00
|
|
|
// setting the update timer
|
|
|
|
update_timer_short_->setSingleShot(true);
|
|
|
|
update_timer_long_->setSingleShot(true);
|
|
|
|
update_timer_short_->setInterval(0);
|
|
|
|
update_timer_long_->setInterval(2000);
|
|
|
|
connect(update_timer_short_, SIGNAL(timeout()),
|
|
|
|
this, SLOT(realUpdateView()));
|
|
|
|
connect(update_timer_long_, SIGNAL(timeout()),
|
|
|
|
this, SLOT(realUpdateView()));
|
|
|
|
|
2016-05-08 22:56:55 +00:00
|
|
|
// fix #9826: Outline disclosure of subsection content disappears one second
|
|
|
|
// after doubleclicking content item.
|
|
|
|
// This is only meant as a workaround. See #6675 for more general issues
|
|
|
|
// regarding unwanted collapse of the tree view.
|
|
|
|
connect(tocTV, SIGNAL(expanded(const QModelIndex &)),
|
|
|
|
update_timer_long_, SLOT(stop()));
|
|
|
|
|
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)
|
2016-04-29 21:29:27 +00:00
|
|
|
return;
|
2009-04-08 21:06:58 +00:00
|
|
|
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();
|
2016-04-29 21:29:27 +00:00
|
|
|
|
2009-04-09 18:51:07 +00:00
|
|
|
Inset * inset = 0;
|
2016-04-29 21:29:27 +00:00
|
|
|
if (current_type_ == "label"
|
2009-04-10 00:42:24 +00:00
|
|
|
|| 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"
|
2015-09-27 06:05:00 +00:00
|
|
|
|| current_type_ == "change"
|
2016-04-29 21:29:27 +00:00
|
|
|
|| current_type_ == "table"
|
2015-09-27 06:05:00 +00:00
|
|
|
|| current_type_ == "listing"
|
|
|
|
|| current_type_ == "figure")
|
2009-04-10 00:42:24 +00:00
|
|
|
inset = &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:
|
2013-11-04 21:07:44 +00:00
|
|
|
status.setEnabled(item.dit() != 0);
|
2009-05-01 17:55:26 +00:00
|
|
|
return true;
|
|
|
|
|
2014-02-11 10:00:20 +00:00
|
|
|
case LFUN_LABEL_COPY_AS_REFERENCE: {
|
2009-05-20 23:58:29 +00:00
|
|
|
// For labels in math, we need to supply the label as a string
|
2015-09-27 06:05:00 +00:00
|
|
|
FuncRequest label_copy(LFUN_LABEL_COPY_AS_REFERENCE, item.str());
|
2009-05-20 23:58:29 +00:00
|
|
|
if (inset)
|
|
|
|
return inset->getStatus(cur, label_copy, status);
|
2015-09-12 18:02:32 +00:00
|
|
|
break;
|
2009-05-20 23:58:29 +00:00
|
|
|
}
|
|
|
|
|
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:
|
2014-03-21 09:21:18 +00:00
|
|
|
dispatch(item.action());
|
|
|
|
cur.dispatch(tmpcmd);
|
|
|
|
break;
|
|
|
|
|
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);
|
2014-03-21 09:21:18 +00:00
|
|
|
// necessary to get the selection drawn.
|
|
|
|
cur.buffer()->changed(true);
|
2014-03-21 23:34:46 +00:00
|
|
|
gui_view_.setFocus();
|
2009-05-01 17:55:26 +00:00
|
|
|
break;
|
2009-05-20 23:58:29 +00:00
|
|
|
|
2014-02-11 10:00:20 +00:00
|
|
|
case LFUN_LABEL_COPY_AS_REFERENCE: {
|
2009-05-20 23:58:29 +00:00
|
|
|
// For labels in math, we need to supply the label as a string
|
2015-09-27 06:05:00 +00:00
|
|
|
FuncRequest label_copy(LFUN_LABEL_COPY_AS_REFERENCE, item.str());
|
2009-05-20 23:58:29 +00:00
|
|
|
if (inset)
|
|
|
|
inset->dispatch(cur, label_copy);
|
|
|
|
break;
|
|
|
|
}
|
2014-02-11 10:00:20 +00:00
|
|
|
|
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();
|
2016-05-30 21:11:27 +00:00
|
|
|
gui_view_.activateWindow();
|
2009-04-08 17:39:14 +00:00
|
|
|
}
|
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);
|
2011-08-08 18:29:52 +00:00
|
|
|
gui_view_.currentBufferView()->buffer().updateBuffer();
|
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);
|
2016-04-29 21:48:53 +00:00
|
|
|
updateViewNow();
|
2008-09-28 17:14:29 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-02 14:38:25 +00:00
|
|
|
#if 0
|
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
|
|
|
}
|
2013-05-02 14:38:25 +00:00
|
|
|
#endif
|
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 (depth == 0)
|
|
|
|
tocTV->collapseAll();
|
|
|
|
else
|
|
|
|
tocTV->expandToDepth(depth - 1);
|
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
|
|
|
{
|
2010-06-01 09:56:07 +00:00
|
|
|
if (index == -1)
|
|
|
|
return;
|
2008-06-17 15:10:03 +00:00
|
|
|
current_type_ = typeCO->itemData(index).toString();
|
2016-04-29 21:48:53 +00:00
|
|
|
updateViewNow();
|
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
|
|
|
{
|
2010-12-26 23:23:48 +00:00
|
|
|
// Subtler optimization for having the delay more UI invisible.
|
|
|
|
// We trigger update immediately for sparse editation actions,
|
|
|
|
// i.e. there was no editation/cursor movement in last 2 sec.
|
|
|
|
// At worst there will be +1 redraw after 2s in a such "calm" mode.
|
2016-04-29 21:48:53 +00:00
|
|
|
if (!update_timer_long_->isActive())
|
|
|
|
update_timer_short_->start();
|
|
|
|
// resets the timer to trigger after 2s
|
|
|
|
update_timer_long_->start();
|
2010-12-19 22:27:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 22:56:55 +00:00
|
|
|
|
2016-04-29 21:48:53 +00:00
|
|
|
void TocWidget::updateViewNow()
|
|
|
|
{
|
|
|
|
update_timer_long_->stop();
|
|
|
|
update_timer_short_->start();
|
|
|
|
}
|
|
|
|
|
2016-05-08 22:56:55 +00:00
|
|
|
|
2016-04-29 21:48:53 +00:00
|
|
|
void TocWidget::realUpdateView()
|
2010-12-19 22:27:21 +00:00
|
|
|
{
|
2009-09-06 13:07:24 +00:00
|
|
|
if (!gui_view_.documentBufferView()) {
|
2008-06-17 15:44:14 +00:00
|
|
|
tocTV->setModel(0);
|
2009-05-01 16:03:06 +00:00
|
|
|
depthSL->setMaximum(0);
|
|
|
|
depthSL->setValue(0);
|
2010-04-30 15:56:54 +00:00
|
|
|
setEnabled(false);
|
2008-06-17 15:44:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-04-30 15:56:54 +00:00
|
|
|
setEnabled(true);
|
2010-02-26 19:48:20 +00:00
|
|
|
bool const is_sortable = isSortable();
|
|
|
|
sortCB->setEnabled(is_sortable);
|
2010-04-26 10:03:09 +00:00
|
|
|
bool focus_ = tocTV->hasFocus();
|
2008-09-30 07:18:24 +00:00
|
|
|
tocTV->setEnabled(false);
|
|
|
|
tocTV->setUpdatesEnabled(false);
|
2008-06-17 15:44:14 +00:00
|
|
|
|
2016-04-29 21:29:27 +00:00
|
|
|
QAbstractItemModel * toc_model =
|
2010-03-08 20:48:48 +00:00
|
|
|
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);
|
2010-04-26 10:03:09 +00:00
|
|
|
if (focus_)
|
|
|
|
tocTV->setFocus();
|
2008-06-17 15:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-29 23:25:46 +00:00
|
|
|
void TocWidget::checkModelChanged()
|
|
|
|
{
|
|
|
|
if (!gui_view_.documentBufferView() ||
|
|
|
|
gui_view_.tocModels().model(current_type_) != tocTV->model())
|
2016-04-29 21:48:53 +00:00
|
|
|
realUpdateView();
|
2016-04-29 23:25:46 +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(
|
2010-04-19 16:05:40 +00:00
|
|
|
filterLE->text(), Qt::CaseInsensitive);
|
2010-02-13 08:30:16 +00:00
|
|
|
tocTV->setRowHidden(index.row(), index.parent(), !matches);
|
|
|
|
}
|
2016-04-29 21:29:27 +00:00
|
|
|
// recursively unhide parents of unhidden children
|
2010-02-13 08:30:16 +00:00
|
|
|
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;
|
2012-04-16 19:40:59 +00:00
|
|
|
if (type.contains("tableofcontents"))
|
2008-06-17 15:10:03 +00:00
|
|
|
type = "tableofcontents";
|
2012-04-16 19:40:59 +00:00
|
|
|
else if (type.contains("lstlistoflistings"))
|
|
|
|
type = "listing";
|
|
|
|
else if (type.contains("floatlist")) {
|
2008-06-17 15:10:03 +00:00
|
|
|
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
|
2010-11-25 16:53:56 +00:00
|
|
|
// guaranteed to exist.
|
2008-06-17 15:10:03 +00:00
|
|
|
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"
|