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