]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QTabularDialog.C
Some string(widget->text()) fixes. Weirdness
[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         form_->changed();
157         form_->update_contents();
158 }
159
160
161 void QTabularDialog::multicolumn_clicked()
162 {
163         form_->controller().set(LyXTabular::MULTICOLUMN);
164         form_->changed();
165         form_->update_contents();
166 }
167
168
169 void QTabularDialog::rotateTabular_checked(int state)
170 {
171         switch (state) {
172         case 0:
173                 form_->controller().set(LyXTabular::UNSET_ROTATE_TABULAR);
174                 break;
175         case 1:
176                 // "no change state", should not happen
177                 break;
178         case 2:
179                 form_->controller().set(LyXTabular::SET_ROTATE_TABULAR);
180                 break;
181         }
182 }
183
184
185 void QTabularDialog::rotateCell_checked(int state)
186 {
187         switch (state) {
188         case 0:
189                 form_->controller().set(LyXTabular::UNSET_ROTATE_CELL);
190                 break;
191         case 1:
192                 // "no change state", should not happen
193                 break;
194         case 2:
195                 form_->controller().set(LyXTabular::SET_ROTATE_CELL);
196                 break;
197         }
198 }
199
200
201 void QTabularDialog::hAlign_changed(int align)
202 {
203         LyXTabular::Feature num = LyXTabular::ALIGN_LEFT;
204         LyXTabular::Feature multi_num = LyXTabular::M_ALIGN_LEFT;
205
206         switch (align) {
207                 case 0:
208                 {
209                         num = LyXTabular::ALIGN_LEFT;
210                         multi_num = LyXTabular::M_ALIGN_LEFT;
211                         break;
212                 }
213                 case 1:
214                 {
215                         num = LyXTabular::ALIGN_CENTER;
216                         multi_num = LyXTabular::M_ALIGN_CENTER;
217                         break;
218                 }
219                 case 2:
220                 {
221                         num = LyXTabular::ALIGN_RIGHT;
222                         multi_num = LyXTabular::M_ALIGN_RIGHT;
223                         break;
224                 case 3:
225                 {
226                         num = LyXTabular::ALIGN_BLOCK;
227                         //multi_num: no equivalent
228                         break;
229                 }
230                 }
231         }
232         if (form_->controller().isMulticolumnCell())
233                 form_->controller().set(multi_num);
234         else
235                 form_->controller().set(num);
236 }
237
238
239 void QTabularDialog::vAlign_changed(int align)
240 {
241         LyXTabular::Feature num = LyXTabular::VALIGN_CENTER;
242         LyXTabular::Feature multi_num = LyXTabular::M_VALIGN_CENTER;
243
244         switch (align) {
245                 case 0:
246                 {
247                         num = LyXTabular::VALIGN_TOP;
248                         multi_num = LyXTabular::M_VALIGN_TOP;
249                         break;
250                 }
251                 case 1:
252                 {
253                         num = LyXTabular::VALIGN_CENTER;
254                         multi_num = LyXTabular::M_VALIGN_CENTER;
255                         break;
256                 }
257                 case 2:
258                 {
259                         num = LyXTabular::VALIGN_BOTTOM;
260                         multi_num = LyXTabular::M_VALIGN_BOTTOM;
261                         break;
262                 }
263         }
264         if (form_->controller().isMulticolumnCell())
265                 form_->controller().set(multi_num);
266         else
267                 form_->controller().set(num);
268 }
269
270
271 void QTabularDialog::longTabular_changed(int state)
272 {
273         switch (state) {
274         case 0:
275                 form_->controller().set(LyXTabular::UNSET_LONGTABULAR);
276                 break;
277         case 1:
278                 // "no change state", should not happen
279                 break;
280         case 2:
281                 form_->controller().set(LyXTabular::SET_LONGTABULAR);
282                 break;
283         }
284         form_->changed();
285 }
286
287
288 void QTabularDialog::ltNewpage_clicked()
289 {
290         form_->controller().set(LyXTabular::SET_LTNEWPAGE);
291         form_->changed();
292 }
293
294
295 void QTabularDialog::ltHeaderStatus_clicked()
296 {
297         bool enable(headerStatusCB->isChecked());
298         if (enable)
299                 form_->controller().set(LyXTabular::SET_LTHEAD, "");
300         else
301                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
302         headerBorderAboveCB->setEnabled(enable);
303         headerBorderBelowCB->setEnabled(enable);
304         firstheaderNoContentsCB->setEnabled(enable);
305         form_->changed();
306 }
307
308
309 void QTabularDialog::ltHeaderBorderAbove_clicked()
310 {
311         if (headerBorderAboveCB->isChecked())
312                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_above");
313         else
314                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
315         form_->changed();
316 }
317
318
319 void QTabularDialog::ltHeaderBorderBelow_clicked()
320 {
321         if (headerBorderBelowCB->isChecked())
322                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_below");
323         else
324                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
325         form_->changed();
326 }
327
328
329 void QTabularDialog::ltFirstHeaderBorderAbove_clicked()
330 {
331         if (firstheaderBorderAboveCB->isChecked())
332                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_above");
333         else
334                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
335         form_->changed();
336 }
337
338
339 void QTabularDialog::ltFirstHeaderBorderBelow_clicked()
340 {
341         if (firstheaderBorderBelowCB->isChecked())
342                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_below");
343         else
344                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
345         form_->changed();
346 }
347
348
349 void QTabularDialog::ltFirstHeaderStatus_clicked()
350 {
351         bool enable(firstheaderStatusCB->isChecked());
352         if (enable)
353                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "");
354         else
355                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
356         firstheaderBorderAboveCB->setEnabled(enable);
357         firstheaderBorderBelowCB->setEnabled(enable);
358         form_->changed();
359 }
360
361
362 void QTabularDialog::ltFirstHeaderEmpty_clicked()
363 {
364         bool enable(firstheaderNoContentsCB->isChecked());
365         if (enable)
366                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "empty");
367         else {
368                 ltFirstHeaderBorderBelow_clicked();
369                 ltFirstHeaderBorderAbove_clicked();
370         }
371         firstheaderStatusCB->setEnabled(!enable);
372         firstheaderBorderAboveCB->setEnabled(!enable);
373         firstheaderBorderBelowCB->setEnabled(!enable);
374         form_->changed();
375 }
376
377
378 void QTabularDialog::ltFooterStatus_clicked()
379 {
380         bool enable(footerStatusCB->isChecked());
381         if (enable)
382                 form_->controller().set(LyXTabular::SET_LTFOOT, "");
383         else
384                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
385         footerBorderAboveCB->setEnabled(enable);
386         footerBorderBelowCB->setEnabled(enable);
387         lastfooterNoContentsCB->setEnabled(enable);
388         form_->changed();
389 }
390
391
392 void QTabularDialog::ltFooterBorderAbove_clicked()
393 {
394         if (footerBorderAboveCB->isChecked())
395                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_above");
396         else
397                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
398         form_->changed();
399 }
400
401
402 void QTabularDialog::ltFooterBorderBelow_clicked()
403 {
404         if (footerBorderBelowCB->isChecked())
405                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_below");
406         else
407                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
408         form_->changed();
409 }
410
411
412 void QTabularDialog::ltLastFooterStatus_clicked()
413 {
414         bool enable(lastfooterStatusCB->isChecked());
415         if (enable)
416                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "");
417         else
418                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
419         lastfooterBorderAboveCB->setEnabled(enable);
420         lastfooterBorderBelowCB->setEnabled(enable);
421         form_->changed();
422 }
423
424
425 void QTabularDialog::ltLastFooterBorderAbove_clicked()
426 {
427         if (lastfooterBorderAboveCB->isChecked())
428                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_above");
429         else
430                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
431         form_->changed();
432 }
433
434
435 void QTabularDialog::ltLastFooterBorderBelow_clicked()
436 {
437         if (lastfooterBorderBelowCB->isChecked())
438                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_below");
439         else
440                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
441         form_->changed();
442 }
443
444
445 void QTabularDialog::ltLastFooterEmpty_clicked()
446 {
447         bool enable(lastfooterNoContentsCB->isChecked());
448         if (enable)
449                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "empty");
450         else {
451                 ltLastFooterBorderBelow_clicked();
452                 ltLastFooterBorderAbove_clicked();
453         }
454         lastfooterStatusCB->setEnabled(!enable);
455         lastfooterBorderAboveCB->setEnabled(!enable);
456         lastfooterBorderBelowCB->setEnabled(!enable);
457         form_->changed();
458 }