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"
36 #include "support/lstrings.h"
39 #include <QPushButton>
40 #include <QRadioButton>
48 GuiTabular::GuiTabular(QWidget * parent)
49 : InsetParamsWidget(parent), firstheader_suppressable_(false),
50 lastfooter_suppressable_(false)
55 tabularWidthED->setValidator(unsignedLengthValidator(tabularWidthED));
56 columnWidthED->setValidator(unsignedLengthValidator(columnWidthED));
57 multirowOffsetED->setValidator(new LengthValidator(multirowOffsetED));
58 topspaceED->setValidator(new LengthValidator(topspaceED));
59 bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
60 interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
62 tabularWidthUnitLC->setCurrentItem(Length::defaultUnit());
63 columnWidthUnitLC->setCurrentItem(Length::defaultUnit());
64 multirowOffsetUnitLC->setCurrentItem(Length::defaultUnit());
65 topspaceUnitLC->setCurrentItem(Length::defaultUnit());
66 bottomspaceUnitLC->setCurrentItem(Length::defaultUnit());
67 interlinespaceUnitLC->setCurrentItem(Length::defaultUnit());
69 connect(topspaceED, SIGNAL(textEdited(const QString &)),
70 this, SLOT(checkEnabled()));
71 connect(topspaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
72 this, SLOT(checkEnabled()));
73 connect(bottomspaceED, SIGNAL(textEdited(const QString &)),
74 this, SLOT(checkEnabled()));
75 connect(bottomspaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
76 this, SLOT(checkEnabled()));
77 connect(interlinespaceED, SIGNAL(textEdited(const QString &)),
78 this, SLOT(checkEnabled()));
79 connect(interlinespaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
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(hAlignCO, SIGNAL(activated(int)),
90 this, SLOT(checkEnabled()));
91 connect(vAlignCO, 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(textEdited(const QString &)),
98 this, SLOT(checkEnabled()));
99 connect(multirowOffsetUnitLC, 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(const QString &)),
134 this, SLOT(checkEnabled()));
135 connect(columnWidthED, SIGNAL(textEdited(const QString &)),
136 this, SLOT(checkEnabled()));
137 connect(columnWidthUnitLC, 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(rotateTabularAngleSB, SIGNAL(valueChanged(int)),
150 this, SLOT(checkEnabled()));
151 connect(rotateCellCB, SIGNAL(clicked()),
152 this, SLOT(checkEnabled()));
153 connect(rotateCellAngleSB, SIGNAL(valueChanged(int)),
154 this, SLOT(checkEnabled()));
155 connect(TableAlignCO, SIGNAL(activated(int)),
156 this, SLOT(checkEnabled()));
157 connect(longTabularCB, SIGNAL(clicked()),
158 this, SLOT(checkEnabled()));
159 connect(leftRB, SIGNAL(clicked()),
160 this, SLOT(checkEnabled()));
161 connect(centerRB, SIGNAL(clicked()),
162 this, SLOT(checkEnabled()));
163 connect(rightRB, SIGNAL(clicked()),
164 this, SLOT(checkEnabled()));
165 connect(tabularWidthED, SIGNAL(textEdited(const QString &)),
166 this, SLOT(checkEnabled()));
168 decimalPointED->setInputMask("X; ");
169 decimalPointED->setMaxLength(1);
171 // initialize the length validator
172 addCheckedWidget(columnWidthED, columnWidthLA);
173 addCheckedWidget(multirowOffsetED, multirowOffsetLA);
174 addCheckedWidget(topspaceED, topspaceLA);
175 addCheckedWidget(bottomspaceED, bottomspaceLA);
176 addCheckedWidget(interlinespaceED, interlinespaceLA);
177 addCheckedWidget(tabularWidthED, tabularWidthLA);
181 void GuiTabular::on_topspaceCO_activated(int index)
183 bool const enable = (index == 2);
184 topspaceED->setEnabled(enable);
185 topspaceUnitLC->setEnabled(enable);
189 void GuiTabular::on_bottomspaceCO_activated(int index)
191 bool const enable = (index == 2);
192 bottomspaceED->setEnabled(enable);
193 bottomspaceUnitLC->setEnabled(enable);
197 void GuiTabular::on_interlinespaceCO_activated(int index)
199 bool const enable = (index == 2);
200 interlinespaceED->setEnabled(enable);
201 interlinespaceUnitLC->setEnabled(enable);
205 void GuiTabular::enableWidgets() const
207 // if there is a LaTeX argument, the width and alignment will be overwritten
208 // therefore disable them in this case
209 columnWidthED->setEnabled(specialAlignmentED->text().isEmpty());
210 columnWidthUnitLC->setEnabled(specialAlignmentED->text().isEmpty());
211 // if the column has a width, multirows are always left-aligned
212 // therefore disable hAlignCB in this case
213 hAlignCO->setEnabled(!(multirowCB->isChecked()
214 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty())
215 && specialAlignmentED->text().isEmpty());
216 // decimal alignment is only possible for non-multicol and non-multirow cells
217 if ((multicolumnCB->isChecked() || multirowCB->isChecked())
218 && hAlignCO->findData(toqstr("decimal")))
219 hAlignCO->removeItem(hAlignCO->findData(toqstr("decimal")));
220 else if (!multicolumnCB->isChecked() && !multirowCB->isChecked()
221 && hAlignCO->findData(toqstr("decimal")) == -1)
222 hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
224 hAlignCO->itemData(hAlignCO->currentIndex()).toString() == QString("decimal");
225 decimalPointED->setEnabled(dalign);
226 decimalLA->setEnabled(dalign);
228 bool const setwidth = TableAlignCO->currentText() == qt_("Middle")
229 && !longTabularCB->isChecked();
230 tabularWidthLA->setEnabled(setwidth);
231 tabularWidthED->setEnabled(setwidth);
232 tabularWidthUnitLC->setEnabled(setwidth);
234 rotateTabularAngleSB->setEnabled(rotateTabularCB->isChecked()
235 && !longTabularCB->isChecked());
236 rotateCellAngleSB->setEnabled(rotateCellCB->isChecked());
238 bool const enable_valign =
239 !multirowCB->isChecked()
240 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty()
241 && specialAlignmentED->text().isEmpty();
242 vAlignCO->setEnabled(enable_valign);
243 vAlignLA->setEnabled(enable_valign);
245 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
246 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
247 topspaceUnitLC->setEnabled(topspaceCO->currentIndex() == 2);
248 bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
249 bottomspaceUnitLC->setEnabled(bottomspaceCO->currentIndex() == 2);
250 interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
251 interlinespaceUnitLC->setEnabled(interlinespaceCO->currentIndex() == 2);
253 // setting as longtable is not allowed when table is inside a float
254 bool const is_tabular_star = !tabularWidthED->text().isEmpty();
255 longTabularCB->setEnabled(!is_tabular_star && funcEnabled(Tabular::SET_LONGTABULAR));
256 bool const longtabular = longTabularCB->isChecked();
257 longtableGB->setEnabled(true);
258 newpageCB->setEnabled(longtabular);
259 alignmentGB->setEnabled(longtabular);
260 // longtables and tabular* cannot have a vertical alignment
261 TableAlignLA->setDisabled(is_tabular_star || longtabular);
262 TableAlignCO->setDisabled(is_tabular_star || longtabular);
263 // longtable cannot be rotated with rotating package, only
264 // with [pdf]lscape, which only supports 90 deg.
265 rotateTabularAngleSB->setDisabled(longtabular);
267 // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
268 // depending on the cursor position is very very unintuitive...
269 // We need some edit boxes to show which rows are header/footer/etc
270 // without having to move the cursor first.
271 headerStatusCB->setEnabled(longtabular
272 && (headerStatusCB->isChecked() ?
273 funcEnabled(Tabular::UNSET_LTHEAD) :
274 funcEnabled(Tabular::SET_LTHEAD)));
275 headerBorderAboveCB->setEnabled(longtabular
276 && headerStatusCB->isChecked());
277 headerBorderBelowCB->setEnabled(longtabular
278 && headerStatusCB->isChecked());
280 // first header can only be suppressed when there is a header
281 // firstheader_suppressable_ is set in paramsToDialog
282 firstheaderNoContentsCB->setEnabled(longtabular && firstheader_suppressable_);
283 // check if setting a first header is allowed
284 // additionally check firstheaderNoContentsCB because when this is
285 // the case a first header makes no sense
286 firstheaderStatusCB->setEnabled((firstheaderStatusCB->isChecked() ?
287 funcEnabled(Tabular::UNSET_LTFIRSTHEAD) :
288 funcEnabled(Tabular::SET_LTFIRSTHEAD))
289 && longtabular && !firstheaderNoContentsCB->isChecked());
290 firstheaderBorderAboveCB->setEnabled(longtabular
291 && firstheaderStatusCB->isChecked());
292 firstheaderBorderBelowCB->setEnabled(longtabular
293 && firstheaderStatusCB->isChecked());
295 footerStatusCB->setEnabled(longtabular
296 && (footerStatusCB->isChecked() ?
297 funcEnabled(Tabular::UNSET_LTFOOT) :
298 funcEnabled(Tabular::SET_LTFOOT)));
299 footerBorderAboveCB->setEnabled(longtabular
300 && footerBorderAboveCB->isChecked());
301 footerBorderBelowCB->setEnabled(longtabular
302 && footerBorderAboveCB->isChecked());
304 // last footer can only be suppressed when there is a footer
305 // lastfooter_suppressable_ is set in paramsToDialog
306 lastfooterNoContentsCB->setEnabled(longtabular && lastfooter_suppressable_);
307 // check if setting a last footer is allowed
308 // additionally check lastfooterNoContentsCB because when this is
309 // the case a last footer makes no sense
310 lastfooterStatusCB->setEnabled((lastfooterStatusCB->isChecked() ?
311 funcEnabled(Tabular::UNSET_LTLASTFOOT) :
312 funcEnabled(Tabular::SET_LTLASTFOOT))
313 && longtabular && !lastfooterNoContentsCB->isChecked());
314 lastfooterBorderAboveCB->setEnabled(longtabular
315 && lastfooterBorderAboveCB->isChecked());
316 lastfooterBorderBelowCB->setEnabled(longtabular
317 && lastfooterBorderAboveCB->isChecked());
319 captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)
322 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN)
323 && !dalign && !multirowCB->isChecked());
324 multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW)
325 && !dalign && !multicolumnCB->isChecked());
326 bool const enable_mr = multirowCB->isChecked();
327 multirowOffsetLA->setEnabled(enable_mr);
328 multirowOffsetED->setEnabled(enable_mr);
329 multirowOffsetUnitLC->setEnabled(enable_mr);
331 // Vertical lines cannot be set in formal tables
332 borders->setLeftEnabled(!booktabsRB->isChecked());
333 borders->setRightEnabled(!booktabsRB->isChecked());
337 void GuiTabular::checkEnabled()
344 void GuiTabular::borderSet_clicked()
346 borders->setTop(true);
347 borders->setBottom(true);
348 borders->setLeft(true);
349 borders->setRight(true);
350 // repaint the setborder widget
356 void GuiTabular::borderUnset_clicked()
358 borders->setTop(false);
359 borders->setBottom(false);
360 borders->setLeft(false);
361 borders->setRight(false);
362 // repaint the setborder widget
368 static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
371 param_str += featureAsString(f) + ' ' + arg;
375 void GuiTabular::setHAlign(string & param_str) const
377 Tabular::Feature num = Tabular::ALIGN_LEFT;
378 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
380 fromqstr(hAlignCO->itemData(hAlignCO->currentIndex()).toString());
381 if (align == "left") {
382 num = Tabular::ALIGN_LEFT;
383 multi_num = Tabular::M_ALIGN_LEFT;
384 } else if (align == "center") {
385 num = Tabular::ALIGN_CENTER;
386 multi_num = Tabular::M_ALIGN_CENTER;
387 } else if (align == "right") {
388 num = Tabular::ALIGN_RIGHT;
389 multi_num = Tabular::M_ALIGN_RIGHT;
390 } else if (align == "justified") {
391 num = Tabular::ALIGN_BLOCK;
392 //multi_num: no equivalent
393 } else if (align == "decimal") {
394 num = Tabular::ALIGN_DECIMAL;
395 //multi_num: no equivalent
398 if (multicolumnCB->isChecked())
399 setParam(param_str, multi_num);
401 setParam(param_str, num);
405 void GuiTabular::setVAlign(string & param_str) const
407 int const align = vAlignCO->currentIndex();
408 enum VALIGN { TOP, MIDDLE, BOTTOM };
412 case 0: v = TOP; break;
413 case 1: v = MIDDLE; break;
414 case 2: v = BOTTOM; break;
417 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
418 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
422 num = Tabular::VALIGN_TOP;
423 multi_num = Tabular::M_VALIGN_TOP;
426 num = Tabular::VALIGN_MIDDLE;
427 multi_num = Tabular::M_VALIGN_MIDDLE;
430 num = Tabular::VALIGN_BOTTOM;
431 multi_num = Tabular::M_VALIGN_BOTTOM;
434 if (multicolumnCB->isChecked() || multirowCB->isChecked())
435 setParam(param_str, multi_num);
437 setParam(param_str, num);
441 void GuiTabular::setTableAlignment(string & param_str) const
443 int const align = TableAlignCO->currentIndex();
445 case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
447 case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
449 case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
455 docstring GuiTabular::dialogToParams() const
457 string param_str = "tabular";
460 string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitLC);
461 if (tabwidth.empty())
463 setParam(param_str, Tabular::SET_TABULAR_WIDTH, tabwidth);
465 // apply the fixed width values
466 // this must be done before applying the column alignment
467 // because its value influences the alignment of multirow cells
468 string width = widgetsToLength(columnWidthED, columnWidthUnitLC);
471 if (multicolumnCB->isChecked())
472 setParam(param_str, Tabular::SET_MPWIDTH, width);
474 setParam(param_str, Tabular::SET_PWIDTH, width);
476 // apply the column alignment
477 // multirows inherit the alignment from the column; if a column width
478 // is set, multirows are always left-aligned so that in this case
479 // its alignment must not be applied (see bug #8084)
480 if (!(multirowCB->isChecked() && width != "0pt"))
481 setHAlign(param_str);
483 // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
484 string decimal_point = fromqstr(decimalPointED->text());
485 if (decimal_point.empty())
486 decimal_point = lyxrc.default_decimal_point;
487 setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
489 setVAlign(param_str);
490 setTableAlignment(param_str);
492 if (booktabsRB->isChecked())
493 setParam(param_str, Tabular::SET_BOOKTABS);
495 setParam(param_str, Tabular::UNSET_BOOKTABS);
498 switch (topspaceCO->currentIndex()) {
500 setParam(param_str, Tabular::SET_TOP_SPACE, "none");
503 setParam(param_str, Tabular::SET_TOP_SPACE, "default");
506 if (!topspaceED->text().isEmpty())
507 setParam(param_str, Tabular::SET_TOP_SPACE,
508 widgetsToLength(topspaceED, topspaceUnitLC));
513 switch (bottomspaceCO->currentIndex()) {
515 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
518 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
521 if (!bottomspaceED->text().isEmpty())
522 setParam(param_str, Tabular::SET_BOTTOM_SPACE,
523 widgetsToLength(bottomspaceED,
529 switch (interlinespaceCO->currentIndex()) {
531 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
534 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
537 if (!interlinespaceED->text().isEmpty())
538 setParam(param_str, Tabular::SET_INTERLINE_SPACE,
539 widgetsToLength(interlinespaceED,
540 interlinespaceUnitLC));
545 if (borders->getTop() && borders->getBottom() && borders->getLeft()
546 && borders->getRight())
547 setParam(param_str, Tabular::SET_ALL_LINES);
548 else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft()
549 && !borders->getRight())
550 setParam(param_str, Tabular::UNSET_ALL_LINES);
552 setParam(param_str, Tabular::SET_LINE_LEFT,
553 borders->getLeft() ? "true" : "false");
554 setParam(param_str, Tabular::SET_LINE_RIGHT,
555 borders->getRight() ? "true" : "false");
556 setParam(param_str, Tabular::SET_LINE_TOP,
557 borders->getTop() ? "true" : "false");
558 setParam(param_str, Tabular::SET_LINE_BOTTOM,
559 borders->getBottom() ? "true" : "false");
562 // apply the special alignment
563 string special = fromqstr(specialAlignmentED->text());
564 if (support::trim(special).empty())
566 if (multicolumnCB->isChecked())
567 setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
569 setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
572 if (multicolumnCB->isChecked())
573 setParam(param_str, Tabular::SET_MULTICOLUMN);
575 setParam(param_str, Tabular::UNSET_MULTICOLUMN);
577 // apply the multirow offset
578 string mroffset = widgetsToLength(multirowOffsetED, multirowOffsetUnitLC);
579 if (mroffset.empty())
581 if (multirowCB->isChecked())
582 setParam(param_str, Tabular::SET_MROFFSET, mroffset);
584 if (multirowCB->isChecked())
585 setParam(param_str, Tabular::SET_MULTIROW);
587 setParam(param_str, Tabular::UNSET_MULTIROW);
588 // store the table rotation angle
589 string const tabular_angle = convert<string>(rotateTabularAngleSB->value());
590 if (rotateTabularCB->isChecked())
591 setParam(param_str, Tabular::SET_ROTATE_TABULAR, tabular_angle);
593 setParam(param_str, Tabular::UNSET_ROTATE_TABULAR, tabular_angle);
594 // store the cell rotation angle
595 string const cell_angle = convert<string>(rotateCellAngleSB->value());
596 if (rotateCellCB->isChecked())
597 setParam(param_str, Tabular::SET_ROTATE_CELL, cell_angle);
599 setParam(param_str, Tabular::UNSET_ROTATE_CELL, cell_angle);
601 if (longTabularCB->isChecked())
602 setParam(param_str, Tabular::SET_LONGTABULAR);
604 setParam(param_str, Tabular::UNSET_LONGTABULAR);
606 if (newpageCB->isChecked())
607 setParam(param_str, Tabular::SET_LTNEWPAGE);
609 setParam(param_str, Tabular::UNSET_LTNEWPAGE);
611 if (captionStatusCB->isChecked())
612 setParam(param_str, Tabular::SET_LTCAPTION);
614 setParam(param_str, Tabular::UNSET_LTCAPTION);
616 if (headerStatusCB->isChecked())
617 setParam(param_str, Tabular::SET_LTHEAD, "none");
619 setParam(param_str, Tabular::UNSET_LTHEAD, "none");
621 if (headerBorderAboveCB->isChecked())
622 setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
624 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
626 if (headerBorderBelowCB->isChecked())
627 setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
629 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
630 if (firstheaderBorderAboveCB->isChecked())
631 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
633 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
634 if (firstheaderBorderBelowCB->isChecked())
635 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
637 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
638 if (firstheaderStatusCB->isChecked())
639 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
641 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
642 if (firstheaderNoContentsCB->isChecked())
643 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
645 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
646 if (footerStatusCB->isChecked())
647 setParam(param_str, Tabular::SET_LTFOOT, "none");
649 setParam(param_str, Tabular::UNSET_LTFOOT, "none");
650 if (footerBorderAboveCB->isChecked())
651 setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
653 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
654 if (footerBorderBelowCB->isChecked())
655 setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
657 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
658 if (lastfooterStatusCB->isChecked())
659 setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
661 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
662 if (lastfooterBorderAboveCB->isChecked())
663 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
665 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
666 if (lastfooterBorderBelowCB->isChecked())
667 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
669 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
670 if (lastfooterNoContentsCB->isChecked())
671 setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
673 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
675 if (leftRB->isChecked())
676 setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
677 else if (centerRB->isChecked())
678 setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
679 else if (rightRB->isChecked())
680 setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
682 return from_utf8(param_str);
686 static Length getColumnPWidth(Tabular const & t, size_t cell)
688 return t.column_info[t.cellColumn(cell)].p_width;
692 static Length getMColumnPWidth(Tabular const & t, size_t cell)
694 if (t.isMultiColumn(cell) || t.isMultiRow(cell))
695 return t.cellInfo(cell).p_width;
700 static Length getMROffset(Tabular const & t, size_t cell)
702 if (t.isMultiRow(cell))
703 return t.cellInfo(cell).mroffset;
708 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
710 if (what == Tabular::SET_SPECIAL_MULTICOLUMN)
711 return t.cellInfo(cell).align_special;
712 return t.column_info[t.cellColumn(cell)].align_special;
716 void GuiTabular::paramsToDialog(Inset const * inset)
718 InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
719 // Copy Tabular of current inset.
720 Tabular const & tabular = itab->tabular;
722 BufferView const * bv = guiApp->currentView()->currentBufferView();
723 size_t const cell = bv->cursor().idx();
725 Tabular::row_type const row = tabular.cellRow(cell);
726 Tabular::col_type const col = tabular.cellColumn(cell);
728 tabularRowED->setText(QString::number(row + 1));
729 tabularColumnED->setText(QString::number(col + 1));
731 bool const multicol = tabular.isMultiColumn(cell);
732 multicolumnCB->setChecked(multicol);
734 bool const multirow = tabular.isMultiRow(cell);
735 multirowCB->setChecked(multirow);
737 rotateCellCB->setChecked(tabular.getRotateCell(cell) != 0);
738 if (rotateCellCB->isChecked()) {
739 if (tabular.getRotateCell(cell) != 0)
740 rotateCellAngleSB->setValue(tabular.getRotateCell(cell));
742 rotateCellAngleSB->setValue(90);
745 longTabularCB->setChecked(tabular.is_long_tabular);
747 rotateTabularCB->setChecked(tabular.rotate != 0);
748 if (rotateTabularCB->isChecked()) {
749 if (longTabularCB->isChecked())
750 rotateTabularAngleSB->setValue(90);
752 rotateTabularAngleSB->setValue(tabular.rotate != 0 ? tabular.rotate : 90);
755 borders->setTop(tabular.topLine(cell));
756 borders->setBottom(tabular.bottomLine(cell));
757 borders->setLeft(tabular.leftLine(cell));
758 borders->setRight(tabular.rightLine(cell));
759 // repaint the setborder widget
762 Length::UNIT const default_unit = Length::defaultUnit();
764 ///////////////////////////////////
765 // Set width and alignment
767 Length const tabwidth = tabular.tabularWidth();
769 && !(tabularWidthED->hasFocus() && tabularWidthED->text() == "0"))
770 tabularWidthED->clear();
772 lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
773 tabwidth.asString(), default_unit);
778 special = getAlignSpecial(tabular, cell,
779 Tabular::SET_SPECIAL_MULTICOLUMN);
780 pwidth = getMColumnPWidth(tabular, cell);
782 special = getAlignSpecial(tabular, cell,
783 Tabular::SET_SPECIAL_COLUMN);
784 pwidth = getColumnPWidth(tabular, cell);
788 && !(columnWidthED->hasFocus() && columnWidthED->text() == "0"))
789 columnWidthED->clear();
791 colwidth = pwidth.asString();
792 lengthToWidgets(columnWidthED, columnWidthUnitLC,
793 colwidth, default_unit);
797 mroffset = getMROffset(tabular, cell);
800 && !(multirowOffsetED->hasFocus() && multirowOffsetED->text() == "0"))
801 multirowOffsetED->clear();
803 offset = mroffset.asString();
804 lengthToWidgets(multirowOffsetED, multirowOffsetUnitLC,
805 offset, default_unit);
807 specialAlignmentED->setText(toqstr(special));
808 ///////////////////////////////////
811 borderDefaultRB->setChecked(!tabular.use_booktabs);
812 booktabsRB->setChecked(tabular.use_booktabs);
814 if (tabular.row_info[row].top_space.empty()
815 && !tabular.row_info[row].top_space_default) {
816 topspaceCO->setCurrentIndex(0);
817 } else if (tabular.row_info[row].top_space_default) {
818 topspaceCO->setCurrentIndex(1);
820 topspaceCO->setCurrentIndex(2);
821 lengthToWidgets(topspaceED,
823 tabular.row_info[row].top_space.asString(),
827 if (tabular.row_info[row].bottom_space.empty()
828 && !tabular.row_info[row].bottom_space_default) {
829 bottomspaceCO->setCurrentIndex(0);
830 } else if (tabular.row_info[row].bottom_space_default) {
831 bottomspaceCO->setCurrentIndex(1);
833 bottomspaceCO->setCurrentIndex(2);
834 lengthToWidgets(bottomspaceED,
836 tabular.row_info[row].bottom_space.asString(),
840 if (tabular.row_info[row].interline_space.empty()
841 && !tabular.row_info[row].interline_space_default) {
842 interlinespaceCO->setCurrentIndex(0);
843 } else if (tabular.row_info[row].interline_space_default) {
844 interlinespaceCO->setCurrentIndex(1);
846 interlinespaceCO->setCurrentIndex(2);
847 lengthToWidgets(interlinespaceED,
848 interlinespaceUnitLC,
849 tabular.row_info[row].interline_space.asString(),
854 hAlignCO->addItem(qt_("Left"), toqstr("left"));
855 hAlignCO->addItem(qt_("Center"), toqstr("center"));
856 hAlignCO->addItem(qt_("Right"), toqstr("right"));
857 if (!multicol && !pwidth.zero())
858 hAlignCO->addItem(qt_("Justified"), toqstr("justified"));
859 if (!multicol && !multirow)
860 hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
863 switch (tabular.getAlignment(cell)) {
867 case LYX_ALIGN_CENTER:
870 case LYX_ALIGN_RIGHT:
873 case LYX_ALIGN_BLOCK:
875 if (!multicol && !pwidth.zero())
879 case LYX_ALIGN_DECIMAL:
881 if (!multicol && !multirow)
886 // we should never end up here
889 hAlignCO->setCurrentIndex(hAlignCO->findData(toqstr(align)));
892 QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
893 if (decimal_point.isEmpty())
894 decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
895 decimalPointED->setText(decimal_point);
898 switch (tabular.getVAlignment(cell)) {
899 case Tabular::LYX_VALIGN_TOP:
902 case Tabular::LYX_VALIGN_MIDDLE:
905 case Tabular::LYX_VALIGN_BOTTOM:
914 vAlignCO->setCurrentIndex(valign);
917 switch (tabular.tabular_valignment) {
918 case Tabular::LYX_VALIGN_TOP:
921 case Tabular::LYX_VALIGN_MIDDLE:
924 case Tabular::LYX_VALIGN_BOTTOM:
931 TableAlignCO->setCurrentIndex(tableValign);
933 if (!tabular.is_long_tabular) {
934 headerStatusCB->setChecked(false);
935 headerBorderAboveCB->setChecked(false);
936 headerBorderBelowCB->setChecked(false);
937 firstheaderStatusCB->setChecked(false);
938 firstheaderBorderAboveCB->setChecked(false);
939 firstheaderBorderBelowCB->setChecked(false);
940 firstheaderNoContentsCB->setChecked(false);
941 footerStatusCB->setChecked(false);
942 footerBorderAboveCB->setChecked(false);
943 footerBorderBelowCB->setChecked(false);
944 lastfooterStatusCB->setChecked(false);
945 lastfooterBorderAboveCB->setChecked(false);
946 lastfooterBorderBelowCB->setChecked(false);
947 lastfooterNoContentsCB->setChecked(false);
948 newpageCB->setChecked(false);
949 captionStatusCB->blockSignals(true);
950 captionStatusCB->setChecked(false);
951 captionStatusCB->blockSignals(false);
955 // longtables cannot have a vertical alignment
956 TableAlignCO->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
958 switch (tabular.longtabular_alignment) {
959 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
960 leftRB->setChecked(true);
962 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
963 centerRB->setChecked(true);
965 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
966 rightRB->setChecked(true);
969 centerRB->setChecked(true);
972 captionStatusCB->blockSignals(true);
973 captionStatusCB->setChecked(tabular.ltCaption(row));
974 captionStatusCB->blockSignals(false);
978 bool row_set = tabular.getRowOfLTHead(row, ltt);
979 headerStatusCB->setChecked(row_set);
981 headerBorderAboveCB->setChecked(ltt.topDL);
982 headerBorderBelowCB->setChecked(ltt.bottomDL);
985 headerBorderAboveCB->setChecked(false);
986 headerBorderBelowCB->setChecked(false);
987 firstheaderNoContentsCB->setChecked(false);
991 row_set = tabular.getRowOfLTFirstHead(row, ltt);
992 firstheaderStatusCB->setChecked(row_set);
993 if (ltt.set && (!ltt.empty || !use_empty)) {
994 firstheaderBorderAboveCB->setChecked(ltt.topDL);
995 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
997 firstheaderBorderAboveCB->setChecked(false);
998 firstheaderBorderBelowCB->setChecked(false);
1001 row_set = tabular.getRowOfLTFoot(row, ltt);
1002 footerStatusCB->setChecked(row_set);
1004 footerBorderAboveCB->setChecked(ltt.topDL);
1005 footerBorderBelowCB->setChecked(ltt.bottomDL);
1008 footerBorderAboveCB->setChecked(false);
1009 footerBorderBelowCB->setChecked(false);
1010 lastfooterNoContentsCB->setChecked(false);
1014 row_set = tabular.getRowOfLTLastFoot(row, ltt);
1015 lastfooterStatusCB->setChecked(row_set);
1016 if (ltt.set && (!ltt.empty || !use_empty)) {
1017 lastfooterBorderAboveCB->setChecked(ltt.topDL);
1018 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
1020 lastfooterBorderAboveCB->setChecked(false);
1021 lastfooterBorderBelowCB->setChecked(false);
1023 newpageCB->setChecked(tabular.getLTNewPage(row));
1025 // first header can only be suppressed when there is a header
1026 firstheader_suppressable_ = tabular.haveLTHead()
1027 && !tabular.haveLTFirstHead();
1028 // last footer can only be suppressed when there is a footer
1029 lastfooter_suppressable_ = tabular.haveLTFoot()
1030 && !tabular.haveLTLastFoot();
1032 // after setting the features, check if they are enabled
1037 bool GuiTabular::checkWidgets(bool readonly) const
1039 tabularRowED->setReadOnly(readonly);
1040 tabularColumnED->setReadOnly(readonly);
1041 tabularWidthED->setReadOnly(readonly);
1042 specialAlignmentED->setReadOnly(readonly);
1043 columnWidthED->setReadOnly(readonly);
1044 multirowOffsetED->setReadOnly(readonly);
1045 decimalPointED->setReadOnly(readonly);
1048 multicolumnCB->setEnabled(false);
1049 multirowCB->setEnabled(false);
1050 rotateCellCB->setEnabled(false);
1051 rotateCellAngleSB->setEnabled(false);
1052 rotateTabularCB->setEnabled(false);
1053 rotateTabularAngleSB->setEnabled(false);
1054 longTabularCB->setEnabled(false);
1055 borders->setEnabled(false);
1056 tabularWidthUnitLC->setEnabled(false);
1057 columnWidthUnitLC->setEnabled(false);
1058 multirowOffsetUnitLC->setEnabled(false);
1059 setBordersGB->setEnabled(false);
1060 allBordersGB->setEnabled(false);
1061 borderStyleGB->setEnabled(false);
1062 booktabsRB->setEnabled(false);
1063 topspaceCO->setEnabled(false);
1064 topspaceUnitLC->setEnabled(false);
1065 bottomspaceCO->setEnabled(false);
1066 bottomspaceUnitLC->setEnabled(false);
1067 interlinespaceCO->setEnabled(false);
1068 interlinespaceUnitLC->setEnabled(false);
1069 hAlignCO->setEnabled(false);
1070 vAlignCO->setEnabled(false);
1071 TableAlignCO->setEnabled(false);
1072 longtableGB->setEnabled(false);
1073 alignmentGB->setEnabled(false);
1077 return InsetParamsWidget::checkWidgets();
1081 bool GuiTabular::funcEnabled(Tabular::Feature f) const
1083 FuncRequest r(LFUN_INSET_MODIFY, "tabular for-dialog" + featureAsString(f));
1084 return getStatus(r).enabled();
1088 } // namespace frontend
1091 #include "moc_GuiTabular.cpp"