]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiTabular.cpp
#10571 improved handling of WM's signal when switching from or to full-screen window
[features.git] / src / frontends / qt / 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  * \author Uwe Stöhr
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "GuiTabular.h"
17
18 #include "GuiApplication.h"
19 #include "GuiSetBorder.h"
20 #include "GuiView.h"
21 #include "LengthCombo.h"
22 #include "qt_helpers.h"
23 #include "Validator.h"
24
25 #include "Buffer.h"
26 #include "BufferView.h"
27 #include "Cursor.h"
28 #include "FuncRequest.h"
29 #include "FuncStatus.h"
30 #include "Language.h"
31 #include "LyX.h"
32 #include "LyXRC.h"
33
34 #include "insets/InsetTabular.h"
35
36 #include "support/convert.h"
37 #include "support/debug.h"
38 #include "support/lstrings.h"
39
40 #include <QCheckBox>
41 #include <QPushButton>
42 #include <QRadioButton>
43 #include <QLineEdit>
44
45 using namespace std;
46
47 namespace lyx {
48 namespace frontend {
49
50 GuiTabular::GuiTabular(QWidget * parent)
51         : InsetParamsWidget(parent), firstheader_suppressable_(false),
52           lastfooter_suppressable_(false), orig_leftborder_(GuiSetBorder::LINE_UNDEF),
53           orig_rightborder_(GuiSetBorder::LINE_UNDEF), lastrow_(0)
54
55 {
56         setupUi(this);
57
58         tabularWidthED->setValidator(unsignedLengthValidator(tabularWidthED));
59         columnWidthED->setValidator(unsignedLengthValidator(columnWidthED));
60         multirowOffsetED->setValidator(new LengthValidator(multirowOffsetED));
61         topspaceED->setValidator(new LengthValidator(topspaceED));
62         bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
63         interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
64
65         tabularWidthUnitLC->setCurrentItem(Length::defaultUnit());
66         columnWidthUnitLC->setCurrentItem(Length::defaultUnit());
67         multirowOffsetUnitLC->setCurrentItem(Length::defaultUnit());
68         topspaceUnitLC->setCurrentItem(Length::defaultUnit());
69         bottomspaceUnitLC->setCurrentItem(Length::defaultUnit());
70         interlinespaceUnitLC->setCurrentItem(Length::defaultUnit());
71
72         connect(topspaceED, SIGNAL(textEdited(const QString &)),
73                 this, SLOT(checkEnabled()));
74         connect(topspaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
75                 this, SLOT(checkEnabled()));
76         connect(bottomspaceED, SIGNAL(textEdited(const QString &)),
77                 this, SLOT(checkEnabled()));
78         connect(bottomspaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
79                 this, SLOT(checkEnabled()));
80         connect(interlinespaceED, SIGNAL(textEdited(const QString &)),
81                 this, SLOT(checkEnabled()));
82         connect(interlinespaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
83                 this, SLOT(checkEnabled()));
84         connect(booktabsRB, SIGNAL(clicked(bool)),
85                 this, SLOT(booktabs_toggled(bool)));
86         connect(borderDefaultRB, SIGNAL(clicked(bool)),
87                 this, SLOT(nonbooktabs_toggled(bool)));
88         connect(borderSetPB, SIGNAL(clicked()),
89                 this, SLOT(borderSet_clicked()));
90         connect(borderUnsetPB, SIGNAL(clicked()),
91                 this, SLOT(borderUnset_clicked()));
92         connect(resetFormalCB, SIGNAL(clicked()),
93                 this, SLOT(checkEnabled()));
94         connect(hAlignCO, SIGNAL(activated(int)),
95                 this, SLOT(checkEnabled()));
96         connect(vAlignCO, SIGNAL(activated(int)),
97                 this, SLOT(checkEnabled()));
98         connect(multicolumnCB, SIGNAL(clicked()),
99                 this, SLOT(checkEnabled()));
100         connect(multirowCB, SIGNAL(clicked()),
101                 this, SLOT(checkEnabled()));
102         connect(multirowOffsetED, SIGNAL(textEdited(const QString &)),
103                 this, SLOT(checkEnabled()));
104         connect(multirowOffsetUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
105                 this, SLOT(checkEnabled()));
106         connect(newpageCB, SIGNAL(clicked()),
107                 this, SLOT(checkEnabled()));
108         connect(headerStatusCB, SIGNAL(clicked()),
109                 this, SLOT(checkEnabled()));
110         connect(headerBorderAboveCB, SIGNAL(clicked()),
111                 this, SLOT(checkEnabled()));
112         connect(headerBorderBelowCB, SIGNAL(clicked()),
113                 this, SLOT(checkEnabled()));
114         connect(firstheaderStatusCB, SIGNAL(clicked()),
115                 this, SLOT(checkEnabled()));
116         connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
117                 this, SLOT(checkEnabled()));
118         connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
119                 this, SLOT(checkEnabled()));
120         connect(firstheaderNoContentsCB, SIGNAL(clicked()),
121                 this, SLOT(checkEnabled()));
122         connect(footerStatusCB, SIGNAL(clicked()),
123                 this, SLOT(checkEnabled()));
124         connect(footerBorderAboveCB, SIGNAL(clicked()),
125                 this, SLOT(checkEnabled()));
126         connect(footerBorderBelowCB, SIGNAL(clicked()),
127                 this, SLOT(checkEnabled()));
128         connect(lastfooterStatusCB, SIGNAL(clicked()),
129                 this, SLOT(checkEnabled()));
130         connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
131                 this, SLOT(checkEnabled()));
132         connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
133                 this, SLOT(checkEnabled()));
134         connect(lastfooterNoContentsCB, SIGNAL(clicked()),
135                 this, SLOT(checkEnabled()));
136         connect(captionStatusCB, SIGNAL(clicked()),
137                 this, SLOT(checkEnabled()));
138         connect(specialAlignmentED, SIGNAL(textEdited(const QString &)),
139                 this, SLOT(checkEnabled()));
140         connect(columnWidthED, SIGNAL(textEdited(const QString &)),
141                 this, SLOT(checkEnabled()));
142         connect(columnWidthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
143                 this, SLOT(checkEnabled()));
144         connect(borders, SIGNAL(topSet()),
145                 this, SLOT(checkEnabled()));
146         connect(borders, SIGNAL(bottomSet()),
147                 this, SLOT(checkEnabled()));
148         connect(borders, SIGNAL(rightSet()),
149                 this, SLOT(checkEnabled()));
150         connect(borders, SIGNAL(leftSet()),
151                 this, SLOT(checkEnabled()));
152         connect(borders, SIGNAL(topLTSet()),
153                 this, SLOT(checkEnabled()));
154         connect(borders, SIGNAL(topRTSet()),
155                 this, SLOT(checkEnabled()));
156         connect(borders, SIGNAL(bottomLTSet()),
157                 this, SLOT(checkEnabled()));
158         connect(borders, SIGNAL(bottomRTSet()),
159                 this, SLOT(checkEnabled()));
160         connect(rotateTabularCB, SIGNAL(clicked()),
161                 this, SLOT(checkEnabled()));
162         connect(rotateTabularAngleSB, SIGNAL(valueChanged(int)),
163                 this, SLOT(checkEnabled()));
164         connect(rotateCellCB, SIGNAL(clicked()),
165                 this, SLOT(checkEnabled()));
166         connect(rotateCellAngleSB, SIGNAL(valueChanged(int)),
167                 this, SLOT(checkEnabled()));
168         connect(TableAlignCO, SIGNAL(activated(int)),
169                 this, SLOT(checkEnabled()));
170         connect(longTabularCB, SIGNAL(clicked()),
171                 this, SLOT(checkEnabled()));
172         connect(leftRB, SIGNAL(clicked()),
173                 this, SLOT(checkEnabled()));
174         connect(centerRB, SIGNAL(clicked()),
175                 this, SLOT(checkEnabled()));
176         connect(rightRB, SIGNAL(clicked()),
177                 this, SLOT(checkEnabled()));
178         connect(tabularWidthED, SIGNAL(textEdited(const QString &)),
179                 this, SLOT(checkEnabled()));
180
181         decimalPointED->setValidator(new QRegExpValidator(QRegExp("\\S"), this));
182         decimalPointED->setMaxLength(1);
183
184         // initialize the length validator
185         addCheckedWidget(columnWidthED, columnWidthLA);
186         addCheckedWidget(multirowOffsetED, multirowOffsetLA);
187         addCheckedWidget(topspaceED, topspaceLA);
188         addCheckedWidget(bottomspaceED, bottomspaceLA);
189         addCheckedWidget(interlinespaceED, interlinespaceLA);
190         addCheckedWidget(tabularWidthED, tabularWidthLA);
191 }
192
193
194 void GuiTabular::on_topspaceCO_activated(int index)
195 {
196         bool const enable = (index == 2);
197         topspaceED->setEnabled(enable);
198         topspaceUnitLC->setEnabled(enable);
199 }
200
201
202 void GuiTabular::on_bottomspaceCO_activated(int index)
203 {
204         bool const enable = (index == 2);
205         bottomspaceED->setEnabled(enable);
206         bottomspaceUnitLC->setEnabled(enable);
207 }
208
209
210 void GuiTabular::on_interlinespaceCO_activated(int index)
211 {
212         bool const enable = (index == 2);
213         interlinespaceED->setEnabled(enable);
214         interlinespaceUnitLC->setEnabled(enable);
215 }
216
217
218 void GuiTabular::on_columnTypeCO_activated(int index)
219 {
220         checkEnabled();
221         if (index == 2)
222                 columnWidthED->setFocus();
223 }
224
225
226 void GuiTabular::enableWidgets() const
227 {
228         // if there is a LaTeX argument, the width and alignment will be overwritten
229         // therefore disable them in this case
230         bool const fixed = specialAlignmentED->text().isEmpty()
231                         && columnTypeCO->currentIndex() == 2;
232         columnWidthED->setEnabled(fixed);
233         columnWidthUnitLC->setEnabled(fixed);
234         // if the column has a width, multirows are always left-aligned
235         // therefore disable hAlignCB in this case
236         hAlignCO->setEnabled(!(multirowCB->isChecked()
237                 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty())
238                 && specialAlignmentED->text().isEmpty());
239         // decimal alignment is only possible for non-multicol and non-multirow cells
240         if ((multicolumnCB->isChecked() || multirowCB->isChecked() || columnTypeCO->currentIndex() == 1)
241                 && hAlignCO->findData(toqstr("decimal")))
242                 hAlignCO->removeItem(hAlignCO->findData(toqstr("decimal")));
243         else if (!multicolumnCB->isChecked() && !multirowCB->isChecked()
244                 && hAlignCO->findData(toqstr("decimal")) == -1)
245                 hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
246         bool const dalign =
247                 hAlignCO->itemData(hAlignCO->currentIndex()).toString() == QString("decimal");
248         decimalPointED->setEnabled(dalign);
249         decimalLA->setEnabled(dalign);
250         resetFormalCB->setEnabled(booktabsRB->isChecked());
251
252         bool const setwidth = TableAlignCO->currentText() == qt_("Middle");
253         tabularWidthLA->setEnabled(setwidth);
254         tabularWidthED->setEnabled(setwidth);
255         tabularWidthUnitLC->setEnabled(setwidth);
256
257         rotateTabularAngleSB->setEnabled(rotateTabularCB->isChecked()
258                                          && !longTabularCB->isChecked());
259         rotateCellAngleSB->setEnabled(rotateCellCB->isChecked());
260
261         bool const enable_valign =
262                 !multirowCB->isChecked()
263                 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty()
264                 && specialAlignmentED->text().isEmpty();
265         vAlignCO->setEnabled(enable_valign);
266         vAlignLA->setEnabled(enable_valign);
267
268         topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
269         topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
270         topspaceUnitLC->setEnabled(topspaceCO->currentIndex() == 2);
271         bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
272         bottomspaceUnitLC->setEnabled(bottomspaceCO->currentIndex() == 2);
273         interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
274         interlinespaceUnitLC->setEnabled(interlinespaceCO->currentIndex() == 2);
275
276         // setting as longtable is not allowed when table is inside a float
277         bool const is_tabular_star = !tabularWidthED->text().isEmpty();
278         longTabularCB->setEnabled(funcEnabled(Tabular::SET_LONGTABULAR));
279         bool const longtabular = longTabularCB->isChecked();
280         longtableGB->setEnabled(true);
281         newpageCB->setEnabled(longtabular);
282         alignmentGB->setEnabled(longtabular);
283         // longtables and tabular* cannot have a vertical alignment
284         TableAlignLA->setDisabled(is_tabular_star || longtabular);
285         TableAlignCO->setDisabled(is_tabular_star || longtabular);
286         // longtable cannot be rotated with rotating package, only
287         // with [pdf]lscape, which only supports 90 deg.
288         rotateTabularAngleSB->setDisabled(longtabular);
289
290         // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
291         // depending on the cursor position is very very unintuitive...
292         // We need some edit boxes to show which rows are header/footer/etc
293         // without having to move the cursor first.
294         headerStatusCB->setEnabled(longtabular
295                 && (headerStatusCB->isChecked() ?
296                     funcEnabled(Tabular::UNSET_LTHEAD) :
297                     funcEnabled(Tabular::SET_LTHEAD)));
298         headerBorderAboveCB->setEnabled(longtabular
299                 && headerStatusCB->isChecked());
300         headerBorderBelowCB->setEnabled(longtabular
301                 && headerStatusCB->isChecked());
302
303         // first header can only be suppressed when there is a header
304         // firstheader_suppressable_ is set in paramsToDialog
305         firstheaderNoContentsCB->setEnabled(longtabular && firstheader_suppressable_);
306         // check if setting a first header is allowed
307         // additionally check firstheaderNoContentsCB because when this is
308         // the case a first header makes no sense
309         firstheaderStatusCB->setEnabled((firstheaderStatusCB->isChecked() ?
310                    funcEnabled(Tabular::UNSET_LTFIRSTHEAD) :
311                    funcEnabled(Tabular::SET_LTFIRSTHEAD))
312                 && longtabular && !firstheaderNoContentsCB->isChecked());
313         firstheaderBorderAboveCB->setEnabled(longtabular
314                 && firstheaderStatusCB->isChecked());
315         firstheaderBorderBelowCB->setEnabled(longtabular
316                 && firstheaderStatusCB->isChecked());
317
318         footerStatusCB->setEnabled(longtabular
319                 && (footerStatusCB->isChecked() ?
320                     funcEnabled(Tabular::UNSET_LTFOOT) :
321                     funcEnabled(Tabular::SET_LTFOOT)));
322         footerBorderAboveCB->setEnabled(longtabular
323                 && footerBorderAboveCB->isChecked());
324         footerBorderBelowCB->setEnabled(longtabular
325                 && footerBorderAboveCB->isChecked());
326
327         // last footer can only be suppressed when there is a footer
328         // lastfooter_suppressable_ is set in paramsToDialog
329         lastfooterNoContentsCB->setEnabled(longtabular && lastfooter_suppressable_);
330         // check if setting a last footer is allowed
331         // additionally check lastfooterNoContentsCB because when this is
332         // the case a last footer makes no sense
333         lastfooterStatusCB->setEnabled((lastfooterStatusCB->isChecked() ?
334                    funcEnabled(Tabular::UNSET_LTLASTFOOT) :
335                    funcEnabled(Tabular::SET_LTLASTFOOT))
336                 && longtabular && !lastfooterNoContentsCB->isChecked());
337         lastfooterBorderAboveCB->setEnabled(longtabular
338                 && lastfooterBorderAboveCB->isChecked());
339         lastfooterBorderBelowCB->setEnabled(longtabular
340                 && lastfooterBorderAboveCB->isChecked());
341
342         captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)
343                 && longtabular);
344
345         multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN)
346                 && !dalign && !multirowCB->isChecked());
347         multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW)
348                 && !dalign && !multicolumnCB->isChecked());
349         bool const enable_mr = multirowCB->isChecked();
350         multirowOffsetLA->setEnabled(enable_mr);
351         multirowOffsetED->setEnabled(enable_mr);
352         multirowOffsetUnitLC->setEnabled(enable_mr);
353
354         // Vertical lines cannot be set in formal tables
355         borders->setLeftEnabled(!booktabsRB->isChecked());
356         borders->setRightEnabled(!booktabsRB->isChecked());
357         // Trimming is only allowed in booktabs and if the line is set
358         int const row = tabularRowED->text().toInt();
359         borders->setTopLeftTrimEnabled(booktabsRB->isChecked()
360                                        && borders->topLineSet()
361                                        && row > 1);
362         borders->setTopRightTrimEnabled(booktabsRB->isChecked()
363                                         && borders->topLineSet()
364                                         && row > 1);
365         borders->setBottomLeftTrimEnabled(booktabsRB->isChecked()
366                                           && borders->bottomLineSet()
367                                           && row < lastrow_);
368         borders->setBottomRightTrimEnabled(booktabsRB->isChecked()
369                                            && borders->bottomLineSet()
370                                            && row < lastrow_);
371 }
372
373
374 void GuiTabular::checkEnabled()
375 {
376         enableWidgets();
377         changed();
378 }
379
380
381 void GuiTabular::borderSet_clicked()
382 {
383         borders->setTop(GuiSetBorder::LINE_SET);
384         borders->setBottom(GuiSetBorder::LINE_SET);
385         borders->setLeft(GuiSetBorder::LINE_SET);
386         borders->setRight(GuiSetBorder::LINE_SET);
387         borders->setTopLeftTrim(GuiSetBorder::LINE_SET);
388         borders->setBottomLeftTrim(GuiSetBorder::LINE_SET);
389         borders->setTopRightTrim(GuiSetBorder::LINE_SET);
390         borders->setBottomRightTrim(GuiSetBorder::LINE_SET);
391         // repaint the setborder widget
392         borders->update();
393         checkEnabled();
394 }
395
396
397 void GuiTabular::borderUnset_clicked()
398 {
399         borders->setTop(GuiSetBorder::LINE_UNSET);
400         borders->setBottom(GuiSetBorder::LINE_UNSET);
401         borders->setLeft(GuiSetBorder::LINE_UNSET);
402         borders->setRight(GuiSetBorder::LINE_UNSET);
403         borders->setTopLeftTrim(GuiSetBorder::LINE_UNSET);
404         borders->setBottomLeftTrim(GuiSetBorder::LINE_UNSET);
405         borders->setTopRightTrim(GuiSetBorder::LINE_UNSET);
406         borders->setBottomRightTrim(GuiSetBorder::LINE_UNSET);
407         // repaint the setborder widget
408         borders->update();
409         checkEnabled();
410 }
411
412
413 void GuiTabular::booktabs_toggled(bool const check)
414 {
415         // when switching from formal, restore the left/right lines
416         if (!check) {
417                 borders->setLeft(orig_leftborder_);
418                 borders->setRight(orig_rightborder_);
419         }
420         // repaint the setborder widget
421         borders->update();
422         checkEnabled();
423 }
424
425
426 void GuiTabular::nonbooktabs_toggled(bool const check)
427 {
428         booktabs_toggled(!check);
429 }
430
431
432 static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
433 {
434         param_str += ' ';
435         param_str += featureAsString(f) + ' ' + arg;
436 }
437
438
439 void GuiTabular::setHAlign(string & param_str) const
440 {
441         Tabular::Feature num = Tabular::ALIGN_LEFT;
442         Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
443         string const align =
444                 fromqstr(hAlignCO->itemData(hAlignCO->currentIndex()).toString());
445         if (align == "left") {
446                 num = Tabular::ALIGN_LEFT;
447                 multi_num = Tabular::M_ALIGN_LEFT;
448         } else if (align == "center") {
449                 num = Tabular::ALIGN_CENTER;
450                 multi_num = Tabular::M_ALIGN_CENTER;
451         } else if (align == "right") {
452                 num = Tabular::ALIGN_RIGHT;
453                 multi_num = Tabular::M_ALIGN_RIGHT;
454         } else if (align == "justified") {
455                 num = Tabular::ALIGN_BLOCK;
456                 //multi_num: no equivalent
457         } else if (align == "decimal") {
458                 num = Tabular::ALIGN_DECIMAL;
459                 //multi_num: no equivalent
460         }
461
462         if (multicolumnCB->isChecked())
463                 setParam(param_str, multi_num);
464         else
465                 setParam(param_str, num);
466 }
467
468
469 void GuiTabular::setVAlign(string & param_str) const
470 {
471         int const align = vAlignCO->currentIndex();
472         enum VALIGN { TOP, MIDDLE, BOTTOM };
473         VALIGN v = TOP;
474
475         switch (align) {
476                 case 0: v = TOP; break;
477                 case 1: v = MIDDLE; break;
478                 case 2: v = BOTTOM; break;
479         }
480
481         Tabular::Feature num = Tabular::VALIGN_MIDDLE;
482         Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
483
484         switch (v) {
485                 case TOP:
486                         num = Tabular::VALIGN_TOP;
487                         multi_num = Tabular::M_VALIGN_TOP;
488                         break;
489                 case MIDDLE:
490                         num = Tabular::VALIGN_MIDDLE;
491                         multi_num = Tabular::M_VALIGN_MIDDLE;
492                         break;
493                 case BOTTOM:
494                         num = Tabular::VALIGN_BOTTOM;
495                         multi_num = Tabular::M_VALIGN_BOTTOM;
496                         break;
497         }
498         if (multicolumnCB->isChecked() || multirowCB->isChecked())
499                 setParam(param_str, multi_num);
500         else
501                 setParam(param_str, num);
502 }
503
504
505 void GuiTabular::setTableAlignment(string & param_str) const
506 {
507         int const align = TableAlignCO->currentIndex();
508         switch (align) {
509                 case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
510                         break;
511                 case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
512                         break;
513                 case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
514                         break;
515         }
516 }
517
518
519 docstring GuiTabular::dialogToParams() const
520 {
521         string param_str = "tabular";
522
523         // table width
524         string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitLC);
525         if (tabwidth.empty())
526                 tabwidth = "0pt";
527         setParam(param_str, Tabular::SET_TABULAR_WIDTH, tabwidth);
528
529         // apply the fixed width values
530         // this must be done before applying the column alignment
531         // because its value influences the alignment of multirow cells
532         string width = widgetsToLength(columnWidthED, columnWidthUnitLC);
533         if (width.empty() || columnTypeCO->currentIndex() != 2)
534                 width = "0pt";
535         if (multicolumnCB->isChecked())
536                 setParam(param_str, Tabular::SET_MPWIDTH, width);
537         else
538                 setParam(param_str, Tabular::SET_PWIDTH, width);
539
540         bool const varwidth = specialAlignmentED->text().isEmpty()
541                         && columnTypeCO->currentIndex() == 1;
542         if (varwidth)
543                 setParam(param_str, Tabular::TOGGLE_VARWIDTH_COLUMN, "on");
544         else
545                 setParam(param_str, Tabular::TOGGLE_VARWIDTH_COLUMN, "off");
546
547         // apply the column alignment
548         // multirows inherit the alignment from the column; if a column width
549         // is set, multirows are always left-aligned so that in this case
550         // its alignment must not be applied (see bug #8084)
551         if (!(multirowCB->isChecked() && width != "0pt"))
552                 setHAlign(param_str);
553
554         // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
555         string decimal_sep = fromqstr(decimalPointED->text());
556         if (decimal_sep.empty())
557                 decimal_sep = to_utf8(decimal_sep_);
558         setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_sep);
559
560         setVAlign(param_str);
561         setTableAlignment(param_str);
562         //
563         if (booktabsRB->isChecked())
564                 setParam(param_str, Tabular::SET_BOOKTABS);
565         else
566                 setParam(param_str, Tabular::UNSET_BOOKTABS);
567
568         //
569         switch (topspaceCO->currentIndex()) {
570                 case 0:
571                         setParam(param_str, Tabular::SET_TOP_SPACE, "none");
572                         break;
573                 case 1:
574                         setParam(param_str, Tabular::SET_TOP_SPACE, "default");
575                         break;
576                 case 2:
577                         if (!topspaceED->text().isEmpty())
578                                 setParam(param_str, Tabular::SET_TOP_SPACE,
579                                          widgetsToLength(topspaceED, topspaceUnitLC));
580                         break;
581         }
582
583         //
584         switch (bottomspaceCO->currentIndex()) {
585                 case 0:
586                         setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
587                         break;
588                 case 1:
589                         setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
590                         break;
591                 case 2:
592                         if (!bottomspaceED->text().isEmpty())
593                                 setParam(param_str, Tabular::SET_BOTTOM_SPACE,
594                                         widgetsToLength(bottomspaceED,
595                                                         bottomspaceUnitLC));
596                         break;
597         }
598
599         //
600         switch (interlinespaceCO->currentIndex()) {
601                 case 0:
602                         setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
603                         break;
604                 case 1:
605                         setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
606                         break;
607                 case 2:
608                         if (!interlinespaceED->text().isEmpty())
609                                 setParam(param_str, Tabular::SET_INTERLINE_SPACE,
610                                         widgetsToLength(interlinespaceED,
611                                                         interlinespaceUnitLC));
612                         break;
613         }
614
615         //
616         if (resetFormalCB->isChecked())
617                 setParam(param_str, Tabular::RESET_FORMAL_DEFAULT);
618         else if (borders->topLineSet() && borders->bottomLineSet() && borders->leftLineSet()
619                 && borders->rightLineSet())
620                 setParam(param_str, Tabular::SET_ALL_LINES);
621         else if (borders->topLineUnset() && borders->bottomLineUnset() && borders->leftLineUnset()
622                 && borders->rightLineUnset())
623                 setParam(param_str, Tabular::UNSET_ALL_LINES);
624         else {
625                 if (borders->getLeft() != GuiSetBorder::LINE_UNDECIDED)
626                         setParam(param_str, Tabular::SET_LINE_LEFT,
627                                  borders->leftLineSet() ? "true" : "false");
628                 if (borders->getRight() != GuiSetBorder::LINE_UNDECIDED)
629                         setParam(param_str, Tabular::SET_LINE_RIGHT,
630                                  borders->rightLineSet() ? "true" : "false");
631                 if (borders->getTop() != GuiSetBorder::LINE_UNDECIDED)
632                         setParam(param_str, Tabular::SET_LINE_TOP,
633                                  borders->topLineSet() ? "true" : "false");
634                 if (borders->getBottom() != GuiSetBorder::LINE_UNDECIDED)
635                         setParam(param_str, Tabular::SET_LINE_BOTTOM,
636                                  borders->bottomLineSet() ? "true" : "false");
637         }
638         if (borders->topLineLTSet())
639                 setParam(param_str, Tabular::SET_LTRIM_TOP, "false");
640         else if (borders->topLineLTUnset())
641                 setParam(param_str, Tabular::SET_LTRIM_TOP, "true");
642         if (borders->topLineRTSet())
643                 setParam(param_str, Tabular::SET_RTRIM_TOP, "false");
644         else if (borders->topLineRTUnset())
645                 setParam(param_str, Tabular::SET_RTRIM_TOP, "true");
646         if (borders->bottomLineLTSet())
647                 setParam(param_str, Tabular::SET_LTRIM_BOTTOM, "false");
648         else if (borders->bottomLineLTUnset())
649                 setParam(param_str, Tabular::SET_LTRIM_BOTTOM, "true");
650         if (borders->bottomLineRTSet())
651                 setParam(param_str, Tabular::SET_RTRIM_BOTTOM, "false");
652         else if (borders->bottomLineRTUnset())
653                 setParam(param_str, Tabular::SET_RTRIM_BOTTOM, "true");
654
655         // apply the special alignment
656         string special = fromqstr(specialAlignmentED->text());
657         if (support::trim(special).empty())
658                 special = "none";
659         if (multicolumnCB->isChecked())
660                 setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
661         else
662                 setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
663
664         //
665         if (multicolumnCB->isChecked())
666                 setParam(param_str, Tabular::SET_MULTICOLUMN);
667         else
668                 setParam(param_str, Tabular::UNSET_MULTICOLUMN);
669
670         // apply the multirow offset
671         string mroffset = widgetsToLength(multirowOffsetED, multirowOffsetUnitLC);
672         if (mroffset.empty())
673                 mroffset = "0pt";
674         if (multirowCB->isChecked())
675                 setParam(param_str, Tabular::SET_MROFFSET, mroffset);
676         //
677         if (multirowCB->isChecked())
678                 setParam(param_str, Tabular::SET_MULTIROW);
679         else
680                 setParam(param_str, Tabular::UNSET_MULTIROW);
681         // store the table rotation angle
682         string const tabular_angle = convert<string>(rotateTabularAngleSB->value());
683         if (rotateTabularCB->isChecked())
684                 setParam(param_str, Tabular::SET_ROTATE_TABULAR, tabular_angle);
685         else
686                 setParam(param_str, Tabular::UNSET_ROTATE_TABULAR, tabular_angle);
687         // store the cell rotation angle
688         string const cell_angle = convert<string>(rotateCellAngleSB->value());
689         if (rotateCellCB->isChecked())
690                 setParam(param_str, Tabular::SET_ROTATE_CELL, cell_angle);
691         else
692                 setParam(param_str, Tabular::UNSET_ROTATE_CELL, cell_angle);
693         //
694         if (longTabularCB->isChecked())
695                 setParam(param_str, Tabular::SET_LONGTABULAR);
696         else
697                 setParam(param_str, Tabular::UNSET_LONGTABULAR);
698         //
699         if (newpageCB->isChecked())
700                 setParam(param_str, Tabular::SET_LTNEWPAGE);
701         else
702                 setParam(param_str, Tabular::UNSET_LTNEWPAGE);
703         //
704         if (captionStatusCB->isChecked())
705                 setParam(param_str, Tabular::SET_LTCAPTION);
706         else
707                 setParam(param_str, Tabular::UNSET_LTCAPTION);
708         //
709         if (headerStatusCB->isChecked())
710                 setParam(param_str, Tabular::SET_LTHEAD, "none");
711         else
712                 setParam(param_str, Tabular::UNSET_LTHEAD, "none");
713         //
714         if (headerBorderAboveCB->isChecked())
715                 setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
716         else
717                 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
718         //
719         if (headerBorderBelowCB->isChecked())
720                 setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
721         else
722                 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
723         if (firstheaderBorderAboveCB->isChecked())
724                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
725         else
726                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
727         if (firstheaderBorderBelowCB->isChecked())
728                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
729         else
730                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
731         if (firstheaderStatusCB->isChecked())
732                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
733         else
734                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
735         if (firstheaderNoContentsCB->isChecked())
736                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
737         else
738                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
739         if (footerStatusCB->isChecked())
740                 setParam(param_str, Tabular::SET_LTFOOT, "none");
741         else
742                 setParam(param_str, Tabular::UNSET_LTFOOT, "none");
743         if (footerBorderAboveCB->isChecked())
744                 setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
745         else
746                 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
747         if (footerBorderBelowCB->isChecked())
748                 setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
749         else
750                 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
751         if (lastfooterStatusCB->isChecked())
752                 setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
753         else
754                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
755         if (lastfooterBorderAboveCB->isChecked())
756                 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
757         else
758                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
759         if (lastfooterBorderBelowCB->isChecked())
760                 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
761         else
762                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
763         if (lastfooterNoContentsCB->isChecked())
764                 setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
765         else
766                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
767
768         if (leftRB->isChecked())
769                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
770         else if (centerRB->isChecked())
771                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
772         else if (rightRB->isChecked())
773                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
774
775         return from_utf8(param_str);
776 }
777
778
779 static Length getColumnPWidth(Tabular const & t, size_t cell)
780 {
781         return t.column_info[t.cellColumn(cell)].p_width;
782 }
783
784
785 static Length getMColumnPWidth(Tabular const & t, size_t cell)
786 {
787         if (t.isMultiColumn(cell) || t.isMultiRow(cell))
788                 return t.cellInfo(cell).p_width;
789         return Length();
790 }
791
792
793 static Length getMROffset(Tabular const & t, size_t cell)
794 {
795         if (t.isMultiRow(cell))
796                 return t.cellInfo(cell).mroffset;
797         return Length();
798 }
799
800
801 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
802 {
803         if (what == Tabular::SET_SPECIAL_MULTICOLUMN)
804                 return t.cellInfo(cell).align_special;
805         return t.column_info[t.cellColumn(cell)].align_special;
806 }
807
808
809 GuiSetBorder::BorderState GuiTabular::borderState(GuiSetBorder::BorderState bs,
810                                                   bool const line)
811 {
812         if (bs == GuiSetBorder::LINE_UNDEF)
813                 bs = line ? GuiSetBorder::LINE_SET : GuiSetBorder::LINE_UNSET;
814         else if ((bs == GuiSetBorder::LINE_SET && !line)
815                  || (bs == GuiSetBorder::LINE_UNSET && line))
816                 bs = GuiSetBorder::LINE_UNDECIDED;
817         return bs;
818 }
819
820
821 void GuiTabular::paramsToDialog(Inset const * inset)
822 {
823         InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
824         // Copy Tabular of current inset.
825         Tabular const & tabular = itab->tabular;
826
827         BufferView const * bv = guiApp->currentView()->currentBufferView();
828         size_t const cell = bv->cursor().idx();
829
830         Tabular::row_type const row = tabular.cellRow(cell);
831         Tabular::col_type const col = tabular.cellColumn(cell);
832
833         tabularRowED->setText(QString::number(row + 1));
834         tabularColumnED->setText(QString::number(col + 1));
835         lastrow_ = int(tabular.nrows());
836
837         bool const multicol = tabular.isMultiColumn(cell);
838         multicolumnCB->setChecked(multicol);
839
840         bool const multirow = tabular.isMultiRow(cell);
841         multirowCB->setChecked(multirow);
842
843         rotateCellCB->setChecked(tabular.getRotateCell(cell) != 0);
844         if (rotateCellCB->isChecked()) {
845                 if (tabular.getRotateCell(cell) != 0)
846                         rotateCellAngleSB->setValue(tabular.getRotateCell(cell));
847                 else
848                         rotateCellAngleSB->setValue(90);
849         }
850
851         longTabularCB->setChecked(tabular.is_long_tabular);
852
853         rotateTabularCB->setChecked(tabular.rotate != 0);
854         if (rotateTabularCB->isChecked()) {
855                 if (longTabularCB->isChecked())
856                         rotateTabularAngleSB->setValue(90);
857                 else
858                         rotateTabularAngleSB->setValue(tabular.rotate != 0 ? tabular.rotate : 90);
859         }
860
861         // In what follows, we check the borders of all selected cells,
862         // and if there are diverging settings, we use the LINE_UNDECIDED
863         // border status.
864         GuiSetBorder::BorderState ltop = GuiSetBorder::LINE_UNDEF;
865         GuiSetBorder::BorderState lbottom = GuiSetBorder::LINE_UNDEF;
866         GuiSetBorder::BorderState lleft = GuiSetBorder::LINE_UNDEF;
867         GuiSetBorder::BorderState lright = GuiSetBorder::LINE_UNDEF;
868         GuiSetBorder::BorderState ltop_ltrim = GuiSetBorder::LINE_UNDEF;
869         GuiSetBorder::BorderState ltop_rtrim = GuiSetBorder::LINE_UNDEF;
870         GuiSetBorder::BorderState lbottom_ltrim = GuiSetBorder::LINE_UNDEF;
871         GuiSetBorder::BorderState lbottom_rtrim = GuiSetBorder::LINE_UNDEF;
872         CursorSlice const & beg = bv->cursor().selBegin();
873         CursorSlice const & end = bv->cursor().selEnd();
874         if (beg != end) {
875                 Tabular::col_type cs = tabular.cellColumn(beg.idx());
876                 Tabular::col_type ce = tabular.cellColumn(end.idx());
877                 if (cs > ce)
878                         swap(cs, ce);
879                 Tabular::row_type rs = tabular.cellRow(beg.idx());
880                 Tabular::row_type re = tabular.cellRow(end.idx());
881                 if (rs > re)
882                         swap(rs, re);
883                 for (Tabular::row_type r = rs; r <= re; ++r)
884                         for (Tabular::col_type c = cs; c <= ce; ++c) {
885                                 idx_type const cc = tabular.cellIndex(r, c);
886                                 ltop = borderState(ltop, tabular.topLine(cc));
887                                 lbottom = borderState(lbottom, tabular.bottomLine(cc));
888                                 lleft = borderState(lleft, tabular.leftLine(cc));
889                                 lright = borderState(lright, tabular.rightLine(cc));
890                                 ltop_ltrim = borderState(ltop_ltrim, !tabular.topLineTrim(cc).first);
891                                 ltop_rtrim = borderState(ltop_rtrim, !tabular.topLineTrim(cc).second);
892                                 lbottom_ltrim = borderState(lbottom_ltrim, !tabular.bottomLineTrim(cc).first);
893                                 lbottom_rtrim = borderState(lbottom_rtrim, !tabular.bottomLineTrim(cc).second);
894                                 // store left/right borders for the case of formal/nonformal switch
895                                 orig_leftborder_ = borderState(lleft, tabular.leftLine(cc, true));
896                                 orig_rightborder_ = borderState(lright, tabular.rightLine(cc, true));
897                         }
898         } else {
899                 ltop = tabular.topLine(cell) ? GuiSetBorder::LINE_SET : GuiSetBorder::LINE_UNSET;
900                 lbottom = tabular.bottomLine(cell) ? GuiSetBorder::LINE_SET : GuiSetBorder::LINE_UNSET;
901                 lleft = tabular.leftLine(cell) ? GuiSetBorder::LINE_SET : GuiSetBorder::LINE_UNSET;
902                 lright = tabular.rightLine(cell) ? GuiSetBorder::LINE_SET : GuiSetBorder::LINE_UNSET;
903                 ltop_ltrim = tabular.topLineTrim(cell).first ? GuiSetBorder::LINE_UNSET : GuiSetBorder::LINE_SET;
904                 ltop_rtrim = tabular.topLineTrim(cell).second ? GuiSetBorder::LINE_UNSET : GuiSetBorder::LINE_SET;
905                 lbottom_ltrim = tabular.bottomLineTrim(cell).first ? GuiSetBorder::LINE_UNSET : GuiSetBorder::LINE_SET;
906                 lbottom_rtrim = tabular.bottomLineTrim(cell).second ? GuiSetBorder::LINE_UNSET : GuiSetBorder::LINE_SET;
907                 // store left/right borders for the case of formal/nonformal switch
908                 orig_leftborder_ = tabular.leftLine(cell, true) ? GuiSetBorder::LINE_SET : GuiSetBorder::LINE_UNSET;
909                 orig_rightborder_ = tabular.rightLine(cell, true) ? GuiSetBorder::LINE_SET : GuiSetBorder::LINE_UNSET;
910         }
911         borders->setTop(ltop);
912         borders->setBottom(lbottom);
913         borders->setLeft(lleft);
914         borders->setRight(lright);
915         borders->setTopLeftTrim(ltop_ltrim);
916         borders->setTopRightTrim(ltop_rtrim);
917         borders->setBottomLeftTrim(lbottom_ltrim);
918         borders->setBottomRightTrim(lbottom_rtrim);
919         // repaint the setborder widget
920         borders->update();
921
922         Length::UNIT const default_unit = Length::defaultUnit();
923
924         ///////////////////////////////////
925         // Set width and alignment
926
927         Length const tabwidth = tabular.tabularWidth();
928         if (tabwidth.zero()
929             && !(tabularWidthED->hasFocus() && tabularWidthED->text() == "0"))
930                 tabularWidthED->clear();
931         else
932                 lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
933                         tabwidth.asString(), default_unit);
934
935         Length pwidth;
936         docstring special;
937         if (multicol) {
938                 special = getAlignSpecial(tabular, cell,
939                         Tabular::SET_SPECIAL_MULTICOLUMN);
940                 pwidth = getMColumnPWidth(tabular, cell);
941         } else {
942                 special = getAlignSpecial(tabular, cell,
943                         Tabular::SET_SPECIAL_COLUMN);
944                 pwidth = getColumnPWidth(tabular, cell);
945         }
946         bool const varwidth = tabular.column_info[tabular.cellColumn(cell)].varwidth;
947         if (varwidth)
948                 columnTypeCO->setCurrentIndex(1);
949         string colwidth;
950         if (pwidth.zero()
951             && !(columnWidthED->hasFocus() && columnWidthED->text() == "0")) {
952                 columnWidthED->clear();
953                 if (!varwidth)
954                         columnTypeCO->setCurrentIndex(0);
955         } else {
956                 colwidth = pwidth.asString();
957                 lengthToWidgets(columnWidthED, columnWidthUnitLC,
958                         colwidth, default_unit);
959                 columnTypeCO->setCurrentIndex(2);
960         }
961         Length mroffset;
962         if (multirow)
963                 mroffset = getMROffset(tabular, cell);
964         string offset;
965         if (mroffset.zero()
966             && !(multirowOffsetED->hasFocus() && multirowOffsetED->text() == "0"))
967                 multirowOffsetED->clear();
968         else {
969                 offset = mroffset.asString();
970                 lengthToWidgets(multirowOffsetED, multirowOffsetUnitLC,
971                         offset, default_unit);
972         }
973         specialAlignmentED->setText(toqstr(special));
974         ///////////////////////////////////
975
976
977         borderDefaultRB->setChecked(!tabular.use_booktabs);
978         booktabsRB->setChecked(tabular.use_booktabs);
979
980         if (tabular.row_info[row].top_space.empty()
981             && !tabular.row_info[row].top_space_default) {
982                 topspaceCO->setCurrentIndex(0);
983         } else if (tabular.row_info[row].top_space_default) {
984                 topspaceCO->setCurrentIndex(1);
985         } else {
986                 topspaceCO->setCurrentIndex(2);
987                 lengthToWidgets(topspaceED,
988                                 topspaceUnitLC,
989                                 tabular.row_info[row].top_space.asString(),
990                                 default_unit);
991         }
992
993         if (tabular.row_info[row].bottom_space.empty()
994             && !tabular.row_info[row].bottom_space_default) {
995                 bottomspaceCO->setCurrentIndex(0);
996         } else if (tabular.row_info[row].bottom_space_default) {
997                 bottomspaceCO->setCurrentIndex(1);
998         } else {
999                 bottomspaceCO->setCurrentIndex(2);
1000                 lengthToWidgets(bottomspaceED,
1001                                 bottomspaceUnitLC,
1002                                 tabular.row_info[row].bottom_space.asString(),
1003                                 default_unit);
1004         }
1005
1006         if (tabular.row_info[row].interline_space.empty()
1007             && !tabular.row_info[row].interline_space_default) {
1008                 interlinespaceCO->setCurrentIndex(0);
1009         } else if (tabular.row_info[row].interline_space_default) {
1010                 interlinespaceCO->setCurrentIndex(1);
1011         } else {
1012                 interlinespaceCO->setCurrentIndex(2);
1013                 lengthToWidgets(interlinespaceED,
1014                                 interlinespaceUnitLC,
1015                                 tabular.row_info[row].interline_space.asString(),
1016                                 default_unit);
1017         }
1018
1019         hAlignCO->clear();
1020         hAlignCO->addItem(qt_("Left"), toqstr("left"));
1021         hAlignCO->addItem(qt_("Center"), toqstr("center"));
1022         hAlignCO->addItem(qt_("Right"), toqstr("right"));
1023         if (!multicol && !pwidth.zero())
1024                 hAlignCO->addItem(qt_("Justified"), toqstr("justified"));
1025         if (!multicol && !multirow)
1026                 hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
1027
1028         string align;
1029         switch (tabular.getAlignment(cell)) {
1030                 case LYX_ALIGN_LEFT:
1031                         align = "left";
1032                         break;
1033                 case LYX_ALIGN_CENTER:
1034                         align = "center";
1035                         break;
1036                 case LYX_ALIGN_RIGHT:
1037                         align = "right";
1038                         break;
1039                 case LYX_ALIGN_BLOCK:
1040                 {
1041                         if (!multicol && !pwidth.zero())
1042                                 align = "justified";
1043                         break;
1044                 }
1045                 case LYX_ALIGN_DECIMAL:
1046                 {
1047                         if (!multicol && !multirow)
1048                                 align = "decimal";
1049                         break;
1050                 }
1051                 default:
1052                         // we should never end up here
1053                         break;
1054         }
1055         hAlignCO->setCurrentIndex(hAlignCO->findData(toqstr(align)));
1056
1057         //
1058         decimal_sep_ = tabular.column_info[col].decimal_point;
1059         if (decimal_sep_.empty()) {
1060                 Language const * lang = itab->buffer().paragraphs().front().getParLanguage(itab->buffer().params());
1061                 decimal_sep_ = lang->decimalSeparator();
1062         }
1063         decimalPointED->setText(toqstr(decimal_sep_));
1064
1065         int valign = 0;
1066         switch (tabular.getVAlignment(cell)) {
1067         case Tabular::LYX_VALIGN_TOP:
1068                 valign = 0;
1069                 break;
1070         case Tabular::LYX_VALIGN_MIDDLE:
1071                 valign = 1;
1072                 break;
1073         case Tabular::LYX_VALIGN_BOTTOM:
1074                 valign = 2;
1075                 break;
1076         default:
1077                 valign = 0;
1078                 break;
1079         }
1080         if (pwidth.zero())
1081                 valign = 0;
1082         vAlignCO->setCurrentIndex(valign);
1083
1084         int tableValign = 1;
1085         switch (tabular.tabular_valignment) {
1086         case Tabular::LYX_VALIGN_TOP:
1087                 tableValign = 0;
1088                 break;
1089         case Tabular::LYX_VALIGN_MIDDLE:
1090                 tableValign = 1;
1091                 break;
1092         case Tabular::LYX_VALIGN_BOTTOM:
1093                 tableValign = 2;
1094                 break;
1095         default:
1096                 tableValign = 0;
1097                 break;
1098         }
1099         TableAlignCO->setCurrentIndex(tableValign);
1100
1101         if (!tabular.is_long_tabular) {
1102                 headerStatusCB->setChecked(false);
1103                 headerBorderAboveCB->setChecked(false);
1104                 headerBorderBelowCB->setChecked(false);
1105                 firstheaderStatusCB->setChecked(false);
1106                 firstheaderBorderAboveCB->setChecked(false);
1107                 firstheaderBorderBelowCB->setChecked(false);
1108                 firstheaderNoContentsCB->setChecked(false);
1109                 footerStatusCB->setChecked(false);
1110                 footerBorderAboveCB->setChecked(false);
1111                 footerBorderBelowCB->setChecked(false);
1112                 lastfooterStatusCB->setChecked(false);
1113                 lastfooterBorderAboveCB->setChecked(false);
1114                 lastfooterBorderBelowCB->setChecked(false);
1115                 lastfooterNoContentsCB->setChecked(false);
1116                 newpageCB->setChecked(false);
1117                 captionStatusCB->blockSignals(true);
1118                 captionStatusCB->setChecked(false);
1119                 captionStatusCB->blockSignals(false);
1120                 checkEnabled();
1121                 return;
1122         } else {
1123                 // longtables cannot have a vertical alignment
1124                 TableAlignCO->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
1125         }
1126         switch (tabular.longtabular_alignment) {
1127         case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
1128                 leftRB->setChecked(true);
1129                 break;
1130         case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
1131                 centerRB->setChecked(true);
1132                 break;
1133         case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
1134                 rightRB->setChecked(true);
1135                 break;
1136         default:
1137                 centerRB->setChecked(true);
1138                 break;
1139         }
1140         captionStatusCB->blockSignals(true);
1141         captionStatusCB->setChecked(tabular.ltCaption(row));
1142         captionStatusCB->blockSignals(false);
1143
1144         Tabular::ltType ltt;
1145         bool use_empty;
1146         bool row_set = tabular.getRowOfLTHead(row, ltt);
1147         headerStatusCB->setChecked(row_set);
1148         if (ltt.set) {
1149                 headerBorderAboveCB->setChecked(ltt.topDL);
1150                 headerBorderBelowCB->setChecked(ltt.bottomDL);
1151                 use_empty = true;
1152         } else {
1153                 headerBorderAboveCB->setChecked(false);
1154                 headerBorderBelowCB->setChecked(false);
1155                 firstheaderNoContentsCB->setChecked(false);
1156                 use_empty = false;
1157         }
1158
1159         row_set = tabular.getRowOfLTFirstHead(row, ltt);
1160         firstheaderStatusCB->setChecked(row_set);
1161         if (ltt.set && (!ltt.empty || !use_empty)) {
1162                 firstheaderBorderAboveCB->setChecked(ltt.topDL);
1163                 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
1164         } else {
1165                 firstheaderBorderAboveCB->setChecked(false);
1166                 firstheaderBorderBelowCB->setChecked(false);
1167         }
1168
1169         row_set = tabular.getRowOfLTFoot(row, ltt);
1170         footerStatusCB->setChecked(row_set);
1171         if (ltt.set) {
1172                 footerBorderAboveCB->setChecked(ltt.topDL);
1173                 footerBorderBelowCB->setChecked(ltt.bottomDL);
1174                 use_empty = true;
1175         } else {
1176                 footerBorderAboveCB->setChecked(false);
1177                 footerBorderBelowCB->setChecked(false);
1178                 lastfooterNoContentsCB->setChecked(false);
1179                 use_empty = false;
1180         }
1181
1182         row_set = tabular.getRowOfLTLastFoot(row, ltt);
1183         lastfooterStatusCB->setChecked(row_set);
1184         if (ltt.set && (!ltt.empty || !use_empty)) {
1185                 lastfooterBorderAboveCB->setChecked(ltt.topDL);
1186                 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
1187         } else {
1188                 lastfooterBorderAboveCB->setChecked(false);
1189                 lastfooterBorderBelowCB->setChecked(false);
1190         }
1191         newpageCB->setChecked(tabular.getLTNewPage(row));
1192
1193         // first header can only be suppressed when there is a header
1194         firstheader_suppressable_ = tabular.haveLTHead()
1195                         && !tabular.haveLTFirstHead();
1196         // last footer can only be suppressed when there is a footer
1197         lastfooter_suppressable_ = tabular.haveLTFoot()
1198                         && !tabular.haveLTLastFoot();
1199
1200         // after setting the features, check if they are enabled
1201         checkEnabled();
1202 }
1203
1204
1205 bool GuiTabular::checkWidgets(bool readonly) const
1206 {
1207         tabularRowED->setReadOnly(readonly);
1208         tabularColumnED->setReadOnly(readonly);
1209         tabularWidthED->setReadOnly(readonly);
1210         specialAlignmentED->setReadOnly(readonly);
1211         columnWidthED->setReadOnly(readonly);
1212         multirowOffsetED->setReadOnly(readonly);
1213         decimalPointED->setReadOnly(readonly);
1214
1215         if (readonly) {
1216                 multicolumnCB->setEnabled(false);
1217                 multirowCB->setEnabled(false);
1218                 rotateCellCB->setEnabled(false);
1219                 rotateCellAngleSB->setEnabled(false);
1220                 rotateTabularCB->setEnabled(false);
1221                 rotateTabularAngleSB->setEnabled(false);
1222                 longTabularCB->setEnabled(false);
1223                 borders->setEnabled(false);
1224                 tabularWidthUnitLC->setEnabled(false);
1225                 columnWidthUnitLC->setEnabled(false);
1226                 columnTypeCO->setEnabled(false);
1227                 multirowOffsetUnitLC->setEnabled(false);
1228                 setBordersGB->setEnabled(false);
1229                 allBordersGB->setEnabled(false);
1230                 borderStyleGB->setEnabled(false);
1231                 booktabsRB->setEnabled(false);
1232                 topspaceCO->setEnabled(false);
1233                 topspaceUnitLC->setEnabled(false);
1234                 bottomspaceCO->setEnabled(false);
1235                 bottomspaceUnitLC->setEnabled(false);
1236                 interlinespaceCO->setEnabled(false);
1237                 interlinespaceUnitLC->setEnabled(false);
1238                 hAlignCO->setEnabled(false);
1239                 vAlignCO->setEnabled(false);
1240                 TableAlignCO->setEnabled(false);
1241                 longtableGB->setEnabled(false);
1242                 alignmentGB->setEnabled(false);
1243         } else
1244                 enableWidgets();
1245
1246         return InsetParamsWidget::checkWidgets();
1247 }
1248
1249
1250 bool GuiTabular::funcEnabled(Tabular::Feature f) const
1251 {
1252         FuncRequest r(LFUN_INSET_MODIFY, "tabular for-dialog" + featureAsString(f));
1253         return getStatus(r).enabled();
1254 }
1255
1256
1257 } // namespace frontend
1258 } // namespace lyx
1259
1260 #include "moc_GuiTabular.cpp"