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::on_columnTypeCO_activated(int index)
209 columnWidthED->setFocus();
213 void GuiTabular::enableWidgets() const
215 // if there is a LaTeX argument, the width and alignment will be overwritten
216 // therefore disable them in this case
217 bool const fixed = specialAlignmentED->text().isEmpty()
218 && columnTypeCO->currentIndex() == 2;
219 columnWidthED->setEnabled(fixed);
220 columnWidthUnitLC->setEnabled(fixed);
221 // if the column has a width, multirows are always left-aligned
222 // therefore disable hAlignCB in this case
223 hAlignCO->setEnabled(!(multirowCB->isChecked()
224 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty())
225 && specialAlignmentED->text().isEmpty());
226 // decimal alignment is only possible for non-multicol and non-multirow cells
227 if ((multicolumnCB->isChecked() || multirowCB->isChecked() || columnTypeCO->currentIndex() == 1)
228 && hAlignCO->findData(toqstr("decimal")))
229 hAlignCO->removeItem(hAlignCO->findData(toqstr("decimal")));
230 else if (!multicolumnCB->isChecked() && !multirowCB->isChecked()
231 && hAlignCO->findData(toqstr("decimal")) == -1)
232 hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
234 hAlignCO->itemData(hAlignCO->currentIndex()).toString() == QString("decimal");
235 decimalPointED->setEnabled(dalign);
236 decimalLA->setEnabled(dalign);
238 bool const setwidth = TableAlignCO->currentText() == qt_("Middle");
239 tabularWidthLA->setEnabled(setwidth);
240 tabularWidthED->setEnabled(setwidth);
241 tabularWidthUnitLC->setEnabled(setwidth);
243 rotateTabularAngleSB->setEnabled(rotateTabularCB->isChecked()
244 && !longTabularCB->isChecked());
245 rotateCellAngleSB->setEnabled(rotateCellCB->isChecked());
247 bool const enable_valign =
248 !multirowCB->isChecked()
249 && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty()
250 && specialAlignmentED->text().isEmpty();
251 vAlignCO->setEnabled(enable_valign);
252 vAlignLA->setEnabled(enable_valign);
254 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
255 topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
256 topspaceUnitLC->setEnabled(topspaceCO->currentIndex() == 2);
257 bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
258 bottomspaceUnitLC->setEnabled(bottomspaceCO->currentIndex() == 2);
259 interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
260 interlinespaceUnitLC->setEnabled(interlinespaceCO->currentIndex() == 2);
262 // setting as longtable is not allowed when table is inside a float
263 bool const is_tabular_star = !tabularWidthED->text().isEmpty();
264 longTabularCB->setEnabled(funcEnabled(Tabular::SET_LONGTABULAR));
265 bool const longtabular = longTabularCB->isChecked();
266 longtableGB->setEnabled(true);
267 newpageCB->setEnabled(longtabular);
268 alignmentGB->setEnabled(longtabular);
269 // longtables and tabular* cannot have a vertical alignment
270 TableAlignLA->setDisabled(is_tabular_star || longtabular);
271 TableAlignCO->setDisabled(is_tabular_star || longtabular);
272 // longtable cannot be rotated with rotating package, only
273 // with [pdf]lscape, which only supports 90 deg.
274 rotateTabularAngleSB->setDisabled(longtabular);
276 // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
277 // depending on the cursor position is very very unintuitive...
278 // We need some edit boxes to show which rows are header/footer/etc
279 // without having to move the cursor first.
280 headerStatusCB->setEnabled(longtabular
281 && (headerStatusCB->isChecked() ?
282 funcEnabled(Tabular::UNSET_LTHEAD) :
283 funcEnabled(Tabular::SET_LTHEAD)));
284 headerBorderAboveCB->setEnabled(longtabular
285 && headerStatusCB->isChecked());
286 headerBorderBelowCB->setEnabled(longtabular
287 && headerStatusCB->isChecked());
289 // first header can only be suppressed when there is a header
290 // firstheader_suppressable_ is set in paramsToDialog
291 firstheaderNoContentsCB->setEnabled(longtabular && firstheader_suppressable_);
292 // check if setting a first header is allowed
293 // additionally check firstheaderNoContentsCB because when this is
294 // the case a first header makes no sense
295 firstheaderStatusCB->setEnabled((firstheaderStatusCB->isChecked() ?
296 funcEnabled(Tabular::UNSET_LTFIRSTHEAD) :
297 funcEnabled(Tabular::SET_LTFIRSTHEAD))
298 && longtabular && !firstheaderNoContentsCB->isChecked());
299 firstheaderBorderAboveCB->setEnabled(longtabular
300 && firstheaderStatusCB->isChecked());
301 firstheaderBorderBelowCB->setEnabled(longtabular
302 && firstheaderStatusCB->isChecked());
304 footerStatusCB->setEnabled(longtabular
305 && (footerStatusCB->isChecked() ?
306 funcEnabled(Tabular::UNSET_LTFOOT) :
307 funcEnabled(Tabular::SET_LTFOOT)));
308 footerBorderAboveCB->setEnabled(longtabular
309 && footerBorderAboveCB->isChecked());
310 footerBorderBelowCB->setEnabled(longtabular
311 && footerBorderAboveCB->isChecked());
313 // last footer can only be suppressed when there is a footer
314 // lastfooter_suppressable_ is set in paramsToDialog
315 lastfooterNoContentsCB->setEnabled(longtabular && lastfooter_suppressable_);
316 // check if setting a last footer is allowed
317 // additionally check lastfooterNoContentsCB because when this is
318 // the case a last footer makes no sense
319 lastfooterStatusCB->setEnabled((lastfooterStatusCB->isChecked() ?
320 funcEnabled(Tabular::UNSET_LTLASTFOOT) :
321 funcEnabled(Tabular::SET_LTLASTFOOT))
322 && longtabular && !lastfooterNoContentsCB->isChecked());
323 lastfooterBorderAboveCB->setEnabled(longtabular
324 && lastfooterBorderAboveCB->isChecked());
325 lastfooterBorderBelowCB->setEnabled(longtabular
326 && lastfooterBorderAboveCB->isChecked());
328 captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)
331 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN)
332 && !dalign && !multirowCB->isChecked());
333 multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW)
334 && !dalign && !multicolumnCB->isChecked());
335 bool const enable_mr = multirowCB->isChecked();
336 multirowOffsetLA->setEnabled(enable_mr);
337 multirowOffsetED->setEnabled(enable_mr);
338 multirowOffsetUnitLC->setEnabled(enable_mr);
340 // Vertical lines cannot be set in formal tables
341 borders->setLeftEnabled(!booktabsRB->isChecked());
342 borders->setRightEnabled(!booktabsRB->isChecked());
346 void GuiTabular::checkEnabled()
353 void GuiTabular::borderSet_clicked()
355 borders->setTop(true);
356 borders->setBottom(true);
357 borders->setLeft(true);
358 borders->setRight(true);
359 // repaint the setborder widget
365 void GuiTabular::borderUnset_clicked()
367 borders->setTop(false);
368 borders->setBottom(false);
369 borders->setLeft(false);
370 borders->setRight(false);
371 // repaint the setborder widget
377 static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
380 param_str += featureAsString(f) + ' ' + arg;
384 void GuiTabular::setHAlign(string & param_str) const
386 Tabular::Feature num = Tabular::ALIGN_LEFT;
387 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
389 fromqstr(hAlignCO->itemData(hAlignCO->currentIndex()).toString());
390 if (align == "left") {
391 num = Tabular::ALIGN_LEFT;
392 multi_num = Tabular::M_ALIGN_LEFT;
393 } else if (align == "center") {
394 num = Tabular::ALIGN_CENTER;
395 multi_num = Tabular::M_ALIGN_CENTER;
396 } else if (align == "right") {
397 num = Tabular::ALIGN_RIGHT;
398 multi_num = Tabular::M_ALIGN_RIGHT;
399 } else if (align == "justified") {
400 num = Tabular::ALIGN_BLOCK;
401 //multi_num: no equivalent
402 } else if (align == "decimal") {
403 num = Tabular::ALIGN_DECIMAL;
404 //multi_num: no equivalent
407 if (multicolumnCB->isChecked())
408 setParam(param_str, multi_num);
410 setParam(param_str, num);
414 void GuiTabular::setVAlign(string & param_str) const
416 int const align = vAlignCO->currentIndex();
417 enum VALIGN { TOP, MIDDLE, BOTTOM };
421 case 0: v = TOP; break;
422 case 1: v = MIDDLE; break;
423 case 2: v = BOTTOM; break;
426 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
427 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
431 num = Tabular::VALIGN_TOP;
432 multi_num = Tabular::M_VALIGN_TOP;
435 num = Tabular::VALIGN_MIDDLE;
436 multi_num = Tabular::M_VALIGN_MIDDLE;
439 num = Tabular::VALIGN_BOTTOM;
440 multi_num = Tabular::M_VALIGN_BOTTOM;
443 if (multicolumnCB->isChecked() || multirowCB->isChecked())
444 setParam(param_str, multi_num);
446 setParam(param_str, num);
450 void GuiTabular::setTableAlignment(string & param_str) const
452 int const align = TableAlignCO->currentIndex();
454 case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
456 case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
458 case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
464 docstring GuiTabular::dialogToParams() const
466 string param_str = "tabular";
469 string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitLC);
470 if (tabwidth.empty())
472 setParam(param_str, Tabular::SET_TABULAR_WIDTH, tabwidth);
474 // apply the fixed width values
475 // this must be done before applying the column alignment
476 // because its value influences the alignment of multirow cells
477 string width = widgetsToLength(columnWidthED, columnWidthUnitLC);
478 if (width.empty() || columnTypeCO->currentIndex() != 2)
480 if (multicolumnCB->isChecked())
481 setParam(param_str, Tabular::SET_MPWIDTH, width);
483 setParam(param_str, Tabular::SET_PWIDTH, width);
485 bool const varwidth = specialAlignmentED->text().isEmpty()
486 && columnTypeCO->currentIndex() == 1;
488 setParam(param_str, Tabular::TOGGLE_VARWIDTH_COLUMN, "on");
490 setParam(param_str, Tabular::TOGGLE_VARWIDTH_COLUMN, "off");
492 // apply the column alignment
493 // multirows inherit the alignment from the column; if a column width
494 // is set, multirows are always left-aligned so that in this case
495 // its alignment must not be applied (see bug #8084)
496 if (!(multirowCB->isChecked() && width != "0pt"))
497 setHAlign(param_str);
499 // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
500 string decimal_point = fromqstr(decimalPointED->text());
501 if (decimal_point.empty())
502 decimal_point = lyxrc.default_decimal_point;
503 setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
505 setVAlign(param_str);
506 setTableAlignment(param_str);
508 if (booktabsRB->isChecked())
509 setParam(param_str, Tabular::SET_BOOKTABS);
511 setParam(param_str, Tabular::UNSET_BOOKTABS);
514 switch (topspaceCO->currentIndex()) {
516 setParam(param_str, Tabular::SET_TOP_SPACE, "none");
519 setParam(param_str, Tabular::SET_TOP_SPACE, "default");
522 if (!topspaceED->text().isEmpty())
523 setParam(param_str, Tabular::SET_TOP_SPACE,
524 widgetsToLength(topspaceED, topspaceUnitLC));
529 switch (bottomspaceCO->currentIndex()) {
531 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
534 setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
537 if (!bottomspaceED->text().isEmpty())
538 setParam(param_str, Tabular::SET_BOTTOM_SPACE,
539 widgetsToLength(bottomspaceED,
545 switch (interlinespaceCO->currentIndex()) {
547 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
550 setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
553 if (!interlinespaceED->text().isEmpty())
554 setParam(param_str, Tabular::SET_INTERLINE_SPACE,
555 widgetsToLength(interlinespaceED,
556 interlinespaceUnitLC));
561 if (borders->getTop() && borders->getBottom() && borders->getLeft()
562 && borders->getRight())
563 setParam(param_str, Tabular::SET_ALL_LINES);
564 else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft()
565 && !borders->getRight())
566 setParam(param_str, Tabular::UNSET_ALL_LINES);
568 setParam(param_str, Tabular::SET_LINE_LEFT,
569 borders->getLeft() ? "true" : "false");
570 setParam(param_str, Tabular::SET_LINE_RIGHT,
571 borders->getRight() ? "true" : "false");
572 setParam(param_str, Tabular::SET_LINE_TOP,
573 borders->getTop() ? "true" : "false");
574 setParam(param_str, Tabular::SET_LINE_BOTTOM,
575 borders->getBottom() ? "true" : "false");
578 // apply the special alignment
579 string special = fromqstr(specialAlignmentED->text());
580 if (support::trim(special).empty())
582 if (multicolumnCB->isChecked())
583 setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
585 setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
588 if (multicolumnCB->isChecked())
589 setParam(param_str, Tabular::SET_MULTICOLUMN);
591 setParam(param_str, Tabular::UNSET_MULTICOLUMN);
593 // apply the multirow offset
594 string mroffset = widgetsToLength(multirowOffsetED, multirowOffsetUnitLC);
595 if (mroffset.empty())
597 if (multirowCB->isChecked())
598 setParam(param_str, Tabular::SET_MROFFSET, mroffset);
600 if (multirowCB->isChecked())
601 setParam(param_str, Tabular::SET_MULTIROW);
603 setParam(param_str, Tabular::UNSET_MULTIROW);
604 // store the table rotation angle
605 string const tabular_angle = convert<string>(rotateTabularAngleSB->value());
606 if (rotateTabularCB->isChecked())
607 setParam(param_str, Tabular::SET_ROTATE_TABULAR, tabular_angle);
609 setParam(param_str, Tabular::UNSET_ROTATE_TABULAR, tabular_angle);
610 // store the cell rotation angle
611 string const cell_angle = convert<string>(rotateCellAngleSB->value());
612 if (rotateCellCB->isChecked())
613 setParam(param_str, Tabular::SET_ROTATE_CELL, cell_angle);
615 setParam(param_str, Tabular::UNSET_ROTATE_CELL, cell_angle);
617 if (longTabularCB->isChecked())
618 setParam(param_str, Tabular::SET_LONGTABULAR);
620 setParam(param_str, Tabular::UNSET_LONGTABULAR);
622 if (newpageCB->isChecked())
623 setParam(param_str, Tabular::SET_LTNEWPAGE);
625 setParam(param_str, Tabular::UNSET_LTNEWPAGE);
627 if (captionStatusCB->isChecked())
628 setParam(param_str, Tabular::SET_LTCAPTION);
630 setParam(param_str, Tabular::UNSET_LTCAPTION);
632 if (headerStatusCB->isChecked())
633 setParam(param_str, Tabular::SET_LTHEAD, "none");
635 setParam(param_str, Tabular::UNSET_LTHEAD, "none");
637 if (headerBorderAboveCB->isChecked())
638 setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
640 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
642 if (headerBorderBelowCB->isChecked())
643 setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
645 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
646 if (firstheaderBorderAboveCB->isChecked())
647 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
649 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
650 if (firstheaderBorderBelowCB->isChecked())
651 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
653 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
654 if (firstheaderStatusCB->isChecked())
655 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
657 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
658 if (firstheaderNoContentsCB->isChecked())
659 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
661 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
662 if (footerStatusCB->isChecked())
663 setParam(param_str, Tabular::SET_LTFOOT, "none");
665 setParam(param_str, Tabular::UNSET_LTFOOT, "none");
666 if (footerBorderAboveCB->isChecked())
667 setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
669 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
670 if (footerBorderBelowCB->isChecked())
671 setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
673 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
674 if (lastfooterStatusCB->isChecked())
675 setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
677 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
678 if (lastfooterBorderAboveCB->isChecked())
679 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
681 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
682 if (lastfooterBorderBelowCB->isChecked())
683 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
685 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
686 if (lastfooterNoContentsCB->isChecked())
687 setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
689 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
691 if (leftRB->isChecked())
692 setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
693 else if (centerRB->isChecked())
694 setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
695 else if (rightRB->isChecked())
696 setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
698 return from_utf8(param_str);
702 static Length getColumnPWidth(Tabular const & t, size_t cell)
704 return t.column_info[t.cellColumn(cell)].p_width;
708 static Length getMColumnPWidth(Tabular const & t, size_t cell)
710 if (t.isMultiColumn(cell) || t.isMultiRow(cell))
711 return t.cellInfo(cell).p_width;
716 static Length getMROffset(Tabular const & t, size_t cell)
718 if (t.isMultiRow(cell))
719 return t.cellInfo(cell).mroffset;
724 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
726 if (what == Tabular::SET_SPECIAL_MULTICOLUMN)
727 return t.cellInfo(cell).align_special;
728 return t.column_info[t.cellColumn(cell)].align_special;
732 void GuiTabular::paramsToDialog(Inset const * inset)
734 InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
735 // Copy Tabular of current inset.
736 Tabular const & tabular = itab->tabular;
738 BufferView const * bv = guiApp->currentView()->currentBufferView();
739 size_t const cell = bv->cursor().idx();
741 Tabular::row_type const row = tabular.cellRow(cell);
742 Tabular::col_type const col = tabular.cellColumn(cell);
744 tabularRowED->setText(QString::number(row + 1));
745 tabularColumnED->setText(QString::number(col + 1));
747 bool const multicol = tabular.isMultiColumn(cell);
748 multicolumnCB->setChecked(multicol);
750 bool const multirow = tabular.isMultiRow(cell);
751 multirowCB->setChecked(multirow);
753 rotateCellCB->setChecked(tabular.getRotateCell(cell) != 0);
754 if (rotateCellCB->isChecked()) {
755 if (tabular.getRotateCell(cell) != 0)
756 rotateCellAngleSB->setValue(tabular.getRotateCell(cell));
758 rotateCellAngleSB->setValue(90);
761 longTabularCB->setChecked(tabular.is_long_tabular);
763 rotateTabularCB->setChecked(tabular.rotate != 0);
764 if (rotateTabularCB->isChecked()) {
765 if (longTabularCB->isChecked())
766 rotateTabularAngleSB->setValue(90);
768 rotateTabularAngleSB->setValue(tabular.rotate != 0 ? tabular.rotate : 90);
771 borders->setTop(tabular.topLine(cell));
772 borders->setBottom(tabular.bottomLine(cell));
773 borders->setLeft(tabular.leftLine(cell));
774 borders->setRight(tabular.rightLine(cell));
775 // repaint the setborder widget
778 Length::UNIT const default_unit = Length::defaultUnit();
780 ///////////////////////////////////
781 // Set width and alignment
783 Length const tabwidth = tabular.tabularWidth();
785 && !(tabularWidthED->hasFocus() && tabularWidthED->text() == "0"))
786 tabularWidthED->clear();
788 lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
789 tabwidth.asString(), default_unit);
794 special = getAlignSpecial(tabular, cell,
795 Tabular::SET_SPECIAL_MULTICOLUMN);
796 pwidth = getMColumnPWidth(tabular, cell);
798 special = getAlignSpecial(tabular, cell,
799 Tabular::SET_SPECIAL_COLUMN);
800 pwidth = getColumnPWidth(tabular, cell);
802 bool const varwidth = tabular.column_info[tabular.cellColumn(cell)].varwidth;
804 columnTypeCO->setCurrentIndex(1);
807 && !(columnWidthED->hasFocus() && columnWidthED->text() == "0")) {
808 columnWidthED->clear();
810 columnTypeCO->setCurrentIndex(0);
812 colwidth = pwidth.asString();
813 lengthToWidgets(columnWidthED, columnWidthUnitLC,
814 colwidth, default_unit);
815 columnTypeCO->setCurrentIndex(2);
819 mroffset = getMROffset(tabular, cell);
822 && !(multirowOffsetED->hasFocus() && multirowOffsetED->text() == "0"))
823 multirowOffsetED->clear();
825 offset = mroffset.asString();
826 lengthToWidgets(multirowOffsetED, multirowOffsetUnitLC,
827 offset, default_unit);
829 specialAlignmentED->setText(toqstr(special));
830 ///////////////////////////////////
833 borderDefaultRB->setChecked(!tabular.use_booktabs);
834 booktabsRB->setChecked(tabular.use_booktabs);
836 if (tabular.row_info[row].top_space.empty()
837 && !tabular.row_info[row].top_space_default) {
838 topspaceCO->setCurrentIndex(0);
839 } else if (tabular.row_info[row].top_space_default) {
840 topspaceCO->setCurrentIndex(1);
842 topspaceCO->setCurrentIndex(2);
843 lengthToWidgets(topspaceED,
845 tabular.row_info[row].top_space.asString(),
849 if (tabular.row_info[row].bottom_space.empty()
850 && !tabular.row_info[row].bottom_space_default) {
851 bottomspaceCO->setCurrentIndex(0);
852 } else if (tabular.row_info[row].bottom_space_default) {
853 bottomspaceCO->setCurrentIndex(1);
855 bottomspaceCO->setCurrentIndex(2);
856 lengthToWidgets(bottomspaceED,
858 tabular.row_info[row].bottom_space.asString(),
862 if (tabular.row_info[row].interline_space.empty()
863 && !tabular.row_info[row].interline_space_default) {
864 interlinespaceCO->setCurrentIndex(0);
865 } else if (tabular.row_info[row].interline_space_default) {
866 interlinespaceCO->setCurrentIndex(1);
868 interlinespaceCO->setCurrentIndex(2);
869 lengthToWidgets(interlinespaceED,
870 interlinespaceUnitLC,
871 tabular.row_info[row].interline_space.asString(),
876 hAlignCO->addItem(qt_("Left"), toqstr("left"));
877 hAlignCO->addItem(qt_("Center"), toqstr("center"));
878 hAlignCO->addItem(qt_("Right"), toqstr("right"));
879 if (!multicol && !pwidth.zero())
880 hAlignCO->addItem(qt_("Justified"), toqstr("justified"));
881 if (!multicol && !multirow)
882 hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
885 switch (tabular.getAlignment(cell)) {
889 case LYX_ALIGN_CENTER:
892 case LYX_ALIGN_RIGHT:
895 case LYX_ALIGN_BLOCK:
897 if (!multicol && !pwidth.zero())
901 case LYX_ALIGN_DECIMAL:
903 if (!multicol && !multirow)
908 // we should never end up here
911 hAlignCO->setCurrentIndex(hAlignCO->findData(toqstr(align)));
914 QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
915 if (decimal_point.isEmpty())
916 decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
917 decimalPointED->setText(decimal_point);
920 switch (tabular.getVAlignment(cell)) {
921 case Tabular::LYX_VALIGN_TOP:
924 case Tabular::LYX_VALIGN_MIDDLE:
927 case Tabular::LYX_VALIGN_BOTTOM:
936 vAlignCO->setCurrentIndex(valign);
939 switch (tabular.tabular_valignment) {
940 case Tabular::LYX_VALIGN_TOP:
943 case Tabular::LYX_VALIGN_MIDDLE:
946 case Tabular::LYX_VALIGN_BOTTOM:
953 TableAlignCO->setCurrentIndex(tableValign);
955 if (!tabular.is_long_tabular) {
956 headerStatusCB->setChecked(false);
957 headerBorderAboveCB->setChecked(false);
958 headerBorderBelowCB->setChecked(false);
959 firstheaderStatusCB->setChecked(false);
960 firstheaderBorderAboveCB->setChecked(false);
961 firstheaderBorderBelowCB->setChecked(false);
962 firstheaderNoContentsCB->setChecked(false);
963 footerStatusCB->setChecked(false);
964 footerBorderAboveCB->setChecked(false);
965 footerBorderBelowCB->setChecked(false);
966 lastfooterStatusCB->setChecked(false);
967 lastfooterBorderAboveCB->setChecked(false);
968 lastfooterBorderBelowCB->setChecked(false);
969 lastfooterNoContentsCB->setChecked(false);
970 newpageCB->setChecked(false);
971 captionStatusCB->blockSignals(true);
972 captionStatusCB->setChecked(false);
973 captionStatusCB->blockSignals(false);
977 // longtables cannot have a vertical alignment
978 TableAlignCO->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
980 switch (tabular.longtabular_alignment) {
981 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
982 leftRB->setChecked(true);
984 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
985 centerRB->setChecked(true);
987 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
988 rightRB->setChecked(true);
991 centerRB->setChecked(true);
994 captionStatusCB->blockSignals(true);
995 captionStatusCB->setChecked(tabular.ltCaption(row));
996 captionStatusCB->blockSignals(false);
1000 bool row_set = tabular.getRowOfLTHead(row, ltt);
1001 headerStatusCB->setChecked(row_set);
1003 headerBorderAboveCB->setChecked(ltt.topDL);
1004 headerBorderBelowCB->setChecked(ltt.bottomDL);
1007 headerBorderAboveCB->setChecked(false);
1008 headerBorderBelowCB->setChecked(false);
1009 firstheaderNoContentsCB->setChecked(false);
1013 row_set = tabular.getRowOfLTFirstHead(row, ltt);
1014 firstheaderStatusCB->setChecked(row_set);
1015 if (ltt.set && (!ltt.empty || !use_empty)) {
1016 firstheaderBorderAboveCB->setChecked(ltt.topDL);
1017 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
1019 firstheaderBorderAboveCB->setChecked(false);
1020 firstheaderBorderBelowCB->setChecked(false);
1023 row_set = tabular.getRowOfLTFoot(row, ltt);
1024 footerStatusCB->setChecked(row_set);
1026 footerBorderAboveCB->setChecked(ltt.topDL);
1027 footerBorderBelowCB->setChecked(ltt.bottomDL);
1030 footerBorderAboveCB->setChecked(false);
1031 footerBorderBelowCB->setChecked(false);
1032 lastfooterNoContentsCB->setChecked(false);
1036 row_set = tabular.getRowOfLTLastFoot(row, ltt);
1037 lastfooterStatusCB->setChecked(row_set);
1038 if (ltt.set && (!ltt.empty || !use_empty)) {
1039 lastfooterBorderAboveCB->setChecked(ltt.topDL);
1040 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
1042 lastfooterBorderAboveCB->setChecked(false);
1043 lastfooterBorderBelowCB->setChecked(false);
1045 newpageCB->setChecked(tabular.getLTNewPage(row));
1047 // first header can only be suppressed when there is a header
1048 firstheader_suppressable_ = tabular.haveLTHead()
1049 && !tabular.haveLTFirstHead();
1050 // last footer can only be suppressed when there is a footer
1051 lastfooter_suppressable_ = tabular.haveLTFoot()
1052 && !tabular.haveLTLastFoot();
1054 // after setting the features, check if they are enabled
1059 bool GuiTabular::checkWidgets(bool readonly) const
1061 tabularRowED->setReadOnly(readonly);
1062 tabularColumnED->setReadOnly(readonly);
1063 tabularWidthED->setReadOnly(readonly);
1064 specialAlignmentED->setReadOnly(readonly);
1065 columnWidthED->setReadOnly(readonly);
1066 multirowOffsetED->setReadOnly(readonly);
1067 decimalPointED->setReadOnly(readonly);
1070 multicolumnCB->setEnabled(false);
1071 multirowCB->setEnabled(false);
1072 rotateCellCB->setEnabled(false);
1073 rotateCellAngleSB->setEnabled(false);
1074 rotateTabularCB->setEnabled(false);
1075 rotateTabularAngleSB->setEnabled(false);
1076 longTabularCB->setEnabled(false);
1077 borders->setEnabled(false);
1078 tabularWidthUnitLC->setEnabled(false);
1079 columnWidthUnitLC->setEnabled(false);
1080 columnTypeCO->setEnabled(false);
1081 multirowOffsetUnitLC->setEnabled(false);
1082 setBordersGB->setEnabled(false);
1083 allBordersGB->setEnabled(false);
1084 borderStyleGB->setEnabled(false);
1085 booktabsRB->setEnabled(false);
1086 topspaceCO->setEnabled(false);
1087 topspaceUnitLC->setEnabled(false);
1088 bottomspaceCO->setEnabled(false);
1089 bottomspaceUnitLC->setEnabled(false);
1090 interlinespaceCO->setEnabled(false);
1091 interlinespaceUnitLC->setEnabled(false);
1092 hAlignCO->setEnabled(false);
1093 vAlignCO->setEnabled(false);
1094 TableAlignCO->setEnabled(false);
1095 longtableGB->setEnabled(false);
1096 alignmentGB->setEnabled(false);
1100 return InsetParamsWidget::checkWidgets();
1104 bool GuiTabular::funcEnabled(Tabular::Feature f) const
1106 FuncRequest r(LFUN_INSET_MODIFY, "tabular for-dialog" + featureAsString(f));
1107 return getStatus(r).enabled();
1111 } // namespace frontend
1114 #include "moc_GuiTabular.cpp"