]> git.lyx.org Git - features.git/blob - src/frontends/qt4/QTocDialog.C
ugras baran: correct switching between different TOC types
[features.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         tocTV->setModel(form_->tocModel());
108         enableButtons();
109 }
110
111
112 void QTocDialog::on_moveUpPB_clicked()
113 {
114         enableButtons(false);
115         QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
116         form_->goTo(index);
117         form_->outlineUp();
118         update();
119 }
120
121
122 void QTocDialog::on_moveDownPB_clicked()
123 {
124         enableButtons(false);
125         QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
126         form_->goTo(index);
127         form_->outlineDown();
128         update();
129 }
130
131
132 void QTocDialog::on_moveInPB_clicked()
133 {
134         enableButtons(false);
135         QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
136         form_->goTo(index);
137         form_->outlineIn();
138         update();
139 }
140
141
142 void QTocDialog::on_moveOutPB_clicked()
143 {
144         enableButtons(false);
145         QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
146         form_->goTo(index);
147         form_->outlineOut();
148         update();
149 }
150
151
152 void QTocDialog::select(QModelIndex const & index)
153 {
154 //      tocTV->setModel(form_->tocModel());
155
156         if (!index.isValid()) {
157                 lyxerr[Debug::GUI]
158                         << "QTocDialog::select(): QModelIndex is invalid!" << endl;
159                 return;
160         }
161
162         tocTV->scrollTo(index);
163         tocTV->selectionModel()->select(index, QItemSelectionModel::Select);
164 }
165
166
167 void QTocDialog::enableButtons(bool enable)
168 {
169         updatePB->setEnabled(enable);
170
171         if (!form_->canOutline())
172                 enable = false;
173
174         moveUpPB->setEnabled(enable);
175         moveDownPB->setEnabled(enable);
176         moveInPB->setEnabled(enable);
177         moveOutPB->setEnabled(enable);
178 }
179
180
181 void QTocDialog::update()
182 {
183         form_->update();
184         updateGui();
185 }
186
187
188 void QTocDialog::updateGui()
189 {
190         QStringListModel * type_model = form_->typeModel();
191         if (type_model->stringList().isEmpty())
192         {
193                 enableButtons();
194                 typeCO->setModel(type_model);
195                 tocTV->setModel(new QStandardItemModel);
196                 return;
197         }
198
199         typeCO->setModel(type_model);
200
201         if (form_->tocModel())
202                 tocTV->setModel(form_->tocModel());
203         tocTV->showColumn(0);
204         // hide the pointless QHeader for now
205         // in the future, new columns may appear
206         // like labels, bookmarks, etc...
207         // tocTV->header()->hide();
208         tocTV->header()->setVisible(false);
209         enableButtons();
210
211         connect(tocTV->selectionModel(),
212                 SIGNAL(currentChanged(const QModelIndex &,
213                         const QModelIndex &)),
214                 this, SLOT(selectionChanged(const QModelIndex &,
215                         const QModelIndex &)));
216
217         select(form_->getCurrentIndex());
218
219         lyxerr[Debug::GUI]
220                 << "form_->tocModel()->rowCount " << form_->tocModel()->rowCount()
221                 << "\nform_->tocModel()->columnCount " << form_->tocModel()->columnCount()
222                 << endl;
223 //      setTitle(form_->guiname())
224 }
225
226
227 void QTocDialog::apply()
228 {
229         // Nothing to do here... for now.
230         // Ideas welcome... (Abdel, 17042006)
231 }
232
233
234 void QTocDialog::hide()
235 {
236         accept();
237 }
238
239
240 void QTocDialog::show()
241 {
242         update();
243         QDialog::show();
244 }
245
246
247 bool QTocDialog::isVisible() const
248 {
249         return QDialog::isVisible();
250 }
251
252
253 } // namespace frontend
254 } // namespace lyx
255
256 #include "QTocDialog_moc.cpp"