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 tabularWidthED->setValidator(unsignedLengthValidator(tabularWidthED));
52 columnWidthED->setValidator(unsignedLengthValidator(columnWidthED));
53 multirowOffsetED->setValidator(new LengthValidator(multirowOffsetED));
54 topspaceED->setValidator(new LengthValidator(topspaceED));
55 bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
56 interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
58 tabularWidthUnitLC->setCurrentItem(Length::defaultUnit());
59 columnWidthUnitLC->setCurrentItem(Length::defaultUnit());
60 multirowOffsetUnitLC->setCurrentItem(Length::defaultUnit());
61 topspaceUnitLC->setCurrentItem(Length::defaultUnit());
62 bottomspaceUnitLC->setCurrentItem(Length::defaultUnit());
63 interlinespaceUnitLC->setCurrentItem(Length::defaultUnit());
65 connect(topspaceED, SIGNAL(textEdited(const QString &)),
66 this, SLOT(checkEnabled()));
67 connect(topspaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
68 this, SLOT(checkEnabled()));
69 connect(bottomspaceED, SIGNAL(textEdited(const QString &)),
70 this, SLOT(checkEnabled()));
71 connect(bottomspaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
72 this, SLOT(checkEnabled()));
73 connect(interlinespaceED, SIGNAL(textEdited(const QString &)),
74 this, SLOT(checkEnabled()));
75 connect(interlinespaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
76 this, SLOT(checkEnabled()));
77 connect(booktabsRB, SIGNAL(clicked(bool)),
78 this, SLOT(checkEnabled()));
79 connect(borderDefaultRB, SIGNAL(clicked(bool)),
80 this, SLOT(checkEnabled()));
81 connect(borderSetPB, SIGNAL(clicked()),
82 this, SLOT(borderSet_clicked()));
83 connect(borderUnsetPB, SIGNAL(clicked()),
84 this, SLOT(borderUnset_clicked()));
85 connect(hAlignCO, SIGNAL(activated(int)),
86 this, SLOT(checkEnabled()));
87 connect(vAlignCO, SIGNAL(activated(int)),
88 this, SLOT(checkEnabled()));
89 connect(multicolumnCB, SIGNAL(clicked()),
90 this, SLOT(checkEnabled()));
91 connect(multirowCB, SIGNAL(clicked()),
92 this, SLOT(checkEnabled()));
93 connect(multirowOffsetED, SIGNAL(textEdited(const QString &)),
94 this, SLOT(checkEnabled()));
95 connect(multirowOffsetUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
96 this, SLOT(checkEnabled()));
97 connect(newpageCB, SIGNAL(clicked()),
98 this, SLOT(checkEnabled()));
99 connect(headerStatusCB, SIGNAL(clicked()),
100 this, SLOT(checkEnabled()));
101 connect(headerBorderAboveCB, SIGNAL(clicked()),
102 this, SLOT(checkEnabled()));
103 connect(headerBorderBelowCB, SIGNAL(clicked()),
104 this, SLOT(checkEnabled()));
105 connect(firstheaderStatusCB, SIGNAL(clicked()),
106 this, SLOT(checkEnabled()));
107 connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
108 this, SLOT(checkEnabled()));
109 connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
110 this, SLOT(checkEnabled()));
111 connect(firstheaderNoContentsCB, SIGNAL(clicked()),
112 this, SLOT(checkEnabled()));
113 connect(footerStatusCB, SIGNAL(clicked()),
114 this, SLOT(checkEnabled()));
115 connect(footerBorderAboveCB, SIGNAL(clicked()),
116 this, SLOT(checkEnabled()));
117 connect(footerBorderBelowCB, SIGNAL(clicked()),
118 this, SLOT(checkEnabled()));
119 connect(lastfooterStatusCB, SIGNAL(clicked()),
120 this, SLOT(checkEnabled()));
121 connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
122 this, SLOT(checkEnabled()));
123 connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
124 this, SLOT(checkEnabled()));
125 connect(lastfooterNoContentsCB, SIGNAL(clicked()),
126 this, SLOT(checkEnabled()));
127 connect(captionStatusCB, SIGNAL(clicked()),
128 this, SLOT(checkEnabled()));
129 connect(specialAlignmentED, SIGNAL(editingFinished()),
130 this, SLOT(checkEnabled()));
131 connect(columnWidthED, SIGNAL(textEdited(const QString &)),
132 this, SLOT(checkEnabled()));
133 connect(columnWidthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
134 this, SLOT(checkEnabled()));
135 connect(borders, SIGNAL(topSet(bool)),
136 this, SLOT(checkEnabled()));
137 connect(borders, SIGNAL(bottomSet(bool)),
138 this, SLOT(checkEnabled()));
139 connect(borders, SIGNAL(rightSet(bool)),
140 this, SLOT(checkEnabled()));
141 connect(borders, SIGNAL(leftSet(bool)),
142 this, SLOT(checkEnabled()));
143 connect(rotateTabularCB, SIGNAL(clicked()),
144 this, SLOT(checkEnabled()));
145 connect(rotateCellCB, SIGNAL(clicked()),
146 this, SLOT(checkEnabled()));
147 connect(TableAlignCO, SIGNAL(activated(int)),
148 this, SLOT(checkEnabled()));
149 connect(longTabularCB, SIGNAL(clicked()),
150 this, SLOT(checkEnabled()));
151 connect(leftRB, SIGNAL(clicked()),
152 this, SLOT(checkEnabled()));
153 connect(centerRB, SIGNAL(clicked()),
154 this, SLOT(checkEnabled()));
155 connect(rightRB, SIGNAL(clicked()),
156 this, SLOT(checkEnabled()));
157 connect(tabularWidthED, SIGNAL(textEdited(const QString &)),
158 this, SLOT(checkEnabled()));
160 decimalPointED->setInputMask("X; ");
161 decimalPointED->setMaxLength(1);
163 // initialize the length validator
164 addCheckedWidget(columnWidthED, columnWidthLA);
165 addCheckedWidget(multirowOffsetED, multirowOffsetLA);
166 addCheckedWidget(topspaceED, topspaceLA);
167 addCheckedWidget(bottomspaceED, bottomspaceLA);
168 addCheckedWidget(interlinespaceED, interlinespaceLA);
169 addCheckedWidget(tabularWidthED, tabularWidthLA);
173 void GuiTabular::on_topspaceCO_activated(int index)
175 bool const enable = (index == 2);
176 topspaceED->setEnabled(enable);
177 topspaceUnitLC->setEnabled(enable);
181 void GuiTabular::on_bottomspaceCO_activated(int index)
183 bool const enable = (index == 2);
184 bottomspaceED->setEnabled(enable);
185 bottomspaceUnitLC->setEnabled(enable);
189 void GuiTabular::on_interlinespaceCO_activated(int index)
191 bool const enable = (index == 2);
192 interlinespaceED->setEnabled(enable);
193 interlinespaceUnitLC->setEnabled(enable);
197 void GuiTabular::checkEnabled()
199 // if there is a LaTeX argument, the width and alignment will be overwritten
200 // therefore disable them in this case
201 columnWidthED->setEnabled(specialAlignmentED->text().isEmpty());
202 // if the column has a width, multirows are always left-aligned
203 // therefore disable hAlignCB in this case
204 hAlignCO->setEnabled(!(multirowCB->isChecked()
205 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty())
206 && specialAlignmentED->text().isEmpty());
208 hAlignCO->itemData(hAlignCO->currentIndex()).toString() == QString("decimal");
209 decimalPointED->setEnabled(dalign);
210 decimalLA->setEnabled(dalign);
212 bool const setwidth = TableAlignCO->currentText() == qt_("Middle")
213 && !longTabularCB->isChecked() && !rotateTabularCB->isChecked();
214 tabularWidthLA->setEnabled(setwidth);
215 tabularWidthED->setEnabled(setwidth);
216 tabularWidthUnitLC->setEnabled(setwidth);
218 bool const is_tabular_star = !tabularWidthED->text().isEmpty();
219 rotateTabularCB->setDisabled(is_tabular_star);
221 vAlignCO->setEnabled(!multirowCB->isChecked()
222 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty()
223 && specialAlignmentED->text().isEmpty());
225 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
226 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
227 topspaceUnitLC->setEnabled(topspaceCO->currentIndex() == 2);
228 bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
229 bottomspaceUnitLC->setEnabled(bottomspaceCO->currentIndex() == 2);
230 interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
231 interlinespaceUnitLC->setEnabled(interlinespaceCO->currentIndex() == 2);
233 // setting as longtable is not allowed when table is inside a float
234 longTabularCB->setEnabled(!is_tabular_star && funcEnabled(Tabular::SET_LONGTABULAR));
235 bool const longtabular = longTabularCB->isChecked();
236 longtableGB->setEnabled(true);
237 newpageCB->setEnabled(longtabular);
238 alignmentGB->setEnabled(longtabular);
239 // longtables and tabular* cannot have a vertical alignment
240 TableAlignLA->setDisabled(is_tabular_star || longtabular);
241 TableAlignCO->setDisabled(is_tabular_star || longtabular);
243 // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
244 // depending on the cursor position is very very unintuitive...
245 // We need some edit boxes to show which rows are header/footer/etc
246 // without having to move the cursor first.
247 headerStatusCB->setEnabled(longtabular);
248 headerBorderAboveCB->setEnabled(longtabular
249 && headerStatusCB->isChecked());
250 headerBorderBelowCB->setEnabled(longtabular
251 && headerStatusCB->isChecked());
253 // first header can only be suppressed when there is a header
254 // firstheader_suppressable_ is set in paramsToDialog
255 firstheaderNoContentsCB->setEnabled(longtabular && firstheader_suppressable_);
256 // check if setting a first header is allowed
257 // additionally check firstheaderNoContentsCB because when this is
258 // the case a first header makes no sense
259 firstheaderStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFIRSTHEAD)
260 && longtabular && !firstheaderNoContentsCB->isChecked());
261 firstheaderBorderAboveCB->setEnabled(longtabular
262 && firstheaderStatusCB->isChecked());
263 firstheaderBorderBelowCB->setEnabled(longtabular
264 && firstheaderStatusCB->isChecked());
266 footerStatusCB->setEnabled(longtabular);
267 footerBorderAboveCB->setEnabled(longtabular
268 && footerBorderAboveCB->isChecked());
269 footerBorderBelowCB->setEnabled(longtabular
270 && footerBorderAboveCB->isChecked());
272 // last footer can only be suppressed when there is a footer
273 // lastfooter_suppressable_ is set in paramsToDialog
274 lastfooterNoContentsCB->setEnabled(longtabular && lastfooter_suppressable_);
275 // check if setting a last footer is allowed
276 // additionally check lastfooterNoContentsCB because when this is
277 // the case a last footer makes no sense
278 lastfooterStatusCB->setEnabled(funcEnabled(Tabular::SET_LTLASTFOOT)
279 && longtabular && !lastfooterNoContentsCB->isChecked());
280 lastfooterBorderAboveCB->setEnabled(longtabular
281 && lastfooterBorderAboveCB->isChecked());
282 lastfooterBorderBelowCB->setEnabled(longtabular
283 && lastfooterBorderAboveCB->isChecked());
285 captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)
288 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
289 multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW));
290 multirowOffsetED->setEnabled(multirowCB->isChecked());
291 multirowOffsetUnitLC->setEnabled(multirowCB->isChecked());
297 void GuiTabular::borderSet_clicked()
299 borders->setTop(true);
300 borders->setBottom(true);
301 borders->setLeft(true);
302 borders->setRight(true);
303 // repaint the setborder widget
309 void GuiTabular::borderUnset_clicked()
311 borders->setTop(false);
312 borders->setBottom(false);
313 borders->setLeft(false);
314 borders->setRight(false);
315 // repaint the setborder widget
321 static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
324 param_str += featureAsString(f) + ' ' + arg;
328 void GuiTabular::setHAlign(string & param_str) const
330 Tabular::Feature num = Tabular::ALIGN_LEFT;
331 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
333 fromqstr(hAlignCO->itemData(hAlignCO->currentIndex()).toString());
334 if (align == "left") {
335 num = Tabular::ALIGN_LEFT;
336 multi_num = Tabular::M_ALIGN_LEFT;
337 } else if (align == "center") {
338 num = Tabular::ALIGN_CENTER;
339 multi_num = Tabular::M_ALIGN_CENTER;
340 } else if (align == "right") {
341 num = Tabular::ALIGN_RIGHT;
342 multi_num = Tabular::M_ALIGN_RIGHT;
343 } else if (align == "justified") {
344 num = Tabular::ALIGN_BLOCK;
345 //multi_num: no equivalent
346 } else if (align == "decimal") {
347 num = Tabular::ALIGN_DECIMAL;
348 //multi_num: no equivalent
351 if (multicolumnCB->isChecked())
352 setParam(param_str, multi_num);
354 setParam(param_str, num);
358 void GuiTabular::setVAlign(string & param_str) const
360 int const align = vAlignCO->currentIndex();
361 enum VALIGN { TOP, MIDDLE, BOTTOM };
365 case 0: v = TOP; break;
366 case 1: v = MIDDLE; break;
367 case 2: v = BOTTOM; break;
370 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
371 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
375 num = Tabular::VALIGN_TOP;
376 multi_num = Tabular::M_VALIGN_TOP;
379 num = Tabular::VALIGN_MIDDLE;
380 multi_num = Tabular::M_VALIGN_MIDDLE;
383 num = Tabular::VALIGN_BOTTOM;
384 multi_num = Tabular::M_VALIGN_BOTTOM;
387 if (multicolumnCB->isChecked() || multirowCB->isChecked())
388 setParam(param_str, multi_num);
390 setParam(param_str, num);
394 void GuiTabular::setTableAlignment(string & param_str) const
396 int const align = TableAlignCO->currentIndex();
398 case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
400 case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
402 case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
408 docstring GuiTabular::dialogToParams() const
410 // FIXME: We should use Tabular directly.
411 string param_str = "tabular from-dialog";
414 string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitLC);
415 if (tabwidth.empty())
417 setParam(param_str, Tabular::SET_TABULAR_WIDTH, tabwidth);
419 // apply the fixed width values
420 // this must be done before applying the column alignment
421 // because its value influences the alignment of multirow cells
422 string width = widgetsToLength(columnWidthED, columnWidthUnitLC);
425 if (multicolumnCB->isChecked())
426 setParam(param_str, Tabular::SET_MPWIDTH, width);
428 setParam(param_str, Tabular::SET_PWIDTH, width);
430 // apply the column alignment
431 setHAlign(param_str);
433 // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
434 string decimal_point = fromqstr(decimalPointED->text());
435 if (decimal_point.empty())
436 decimal_point = lyxrc.default_decimal_point;
437 setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
439 setVAlign(param_str);
440 setTableAlignment(param_str);
442 if (booktabsRB->isChecked())
443 setParam(param_str, Tabular::SET_BOOKTABS);
445 setParam(param_str, Tabular::UNSET_BOOKTABS);
448 switch (topspaceCO->currentIndex()) {
450 setParam(param_str, Tabular::SET_TOP_SPACE, "none");
453 setParam(param_str, Tabular::SET_TOP_SPACE, "default");
456 if (!topspaceED->text().isEmpty())
457 setParam(param_str, Tabular::SET_TOP_SPACE,
458 widgetsToLength(topspaceED, topspaceUnitLC));
463 switch (bottomspaceCO->currentIndex()) {
465 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
468 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
471 if (!bottomspaceED->text().isEmpty())
472 setParam(param_str, Tabular::SET_BOTTOM_SPACE,
473 widgetsToLength(bottomspaceED,
479 switch (interlinespaceCO->currentIndex()) {
481 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
484 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
487 if (!interlinespaceED->text().isEmpty())
488 setParam(param_str, Tabular::SET_INTERLINE_SPACE,
489 widgetsToLength(interlinespaceED,
490 interlinespaceUnitLC));
495 if (borders->getTop() && borders->getBottom() && borders->getLeft()
496 && borders->getRight())
497 setParam(param_str, Tabular::SET_ALL_LINES);
498 else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft()
499 && !borders->getRight())
500 setParam(param_str, Tabular::UNSET_ALL_LINES);
502 setParam(param_str, Tabular::SET_LINE_LEFT,
503 borders->getLeft() ? "true" : "false");
504 setParam(param_str, Tabular::SET_LINE_RIGHT,
505 borders->getRight() ? "true" : "false");
506 setParam(param_str, Tabular::SET_LINE_TOP,
507 borders->getTop() ? "true" : "false");
508 setParam(param_str, Tabular::SET_LINE_BOTTOM,
509 borders->getBottom() ? "true" : "false");
512 // apply the special alignment
513 string special = fromqstr(specialAlignmentED->text());
516 if (multicolumnCB->isChecked())
517 setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
519 setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
522 if (multicolumnCB->isChecked())
523 setParam(param_str, Tabular::SET_MULTICOLUMN);
525 setParam(param_str, Tabular::UNSET_MULTICOLUMN);
527 // apply the multirow offset
528 string mroffset = widgetsToLength(multirowOffsetED, multirowOffsetUnitLC);
529 if (mroffset.empty())
531 if (multirowCB->isChecked())
532 setParam(param_str, Tabular::SET_MROFFSET, mroffset);
534 if (multirowCB->isChecked())
535 setParam(param_str, Tabular::SET_MULTIROW);
537 setParam(param_str, Tabular::UNSET_MULTIROW);
539 if (rotateTabularCB->isChecked())
540 setParam(param_str, Tabular::SET_ROTATE_TABULAR);
542 setParam(param_str, Tabular::UNSET_ROTATE_TABULAR);
544 if (rotateCellCB->isChecked())
545 setParam(param_str, Tabular::SET_ROTATE_CELL);
547 setParam(param_str, Tabular::UNSET_ROTATE_CELL);
549 if (longTabularCB->isChecked())
550 setParam(param_str, Tabular::SET_LONGTABULAR);
552 setParam(param_str, Tabular::UNSET_LONGTABULAR);
554 if (newpageCB->isChecked())
555 setParam(param_str, Tabular::SET_LTNEWPAGE);
557 if (captionStatusCB->isChecked())
558 setParam(param_str, Tabular::SET_LTCAPTION);
560 setParam(param_str, Tabular::UNSET_LTCAPTION);
562 if (headerStatusCB->isChecked())
563 setParam(param_str, Tabular::SET_LTHEAD, "none");
565 setParam(param_str, Tabular::UNSET_LTHEAD, "none");
567 if (headerBorderAboveCB->isChecked())
568 setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
570 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
572 if (headerBorderBelowCB->isChecked())
573 setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
575 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
576 if (firstheaderBorderAboveCB->isChecked())
577 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
579 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
580 if (firstheaderBorderBelowCB->isChecked())
581 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
583 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
584 if (firstheaderStatusCB->isChecked())
585 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
587 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
588 if (firstheaderNoContentsCB->isChecked())
589 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
591 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
592 if (footerStatusCB->isChecked())
593 setParam(param_str, Tabular::SET_LTFOOT, "none");
595 setParam(param_str, Tabular::UNSET_LTFOOT, "none");
596 if (footerBorderAboveCB->isChecked())
597 setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
599 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
600 if (footerBorderBelowCB->isChecked())
601 setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
603 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
604 if (lastfooterStatusCB->isChecked())
605 setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
607 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
608 if (lastfooterBorderAboveCB->isChecked())
609 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
611 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
612 if (lastfooterBorderBelowCB->isChecked())
613 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
615 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
616 if (lastfooterNoContentsCB->isChecked())
617 setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
619 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
621 if (leftRB->isChecked())
622 setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
623 else if (centerRB->isChecked())
624 setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
625 else if (rightRB->isChecked())
626 setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
628 return from_utf8(param_str);
632 static Length getColumnPWidth(Tabular const & t, size_t cell)
634 return t.column_info[t.cellColumn(cell)].p_width;
638 static Length getMColumnPWidth(Tabular const & t, size_t cell)
640 if (t.isMultiColumn(cell) || t.isMultiRow(cell))
641 return t.cellInfo(cell).p_width;
646 static Length getMROffset(Tabular const & t, size_t cell)
648 if (t.isMultiRow(cell))
649 return t.cellInfo(cell).mroffset;
654 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
656 if (what == Tabular::SET_SPECIAL_MULTICOLUMN)
657 return t.cellInfo(cell).align_special;
658 return t.column_info[t.cellColumn(cell)].align_special;
662 void GuiTabular::paramsToDialog(Inset const * inset)
664 InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
665 // Copy Tabular of current inset.
666 Tabular const & tabular = itab->tabular;
668 BufferView const * bv = guiApp->currentView()->currentBufferView();
669 size_t const cell = bv->cursor().idx();
671 Tabular::row_type const row = tabular.cellRow(cell);
672 Tabular::col_type const col = tabular.cellColumn(cell);
674 tabularRowED->setText(QString::number(row + 1));
675 tabularColumnED->setText(QString::number(col + 1));
677 bool const multicol = tabular.isMultiColumn(cell);
678 multicolumnCB->setChecked(multicol);
680 bool const multirow = tabular.isMultiRow(cell);
681 multirowCB->setChecked(multirow);
683 rotateCellCB->setChecked(tabular.getRotateCell(cell));
684 rotateTabularCB->setChecked(tabular.rotate);
686 longTabularCB->setChecked(tabular.is_long_tabular);
688 borders->setTop(tabular.topLine(cell));
689 borders->setBottom(tabular.bottomLine(cell));
690 borders->setLeft(tabular.leftLine(cell));
691 borders->setRight(tabular.rightLine(cell));
692 // repaint the setborder widget
695 Length::UNIT const default_unit = Length::defaultUnit();
697 ///////////////////////////////////
698 // Set width and alignment
700 Length const tabwidth = tabular.tabularWidth();
702 tabularWidthED->clear();
704 lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
705 tabwidth.asString(), default_unit);
710 special = getAlignSpecial(tabular, cell,
711 Tabular::SET_SPECIAL_MULTICOLUMN);
712 pwidth = getMColumnPWidth(tabular, cell);
714 special = getAlignSpecial(tabular, cell,
715 Tabular::SET_SPECIAL_COLUMN);
716 pwidth = getColumnPWidth(tabular, cell);
720 columnWidthED->clear();
722 colwidth = pwidth.asString();
723 lengthToWidgets(columnWidthED, columnWidthUnitLC,
724 colwidth, default_unit);
728 mroffset = getMROffset(tabular, cell);
731 multirowOffsetED->clear();
733 offset = mroffset.asString();
734 lengthToWidgets(multirowOffsetED, multirowOffsetUnitLC,
735 offset, default_unit);
737 specialAlignmentED->setText(toqstr(special));
738 ///////////////////////////////////
741 borderDefaultRB->setChecked(!tabular.use_booktabs);
742 booktabsRB->setChecked(tabular.use_booktabs);
744 if (tabular.row_info[row].top_space.empty()
745 && !tabular.row_info[row].top_space_default) {
746 topspaceCO->setCurrentIndex(0);
747 } else if (tabular.row_info[row].top_space_default) {
748 topspaceCO->setCurrentIndex(1);
750 topspaceCO->setCurrentIndex(2);
751 lengthToWidgets(topspaceED,
753 tabular.row_info[row].top_space.asString(),
757 if (tabular.row_info[row].bottom_space.empty()
758 && !tabular.row_info[row].bottom_space_default) {
759 bottomspaceCO->setCurrentIndex(0);
760 } else if (tabular.row_info[row].bottom_space_default) {
761 bottomspaceCO->setCurrentIndex(1);
763 bottomspaceCO->setCurrentIndex(2);
764 lengthToWidgets(bottomspaceED,
766 tabular.row_info[row].bottom_space.asString(),
770 if (tabular.row_info[row].interline_space.empty()
771 && !tabular.row_info[row].interline_space_default) {
772 interlinespaceCO->setCurrentIndex(0);
773 } else if (tabular.row_info[row].interline_space_default) {
774 interlinespaceCO->setCurrentIndex(1);
776 interlinespaceCO->setCurrentIndex(2);
777 lengthToWidgets(interlinespaceED,
778 interlinespaceUnitLC,
779 tabular.row_info[row].interline_space.asString(),
784 hAlignCO->addItem(qt_("Left"), toqstr("left"));
785 hAlignCO->addItem(qt_("Center"), toqstr("center"));
786 hAlignCO->addItem(qt_("Right"), toqstr("right"));
787 if (!multicol && !pwidth.zero())
788 hAlignCO->addItem(qt_("Justified"), toqstr("justified"));
790 hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
793 switch (tabular.getAlignment(cell)) {
797 case LYX_ALIGN_CENTER:
800 case LYX_ALIGN_RIGHT:
803 case LYX_ALIGN_BLOCK:
805 if (!multicol && !pwidth.zero())
809 case LYX_ALIGN_DECIMAL:
816 // we should never end up here
819 hAlignCO->setCurrentIndex(hAlignCO->findData(toqstr(align)));
822 QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
823 if (decimal_point.isEmpty())
824 decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
825 decimalPointED->setText(decimal_point);
828 switch (tabular.getVAlignment(cell)) {
829 case Tabular::LYX_VALIGN_TOP:
832 case Tabular::LYX_VALIGN_MIDDLE:
835 case Tabular::LYX_VALIGN_BOTTOM:
844 vAlignCO->setCurrentIndex(valign);
847 switch (tabular.tabular_valignment) {
848 case Tabular::LYX_VALIGN_TOP:
851 case Tabular::LYX_VALIGN_MIDDLE:
854 case Tabular::LYX_VALIGN_BOTTOM:
861 TableAlignCO->setCurrentIndex(tableValign);
863 if (!tabular.is_long_tabular) {
864 headerStatusCB->setChecked(false);
865 headerBorderAboveCB->setChecked(false);
866 headerBorderBelowCB->setChecked(false);
867 firstheaderStatusCB->setChecked(false);
868 firstheaderBorderAboveCB->setChecked(false);
869 firstheaderBorderBelowCB->setChecked(false);
870 firstheaderNoContentsCB->setChecked(false);
871 footerStatusCB->setChecked(false);
872 footerBorderAboveCB->setChecked(false);
873 footerBorderBelowCB->setChecked(false);
874 lastfooterStatusCB->setChecked(false);
875 lastfooterBorderAboveCB->setChecked(false);
876 lastfooterBorderBelowCB->setChecked(false);
877 lastfooterNoContentsCB->setChecked(false);
878 newpageCB->setChecked(false);
879 captionStatusCB->blockSignals(true);
880 captionStatusCB->setChecked(false);
881 captionStatusCB->blockSignals(false);
885 // longtables cannot have a vertical alignment
886 TableAlignCO->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
888 switch (tabular.longtabular_alignment) {
889 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
890 leftRB->setChecked(true);
892 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
893 centerRB->setChecked(true);
895 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
896 rightRB->setChecked(true);
899 centerRB->setChecked(true);
902 captionStatusCB->blockSignals(true);
903 captionStatusCB->setChecked(tabular.ltCaption(row));
904 captionStatusCB->blockSignals(false);
908 bool row_set = tabular.getRowOfLTHead(row, ltt);
909 headerStatusCB->setChecked(row_set);
911 headerBorderAboveCB->setChecked(ltt.topDL);
912 headerBorderBelowCB->setChecked(ltt.bottomDL);
915 headerBorderAboveCB->setChecked(false);
916 headerBorderBelowCB->setChecked(false);
917 firstheaderNoContentsCB->setChecked(false);
921 row_set = tabular.getRowOfLTFirstHead(row, ltt);
922 firstheaderStatusCB->setChecked(row_set);
923 if (ltt.set && (!ltt.empty || !use_empty)) {
924 firstheaderBorderAboveCB->setChecked(ltt.topDL);
925 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
927 firstheaderBorderAboveCB->setChecked(false);
928 firstheaderBorderBelowCB->setChecked(false);
931 row_set = tabular.getRowOfLTFoot(row, ltt);
932 footerStatusCB->setChecked(row_set);
934 footerBorderAboveCB->setChecked(ltt.topDL);
935 footerBorderBelowCB->setChecked(ltt.bottomDL);
938 footerBorderAboveCB->setChecked(false);
939 footerBorderBelowCB->setChecked(false);
940 lastfooterNoContentsCB->setChecked(false);
944 row_set = tabular.getRowOfLTLastFoot(row, ltt);
945 lastfooterStatusCB->setChecked(row_set);
946 if (ltt.set && (!ltt.empty || !use_empty)) {
947 lastfooterBorderAboveCB->setChecked(ltt.topDL);
948 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
950 lastfooterBorderAboveCB->setChecked(false);
951 lastfooterBorderBelowCB->setChecked(false);
953 newpageCB->setChecked(tabular.getLTNewPage(row));
955 // first header can only be suppressed when there is a header
956 firstheader_suppressable_ = tabular.haveLTHead()
957 && !tabular.haveLTFirstHead();
958 // last footer can only be suppressed when there is a footer
959 lastfooter_suppressable_ = tabular.haveLTFoot()
960 && !tabular.haveLTLastFoot();
962 // after setting the features, check if they are enabled
967 bool GuiTabular::funcEnabled(Tabular::Feature f) const
969 string cmd = "tabular " + featureAsString(f);
970 return getStatus(FuncRequest(LFUN_INSET_MODIFY, cmd)).enabled();
974 } // namespace frontend
977 #include "moc_GuiTabular.cpp"