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){
93 return (index.parent() == QModelIndex())? depth : getIndexDepth(index.parent(),depth);
97 void QTocDialog::on_depthSL_valueChanged(int depth)
105 void QTocDialog::setTreeDepth(int depth)
109 // tocTV->expandAll(); //expanding and then collapsing is probably better, but my qt 4.1.2 doesn't have expandAll()..
110 QModelIndexList indices =
111 form_->tocModel()->match(form_->tocModel()->index(0,0),
112 Qt::DisplayRole, "*", -1,
113 Qt::MatchWildcard|Qt::MatchRecursive);
114 Q_FOREACH (QModelIndex index, indices) { // I had to use Q_FOREACH instead of foreach
115 if(getIndexDepth(index) < depth_) // because compile flag -DQT_NO_KEYWORDS doesn't allow me..
116 tocTV->expand(index);
118 tocTV->collapse(index);
123 void QTocDialog::on_typeCO_activated(int value)
125 form_->setTocModel(value);
126 tocTV->setModel(form_->tocModel());
127 reconnectSelectionModel();
132 void QTocDialog::on_moveUpPB_clicked()
134 enableButtons(false);
135 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
142 void QTocDialog::on_moveDownPB_clicked()
144 enableButtons(false);
145 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
147 form_->outlineDown();
152 void QTocDialog::on_moveInPB_clicked()
154 enableButtons(false);
155 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
162 void QTocDialog::on_moveOutPB_clicked()
164 enableButtons(false);
165 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
172 void QTocDialog::select(QModelIndex const & index)
174 // tocTV->setModel(form_->tocModel());
176 if (!index.isValid()) {
178 << "QTocDialog::select(): QModelIndex is invalid!" << endl;
182 tocTV->scrollTo(index);
183 tocTV->selectionModel()->select(index, QItemSelectionModel::Select);
187 void QTocDialog::enableButtons(bool enable)
189 updatePB->setEnabled(enable);
191 if (!form_->canOutline())
194 moveUpPB->setEnabled(enable);
195 moveDownPB->setEnabled(enable);
196 moveInPB->setEnabled(enable);
197 moveOutPB->setEnabled(enable);
201 void QTocDialog::update()
208 void QTocDialog::updateGui()
210 QStringListModel * type_model = form_->typeModel();
211 if (type_model->stringList().isEmpty())
214 typeCO->setModel(type_model);
215 tocTV->setModel(new QStandardItemModel);
219 typeCO->setModel(type_model);
220 typeCO->setCurrentIndex(form_->getType());
222 if (form_->tocModel())
223 tocTV->setModel(form_->tocModel());
224 tocTV->showColumn(0);
225 // hide the pointless QHeader for now
226 // in the future, new columns may appear
227 // like labels, bookmarks, etc...
228 // tocTV->header()->hide();
229 tocTV->header()->setVisible(false);
232 reconnectSelectionModel();
233 depthSL->setMaximum(form_->getTocDepth());
235 select(form_->getCurrentIndex());
238 << "form_->tocModel()->rowCount " << form_->tocModel()->rowCount()
239 << "\nform_->tocModel()->columnCount " << form_->tocModel()->columnCount()
241 // setTitle(form_->guiname())
245 void QTocDialog::reconnectSelectionModel()
247 connect(tocTV->selectionModel(),
248 SIGNAL(currentChanged(const QModelIndex &,
249 const QModelIndex &)),
250 this, SLOT(selectionChanged(const QModelIndex &,
251 const QModelIndex &)));
255 void QTocDialog::apply()
257 // Nothing to do here... for now.
258 // Ideas welcome... (Abdel, 17042006)
262 void QTocDialog::hide()
268 void QTocDialog::show()
275 bool QTocDialog::isVisible() const
277 return QDialog::isVisible();
281 } // namespace frontend
284 #include "QTocDialog_moc.cpp"