2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-03-12 14:23:44 +00:00
|
|
|
* \file TocWidget.C
|
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"
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "QToc.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
#include <QHeaderView>
|
2007-03-12 14:23:44 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QTreeWidgetItem>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <stack>
|
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
using std::pair;
|
|
|
|
using std::stack;
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
|
2007-03-12 15:45:08 +00:00
|
|
|
TocWidget::TocWidget(QToc * form, QWidget * parent)
|
2007-03-12 14:23:44 +00:00
|
|
|
: QWidget(parent), form_(form), depth_(0)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
connect(form, SIGNAL(modelReset()),
|
|
|
|
SLOT(updateGui()));
|
2006-03-05 17:24:44 +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);
|
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
|
|
|
{
|
|
|
|
lyxerr[Debug::GUI]
|
2006-07-06 08:18:51 +00:00
|
|
|
<< "selectionChanged index " << current.row()
|
|
|
|
<< ", " << current.column()
|
2006-04-18 09:57:47 +00:00
|
|
|
<< endl;
|
|
|
|
|
|
|
|
form_->goTo(current);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::on_updatePB_clicked()
|
2006-03-31 13:17:44 +00:00
|
|
|
{
|
2007-03-12 14:23:44 +00:00
|
|
|
form_->updateBackend();
|
|
|
|
form_->update();
|
2006-11-17 17:19:43 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
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
|
|
|
|
|
|
|
// expanding and then collapsing is probably better,
|
|
|
|
// but my qt 4.1.2 doesn't have expandAll()..
|
|
|
|
//tocTV->expandAll();
|
2006-11-17 17:19:43 +00:00
|
|
|
QModelIndexList indices =
|
|
|
|
form_->tocModel()->match(form_->tocModel()->index(0,0),
|
|
|
|
Qt::DisplayRole, "*", -1,
|
|
|
|
Qt::MatchWildcard|Qt::MatchRecursive);
|
2006-12-30 10:35:17 +00:00
|
|
|
|
|
|
|
int size = indices.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
QModelIndex index = indices[i];
|
|
|
|
if (getIndexDepth(index) < depth_)
|
|
|
|
tocTV->expand(index);
|
2006-11-17 17:19:43 +00:00
|
|
|
else
|
2006-12-30 10:35:17 +00:00
|
|
|
tocTV->collapse(index);
|
2006-11-17 17:19:43 +00:00
|
|
|
}
|
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_typeCO_activated(int value)
|
2006-03-31 13:17:44 +00:00
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
form_->setTocModel(value);
|
2007-03-12 14:23:44 +00:00
|
|
|
updateGui();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::on_moveUpPB_clicked()
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2006-04-28 09:16:48 +00:00
|
|
|
enableButtons(false);
|
2007-03-12 14:23:44 +00:00
|
|
|
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
enableButtons(false);
|
|
|
|
form_->goTo(list[0]);
|
|
|
|
form_->outlineUp();
|
|
|
|
enableButtons(true);
|
|
|
|
}
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::on_moveDownPB_clicked()
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2006-04-28 09:16:48 +00:00
|
|
|
enableButtons(false);
|
2007-03-12 14:23:44 +00:00
|
|
|
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
enableButtons(false);
|
|
|
|
form_->goTo(list[0]);
|
|
|
|
form_->outlineDown();
|
|
|
|
enableButtons(true);
|
|
|
|
}
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::on_moveInPB_clicked()
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2006-04-28 09:16:48 +00:00
|
|
|
enableButtons(false);
|
2007-03-12 14:23:44 +00:00
|
|
|
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
enableButtons(false);
|
|
|
|
form_->goTo(list[0]);
|
|
|
|
form_->outlineIn();
|
|
|
|
enableButtons(true);
|
|
|
|
}
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::on_moveOutPB_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()) {
|
|
|
|
enableButtons(false);
|
|
|
|
form_->goTo(list[0]);
|
|
|
|
form_->outlineOut();
|
|
|
|
enableButtons(true);
|
|
|
|
}
|
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()) {
|
|
|
|
lyxerr[Debug::GUI]
|
2007-03-12 14:23:44 +00:00
|
|
|
<< "TocWidget::select(): QModelIndex is invalid!" << endl;
|
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-03-12 14:23:44 +00:00
|
|
|
tocTV->selectionModel()->blockSignals(true);
|
2006-04-19 14:48:22 +00:00
|
|
|
tocTV->scrollTo(index);
|
2007-03-12 14:23:44 +00:00
|
|
|
tocTV->selectionModel()->setCurrentIndex(index,
|
|
|
|
QItemSelectionModel::ClearAndSelect);
|
|
|
|
tocTV->selectionModel()->blockSignals(false);
|
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-03-12 14:23:44 +00:00
|
|
|
void TocWidget::enableButtons(bool enable)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
|
|
|
updatePB->setEnabled(enable);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
if (!form_->canOutline())
|
|
|
|
enable = false;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
moveUpPB->setEnabled(enable);
|
|
|
|
moveDownPB->setEnabled(enable);
|
|
|
|
moveInPB->setEnabled(enable);
|
|
|
|
moveOutPB->setEnabled(enable);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::update()
|
2006-04-22 18:48:28 +00:00
|
|
|
{
|
2007-03-12 14:23:44 +00:00
|
|
|
select(form_->getCurrentIndex());
|
|
|
|
QWidget::update();
|
2006-04-22 18:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
void TocWidget::updateGui()
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2006-10-16 08:51:55 +00:00
|
|
|
QStringListModel * type_model = form_->typeModel();
|
2007-01-04 19:52:41 +00:00
|
|
|
if (type_model->stringList().isEmpty()) {
|
2007-03-12 14:23:44 +00:00
|
|
|
enableButtons(false);
|
2006-10-19 14:35:06 +00:00
|
|
|
typeCO->setModel(type_model);
|
|
|
|
tocTV->setModel(new QStandardItemModel);
|
2006-12-30 21:51:05 +00:00
|
|
|
tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
2007-01-07 16:39:35 +00:00
|
|
|
depthSL->setEnabled(false);
|
2006-10-16 08:51:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
typeCO->setModel(type_model);
|
2006-11-16 12:37:55 +00:00
|
|
|
typeCO->setCurrentIndex(form_->getType());
|
2006-10-16 08:51:55 +00:00
|
|
|
|
2007-03-12 14:23:44 +00:00
|
|
|
bool buttons_enabled = false;
|
2007-01-04 19:52:41 +00:00
|
|
|
if (form_->tocModel()) {
|
2007-03-12 14:23:44 +00:00
|
|
|
buttons_enabled = form_->tocModel()->rowCount() > 0;
|
2006-10-16 08:51:55 +00:00
|
|
|
tocTV->setModel(form_->tocModel());
|
2006-12-30 21:51:05 +00:00
|
|
|
tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
}
|
2007-03-12 14:23:44 +00:00
|
|
|
|
|
|
|
enableButtons(buttons_enabled);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-11-16 12:37:55 +00:00
|
|
|
reconnectSelectionModel();
|
2007-01-07 16:39:35 +00:00
|
|
|
depthSL->setEnabled(true);
|
2006-11-25 22:16:22 +00:00
|
|
|
depthSL->setMaximum(form_->getTocDepth());
|
2007-03-12 14:23:44 +00:00
|
|
|
depthSL->setValue(depth_);
|
2006-04-19 14:48:22 +00:00
|
|
|
select(form_->getCurrentIndex());
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "form_->tocModel()->rowCount " << form_->tocModel()->rowCount()
|
|
|
|
<< "\nform_->tocModel()->columnCount " << form_->tocModel()->columnCount()
|
|
|
|
<< endl;
|
|
|
|
}
|
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(),
|
|
|
|
SIGNAL(currentChanged(const QModelIndex &,
|
|
|
|
const QModelIndex &)),
|
|
|
|
this, SLOT(selectionChanged(const QModelIndex &,
|
|
|
|
const QModelIndex &)));
|
|
|
|
}
|
|
|
|
|
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"
|