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