]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QTocDialog.C
* Painter.h:
[lyx.git] / src / frontends / qt4 / QTocDialog.C
1 /**
2  * \file QTocDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "QTocDialog.h"
15 #include "QToc.h"
16 #include "Qt2BC.h"
17 #include "qt_helpers.h"
18 #include "controllers/ControlToc.h"
19
20 #include "debug.h"
21
22 #include <QTreeWidgetItem>
23 #include <QPushButton>
24 #include <QCloseEvent>
25 #include <QHeaderView>
26
27 #include <vector>
28 #include <string>
29 #include <stack>
30
31 using std::endl;
32 using std::pair;
33 using std::stack;
34 using std::vector;
35 using std::string;
36
37
38 namespace lyx {
39 namespace frontend {
40
41 QTocDialog::QTocDialog(Dialog & dialog, QToc * form)
42         : Dialog::View(dialog, _("Toc")), form_(form), depth_(2)
43 {
44         setupUi(this);
45
46         updateGui();
47
48         connect(tocTV->selectionModel(),
49                 SIGNAL(currentChanged(const QModelIndex &,
50                         const QModelIndex &)),
51                 this, SLOT(selectionChanged(const QModelIndex &,
52                         const QModelIndex &)));
53 }
54
55
56 QTocDialog::~QTocDialog()
57 {
58         accept();
59 }
60
61
62 void QTocDialog::selectionChanged(const QModelIndex & current,
63                                   const QModelIndex & /*previous*/)
64 {
65         lyxerr[Debug::GUI]
66                 << "selectionChanged index " << current.row()
67                 << ", " << current.column()
68                 << endl;
69
70         form_->goTo(current);
71 }
72
73
74 void QTocDialog::on_closePB_clicked()
75 {
76         accept();
77 }
78
79
80 void QTocDialog::on_updatePB_clicked()
81 {
82         update();
83 }
84
85
86 void QTocDialog::on_depthSL_valueChanged(int depth)
87 {
88         if (depth == depth_)
89                 return;
90
91         depth_ = depth;
92
93 /*
94         while (
95         tocTv->setExpanded();
96                         if (iter->depth() > depth_)
97                                 tocTV->collapseItem(topLevelItem);
98                         else if (iter->depth() <= depth_)
99                                 tocTV->expandItem(topLevelItem);
100 */
101 }
102
103
104 void QTocDialog::on_typeCO_activated(int value)
105 {
106         form_->setTocModel(value);
107         enableButtons();
108 }
109
110
111 void QTocDialog::on_moveUpPB_clicked()
112 {
113         enableButtons(false);
114         QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
115         form_->goTo(index);
116         form_->outlineUp();
117         update();
118 }
119
120
121 void QTocDialog::on_moveDownPB_clicked()
122 {
123         enableButtons(false);
124         QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
125         form_->goTo(index);
126         form_->outlineDown();
127         update();
128 }
129
130
131 void QTocDialog::on_moveInPB_clicked()
132 {
133         enableButtons(false);
134         QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
135         form_->goTo(index);
136         form_->outlineIn();
137         update();
138 }
139
140
141 void QTocDialog::on_moveOutPB_clicked()
142 {
143         enableButtons(false);
144         QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
145         form_->goTo(index);
146         form_->outlineOut();
147         update();
148 }
149
150
151 void QTocDialog::select(QModelIndex const & index)
152 {
153 //      tocTV->setModel(form_->tocModel());
154
155         if (!index.isValid()) {
156                 lyxerr[Debug::GUI]
157                         << "QTocDialog::select(): QModelIndex is invalid!" << endl;
158                 return;
159         }
160
161         tocTV->scrollTo(index);
162         tocTV->selectionModel()->select(index, QItemSelectionModel::Select);
163 }
164
165
166 void QTocDialog::enableButtons(bool enable)
167 {
168         updatePB->setEnabled(enable);
169
170         if (!form_->canOutline())
171                 enable = false;
172
173         moveUpPB->setEnabled(enable);
174         moveDownPB->setEnabled(enable);
175         moveInPB->setEnabled(enable);
176         moveOutPB->setEnabled(enable);
177 }
178
179
180 void QTocDialog::update()
181 {
182         form_->update();
183         updateGui();
184 }
185
186
187 void QTocDialog::updateGui()
188 {
189         QStringListModel * type_model = form_->typeModel();
190         if (type_model->stringList().isEmpty())
191         {
192                 enableButtons();
193                 typeCO->setModel(type_model);
194                 tocTV->setModel(new QStandardItemModel);
195                 return;
196         }
197
198         typeCO->setModel(type_model);
199
200         if (form_->tocModel())
201                 tocTV->setModel(form_->tocModel());
202         tocTV->showColumn(0);
203         // hide the pointless QHeader for now
204         // in the future, new columns may appear
205         // like labels, bookmarks, etc...
206         // tocTV->header()->hide();
207         tocTV->header()->setVisible(true);
208         enableButtons();
209
210         connect(tocTV->selectionModel(),
211                 SIGNAL(currentChanged(const QModelIndex &,
212                         const QModelIndex &)),
213                 this, SLOT(selectionChanged(const QModelIndex &,
214                         const QModelIndex &)));
215
216         select(form_->getCurrentIndex());
217
218         lyxerr[Debug::GUI]
219                 << "form_->tocModel()->rowCount " << form_->tocModel()->rowCount()
220                 << "\nform_->tocModel()->columnCount " << form_->tocModel()->columnCount()
221                 << endl;
222 //      setTitle(form_->guiname())
223 }
224
225
226 void QTocDialog::apply()
227 {
228         // Nothing to do here... for now.
229         // Ideas welcome... (Abdel, 17042006)
230 }
231
232
233 void QTocDialog::hide()
234 {
235         accept();
236 }
237
238
239 void QTocDialog::show()
240 {
241         update();
242         QDialog::show();
243 }
244
245
246 bool QTocDialog::isVisible() const
247 {
248         return QDialog::isVisible();
249 }
250
251
252 } // namespace frontend
253 } // namespace lyx
254
255 #include "QTocDialog_moc.cpp"