]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QTabularDialog.C
dont use pragma impementation and interface anymore
[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 Juergen Spitzmueller
8  * \author Herbert Voss
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 #include <config.h>
14
15
16 #include "ControlTabular.h"
17
18 #include "QTabular.h"
19 #include "QTabularDialog.h"
20 #include "tabular.h"
21 #include "lengthcombo.h"
22 #include "qsetborder.h"
23 #include "qt_helpers.h"
24
25 #include <qcheckbox.h>
26 #include <qpushbutton.h>
27 #include <qlineedit.h>
28
29
30 QTabularDialog::QTabularDialog(QTabular * form)
31         : QTabularDialogBase(0, 0, false, 0),
32         form_(form)
33 {
34         connect(closePB, SIGNAL(clicked()),
35                 form, SLOT(slotClose()));
36 }
37
38
39 void QTabularDialog::change_adaptor()
40 {
41         form_->changed();
42 }
43
44
45 void QTabularDialog::closeEvent(QCloseEvent * e)
46 {
47         form_->slotWMHide();
48         e->accept();
49 }
50
51 void QTabularDialog::close_clicked()
52 {
53         form_->closeGUI();
54 }
55
56 void QTabularDialog::columnAppend_clicked()
57 {
58         form_->controller().set(LyXTabular::APPEND_COLUMN);
59 }
60
61
62 void QTabularDialog::rowAppend_clicked()
63 {
64         form_->controller().set(LyXTabular::APPEND_ROW);
65 }
66
67
68 void QTabularDialog::columnDelete_clicked()
69 {
70         form_->controller().set(LyXTabular::DELETE_COLUMN);
71 }
72
73
74 void QTabularDialog::rowDelete_clicked()
75 {
76         form_->controller().set(LyXTabular::DELETE_ROW);
77 }
78
79
80 void QTabularDialog::borderSet_clicked()
81 {
82         form_->controller().set(LyXTabular::SET_ALL_LINES);
83         form_->update_borders();
84         form_->changed();
85 }
86
87 void QTabularDialog::borderUnset_clicked()
88 {
89         form_->controller().set(LyXTabular::UNSET_ALL_LINES);
90         form_->update_borders();
91         form_->changed();
92 }
93
94
95 void QTabularDialog::leftBorder_changed()
96 {
97         if (form_->controller().isMulticolumnCell())
98                 form_->controller().set(LyXTabular::M_TOGGLE_LINE_LEFT);
99         else
100                 form_->controller().set(LyXTabular::TOGGLE_LINE_LEFT);
101         form_->changed();
102 }
103
104
105 void QTabularDialog::rightBorder_changed()
106 {
107         if (form_->controller().isMulticolumnCell())
108                 form_->controller().set(LyXTabular::M_TOGGLE_LINE_RIGHT);
109         else
110                 form_->controller().set(LyXTabular::TOGGLE_LINE_RIGHT);
111         form_->changed();
112 }
113
114
115 void QTabularDialog::topBorder_changed()
116 {
117         if (form_->controller().isMulticolumnCell())
118                 form_->controller().set(LyXTabular::M_TOGGLE_LINE_TOP);
119         else
120                 form_->controller().set(LyXTabular::TOGGLE_LINE_TOP);
121         form_->changed();
122 }
123
124
125 void QTabularDialog::bottomBorder_changed()
126 {
127         if (form_->controller().isMulticolumnCell())
128                 form_->controller().set(LyXTabular::M_TOGGLE_LINE_BOTTOM);
129         else
130                 form_->controller().set(LyXTabular::TOGGLE_LINE_BOTTOM);
131         form_->changed();
132 }
133
134
135 void QTabularDialog::specialAlignment_changed()
136 {
137         string special = fromqstr(specialAlignmentED->text());
138         if (form_->controller().isMulticolumnCell())
139                 form_->controller().set(LyXTabular::SET_SPECIAL_MULTI, special);
140         else
141                 form_->controller().set(LyXTabular::SET_SPECIAL_COLUMN, special);
142 }
143
144
145 void QTabularDialog::width_changed()
146 {
147         string const width =
148                 LyXLength(widthED->text().toDouble(),
149                         widthUnit->currentLengthItem()).asString();
150         if (form_->controller().isMulticolumnCell())
151                 form_->controller().set(LyXTabular::SET_MPWIDTH, width);
152         else
153                 form_->controller().set(LyXTabular::SET_PWIDTH, width);
154         form_->changed();
155         form_->update_contents();
156 }
157
158
159 void QTabularDialog::multicolumn_clicked()
160 {
161         form_->controller().set(LyXTabular::MULTICOLUMN);
162         form_->changed();
163         form_->update_contents();
164 }
165
166
167 void QTabularDialog::rotateTabular_checked(int state)
168 {
169         switch (state) {
170         case 0:
171                 form_->controller().set(LyXTabular::UNSET_ROTATE_TABULAR);
172                 break;
173         case 1:
174                 // "no change state", should not happen
175                 break;
176         case 2:
177                 form_->controller().set(LyXTabular::SET_ROTATE_TABULAR);
178                 break;
179         }
180 }
181
182
183 void QTabularDialog::rotateCell_checked(int state)
184 {
185         switch (state) {
186         case 0:
187                 form_->controller().set(LyXTabular::UNSET_ROTATE_CELL);
188                 break;
189         case 1:
190                 // "no change state", should not happen
191                 break;
192         case 2:
193                 form_->controller().set(LyXTabular::SET_ROTATE_CELL);
194                 break;
195         }
196 }
197
198
199 void QTabularDialog::hAlign_changed(int align)
200 {
201         LyXTabular::Feature num = LyXTabular::ALIGN_LEFT;
202         LyXTabular::Feature multi_num = LyXTabular::M_ALIGN_LEFT;
203
204         switch (align) {
205                 case 0:
206                 {
207                         num = LyXTabular::ALIGN_LEFT;
208                         multi_num = LyXTabular::M_ALIGN_LEFT;
209                         break;
210                 }
211                 case 1:
212                 {
213                         num = LyXTabular::ALIGN_CENTER;
214                         multi_num = LyXTabular::M_ALIGN_CENTER;
215                         break;
216                 }
217                 case 2:
218                 {
219                         num = LyXTabular::ALIGN_RIGHT;
220                         multi_num = LyXTabular::M_ALIGN_RIGHT;
221                         break;
222                 case 3:
223                 {
224                         num = LyXTabular::ALIGN_BLOCK;
225                         //multi_num: no equivalent
226                         break;
227                 }
228                 }
229         }
230         if (form_->controller().isMulticolumnCell())
231                 form_->controller().set(multi_num);
232         else
233                 form_->controller().set(num);
234 }
235
236
237 void QTabularDialog::vAlign_changed(int align)
238 {
239         LyXTabular::Feature num = LyXTabular::VALIGN_CENTER;
240         LyXTabular::Feature multi_num = LyXTabular::M_VALIGN_CENTER;
241
242         switch (align) {
243                 case 0:
244                 {
245                         num = LyXTabular::VALIGN_TOP;
246                         multi_num = LyXTabular::M_VALIGN_TOP;
247                         break;
248                 }
249                 case 1:
250                 {
251                         num = LyXTabular::VALIGN_CENTER;
252                         multi_num = LyXTabular::M_VALIGN_CENTER;
253                         break;
254                 }
255                 case 2:
256                 {
257                         num = LyXTabular::VALIGN_BOTTOM;
258                         multi_num = LyXTabular::M_VALIGN_BOTTOM;
259                         break;
260                 }
261         }
262         if (form_->controller().isMulticolumnCell())
263                 form_->controller().set(multi_num);
264         else
265                 form_->controller().set(num);
266 }
267
268
269 void QTabularDialog::longTabular_changed(int state)
270 {
271         switch (state) {
272         case 0:
273                 form_->controller().set(LyXTabular::UNSET_LONGTABULAR);
274                 break;
275         case 1:
276                 // "no change state", should not happen
277                 break;
278         case 2:
279                 form_->controller().set(LyXTabular::SET_LONGTABULAR);
280                 break;
281         }
282         form_->changed();
283 }
284
285
286 void QTabularDialog::ltNewpage_clicked()
287 {
288         form_->controller().set(LyXTabular::SET_LTNEWPAGE);
289         form_->changed();
290 }
291
292
293 void QTabularDialog::ltHeaderStatus_clicked()
294 {
295         bool enable(headerStatusCB->isChecked());
296         if (enable)
297                 form_->controller().set(LyXTabular::SET_LTHEAD, "");
298         else
299                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
300         headerBorderAboveCB->setEnabled(enable);
301         headerBorderBelowCB->setEnabled(enable);
302         firstheaderNoContentsCB->setEnabled(enable);
303         form_->changed();
304 }
305
306
307 void QTabularDialog::ltHeaderBorderAbove_clicked()
308 {
309         if (headerBorderAboveCB->isChecked())
310                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_above");
311         else
312                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
313         form_->changed();
314 }
315
316
317 void QTabularDialog::ltHeaderBorderBelow_clicked()
318 {
319         if (headerBorderBelowCB->isChecked())
320                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_below");
321         else
322                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
323         form_->changed();
324 }
325
326
327 void QTabularDialog::ltFirstHeaderBorderAbove_clicked()
328 {
329         if (firstheaderBorderAboveCB->isChecked())
330                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_above");
331         else
332                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
333         form_->changed();
334 }
335
336
337 void QTabularDialog::ltFirstHeaderBorderBelow_clicked()
338 {
339         if (firstheaderBorderBelowCB->isChecked())
340                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_below");
341         else
342                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
343         form_->changed();
344 }
345
346
347 void QTabularDialog::ltFirstHeaderStatus_clicked()
348 {
349         bool enable(firstheaderStatusCB->isChecked());
350         if (enable)
351                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "");
352         else
353                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
354         firstheaderBorderAboveCB->setEnabled(enable);
355         firstheaderBorderBelowCB->setEnabled(enable);
356         form_->changed();
357 }
358
359
360 void QTabularDialog::ltFirstHeaderEmpty_clicked()
361 {
362         bool enable(firstheaderNoContentsCB->isChecked());
363         if (enable)
364                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "empty");
365         else {
366                 ltFirstHeaderBorderBelow_clicked();
367                 ltFirstHeaderBorderAbove_clicked();
368         }
369         firstheaderStatusCB->setEnabled(!enable);
370         firstheaderBorderAboveCB->setEnabled(!enable);
371         firstheaderBorderBelowCB->setEnabled(!enable);
372         form_->changed();
373 }
374
375
376 void QTabularDialog::ltFooterStatus_clicked()
377 {
378         bool enable(footerStatusCB->isChecked());
379         if (enable)
380                 form_->controller().set(LyXTabular::SET_LTFOOT, "");
381         else
382                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
383         footerBorderAboveCB->setEnabled(enable);
384         footerBorderBelowCB->setEnabled(enable);
385         lastfooterNoContentsCB->setEnabled(enable);
386         form_->changed();
387 }
388
389
390 void QTabularDialog::ltFooterBorderAbove_clicked()
391 {
392         if (footerBorderAboveCB->isChecked())
393                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_above");
394         else
395                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
396         form_->changed();
397 }
398
399
400 void QTabularDialog::ltFooterBorderBelow_clicked()
401 {
402         if (footerBorderBelowCB->isChecked())
403                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_below");
404         else
405                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
406         form_->changed();
407 }
408
409
410 void QTabularDialog::ltLastFooterStatus_clicked()
411 {
412         bool enable(lastfooterStatusCB->isChecked());
413         if (enable)
414                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "");
415         else
416                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
417         lastfooterBorderAboveCB->setEnabled(enable);
418         lastfooterBorderBelowCB->setEnabled(enable);
419         form_->changed();
420 }
421
422
423 void QTabularDialog::ltLastFooterBorderAbove_clicked()
424 {
425         if (lastfooterBorderAboveCB->isChecked())
426                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_above");
427         else
428                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
429         form_->changed();
430 }
431
432
433 void QTabularDialog::ltLastFooterBorderBelow_clicked()
434 {
435         if (lastfooterBorderBelowCB->isChecked())
436                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_below");
437         else
438                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
439         form_->changed();
440 }
441
442
443 void QTabularDialog::ltLastFooterEmpty_clicked()
444 {
445         bool enable(lastfooterNoContentsCB->isChecked());
446         if (enable)
447                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "empty");
448         else {
449                 ltLastFooterBorderBelow_clicked();
450                 ltLastFooterBorderAbove_clicked();
451         }
452         lastfooterStatusCB->setEnabled(!enable);
453         lastfooterBorderAboveCB->setEnabled(!enable);
454         lastfooterBorderBelowCB->setEnabled(!enable);
455         form_->changed();
456 }