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