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