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)
103 // tocTV->expandAll(); //expanding and then collapsing is probably better, but my qt 4.1.2 doesn't have expandAll()..
104 QModelIndexList indices =
105 form_->tocModel()->match(form_->tocModel()->index(0,0),
106 Qt::DisplayRole, "*", -1,
107 Qt::MatchWildcard|Qt::MatchRecursive);
108 Q_FOREACH (QModelIndex index, indices) { // I had to use Q_FOREACH instead of foreach
109 if(getIndexDepth(index) < depth) // because compile flag -DQT_NO_KEYWORDS doesn't allow me..
110 tocTV->expand(index);
112 tocTV->collapse(index);
117 void QTocDialog::on_typeCO_activated(int value)
119 form_->setTocModel(value);
120 tocTV->setModel(form_->tocModel());
121 reconnectSelectionModel();
126 void QTocDialog::on_moveUpPB_clicked()
128 enableButtons(false);
129 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
136 void QTocDialog::on_moveDownPB_clicked()
138 enableButtons(false);
139 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
141 form_->outlineDown();
146 void QTocDialog::on_moveInPB_clicked()
148 enableButtons(false);
149 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
156 void QTocDialog::on_moveOutPB_clicked()
158 enableButtons(false);
159 QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
166 void QTocDialog::select(QModelIndex const & index)
168 // tocTV->setModel(form_->tocModel());
170 if (!index.isValid()) {
172 << "QTocDialog::select(): QModelIndex is invalid!" << endl;
176 tocTV->scrollTo(index);
177 tocTV->selectionModel()->select(index, QItemSelectionModel::Select);
181 void QTocDialog::enableButtons(bool enable)
183 updatePB->setEnabled(enable);
185 if (!form_->canOutline())
188 moveUpPB->setEnabled(enable);
189 moveDownPB->setEnabled(enable);
190 moveInPB->setEnabled(enable);
191 moveOutPB->setEnabled(enable);
195 void QTocDialog::update()
202 void QTocDialog::updateGui()
204 QStringListModel * type_model = form_->typeModel();
205 if (type_model->stringList().isEmpty())
208 typeCO->setModel(type_model);
209 tocTV->setModel(new QStandardItemModel);
213 typeCO->setModel(type_model);
214 typeCO->setCurrentIndex(form_->getType());
216 if (form_->tocModel())
217 tocTV->setModel(form_->tocModel());
218 tocTV->showColumn(0);
219 // hide the pointless QHeader for now
220 // in the future, new columns may appear
221 // like labels, bookmarks, etc...
222 // tocTV->header()->hide();
223 tocTV->header()->setVisible(false);
226 reconnectSelectionModel();
227 select(form_->getCurrentIndex());
230 << "form_->tocModel()->rowCount " << form_->tocModel()->rowCount()
231 << "\nform_->tocModel()->columnCount " << form_->tocModel()->columnCount()
233 // setTitle(form_->guiname())
237 void QTocDialog::reconnectSelectionModel()
239 connect(tocTV->selectionModel(),
240 SIGNAL(currentChanged(const QModelIndex &,
241 const QModelIndex &)),
242 this, SLOT(selectionChanged(const QModelIndex &,
243 const QModelIndex &)));
247 void QTocDialog::apply()
249 // Nothing to do here... for now.
250 // Ideas welcome... (Abdel, 17042006)
254 void QTocDialog::hide()
260 void QTocDialog::show()
267 bool QTocDialog::isVisible() const
269 return QDialog::isVisible();
273 } // namespace frontend
276 #include "QTocDialog_moc.cpp"