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(rotateTabularAngleSB, SIGNAL(valueChanged(int)),
147 this, SLOT(checkEnabled()));
148 connect(rotateCellCB, SIGNAL(clicked()),
149 this, SLOT(checkEnabled()));
150 connect(rotateCellAngleSB, SIGNAL(valueChanged(int)),
151 this, SLOT(checkEnabled()));
152 connect(TableAlignCO, SIGNAL(activated(int)),
153 this, SLOT(checkEnabled()));
154 connect(longTabularCB, SIGNAL(clicked()),
155 this, SLOT(checkEnabled()));
156 connect(leftRB, SIGNAL(clicked()),
157 this, SLOT(checkEnabled()));
158 connect(centerRB, SIGNAL(clicked()),
159 this, SLOT(checkEnabled()));
160 connect(rightRB, SIGNAL(clicked()),
161 this, SLOT(checkEnabled()));
162 connect(tabularWidthED, SIGNAL(textEdited(const QString &)),
163 this, SLOT(checkEnabled()));
165 decimalPointED->setInputMask("X; ");
166 decimalPointED->setMaxLength(1);
168 // initialize the length validator
169 addCheckedWidget(columnWidthED, columnWidthLA);
170 addCheckedWidget(multirowOffsetED, multirowOffsetLA);
171 addCheckedWidget(topspaceED, topspaceLA);
172 addCheckedWidget(bottomspaceED, bottomspaceLA);
173 addCheckedWidget(interlinespaceED, interlinespaceLA);
174 addCheckedWidget(tabularWidthED, tabularWidthLA);
178 void GuiTabular::on_topspaceCO_activated(int index)
180 bool const enable = (index == 2);
181 topspaceED->setEnabled(enable);
182 topspaceUnitLC->setEnabled(enable);
186 void GuiTabular::on_bottomspaceCO_activated(int index)
188 bool const enable = (index == 2);
189 bottomspaceED->setEnabled(enable);
190 bottomspaceUnitLC->setEnabled(enable);
194 void GuiTabular::on_interlinespaceCO_activated(int index)
196 bool const enable = (index == 2);
197 interlinespaceED->setEnabled(enable);
198 interlinespaceUnitLC->setEnabled(enable);
202 void GuiTabular::checkEnabled()
204 // if there is a LaTeX argument, the width and alignment will be overwritten
205 // therefore disable them in this case
206 columnWidthED->setEnabled(specialAlignmentED->text().isEmpty());
207 // if the column has a width, multirows are always left-aligned
208 // therefore disable hAlignCB in this case
209 hAlignCO->setEnabled(!(multirowCB->isChecked()
210 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty())
211 && specialAlignmentED->text().isEmpty());
212 // decimal alignment is only possible for non-multicol and non-multirow cells
213 if ((multicolumnCB->isChecked() || multirowCB->isChecked())
214 && hAlignCO->findData(toqstr("decimal")))
215 hAlignCO->removeItem(hAlignCO->findData(toqstr("decimal")));
216 else if (!multicolumnCB->isChecked() && !multirowCB->isChecked()
217 && hAlignCO->findData(toqstr("decimal")) == -1)
218 hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
220 hAlignCO->itemData(hAlignCO->currentIndex()).toString() == QString("decimal");
221 decimalPointED->setEnabled(dalign);
222 decimalLA->setEnabled(dalign);
224 bool const setwidth = TableAlignCO->currentText() == qt_("Middle")
225 && !longTabularCB->isChecked();
226 tabularWidthLA->setEnabled(setwidth);
227 tabularWidthED->setEnabled(setwidth);
228 tabularWidthUnitLC->setEnabled(setwidth);
230 rotateTabularAngleSB->setEnabled(rotateTabularCB->isChecked());
231 rotateCellAngleSB->setEnabled(rotateCellCB->isChecked());
233 bool const enable_valign =
234 !multirowCB->isChecked()
235 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty()
236 && specialAlignmentED->text().isEmpty();
237 vAlignCO->setEnabled(enable_valign);
238 vAlignLA->setEnabled(enable_valign);
240 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
241 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
242 topspaceUnitLC->setEnabled(topspaceCO->currentIndex() == 2);
243 bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
244 bottomspaceUnitLC->setEnabled(bottomspaceCO->currentIndex() == 2);
245 interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
246 interlinespaceUnitLC->setEnabled(interlinespaceCO->currentIndex() == 2);
248 // setting as longtable is not allowed when table is inside a float
249 bool const is_tabular_star = !tabularWidthED->text().isEmpty();
250 longTabularCB->setEnabled(!is_tabular_star && funcEnabled(Tabular::SET_LONGTABULAR));
251 bool const longtabular = longTabularCB->isChecked();
252 longtableGB->setEnabled(true);
253 newpageCB->setEnabled(longtabular);
254 alignmentGB->setEnabled(longtabular);
255 // longtables and tabular* cannot have a vertical alignment
256 TableAlignLA->setDisabled(is_tabular_star || longtabular);
257 TableAlignCO->setDisabled(is_tabular_star || longtabular);
259 // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
260 // depending on the cursor position is very very unintuitive...
261 // We need some edit boxes to show which rows are header/footer/etc
262 // without having to move the cursor first.
263 headerStatusCB->setEnabled(longtabular
264 && (headerStatusCB->isChecked() ?
265 funcEnabled(Tabular::UNSET_LTHEAD) :
266 funcEnabled(Tabular::SET_LTHEAD)));
267 headerBorderAboveCB->setEnabled(longtabular
268 && headerStatusCB->isChecked());
269 headerBorderBelowCB->setEnabled(longtabular
270 && headerStatusCB->isChecked());
272 // first header can only be suppressed when there is a header
273 // firstheader_suppressable_ is set in paramsToDialog
274 firstheaderNoContentsCB->setEnabled(longtabular && firstheader_suppressable_);
275 // check if setting a first header is allowed
276 // additionally check firstheaderNoContentsCB because when this is
277 // the case a first header makes no sense
278 firstheaderStatusCB->setEnabled((firstheaderStatusCB->isChecked() ?
279 funcEnabled(Tabular::UNSET_LTFIRSTHEAD) :
280 funcEnabled(Tabular::SET_LTFIRSTHEAD))
281 && longtabular && !firstheaderNoContentsCB->isChecked());
282 firstheaderBorderAboveCB->setEnabled(longtabular
283 && firstheaderStatusCB->isChecked());
284 firstheaderBorderBelowCB->setEnabled(longtabular
285 && firstheaderStatusCB->isChecked());
287 footerStatusCB->setEnabled(longtabular
288 && (footerStatusCB->isChecked() ?
289 funcEnabled(Tabular::UNSET_LTFOOT) :
290 funcEnabled(Tabular::SET_LTFOOT)));
291 footerBorderAboveCB->setEnabled(longtabular
292 && footerBorderAboveCB->isChecked());
293 footerBorderBelowCB->setEnabled(longtabular
294 && footerBorderAboveCB->isChecked());
296 // last footer can only be suppressed when there is a footer
297 // lastfooter_suppressable_ is set in paramsToDialog
298 lastfooterNoContentsCB->setEnabled(longtabular && lastfooter_suppressable_);
299 // check if setting a last footer is allowed
300 // additionally check lastfooterNoContentsCB because when this is
301 // the case a last footer makes no sense
302 lastfooterStatusCB->setEnabled((lastfooterStatusCB->isChecked() ?
303 funcEnabled(Tabular::UNSET_LTLASTFOOT) :
304 funcEnabled(Tabular::SET_LTLASTFOOT))
305 && longtabular && !lastfooterNoContentsCB->isChecked());
306 lastfooterBorderAboveCB->setEnabled(longtabular
307 && lastfooterBorderAboveCB->isChecked());
308 lastfooterBorderBelowCB->setEnabled(longtabular
309 && lastfooterBorderAboveCB->isChecked());
311 captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)
314 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN)
315 && !dalign && !multirowCB->isChecked());
316 multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW)
317 && !dalign && !multicolumnCB->isChecked());
318 bool const enable_mr = multirowCB->isChecked();
319 multirowOffsetLA->setEnabled(enable_mr);
320 multirowOffsetED->setEnabled(enable_mr);
321 multirowOffsetUnitLC->setEnabled(enable_mr);
327 void GuiTabular::borderSet_clicked()
329 borders->setTop(true);
330 borders->setBottom(true);
331 borders->setLeft(true);
332 borders->setRight(true);
333 // repaint the setborder widget
339 void GuiTabular::borderUnset_clicked()
341 borders->setTop(false);
342 borders->setBottom(false);
343 borders->setLeft(false);
344 borders->setRight(false);
345 // repaint the setborder widget
351 static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
354 param_str += featureAsString(f) + ' ' + arg;
358 void GuiTabular::setHAlign(string & param_str) const
360 Tabular::Feature num = Tabular::ALIGN_LEFT;
361 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
363 fromqstr(hAlignCO->itemData(hAlignCO->currentIndex()).toString());
364 if (align == "left") {
365 num = Tabular::ALIGN_LEFT;
366 multi_num = Tabular::M_ALIGN_LEFT;
367 } else if (align == "center") {
368 num = Tabular::ALIGN_CENTER;
369 multi_num = Tabular::M_ALIGN_CENTER;
370 } else if (align == "right") {
371 num = Tabular::ALIGN_RIGHT;
372 multi_num = Tabular::M_ALIGN_RIGHT;
373 } else if (align == "justified") {
374 num = Tabular::ALIGN_BLOCK;
375 //multi_num: no equivalent
376 } else if (align == "decimal") {
377 num = Tabular::ALIGN_DECIMAL;
378 //multi_num: no equivalent
381 if (multicolumnCB->isChecked())
382 setParam(param_str, multi_num);
384 setParam(param_str, num);
388 void GuiTabular::setVAlign(string & param_str) const
390 int const align = vAlignCO->currentIndex();
391 enum VALIGN { TOP, MIDDLE, BOTTOM };
395 case 0: v = TOP; break;
396 case 1: v = MIDDLE; break;
397 case 2: v = BOTTOM; break;
400 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
401 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
405 num = Tabular::VALIGN_TOP;
406 multi_num = Tabular::M_VALIGN_TOP;
409 num = Tabular::VALIGN_MIDDLE;
410 multi_num = Tabular::M_VALIGN_MIDDLE;
413 num = Tabular::VALIGN_BOTTOM;
414 multi_num = Tabular::M_VALIGN_BOTTOM;
417 if (multicolumnCB->isChecked() || multirowCB->isChecked())
418 setParam(param_str, multi_num);
420 setParam(param_str, num);
424 void GuiTabular::setTableAlignment(string & param_str) const
426 int const align = TableAlignCO->currentIndex();
428 case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
430 case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
432 case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
438 docstring GuiTabular::dialogToParams() const
440 // FIXME: We should use Tabular directly.
441 string param_str = "tabular from-dialog";
444 string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitLC);
445 if (tabwidth.empty())
447 setParam(param_str, Tabular::SET_TABULAR_WIDTH, tabwidth);
449 // apply the fixed width values
450 // this must be done before applying the column alignment
451 // because its value influences the alignment of multirow cells
452 string width = widgetsToLength(columnWidthED, columnWidthUnitLC);
455 if (multicolumnCB->isChecked())
456 setParam(param_str, Tabular::SET_MPWIDTH, width);
458 setParam(param_str, Tabular::SET_PWIDTH, width);
460 // apply the column alignment
461 // multirows inherit the alignment from the column; if a column width
462 // is set, multirows are always left-aligned so that in this case
463 // its alignment must not be applied (see bug #8084)
464 if (!(multirowCB->isChecked() && width != "0pt"))
465 setHAlign(param_str);
467 // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
468 string decimal_point = fromqstr(decimalPointED->text());
469 if (decimal_point.empty())
470 decimal_point = lyxrc.default_decimal_point;
471 setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
473 setVAlign(param_str);
474 setTableAlignment(param_str);
476 if (booktabsRB->isChecked())
477 setParam(param_str, Tabular::SET_BOOKTABS);
479 setParam(param_str, Tabular::UNSET_BOOKTABS);
482 switch (topspaceCO->currentIndex()) {
484 setParam(param_str, Tabular::SET_TOP_SPACE, "none");
487 setParam(param_str, Tabular::SET_TOP_SPACE, "default");
490 if (!topspaceED->text().isEmpty())
491 setParam(param_str, Tabular::SET_TOP_SPACE,
492 widgetsToLength(topspaceED, topspaceUnitLC));
497 switch (bottomspaceCO->currentIndex()) {
499 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
502 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
505 if (!bottomspaceED->text().isEmpty())
506 setParam(param_str, Tabular::SET_BOTTOM_SPACE,
507 widgetsToLength(bottomspaceED,
513 switch (interlinespaceCO->currentIndex()) {
515 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
518 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
521 if (!interlinespaceED->text().isEmpty())
522 setParam(param_str, Tabular::SET_INTERLINE_SPACE,
523 widgetsToLength(interlinespaceED,
524 interlinespaceUnitLC));
529 if (borders->getTop() && borders->getBottom() && borders->getLeft()
530 && borders->getRight())
531 setParam(param_str, Tabular::SET_ALL_LINES);
532 else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft()
533 && !borders->getRight())
534 setParam(param_str, Tabular::UNSET_ALL_LINES);
536 setParam(param_str, Tabular::SET_LINE_LEFT,
537 borders->getLeft() ? "true" : "false");
538 setParam(param_str, Tabular::SET_LINE_RIGHT,
539 borders->getRight() ? "true" : "false");
540 setParam(param_str, Tabular::SET_LINE_TOP,
541 borders->getTop() ? "true" : "false");
542 setParam(param_str, Tabular::SET_LINE_BOTTOM,
543 borders->getBottom() ? "true" : "false");
546 // apply the special alignment
547 string special = fromqstr(specialAlignmentED->text());
550 if (multicolumnCB->isChecked())
551 setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
553 setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
556 if (multicolumnCB->isChecked())
557 setParam(param_str, Tabular::SET_MULTICOLUMN);
559 setParam(param_str, Tabular::UNSET_MULTICOLUMN);
561 // apply the multirow offset
562 string mroffset = widgetsToLength(multirowOffsetED, multirowOffsetUnitLC);
563 if (mroffset.empty())
565 if (multirowCB->isChecked())
566 setParam(param_str, Tabular::SET_MROFFSET, mroffset);
568 if (multirowCB->isChecked())
569 setParam(param_str, Tabular::SET_MULTIROW);
571 setParam(param_str, Tabular::UNSET_MULTIROW);
572 // store the table rotation angle
573 string const tabular_angle = convert<string>(rotateTabularAngleSB->value());
574 if (rotateTabularCB->isChecked())
575 setParam(param_str, Tabular::SET_ROTATE_TABULAR, tabular_angle);
577 setParam(param_str, Tabular::UNSET_ROTATE_TABULAR, tabular_angle);
578 // store the cell rotation angle
579 string const cell_angle = convert<string>(rotateCellAngleSB->value());
580 if (rotateCellCB->isChecked())
581 setParam(param_str, Tabular::SET_ROTATE_CELL, cell_angle);
583 setParam(param_str, Tabular::UNSET_ROTATE_CELL, cell_angle);
585 if (longTabularCB->isChecked())
586 setParam(param_str, Tabular::SET_LONGTABULAR);
588 setParam(param_str, Tabular::UNSET_LONGTABULAR);
590 if (newpageCB->isChecked())
591 setParam(param_str, Tabular::SET_LTNEWPAGE);
593 setParam(param_str, Tabular::UNSET_LTNEWPAGE);
595 if (captionStatusCB->isChecked())
596 setParam(param_str, Tabular::SET_LTCAPTION);
598 setParam(param_str, Tabular::UNSET_LTCAPTION);
600 if (headerStatusCB->isChecked())
601 setParam(param_str, Tabular::SET_LTHEAD, "none");
603 setParam(param_str, Tabular::UNSET_LTHEAD, "none");
605 if (headerBorderAboveCB->isChecked())
606 setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
608 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
610 if (headerBorderBelowCB->isChecked())
611 setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
613 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
614 if (firstheaderBorderAboveCB->isChecked())
615 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
617 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
618 if (firstheaderBorderBelowCB->isChecked())
619 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
621 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
622 if (firstheaderStatusCB->isChecked())
623 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
625 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
626 if (firstheaderNoContentsCB->isChecked())
627 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
629 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
630 if (footerStatusCB->isChecked())
631 setParam(param_str, Tabular::SET_LTFOOT, "none");
633 setParam(param_str, Tabular::UNSET_LTFOOT, "none");
634 if (footerBorderAboveCB->isChecked())
635 setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
637 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
638 if (footerBorderBelowCB->isChecked())
639 setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
641 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
642 if (lastfooterStatusCB->isChecked())
643 setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
645 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
646 if (lastfooterBorderAboveCB->isChecked())
647 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
649 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
650 if (lastfooterBorderBelowCB->isChecked())
651 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
653 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
654 if (lastfooterNoContentsCB->isChecked())
655 setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
657 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
659 if (leftRB->isChecked())
660 setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
661 else if (centerRB->isChecked())
662 setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
663 else if (rightRB->isChecked())
664 setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
666 return from_utf8(param_str);
670 static Length getColumnPWidth(Tabular const & t, size_t cell)
672 return t.column_info[t.cellColumn(cell)].p_width;
676 static Length getMColumnPWidth(Tabular const & t, size_t cell)
678 if (t.isMultiColumn(cell) || t.isMultiRow(cell))
679 return t.cellInfo(cell).p_width;
684 static Length getMROffset(Tabular const & t, size_t cell)
686 if (t.isMultiRow(cell))
687 return t.cellInfo(cell).mroffset;
692 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
694 if (what == Tabular::SET_SPECIAL_MULTICOLUMN)
695 return t.cellInfo(cell).align_special;
696 return t.column_info[t.cellColumn(cell)].align_special;
700 void GuiTabular::paramsToDialog(Inset const * inset)
702 InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
703 // Copy Tabular of current inset.
704 Tabular const & tabular = itab->tabular;
706 BufferView const * bv = guiApp->currentView()->currentBufferView();
707 size_t const cell = bv->cursor().idx();
709 Tabular::row_type const row = tabular.cellRow(cell);
710 Tabular::col_type const col = tabular.cellColumn(cell);
712 tabularRowED->setText(QString::number(row + 1));
713 tabularColumnED->setText(QString::number(col + 1));
715 bool const multicol = tabular.isMultiColumn(cell);
716 multicolumnCB->setChecked(multicol);
718 bool const multirow = tabular.isMultiRow(cell);
719 multirowCB->setChecked(multirow);
721 rotateCellCB->setChecked(tabular.getRotateCell(cell) != 0);
722 if (rotateCellCB->isChecked()) {
723 if (tabular.getRotateCell(cell) != 0)
724 rotateCellAngleSB->setValue(tabular.getRotateCell(cell));
726 rotateCellAngleSB->setValue(90);
729 rotateTabularCB->setChecked(tabular.rotate != 0);
730 if (rotateTabularCB->isChecked())
731 rotateTabularAngleSB->setValue(tabular.rotate != 0 ? tabular.rotate : 90);
733 longTabularCB->setChecked(tabular.is_long_tabular);
735 borders->setTop(tabular.topLine(cell));
736 borders->setBottom(tabular.bottomLine(cell));
737 borders->setLeft(tabular.leftLine(cell));
738 borders->setRight(tabular.rightLine(cell));
739 // repaint the setborder widget
742 Length::UNIT const default_unit = Length::defaultUnit();
744 ///////////////////////////////////
745 // Set width and alignment
747 Length const tabwidth = tabular.tabularWidth();
749 tabularWidthED->clear();
751 lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
752 tabwidth.asString(), default_unit);
757 special = getAlignSpecial(tabular, cell,
758 Tabular::SET_SPECIAL_MULTICOLUMN);
759 pwidth = getMColumnPWidth(tabular, cell);
761 special = getAlignSpecial(tabular, cell,
762 Tabular::SET_SPECIAL_COLUMN);
763 pwidth = getColumnPWidth(tabular, cell);
767 columnWidthED->clear();
769 colwidth = pwidth.asString();
770 lengthToWidgets(columnWidthED, columnWidthUnitLC,
771 colwidth, default_unit);
775 mroffset = getMROffset(tabular, cell);
778 multirowOffsetED->clear();
780 offset = mroffset.asString();
781 lengthToWidgets(multirowOffsetED, multirowOffsetUnitLC,
782 offset, default_unit);
784 specialAlignmentED->setText(toqstr(special));
785 ///////////////////////////////////
788 borderDefaultRB->setChecked(!tabular.use_booktabs);
789 booktabsRB->setChecked(tabular.use_booktabs);
791 if (tabular.row_info[row].top_space.empty()
792 && !tabular.row_info[row].top_space_default) {
793 topspaceCO->setCurrentIndex(0);
794 } else if (tabular.row_info[row].top_space_default) {
795 topspaceCO->setCurrentIndex(1);
797 topspaceCO->setCurrentIndex(2);
798 lengthToWidgets(topspaceED,
800 tabular.row_info[row].top_space.asString(),
804 if (tabular.row_info[row].bottom_space.empty()
805 && !tabular.row_info[row].bottom_space_default) {
806 bottomspaceCO->setCurrentIndex(0);
807 } else if (tabular.row_info[row].bottom_space_default) {
808 bottomspaceCO->setCurrentIndex(1);
810 bottomspaceCO->setCurrentIndex(2);
811 lengthToWidgets(bottomspaceED,
813 tabular.row_info[row].bottom_space.asString(),
817 if (tabular.row_info[row].interline_space.empty()
818 && !tabular.row_info[row].interline_space_default) {
819 interlinespaceCO->setCurrentIndex(0);
820 } else if (tabular.row_info[row].interline_space_default) {
821 interlinespaceCO->setCurrentIndex(1);
823 interlinespaceCO->setCurrentIndex(2);
824 lengthToWidgets(interlinespaceED,
825 interlinespaceUnitLC,
826 tabular.row_info[row].interline_space.asString(),
831 hAlignCO->addItem(qt_("Left"), toqstr("left"));
832 hAlignCO->addItem(qt_("Center"), toqstr("center"));
833 hAlignCO->addItem(qt_("Right"), toqstr("right"));
834 if (!multicol && !pwidth.zero())
835 hAlignCO->addItem(qt_("Justified"), toqstr("justified"));
836 if (!multicol && !multirow)
837 hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
840 switch (tabular.getAlignment(cell)) {
844 case LYX_ALIGN_CENTER:
847 case LYX_ALIGN_RIGHT:
850 case LYX_ALIGN_BLOCK:
852 if (!multicol && !pwidth.zero())
856 case LYX_ALIGN_DECIMAL:
858 if (!multicol && !multirow)
863 // we should never end up here
866 hAlignCO->setCurrentIndex(hAlignCO->findData(toqstr(align)));
869 QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
870 if (decimal_point.isEmpty())
871 decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
872 decimalPointED->setText(decimal_point);
875 switch (tabular.getVAlignment(cell)) {
876 case Tabular::LYX_VALIGN_TOP:
879 case Tabular::LYX_VALIGN_MIDDLE:
882 case Tabular::LYX_VALIGN_BOTTOM:
891 vAlignCO->setCurrentIndex(valign);
894 switch (tabular.tabular_valignment) {
895 case Tabular::LYX_VALIGN_TOP:
898 case Tabular::LYX_VALIGN_MIDDLE:
901 case Tabular::LYX_VALIGN_BOTTOM:
908 TableAlignCO->setCurrentIndex(tableValign);
910 if (!tabular.is_long_tabular) {
911 headerStatusCB->setChecked(false);
912 headerBorderAboveCB->setChecked(false);
913 headerBorderBelowCB->setChecked(false);
914 firstheaderStatusCB->setChecked(false);
915 firstheaderBorderAboveCB->setChecked(false);
916 firstheaderBorderBelowCB->setChecked(false);
917 firstheaderNoContentsCB->setChecked(false);
918 footerStatusCB->setChecked(false);
919 footerBorderAboveCB->setChecked(false);
920 footerBorderBelowCB->setChecked(false);
921 lastfooterStatusCB->setChecked(false);
922 lastfooterBorderAboveCB->setChecked(false);
923 lastfooterBorderBelowCB->setChecked(false);
924 lastfooterNoContentsCB->setChecked(false);
925 newpageCB->setChecked(false);
926 captionStatusCB->blockSignals(true);
927 captionStatusCB->setChecked(false);
928 captionStatusCB->blockSignals(false);
932 // longtables cannot have a vertical alignment
933 TableAlignCO->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
935 switch (tabular.longtabular_alignment) {
936 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
937 leftRB->setChecked(true);
939 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
940 centerRB->setChecked(true);
942 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
943 rightRB->setChecked(true);
946 centerRB->setChecked(true);
949 captionStatusCB->blockSignals(true);
950 captionStatusCB->setChecked(tabular.ltCaption(row));
951 captionStatusCB->blockSignals(false);
955 bool row_set = tabular.getRowOfLTHead(row, ltt);
956 headerStatusCB->setChecked(row_set);
958 headerBorderAboveCB->setChecked(ltt.topDL);
959 headerBorderBelowCB->setChecked(ltt.bottomDL);
962 headerBorderAboveCB->setChecked(false);
963 headerBorderBelowCB->setChecked(false);
964 firstheaderNoContentsCB->setChecked(false);
968 row_set = tabular.getRowOfLTFirstHead(row, ltt);
969 firstheaderStatusCB->setChecked(row_set);
970 if (ltt.set && (!ltt.empty || !use_empty)) {
971 firstheaderBorderAboveCB->setChecked(ltt.topDL);
972 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
974 firstheaderBorderAboveCB->setChecked(false);
975 firstheaderBorderBelowCB->setChecked(false);
978 row_set = tabular.getRowOfLTFoot(row, ltt);
979 footerStatusCB->setChecked(row_set);
981 footerBorderAboveCB->setChecked(ltt.topDL);
982 footerBorderBelowCB->setChecked(ltt.bottomDL);
985 footerBorderAboveCB->setChecked(false);
986 footerBorderBelowCB->setChecked(false);
987 lastfooterNoContentsCB->setChecked(false);
991 row_set = tabular.getRowOfLTLastFoot(row, ltt);
992 lastfooterStatusCB->setChecked(row_set);
993 if (ltt.set && (!ltt.empty || !use_empty)) {
994 lastfooterBorderAboveCB->setChecked(ltt.topDL);
995 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
997 lastfooterBorderAboveCB->setChecked(false);
998 lastfooterBorderBelowCB->setChecked(false);
1000 newpageCB->setChecked(tabular.getLTNewPage(row));
1002 // first header can only be suppressed when there is a header
1003 firstheader_suppressable_ = tabular.haveLTHead()
1004 && !tabular.haveLTFirstHead();
1005 // last footer can only be suppressed when there is a footer
1006 lastfooter_suppressable_ = tabular.haveLTFoot()
1007 && !tabular.haveLTLastFoot();
1009 // after setting the features, check if they are enabled
1014 bool GuiTabular::funcEnabled(Tabular::Feature f) const
1016 string cmd = "tabular " + featureAsString(f);
1017 return getStatus(FuncRequest(LFUN_INSET_MODIFY, cmd)).enabled();
1021 } // namespace frontend
1024 #include "moc_GuiTabular.cpp"