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"
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiToc.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
#include <QHeaderView>
|
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
|
|
|
|
2007-09-08 17:28:14 +00:00
|
|
|
TocWidget::TocWidget(GuiToc & form, QWidget * parent)
|
|
|
|
: QWidget(parent), depth_(0), form_(form)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2007-10-17 18:28:45 +00:00
|
|
|
moveOutTB->setIcon(QIcon(":/images/promote.png"));
|
|
|
|
moveInTB->setIcon(QIcon(":/images/demote.png"));
|
|
|
|
moveUpTB->setIcon(QIcon(":/images/up.png"));
|
|
|
|
moveDownTB->setIcon(QIcon(":/images/down.png"));
|
|
|
|
updateTB->setIcon(QIcon(":/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);
|
2006-03-31 13:17:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-19 14:48:22 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::selectionChanged(const QModelIndex & current,
|
2006-07-06 08:18:51 +00:00
|
|
|
const QModelIndex & /*previous*/)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "selectionChanged index " << current.row()
|
|
|
|
<< ", " << current.column());
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-09-08 17:28:14 +00:00
|
|
|
form_.goTo(typeCO->currentIndex(), current);
|
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);
|
2007-09-08 17:28:14 +00:00
|
|
|
form_.updateBackend();
|
2006-11-17 17:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME (Ugras 17/11/06):
|
|
|
|
I have implemented a getIndexDepth function to get the model indices. In my
|
|
|
|
opinion, somebody should derive a new qvariant class for tocModelItem
|
|
|
|
which saves the string data and depth information. that will save the
|
|
|
|
depth calculation.
|
|
|
|
*/
|
2007-03-12 14:23:44 +00:00
|
|
|
int TocWidget::getIndexDepth(QModelIndex const & index, int depth)
|
2006-12-30 21:51:05 +00:00
|
|
|
{
|
2006-11-17 17:19:43 +00:00
|
|
|
++depth;
|
2007-09-05 20:33:29 +00:00
|
|
|
return (index.parent() == QModelIndex())
|
|
|
|
? depth : getIndexDepth(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);
|
|
|
|
}
|
|
|
|
|
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;
|
2006-12-30 10:35:17 +00:00
|
|
|
|
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(
|
|
|
|
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];
|
2007-05-28 22:27:45 +00:00
|
|
|
if (getIndexDepth(index) < depth_)
|
|
|
|
tocTV->expand(index);
|
2006-11-17 17:19:43 +00:00
|
|
|
else
|
2007-05-28 22:27:45 +00:00
|
|
|
tocTV->collapse(index);
|
2006-11-17 17:19:43 +00:00
|
|
|
}
|
2006-03-31 13:17:44 +00:00
|
|
|
}
|
|
|
|
|
2007-05-10 16:25:11 +00:00
|
|
|
void TocWidget::on_typeCO_currentIndexChanged(int value)
|
2006-03-31 13:17:44 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
setTocModel(value);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-05-04 17:46:03 +00:00
|
|
|
void TocWidget::on_moveUpTB_clicked()
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(false);
|
2007-03-12 14:23:44 +00:00
|
|
|
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
|
|
|
|
if (!list.isEmpty()) {
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(false);
|
2007-09-08 17:28:14 +00:00
|
|
|
form_.goTo(typeCO->currentIndex(), list[0]);
|
|
|
|
form_.outlineUp();
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(true);
|
2007-03-12 14:23:44 +00:00
|
|
|
}
|
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
|
|
|
{
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(false);
|
2007-03-12 14:23:44 +00:00
|
|
|
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
|
|
|
|
if (!list.isEmpty()) {
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(false);
|
2007-09-08 17:28:14 +00:00
|
|
|
form_.goTo(typeCO->currentIndex(), list[0]);
|
|
|
|
form_.outlineDown();
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(true);
|
2007-03-12 14:23:44 +00:00
|
|
|
}
|
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
|
|
|
{
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(false);
|
2007-03-12 14:23:44 +00:00
|
|
|
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
|
|
|
|
if (!list.isEmpty()) {
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(false);
|
2007-09-08 17:28:14 +00:00
|
|
|
form_.goTo(typeCO->currentIndex(), list[0]);
|
|
|
|
form_.outlineIn();
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(true);
|
2007-03-12 14:23:44 +00:00
|
|
|
}
|
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
|
|
|
{
|
2007-03-12 14:23:44 +00:00
|
|
|
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
|
|
|
|
if (!list.isEmpty()) {
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(false);
|
2007-09-08 17:28:14 +00:00
|
|
|
form_.goTo(typeCO->currentIndex(), list[0]);
|
|
|
|
form_.outlineOut();
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(true);
|
2007-03-12 14:23:44 +00:00
|
|
|
}
|
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-15 11:26:24 +00:00
|
|
|
disconnectSelectionModel();
|
|
|
|
tocTV->setCurrentIndex(index);
|
2007-05-28 22:27:45 +00:00
|
|
|
tocTV->scrollTo(index);
|
2007-05-15 11:26:24 +00:00
|
|
|
reconnectSelectionModel();
|
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
|
|
|
|
2007-09-08 17:28:14 +00:00
|
|
|
if (!form_.canOutline(typeCO->currentIndex()))
|
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);
|
2007-04-17 10:27:53 +00:00
|
|
|
|
|
|
|
depthSL->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
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "In TocWidget::updateView()");
|
2007-10-06 20:35:44 +00:00
|
|
|
select(form_.currentIndex(typeCO->currentIndex()));
|
2006-04-22 18:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-12 07:47:16 +00:00
|
|
|
void TocWidget::updateGui(int selected_type)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
vector<docstring> const & type_names = form_.typeNames();
|
2007-05-10 16:25:11 +00:00
|
|
|
if (type_names.empty()) {
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(false);
|
2007-05-10 16:25:11 +00:00
|
|
|
typeCO->clear();
|
2006-10-19 14:35:06 +00:00
|
|
|
tocTV->setModel(new QStandardItemModel);
|
2006-12-30 21:51:05 +00:00
|
|
|
tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
2006-10-16 08:51:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
QString current_text = typeCO->currentText();
|
2007-05-10 16:25:11 +00:00
|
|
|
typeCO->blockSignals(true);
|
2007-05-11 14:05:43 +00:00
|
|
|
typeCO->clear();
|
2007-05-10 16:25:11 +00:00
|
|
|
for (size_t i = 0; i != type_names.size(); ++i) {
|
2007-06-04 13:27:27 +00:00
|
|
|
QString item = toqstr(type_names[i]);
|
2007-05-10 16:25:11 +00:00
|
|
|
typeCO->addItem(item);
|
|
|
|
}
|
2008-02-12 07:47:16 +00:00
|
|
|
typeCO->setCurrentIndex(selected_type);
|
2007-05-10 16:25:11 +00:00
|
|
|
typeCO->blockSignals(false);
|
2006-10-16 08:51:55 +00:00
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
setTocModel(typeCO->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TocWidget::setTocModel(size_t type)
|
|
|
|
{
|
2007-04-17 10:27:53 +00:00
|
|
|
bool controls_enabled = false;
|
2007-09-08 17:28:14 +00:00
|
|
|
QStandardItemModel * toc_model = form_.tocModel(type);
|
2007-03-16 14:14:55 +00:00
|
|
|
if (toc_model) {
|
2007-04-17 10:27:53 +00:00
|
|
|
controls_enabled = toc_model->rowCount() > 0;
|
2007-03-16 14:14:55 +00:00
|
|
|
tocTV->setModel(toc_model);
|
2006-12-30 21:51:05 +00:00
|
|
|
tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
}
|
2007-03-12 14:23:44 +00:00
|
|
|
|
2007-04-17 10:27:53 +00:00
|
|
|
enableControls(controls_enabled);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-11-16 12:37:55 +00:00
|
|
|
reconnectSelectionModel();
|
2007-04-17 10:27:53 +00:00
|
|
|
|
|
|
|
if (controls_enabled) {
|
2007-09-08 17:28:14 +00:00
|
|
|
depthSL->setMaximum(form_.getTocDepth(type));
|
2007-04-17 10:27:53 +00:00
|
|
|
depthSL->setValue(depth_);
|
|
|
|
}
|
2006-04-19 14:48:22 +00:00
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "In TocWidget::updateGui()");
|
2007-03-16 14:14:55 +00:00
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
select(form_.currentIndex(typeCO->currentIndex()));
|
2007-03-16 14:14:55 +00:00
|
|
|
|
|
|
|
if (toc_model) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "tocModel()->rowCount "
|
2007-03-16 14:14:55 +00:00
|
|
|
<< toc_model->rowCount()
|
|
|
|
<< "\nform_->tocModel()->columnCount "
|
2007-11-15 20:04:51 +00:00
|
|
|
<< toc_model->columnCount());
|
2007-03-16 14:14:55 +00:00
|
|
|
}
|
2006-04-18 09:57:47 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::reconnectSelectionModel()
|
2006-11-16 12:37:55 +00:00
|
|
|
{
|
|
|
|
connect(tocTV->selectionModel(),
|
2007-05-15 11:26:24 +00:00
|
|
|
SIGNAL(currentChanged(const QModelIndex &,
|
|
|
|
const QModelIndex &)),
|
|
|
|
this,
|
|
|
|
SLOT(selectionChanged(const QModelIndex &,
|
|
|
|
const QModelIndex &)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TocWidget::disconnectSelectionModel()
|
|
|
|
{
|
|
|
|
disconnect(tocTV->selectionModel(),
|
2007-10-06 20:54:31 +00:00
|
|
|
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
|
|
|
this, SLOT(selectionChanged(QModelIndex, QModelIndex)));
|
2006-11-16 12:37:55 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
#include "TocWidget_moc.cpp"
|