3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Jürgen Spitzmüller
11 * Full author contact details are available in file CREDITS.
16 #include "GuiTabular.h"
18 #include "GuiApplication.h"
19 #include "GuiSetBorder.h"
21 #include "LengthCombo.h"
22 #include "qt_helpers.h"
23 #include "Validator.h"
25 #include "BufferView.h"
27 #include "FuncRequest.h"
28 #include "FuncStatus.h"
32 #include "insets/InsetTabular.h"
34 #include "support/debug.h"
37 #include <QPushButton>
38 #include <QRadioButton>
46 GuiTabular::GuiTabular(QWidget * parent)
47 : InsetParamsWidget(parent)
51 widthED->setValidator(unsignedLengthValidator(widthED));
52 multirowOffsetED->setValidator(new LengthValidator(multirowOffsetED));
53 topspaceED->setValidator(new LengthValidator(topspaceED));
54 bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
55 interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
57 widthUnitCB->setCurrentItem(Length::defaultUnit());
58 multirowOffsetUnitCB->setCurrentItem(Length::defaultUnit());
59 topspaceUnitCB->setCurrentItem(Length::defaultUnit());
60 bottomspaceUnitCB->setCurrentItem(Length::defaultUnit());
61 interlinespaceUnitCB->setCurrentItem(Length::defaultUnit());
63 connect(topspaceED, SIGNAL(editingFinished()),
64 this, SLOT(checkEnabled()));
65 connect(topspaceUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
66 this, SLOT(checkEnabled()));
67 connect(topspaceCO, SIGNAL(activated(int)),
68 this, SLOT(checkEnabled()));
69 connect(bottomspaceED, SIGNAL(editingFinished()),
70 this, SLOT(checkEnabled()));
71 connect(bottomspaceUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
72 this, SLOT(checkEnabled()));
73 connect(bottomspaceCO, SIGNAL(activated(int)),
74 this, SLOT(checkEnabled()));
75 connect(interlinespaceED, SIGNAL(editingFinished()),
76 this, SLOT(checkEnabled()));
77 connect(interlinespaceUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
78 this, SLOT(checkEnabled()));
79 connect(interlinespaceCO, SIGNAL(activated(int)),
80 this, SLOT(checkEnabled()));
81 connect(booktabsRB, SIGNAL(clicked(bool)),
82 this, SLOT(checkEnabled()));
83 connect(borderDefaultRB, SIGNAL(clicked(bool)),
84 this, SLOT(checkEnabled()));
85 connect(borderSetPB, SIGNAL(clicked()),
86 this, SLOT(borderSet_clicked()));
87 connect(borderUnsetPB, SIGNAL(clicked()),
88 this, SLOT(borderUnset_clicked()));
89 connect(hAlignCB, SIGNAL(activated(int)),
90 this, SLOT(checkEnabled()));
91 connect(vAlignCB, SIGNAL(activated(int)),
92 this, SLOT(checkEnabled()));
93 connect(multicolumnCB, SIGNAL(clicked()),
94 this, SLOT(checkEnabled()));
95 connect(multirowCB, SIGNAL(clicked()),
96 this, SLOT(checkEnabled()));
97 connect(multirowOffsetED, SIGNAL(editingFinished()),
98 this, SLOT(checkEnabled()));
99 connect(multirowOffsetUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
100 this, SLOT(checkEnabled()));
101 connect(newpageCB, SIGNAL(clicked()),
102 this, SLOT(checkEnabled()));
103 connect(headerStatusCB, SIGNAL(clicked()),
104 this, SLOT(checkEnabled()));
105 connect(headerBorderAboveCB, SIGNAL(clicked()),
106 this, SLOT(checkEnabled()));
107 connect(headerBorderBelowCB, SIGNAL(clicked()),
108 this, SLOT(checkEnabled()));
109 connect(firstheaderStatusCB, SIGNAL(clicked()),
110 this, SLOT(checkEnabled()));
111 connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
112 this, SLOT(checkEnabled()));
113 connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
114 this, SLOT(checkEnabled()));
115 connect(firstheaderNoContentsCB, SIGNAL(clicked()),
116 this, SLOT(checkEnabled()));
117 connect(footerStatusCB, SIGNAL(clicked()),
118 this, SLOT(checkEnabled()));
119 connect(footerBorderAboveCB, SIGNAL(clicked()),
120 this, SLOT(checkEnabled()));
121 connect(footerBorderBelowCB, SIGNAL(clicked()),
122 this, SLOT(checkEnabled()));
123 connect(lastfooterStatusCB, SIGNAL(clicked()),
124 this, SLOT(checkEnabled()));
125 connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
126 this, SLOT(checkEnabled()));
127 connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
128 this, SLOT(checkEnabled()));
129 connect(lastfooterNoContentsCB, SIGNAL(clicked()),
130 this, SLOT(checkEnabled()));
131 connect(captionStatusCB, SIGNAL(clicked()),
132 this, SLOT(checkEnabled()));
133 connect(specialAlignmentED, SIGNAL(textEdited(QString)),
134 this, SLOT(checkEnabled()));
135 connect(widthED, SIGNAL(editingFinished()),
136 this, SLOT(checkEnabled()));
137 connect(widthUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
138 this, SLOT(checkEnabled()));
139 connect(borders, SIGNAL(topSet(bool)),
140 this, SLOT(checkEnabled()));
141 connect(borders, SIGNAL(bottomSet(bool)),
142 this, SLOT(checkEnabled()));
143 connect(borders, SIGNAL(rightSet(bool)),
144 this, SLOT(checkEnabled()));
145 connect(borders, SIGNAL(leftSet(bool)),
146 this, SLOT(checkEnabled()));
147 connect(rotateTabularCB, SIGNAL(clicked()),
148 this, SLOT(checkEnabled()));
149 connect(rotateCellCB, SIGNAL(clicked()),
150 this, SLOT(checkEnabled()));
151 connect(TableAlignCB, SIGNAL(activated(int)),
152 this, SLOT(checkEnabled()));
153 connect(longTabularCB, SIGNAL(clicked()),
154 this, SLOT(checkEnabled()));
155 connect(leftRB, SIGNAL(clicked()),
156 this, SLOT(checkEnabled()));
157 connect(centerRB, SIGNAL(clicked()),
158 this, SLOT(checkEnabled()));
159 connect(rightRB, SIGNAL(clicked()),
160 this, SLOT(checkEnabled()));
163 // initialize the length validator
164 addCheckedWidget(widthED, fixedWidthColLA);
165 addCheckedWidget(multirowOffsetED, multirowOffsetLA);
166 addCheckedWidget(topspaceED, topspaceLA);
167 addCheckedWidget(bottomspaceED, bottomspaceLA);
168 addCheckedWidget(interlinespaceED, interlinespaceLA);
172 void GuiTabular::checkEnabled()
174 // if the column has a width, multirows are always left-aligned
175 // therefore disable hAlignCB in this case
176 hAlignCB->setEnabled(!(multirowCB->isChecked()
177 && !widgetsToLength(widthED, widthUnitCB).empty()));
179 hAlignCB->itemData(hAlignCB->currentIndex()).toString() == QString("decimal");
180 decimalPointLE->setEnabled(dalign);
181 decimalL->setEnabled(dalign);
183 vAlignCB->setEnabled(!multirowCB->isChecked()
184 && !widgetsToLength(widthED, widthUnitCB).empty());
186 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
187 topspaceUnitCB->setEnabled(topspaceCO->currentIndex() == 2);
188 bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
189 bottomspaceUnitCB->setEnabled(bottomspaceCO->currentIndex() == 2);
190 interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
191 interlinespaceUnitCB->setEnabled(interlinespaceCO->currentIndex() == 2);
193 // setting as longtable is not allowed when table is inside a float
194 longTabularCB->setEnabled(funcEnabled(Tabular::SET_LONGTABULAR));
195 bool const longtabular = longTabularCB->isChecked();
196 longtableGB->setEnabled(true);
197 newpageCB->setEnabled(longtabular);
198 alignmentGB->setEnabled(longtabular);
199 // longtables cannot have a vertical alignment
200 TableAlignCB->setDisabled(longtabular);
202 // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
203 // depending on the cursor position is very very unintuitive...
204 // We need some edit boxes to show which rows are header/footer/etc
205 // without having to move the cursor first.
206 headerStatusCB->setEnabled(longtabular);
207 headerBorderAboveCB->setEnabled(longtabular
208 && headerStatusCB->isChecked());
209 headerBorderBelowCB->setEnabled(longtabular
210 && headerStatusCB->isChecked());
212 // first header can only be suppressed when there is a header
213 // firstheader_suppressable_ is set in paramsToDialog
214 firstheaderNoContentsCB->setEnabled(longtabular && firstheader_suppressable_);
215 // check if setting a first header is allowed
216 // additionally check firstheaderNoContentsCB because when this is
217 // the case a first header makes no sense
218 firstheaderStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFIRSTHEAD)
219 && longtabular && !firstheaderNoContentsCB->isChecked());
220 firstheaderBorderAboveCB->setEnabled(longtabular
221 && firstheaderStatusCB->isChecked());
222 firstheaderBorderBelowCB->setEnabled(longtabular
223 && firstheaderStatusCB->isChecked());
225 footerStatusCB->setEnabled(longtabular);
226 footerBorderAboveCB->setEnabled(longtabular
227 && footerBorderAboveCB->isChecked());
228 footerBorderBelowCB->setEnabled(longtabular
229 && footerBorderAboveCB->isChecked());
231 // last footer can only be suppressed when there is a footer
232 // lastfooter_suppressable_ is set in paramsToDialog
233 lastfooterNoContentsCB->setEnabled(longtabular && lastfooter_suppressable_);
234 // check if setting a last footer is allowed
235 // additionally check lastfooterNoContentsCB because when this is
236 // the case a last footer makes no sense
237 lastfooterStatusCB->setEnabled(funcEnabled(Tabular::SET_LTLASTFOOT)
238 && longtabular && !lastfooterNoContentsCB->isChecked());
239 lastfooterBorderAboveCB->setEnabled(longtabular
240 && lastfooterBorderAboveCB->isChecked());
241 lastfooterBorderBelowCB->setEnabled(longtabular
242 && lastfooterBorderAboveCB->isChecked());
244 captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)
247 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
248 multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW));
249 multirowOffsetED->setEnabled(multirowCB->isChecked());
250 multirowOffsetUnitCB->setEnabled(multirowCB->isChecked());
256 void GuiTabular::borderSet_clicked()
258 borders->setTop(true);
259 borders->setBottom(true);
260 borders->setLeft(true);
261 borders->setRight(true);
262 // repaint the setborder widget
268 void GuiTabular::borderUnset_clicked()
270 borders->setTop(false);
271 borders->setBottom(false);
272 borders->setLeft(false);
273 borders->setRight(false);
274 // repaint the setborder widget
280 static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
283 param_str += featureAsString(f) + ' ' + arg;
287 void GuiTabular::setHAlign(string & param_str) const
289 Tabular::Feature num = Tabular::ALIGN_LEFT;
290 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
292 fromqstr(hAlignCB->itemData(hAlignCB->currentIndex()).toString());
293 if (align == "left") {
294 num = Tabular::ALIGN_LEFT;
295 multi_num = Tabular::M_ALIGN_LEFT;
296 } else if (align == "center") {
297 num = Tabular::ALIGN_CENTER;
298 multi_num = Tabular::M_ALIGN_CENTER;
299 } else if (align == "right") {
300 num = Tabular::ALIGN_RIGHT;
301 multi_num = Tabular::M_ALIGN_RIGHT;
302 } else if (align == "justified") {
303 num = Tabular::ALIGN_BLOCK;
304 //multi_num: no equivalent
305 } else if (align == "decimal") {
306 num = Tabular::ALIGN_DECIMAL;
307 //multi_num: no equivalent
310 if (multicolumnCB->isChecked())
311 setParam(param_str, multi_num);
313 setParam(param_str, num);
317 void GuiTabular::setVAlign(string & param_str) const
319 int const align = vAlignCB->currentIndex();
320 enum VALIGN { TOP, MIDDLE, BOTTOM };
324 case 0: v = TOP; break;
325 case 1: v = MIDDLE; break;
326 case 2: v = BOTTOM; break;
329 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
330 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
334 num = Tabular::VALIGN_TOP;
335 multi_num = Tabular::M_VALIGN_TOP;
338 num = Tabular::VALIGN_MIDDLE;
339 multi_num = Tabular::M_VALIGN_MIDDLE;
342 num = Tabular::VALIGN_BOTTOM;
343 multi_num = Tabular::M_VALIGN_BOTTOM;
346 if (multicolumnCB->isChecked() || multirowCB->isChecked())
347 setParam(param_str, multi_num);
349 setParam(param_str, num);
353 void GuiTabular::setTableAlignment(string & param_str) const
355 int const align = TableAlignCB->currentIndex();
357 case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
359 case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
361 case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
367 docstring GuiTabular::dialogToParams() const
369 // FIXME: We should use Tabular directly.
370 string param_str = "tabular";
372 // apply the fixed width values
373 // this must be done before applying the column alignment
374 // because its value influences the alignment of multirow cells
375 string width = widgetsToLength(widthED, widthUnitCB);
378 if (multicolumnCB->isChecked())
379 setParam(param_str, Tabular::SET_MPWIDTH, width);
381 setParam(param_str, Tabular::SET_PWIDTH, width);
383 // apply the column alignment
384 setHAlign(param_str);
386 // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
387 string decimal_point = fromqstr(decimalPointLE->text());
388 if (decimal_point.empty())
389 decimal_point = lyxrc.default_decimal_point;
390 setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
392 setVAlign(param_str);
393 setTableAlignment(param_str);
395 if (booktabsRB->isChecked())
396 setParam(param_str, Tabular::SET_BOOKTABS);
398 setParam(param_str, Tabular::UNSET_BOOKTABS);
401 switch (topspaceCO->currentIndex()) {
403 setParam(param_str, Tabular::SET_TOP_SPACE, "none");
406 setParam(param_str, Tabular::SET_TOP_SPACE, "default");
409 if (!topspaceED->text().isEmpty())
410 setParam(param_str, Tabular::SET_TOP_SPACE,
411 widgetsToLength(topspaceED, topspaceUnitCB));
416 switch (bottomspaceCO->currentIndex()) {
418 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
421 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
424 if (!bottomspaceED->text().isEmpty())
425 setParam(param_str, Tabular::SET_BOTTOM_SPACE,
426 widgetsToLength(bottomspaceED,
432 switch (interlinespaceCO->currentIndex()) {
434 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
437 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
440 if (!interlinespaceED->text().isEmpty())
441 setParam(param_str, Tabular::SET_INTERLINE_SPACE,
442 widgetsToLength(interlinespaceED,
443 interlinespaceUnitCB));
448 if (borders->getTop() && borders->getBottom() && borders->getLeft()
449 && borders->getRight())
450 setParam(param_str, Tabular::SET_ALL_LINES);
451 else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft()
452 && !borders->getRight())
453 setParam(param_str, Tabular::UNSET_ALL_LINES);
455 setParam(param_str, Tabular::SET_LINE_LEFT,
456 borders->getLeft() ? "true" : "false");
457 setParam(param_str, Tabular::SET_LINE_RIGHT,
458 borders->getRight() ? "true" : "false");
459 setParam(param_str, Tabular::SET_LINE_TOP,
460 borders->getTop() ? "true" : "false");
461 setParam(param_str, Tabular::SET_LINE_BOTTOM,
462 borders->getBottom() ? "true" : "false");
465 // apply the special alignment
466 string special = fromqstr(specialAlignmentED->text());
469 if (multicolumnCB->isChecked())
470 setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
472 setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
475 if (multicolumnCB->isChecked())
476 setParam(param_str, Tabular::SET_MULTICOLUMN);
478 setParam(param_str, Tabular::UNSET_MULTICOLUMN);
480 // apply the multirow offset
481 string mroffset = widgetsToLength(multirowOffsetED, multirowOffsetUnitCB);
482 if (mroffset.empty())
484 if (multirowCB->isChecked())
485 setParam(param_str, Tabular::SET_MROFFSET, mroffset);
487 if (multirowCB->isChecked())
488 setParam(param_str, Tabular::SET_MULTIROW);
490 setParam(param_str, Tabular::UNSET_MULTIROW);
492 if (rotateTabularCB->isChecked())
493 setParam(param_str, Tabular::SET_ROTATE_TABULAR);
495 setParam(param_str, Tabular::UNSET_ROTATE_TABULAR);
497 if (rotateCellCB->isChecked())
498 setParam(param_str, Tabular::SET_ROTATE_CELL);
500 setParam(param_str, Tabular::UNSET_ROTATE_CELL);
502 if (longTabularCB->isChecked())
503 setParam(param_str, Tabular::SET_LONGTABULAR);
505 setParam(param_str, Tabular::UNSET_LONGTABULAR);
507 if (newpageCB->isChecked())
508 setParam(param_str, Tabular::SET_LTNEWPAGE);
510 if (captionStatusCB->isChecked())
511 setParam(param_str, Tabular::SET_LTCAPTION);
513 setParam(param_str, Tabular::UNSET_LTCAPTION);
515 if (headerStatusCB->isChecked())
516 setParam(param_str, Tabular::SET_LTHEAD, "none");
518 setParam(param_str, Tabular::UNSET_LTHEAD, "none");
520 if (headerBorderAboveCB->isChecked())
521 setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
523 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
525 if (headerBorderBelowCB->isChecked())
526 setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
528 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
529 if (firstheaderBorderAboveCB->isChecked())
530 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
532 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
533 if (firstheaderBorderBelowCB->isChecked())
534 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
536 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
537 if (firstheaderStatusCB->isChecked())
538 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
540 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
541 if (firstheaderNoContentsCB->isChecked())
542 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
544 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
545 if (footerStatusCB->isChecked())
546 setParam(param_str, Tabular::SET_LTFOOT, "none");
548 setParam(param_str, Tabular::UNSET_LTFOOT, "none");
549 if (footerBorderAboveCB->isChecked())
550 setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
552 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
553 if (footerBorderBelowCB->isChecked())
554 setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
556 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
557 if (lastfooterStatusCB->isChecked())
558 setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
560 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
561 if (lastfooterBorderAboveCB->isChecked())
562 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
564 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
565 if (lastfooterBorderBelowCB->isChecked())
566 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
568 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
569 if (lastfooterNoContentsCB->isChecked())
570 setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
572 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
574 if (leftRB->isChecked())
575 setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
576 else if (centerRB->isChecked())
577 setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
578 else if (rightRB->isChecked())
579 setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
581 return from_utf8(param_str);
585 static Length getColumnPWidth(Tabular const & t, size_t cell)
587 return t.column_info[t.cellColumn(cell)].p_width;
591 static Length getMColumnPWidth(Tabular const & t, size_t cell)
593 if (t.isMultiColumn(cell) || t.isMultiRow(cell))
594 return t.cellInfo(cell).p_width;
599 static Length getMROffset(Tabular const & t, size_t cell)
601 if (t.isMultiRow(cell))
602 return t.cellInfo(cell).mroffset;
607 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
609 if (what == Tabular::SET_SPECIAL_MULTICOLUMN)
610 return t.cellInfo(cell).align_special;
611 return t.column_info[t.cellColumn(cell)].align_special;
615 void GuiTabular::paramsToDialog(Inset const * inset)
617 InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
618 // Copy Tabular of current inset.
619 Tabular const & tabular = itab->tabular;
621 BufferView const * bv = guiApp->currentView()->currentBufferView();
622 size_t const cell = bv->cursor().idx();
624 Tabular::row_type const row = tabular.cellRow(cell);
625 Tabular::col_type const col = tabular.cellColumn(cell);
627 tabularRowED->setText(QString::number(row + 1));
628 tabularColumnED->setText(QString::number(col + 1));
630 bool const multicol = tabular.isMultiColumn(cell);
631 multicolumnCB->setChecked(multicol);
633 bool const multirow = tabular.isMultiRow(cell);
634 multirowCB->setChecked(multirow);
636 rotateCellCB->setChecked(tabular.getRotateCell(cell));
637 rotateTabularCB->setChecked(tabular.rotate);
639 longTabularCB->setChecked(tabular.is_long_tabular);
641 borders->setTop(tabular.topLine(cell));
642 borders->setBottom(tabular.bottomLine(cell));
643 borders->setLeft(tabular.leftLine(cell));
644 borders->setRight(tabular.rightLine(cell));
645 // repaint the setborder widget
648 Length::UNIT const default_unit = Length::defaultUnit();
650 ///////////////////////////////////
651 // Set width and alignment
655 special = getAlignSpecial(tabular, cell,
656 Tabular::SET_SPECIAL_MULTICOLUMN);
657 pwidth = getMColumnPWidth(tabular, cell);
659 special = getAlignSpecial(tabular, cell,
660 Tabular::SET_SPECIAL_COLUMN);
661 pwidth = getColumnPWidth(tabular, cell);
667 colwidth = pwidth.asString();
668 lengthToWidgets(widthED, widthUnitCB,
669 colwidth, default_unit);
673 mroffset = getMROffset(tabular, cell);
676 multirowOffsetED->clear();
678 offset = mroffset.asString();
679 lengthToWidgets(multirowOffsetED, multirowOffsetUnitCB,
680 offset, default_unit);
682 specialAlignmentED->setText(toqstr(special));
683 ///////////////////////////////////
686 borderDefaultRB->setChecked(!tabular.use_booktabs);
687 booktabsRB->setChecked(tabular.use_booktabs);
689 if (tabular.row_info[row].top_space.empty()
690 && !tabular.row_info[row].top_space_default) {
691 topspaceCO->setCurrentIndex(0);
692 } else if (tabular.row_info[row].top_space_default) {
693 topspaceCO->setCurrentIndex(1);
695 topspaceCO->setCurrentIndex(2);
696 lengthToWidgets(topspaceED,
698 tabular.row_info[row].top_space.asString(),
702 if (tabular.row_info[row].bottom_space.empty()
703 && !tabular.row_info[row].bottom_space_default) {
704 bottomspaceCO->setCurrentIndex(0);
705 } else if (tabular.row_info[row].bottom_space_default) {
706 bottomspaceCO->setCurrentIndex(1);
708 bottomspaceCO->setCurrentIndex(2);
709 lengthToWidgets(bottomspaceED,
711 tabular.row_info[row].bottom_space.asString(),
715 if (tabular.row_info[row].interline_space.empty()
716 && !tabular.row_info[row].interline_space_default) {
717 interlinespaceCO->setCurrentIndex(0);
718 } else if (tabular.row_info[row].interline_space_default) {
719 interlinespaceCO->setCurrentIndex(1);
721 interlinespaceCO->setCurrentIndex(2);
722 lengthToWidgets(interlinespaceED,
723 interlinespaceUnitCB,
724 tabular.row_info[row].interline_space.asString(),
729 hAlignCB->addItem(qt_("Left"), toqstr("left"));
730 hAlignCB->addItem(qt_("Center"), toqstr("center"));
731 hAlignCB->addItem(qt_("Right"), toqstr("right"));
732 if (!multicol && !pwidth.zero())
733 hAlignCB->addItem(qt_("Justified"), toqstr("justified"));
735 hAlignCB->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
738 switch (tabular.getAlignment(cell)) {
742 case LYX_ALIGN_CENTER:
745 case LYX_ALIGN_RIGHT:
748 case LYX_ALIGN_BLOCK:
750 if (!multicol && !pwidth.zero())
754 case LYX_ALIGN_DECIMAL:
761 // we should never end up here
764 hAlignCB->setCurrentIndex(hAlignCB->findData(toqstr(align)));
767 QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
768 if (decimal_point.isEmpty())
769 decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
770 decimalPointLE->setText(decimal_point);
773 switch (tabular.getVAlignment(cell)) {
774 case Tabular::LYX_VALIGN_TOP:
777 case Tabular::LYX_VALIGN_MIDDLE:
780 case Tabular::LYX_VALIGN_BOTTOM:
789 vAlignCB->setCurrentIndex(valign);
792 switch (tabular.tabular_valignment) {
793 case Tabular::LYX_VALIGN_TOP:
796 case Tabular::LYX_VALIGN_MIDDLE:
799 case Tabular::LYX_VALIGN_BOTTOM:
806 TableAlignCB->setCurrentIndex(tableValign);
808 if (!tabular.is_long_tabular) {
809 headerStatusCB->setChecked(false);
810 headerBorderAboveCB->setChecked(false);
811 headerBorderBelowCB->setChecked(false);
812 firstheaderStatusCB->setChecked(false);
813 firstheaderBorderAboveCB->setChecked(false);
814 firstheaderBorderBelowCB->setChecked(false);
815 firstheaderNoContentsCB->setChecked(false);
816 footerStatusCB->setChecked(false);
817 footerBorderAboveCB->setChecked(false);
818 footerBorderBelowCB->setChecked(false);
819 lastfooterStatusCB->setChecked(false);
820 lastfooterBorderAboveCB->setChecked(false);
821 lastfooterBorderBelowCB->setChecked(false);
822 lastfooterNoContentsCB->setChecked(false);
823 newpageCB->setChecked(false);
824 captionStatusCB->blockSignals(true);
825 captionStatusCB->setChecked(false);
826 captionStatusCB->blockSignals(false);
830 // longtables cannot have a vertical alignment
831 TableAlignCB->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
833 switch (tabular.longtabular_alignment) {
834 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
835 leftRB->setChecked(true);
837 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
838 centerRB->setChecked(true);
840 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
841 rightRB->setChecked(true);
844 centerRB->setChecked(true);
847 captionStatusCB->blockSignals(true);
848 captionStatusCB->setChecked(tabular.ltCaption(row));
849 captionStatusCB->blockSignals(false);
853 bool row_set = tabular.getRowOfLTHead(row, ltt);
854 headerStatusCB->setChecked(row_set);
856 headerBorderAboveCB->setChecked(ltt.topDL);
857 headerBorderBelowCB->setChecked(ltt.bottomDL);
860 headerBorderAboveCB->setChecked(false);
861 headerBorderBelowCB->setChecked(false);
862 firstheaderNoContentsCB->setChecked(false);
866 row_set = tabular.getRowOfLTFirstHead(row, ltt);
867 firstheaderStatusCB->setChecked(row_set);
868 if (ltt.set && (!ltt.empty || !use_empty)) {
869 firstheaderBorderAboveCB->setChecked(ltt.topDL);
870 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
872 firstheaderBorderAboveCB->setChecked(false);
873 firstheaderBorderBelowCB->setChecked(false);
876 row_set = tabular.getRowOfLTFoot(row, ltt);
877 footerStatusCB->setChecked(row_set);
879 footerBorderAboveCB->setChecked(ltt.topDL);
880 footerBorderBelowCB->setChecked(ltt.bottomDL);
883 footerBorderAboveCB->setChecked(false);
884 footerBorderBelowCB->setChecked(false);
885 lastfooterNoContentsCB->setChecked(false);
889 row_set = tabular.getRowOfLTLastFoot(row, ltt);
890 lastfooterStatusCB->setChecked(row_set);
891 if (ltt.set && (!ltt.empty || !use_empty)) {
892 lastfooterBorderAboveCB->setChecked(ltt.topDL);
893 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
895 lastfooterBorderAboveCB->setChecked(false);
896 lastfooterBorderBelowCB->setChecked(false);
898 newpageCB->setChecked(tabular.getLTNewPage(row));
900 // first header can only be suppressed when there is a header
901 firstheader_suppressable_ = tabular.haveLTHead()
902 && !tabular.haveLTFirstHead();
903 // last footer can only be suppressed when there is a footer
904 lastfooter_suppressable_ = tabular.haveLTFoot()
905 && !tabular.haveLTLastFoot();
907 // after setting the features, check if they are enabled
912 bool GuiTabular::funcEnabled(Tabular::Feature f) const
914 string cmd = "tabular " + featureAsString(f);
915 return getStatus(FuncRequest(LFUN_INSET_MODIFY, cmd)).enabled();
919 } // namespace frontend
922 #include "moc_GuiTabular.cpp"