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"
16 #include "qt_helpers.h"
17 #include "controllers/ControlToc.h"
21 #include <QTreeWidget>
22 #include <QTreeWidgetItem>
23 #include <QPushButton>
24 #include <QCloseEvent>
39 QTocDialog::QTocDialog(QToc * form)
40 : form_(form), depth_(2)
45 tocTW->setSortingEnabled(false);
46 tocTW->setColumnCount(1);
48 // hide the pointless QHeader
49 // QWidget * w = static_cast<QWidget*>(tocTW->child("list view header"));
53 // connect(closePB, SIGNAL(clicked()),
54 // form, SLOT(slotClose()));
58 QTocDialog::~QTocDialog()
63 void QTocDialog::on_tocTW_currentItemChanged(QTreeWidgetItem * current,
64 QTreeWidgetItem * previous)
66 form_->select(fromqstr(current->text(0)));
68 << fromqstr(current->text(0)) << " selected" << endl;
71 void QTocDialog::on_closePB_clicked()
76 void QTocDialog::on_updatePB_clicked()
81 void QTocDialog::on_depthSL_valueChanged(int depth)
90 void QTocDialog::on_typeCO_activated(int value)
95 void QTocDialog::on_moveUpPB_clicked()
102 void QTocDialog::on_moveDownPB_clicked()
104 enableButtons(false);
109 void QTocDialog::on_moveInPB_clicked()
111 enableButtons(false);
116 void QTocDialog::on_moveOutPB_clicked()
118 enableButtons(false);
123 void QTocDialog::enableButtons(bool enable)
125 moveUpPB->setEnabled(enable);
126 moveDownPB->setEnabled(enable);
127 moveInPB->setEnabled(enable);
128 moveOutPB->setEnabled(enable);
129 updatePB->setEnabled(enable);
132 void QTocDialog::updateType()
136 vector<string> const & choice = form_->controller().getTypes();
137 string const & type = toc::getType(form_->controller().params().getCmdName());
139 for (vector<string>::const_iterator it = choice.begin();
140 it != choice.end(); ++it) {
141 string const & guiname = form_->controller().getGuiName(*it);
142 typeCO->insertItem(toqstr(guiname));
144 typeCO->setCurrentItem(it - choice.begin());
145 form_->setTitle(guiname);
150 void QTocDialog::updateToc(bool newdepth)
152 vector<string> const & choice = form_->controller().getTypes();
155 type = choice[typeCO->currentItem()];
157 toc::Toc const & contents = form_->controller().getContents(type);
159 // Check if all elements are the same.
160 if (!newdepth && form_->get_toclist() == contents) {
166 form_->get_toclist() = contents;
168 if (form_->get_toclist().empty())
171 tocTW->setUpdatesEnabled(false);
173 QTreeWidgetItem * topLevelItem;
175 toc::Toc::const_iterator iter = form_->get_toclist().begin();
177 while (iter != form_->get_toclist().end()) {
179 if (iter->depth == 1) {
180 topLevelItem = new QTreeWidgetItem(tocTW);
181 topLevelItem->setText(0, toqstr(iter->str));
182 if (iter->depth < depth_) tocTW->collapseItem(topLevelItem);
185 << "Table of contents\n"
186 << "Added Top Level item " << iter->str
187 << " at depth " << iter->depth
190 populateItem(topLevelItem, iter);
193 if (iter == form_->get_toclist().end())
199 tocTW->setUpdatesEnabled(true);
201 form_->setTitle(fromqstr(typeCO->currentText()));
205 void QTocDialog::populateItem(QTreeWidgetItem * parentItem, toc::Toc::const_iterator& iter)
207 int curdepth = iter->depth+1;
208 QTreeWidgetItem * item;
210 while (iter != form_->get_toclist().end()) {
214 if (iter == form_->get_toclist().end())
217 if (iter->depth < curdepth) {
221 if (iter->depth > curdepth) {
226 item = new QTreeWidgetItem(parentItem);
227 item->setText(0, toqstr(iter->str));
229 if (iter->depth < depth_) tocTW->collapseItem(item);
230 // else tocTW->expandItem(item);
232 << "Table of contents: Added item " << iter->str
233 << " at depth " << iter->depth
235 << fromqstr(parentItem->text(0)) << '"'
238 populateItem(item, iter);
243 void QTocDialog::closeEvent(QCloseEvent * e)
249 } // namespace frontend