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/convert.h"
35 #include "support/debug.h"
38 #include <QPushButton>
39 #include <QRadioButton>
47 GuiTabular::GuiTabular(QWidget * parent)
48 : InsetParamsWidget(parent)
52 tabularWidthED->setValidator(unsignedLengthValidator(tabularWidthED));
53 columnWidthED->setValidator(unsignedLengthValidator(columnWidthED));
54 multirowOffsetED->setValidator(new LengthValidator(multirowOffsetED));
55 topspaceED->setValidator(new LengthValidator(topspaceED));
56 bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
57 interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
59 tabularWidthUnitLC->setCurrentItem(Length::defaultUnit());
60 columnWidthUnitLC->setCurrentItem(Length::defaultUnit());
61 multirowOffsetUnitLC->setCurrentItem(Length::defaultUnit());
62 topspaceUnitLC->setCurrentItem(Length::defaultUnit());
63 bottomspaceUnitLC->setCurrentItem(Length::defaultUnit());
64 interlinespaceUnitLC->setCurrentItem(Length::defaultUnit());
66 connect(topspaceED, SIGNAL(textEdited(const QString &)),
67 this, SLOT(checkEnabled()));
68 connect(topspaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
69 this, SLOT(checkEnabled()));
70 connect(bottomspaceED, SIGNAL(textEdited(const QString &)),
71 this, SLOT(checkEnabled()));
72 connect(bottomspaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
73 this, SLOT(checkEnabled()));
74 connect(interlinespaceED, SIGNAL(textEdited(const QString &)),
75 this, SLOT(checkEnabled()));
76 connect(interlinespaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
77 this, SLOT(checkEnabled()));
78 connect(booktabsRB, SIGNAL(clicked(bool)),
79 this, SLOT(checkEnabled()));
80 connect(borderDefaultRB, SIGNAL(clicked(bool)),
81 this, SLOT(checkEnabled()));
82 connect(borderSetPB, SIGNAL(clicked()),
83 this, SLOT(borderSet_clicked()));
84 connect(borderUnsetPB, SIGNAL(clicked()),
85 this, SLOT(borderUnset_clicked()));
86 connect(hAlignCO, SIGNAL(activated(int)),
87 this, SLOT(checkEnabled()));
88 connect(vAlignCO, SIGNAL(activated(int)),
89 this, SLOT(checkEnabled()));
90 connect(multicolumnCB, SIGNAL(clicked()),
91 this, SLOT(checkEnabled()));
92 connect(multirowCB, SIGNAL(clicked()),
93 this, SLOT(checkEnabled()));
94 connect(multirowOffsetED, SIGNAL(textEdited(const QString &)),
95 this, SLOT(checkEnabled()));
96 connect(multirowOffsetUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
97 this, SLOT(checkEnabled()));
98 connect(newpageCB, SIGNAL(clicked()),
99 this, SLOT(checkEnabled()));
100 connect(headerStatusCB, SIGNAL(clicked()),
101 this, SLOT(checkEnabled()));
102 connect(headerBorderAboveCB, SIGNAL(clicked()),
103 this, SLOT(checkEnabled()));
104 connect(headerBorderBelowCB, SIGNAL(clicked()),
105 this, SLOT(checkEnabled()));
106 connect(firstheaderStatusCB, SIGNAL(clicked()),
107 this, SLOT(checkEnabled()));
108 connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
109 this, SLOT(checkEnabled()));
110 connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
111 this, SLOT(checkEnabled()));
112 connect(firstheaderNoContentsCB, SIGNAL(clicked()),
113 this, SLOT(checkEnabled()));
114 connect(footerStatusCB, SIGNAL(clicked()),
115 this, SLOT(checkEnabled()));
116 connect(footerBorderAboveCB, SIGNAL(clicked()),
117 this, SLOT(checkEnabled()));
118 connect(footerBorderBelowCB, SIGNAL(clicked()),
119 this, SLOT(checkEnabled()));
120 connect(lastfooterStatusCB, SIGNAL(clicked()),
121 this, SLOT(checkEnabled()));
122 connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
123 this, SLOT(checkEnabled()));
124 connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
125 this, SLOT(checkEnabled()));
126 connect(lastfooterNoContentsCB, SIGNAL(clicked()),
127 this, SLOT(checkEnabled()));
128 connect(captionStatusCB, SIGNAL(clicked()),
129 this, SLOT(checkEnabled()));
130 connect(specialAlignmentED, SIGNAL(editingFinished()),
131 this, SLOT(checkEnabled()));
132 connect(columnWidthED, SIGNAL(textEdited(const QString &)),
133 this, SLOT(checkEnabled()));
134 connect(columnWidthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
135 this, SLOT(checkEnabled()));
136 connect(borders, SIGNAL(topSet(bool)),
137 this, SLOT(checkEnabled()));
138 connect(borders, SIGNAL(bottomSet(bool)),
139 this, SLOT(checkEnabled()));
140 connect(borders, SIGNAL(rightSet(bool)),
141 this, SLOT(checkEnabled()));
142 connect(borders, SIGNAL(leftSet(bool)),
143 this, SLOT(checkEnabled()));
144 connect(rotateTabularCB, SIGNAL(clicked()),
145 this, SLOT(checkEnabled()));
146 connect(rotateCellCB, SIGNAL(clicked()),
147 this, SLOT(checkEnabled()));
148 connect(rotateCellAngleSB, SIGNAL(valueChanged(int)),
149 this, SLOT(checkEnabled()));
150 connect(TableAlignCO, SIGNAL(activated(int)),
151 this, SLOT(checkEnabled()));
152 connect(longTabularCB, SIGNAL(clicked()),
153 this, SLOT(checkEnabled()));
154 connect(leftRB, SIGNAL(clicked()),
155 this, SLOT(checkEnabled()));
156 connect(centerRB, SIGNAL(clicked()),
157 this, SLOT(checkEnabled()));
158 connect(rightRB, SIGNAL(clicked()),
159 this, SLOT(checkEnabled()));
160 connect(tabularWidthED, SIGNAL(textEdited(const QString &)),
161 this, SLOT(checkEnabled()));
163 decimalPointED->setInputMask("X; ");
164 decimalPointED->setMaxLength(1);
166 // initialize the length validator
167 addCheckedWidget(columnWidthED, columnWidthLA);
168 addCheckedWidget(multirowOffsetED, multirowOffsetLA);
169 addCheckedWidget(topspaceED, topspaceLA);
170 addCheckedWidget(bottomspaceED, bottomspaceLA);
171 addCheckedWidget(interlinespaceED, interlinespaceLA);
172 addCheckedWidget(tabularWidthED, tabularWidthLA);
176 void GuiTabular::on_topspaceCO_activated(int index)
178 bool const enable = (index == 2);
179 topspaceED->setEnabled(enable);
180 topspaceUnitLC->setEnabled(enable);
184 void GuiTabular::on_bottomspaceCO_activated(int index)
186 bool const enable = (index == 2);
187 bottomspaceED->setEnabled(enable);
188 bottomspaceUnitLC->setEnabled(enable);
192 void GuiTabular::on_interlinespaceCO_activated(int index)
194 bool const enable = (index == 2);
195 interlinespaceED->setEnabled(enable);
196 interlinespaceUnitLC->setEnabled(enable);
200 void GuiTabular::checkEnabled()
202 // if there is a LaTeX argument, the width and alignment will be overwritten
203 // therefore disable them in this case
204 columnWidthED->setEnabled(specialAlignmentED->text().isEmpty());
205 // if the column has a width, multirows are always left-aligned
206 // therefore disable hAlignCB in this case
207 hAlignCO->setEnabled(!(multirowCB->isChecked()
208 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty())
209 && specialAlignmentED->text().isEmpty());
211 hAlignCO->itemData(hAlignCO->currentIndex()).toString() == QString("decimal");
212 decimalPointED->setEnabled(dalign);
213 decimalLA->setEnabled(dalign);
215 bool const setwidth = TableAlignCO->currentText() == qt_("Middle")
216 && !longTabularCB->isChecked() && !rotateTabularCB->isChecked();
217 tabularWidthLA->setEnabled(setwidth);
218 tabularWidthED->setEnabled(setwidth);
219 tabularWidthUnitLC->setEnabled(setwidth);
221 bool const is_tabular_star = !tabularWidthED->text().isEmpty();
222 rotateTabularCB->setDisabled(is_tabular_star);
224 rotateCellAngleSB->setEnabled(rotateCellCB->isChecked());
226 bool const enable_valign =
227 !multirowCB->isChecked()
228 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty()
229 && specialAlignmentED->text().isEmpty();
230 vAlignCO->setEnabled(enable_valign);
231 vAlignLA->setEnabled(enable_valign);
233 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
234 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
235 topspaceUnitLC->setEnabled(topspaceCO->currentIndex() == 2);
236 bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
237 bottomspaceUnitLC->setEnabled(bottomspaceCO->currentIndex() == 2);
238 interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
239 interlinespaceUnitLC->setEnabled(interlinespaceCO->currentIndex() == 2);
241 // setting as longtable is not allowed when table is inside a float
242 longTabularCB->setEnabled(!is_tabular_star && funcEnabled(Tabular::SET_LONGTABULAR));
243 bool const longtabular = longTabularCB->isChecked();
244 longtableGB->setEnabled(true);
245 newpageCB->setEnabled(longtabular);
246 alignmentGB->setEnabled(longtabular);
247 // longtables and tabular* cannot have a vertical alignment
248 TableAlignLA->setDisabled(is_tabular_star || longtabular);
249 TableAlignCO->setDisabled(is_tabular_star || longtabular);
251 // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
252 // depending on the cursor position is very very unintuitive...
253 // We need some edit boxes to show which rows are header/footer/etc
254 // without having to move the cursor first.
255 headerStatusCB->setEnabled(longtabular
256 && (headerStatusCB->isChecked() ?
257 funcEnabled(Tabular::UNSET_LTHEAD) :
258 funcEnabled(Tabular::SET_LTHEAD)));
259 headerBorderAboveCB->setEnabled(longtabular
260 && headerStatusCB->isChecked());
261 headerBorderBelowCB->setEnabled(longtabular
262 && headerStatusCB->isChecked());
264 // first header can only be suppressed when there is a header
265 // firstheader_suppressable_ is set in paramsToDialog
266 firstheaderNoContentsCB->setEnabled(longtabular && firstheader_suppressable_);
267 // check if setting a first header is allowed
268 // additionally check firstheaderNoContentsCB because when this is
269 // the case a first header makes no sense
270 firstheaderStatusCB->setEnabled((firstheaderStatusCB->isChecked() ?
271 funcEnabled(Tabular::UNSET_LTFIRSTHEAD) :
272 funcEnabled(Tabular::SET_LTFIRSTHEAD))
273 && longtabular && !firstheaderNoContentsCB->isChecked());
274 firstheaderBorderAboveCB->setEnabled(longtabular
275 && firstheaderStatusCB->isChecked());
276 firstheaderBorderBelowCB->setEnabled(longtabular
277 && firstheaderStatusCB->isChecked());
279 footerStatusCB->setEnabled(longtabular
280 && (footerStatusCB->isChecked() ?
281 funcEnabled(Tabular::UNSET_LTFOOT) :
282 funcEnabled(Tabular::SET_LTFOOT)));
283 footerBorderAboveCB->setEnabled(longtabular
284 && footerBorderAboveCB->isChecked());
285 footerBorderBelowCB->setEnabled(longtabular
286 && footerBorderAboveCB->isChecked());
288 // last footer can only be suppressed when there is a footer
289 // lastfooter_suppressable_ is set in paramsToDialog
290 lastfooterNoContentsCB->setEnabled(longtabular && lastfooter_suppressable_);
291 // check if setting a last footer is allowed
292 // additionally check lastfooterNoContentsCB because when this is
293 // the case a last footer makes no sense
294 lastfooterStatusCB->setEnabled((lastfooterStatusCB->isChecked() ?
295 funcEnabled(Tabular::UNSET_LTLASTFOOT) :
296 funcEnabled(Tabular::SET_LTLASTFOOT))
297 && longtabular && !lastfooterNoContentsCB->isChecked());
298 lastfooterBorderAboveCB->setEnabled(longtabular
299 && lastfooterBorderAboveCB->isChecked());
300 lastfooterBorderBelowCB->setEnabled(longtabular
301 && lastfooterBorderAboveCB->isChecked());
303 captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)
306 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
307 multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW));
308 bool const enable_mr = multirowCB->isChecked();
309 multirowOffsetLA->setEnabled(enable_mr);
310 multirowOffsetED->setEnabled(enable_mr);
311 multirowOffsetUnitLC->setEnabled(enable_mr);
317 void GuiTabular::borderSet_clicked()
319 borders->setTop(true);
320 borders->setBottom(true);
321 borders->setLeft(true);
322 borders->setRight(true);
323 // repaint the setborder widget
329 void GuiTabular::borderUnset_clicked()
331 borders->setTop(false);
332 borders->setBottom(false);
333 borders->setLeft(false);
334 borders->setRight(false);
335 // repaint the setborder widget
341 static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
344 param_str += featureAsString(f) + ' ' + arg;
348 void GuiTabular::setHAlign(string & param_str) const
350 Tabular::Feature num = Tabular::ALIGN_LEFT;
351 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
353 fromqstr(hAlignCO->itemData(hAlignCO->currentIndex()).toString());
354 if (align == "left") {
355 num = Tabular::ALIGN_LEFT;
356 multi_num = Tabular::M_ALIGN_LEFT;
357 } else if (align == "center") {
358 num = Tabular::ALIGN_CENTER;
359 multi_num = Tabular::M_ALIGN_CENTER;
360 } else if (align == "right") {
361 num = Tabular::ALIGN_RIGHT;
362 multi_num = Tabular::M_ALIGN_RIGHT;
363 } else if (align == "justified") {
364 num = Tabular::ALIGN_BLOCK;
365 //multi_num: no equivalent
366 } else if (align == "decimal") {
367 num = Tabular::ALIGN_DECIMAL;
368 //multi_num: no equivalent
371 if (multicolumnCB->isChecked())
372 setParam(param_str, multi_num);
374 setParam(param_str, num);
378 void GuiTabular::setVAlign(string & param_str) const
380 int const align = vAlignCO->currentIndex();
381 enum VALIGN { TOP, MIDDLE, BOTTOM };
385 case 0: v = TOP; break;
386 case 1: v = MIDDLE; break;
387 case 2: v = BOTTOM; break;
390 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
391 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
395 num = Tabular::VALIGN_TOP;
396 multi_num = Tabular::M_VALIGN_TOP;
399 num = Tabular::VALIGN_MIDDLE;
400 multi_num = Tabular::M_VALIGN_MIDDLE;
403 num = Tabular::VALIGN_BOTTOM;
404 multi_num = Tabular::M_VALIGN_BOTTOM;
407 if (multicolumnCB->isChecked() || multirowCB->isChecked())
408 setParam(param_str, multi_num);
410 setParam(param_str, num);
414 void GuiTabular::setTableAlignment(string & param_str) const
416 int const align = TableAlignCO->currentIndex();
418 case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
420 case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
422 case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
428 docstring GuiTabular::dialogToParams() const
430 // FIXME: We should use Tabular directly.
431 string param_str = "tabular from-dialog";
434 string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitLC);
435 if (tabwidth.empty())
437 setParam(param_str, Tabular::SET_TABULAR_WIDTH, tabwidth);
439 // apply the fixed width values
440 // this must be done before applying the column alignment
441 // because its value influences the alignment of multirow cells
442 string width = widgetsToLength(columnWidthED, columnWidthUnitLC);
445 if (multicolumnCB->isChecked())
446 setParam(param_str, Tabular::SET_MPWIDTH, width);
448 setParam(param_str, Tabular::SET_PWIDTH, width);
450 // apply the column alignment
451 // multirows inherit the alignment from the column; if a column width
452 // is set, multirows are always left-aligned so that in this case
453 // its alignment must not be applied (see bug #8084)
454 if (!(multirowCB->isChecked() && width != "0pt"))
455 setHAlign(param_str);
457 // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
458 string decimal_point = fromqstr(decimalPointED->text());
459 if (decimal_point.empty())
460 decimal_point = lyxrc.default_decimal_point;
461 setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
463 setVAlign(param_str);
464 setTableAlignment(param_str);
466 if (booktabsRB->isChecked())
467 setParam(param_str, Tabular::SET_BOOKTABS);
469 setParam(param_str, Tabular::UNSET_BOOKTABS);
472 switch (topspaceCO->currentIndex()) {
474 setParam(param_str, Tabular::SET_TOP_SPACE, "none");
477 setParam(param_str, Tabular::SET_TOP_SPACE, "default");
480 if (!topspaceED->text().isEmpty())
481 setParam(param_str, Tabular::SET_TOP_SPACE,
482 widgetsToLength(topspaceED, topspaceUnitLC));
487 switch (bottomspaceCO->currentIndex()) {
489 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
492 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
495 if (!bottomspaceED->text().isEmpty())
496 setParam(param_str, Tabular::SET_BOTTOM_SPACE,
497 widgetsToLength(bottomspaceED,
503 switch (interlinespaceCO->currentIndex()) {
505 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
508 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
511 if (!interlinespaceED->text().isEmpty())
512 setParam(param_str, Tabular::SET_INTERLINE_SPACE,
513 widgetsToLength(interlinespaceED,
514 interlinespaceUnitLC));
519 if (borders->getTop() && borders->getBottom() && borders->getLeft()
520 && borders->getRight())
521 setParam(param_str, Tabular::SET_ALL_LINES);
522 else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft()
523 && !borders->getRight())
524 setParam(param_str, Tabular::UNSET_ALL_LINES);
526 setParam(param_str, Tabular::SET_LINE_LEFT,
527 borders->getLeft() ? "true" : "false");
528 setParam(param_str, Tabular::SET_LINE_RIGHT,
529 borders->getRight() ? "true" : "false");
530 setParam(param_str, Tabular::SET_LINE_TOP,
531 borders->getTop() ? "true" : "false");
532 setParam(param_str, Tabular::SET_LINE_BOTTOM,
533 borders->getBottom() ? "true" : "false");
536 // apply the special alignment
537 string special = fromqstr(specialAlignmentED->text());
540 if (multicolumnCB->isChecked())
541 setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
543 setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
546 if (multicolumnCB->isChecked())
547 setParam(param_str, Tabular::SET_MULTICOLUMN);
549 setParam(param_str, Tabular::UNSET_MULTICOLUMN);
551 // apply the multirow offset
552 string mroffset = widgetsToLength(multirowOffsetED, multirowOffsetUnitLC);
553 if (mroffset.empty())
555 if (multirowCB->isChecked())
556 setParam(param_str, Tabular::SET_MROFFSET, mroffset);
558 if (multirowCB->isChecked())
559 setParam(param_str, Tabular::SET_MULTIROW);
561 setParam(param_str, Tabular::UNSET_MULTIROW);
563 if (rotateTabularCB->isChecked())
564 setParam(param_str, Tabular::SET_ROTATE_TABULAR);
566 setParam(param_str, Tabular::UNSET_ROTATE_TABULAR);
567 // store the cell rotation angle
568 string angle = convert<string>(rotateCellAngleSB->value());
569 if (rotateCellCB->isChecked())
570 setParam(param_str, Tabular::SET_ROTATE_CELL, angle);
572 setParam(param_str, Tabular::UNSET_ROTATE_CELL, angle);
574 if (longTabularCB->isChecked())
575 setParam(param_str, Tabular::SET_LONGTABULAR);
577 setParam(param_str, Tabular::UNSET_LONGTABULAR);
579 if (newpageCB->isChecked())
580 setParam(param_str, Tabular::SET_LTNEWPAGE);
582 if (captionStatusCB->isChecked())
583 setParam(param_str, Tabular::SET_LTCAPTION);
585 setParam(param_str, Tabular::UNSET_LTCAPTION);
587 if (headerStatusCB->isChecked())
588 setParam(param_str, Tabular::SET_LTHEAD, "none");
590 setParam(param_str, Tabular::UNSET_LTHEAD, "none");
592 if (headerBorderAboveCB->isChecked())
593 setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
595 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
597 if (headerBorderBelowCB->isChecked())
598 setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
600 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
601 if (firstheaderBorderAboveCB->isChecked())
602 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
604 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
605 if (firstheaderBorderBelowCB->isChecked())
606 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
608 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
609 if (firstheaderStatusCB->isChecked())
610 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
612 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
613 if (firstheaderNoContentsCB->isChecked())
614 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
616 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
617 if (footerStatusCB->isChecked())
618 setParam(param_str, Tabular::SET_LTFOOT, "none");
620 setParam(param_str, Tabular::UNSET_LTFOOT, "none");
621 if (footerBorderAboveCB->isChecked())
622 setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
624 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
625 if (footerBorderBelowCB->isChecked())
626 setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
628 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
629 if (lastfooterStatusCB->isChecked())
630 setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
632 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
633 if (lastfooterBorderAboveCB->isChecked())
634 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
636 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
637 if (lastfooterBorderBelowCB->isChecked())
638 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
640 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
641 if (lastfooterNoContentsCB->isChecked())
642 setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
644 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
646 if (leftRB->isChecked())
647 setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
648 else if (centerRB->isChecked())
649 setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
650 else if (rightRB->isChecked())
651 setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
653 return from_utf8(param_str);
657 static Length getColumnPWidth(Tabular const & t, size_t cell)
659 return t.column_info[t.cellColumn(cell)].p_width;
663 static Length getMColumnPWidth(Tabular const & t, size_t cell)
665 if (t.isMultiColumn(cell) || t.isMultiRow(cell))
666 return t.cellInfo(cell).p_width;
671 static Length getMROffset(Tabular const & t, size_t cell)
673 if (t.isMultiRow(cell))
674 return t.cellInfo(cell).mroffset;
679 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
681 if (what == Tabular::SET_SPECIAL_MULTICOLUMN)
682 return t.cellInfo(cell).align_special;
683 return t.column_info[t.cellColumn(cell)].align_special;
687 void GuiTabular::paramsToDialog(Inset const * inset)
689 InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
690 // Copy Tabular of current inset.
691 Tabular const & tabular = itab->tabular;
693 BufferView const * bv = guiApp->currentView()->currentBufferView();
694 size_t const cell = bv->cursor().idx();
696 Tabular::row_type const row = tabular.cellRow(cell);
697 Tabular::col_type const col = tabular.cellColumn(cell);
699 tabularRowED->setText(QString::number(row + 1));
700 tabularColumnED->setText(QString::number(col + 1));
702 bool const multicol = tabular.isMultiColumn(cell);
703 multicolumnCB->setChecked(multicol);
705 bool const multirow = tabular.isMultiRow(cell);
706 multirowCB->setChecked(multirow);
708 rotateCellCB->setChecked(tabular.getRotateCell(cell) != 0);
709 if (tabular.getRotateCell(cell) != 0)
710 rotateCellAngleSB->setValue(tabular.getRotateCell(cell));
712 rotateCellAngleSB->setValue(90);
713 rotateTabularCB->setChecked(tabular.rotate);
715 longTabularCB->setChecked(tabular.is_long_tabular);
717 borders->setTop(tabular.topLine(cell));
718 borders->setBottom(tabular.bottomLine(cell));
719 borders->setLeft(tabular.leftLine(cell));
720 borders->setRight(tabular.rightLine(cell));
721 // repaint the setborder widget
724 Length::UNIT const default_unit = Length::defaultUnit();
726 ///////////////////////////////////
727 // Set width and alignment
729 Length const tabwidth = tabular.tabularWidth();
731 tabularWidthED->clear();
733 lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
734 tabwidth.asString(), default_unit);
739 special = getAlignSpecial(tabular, cell,
740 Tabular::SET_SPECIAL_MULTICOLUMN);
741 pwidth = getMColumnPWidth(tabular, cell);
743 special = getAlignSpecial(tabular, cell,
744 Tabular::SET_SPECIAL_COLUMN);
745 pwidth = getColumnPWidth(tabular, cell);
749 columnWidthED->clear();
751 colwidth = pwidth.asString();
752 lengthToWidgets(columnWidthED, columnWidthUnitLC,
753 colwidth, default_unit);
757 mroffset = getMROffset(tabular, cell);
760 multirowOffsetED->clear();
762 offset = mroffset.asString();
763 lengthToWidgets(multirowOffsetED, multirowOffsetUnitLC,
764 offset, default_unit);
766 specialAlignmentED->setText(toqstr(special));
767 ///////////////////////////////////
770 borderDefaultRB->setChecked(!tabular.use_booktabs);
771 booktabsRB->setChecked(tabular.use_booktabs);
773 if (tabular.row_info[row].top_space.empty()
774 && !tabular.row_info[row].top_space_default) {
775 topspaceCO->setCurrentIndex(0);
776 } else if (tabular.row_info[row].top_space_default) {
777 topspaceCO->setCurrentIndex(1);
779 topspaceCO->setCurrentIndex(2);
780 lengthToWidgets(topspaceED,
782 tabular.row_info[row].top_space.asString(),
786 if (tabular.row_info[row].bottom_space.empty()
787 && !tabular.row_info[row].bottom_space_default) {
788 bottomspaceCO->setCurrentIndex(0);
789 } else if (tabular.row_info[row].bottom_space_default) {
790 bottomspaceCO->setCurrentIndex(1);
792 bottomspaceCO->setCurrentIndex(2);
793 lengthToWidgets(bottomspaceED,
795 tabular.row_info[row].bottom_space.asString(),
799 if (tabular.row_info[row].interline_space.empty()
800 && !tabular.row_info[row].interline_space_default) {
801 interlinespaceCO->setCurrentIndex(0);
802 } else if (tabular.row_info[row].interline_space_default) {
803 interlinespaceCO->setCurrentIndex(1);
805 interlinespaceCO->setCurrentIndex(2);
806 lengthToWidgets(interlinespaceED,
807 interlinespaceUnitLC,
808 tabular.row_info[row].interline_space.asString(),
813 hAlignCO->addItem(qt_("Left"), toqstr("left"));
814 hAlignCO->addItem(qt_("Center"), toqstr("center"));
815 hAlignCO->addItem(qt_("Right"), toqstr("right"));
816 if (!multicol && !pwidth.zero())
817 hAlignCO->addItem(qt_("Justified"), toqstr("justified"));
819 hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
822 switch (tabular.getAlignment(cell)) {
826 case LYX_ALIGN_CENTER:
829 case LYX_ALIGN_RIGHT:
832 case LYX_ALIGN_BLOCK:
834 if (!multicol && !pwidth.zero())
838 case LYX_ALIGN_DECIMAL:
845 // we should never end up here
848 hAlignCO->setCurrentIndex(hAlignCO->findData(toqstr(align)));
851 QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
852 if (decimal_point.isEmpty())
853 decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
854 decimalPointED->setText(decimal_point);
857 switch (tabular.getVAlignment(cell)) {
858 case Tabular::LYX_VALIGN_TOP:
861 case Tabular::LYX_VALIGN_MIDDLE:
864 case Tabular::LYX_VALIGN_BOTTOM:
873 vAlignCO->setCurrentIndex(valign);
876 switch (tabular.tabular_valignment) {
877 case Tabular::LYX_VALIGN_TOP:
880 case Tabular::LYX_VALIGN_MIDDLE:
883 case Tabular::LYX_VALIGN_BOTTOM:
890 TableAlignCO->setCurrentIndex(tableValign);
892 if (!tabular.is_long_tabular) {
893 headerStatusCB->setChecked(false);
894 headerBorderAboveCB->setChecked(false);
895 headerBorderBelowCB->setChecked(false);
896 firstheaderStatusCB->setChecked(false);
897 firstheaderBorderAboveCB->setChecked(false);
898 firstheaderBorderBelowCB->setChecked(false);
899 firstheaderNoContentsCB->setChecked(false);
900 footerStatusCB->setChecked(false);
901 footerBorderAboveCB->setChecked(false);
902 footerBorderBelowCB->setChecked(false);
903 lastfooterStatusCB->setChecked(false);
904 lastfooterBorderAboveCB->setChecked(false);
905 lastfooterBorderBelowCB->setChecked(false);
906 lastfooterNoContentsCB->setChecked(false);
907 newpageCB->setChecked(false);
908 captionStatusCB->blockSignals(true);
909 captionStatusCB->setChecked(false);
910 captionStatusCB->blockSignals(false);
914 // longtables cannot have a vertical alignment
915 TableAlignCO->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
917 switch (tabular.longtabular_alignment) {
918 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
919 leftRB->setChecked(true);
921 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
922 centerRB->setChecked(true);
924 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
925 rightRB->setChecked(true);
928 centerRB->setChecked(true);
931 captionStatusCB->blockSignals(true);
932 captionStatusCB->setChecked(tabular.ltCaption(row));
933 captionStatusCB->blockSignals(false);
937 bool row_set = tabular.getRowOfLTHead(row, ltt);
938 headerStatusCB->setChecked(row_set);
940 headerBorderAboveCB->setChecked(ltt.topDL);
941 headerBorderBelowCB->setChecked(ltt.bottomDL);
944 headerBorderAboveCB->setChecked(false);
945 headerBorderBelowCB->setChecked(false);
946 firstheaderNoContentsCB->setChecked(false);
950 row_set = tabular.getRowOfLTFirstHead(row, ltt);
951 firstheaderStatusCB->setChecked(row_set);
952 if (ltt.set && (!ltt.empty || !use_empty)) {
953 firstheaderBorderAboveCB->setChecked(ltt.topDL);
954 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
956 firstheaderBorderAboveCB->setChecked(false);
957 firstheaderBorderBelowCB->setChecked(false);
960 row_set = tabular.getRowOfLTFoot(row, ltt);
961 footerStatusCB->setChecked(row_set);
963 footerBorderAboveCB->setChecked(ltt.topDL);
964 footerBorderBelowCB->setChecked(ltt.bottomDL);
967 footerBorderAboveCB->setChecked(false);
968 footerBorderBelowCB->setChecked(false);
969 lastfooterNoContentsCB->setChecked(false);
973 row_set = tabular.getRowOfLTLastFoot(row, ltt);
974 lastfooterStatusCB->setChecked(row_set);
975 if (ltt.set && (!ltt.empty || !use_empty)) {
976 lastfooterBorderAboveCB->setChecked(ltt.topDL);
977 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
979 lastfooterBorderAboveCB->setChecked(false);
980 lastfooterBorderBelowCB->setChecked(false);
982 newpageCB->setChecked(tabular.getLTNewPage(row));
984 // first header can only be suppressed when there is a header
985 firstheader_suppressable_ = tabular.haveLTHead()
986 && !tabular.haveLTFirstHead();
987 // last footer can only be suppressed when there is a footer
988 lastfooter_suppressable_ = tabular.haveLTFoot()
989 && !tabular.haveLTLastFoot();
991 // after setting the features, check if they are enabled
996 bool GuiTabular::funcEnabled(Tabular::Feature f) const
998 string cmd = "tabular " + featureAsString(f);
999 return getStatus(FuncRequest(LFUN_INSET_MODIFY, cmd)).enabled();
1003 } // namespace frontend
1006 #include "moc_GuiTabular.cpp"