]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QTabularDialog.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / qt2 / QTabularDialog.C
1 /**
2  * \file QTabularDialog.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 Jürgen Spitzmüller
8  * \author Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "QTabularDialog.h"
16 #include "QTabular.h"
17 #include "lengthvalidator.h"
18 #include "qt_helpers.h"
19
20 #include "controllers/ControlTabular.h"
21
22 #include <qcheckbox.h>
23 #include <qpushbutton.h>
24 #include <qlineedit.h>
25
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31
32 namespace {
33
34 LengthValidator * unsignedLengthValidator(QLineEdit * ed)
35 {
36         LengthValidator * v = new LengthValidator(ed);
37         v->setBottom(LyXLength());
38         return v;
39 }
40
41 } // namespace anon
42
43
44 QTabularDialog::QTabularDialog(QTabular * form)
45         : QTabularDialogBase(0, 0, false, 0),
46         form_(form)
47 {
48         connect(closePB, SIGNAL(clicked()),
49                 form, SLOT(slotClose()));
50                 
51         widthED->setValidator(unsignedLengthValidator(widthED));
52 }
53
54
55 void QTabularDialog::change_adaptor()
56 {
57         form_->changed();
58 }
59
60
61 void QTabularDialog::closeEvent(QCloseEvent * e)
62 {
63         form_->slotWMHide();
64         e->accept();
65 }
66
67
68 void QTabularDialog::close_clicked()
69 {
70         form_->closeGUI();
71 }
72
73
74 void QTabularDialog::borderSet_clicked()
75 {
76         form_->controller().set(LyXTabular::SET_ALL_LINES);
77         form_->update_borders();
78         form_->changed();
79 }
80
81
82 void QTabularDialog::borderUnset_clicked()
83 {
84         form_->controller().set(LyXTabular::UNSET_ALL_LINES);
85         form_->update_borders();
86         form_->changed();
87 }
88
89
90 void QTabularDialog::leftBorder_changed()
91 {
92         form_->controller().toggleLeftLine();
93         form_->changed();
94 }
95
96
97 void QTabularDialog::rightBorder_changed()
98 {
99         form_->controller().toggleRightLine();
100         form_->changed();
101 }
102
103
104 void QTabularDialog::topBorder_changed()
105 {
106         form_->controller().toggleTopLine();
107         form_->changed();
108 }
109
110
111 void QTabularDialog::bottomBorder_changed()
112 {
113         form_->controller().toggleBottomLine();
114         form_->changed();
115 }
116
117
118 void QTabularDialog::specialAlignment_changed()
119 {
120         string special = fromqstr(specialAlignmentED->text());
121         form_->controller().setSpecial(special);
122         form_->changed();
123 }
124
125
126 void QTabularDialog::width_changed()
127 {
128         form_->changed();
129         string const width = widgetsToLength(widthED, widthUnit);
130         form_->controller().setWidth(width);
131 }
132
133
134 void QTabularDialog::multicolumn_clicked()
135 {
136         form_->controller().toggleMultiColumn();
137         form_->changed();
138 }
139
140
141 void QTabularDialog::rotateTabular()
142 {
143         form_->controller().rotateTabular(rotateTabularCB->isChecked());
144         form_->changed();
145 }
146
147
148 void QTabularDialog::rotateCell()
149 {
150         form_->controller().rotateCell(rotateCellCB->isChecked());
151         form_->changed();
152 }
153
154
155 void QTabularDialog::hAlign_changed(int align)
156 {
157         ControlTabular::HALIGN h = ControlTabular::LEFT;
158
159         switch (align) {
160                 case 0: h = ControlTabular::LEFT; break;
161                 case 1: h = ControlTabular::CENTER; break;
162                 case 2: h = ControlTabular::RIGHT; break;
163                 case 3: h = ControlTabular::BLOCK; break;
164         }
165
166         form_->controller().halign(h);
167 }
168
169
170 void QTabularDialog::vAlign_changed(int align)
171 {
172         ControlTabular::VALIGN v = ControlTabular::TOP;
173
174         switch (align) {
175                 case 0: v = ControlTabular::TOP; break;
176                 case 1: v = ControlTabular::MIDDLE; break;
177                 case 2: v = ControlTabular::BOTTOM; break;
178         }
179
180         form_->controller().valign(v);
181 }
182
183
184 void QTabularDialog::longTabular()
185 {
186         form_->controller().longTabular(longTabularCB->isChecked());
187         form_->changed();
188 }
189
190
191 void QTabularDialog::ltNewpage_clicked()
192 {
193         form_->controller().set(LyXTabular::SET_LTNEWPAGE);
194         form_->changed();
195 }
196
197
198 void QTabularDialog::ltHeaderStatus_clicked()
199 {
200         bool enable(headerStatusCB->isChecked());
201         if (enable)
202                 form_->controller().set(LyXTabular::SET_LTHEAD, "");
203         else
204                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
205         headerBorderAboveCB->setEnabled(enable);
206         headerBorderBelowCB->setEnabled(enable);
207         firstheaderNoContentsCB->setEnabled(enable);
208         form_->changed();
209 }
210
211
212 void QTabularDialog::ltHeaderBorderAbove_clicked()
213 {
214         if (headerBorderAboveCB->isChecked())
215                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_above");
216         else
217                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
218         form_->changed();
219 }
220
221
222 void QTabularDialog::ltHeaderBorderBelow_clicked()
223 {
224         if (headerBorderBelowCB->isChecked())
225                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_below");
226         else
227                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
228         form_->changed();
229 }
230
231
232 void QTabularDialog::ltFirstHeaderBorderAbove_clicked()
233 {
234         if (firstheaderBorderAboveCB->isChecked())
235                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_above");
236         else
237                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
238         form_->changed();
239 }
240
241
242 void QTabularDialog::ltFirstHeaderBorderBelow_clicked()
243 {
244         if (firstheaderBorderBelowCB->isChecked())
245                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_below");
246         else
247                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
248         form_->changed();
249 }
250
251
252 void QTabularDialog::ltFirstHeaderStatus_clicked()
253 {
254         bool enable(firstheaderStatusCB->isChecked());
255         if (enable)
256                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "");
257         else
258                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
259         firstheaderBorderAboveCB->setEnabled(enable);
260         firstheaderBorderBelowCB->setEnabled(enable);
261         form_->changed();
262 }
263
264
265 void QTabularDialog::ltFirstHeaderEmpty_clicked()
266 {
267         bool enable(firstheaderNoContentsCB->isChecked());
268         if (enable)
269                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "empty");
270         else {
271                 ltFirstHeaderBorderBelow_clicked();
272                 ltFirstHeaderBorderAbove_clicked();
273         }
274         firstheaderStatusCB->setEnabled(!enable);
275         firstheaderBorderAboveCB->setEnabled(!enable);
276         firstheaderBorderBelowCB->setEnabled(!enable);
277         form_->changed();
278 }
279
280
281 void QTabularDialog::ltFooterStatus_clicked()
282 {
283         bool enable(footerStatusCB->isChecked());
284         if (enable)
285                 form_->controller().set(LyXTabular::SET_LTFOOT, "");
286         else
287                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
288         footerBorderAboveCB->setEnabled(enable);
289         footerBorderBelowCB->setEnabled(enable);
290         lastfooterNoContentsCB->setEnabled(enable);
291         form_->changed();
292 }
293
294
295 void QTabularDialog::ltFooterBorderAbove_clicked()
296 {
297         if (footerBorderAboveCB->isChecked())
298                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_above");
299         else
300                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
301         form_->changed();
302 }
303
304
305 void QTabularDialog::ltFooterBorderBelow_clicked()
306 {
307         if (footerBorderBelowCB->isChecked())
308                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_below");
309         else
310                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
311         form_->changed();
312 }
313
314
315 void QTabularDialog::ltLastFooterStatus_clicked()
316 {
317         bool enable(lastfooterStatusCB->isChecked());
318         if (enable)
319                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "");
320         else
321                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
322         lastfooterBorderAboveCB->setEnabled(enable);
323         lastfooterBorderBelowCB->setEnabled(enable);
324         form_->changed();
325 }
326
327
328 void QTabularDialog::ltLastFooterBorderAbove_clicked()
329 {
330         if (lastfooterBorderAboveCB->isChecked())
331                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_above");
332         else
333                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
334         form_->changed();
335 }
336
337
338 void QTabularDialog::ltLastFooterBorderBelow_clicked()
339 {
340         if (lastfooterBorderBelowCB->isChecked())
341                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_below");
342         else
343                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
344         form_->changed();
345 }
346
347
348 void QTabularDialog::ltLastFooterEmpty_clicked()
349 {
350         bool enable(lastfooterNoContentsCB->isChecked());
351         if (enable)
352                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "empty");
353         else {
354                 ltLastFooterBorderBelow_clicked();
355                 ltLastFooterBorderAbove_clicked();
356         }
357         lastfooterStatusCB->setEnabled(!enable);
358         lastfooterBorderAboveCB->setEnabled(!enable);
359         lastfooterBorderBelowCB->setEnabled(!enable);
360         form_->changed();
361 }
362
363 } // namespace frontend
364 } // namespace lyx