]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiTabular.cpp
0828a56a4e2f5f67454384a9c738f0460d58c222
[lyx.git] / src / frontends / qt4 / GuiTabular.cpp
1 /**
2  * \file GuiTabular.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Jürgen Spitzmüller
8  * \author Herbert Voß
9  * \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 =
164                 hAlignCB->itemData(hAlignCB->currentIndex()).toString() == QString("decimal");
165         decimalPointLE->setEnabled(dalign);
166         decimalL->setEnabled(dalign);
167
168         vAlignCB->setEnabled(!multirowCB->isChecked() 
169                 && !widgetsToLength(widthED, widthUnitCB).empty());
170
171         topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
172         topspaceUnit->setEnabled(topspaceCO->currentIndex() == 2);
173         bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
174         bottomspaceUnit->setEnabled(bottomspaceCO->currentIndex() == 2);
175         interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
176         interlinespaceUnit->setEnabled(interlinespaceCO->currentIndex() == 2);
177
178         bool const longtabular = longTabularCB->isChecked();
179         longtableGB->setEnabled(true);
180         newpageCB->setEnabled(longtabular);
181         alignmentGB->setEnabled(longtabular);
182         // longtables cannot have a vertical alignment
183         TableAlignCB->setDisabled(longtabular);
184
185         // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
186         // depending on the cursor position is very very unintuitive...
187         // We need some edit boxes to show which rows are header/footer/etc
188         // without having to move the cursor first.
189         headerStatusCB->setEnabled(longtabular);
190         headerBorderAboveCB->setEnabled(longtabular
191                 && headerStatusCB->isChecked());
192         headerBorderBelowCB->setEnabled(longtabular
193                 && headerStatusCB->isChecked());
194
195         // first header can only be suppressed when there is a header
196         // FIXME: old code also checked for
197         //  tabular.haveLTHead() && !tabular.haveLTFirstHead());
198         firstheaderNoContentsCB->setEnabled(longtabular);
199         // check if setting a first header is allowed
200         // additionally check firstheaderNoContentsCB because when this is
201         // the case a first header makes no sense
202         firstheaderStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFIRSTHEAD)
203                 && longtabular && !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(funcEnabled(Tabular::SET_LTLASTFOOT)
223                 && longtabular && !lastfooterNoContentsCB->isChecked());
224         lastfooterBorderAboveCB->setEnabled(longtabular
225                 && lastfooterBorderAboveCB->isChecked());
226         lastfooterBorderBelowCB->setEnabled(longtabular
227                 && lastfooterBorderAboveCB->isChecked());
228
229         captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION));
230         
231         multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
232         multirowCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
233
234         changed();
235 }
236
237
238 void GuiTabular::borderSet_clicked()
239 {
240         borders->setTop(true);
241         borders->setBottom(true);
242         borders->setLeft(true);
243         borders->setRight(true);
244         // repaint the setborder widget
245         borders->update();
246         checkEnabled();
247 }
248
249
250 void GuiTabular::borderUnset_clicked()
251 {
252         borders->setTop(false);
253         borders->setBottom(false);
254         borders->setLeft(false);
255         borders->setRight(false);
256         // repaint the setborder widget
257         borders->update();
258         checkEnabled();
259 }
260
261
262 static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
263 {
264         param_str += ' ';
265         param_str += featureAsString(f) + ' ' + arg;
266 }
267
268
269 void GuiTabular::setHAlign(string & param_str) const
270 {
271         Tabular::Feature num = Tabular::ALIGN_LEFT;
272         Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
273         string const align = 
274                 fromqstr(hAlignCB->itemData(hAlignCB->currentIndex()).toString());
275         if (align == "left") {
276                 num = Tabular::ALIGN_LEFT;
277                 multi_num = Tabular::M_ALIGN_LEFT;
278         } else if (align == "center") {
279                 num = Tabular::ALIGN_CENTER;
280                 multi_num = Tabular::M_ALIGN_CENTER;
281         } else if (align == "right") {
282                 num = Tabular::ALIGN_RIGHT;
283                 multi_num = Tabular::M_ALIGN_RIGHT;
284         } else if (align == "justified") {
285                 num = Tabular::ALIGN_BLOCK;
286                 //multi_num: no equivalent
287         } else if (align == "decimal") {
288                 num = Tabular::ALIGN_DECIMAL;
289                 //multi_num: no equivalent
290         }
291
292         if (multicolumnCB->isChecked())
293                 setParam(param_str, multi_num);
294         else
295                 setParam(param_str, num);
296 }
297
298
299 void GuiTabular::setVAlign(string & param_str) const
300 {
301         int const align = vAlignCB->currentIndex();
302         enum VALIGN { TOP, MIDDLE, BOTTOM };
303         VALIGN v = TOP;
304
305         switch (align) {
306                 case 0: v = TOP; break;
307                 case 1: v = MIDDLE; break;
308                 case 2: v = BOTTOM; break;
309         }
310
311         Tabular::Feature num = Tabular::VALIGN_MIDDLE;
312         Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
313
314         switch (v) {
315                 case TOP:
316                         num = Tabular::VALIGN_TOP;
317                         multi_num = Tabular::M_VALIGN_TOP;
318                         break;
319                 case MIDDLE:
320                         num = Tabular::VALIGN_MIDDLE;
321                         multi_num = Tabular::M_VALIGN_MIDDLE;
322                         break;
323                 case BOTTOM:
324                         num = Tabular::VALIGN_BOTTOM;
325                         multi_num = Tabular::M_VALIGN_BOTTOM;
326                         break;
327         }
328         if (multicolumnCB->isChecked() || multirowCB->isChecked())
329                 setParam(param_str, multi_num);
330         else
331                 setParam(param_str, num);
332 }
333
334
335 void GuiTabular::setTableAlignment(string & param_str) const
336 {
337         int const align = TableAlignCB->currentIndex();
338         switch (align) {
339                 case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
340                         break;
341                 case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
342                         break;
343                 case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
344                         break;
345         }
346 }
347
348
349 docstring GuiTabular::dialogToParams() const
350 {
351         // FIXME: We should use Tabular directly.
352         string param_str = "tabular";
353         setHAlign(param_str);
354
355         // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
356         string decimal_point = fromqstr(decimalPointLE->text());
357         if (decimal_point.empty())
358                 decimal_point = lyxrc.default_decimal_point;
359         setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
360
361         setVAlign(param_str);
362         setTableAlignment(param_str);
363         //
364         if (booktabsRB->isChecked())
365                 setParam(param_str, Tabular::SET_BOOKTABS);
366         else
367                 setParam(param_str, Tabular::UNSET_BOOKTABS);
368
369         //
370         switch (topspaceCO->currentIndex()) {
371                 case 0:
372                         setParam(param_str, Tabular::SET_TOP_SPACE, "none");
373                         break;
374                 case 1:
375                         setParam(param_str, Tabular::SET_TOP_SPACE, "default");
376                         break;
377                 case 2:
378                         if (!topspaceED->text().isEmpty())
379                                 setParam(param_str, Tabular::SET_TOP_SPACE,
380                                          widgetsToLength(topspaceED, topspaceUnit));
381                         break;
382         }
383
384         //
385         switch (bottomspaceCO->currentIndex()) {
386                 case 0:
387                         setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
388                         break;
389                 case 1:
390                         setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
391                         break;
392                 case 2:
393                         if (!bottomspaceED->text().isEmpty())
394                                 setParam(param_str, Tabular::SET_BOTTOM_SPACE,
395                                         widgetsToLength(bottomspaceED,
396                                                         bottomspaceUnit));
397                         break;
398         }
399
400         //
401         switch (interlinespaceCO->currentIndex()) {
402                 case 0:
403                         setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
404                         break;
405                 case 1:
406                         setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
407                         break;
408                 case 2:
409                         if (!interlinespaceED->text().isEmpty())
410                                 setParam(param_str, Tabular::SET_INTERLINE_SPACE,
411                                         widgetsToLength(interlinespaceED,
412                                                         interlinespaceUnit));
413                         break;
414         }
415
416         //
417         if (borders->getTop() && borders->getBottom() && borders->getLeft()
418                 && borders->getRight())
419                 setParam(param_str, Tabular::SET_ALL_LINES);
420         else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft()
421                 && !borders->getRight())
422                 setParam(param_str, Tabular::UNSET_ALL_LINES);
423         else {
424                 setParam(param_str, Tabular::SET_LINE_LEFT,
425                          borders->getLeft() ? "true" : "false");
426                 setParam(param_str, Tabular::SET_LINE_RIGHT,
427                          borders->getRight() ? "true" : "false");
428                 setParam(param_str, Tabular::SET_LINE_TOP,
429                          borders->getTop() ? "true" : "false");
430                 setParam(param_str, Tabular::SET_LINE_BOTTOM,
431                          borders->getBottom() ? "true" : "false");
432         }
433
434         // apply the special alignment
435         string special = fromqstr(specialAlignmentED->text());
436         if (special.empty())
437                 special = "none";
438         if (multicolumnCB->isChecked())
439                 setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
440         else if (multirowCB->isChecked())
441                 setParam(param_str, Tabular::SET_SPECIAL_MULTIROW, special);
442         else
443                 setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
444
445         // apply the fixed width values
446         string width = widgetsToLength(widthED, widthUnitCB);
447         if (width.empty())
448                 width = "0pt";
449         if (multicolumnCB->isChecked())
450                 setParam(param_str, Tabular::SET_MPWIDTH, width);
451         else
452                 setParam(param_str, Tabular::SET_PWIDTH, width);
453
454         //
455         if (multicolumnCB->isChecked())
456                 setParam(param_str, Tabular::MULTICOLUMN);
457         //
458         if (multirowCB->isChecked())
459                 setParam(param_str, Tabular::MULTIROW);
460         //
461         if (rotateTabularCB->isChecked())
462                 setParam(param_str, Tabular::SET_ROTATE_TABULAR);
463         else
464                 setParam(param_str, Tabular::UNSET_ROTATE_TABULAR);
465         //
466         if (rotateCellCB->isChecked())
467                 setParam(param_str, Tabular::SET_ROTATE_CELL);
468         else
469                 setParam(param_str, Tabular::UNSET_ROTATE_CELL);
470         //
471         if (longTabularCB->isChecked())
472                 setParam(param_str, Tabular::SET_LONGTABULAR);
473         else
474                 setParam(param_str, Tabular::UNSET_LONGTABULAR);
475         //
476         if (newpageCB->isChecked())
477                 setParam(param_str, Tabular::SET_LTNEWPAGE);
478         //
479         if (captionStatusCB->isChecked())
480                 setParam(param_str, Tabular::TOGGLE_LTCAPTION);
481         //
482         if (headerStatusCB->isChecked())
483                 setParam(param_str, Tabular::SET_LTHEAD, "none");
484         else
485                 setParam(param_str, Tabular::UNSET_LTHEAD, "none");
486         //
487         if (headerBorderAboveCB->isChecked())
488                 setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
489         else
490                 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
491         //
492         if (headerBorderBelowCB->isChecked())
493                 setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
494         else
495                 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
496         if (firstheaderBorderAboveCB->isChecked())
497                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
498         else
499                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
500         if (firstheaderBorderBelowCB->isChecked())
501                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
502         else
503                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
504         if (firstheaderStatusCB->isChecked())
505                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
506         else
507                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
508         if (firstheaderNoContentsCB->isChecked())
509                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
510         else
511                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
512         if (footerStatusCB->isChecked())
513                 setParam(param_str, Tabular::SET_LTFOOT, "none");
514         else
515                 setParam(param_str, Tabular::UNSET_LTFOOT, "none");
516         if (footerBorderAboveCB->isChecked())
517                 setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
518         else
519                 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
520         if (footerBorderBelowCB->isChecked())
521                 setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
522         else
523                 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
524         if (lastfooterStatusCB->isChecked())
525                 setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
526         else
527                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
528         if (lastfooterBorderAboveCB->isChecked())
529                 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
530         else
531                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
532         if (lastfooterBorderBelowCB->isChecked())
533                 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
534         else
535                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
536         if (lastfooterNoContentsCB->isChecked())
537                 setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
538         else
539                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
540
541         if (leftRB->isChecked())
542                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
543         else if (centerRB->isChecked())
544                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
545         else if (rightRB->isChecked())
546                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
547
548         return from_utf8(param_str);
549 }
550
551
552 static Length getColumnPWidth(Tabular const & t, size_t cell)
553 {
554         return t.column_info[t.cellColumn(cell)].p_width;
555 }
556
557
558 static Length getMColumnPWidth(Tabular const & t, size_t cell)
559 {
560         if (t.isMultiColumn(cell) || t.isMultiRow(cell))
561                 return t.cellInfo(cell).p_width;
562         return Length();
563 }
564
565
566 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
567 {
568         if (what == Tabular::SET_SPECIAL_MULTICOLUMN
569                 || what == Tabular::SET_SPECIAL_MULTIROW)
570                 return t.cellInfo(cell).align_special;
571         return t.column_info[t.cellColumn(cell)].align_special;
572 }
573
574
575 void GuiTabular::paramsToDialog(Inset const * inset)
576 {
577         InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
578         // Copy Tabular of current inset.
579         Tabular const & tabular = itab->tabular;
580
581         BufferView const * bv = guiApp->currentView()->currentBufferView();
582         size_t const cell = bv->cursor().idx();
583
584         Tabular::row_type const row = tabular.cellRow(cell);
585         Tabular::col_type const col = tabular.cellColumn(cell);
586
587         tabularRowED->setText(QString::number(row + 1));
588         tabularColumnED->setText(QString::number(col + 1));
589
590         bool const multicol = tabular.isMultiColumn(cell);
591         multicolumnCB->setChecked(multicol);
592
593         bool const multirow = tabular.isMultiRow(cell);
594         multirowCB->setChecked(multirow);
595
596         rotateCellCB->setChecked(tabular.getRotateCell(cell));
597         rotateTabularCB->setChecked(tabular.rotate);
598
599         longTabularCB->setChecked(tabular.is_long_tabular);
600
601         borders->setTop(tabular.topLine(cell));
602         borders->setBottom(tabular.bottomLine(cell));
603         borders->setLeft(tabular.leftLine(cell));
604         borders->setRight(tabular.rightLine(cell));
605         // repaint the setborder widget
606         borders->update();
607
608         Length::UNIT const default_unit = Length::defaultUnit();
609
610         ///////////////////////////////////
611         // Set width and alignment
612         Length pwidth;
613         docstring special;
614         if (multicol) {
615                 special = getAlignSpecial(tabular, cell,
616                         Tabular::SET_SPECIAL_MULTICOLUMN);
617                 pwidth = getMColumnPWidth(tabular, cell);
618         } else if (multirow) {
619                 special = getAlignSpecial(tabular, cell,
620                         Tabular::SET_SPECIAL_MULTIROW);
621                 pwidth = getMColumnPWidth(tabular, cell);
622         } else {
623                 special = getAlignSpecial(tabular, cell,
624                         Tabular::SET_SPECIAL_COLUMN);
625                 pwidth = getColumnPWidth(tabular, cell);
626         }
627         string colwidth;
628         if (pwidth.zero())
629                 widthED->clear();
630         else {
631                 colwidth = pwidth.asString();
632                 lengthToWidgets(widthED, widthUnitCB,
633                         colwidth, default_unit);
634         }
635         specialAlignmentED->setText(toqstr(special));
636         ///////////////////////////////////
637
638
639         borderDefaultRB->setChecked(!tabular.use_booktabs);
640         booktabsRB->setChecked(tabular.use_booktabs);
641
642         if (tabular.row_info[row].top_space.empty()
643             && !tabular.row_info[row].top_space_default) {
644                 topspaceCO->setCurrentIndex(0);
645         } else if (tabular.row_info[row].top_space_default) {
646                 topspaceCO->setCurrentIndex(1);
647         } else {
648                 topspaceCO->setCurrentIndex(2);
649                 lengthToWidgets(topspaceED,
650                                 topspaceUnit,
651                                 tabular.row_info[row].top_space.asString(),
652                                 default_unit);
653         }
654
655         if (tabular.row_info[row].bottom_space.empty()
656             && !tabular.row_info[row].bottom_space_default) {
657                 bottomspaceCO->setCurrentIndex(0);
658         } else if (tabular.row_info[row].bottom_space_default) {
659                 bottomspaceCO->setCurrentIndex(1);
660         } else {
661                 bottomspaceCO->setCurrentIndex(2);
662                 lengthToWidgets(bottomspaceED,
663                                 bottomspaceUnit,
664                                 tabular.row_info[row].bottom_space.asString(),
665                                 default_unit);
666         }
667
668         if (tabular.row_info[row].interline_space.empty()
669             && !tabular.row_info[row].interline_space_default) {
670                 interlinespaceCO->setCurrentIndex(0);
671         } else if (tabular.row_info[row].interline_space_default) {
672                 interlinespaceCO->setCurrentIndex(1);
673         } else {
674                 interlinespaceCO->setCurrentIndex(2);
675                 lengthToWidgets(interlinespaceED,
676                                 interlinespaceUnit,
677                                 tabular.row_info[row].interline_space.asString(),
678                                 default_unit);
679         }
680
681         hAlignCB->clear();
682         hAlignCB->addItem(qt_("Left"), toqstr("left"));
683         hAlignCB->addItem(qt_("Center"), toqstr("center"));
684         hAlignCB->addItem(qt_("Right"), toqstr("right"));
685         if (!multicol && !pwidth.zero())
686                 hAlignCB->addItem(qt_("Justified"), toqstr("justified"));
687         if (!multicol)
688                 hAlignCB->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
689
690         string align;
691         switch (tabular.getAlignment(cell)) {
692                 case LYX_ALIGN_LEFT:
693                         align = "left";
694                         break;
695                 case LYX_ALIGN_CENTER:
696                         align = "center";
697                         break;
698                 case LYX_ALIGN_RIGHT:
699                         align = "right";
700                         break;
701                 case LYX_ALIGN_BLOCK:
702                 {
703                         if (!multicol && !pwidth.zero())
704                                 align = "justified";
705                         break;
706                 }
707                 case LYX_ALIGN_DECIMAL:
708                 {
709                         if (!multicol)
710                                 align = "decimal";
711                         break;
712                 }
713                 default:
714                         // we should never end up here
715                         break;
716         }
717         hAlignCB->setCurrentIndex(hAlignCB->findData(toqstr(align)));
718
719         //
720         QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
721         if (decimal_point.isEmpty())
722                 decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
723         decimalPointLE->setText(decimal_point);
724
725         int valign = 0;
726         switch (tabular.getVAlignment(cell)) {
727         case Tabular::LYX_VALIGN_TOP:
728                 valign = 0;
729                 break;
730         case Tabular::LYX_VALIGN_MIDDLE:
731                 valign = 1;
732                 break;
733         case Tabular::LYX_VALIGN_BOTTOM:
734                 valign = 2;
735                 break;
736         default:
737                 valign = 0;
738                 break;
739         }
740         if (pwidth.zero())
741                 valign = 0;
742         vAlignCB->setCurrentIndex(valign);
743
744         int tableValign = 1;
745         switch (tabular.tabular_valignment) {
746         case Tabular::LYX_VALIGN_TOP:
747                 tableValign = 0;
748                 break;
749         case Tabular::LYX_VALIGN_MIDDLE:
750                 tableValign = 1;
751                 break;
752         case Tabular::LYX_VALIGN_BOTTOM:
753                 tableValign = 2;
754                 break;
755         default:
756                 tableValign = 0;
757                 break;
758         }
759         TableAlignCB->setCurrentIndex(tableValign);
760
761         if (!tabular.is_long_tabular) {
762                 headerStatusCB->setChecked(false);
763                 headerBorderAboveCB->setChecked(false);
764                 headerBorderBelowCB->setChecked(false);
765                 firstheaderStatusCB->setChecked(false);
766                 firstheaderBorderAboveCB->setChecked(false);
767                 firstheaderBorderBelowCB->setChecked(false);
768                 firstheaderNoContentsCB->setChecked(false);
769                 footerStatusCB->setChecked(false);
770                 footerBorderAboveCB->setChecked(false);
771                 footerBorderBelowCB->setChecked(false);
772                 lastfooterStatusCB->setChecked(false);
773                 lastfooterBorderAboveCB->setChecked(false);
774                 lastfooterBorderBelowCB->setChecked(false);
775                 lastfooterNoContentsCB->setChecked(false);
776                 newpageCB->setChecked(false);
777                 captionStatusCB->blockSignals(true);
778                 captionStatusCB->setChecked(false);
779                 captionStatusCB->blockSignals(false);
780                 checkEnabled();
781                 return;
782         } else {
783                 // longtables cannot have a vertical alignment
784                 TableAlignCB->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
785         }
786         switch (tabular.longtabular_alignment) {
787         case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
788                 leftRB->setChecked(true);
789                 break;
790         case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
791                 centerRB->setChecked(true);
792                 break;
793         case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
794                 rightRB->setChecked(true);
795                 break;
796         default:
797                 centerRB->setChecked(true);
798                 break;
799         }
800         captionStatusCB->blockSignals(true);
801         captionStatusCB->setChecked(tabular.ltCaption(row));
802         captionStatusCB->blockSignals(false);
803
804         Tabular::ltType ltt;
805         bool use_empty;
806         bool row_set = tabular.getRowOfLTHead(row, ltt);
807         headerStatusCB->setChecked(row_set);
808         if (ltt.set) {
809                 headerBorderAboveCB->setChecked(ltt.topDL);
810                 headerBorderBelowCB->setChecked(ltt.bottomDL);
811                 use_empty = true;
812         } else {
813                 headerBorderAboveCB->setChecked(false);
814                 headerBorderBelowCB->setChecked(false);
815                 firstheaderNoContentsCB->setChecked(false);
816                 use_empty = false;
817         }
818
819         row_set = tabular.getRowOfLTFirstHead(row, ltt);
820         firstheaderStatusCB->setChecked(row_set);
821         if (ltt.set && (!ltt.empty || !use_empty)) {
822                 firstheaderBorderAboveCB->setChecked(ltt.topDL);
823                 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
824         } else {
825                 firstheaderBorderAboveCB->setChecked(false);
826                 firstheaderBorderBelowCB->setChecked(false);
827         }
828
829         row_set = tabular.getRowOfLTFoot(row, ltt);
830         footerStatusCB->setChecked(row_set);
831         if (ltt.set) {
832                 footerBorderAboveCB->setChecked(ltt.topDL);
833                 footerBorderBelowCB->setChecked(ltt.bottomDL);
834                 use_empty = true;
835         } else {
836                 footerBorderAboveCB->setChecked(false);
837                 footerBorderBelowCB->setChecked(false);
838                 lastfooterNoContentsCB->setChecked(false);
839                 use_empty = false;
840         }
841
842         row_set = tabular.getRowOfLTLastFoot(row, ltt);
843         lastfooterStatusCB->setChecked(row_set);
844         if (ltt.set && (!ltt.empty || !use_empty)) {
845                 lastfooterBorderAboveCB->setChecked(ltt.topDL);
846                 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
847         } else {
848                 lastfooterBorderAboveCB->setChecked(false);
849                 lastfooterBorderBelowCB->setChecked(false);
850         }
851         newpageCB->setChecked(tabular.getLTNewPage(row));
852 }
853
854
855 bool GuiTabular::funcEnabled(Tabular::Feature f) const
856 {
857         string cmd = "tabular " + featureAsString(f);
858         return getStatus(FuncRequest(LFUN_INSET_MODIFY, cmd)).enabled();
859 }
860
861
862 } // namespace frontend
863 } // namespace lyx
864
865 #include "moc_GuiTabular.cpp"