]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiTabular.cpp
2c7051441d3dada2ca407de622e73aad752ac460
[features.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  * \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 "BufferView.h"
26 #include "Cursor.h"
27 #include "FuncRequest.h"
28 #include "FuncStatus.h"
29 #include "LyX.h"
30 #include "LyXRC.h"
31
32 #include "insets/InsetTabular.h"
33
34 #include "support/debug.h"
35
36 #include <QCheckBox>
37 #include <QPushButton>
38 #include <QRadioButton>
39 #include <QLineEdit>
40
41 using namespace std;
42
43 namespace lyx {
44 namespace frontend {
45
46 GuiTabular::GuiTabular(QWidget * parent)
47         : InsetParamsWidget(parent)
48 {
49         setupUi(this);
50
51         widthED->setValidator(unsignedLengthValidator(widthED));
52         topspaceED->setValidator(new LengthValidator(topspaceED));
53         bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
54         interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
55
56         widthUnitCB->setCurrentItem(Length::defaultUnit());
57
58         connect(topspaceED, SIGNAL(returnPressed()),
59                 this, SLOT(checkEnabled()));
60         connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
61                 this, SLOT(checkEnabled()));
62         connect(topspaceCO, SIGNAL(activated(int)),
63                 this, SLOT(checkEnabled()));
64         connect(bottomspaceED, SIGNAL(returnPressed()),
65                 this, SLOT(checkEnabled()));
66         connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
67                 this, SLOT(checkEnabled()));
68         connect(bottomspaceCO, SIGNAL(activated(int)),
69                 this, SLOT(checkEnabled()));
70         connect(interlinespaceED, SIGNAL(returnPressed()),
71                 this, SLOT(checkEnabled()));
72         connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
73                 this, SLOT(checkEnabled()));
74         connect(interlinespaceCO, SIGNAL(activated(int)),
75                 this, SLOT(checkEnabled()));
76         connect(booktabsRB, SIGNAL(clicked(bool)),
77                 this, SLOT(checkEnabled()));
78         connect(borderDefaultRB, SIGNAL(clicked(bool)),
79                 this, SLOT(checkEnabled()));
80         connect(borderSetPB, SIGNAL(clicked()),
81                 this, SLOT(borderSet_clicked()));
82         connect(borderUnsetPB, SIGNAL(clicked()), 
83                 this, SLOT(borderUnset_clicked()));
84         connect(hAlignCB, SIGNAL(activated(int)),
85                 this, SLOT(checkEnabled()));
86         connect(vAlignCB, SIGNAL(activated(int)),
87                 this, SLOT(checkEnabled()));
88         connect(multicolumnCB, SIGNAL(clicked()),
89                 this, SLOT(checkEnabled()));
90         connect(multirowCB, SIGNAL(clicked()),
91                 this, SLOT(checkEnabled()));
92         connect(newpageCB, SIGNAL(clicked()),
93                 this, SLOT(checkEnabled()));
94         connect(headerStatusCB, SIGNAL(clicked()),
95                 this, SLOT(checkEnabled()));
96         connect(headerBorderAboveCB, SIGNAL(clicked()),
97                 this, SLOT(checkEnabled()));
98         connect(headerBorderBelowCB, SIGNAL(clicked()),
99                 this, SLOT(checkEnabled()));
100         connect(firstheaderStatusCB, SIGNAL(clicked()),
101                 this, SLOT(checkEnabled()));
102         connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
103                 this, SLOT(checkEnabled()));
104         connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
105                 this, SLOT(checkEnabled()));
106         connect(firstheaderNoContentsCB, SIGNAL(clicked()),
107                 this, SLOT(checkEnabled()));
108         connect(footerStatusCB, SIGNAL(clicked()),
109                 this, SLOT(checkEnabled()));
110         connect(footerBorderAboveCB, SIGNAL(clicked()),
111                 this, SLOT(checkEnabled()));
112         connect(footerBorderBelowCB, SIGNAL(clicked()),
113                 this, SLOT(checkEnabled()));
114         connect(lastfooterStatusCB, SIGNAL(clicked()),
115                 this, SLOT(checkEnabled()));
116         connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
117                 this, SLOT(checkEnabled()));
118         connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
119                 this, SLOT(checkEnabled()));
120         connect(lastfooterNoContentsCB, SIGNAL(clicked()),
121                 this, SLOT(checkEnabled()));
122         connect(specialAlignmentED, SIGNAL(returnPressed()),
123                 this, SLOT(checkEnabled()));
124         connect(widthED, SIGNAL(textEdited(QString)),
125                 this, SLOT(checkEnabled()));
126         connect(widthUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
127                 this, SLOT(checkEnabled()));
128         connect(borders, SIGNAL(topSet(bool)),
129                 this, SLOT(checkEnabled()));
130         connect(borders, SIGNAL(bottomSet(bool)),
131                 this, SLOT(checkEnabled()));
132         connect(borders, SIGNAL(rightSet(bool)),
133                 this, SLOT(checkEnabled()));
134         connect(borders, SIGNAL(leftSet(bool)),
135                 this, SLOT(checkEnabled()));
136         connect(rotateTabularCB, SIGNAL(clicked()),
137                 this, SLOT(checkEnabled()));
138         connect(rotateCellCB, SIGNAL(clicked()),
139                 this, SLOT(checkEnabled()));
140         connect(TableAlignCB, SIGNAL(activated(int)),
141                 this, SLOT(checkEnabled()));
142         connect(longTabularCB, SIGNAL(clicked()),
143                 this, SLOT(checkEnabled()));
144         connect(leftRB, SIGNAL(clicked()),
145                 this, SLOT(checkEnabled()));
146         connect(centerRB, SIGNAL(clicked()),
147                 this, SLOT(checkEnabled()));
148         connect(rightRB, SIGNAL(clicked()),
149                 this, SLOT(checkEnabled()));
150                 
151         
152         // initialize the length validator
153         addCheckedWidget(widthED, fixedWidthColLA);
154         addCheckedWidget(topspaceED, topspaceLA);
155         addCheckedWidget(bottomspaceED, bottomspaceLA);
156         addCheckedWidget(interlinespaceED, interlinespaceLA);
157 }
158
159
160 void GuiTabular::checkEnabled()
161 {
162         hAlignCB->setEnabled(true);
163         bool dalign = hAlignCB->currentText() == QString("Decimal");
164         decimalPointLE->setEnabled(dalign);
165         decimalL->setEnabled(dalign);
166
167         vAlignCB->setEnabled(!multirowCB->isChecked() 
168                 && !widgetsToLength(widthED, widthUnitCB).empty());
169
170         topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
171         topspaceUnit->setEnabled(topspaceCO->currentIndex() == 2);
172         bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
173         bottomspaceUnit->setEnabled(bottomspaceCO->currentIndex() == 2);
174         interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
175         interlinespaceUnit->setEnabled(interlinespaceCO->currentIndex() == 2);
176
177         bool const longtabular = longTabularCB->isChecked();
178         longtableGB->setEnabled(true);
179         newpageCB->setEnabled(longtabular);
180         alignmentGB->setEnabled(longtabular);
181         // longtables cannot have a vertical alignment
182         TableAlignCB->setDisabled(longtabular);
183
184         // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
185         // depending on the cursor position is very very unintuitive...
186         // We need some edit boxes to show which rows are header/footer/etc
187         // without having to move the cursor first.
188         headerStatusCB->setEnabled(longtabular);
189         headerBorderAboveCB->setEnabled(longtabular
190                 && headerStatusCB->isChecked());
191         headerBorderBelowCB->setEnabled(longtabular
192                 && headerStatusCB->isChecked());
193
194         // first header can only be suppressed when there is a header
195         // FIXME: old code also checked for
196         //  tabular.haveLTHead() && !tabular.haveLTFirstHead());
197         firstheaderNoContentsCB->setEnabled(longtabular);
198         // check if setting a first header is allowed
199         // additionally check firstheaderNoContentsCB because when this is
200         // the case a first header makes no sense
201         // FIXME: verify that some previous row was not set.
202         firstheaderStatusCB->setEnabled(longtabular
203                 && !firstheaderNoContentsCB->isChecked());
204         firstheaderBorderAboveCB->setEnabled(longtabular
205                 && firstheaderStatusCB->isChecked());
206         firstheaderBorderBelowCB->setEnabled(longtabular
207                 && firstheaderStatusCB->isChecked());
208
209         footerStatusCB->setEnabled(longtabular);
210         footerBorderAboveCB->setEnabled(longtabular
211                 && footerBorderAboveCB->isChecked());
212         footerBorderBelowCB->setEnabled(longtabular
213                 && footerBorderAboveCB->isChecked());
214
215         // last footer can only be suppressed when there is a footer
216         // FIXME: old code also checked for
217         //   tabular.haveLTFoot() && !tabular.haveLTLastFoot());
218         lastfooterNoContentsCB->setEnabled(longtabular);
219         // check if setting a last footer is allowed
220         // additionally check lastfooterNoContentsCB because when this is
221         // the case a last footer makes no sense
222         lastfooterStatusCB->setEnabled(longtabular
223                 && !lastfooterNoContentsCB->isChecked());
224         lastfooterBorderAboveCB->setEnabled(longtabular
225                 && lastfooterBorderAboveCB->isChecked());
226         lastfooterBorderBelowCB->setEnabled(longtabular
227                 && lastfooterBorderAboveCB->isChecked());
228
229         // FIXME: verify if previous row doesn't have a caption already.
230         captionStatusCB->setEnabled(longtabular);
231
232         // When a row is set as longtable caption, it must not be allowed
233         // to unset that this row is a multicolumn.
234         // FIXME: old code also checked for:
235         //    funcEnabled(Tabular::MULTICOLUMN)
236         multicolumnCB->setEnabled(longtabular);
237
238         // FIXME: old code also checked for:
239         //    funcEnabled(Tabular::MULTICOLUMN)
240         multirowCB->setEnabled(longtabular);
241
242         changed();
243 }
244
245
246 void GuiTabular::borderSet_clicked()
247 {
248         borders->setTop(true);
249         borders->setBottom(true);
250         borders->setLeft(true);
251         borders->setRight(true);
252         // repaint the setborder widget
253         borders->update();
254         checkEnabled();
255 }
256
257
258 void GuiTabular::borderUnset_clicked()
259 {
260         borders->setTop(false);
261         borders->setBottom(false);
262         borders->setLeft(false);
263         borders->setRight(false);
264         // repaint the setborder widget
265         borders->update();
266         checkEnabled();
267 }
268
269
270 static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
271 {
272         param_str += ' ';
273         param_str += featureAsString(f) + ' ' + arg;
274 }
275
276
277 void GuiTabular::setHAlign(string & param_str) const
278 {
279         Tabular::Feature num = Tabular::ALIGN_LEFT;
280         Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
281         QString const align = hAlignCB->currentText();
282         if (align == qt_("Left")) {
283                 num = Tabular::ALIGN_LEFT;
284                 multi_num = Tabular::M_ALIGN_LEFT;
285         } else if (align == qt_("Center")) {
286                 num = Tabular::ALIGN_CENTER;
287                 multi_num = Tabular::M_ALIGN_CENTER;
288         } else if (align == qt_("Right")) {
289                 num = Tabular::ALIGN_RIGHT;
290                 multi_num = Tabular::M_ALIGN_RIGHT;
291         } else if (align == qt_("Justified")) {
292                 num = Tabular::ALIGN_BLOCK;
293                 //multi_num: no equivalent
294         } else if (align == qt_("Decimal")) {
295                 num = Tabular::ALIGN_DECIMAL;
296                 //multi_num: no equivalent
297         }
298
299         if (multicolumnCB->isChecked())
300                 setParam(param_str, multi_num);
301         else
302                 setParam(param_str, num);
303 }
304
305
306 void GuiTabular::setVAlign(string & param_str) const
307 {
308         int const align = vAlignCB->currentIndex();
309         enum VALIGN { TOP, MIDDLE, BOTTOM };
310         VALIGN v = TOP;
311
312         switch (align) {
313                 case 0: v = TOP; break;
314                 case 1: v = MIDDLE; break;
315                 case 2: v = BOTTOM; break;
316         }
317
318         Tabular::Feature num = Tabular::VALIGN_MIDDLE;
319         Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
320
321         switch (v) {
322                 case TOP:
323                         num = Tabular::VALIGN_TOP;
324                         multi_num = Tabular::M_VALIGN_TOP;
325                         break;
326                 case MIDDLE:
327                         num = Tabular::VALIGN_MIDDLE;
328                         multi_num = Tabular::M_VALIGN_MIDDLE;
329                         break;
330                 case BOTTOM:
331                         num = Tabular::VALIGN_BOTTOM;
332                         multi_num = Tabular::M_VALIGN_BOTTOM;
333                         break;
334         }
335         if (multicolumnCB->isChecked() || multirowCB->isChecked())
336                 setParam(param_str, multi_num);
337         else
338                 setParam(param_str, num);
339 }
340
341
342 void GuiTabular::setTableAlignment(string & param_str) const
343 {
344         int const align = TableAlignCB->currentIndex();
345         switch (align) {
346                 case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
347                         break;
348                 case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
349                         break;
350                 case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
351                         break;
352         }
353 }
354
355
356 docstring GuiTabular::dialogToParams() const
357 {
358         // FIXME: We should use Tabular directly.
359         string param_str = "tabular";
360         setHAlign(param_str);
361
362         // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
363         string decimal_point = fromqstr(decimalPointLE->text());
364         if (decimal_point.empty())
365                 decimal_point = lyxrc.default_decimal_point;
366         setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
367
368         setVAlign(param_str);
369         setTableAlignment(param_str);
370         //
371         if (booktabsRB->isChecked())
372                 setParam(param_str, Tabular::SET_BOOKTABS);
373         else
374                 setParam(param_str, Tabular::UNSET_BOOKTABS);
375
376         //
377         switch (topspaceCO->currentIndex()) {
378                 case 0:
379                         setParam(param_str, Tabular::SET_TOP_SPACE, "none");
380                         break;
381                 case 1:
382                         setParam(param_str, Tabular::SET_TOP_SPACE, "default");
383                         break;
384                 case 2:
385                         if (!topspaceED->text().isEmpty())
386                                 setParam(param_str, Tabular::SET_TOP_SPACE,
387                                          widgetsToLength(topspaceED, topspaceUnit));
388                         break;
389         }
390
391         //
392         switch (bottomspaceCO->currentIndex()) {
393                 case 0:
394                         setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
395                         break;
396                 case 1:
397                         setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
398                         break;
399                 case 2:
400                         if (!bottomspaceED->text().isEmpty())
401                                 setParam(param_str, Tabular::SET_BOTTOM_SPACE,
402                                         widgetsToLength(bottomspaceED,
403                                                         bottomspaceUnit));
404                         break;
405         }
406
407         //
408         switch (interlinespaceCO->currentIndex()) {
409                 case 0:
410                         setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
411                         break;
412                 case 1:
413                         setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
414                         break;
415                 case 2:
416                         if (!interlinespaceED->text().isEmpty())
417                                 setParam(param_str, Tabular::SET_INTERLINE_SPACE,
418                                         widgetsToLength(interlinespaceED,
419                                                         interlinespaceUnit));
420                         break;
421         }
422
423         //
424         if (borders->getTop() && borders->getBottom() && borders->getLeft()
425                 && borders->getRight())
426                 setParam(param_str, Tabular::SET_ALL_LINES);
427         else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft()
428                 && !borders->getRight())
429                 setParam(param_str, Tabular::UNSET_ALL_LINES);
430         else {
431                 setParam(param_str, Tabular::SET_LINE_LEFT,
432                          borders->getLeft() ? "true" : "false");
433                 setParam(param_str, Tabular::SET_LINE_RIGHT,
434                          borders->getRight() ? "true" : "false");
435                 setParam(param_str, Tabular::SET_LINE_TOP,
436                          borders->getTop() ? "true" : "false");
437                 setParam(param_str, Tabular::SET_LINE_BOTTOM,
438                          borders->getBottom() ? "true" : "false");
439         }
440
441         // apply the special alignment
442         string special = fromqstr(specialAlignmentED->text());
443         if (special.empty())
444                 special = "none";
445         if (multicolumnCB->isChecked())
446                 setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
447         else if (multirowCB->isChecked())
448                 setParam(param_str, Tabular::SET_SPECIAL_MULTIROW, special);
449         else
450                 setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
451
452         // apply the fixed width values
453         string width = widgetsToLength(widthED, widthUnitCB);
454         if (width.empty())
455                 width = "0pt";
456         if (multicolumnCB->isChecked())
457                 setParam(param_str, Tabular::SET_MPWIDTH, width);
458         else
459                 setParam(param_str, Tabular::SET_PWIDTH, width);
460
461         //
462         if (multicolumnCB->isChecked())
463                 setParam(param_str, Tabular::MULTICOLUMN);
464         //
465         if (multirowCB->isChecked())
466                 setParam(param_str, Tabular::MULTIROW);
467         //
468         if (rotateTabularCB->isChecked())
469                 setParam(param_str, Tabular::SET_ROTATE_TABULAR);
470         else
471                 setParam(param_str, Tabular::UNSET_ROTATE_TABULAR);
472         //
473         if (rotateCellCB->isChecked())
474                 setParam(param_str, Tabular::SET_ROTATE_CELL);
475         else
476                 setParam(param_str, Tabular::UNSET_ROTATE_CELL);
477         //
478         if (longTabularCB->isChecked())
479                 setParam(param_str, Tabular::SET_LONGTABULAR);
480         else
481                 setParam(param_str, Tabular::UNSET_LONGTABULAR);
482         //
483         if (newpageCB->isChecked())
484                 setParam(param_str, Tabular::SET_LTNEWPAGE);
485         //
486         if (captionStatusCB->isChecked())
487                 setParam(param_str, Tabular::TOGGLE_LTCAPTION);
488         //
489         if (headerStatusCB->isChecked())
490                 setParam(param_str, Tabular::SET_LTHEAD, "none");
491         else
492                 setParam(param_str, Tabular::UNSET_LTHEAD, "none");
493         //
494         if (headerBorderAboveCB->isChecked())
495                 setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
496         else
497                 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
498         //
499         if (headerBorderBelowCB->isChecked())
500                 setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
501         else
502                 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
503         if (firstheaderBorderAboveCB->isChecked())
504                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
505         else
506                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
507         if (firstheaderBorderBelowCB->isChecked())
508                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
509         else
510                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
511         if (firstheaderStatusCB->isChecked())
512                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
513         else
514                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
515         if (firstheaderNoContentsCB->isChecked())
516                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
517         else
518                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
519         if (footerStatusCB->isChecked())
520                 setParam(param_str, Tabular::SET_LTFOOT, "none");
521         else
522                 setParam(param_str, Tabular::UNSET_LTFOOT, "none");
523         if (footerBorderAboveCB->isChecked())
524                 setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
525         else
526                 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
527         if (footerBorderBelowCB->isChecked())
528                 setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
529         else
530                 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
531         if (lastfooterStatusCB->isChecked())
532                 setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
533         else
534                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
535         if (lastfooterBorderAboveCB->isChecked())
536                 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
537         else
538                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
539         if (lastfooterBorderBelowCB->isChecked())
540                 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
541         else
542                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
543         if (lastfooterNoContentsCB->isChecked())
544                 setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
545         else
546                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
547
548         if (leftRB->isChecked())
549                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
550         else if (centerRB->isChecked())
551                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
552         else if (rightRB->isChecked())
553                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
554
555         return from_utf8(param_str);
556 }
557
558
559 static Length getColumnPWidth(Tabular const & t, size_t cell)
560 {
561         return t.column_info[t.cellColumn(cell)].p_width;
562 }
563
564
565 static Length getMColumnPWidth(Tabular const & t, size_t cell)
566 {
567         if (t.isMultiColumn(cell) || t.isMultiRow(cell))
568                 return t.cellInfo(cell).p_width;
569         return Length();
570 }
571
572
573 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
574 {
575         if (what == Tabular::SET_SPECIAL_MULTICOLUMN
576                 || what == Tabular::SET_SPECIAL_MULTIROW)
577                 return t.cellInfo(cell).align_special;
578         return t.column_info[t.cellColumn(cell)].align_special;
579 }
580
581
582 void GuiTabular::paramsToDialog(Inset const * inset)
583 {
584         InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
585         // Copy Tabular of current inset.
586         Tabular const & tabular = itab->tabular;
587
588         BufferView const * bv = guiApp->currentView()->currentBufferView();
589         size_t const cell = bv->cursor().idx();
590
591         Tabular::row_type const row = tabular.cellRow(cell);
592         Tabular::col_type const col = tabular.cellColumn(cell);
593
594         tabularRowED->setText(QString::number(row + 1));
595         tabularColumnED->setText(QString::number(col + 1));
596
597         bool const multicol = tabular.isMultiColumn(cell);
598         multicolumnCB->setChecked(multicol);
599
600         bool const multirow = tabular.isMultiRow(cell);
601         multirowCB->setChecked(multirow);
602
603         rotateCellCB->setChecked(tabular.getRotateCell(cell));
604         rotateTabularCB->setChecked(tabular.rotate);
605
606         longTabularCB->setChecked(tabular.is_long_tabular);
607
608         borders->setTop(tabular.topLine(cell));
609         borders->setBottom(tabular.bottomLine(cell));
610         borders->setLeft(tabular.leftLine(cell));
611         borders->setRight(tabular.rightLine(cell));
612         // repaint the setborder widget
613         borders->update();
614
615         Length::UNIT const default_unit = Length::defaultUnit();
616
617         ///////////////////////////////////
618         // Set width and alignment
619         Length pwidth;
620         docstring special;
621         if (multicol) {
622                 special = getAlignSpecial(tabular, cell,
623                         Tabular::SET_SPECIAL_MULTICOLUMN);
624                 pwidth = getMColumnPWidth(tabular, cell);
625         } else if (multirow) {
626                 special = getAlignSpecial(tabular, cell,
627                         Tabular::SET_SPECIAL_MULTIROW);
628                 pwidth = getMColumnPWidth(tabular, cell);
629         } else {
630                 special = getAlignSpecial(tabular, cell,
631                         Tabular::SET_SPECIAL_COLUMN);
632                 pwidth = getColumnPWidth(tabular, cell);
633         }
634         string colwidth;
635         if (pwidth.zero())
636                 widthED->clear();
637         else {
638                 colwidth = pwidth.asString();
639                 lengthToWidgets(widthED, widthUnitCB,
640                         colwidth, default_unit);
641         }
642         specialAlignmentED->setText(toqstr(special));
643         ///////////////////////////////////
644
645
646         borderDefaultRB->setChecked(!tabular.use_booktabs);
647         booktabsRB->setChecked(tabular.use_booktabs);
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
662         if (tabular.row_info[row].bottom_space.empty()
663             && !tabular.row_info[row].bottom_space_default) {
664                 bottomspaceCO->setCurrentIndex(0);
665         } else if (tabular.row_info[row].bottom_space_default) {
666                 bottomspaceCO->setCurrentIndex(1);
667         } else {
668                 bottomspaceCO->setCurrentIndex(2);
669                 lengthToWidgets(bottomspaceED,
670                                 bottomspaceUnit,
671                                 tabular.row_info[row].bottom_space.asString(),
672                                 default_unit);
673         }
674
675         if (tabular.row_info[row].interline_space.empty()
676             && !tabular.row_info[row].interline_space_default) {
677                 interlinespaceCO->setCurrentIndex(0);
678         } else if (tabular.row_info[row].interline_space_default) {
679                 interlinespaceCO->setCurrentIndex(1);
680         } else {
681                 interlinespaceCO->setCurrentIndex(2);
682                 lengthToWidgets(interlinespaceED,
683                                 interlinespaceUnit,
684                                 tabular.row_info[row].interline_space.asString(),
685                                 default_unit);
686         }
687
688         hAlignCB->clear();
689         hAlignCB->addItem(qt_("Left"));
690         hAlignCB->addItem(qt_("Center"));
691         hAlignCB->addItem(qt_("Right"));
692         if (!multicol && !pwidth.zero())
693                 hAlignCB->addItem(qt_("Justified"));
694         if (!multicol)
695                 hAlignCB->addItem(qt_("Decimal"));
696
697         QString align;
698         switch (tabular.getAlignment(cell)) {
699                 case LYX_ALIGN_LEFT:
700                         align = qt_("Left");
701                         break;
702                 case LYX_ALIGN_CENTER:
703                         align = qt_("Center");
704                         break;
705                 case LYX_ALIGN_RIGHT:
706                         align = qt_("Right");
707                         break;
708                 case LYX_ALIGN_BLOCK:
709                 {
710                         if (!multicol && !pwidth.zero())
711                                 align = qt_("Justified");
712                         break;
713                 }
714                 case LYX_ALIGN_DECIMAL:
715                 {
716                         if (!multicol)
717                                 align = qt_("Decimal");
718                         break;
719                 }
720                 default:
721                         // we should never end up here
722                         break;
723         }
724         hAlignCB->setCurrentIndex(hAlignCB->findText(align));
725
726         //
727         QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
728         if (decimal_point.isEmpty())
729                 decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
730         decimalPointLE->setText(decimal_point);
731
732         int valign = 0;
733         switch (tabular.getVAlignment(cell)) {
734         case Tabular::LYX_VALIGN_TOP:
735                 valign = 0;
736                 break;
737         case Tabular::LYX_VALIGN_MIDDLE:
738                 valign = 1;
739                 break;
740         case Tabular::LYX_VALIGN_BOTTOM:
741                 valign = 2;
742                 break;
743         default:
744                 valign = 0;
745                 break;
746         }
747         if (pwidth.zero())
748                 valign = 0;
749         vAlignCB->setCurrentIndex(valign);
750
751         int tableValign = 1;
752         switch (tabular.tabular_valignment) {
753         case Tabular::LYX_VALIGN_TOP:
754                 tableValign = 0;
755                 break;
756         case Tabular::LYX_VALIGN_MIDDLE:
757                 tableValign = 1;
758                 break;
759         case Tabular::LYX_VALIGN_BOTTOM:
760                 tableValign = 2;
761                 break;
762         default:
763                 tableValign = 0;
764                 break;
765         }
766         TableAlignCB->setCurrentIndex(tableValign);
767
768         if (!tabular.is_long_tabular) {
769                 headerStatusCB->setChecked(false);
770                 headerBorderAboveCB->setChecked(false);
771                 headerBorderBelowCB->setChecked(false);
772                 firstheaderStatusCB->setChecked(false);
773                 firstheaderBorderAboveCB->setChecked(false);
774                 firstheaderBorderBelowCB->setChecked(false);
775                 firstheaderNoContentsCB->setChecked(false);
776                 footerStatusCB->setChecked(false);
777                 footerBorderAboveCB->setChecked(false);
778                 footerBorderBelowCB->setChecked(false);
779                 lastfooterStatusCB->setChecked(false);
780                 lastfooterBorderAboveCB->setChecked(false);
781                 lastfooterBorderBelowCB->setChecked(false);
782                 lastfooterNoContentsCB->setChecked(false);
783                 newpageCB->setChecked(false);
784                 captionStatusCB->blockSignals(true);
785                 captionStatusCB->setChecked(false);
786                 captionStatusCB->blockSignals(false);
787                 checkEnabled();
788                 return;
789         } else {
790                 // longtables cannot have a vertical alignment
791                 TableAlignCB->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
792         }
793         switch (tabular.longtabular_alignment) {
794         case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
795                 leftRB->setChecked(true);
796                 break;
797         case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
798                 centerRB->setChecked(true);
799                 break;
800         case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
801                 rightRB->setChecked(true);
802                 break;
803         default:
804                 centerRB->setChecked(true);
805                 break;
806         }
807         captionStatusCB->blockSignals(true);
808         captionStatusCB->setChecked(tabular.ltCaption(row));
809         captionStatusCB->blockSignals(false);
810
811         Tabular::ltType ltt;
812         bool use_empty;
813         bool row_set = tabular.getRowOfLTHead(row, ltt);
814         headerStatusCB->setChecked(row_set);
815         if (ltt.set) {
816                 headerBorderAboveCB->setChecked(ltt.topDL);
817                 headerBorderBelowCB->setChecked(ltt.bottomDL);
818                 use_empty = true;
819         } else {
820                 headerBorderAboveCB->setChecked(false);
821                 headerBorderBelowCB->setChecked(false);
822                 firstheaderNoContentsCB->setChecked(false);
823                 use_empty = false;
824         }
825
826         row_set = tabular.getRowOfLTFirstHead(row, ltt);
827         firstheaderStatusCB->setChecked(row_set);
828         if (ltt.set && (!ltt.empty || !use_empty)) {
829                 firstheaderBorderAboveCB->setChecked(ltt.topDL);
830                 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
831         } else {
832                 firstheaderBorderAboveCB->setChecked(false);
833                 firstheaderBorderBelowCB->setChecked(false);
834         }
835
836         row_set = tabular.getRowOfLTFoot(row, ltt);
837         footerStatusCB->setChecked(row_set);
838         if (ltt.set) {
839                 footerBorderAboveCB->setChecked(ltt.topDL);
840                 footerBorderBelowCB->setChecked(ltt.bottomDL);
841                 use_empty = true;
842         } else {
843                 footerBorderAboveCB->setChecked(false);
844                 footerBorderBelowCB->setChecked(false);
845                 lastfooterNoContentsCB->setChecked(false);
846                 use_empty = false;
847         }
848
849         row_set = tabular.getRowOfLTLastFoot(row, ltt);
850         lastfooterStatusCB->setChecked(row_set);
851         if (ltt.set && (!ltt.empty || !use_empty)) {
852                 lastfooterBorderAboveCB->setChecked(ltt.topDL);
853                 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
854         } else {
855                 lastfooterBorderAboveCB->setChecked(false);
856                 lastfooterBorderBelowCB->setChecked(false);
857         }
858         newpageCB->setChecked(tabular.getLTNewPage(row));
859 }
860
861
862 } // namespace frontend
863 } // namespace lyx
864
865 #include "moc_GuiTabular.cpp"