3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
14 #include "QTocDialog.h"
17 #include "qt_helpers.h"
18 #include "controllers/ControlToc.h"
22 #include <QTreeWidgetItem>
23 #include <QPushButton>
24 #include <QCloseEvent>
25 #include <QHeaderView>
41 QTocDialog::QTocDialog(Dialog & dialog, QToc * form)
42 : Dialog::View(dialog, _("Toc")), form_(form), depth_(2)
48 connect(tocTV->selectionModel(),
49 SIGNAL(currentChanged(const QModelIndex &,
50 const QModelIndex &)),
51 this, SLOT(selectionChanged(const QModelIndex &,
52 const QModelIndex &)));
56 QTocDialog::~QTocDialog()
62 void QTocDialog::selectionChanged(const QModelIndex & current,
63 const QModelIndex & /*previous*/)
66 << "selectionChanged index " << current.row()
67 << ", " << current.column()
74 void QTocDialog::on_closePB_clicked()
80 void QTocDialog::on_updatePB_clicked()
85 /* FIXME (Ugras 17/11/06):
86 I have implemented a getIndexDepth function to get the model indices. In my
87 opinion, somebody should derive a new qvariant class for tocModelItem
88 which saves the string data and depth information. that will save the
91 int QTocDialog::getIndexDepth(QModelIndex const & index, int depth)
94 return (index.parent() == QModelIndex())? depth : getIndexDepth(index.parent(),depth);
98 void QTocDialog::on_depthSL_valueChanged(int depth)
106 void QTocDialog::setTreeDepth(int depth)
111 // expanding and then collapsing is probably better,
112 // but my qt 4.1.2 doesn't have expandAll()..
113 //tocTV->expandAll();
114 QModelIndexList indices =
115 form_->tocModel()->match(form_->tocModel()->index(0,0),
116 Qt::DisplayRole, "*", -1,
117 Qt::MatchWildcard|Qt::MatchRecursive);
119 int size = indices.size();
120 for (int i = 0; i < size; i++) {
121 QModelIndex index = indices[i];
122 if (getIndexDepth(index) < depth_)
123 tocTV->expand(index);
125 tocTV->collapse(index);
130 void QTocDialog::on_typeCO_activated(int value)
132 form_->setTocModel(value);
133 tocTV->setModel(form_->tocModel());
134 reconnectSelectionModel();
140 void QTocDialog::on_moveUpPB_clicked()
142 enableButtons(false);
143 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
150 void QTocDialog::on_moveDownPB_clicked()
152 enableButtons(false);
153 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
155 form_->outlineDown();
160 void QTocDialog::on_moveInPB_clicked()
162 enableButtons(false);
163 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
170 void QTocDialog::on_moveOutPB_clicked()
172 enableButtons(false);
173 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
180 void QTocDialog::select(QModelIndex const & index)
182 // tocTV->setModel(form_->tocModel());
184 if (!index.isValid()) {
186 << "QTocDialog::select(): QModelIndex is invalid!" << endl;
190 tocTV->scrollTo(index);
191 tocTV->selectionModel()->select(index, QItemSelectionModel::Select);
195 void QTocDialog::enableButtons(bool enable)
197 updatePB->setEnabled(enable);
199 if (!form_->canOutline())
202 moveUpPB->setEnabled(enable);
203 moveDownPB->setEnabled(enable);
204 moveInPB->setEnabled(enable);
205 moveOutPB->setEnabled(enable);
209 void QTocDialog::update()
216 void QTocDialog::updateGui()
218 QStringListModel * type_model = form_->typeModel();
219 if (type_model->stringList().isEmpty()) {
221 typeCO->setModel(type_model);
222 tocTV->setModel(new QStandardItemModel);
223 tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
224 depthSL->setEnabled(false);
228 typeCO->setModel(type_model);
229 typeCO->setCurrentIndex(form_->getType());
231 if (form_->tocModel()) {
232 tocTV->setModel(form_->tocModel());
233 tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
236 tocTV-> setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
237 tocTV->showColumn(0);
238 // hide the pointless QHeader for now
239 // in the future, new columns may appear
240 // like labels, bookmarks, etc...
241 // tocTV->header()->hide();
242 tocTV->header()->setVisible(false);
245 reconnectSelectionModel();
246 depthSL->setEnabled(true);
247 depthSL->setMaximum(form_->getTocDepth());
249 select(form_->getCurrentIndex());
252 << "form_->tocModel()->rowCount " << form_->tocModel()->rowCount()
253 << "\nform_->tocModel()->columnCount " << form_->tocModel()->columnCount()
255 // setTitle(form_->guiname())
259 void QTocDialog::reconnectSelectionModel()
261 connect(tocTV->selectionModel(),
262 SIGNAL(currentChanged(const QModelIndex &,
263 const QModelIndex &)),
264 this, SLOT(selectionChanged(const QModelIndex &,
265 const QModelIndex &)));
269 void QTocDialog::apply()
271 // Nothing to do here... for now.
272 // Ideas welcome... (Abdel, 17042006)
276 void QTocDialog::hide()
282 void QTocDialog::show()
289 bool QTocDialog::isVisible() const
291 return QDialog::isVisible();
295 } // namespace frontend
298 #include "QTocDialog_moc.cpp"