]> git.lyx.org Git - lyx.git/blob - src/frontends/qt3/QTabularDialog.C
Extracted from r14281
[lyx.git] / src / frontends / qt3 / 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 "lengthcombo.h"
18 #include "validators.h"
19 #include "qt_helpers.h"
20
21 #include "controllers/ButtonController.h"
22 #include "controllers/ControlTabular.h"
23
24 #include <qcheckbox.h>
25 #include <qpushbutton.h>
26 #include <qradiobutton.h>
27 #include <qlineedit.h>
28
29 using std::string;
30
31 namespace lyx {
32 namespace frontend {
33
34
35 QTabularDialog::QTabularDialog(QTabular * form)
36         : QTabularDialogBase(0, 0, false, 0),
37         form_(form)
38 {
39         connect(closePB, SIGNAL(clicked()),
40                 form, SLOT(slotClose()));
41
42         widthED->setValidator(unsignedLengthValidator(widthED));
43         topspaceED->setValidator(new LengthValidator(topspaceED));
44         bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
45         interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
46 }
47
48
49 void QTabularDialog::change_adaptor()
50 {
51         form_->changed();
52 }
53
54
55 void QTabularDialog::closeEvent(QCloseEvent * e)
56 {
57         form_->slotWMHide();
58         e->accept();
59 }
60
61
62 void QTabularDialog::close_clicked()
63 {
64         form_->closeGUI();
65 }
66
67
68 void QTabularDialog::borderSet_clicked()
69 {
70         form_->controller().set(LyXTabular::SET_ALL_LINES);
71         form_->update_borders();
72         form_->changed();
73 }
74
75
76 void QTabularDialog::borderUnset_clicked()
77 {
78         form_->controller().set(LyXTabular::UNSET_ALL_LINES);
79         form_->update_borders();
80         form_->changed();
81 }
82
83
84 void QTabularDialog::leftBorder_changed()
85 {
86         form_->controller().toggleLeftLine();
87         form_->changed();
88 }
89
90
91 void QTabularDialog::rightBorder_changed()
92 {
93         form_->controller().toggleRightLine();
94         form_->changed();
95 }
96
97
98 void QTabularDialog::topBorder_changed()
99 {
100         form_->controller().toggleTopLine();
101         form_->changed();
102 }
103
104
105 void QTabularDialog::bottomBorder_changed()
106 {
107         form_->controller().toggleBottomLine();
108         form_->changed();
109 }
110
111
112 void QTabularDialog::specialAlignment_changed()
113 {
114         string special = fromqstr(specialAlignmentED->text());
115         form_->controller().setSpecial(special);
116         form_->changed();
117 }
118
119
120 void QTabularDialog::width_changed()
121 {
122         form_->changed();
123         string const width = widgetsToLength(widthED, widthUnit);
124         form_->controller().setWidth(width);
125 }
126
127
128 void QTabularDialog::topspace_changed()
129 {
130         switch(topspaceCO->currentItem()) {
131                 case 0: {
132                         form_->controller().set(LyXTabular::SET_TOP_SPACE, "");
133                         topspaceED->setEnabled(false);
134                         topspaceUnit->setEnabled(false);
135                         break;
136                 }
137                 case 1: {
138                         form_->controller().set(LyXTabular::SET_TOP_SPACE, "default");
139                         topspaceED->setEnabled(false);
140                         topspaceUnit->setEnabled(false);
141                         break;
142                 }
143                 case 2: {
144                         if (!topspaceED->text().isEmpty())
145                                 form_->controller().set(LyXTabular::SET_TOP_SPACE,
146                                         widgetsToLength(topspaceED, topspaceUnit));
147                         if (!form_->bc().bp().isReadOnly()) {
148                                 topspaceED->setEnabled(true);
149                                 topspaceUnit->setEnabled(true);
150                         }
151                         break;
152                 }
153         }
154         form_->changed();
155 }
156
157
158 void QTabularDialog::bottomspace_changed()
159 {
160         switch(bottomspaceCO->currentItem()) {
161                 case 0: {
162                         form_->controller().set(LyXTabular::SET_BOTTOM_SPACE, "");
163                                 bottomspaceED->setEnabled(false);
164                                 bottomspaceUnit->setEnabled(false);
165                         break;
166                 }
167                 case 1: {
168                         form_->controller().set(LyXTabular::SET_BOTTOM_SPACE, "default");
169                         bottomspaceED->setEnabled(false);
170                         bottomspaceUnit->setEnabled(false);
171                         break;
172                 }
173                 case 2: {
174                         if (!bottomspaceED->text().isEmpty())
175                                 form_->controller().set(LyXTabular::SET_BOTTOM_SPACE,
176                                         widgetsToLength(bottomspaceED, bottomspaceUnit));
177                         if (!form_->bc().bp().isReadOnly()) {
178                                 bottomspaceED->setEnabled(true);
179                                 bottomspaceUnit->setEnabled(true);
180                         }
181                         break;
182                 }
183         }
184         form_->changed();
185 }
186
187
188 void QTabularDialog::interlinespace_changed()
189 {
190         switch(interlinespaceCO->currentItem()) {
191                 case 0: {
192                         form_->controller().set(LyXTabular::SET_INTERLINE_SPACE, "");
193                                 interlinespaceED->setEnabled(false);
194                                 interlinespaceUnit->setEnabled(false);
195                         break;
196                 }
197                 case 1: {
198                         form_->controller().set(LyXTabular::SET_INTERLINE_SPACE, "default");
199                         interlinespaceED->setEnabled(false);
200                         interlinespaceUnit->setEnabled(false);
201                         break;
202                 }
203                 case 2: {
204                         if (!interlinespaceED->text().isEmpty())
205                                 form_->controller().set(LyXTabular::SET_INTERLINE_SPACE,
206                                         widgetsToLength(interlinespaceED, interlinespaceUnit));
207                         if (!form_->bc().bp().isReadOnly()) {
208                                 interlinespaceED->setEnabled(true);
209                                 interlinespaceUnit->setEnabled(true);
210                         }
211                         break;
212                 }
213         }
214         form_->changed();
215 }
216
217
218 void QTabularDialog::multicolumn_clicked()
219 {
220         form_->controller().toggleMultiColumn();
221         form_->changed();
222 }
223
224
225 void QTabularDialog::rotateTabular()
226 {
227         form_->controller().rotateTabular(rotateTabularCB->isChecked());
228         form_->changed();
229 }
230
231
232 void QTabularDialog::rotateCell()
233 {
234         form_->controller().rotateCell(rotateCellCB->isChecked());
235         form_->changed();
236 }
237
238
239 void QTabularDialog::hAlign_changed(int align)
240 {
241         ControlTabular::HALIGN h = ControlTabular::LEFT;
242
243         switch (align) {
244                 case 0: h = ControlTabular::LEFT; break;
245                 case 1: h = ControlTabular::CENTER; break;
246                 case 2: h = ControlTabular::RIGHT; break;
247                 case 3: h = ControlTabular::BLOCK; break;
248         }
249
250         form_->controller().halign(h);
251 }
252
253
254 void QTabularDialog::vAlign_changed(int align)
255 {
256         ControlTabular::VALIGN v = ControlTabular::TOP;
257
258         switch (align) {
259                 case 0: v = ControlTabular::TOP; break;
260                 case 1: v = ControlTabular::MIDDLE; break;
261                 case 2: v = ControlTabular::BOTTOM; break;
262         }
263
264         form_->controller().valign(v);
265 }
266
267
268 void QTabularDialog::longTabular()
269 {
270         form_->controller().longTabular(longTabularCB->isChecked());
271         form_->changed();
272 }
273
274
275 void QTabularDialog::ltNewpage_clicked()
276 {
277         form_->controller().set(LyXTabular::SET_LTNEWPAGE);
278         form_->changed();
279 }
280
281
282 void QTabularDialog::ltHeaderStatus_clicked()
283 {
284         bool enable(headerStatusCB->isChecked());
285         if (enable)
286                 form_->controller().set(LyXTabular::SET_LTHEAD, "");
287         else
288                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
289         headerBorderAboveCB->setEnabled(enable);
290         headerBorderBelowCB->setEnabled(enable);
291         firstheaderNoContentsCB->setEnabled(enable);
292         form_->changed();
293 }
294
295
296 void QTabularDialog::ltHeaderBorderAbove_clicked()
297 {
298         if (headerBorderAboveCB->isChecked())
299                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_above");
300         else
301                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "dl_above");
302         form_->changed();
303 }
304
305
306 void QTabularDialog::ltHeaderBorderBelow_clicked()
307 {
308         if (headerBorderBelowCB->isChecked())
309                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_below");
310         else
311                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "dl_below");
312         form_->changed();
313 }
314
315
316 void QTabularDialog::ltFirstHeaderBorderAbove_clicked()
317 {
318         if (firstheaderBorderAboveCB->isChecked())
319                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_above");
320         else
321                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "dl_above");
322         form_->changed();
323 }
324
325
326 void QTabularDialog::ltFirstHeaderBorderBelow_clicked()
327 {
328         if (firstheaderBorderBelowCB->isChecked())
329                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_below");
330         else
331                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "dl_below");
332         form_->changed();
333 }
334
335
336 void QTabularDialog::ltFirstHeaderStatus_clicked()
337 {
338         bool enable(firstheaderStatusCB->isChecked());
339         if (enable)
340                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "");
341         else
342                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
343         firstheaderBorderAboveCB->setEnabled(enable);
344         firstheaderBorderBelowCB->setEnabled(enable);
345         form_->changed();
346 }
347
348
349 void QTabularDialog::ltFirstHeaderEmpty_clicked()
350 {
351         bool enable(firstheaderNoContentsCB->isChecked());
352         if (enable)
353                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "empty");
354         else
355                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "empty");
356         firstheaderStatusCB->setEnabled(!enable);
357         firstheaderBorderAboveCB->setEnabled(!enable);
358         firstheaderBorderBelowCB->setEnabled(!enable);
359         form_->changed();
360 }
361
362
363 void QTabularDialog::ltFooterStatus_clicked()
364 {
365         bool enable(footerStatusCB->isChecked());
366         if (enable)
367                 form_->controller().set(LyXTabular::SET_LTFOOT, "");
368         else
369                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
370         footerBorderAboveCB->setEnabled(enable);
371         footerBorderBelowCB->setEnabled(enable);
372         lastfooterNoContentsCB->setEnabled(enable);
373         form_->changed();
374 }
375
376
377 void QTabularDialog::ltFooterBorderAbove_clicked()
378 {
379         if (footerBorderAboveCB->isChecked())
380                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_above");
381         else
382                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "dl_above");
383         form_->changed();
384 }
385
386
387 void QTabularDialog::ltFooterBorderBelow_clicked()
388 {
389         if (footerBorderBelowCB->isChecked())
390                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_below");
391         else
392                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "dl_below");
393         form_->changed();
394 }
395
396
397 void QTabularDialog::ltLastFooterStatus_clicked()
398 {
399         bool enable(lastfooterStatusCB->isChecked());
400         if (enable)
401                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "");
402         else
403                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
404         lastfooterBorderAboveCB->setEnabled(enable);
405         lastfooterBorderBelowCB->setEnabled(enable);
406         form_->changed();
407 }
408
409
410 void QTabularDialog::ltLastFooterBorderAbove_clicked()
411 {
412         if (lastfooterBorderAboveCB->isChecked())
413                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_above");
414         else
415                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "dl_above");
416         form_->changed();
417 }
418
419
420 void QTabularDialog::ltLastFooterBorderBelow_clicked()
421 {
422         if (lastfooterBorderBelowCB->isChecked())
423                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_below");
424         else
425                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "dl_below");
426         form_->changed();
427 }
428
429
430 void QTabularDialog::ltLastFooterEmpty_clicked()
431 {
432         bool enable(lastfooterNoContentsCB->isChecked());
433         if (enable)
434                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "empty");
435         else
436                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "empty");
437         lastfooterStatusCB->setEnabled(!enable);
438         lastfooterBorderAboveCB->setEnabled(!enable);
439         lastfooterBorderBelowCB->setEnabled(!enable);
440         form_->changed();
441 }
442
443
444 void QTabularDialog::booktabs_clicked()
445 {
446         if (booktabsRB->isChecked())
447                 form_->controller().set(LyXTabular::SET_BOOKTABS);
448         else
449                 form_->controller().set(LyXTabular::UNSET_BOOKTABS);
450         form_->update_borders();
451         form_->changed();
452 }
453
454 } // namespace frontend
455 } // namespace lyx