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