]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiTabular.cpp
shuffle stuff around
[lyx.git] / src / frontends / qt4 / GuiTabular.cpp
1 /**
2  * \file GuiTabular.cpp
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 Jürgen Spitzmüller
8  * \author Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiTabular.h"
16
17 #include "ControlTabular.h"
18 #include "GuiSetBorder.h"
19 #include "LengthCombo.h"
20 #include "Validator.h"
21 #include "qt_helpers.h"
22
23 #include <QCloseEvent>
24 #include <QCheckBox>
25 #include <QPushButton>
26 #include <QRadioButton>
27 #include <QLineEdit>
28
29 using std::string;
30
31
32 namespace lyx {
33 namespace frontend {
34
35 GuiTabularDialog::GuiTabularDialog(LyXView & lv)
36         : GuiDialog(lv, "tabular")
37 {
38         setupUi(this);
39         setViewTitle(_("Table Settings"));
40         setController(new ControlTabular(*this));
41
42         widthED->setValidator(unsignedLengthValidator(widthED));
43         topspaceED->setValidator(new LengthValidator(topspaceED));
44         bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
45         interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
46
47         connect(topspaceED, SIGNAL(returnPressed()),
48                 this, SLOT(topspace_changed()));
49         connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
50                 this, SLOT(topspace_changed()));
51         connect(topspaceCO, SIGNAL(activated(int)), this, SLOT(topspace_changed()));
52         connect(bottomspaceED, SIGNAL(returnPressed()),
53                 this, SLOT(bottomspace_changed()));
54         connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
55                 this, SLOT(bottomspace_changed()));
56         connect(bottomspaceCO, SIGNAL(activated(int)), this, SLOT(bottomspace_changed()));
57         connect(interlinespaceED, SIGNAL(returnPressed()),
58                 this, SLOT(interlinespace_changed()));
59         connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
60                 this, SLOT(interlinespace_changed()));
61         connect(interlinespaceCO, SIGNAL(activated(int)), this, SLOT(interlinespace_changed()));
62         connect(booktabsRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
63         connect(borderDefaultRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
64         connect(borderSetPB, SIGNAL(clicked()), this, SLOT(borderSet_clicked()));
65         connect(borderUnsetPB, SIGNAL(clicked()), this, SLOT(borderUnset_clicked()));
66         connect(longTabularCB, SIGNAL(toggled(bool)), longtableGB, SLOT(setEnabled(bool)));
67         connect(longTabularCB, SIGNAL(toggled(bool)), newpageCB, SLOT(setEnabled(bool)));
68         connect(hAlignCB, SIGNAL(activated(int)), this, SLOT(hAlign_changed(int)));
69         connect(vAlignCB, SIGNAL(activated(int)), this, SLOT(vAlign_changed(int)));
70         connect(multicolumnCB, SIGNAL(clicked()), this, SLOT(multicolumn_clicked()));
71         connect(newpageCB, SIGNAL(clicked()), this, SLOT(ltNewpage_clicked()));
72         connect(headerStatusCB, SIGNAL(clicked()), this, SLOT(ltHeaderStatus_clicked()));
73         connect(headerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderAbove_clicked()));
74         connect(headerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderBelow_clicked()));
75         connect(firstheaderStatusCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderStatus_clicked()));
76         connect(firstheaderBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderAbove_clicked()));
77         connect(firstheaderBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderBelow_clicked()));
78         connect(firstheaderNoContentsCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderEmpty_clicked()));
79         connect(footerStatusCB, SIGNAL(clicked()), this, SLOT(ltFooterStatus_clicked()));
80         connect(footerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderAbove_clicked()));
81         connect(footerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderBelow_clicked()));
82         connect(lastfooterStatusCB, SIGNAL(clicked()), this, SLOT(ltLastFooterStatus_clicked()));
83         connect(lastfooterBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderAbove_clicked()));
84         connect(lastfooterBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderBelow_clicked()));
85         connect(lastfooterNoContentsCB, SIGNAL(clicked()), this, SLOT(ltLastFooterEmpty_clicked()));
86         connect(specialAlignmentED, SIGNAL(returnPressed()), this, SLOT(specialAlignment_changed()));
87         connect(widthED, SIGNAL(returnPressed()), this, SLOT(width_changed()));
88         connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), this, SLOT(width_changed()));
89         connect(closePB, SIGNAL(clicked()), this, SLOT(close_clicked()));
90         connect(borders, SIGNAL(topSet(bool)), this, SLOT(topBorder_changed()));
91         connect(borders, SIGNAL(bottomSet(bool)), this, SLOT(bottomBorder_changed()));
92         connect(borders, SIGNAL(rightSet(bool)), this, SLOT(rightBorder_changed()));
93         connect(borders, SIGNAL(leftSet(bool)), this, SLOT(leftBorder_changed()));
94         connect(rotateTabularCB, SIGNAL(clicked()), this, SLOT(rotateTabular()));
95         connect(rotateCellCB, SIGNAL(clicked()), this, SLOT(rotateCell()));
96         connect(longTabularCB, SIGNAL(clicked()), this, SLOT(longTabular()));
97
98         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
99         bc().setCancel(closePB);
100
101         bc().addReadOnly(topspaceED);
102         bc().addReadOnly(topspaceUnit);
103         bc().addReadOnly(topspaceCO);
104         bc().addReadOnly(bottomspaceED);
105         bc().addReadOnly(bottomspaceUnit);
106         bc().addReadOnly(bottomspaceCO);
107         bc().addReadOnly(interlinespaceED);
108         bc().addReadOnly(interlinespaceUnit);
109         bc().addReadOnly(interlinespaceCO);
110         bc().addReadOnly(borderDefaultRB);
111         bc().addReadOnly(booktabsRB);
112
113         bc().addReadOnly(multicolumnCB);
114         bc().addReadOnly(rotateCellCB);
115         bc().addReadOnly(rotateTabularCB);
116         bc().addReadOnly(specialAlignmentED);
117         bc().addReadOnly(widthED);
118         bc().addReadOnly(widthUnit);
119         bc().addReadOnly(hAlignCB);
120         bc().addReadOnly(vAlignCB);
121         bc().addReadOnly(borderSetPB);
122         bc().addReadOnly(borderUnsetPB);
123         bc().addReadOnly(borders);
124         bc().addReadOnly(longTabularCB);
125         bc().addReadOnly(headerStatusCB);
126         bc().addReadOnly(headerBorderAboveCB);
127         bc().addReadOnly(headerBorderBelowCB);
128         bc().addReadOnly(firstheaderStatusCB);
129         bc().addReadOnly(firstheaderBorderAboveCB);
130         bc().addReadOnly(firstheaderBorderBelowCB);
131         bc().addReadOnly(firstheaderNoContentsCB);
132         bc().addReadOnly(footerStatusCB);
133         bc().addReadOnly(footerBorderAboveCB);
134         bc().addReadOnly(footerBorderBelowCB);
135         bc().addReadOnly(lastfooterStatusCB);
136         bc().addReadOnly(lastfooterBorderAboveCB);
137         bc().addReadOnly(lastfooterBorderBelowCB);
138         bc().addReadOnly(lastfooterNoContentsCB);
139         bc().addReadOnly(newpageCB);
140
141         // initialize the length validator
142         bc().addCheckedLineEdit(widthED, fixedWidthColLA);
143         bc().addCheckedLineEdit(topspaceED, topspaceLA);
144         bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA);
145         bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA);
146 }
147
148
149 ControlTabular & GuiTabularDialog::controller()
150 {
151         return static_cast<ControlTabular &>(GuiDialog::controller());
152 }
153
154
155 void GuiTabularDialog::change_adaptor()
156 {
157         changed();
158 }
159
160
161 void GuiTabularDialog::closeEvent(QCloseEvent * e)
162 {
163         slotClose();
164         e->accept();
165 }
166
167
168 void GuiTabularDialog::booktabsChanged(bool)
169 {
170         changed();
171         controller().booktabs(booktabsRB->isChecked());
172         update_borders();
173 }
174
175
176 void GuiTabularDialog::topspace_changed()
177 {
178         switch(topspaceCO->currentIndex()) {
179                 case 0: {
180                         controller().set(Tabular::SET_TOP_SPACE, "");
181                                 topspaceED->setEnabled(false);
182                                 topspaceUnit->setEnabled(false);
183                         break;
184                 }
185                 case 1: {
186                         controller().set(Tabular::SET_TOP_SPACE, "default");
187                         topspaceED->setEnabled(false);
188                         topspaceUnit->setEnabled(false);
189                         break;
190                 }
191                 case 2: {
192                         if (!topspaceED->text().isEmpty())
193                                 controller().set(Tabular::SET_TOP_SPACE,
194                                         widgetsToLength(topspaceED, topspaceUnit));
195                         if (!bc().policy().isReadOnly()) {
196                                 topspaceED->setEnabled(true);
197                                 topspaceUnit->setEnabled(true);
198                         }
199                         break;
200                 }
201         }
202         changed();
203 }
204
205
206 void GuiTabularDialog::bottomspace_changed()
207 {
208         switch(bottomspaceCO->currentIndex()) {
209                 case 0: {
210                         controller().set(Tabular::SET_BOTTOM_SPACE, "");
211                                 bottomspaceED->setEnabled(false);
212                                 bottomspaceUnit->setEnabled(false);
213                         break;
214                 }
215                 case 1: {
216                         controller().set(Tabular::SET_BOTTOM_SPACE, "default");
217                         bottomspaceED->setEnabled(false);
218                         bottomspaceUnit->setEnabled(false);
219                         break;
220                 }
221                 case 2: {
222                         if (!bottomspaceED->text().isEmpty())
223                                 controller().set(Tabular::SET_BOTTOM_SPACE,
224                                         widgetsToLength(bottomspaceED, bottomspaceUnit));
225                         if (!bc().policy().isReadOnly()) {
226                                 bottomspaceED->setEnabled(true);
227                                 bottomspaceUnit->setEnabled(true);
228                         }
229                         break;
230                 }
231         }
232         changed();
233 }
234
235
236 void GuiTabularDialog::interlinespace_changed()
237 {
238         switch(interlinespaceCO->currentIndex()) {
239                 case 0: {
240                         controller().set(Tabular::SET_INTERLINE_SPACE, "");
241                                 interlinespaceED->setEnabled(false);
242                                 interlinespaceUnit->setEnabled(false);
243                         break;
244                 }
245                 case 1: {
246                         controller().set(Tabular::SET_INTERLINE_SPACE, "default");
247                         interlinespaceED->setEnabled(false);
248                         interlinespaceUnit->setEnabled(false);
249                         break;
250                 }
251                 case 2: {
252                         if (!interlinespaceED->text().isEmpty())
253                                 controller().set(Tabular::SET_INTERLINE_SPACE,
254                                         widgetsToLength(interlinespaceED, interlinespaceUnit));
255                         if (!bc().policy().isReadOnly()) {
256                                 interlinespaceED->setEnabled(true);
257                                 interlinespaceUnit->setEnabled(true);
258                         }
259                         break;
260                 }
261         }
262         changed();
263 }
264
265
266 void GuiTabularDialog::close_clicked()
267 {
268         closeGUI();
269         slotClose();
270 }
271
272
273 void GuiTabularDialog::borderSet_clicked()
274 {
275         controller().set(Tabular::SET_ALL_LINES);
276         update_borders();
277         changed();
278 }
279
280
281 void GuiTabularDialog::borderUnset_clicked()
282 {
283         controller().set(Tabular::UNSET_ALL_LINES);
284         update_borders();
285         changed();
286 }
287
288
289 void GuiTabularDialog::leftBorder_changed()
290 {
291         controller().toggleLeftLine();
292         changed();
293 }
294
295
296 void GuiTabularDialog::rightBorder_changed()
297 {
298         controller().toggleRightLine();
299         changed();
300 }
301
302
303 void GuiTabularDialog::topBorder_changed()
304 {
305         controller().toggleTopLine();
306         changed();
307 }
308
309
310 void GuiTabularDialog::bottomBorder_changed()
311 {
312         controller().toggleBottomLine();
313         changed();
314 }
315
316
317 void GuiTabularDialog::specialAlignment_changed()
318 {
319         string special = fromqstr(specialAlignmentED->text());
320         controller().setSpecial(special);
321         changed();
322 }
323
324
325 void GuiTabularDialog::width_changed()
326 {
327         changed();
328         string const width = widgetsToLength(widthED, widthUnit);
329         controller().setWidth(width);
330 }
331
332
333 void GuiTabularDialog::multicolumn_clicked()
334 {
335         controller().toggleMultiColumn();
336         changed();
337 }
338
339
340 void GuiTabularDialog::rotateTabular()
341 {
342         controller().rotateTabular(rotateTabularCB->isChecked());
343         changed();
344 }
345
346
347 void GuiTabularDialog::rotateCell()
348 {
349         controller().rotateCell(rotateCellCB->isChecked());
350         changed();
351 }
352
353
354 void GuiTabularDialog::hAlign_changed(int align)
355 {
356         ControlTabular::HALIGN h = ControlTabular::LEFT;
357
358         switch (align) {
359                 case 0: h = ControlTabular::LEFT; break;
360                 case 1: h = ControlTabular::CENTER; break;
361                 case 2: h = ControlTabular::RIGHT; break;
362                 case 3: h = ControlTabular::BLOCK; break;
363         }
364
365         controller().halign(h);
366 }
367
368
369 void GuiTabularDialog::vAlign_changed(int align)
370 {
371         ControlTabular::VALIGN v = ControlTabular::TOP;
372
373         switch (align) {
374                 case 0: v = ControlTabular::TOP; break;
375                 case 1: v = ControlTabular::MIDDLE; break;
376                 case 2: v = ControlTabular::BOTTOM; break;
377         }
378
379         controller().valign(v);
380 }
381
382
383 void GuiTabularDialog::longTabular()
384 {
385         controller().longTabular(longTabularCB->isChecked());
386         changed();
387 }
388
389
390 void GuiTabularDialog::ltNewpage_clicked()
391 {
392         controller().set(Tabular::SET_LTNEWPAGE);
393         changed();
394 }
395
396
397 void GuiTabularDialog::ltHeaderStatus_clicked()
398 {
399         bool enable(headerStatusCB->isChecked());
400         if (enable)
401                 controller().set(Tabular::SET_LTHEAD, "");
402         else
403                 controller().set(Tabular::UNSET_LTHEAD, "");
404         headerBorderAboveCB->setEnabled(enable);
405         headerBorderBelowCB->setEnabled(enable);
406         firstheaderNoContentsCB->setEnabled(enable);
407         changed();
408 }
409
410
411 void GuiTabularDialog::ltHeaderBorderAbove_clicked()
412 {
413         if (headerBorderAboveCB->isChecked())
414                 controller().set(Tabular::SET_LTHEAD, "dl_above");
415         else
416                 controller().set(Tabular::UNSET_LTHEAD, "dl_above");
417         changed();
418 }
419
420
421 void GuiTabularDialog::ltHeaderBorderBelow_clicked()
422 {
423         if (headerBorderBelowCB->isChecked())
424                 controller().set(Tabular::SET_LTHEAD, "dl_below");
425         else
426                 controller().set(Tabular::UNSET_LTHEAD, "dl_below");
427         changed();
428 }
429
430
431 void GuiTabularDialog::ltFirstHeaderBorderAbove_clicked()
432 {
433         if (firstheaderBorderAboveCB->isChecked())
434                 controller().set(Tabular::SET_LTFIRSTHEAD, "dl_above");
435         else
436                 controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
437         changed();
438 }
439
440
441 void GuiTabularDialog::ltFirstHeaderBorderBelow_clicked()
442 {
443         if (firstheaderBorderBelowCB->isChecked())
444                 controller().set(Tabular::SET_LTFIRSTHEAD, "dl_below");
445         else
446                 controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
447         changed();
448 }
449
450
451 void GuiTabularDialog::ltFirstHeaderStatus_clicked()
452 {
453         bool enable(firstheaderStatusCB->isChecked());
454         if (enable)
455                 controller().set(Tabular::SET_LTFIRSTHEAD, "");
456         else
457                 controller().set(Tabular::UNSET_LTFIRSTHEAD, "");
458         firstheaderBorderAboveCB->setEnabled(enable);
459         firstheaderBorderBelowCB->setEnabled(enable);
460         changed();
461 }
462
463
464 void GuiTabularDialog::ltFirstHeaderEmpty_clicked()
465 {
466         bool enable(firstheaderNoContentsCB->isChecked());
467         if (enable)
468                 controller().set(Tabular::SET_LTFIRSTHEAD, "empty");
469         else
470                 controller().set(Tabular::UNSET_LTFIRSTHEAD, "empty");
471         firstheaderStatusCB->setEnabled(!enable);
472         firstheaderBorderAboveCB->setEnabled(!enable);
473         firstheaderBorderBelowCB->setEnabled(!enable);
474         changed();
475 }
476
477
478 void GuiTabularDialog::ltFooterStatus_clicked()
479 {
480         bool enable(footerStatusCB->isChecked());
481         if (enable)
482                 controller().set(Tabular::SET_LTFOOT, "");
483         else
484                 controller().set(Tabular::UNSET_LTFOOT, "");
485         footerBorderAboveCB->setEnabled(enable);
486         footerBorderBelowCB->setEnabled(enable);
487         lastfooterNoContentsCB->setEnabled(enable);
488         changed();
489 }
490
491
492 void GuiTabularDialog::ltFooterBorderAbove_clicked()
493 {
494         if (footerBorderAboveCB->isChecked())
495                 controller().set(Tabular::SET_LTFOOT, "dl_above");
496         else
497                 controller().set(Tabular::UNSET_LTFOOT, "dl_above");
498         changed();
499 }
500
501
502 void GuiTabularDialog::ltFooterBorderBelow_clicked()
503 {
504         if (footerBorderBelowCB->isChecked())
505                 controller().set(Tabular::SET_LTFOOT, "dl_below");
506         else
507                 controller().set(Tabular::UNSET_LTFOOT, "dl_below");
508         changed();
509 }
510
511
512 void GuiTabularDialog::ltLastFooterStatus_clicked()
513 {
514         bool enable(lastfooterStatusCB->isChecked());
515         if (enable)
516                 controller().set(Tabular::SET_LTLASTFOOT, "");
517         else
518                 controller().set(Tabular::UNSET_LTLASTFOOT, "");
519         lastfooterBorderAboveCB->setEnabled(enable);
520         lastfooterBorderBelowCB->setEnabled(enable);
521         changed();
522 }
523
524
525 void GuiTabularDialog::ltLastFooterBorderAbove_clicked()
526 {
527         if (lastfooterBorderAboveCB->isChecked())
528                 controller().set(Tabular::SET_LTLASTFOOT, "dl_above");
529         else
530                 controller().set(Tabular::UNSET_LTLASTFOOT, "dl_above");
531         changed();
532 }
533
534
535 void GuiTabularDialog::ltLastFooterBorderBelow_clicked()
536 {
537         if (lastfooterBorderBelowCB->isChecked())
538                 controller().set(Tabular::SET_LTLASTFOOT, "dl_below");
539         else
540                 controller().set(Tabular::UNSET_LTLASTFOOT, "dl_below");
541         changed();
542 }
543
544
545 void GuiTabularDialog::ltLastFooterEmpty_clicked()
546 {
547         bool enable(lastfooterNoContentsCB->isChecked());
548         if (enable)
549                 controller().set(Tabular::SET_LTLASTFOOT, "empty");
550         else
551                 controller().set(Tabular::UNSET_LTLASTFOOT, "empty");
552         lastfooterStatusCB->setEnabled(!enable);
553         lastfooterBorderAboveCB->setEnabled(!enable);
554         lastfooterBorderBelowCB->setEnabled(!enable);
555         changed();
556 }
557
558
559 void GuiTabularDialog::update_borders()
560 {
561         Tabular const & tabular = controller().tabular();
562         Tabular::idx_type const cell = controller().getActiveCell();
563         bool const isMulticolumnCell = tabular.isMultiColumn(cell);
564
565         if (!isMulticolumnCell) {
566                 borders->setLeftEnabled(true);
567                 borders->setRightEnabled(true);
568                 borders->setTop(tabular.topLine(cell, true));
569                 borders->setBottom(tabular.bottomLine(cell, true));
570                 borders->setLeft(tabular.leftLine(cell, true));
571                 borders->setRight(tabular.rightLine(cell, true));
572                 // repaint the setborder widget
573                 borders->update();
574                 return;
575         }
576
577         borders->setTop(tabular.topLine(cell));
578         borders->setBottom(tabular.bottomLine(cell));
579         // pay attention to left/right lines: they are only allowed
580         // to set if we are in first/last cell of row or if the left/right
581         // cell is also a multicolumn.
582         if (tabular.isFirstCellInRow(cell) || tabular.isMultiColumn(cell - 1)) {
583                 borders->setLeftEnabled(true);
584                 borders->setLeft(tabular.leftLine(cell));
585         } else {
586                 borders->setLeft(false);
587                 borders->setLeftEnabled(false);
588         }
589         if (tabular.isLastCellInRow(cell) || tabular.isMultiColumn(cell + 1)) {
590                 borders->setRightEnabled(true);
591                 borders->setRight(tabular.rightLine(cell));
592         } else {
593                 borders->setRight(false);
594                 borders->setRightEnabled(false);
595         }
596         // repaint the setborder widget
597         borders->update();
598 }
599
600
601 void GuiTabularDialog::updateContents()
602 {
603         controller().initialiseParams(string());
604
605         Tabular const & tabular(controller().tabular());
606         Tabular::idx_type const cell = controller().getActiveCell();
607
608         Tabular::row_type const row = tabular.cellRow(cell);
609         Tabular::col_type const col = tabular.cellColumn(cell);
610
611         tabularRowED->setText(QString::number(row + 1));
612         tabularColumnED->setText(QString::number(col + 1));
613
614         bool const multicol(tabular.isMultiColumn(cell));
615
616         multicolumnCB->setChecked(multicol);
617
618         rotateCellCB->setChecked(tabular.getRotateCell(cell));
619         rotateTabularCB->setChecked(tabular.getRotateTabular());
620
621         longTabularCB->setChecked(tabular.isLongTabular());
622
623         update_borders();
624
625         Length pwidth;
626         docstring special;
627
628         if (multicol) {
629                 special = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
630                 pwidth = tabular.getMColumnPWidth(cell);
631         } else {
632                 special = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
633                 pwidth = tabular.getColumnPWidth(cell);
634         }
635
636         specialAlignmentED->setText(toqstr(special));
637
638         bool const isReadonly = bc().policy().isReadOnly();
639         specialAlignmentED->setEnabled(!isReadonly);
640
641         Length::UNIT default_unit =
642                 controller().useMetricUnits() ? Length::CM : Length::IN;
643
644         borderDefaultRB->setChecked(!tabular.useBookTabs());
645         booktabsRB->setChecked(tabular.useBookTabs());
646
647         if (tabular.row_info[row].top_space.empty()
648             && !tabular.row_info[row].top_space_default) {
649                 topspaceCO->setCurrentIndex(0);
650         } else if (tabular.row_info[row].top_space_default) {
651                 topspaceCO->setCurrentIndex(1);
652         } else {
653                 topspaceCO->setCurrentIndex(2);
654                 lengthToWidgets(topspaceED,
655                                 topspaceUnit,
656                                 tabular.row_info[row].top_space.asString(),
657                                 default_unit);
658         }
659         topspaceED->setEnabled(!isReadonly
660                 && (topspaceCO->currentIndex() == 2));
661         topspaceUnit->setEnabled(!isReadonly
662                 && (topspaceCO->currentIndex() == 2));
663         topspaceCO->setEnabled(!isReadonly);
664
665         if (tabular.row_info[row].bottom_space.empty()
666             && !tabular.row_info[row].bottom_space_default) {
667                 bottomspaceCO->setCurrentIndex(0);
668         } else if (tabular.row_info[row].bottom_space_default) {
669                 bottomspaceCO->setCurrentIndex(1);
670         } else {
671                 bottomspaceCO->setCurrentIndex(2);
672                 lengthToWidgets(bottomspaceED,
673                                 bottomspaceUnit,
674                                 tabular.row_info[row].bottom_space.asString(),
675                                 default_unit);
676         }
677         bottomspaceED->setEnabled(!isReadonly
678                 && (bottomspaceCO->currentIndex() == 2));
679         bottomspaceUnit->setEnabled(!isReadonly
680                 && (bottomspaceCO->currentIndex() == 2));
681         bottomspaceCO->setEnabled(!isReadonly);
682
683         if (tabular.row_info[row].interline_space.empty()
684             && !tabular.row_info[row].interline_space_default) {
685                 interlinespaceCO->setCurrentIndex(0);
686         } else if (tabular.row_info[row].interline_space_default) {
687                 interlinespaceCO->setCurrentIndex(1);
688         } else {
689                 interlinespaceCO->setCurrentIndex(2);
690                 lengthToWidgets(interlinespaceED,
691                                 interlinespaceUnit,
692                                 tabular.row_info[row].interline_space.asString(),
693                                 default_unit);
694         }
695         interlinespaceED->setEnabled(!isReadonly
696                 && (interlinespaceCO->currentIndex() == 2));
697         interlinespaceUnit->setEnabled(!isReadonly
698                 && (interlinespaceCO->currentIndex() == 2));
699         interlinespaceCO->setEnabled(!isReadonly);
700
701         string colwidth;
702         if (!pwidth.zero())
703                 colwidth = pwidth.asString();
704         lengthToWidgets(widthED, widthUnit,
705                 colwidth, default_unit);
706
707         widthED->setEnabled(!isReadonly);
708         widthUnit->setEnabled(!isReadonly);
709
710         hAlignCB->clear();
711         hAlignCB->addItem(qt_("Left"));
712         hAlignCB->addItem(qt_("Center"));
713         hAlignCB->addItem(qt_("Right"));
714         if (!multicol && !pwidth.zero())
715                 hAlignCB->addItem(qt_("Justified"));
716
717         int align = 0;
718         switch (tabular.getAlignment(cell)) {
719         case LYX_ALIGN_LEFT:
720                 align = 0;
721                 break;
722         case LYX_ALIGN_CENTER:
723                 align = 1;
724                 break;
725         case LYX_ALIGN_RIGHT:
726                 align = 2;
727                 break;
728         case LYX_ALIGN_BLOCK:
729         {
730                 if (!multicol && !pwidth.zero())
731                         align = 3;
732                 break;
733         }
734         default:
735                 align = 0;
736                 break;
737         }
738         hAlignCB->setCurrentIndex(align);
739
740         int valign = 0;
741         switch (tabular.getVAlignment(cell)) {
742         case Tabular::LYX_VALIGN_TOP:
743                 valign = 0;
744                 break;
745         case Tabular::LYX_VALIGN_MIDDLE:
746                 valign = 1;
747                 break;
748         case Tabular::LYX_VALIGN_BOTTOM:
749                 valign = 2;
750                 break;
751         default:
752                 valign = 1;
753                 break;
754         }
755         if (pwidth.zero())
756                 valign = 1;
757         vAlignCB->setCurrentIndex(valign);
758
759         hAlignCB->setEnabled(true);
760         vAlignCB->setEnabled(!pwidth.zero());
761
762         if (!tabular.isLongTabular()) {
763                 headerStatusCB->setChecked(false);
764                 headerBorderAboveCB->setChecked(false);
765                 headerBorderBelowCB->setChecked(false);
766                 firstheaderStatusCB->setChecked(false);
767                 firstheaderBorderAboveCB->setChecked(false);
768                 firstheaderBorderBelowCB->setChecked(false);
769                 firstheaderNoContentsCB->setChecked(false);
770                 footerStatusCB->setChecked(false);
771                 footerBorderAboveCB->setChecked(false);
772                 footerBorderBelowCB->setChecked(false);
773                 lastfooterStatusCB->setChecked(false);
774                 lastfooterBorderAboveCB->setChecked(false);
775                 lastfooterBorderBelowCB->setChecked(false);
776                 lastfooterNoContentsCB->setChecked(false);
777                 newpageCB->setChecked(false);
778                 newpageCB->setEnabled(false);
779                 return;
780         }
781
782         Tabular::ltType ltt;
783         bool use_empty;
784         bool row_set = tabular.getRowOfLTHead(row, ltt);
785         headerStatusCB->setChecked(row_set);
786         if (ltt.set) {
787                 headerBorderAboveCB->setChecked(ltt.topDL);
788                 headerBorderBelowCB->setChecked(ltt.bottomDL);
789                 use_empty = true;
790         } else {
791                 headerBorderAboveCB->setChecked(false);
792                 headerBorderBelowCB->setChecked(false);
793                 headerBorderAboveCB->setEnabled(false);
794                 headerBorderBelowCB->setEnabled(false);
795                 firstheaderNoContentsCB->setChecked(false);
796                 firstheaderNoContentsCB->setEnabled(false);
797                 use_empty = false;
798         }
799
800         row_set = tabular.getRowOfLTFirstHead(row, ltt);
801         firstheaderStatusCB->setChecked(row_set);
802         if (ltt.set && (!ltt.empty || !use_empty)) {
803                 firstheaderBorderAboveCB->setChecked(ltt.topDL);
804                 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
805         } else {
806                 firstheaderBorderAboveCB->setEnabled(false);
807                 firstheaderBorderBelowCB->setEnabled(false);
808                 firstheaderBorderAboveCB->setChecked(false);
809                 firstheaderBorderBelowCB->setChecked(false);
810                 if (use_empty) {
811                         firstheaderNoContentsCB->setChecked(ltt.empty);
812                         if (ltt.empty)
813                                 firstheaderStatusCB->setEnabled(false);
814                 }
815         }
816
817         row_set = tabular.getRowOfLTFoot(row, ltt);
818         footerStatusCB->setChecked(row_set);
819         if (ltt.set) {
820                 footerBorderAboveCB->setChecked(ltt.topDL);
821                 footerBorderBelowCB->setChecked(ltt.bottomDL);
822                 use_empty = true;
823         } else {
824                 footerBorderAboveCB->setChecked(false);
825                 footerBorderBelowCB->setChecked(false);
826                 footerBorderAboveCB->setEnabled(false);
827                 footerBorderBelowCB->setEnabled(false);
828                 lastfooterNoContentsCB->setChecked(false);
829                 lastfooterNoContentsCB->setEnabled(false);
830                 use_empty = false;
831         }
832
833         row_set = tabular.getRowOfLTLastFoot(row, ltt);
834                 lastfooterStatusCB->setChecked(row_set);
835         if (ltt.set && (!ltt.empty || !use_empty)) {
836                 lastfooterBorderAboveCB->setChecked(ltt.topDL);
837                 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
838         } else {
839                 lastfooterBorderAboveCB->setEnabled(false);
840                 lastfooterBorderBelowCB->setEnabled(false);
841                 lastfooterBorderAboveCB->setChecked(false);
842                 lastfooterBorderBelowCB->setChecked(false);
843                 if (use_empty) {
844                         lastfooterNoContentsCB->setChecked(ltt.empty);
845                         if (ltt.empty)
846                                 lastfooterStatusCB->setEnabled(false);
847                 }
848         }
849         newpageCB->setChecked(tabular.getLTNewPage(row));
850 }
851
852
853 void GuiTabularDialog::closeGUI()
854 {
855         // ugly hack to auto-apply the stuff that hasn't been
856         // yet. don't let this continue to exist ...
857
858         // Subtle here, we must /not/ apply any changes and
859         // then refer to tabular, as it will have been freed
860         // since the changes update the actual controller().tabular()
861         Tabular const & tabular(controller().tabular());
862
863         // apply the fixed width values
864         Tabular::idx_type const cell = controller().getActiveCell();
865         bool const multicol = tabular.isMultiColumn(cell);
866         string width = widgetsToLength(widthED, widthUnit);
867         string width2;
868
869         Length llen = tabular.getColumnPWidth(cell);
870         Length llenMulti = tabular.getMColumnPWidth(cell);
871
872         if (multicol && !llenMulti.zero())
873                         width2 = llenMulti.asString();
874         else if (!multicol && !llen.zero())
875                         width2 = llen.asString();
876
877         // apply the special alignment
878         docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text());
879         docstring sa2;
880
881         if (multicol)
882                 sa2 = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
883         else
884                 sa2 = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
885
886         if (sa1 != sa2) {
887                 if (multicol)
888                         controller().set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
889                 else
890                         controller().set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
891         }
892
893         if (width != width2) {
894                 if (multicol)
895                         controller().set(Tabular::SET_MPWIDTH, width);
896                 else
897                         controller().set(Tabular::SET_PWIDTH, width);
898         }
899
900         /* DO WE NEED THIS?
901         switch (topspaceCO->currentIndex()) {
902                 case 0:
903                         controller().set(Tabular::SET_TOP_SPACE, "");
904                         break;
905                 case 1:
906                         controller().set(Tabular::SET_TOP_SPACE, "default");
907                         break;
908                 case 2:
909                         controller().set(Tabular::SET_TOP_SPACE,
910                                 widgetsToLength(topspaceED,
911                                         topspaceUnit));
912                         break;
913         }
914
915         switch (bottomspaceCO->currentIndex()) {
916                 case 0:
917                         controller().set(Tabular::SET_BOTTOM_SPACE, "");
918                         break;
919                 case 1:
920                         controller().set(Tabular::SET_BOTTOM_SPACE, "default");
921                         break;
922                 case 2:
923                         controller().set(Tabular::SET_BOTTOM_SPACE,
924                                 widgetsToLength(bottomspaceED,
925                                         bottomspaceUnit));
926                         break;
927         }
928
929         switch (interlinespaceCO->currentIndex()) {
930                 case 0:
931                         controller().set(Tabular::SET_INTERLINE_SPACE, "");
932                         break;
933                 case 1:
934                         controller().set(Tabular::SET_INTERLINE_SPACE, "default");
935                         break;
936                 case 2:
937                         controller().set(Tabular::SET_INTERLINE_SPACE,
938                                 widgetsToLength(interlinespaceED,
939                                         interlinespaceUnit));
940                         break;
941         }
942 */
943 }
944
945 } // namespace frontend
946 } // namespace lyx
947
948 #include "GuiTabular_moc.cpp"