2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file QTocDialog.C
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include "QTocDialog.h"
|
|
|
|
#include "QToc.h"
|
2006-04-11 09:56:56 +00:00
|
|
|
#include "Qt2BC.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "controllers/ControlToc.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QCloseEvent>
|
2006-04-18 09:57:47 +00:00
|
|
|
#include <QHeaderView>
|
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 {
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
QTocDialog::QTocDialog(Dialog & dialog, QToc * form)
|
2006-10-09 10:35:14 +00:00
|
|
|
: Dialog::View(dialog, _("Toc")), form_(form), depth_(2)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
updateGui();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QTocDialog::~QTocDialog()
|
|
|
|
{
|
2006-03-31 13:17:44 +00:00
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
2006-04-19 14:48:22 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QTocDialog::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-31 13:17:44 +00:00
|
|
|
void QTocDialog::on_closePB_clicked()
|
|
|
|
{
|
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2006-03-31 13:17:44 +00:00
|
|
|
void QTocDialog::on_updatePB_clicked()
|
|
|
|
{
|
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.
|
|
|
|
*/
|
|
|
|
int QTocDialog::getIndexDepth(QModelIndex const & index, int depth){
|
|
|
|
++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
|
|
|
|
2006-04-05 23:56:29 +00:00
|
|
|
void QTocDialog::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
|
|
|
|
2006-11-25 22:16:22 +00:00
|
|
|
void QTocDialog::setTreeDepth(int depth)
|
|
|
|
{
|
|
|
|
if(depth!=-1)
|
|
|
|
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
|
|
|
|
2006-03-31 13:17:44 +00:00
|
|
|
void QTocDialog::on_typeCO_activated(int value)
|
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
form_->setTocModel(value);
|
2006-11-10 13:13:10 +00:00
|
|
|
tocTV->setModel(form_->tocModel());
|
2006-11-16 12:37:55 +00:00
|
|
|
reconnectSelectionModel();
|
2006-04-18 09:57:47 +00:00
|
|
|
enableButtons();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2006-03-29 16:57:47 +00:00
|
|
|
void QTocDialog::on_moveUpPB_clicked()
|
|
|
|
{
|
2006-04-28 09:16:48 +00:00
|
|
|
enableButtons(false);
|
|
|
|
QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
|
|
|
|
form_->goTo(index);
|
|
|
|
form_->outlineUp();
|
|
|
|
update();
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2006-03-29 16:57:47 +00:00
|
|
|
void QTocDialog::on_moveDownPB_clicked()
|
|
|
|
{
|
2006-04-28 09:16:48 +00:00
|
|
|
enableButtons(false);
|
|
|
|
QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
|
|
|
|
form_->goTo(index);
|
|
|
|
form_->outlineDown();
|
|
|
|
update();
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2006-03-29 16:57:47 +00:00
|
|
|
void QTocDialog::on_moveInPB_clicked()
|
|
|
|
{
|
2006-04-28 09:16:48 +00:00
|
|
|
enableButtons(false);
|
|
|
|
QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
|
|
|
|
form_->goTo(index);
|
|
|
|
form_->outlineIn();
|
|
|
|
update();
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2006-03-29 16:57:47 +00:00
|
|
|
void QTocDialog::on_moveOutPB_clicked()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
enableButtons(false);
|
|
|
|
QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
|
2006-04-19 14:48:22 +00:00
|
|
|
form_->goTo(index);
|
2006-04-28 09:16:48 +00:00
|
|
|
form_->outlineOut();
|
|
|
|
update();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QTocDialog::select(QModelIndex const & index)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-04-22 18:48:28 +00:00
|
|
|
// tocTV->setModel(form_->tocModel());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-19 14:48:22 +00:00
|
|
|
if (!index.isValid()) {
|
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "QTocDialog::select(): QModelIndex is invalid!" << endl;
|
|
|
|
return;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2006-04-19 14:48:22 +00:00
|
|
|
|
|
|
|
tocTV->scrollTo(index);
|
|
|
|
tocTV->selectionModel()->select(index, QItemSelectionModel::Select);
|
2006-04-18 09:57:47 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QTocDialog::enableButtons(bool enable)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QTocDialog::update()
|
2006-04-22 18:48:28 +00:00
|
|
|
{
|
2006-11-16 12:37:55 +00:00
|
|
|
form_->updateToc();
|
2006-04-22 18:48:28 +00:00
|
|
|
updateGui();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QTocDialog::updateGui()
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2006-10-16 08:51:55 +00:00
|
|
|
QStringListModel * type_model = form_->typeModel();
|
|
|
|
if (type_model->stringList().isEmpty())
|
|
|
|
{
|
|
|
|
enableButtons();
|
2006-10-19 14:35:06 +00:00
|
|
|
typeCO->setModel(type_model);
|
|
|
|
tocTV->setModel(new QStandardItemModel);
|
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
|
|
|
|
|
|
|
if (form_->tocModel())
|
|
|
|
tocTV->setModel(form_->tocModel());
|
2006-04-18 09:57:47 +00:00
|
|
|
tocTV->showColumn(0);
|
|
|
|
// hide the pointless QHeader for now
|
2006-07-06 08:18:51 +00:00
|
|
|
// in the future, new columns may appear
|
2006-04-18 09:57:47 +00:00
|
|
|
// like labels, bookmarks, etc...
|
|
|
|
// tocTV->header()->hide();
|
2006-11-10 13:13:10 +00:00
|
|
|
tocTV->header()->setVisible(false);
|
2006-04-18 09:57:47 +00:00
|
|
|
enableButtons();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-11-16 12:37:55 +00:00
|
|
|
reconnectSelectionModel();
|
2006-11-25 22:16:22 +00:00
|
|
|
depthSL->setMaximum(form_->getTocDepth());
|
|
|
|
setTreeDepth();
|
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;
|
|
|
|
// setTitle(form_->guiname())
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2006-11-16 12:37:55 +00:00
|
|
|
void QTocDialog::reconnectSelectionModel()
|
|
|
|
{
|
|
|
|
connect(tocTV->selectionModel(),
|
|
|
|
SIGNAL(currentChanged(const QModelIndex &,
|
|
|
|
const QModelIndex &)),
|
|
|
|
this, SLOT(selectionChanged(const QModelIndex &,
|
|
|
|
const QModelIndex &)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QTocDialog::apply()
|
|
|
|
{
|
|
|
|
// Nothing to do here... for now.
|
|
|
|
// Ideas welcome... (Abdel, 17042006)
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QTocDialog::hide()
|
|
|
|
{
|
|
|
|
accept();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
|
|
|
void QTocDialog::show()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-11-16 12:37:55 +00:00
|
|
|
form_->update();
|
2006-04-18 09:57:47 +00:00
|
|
|
QDialog::show();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
bool QTocDialog::isVisible() const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
return QDialog::isVisible();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
|
|
#include "QTocDialog_moc.cpp"
|