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
10 * Full author contact details are available in file CREDITS.
15 #include "GuiTabular.h"
17 #include "GuiSetBorder.h"
19 #include "LengthCombo.h"
20 #include "qt_helpers.h"
21 #include "Validator.h"
23 #include "BufferView.h"
25 #include "FuncRequest.h"
28 #include "insets/InsetTabular.h"
31 #include <QPushButton>
32 #include <QRadioButton>
40 GuiTabular::GuiTabular(GuiView & lv)
41 : GuiDialog(lv, "tabular", qt_("Table Settings")),
42 // tabular_ is initialised at dialog construction in initialiseParams()
43 tabular_(*lv.buffer(), 0, 0)
45 active_cell_ = Tabular::npos;
49 widthED->setValidator(unsignedLengthValidator(widthED));
50 topspaceED->setValidator(new LengthValidator(topspaceED));
51 bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
52 interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
54 connect(topspaceED, SIGNAL(returnPressed()),
55 this, SLOT(topspace_changed()));
56 connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
57 this, SLOT(topspace_changed()));
58 connect(topspaceCO, SIGNAL(activated(int)), this, SLOT(topspace_changed()));
59 connect(bottomspaceED, SIGNAL(returnPressed()),
60 this, SLOT(bottomspace_changed()));
61 connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
62 this, SLOT(bottomspace_changed()));
63 connect(bottomspaceCO, SIGNAL(activated(int)), this, SLOT(bottomspace_changed()));
64 connect(interlinespaceED, SIGNAL(returnPressed()),
65 this, SLOT(interlinespace_changed()));
66 connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
67 this, SLOT(interlinespace_changed()));
68 connect(interlinespaceCO, SIGNAL(activated(int)), this, SLOT(interlinespace_changed()));
69 connect(booktabsRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
70 connect(borderDefaultRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
71 connect(borderSetPB, SIGNAL(clicked()), this, SLOT(borderSet_clicked()));
72 connect(borderUnsetPB, SIGNAL(clicked()), this, SLOT(borderUnset_clicked()));
73 connect(longTabularCB, SIGNAL(toggled(bool)), longtableGB, SLOT(setEnabled(bool)));
74 connect(longTabularCB, SIGNAL(toggled(bool)), newpageCB, SLOT(setEnabled(bool)));
75 connect(hAlignCB, SIGNAL(activated(int)), this, SLOT(hAlign_changed(int)));
76 connect(vAlignCB, SIGNAL(activated(int)), this, SLOT(vAlign_changed(int)));
77 connect(multicolumnCB, SIGNAL(clicked()), this, SLOT(multicolumn_clicked()));
78 connect(newpageCB, SIGNAL(clicked()), this, SLOT(ltNewpage_clicked()));
79 connect(headerStatusCB, SIGNAL(clicked()), this, SLOT(ltHeaderStatus_clicked()));
80 connect(headerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderAbove_clicked()));
81 connect(headerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderBelow_clicked()));
82 connect(firstheaderStatusCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderStatus_clicked()));
83 connect(firstheaderBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderAbove_clicked()));
84 connect(firstheaderBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderBelow_clicked()));
85 connect(firstheaderNoContentsCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderEmpty_clicked()));
86 connect(footerStatusCB, SIGNAL(clicked()), this, SLOT(ltFooterStatus_clicked()));
87 connect(footerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderAbove_clicked()));
88 connect(footerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderBelow_clicked()));
89 connect(lastfooterStatusCB, SIGNAL(clicked()), this, SLOT(ltLastFooterStatus_clicked()));
90 connect(lastfooterBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderAbove_clicked()));
91 connect(lastfooterBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderBelow_clicked()));
92 connect(lastfooterNoContentsCB, SIGNAL(clicked()), this, SLOT(ltLastFooterEmpty_clicked()));
93 connect(specialAlignmentED, SIGNAL(returnPressed()), this, SLOT(specialAlignment_changed()));
94 connect(widthED, SIGNAL(editingFinished()), this, SLOT(width_changed()));
95 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), this, SLOT(width_changed()));
96 connect(closePB, SIGNAL(clicked()), this, SLOT(close_clicked()));
97 connect(borders, SIGNAL(topSet(bool)), this, SLOT(topBorder_changed()));
98 connect(borders, SIGNAL(bottomSet(bool)), this, SLOT(bottomBorder_changed()));
99 connect(borders, SIGNAL(rightSet(bool)), this, SLOT(rightBorder_changed()));
100 connect(borders, SIGNAL(leftSet(bool)), this, SLOT(leftBorder_changed()));
101 connect(rotateTabularCB, SIGNAL(clicked()), this, SLOT(rotateTabular()));
102 connect(rotateCellCB, SIGNAL(clicked()), this, SLOT(rotateCell()));
103 connect(longTabularCB, SIGNAL(clicked()), this, SLOT(longTabular()));
105 bc().setPolicy(ButtonPolicy::IgnorantPolicy);
107 bc().addReadOnly(topspaceED);
108 bc().addReadOnly(topspaceUnit);
109 bc().addReadOnly(topspaceCO);
110 bc().addReadOnly(bottomspaceED);
111 bc().addReadOnly(bottomspaceUnit);
112 bc().addReadOnly(bottomspaceCO);
113 bc().addReadOnly(interlinespaceED);
114 bc().addReadOnly(interlinespaceUnit);
115 bc().addReadOnly(interlinespaceCO);
116 bc().addReadOnly(borderDefaultRB);
117 bc().addReadOnly(booktabsRB);
119 bc().addReadOnly(multicolumnCB);
120 bc().addReadOnly(rotateCellCB);
121 bc().addReadOnly(rotateTabularCB);
122 bc().addReadOnly(specialAlignmentED);
123 bc().addReadOnly(widthED);
124 bc().addReadOnly(widthUnit);
125 bc().addReadOnly(hAlignCB);
126 bc().addReadOnly(vAlignCB);
127 bc().addReadOnly(borderSetPB);
128 bc().addReadOnly(borderUnsetPB);
129 bc().addReadOnly(borders);
130 bc().addReadOnly(longTabularCB);
131 bc().addReadOnly(headerStatusCB);
132 bc().addReadOnly(headerBorderAboveCB);
133 bc().addReadOnly(headerBorderBelowCB);
134 bc().addReadOnly(firstheaderStatusCB);
135 bc().addReadOnly(firstheaderBorderAboveCB);
136 bc().addReadOnly(firstheaderBorderBelowCB);
137 bc().addReadOnly(firstheaderNoContentsCB);
138 bc().addReadOnly(footerStatusCB);
139 bc().addReadOnly(footerBorderAboveCB);
140 bc().addReadOnly(footerBorderBelowCB);
141 bc().addReadOnly(lastfooterStatusCB);
142 bc().addReadOnly(lastfooterBorderAboveCB);
143 bc().addReadOnly(lastfooterBorderBelowCB);
144 bc().addReadOnly(lastfooterNoContentsCB);
145 bc().addReadOnly(newpageCB);
147 // initialize the length validator
148 bc().addCheckedLineEdit(widthED, fixedWidthColLA);
149 bc().addCheckedLineEdit(topspaceED, topspaceLA);
150 bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA);
151 bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA);
155 GuiTabular::~GuiTabular()
160 void GuiTabular::change_adaptor()
166 void GuiTabular::booktabsChanged(bool)
169 booktabs(booktabsRB->isChecked());
174 void GuiTabular::topspace_changed()
176 switch (topspaceCO->currentIndex()) {
178 set(Tabular::SET_TOP_SPACE, "");
179 topspaceED->setEnabled(false);
180 topspaceUnit->setEnabled(false);
184 set(Tabular::SET_TOP_SPACE, "default");
185 topspaceED->setEnabled(false);
186 topspaceUnit->setEnabled(false);
190 if (!topspaceED->text().isEmpty())
191 set(Tabular::SET_TOP_SPACE,
192 widgetsToLength(topspaceED, topspaceUnit));
193 if (!bc().policy().isReadOnly()) {
194 topspaceED->setEnabled(true);
195 topspaceUnit->setEnabled(true);
204 void GuiTabular::bottomspace_changed()
206 switch (bottomspaceCO->currentIndex()) {
208 set(Tabular::SET_BOTTOM_SPACE, "");
209 bottomspaceED->setEnabled(false);
210 bottomspaceUnit->setEnabled(false);
214 set(Tabular::SET_BOTTOM_SPACE, "default");
215 bottomspaceED->setEnabled(false);
216 bottomspaceUnit->setEnabled(false);
220 if (!bottomspaceED->text().isEmpty())
221 set(Tabular::SET_BOTTOM_SPACE,
222 widgetsToLength(bottomspaceED, bottomspaceUnit));
223 if (!bc().policy().isReadOnly()) {
224 bottomspaceED->setEnabled(true);
225 bottomspaceUnit->setEnabled(true);
234 void GuiTabular::interlinespace_changed()
236 switch (interlinespaceCO->currentIndex()) {
238 set(Tabular::SET_INTERLINE_SPACE, "");
239 interlinespaceED->setEnabled(false);
240 interlinespaceUnit->setEnabled(false);
244 set(Tabular::SET_INTERLINE_SPACE, "default");
245 interlinespaceED->setEnabled(false);
246 interlinespaceUnit->setEnabled(false);
250 if (!interlinespaceED->text().isEmpty())
251 set(Tabular::SET_INTERLINE_SPACE,
252 widgetsToLength(interlinespaceED, interlinespaceUnit));
253 if (!bc().policy().isReadOnly()) {
254 interlinespaceED->setEnabled(true);
255 interlinespaceUnit->setEnabled(true);
264 void GuiTabular::close_clicked()
271 void GuiTabular::borderSet_clicked()
273 set(Tabular::SET_ALL_LINES);
279 void GuiTabular::borderUnset_clicked()
281 set(Tabular::UNSET_ALL_LINES);
287 void GuiTabular::leftBorder_changed()
289 set(Tabular::TOGGLE_LINE_LEFT);
294 void GuiTabular::rightBorder_changed()
296 set(Tabular::TOGGLE_LINE_RIGHT);
301 void GuiTabular::topBorder_changed()
303 set(Tabular::TOGGLE_LINE_TOP);
308 void GuiTabular::bottomBorder_changed()
310 set(Tabular::TOGGLE_LINE_BOTTOM);
315 void GuiTabular::specialAlignment_changed()
317 string special = fromqstr(specialAlignmentED->text());
323 void GuiTabular::width_changed()
326 string const width = widgetsToLength(widthED, widthUnit);
331 void GuiTabular::multicolumn_clicked()
338 void GuiTabular::rotateTabular()
340 rotateTabular(rotateTabularCB->isChecked());
345 void GuiTabular::rotateCell()
347 rotateCell(rotateCellCB->isChecked());
352 void GuiTabular::hAlign_changed(int align)
354 GuiTabular::HALIGN h = GuiTabular::LEFT;
357 case 0: h = GuiTabular::LEFT; break;
358 case 1: h = GuiTabular::CENTER; break;
359 case 2: h = GuiTabular::RIGHT; break;
360 case 3: h = GuiTabular::BLOCK; break;
367 void GuiTabular::vAlign_changed(int align)
369 GuiTabular::VALIGN v = GuiTabular::TOP;
372 case 0: v = GuiTabular::TOP; break;
373 case 1: v = GuiTabular::MIDDLE; break;
374 case 2: v = GuiTabular::BOTTOM; break;
381 void GuiTabular::longTabular()
383 longTabular(longTabularCB->isChecked());
388 void GuiTabular::ltNewpage_clicked()
390 set(Tabular::SET_LTNEWPAGE);
395 void GuiTabular::on_captionStatusCB_toggled()
397 set(Tabular::TOGGLE_LTCAPTION);
402 void GuiTabular::ltHeaderStatus_clicked()
404 bool enable = headerStatusCB->isChecked();
406 set(Tabular::SET_LTHEAD, "");
408 set(Tabular::UNSET_LTHEAD, "");
409 headerBorderAboveCB->setEnabled(enable);
410 headerBorderBelowCB->setEnabled(enable);
411 firstheaderNoContentsCB->setEnabled(enable);
416 void GuiTabular::ltHeaderBorderAbove_clicked()
418 if (headerBorderAboveCB->isChecked())
419 set(Tabular::SET_LTHEAD, "dl_above");
421 set(Tabular::UNSET_LTHEAD, "dl_above");
426 void GuiTabular::ltHeaderBorderBelow_clicked()
428 if (headerBorderBelowCB->isChecked())
429 set(Tabular::SET_LTHEAD, "dl_below");
431 set(Tabular::UNSET_LTHEAD, "dl_below");
436 void GuiTabular::ltFirstHeaderBorderAbove_clicked()
438 if (firstheaderBorderAboveCB->isChecked())
439 set(Tabular::SET_LTFIRSTHEAD, "dl_above");
441 set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
446 void GuiTabular::ltFirstHeaderBorderBelow_clicked()
448 if (firstheaderBorderBelowCB->isChecked())
449 set(Tabular::SET_LTFIRSTHEAD, "dl_below");
451 set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
456 void GuiTabular::ltFirstHeaderStatus_clicked()
458 bool enable = firstheaderStatusCB->isChecked();
460 set(Tabular::SET_LTFIRSTHEAD, "");
462 set(Tabular::UNSET_LTFIRSTHEAD, "");
463 firstheaderBorderAboveCB->setEnabled(enable);
464 firstheaderBorderBelowCB->setEnabled(enable);
469 void GuiTabular::ltFirstHeaderEmpty_clicked()
471 bool enable = firstheaderNoContentsCB->isChecked();
473 set(Tabular::SET_LTFIRSTHEAD, "empty");
475 set(Tabular::UNSET_LTFIRSTHEAD, "empty");
476 firstheaderStatusCB->setEnabled(!enable);
477 firstheaderBorderAboveCB->setEnabled(!enable);
478 firstheaderBorderBelowCB->setEnabled(!enable);
483 void GuiTabular::ltFooterStatus_clicked()
485 bool enable = footerStatusCB->isChecked();
487 set(Tabular::SET_LTFOOT, "");
489 set(Tabular::UNSET_LTFOOT, "");
490 footerBorderAboveCB->setEnabled(enable);
491 footerBorderBelowCB->setEnabled(enable);
492 lastfooterNoContentsCB->setEnabled(enable);
497 void GuiTabular::ltFooterBorderAbove_clicked()
499 if (footerBorderAboveCB->isChecked())
500 set(Tabular::SET_LTFOOT, "dl_above");
502 set(Tabular::UNSET_LTFOOT, "dl_above");
507 void GuiTabular::ltFooterBorderBelow_clicked()
509 if (footerBorderBelowCB->isChecked())
510 set(Tabular::SET_LTFOOT, "dl_below");
512 set(Tabular::UNSET_LTFOOT, "dl_below");
517 void GuiTabular::ltLastFooterStatus_clicked()
519 bool enable = lastfooterStatusCB->isChecked();
521 set(Tabular::SET_LTLASTFOOT, "");
523 set(Tabular::UNSET_LTLASTFOOT, "");
524 lastfooterBorderAboveCB->setEnabled(enable);
525 lastfooterBorderBelowCB->setEnabled(enable);
530 void GuiTabular::ltLastFooterBorderAbove_clicked()
532 if (lastfooterBorderAboveCB->isChecked())
533 set(Tabular::SET_LTLASTFOOT, "dl_above");
535 set(Tabular::UNSET_LTLASTFOOT, "dl_above");
540 void GuiTabular::ltLastFooterBorderBelow_clicked()
542 if (lastfooterBorderBelowCB->isChecked())
543 set(Tabular::SET_LTLASTFOOT, "dl_below");
545 set(Tabular::UNSET_LTLASTFOOT, "dl_below");
550 void GuiTabular::ltLastFooterEmpty_clicked()
552 bool enable = lastfooterNoContentsCB->isChecked();
554 set(Tabular::SET_LTLASTFOOT, "empty");
556 set(Tabular::UNSET_LTLASTFOOT, "empty");
557 lastfooterStatusCB->setEnabled(!enable);
558 lastfooterBorderAboveCB->setEnabled(!enable);
559 lastfooterBorderBelowCB->setEnabled(!enable);
564 void GuiTabular::update_borders()
566 Tabular::idx_type const cell = getActiveCell();
567 borders->setTop(tabular_.topLine(cell));
568 borders->setBottom(tabular_.bottomLine(cell));
569 borders->setLeft(tabular_.leftLine(cell));
570 borders->setRight(tabular_.rightLine(cell));
571 // repaint the setborder widget
578 Length getColumnPWidth(Tabular const & t, size_t cell)
580 return t.column_info[t.cellColumn(cell)].p_width;
584 Length getMColumnPWidth(Tabular const & t, size_t cell)
586 if (t.isMultiColumn(cell))
587 return t.cellInfo(cell).p_width;
592 docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
594 if (what == Tabular::SET_SPECIAL_MULTI)
595 return t.cellInfo(cell).align_special;
596 return t.column_info[t.cellColumn(cell)].align_special;
603 void GuiTabular::updateContents()
605 initialiseParams(string());
607 size_t const cell = getActiveCell();
609 Tabular::row_type const row = tabular_.cellRow(cell);
610 Tabular::col_type const col = tabular_.cellColumn(cell);
612 tabularRowED->setText(QString::number(row + 1));
613 tabularColumnED->setText(QString::number(col + 1));
615 bool const multicol(tabular_.isMultiColumn(cell));
617 multicolumnCB->setChecked(multicol);
619 rotateCellCB->setChecked(tabular_.getRotateCell(cell));
620 rotateTabularCB->setChecked(tabular_.rotate);
622 longTabularCB->setChecked(tabular_.is_long_tabular);
630 special = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_MULTI);
631 pwidth = getMColumnPWidth(tabular_, cell);
633 special = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_COLUMN);
634 pwidth = getColumnPWidth(tabular_, cell);
637 specialAlignmentED->setText(toqstr(special));
639 bool const isReadonly = bc().policy().isReadOnly();
640 specialAlignmentED->setEnabled(!isReadonly);
642 Length::UNIT default_unit =
643 useMetricUnits() ? Length::CM : Length::IN;
645 borderDefaultRB->setChecked(!tabular_.use_booktabs);
646 booktabsRB->setChecked(tabular_.use_booktabs);
648 if (tabular_.row_info[row].top_space.empty()
649 && !tabular_.row_info[row].top_space_default) {
650 topspaceCO->setCurrentIndex(0);
651 } else if (tabular_.row_info[row].top_space_default) {
652 topspaceCO->setCurrentIndex(1);
654 topspaceCO->setCurrentIndex(2);
655 lengthToWidgets(topspaceED,
657 tabular_.row_info[row].top_space.asString(),
660 topspaceED->setEnabled(!isReadonly
661 && (topspaceCO->currentIndex() == 2));
662 topspaceUnit->setEnabled(!isReadonly
663 && (topspaceCO->currentIndex() == 2));
664 topspaceCO->setEnabled(!isReadonly);
666 if (tabular_.row_info[row].bottom_space.empty()
667 && !tabular_.row_info[row].bottom_space_default) {
668 bottomspaceCO->setCurrentIndex(0);
669 } else if (tabular_.row_info[row].bottom_space_default) {
670 bottomspaceCO->setCurrentIndex(1);
672 bottomspaceCO->setCurrentIndex(2);
673 lengthToWidgets(bottomspaceED,
675 tabular_.row_info[row].bottom_space.asString(),
678 bottomspaceED->setEnabled(!isReadonly
679 && (bottomspaceCO->currentIndex() == 2));
680 bottomspaceUnit->setEnabled(!isReadonly
681 && (bottomspaceCO->currentIndex() == 2));
682 bottomspaceCO->setEnabled(!isReadonly);
684 if (tabular_.row_info[row].interline_space.empty()
685 && !tabular_.row_info[row].interline_space_default) {
686 interlinespaceCO->setCurrentIndex(0);
687 } else if (tabular_.row_info[row].interline_space_default) {
688 interlinespaceCO->setCurrentIndex(1);
690 interlinespaceCO->setCurrentIndex(2);
691 lengthToWidgets(interlinespaceED,
693 tabular_.row_info[row].interline_space.asString(),
696 interlinespaceED->setEnabled(!isReadonly
697 && (interlinespaceCO->currentIndex() == 2));
698 interlinespaceUnit->setEnabled(!isReadonly
699 && (interlinespaceCO->currentIndex() == 2));
700 interlinespaceCO->setEnabled(!isReadonly);
704 colwidth = pwidth.asString();
705 lengthToWidgets(widthED, widthUnit,
706 colwidth, default_unit);
708 widthED->setEnabled(!isReadonly);
709 widthUnit->setEnabled(!isReadonly);
712 hAlignCB->addItem(qt_("Left"));
713 hAlignCB->addItem(qt_("Center"));
714 hAlignCB->addItem(qt_("Right"));
715 if (!multicol && !pwidth.zero())
716 hAlignCB->addItem(qt_("Justified"));
719 switch (tabular_.getAlignment(cell)) {
723 case LYX_ALIGN_CENTER:
726 case LYX_ALIGN_RIGHT:
729 case LYX_ALIGN_BLOCK:
731 if (!multicol && !pwidth.zero())
739 hAlignCB->setCurrentIndex(align);
742 switch (tabular_.getVAlignment(cell)) {
743 case Tabular::LYX_VALIGN_TOP:
746 case Tabular::LYX_VALIGN_MIDDLE:
749 case Tabular::LYX_VALIGN_BOTTOM:
758 vAlignCB->setCurrentIndex(valign);
760 hAlignCB->setEnabled(true);
761 vAlignCB->setEnabled(!pwidth.zero());
763 if (!tabular_.is_long_tabular) {
764 headerStatusCB->setChecked(false);
765 headerBorderAboveCB->setChecked(false);
766 headerBorderBelowCB->setChecked(false);
767 firstheaderStatusCB->setChecked(false);
768 firstheaderBorderAboveCB->setChecked(false);
769 firstheaderBorderBelowCB->setChecked(false);
770 firstheaderNoContentsCB->setChecked(false);
771 footerStatusCB->setChecked(false);
772 footerBorderAboveCB->setChecked(false);
773 footerBorderBelowCB->setChecked(false);
774 lastfooterStatusCB->setChecked(false);
775 lastfooterBorderAboveCB->setChecked(false);
776 lastfooterBorderBelowCB->setChecked(false);
777 lastfooterNoContentsCB->setChecked(false);
778 newpageCB->setChecked(false);
779 newpageCB->setEnabled(false);
780 captionStatusCB->blockSignals(true);
781 captionStatusCB->setChecked(false);
782 captionStatusCB->blockSignals(false);
785 captionStatusCB->blockSignals(true);
786 captionStatusCB->setChecked(tabular_.ltCaption(row));
787 captionStatusCB->blockSignals(false);
791 bool row_set = tabular_.getRowOfLTHead(row, ltt);
792 headerStatusCB->setChecked(row_set);
794 headerBorderAboveCB->setChecked(ltt.topDL);
795 headerBorderBelowCB->setChecked(ltt.bottomDL);
798 headerBorderAboveCB->setChecked(false);
799 headerBorderBelowCB->setChecked(false);
800 headerBorderAboveCB->setEnabled(false);
801 headerBorderBelowCB->setEnabled(false);
802 firstheaderNoContentsCB->setChecked(false);
803 firstheaderNoContentsCB->setEnabled(false);
807 row_set = tabular_.getRowOfLTFirstHead(row, ltt);
808 firstheaderStatusCB->setChecked(row_set);
809 if (ltt.set && (!ltt.empty || !use_empty)) {
810 firstheaderBorderAboveCB->setChecked(ltt.topDL);
811 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
813 firstheaderBorderAboveCB->setEnabled(false);
814 firstheaderBorderBelowCB->setEnabled(false);
815 firstheaderBorderAboveCB->setChecked(false);
816 firstheaderBorderBelowCB->setChecked(false);
818 firstheaderNoContentsCB->setChecked(ltt.empty);
820 firstheaderStatusCB->setEnabled(false);
824 row_set = tabular_.getRowOfLTFoot(row, ltt);
825 footerStatusCB->setChecked(row_set);
827 footerBorderAboveCB->setChecked(ltt.topDL);
828 footerBorderBelowCB->setChecked(ltt.bottomDL);
831 footerBorderAboveCB->setChecked(false);
832 footerBorderBelowCB->setChecked(false);
833 footerBorderAboveCB->setEnabled(false);
834 footerBorderBelowCB->setEnabled(false);
835 lastfooterNoContentsCB->setChecked(false);
836 lastfooterNoContentsCB->setEnabled(false);
840 row_set = tabular_.getRowOfLTLastFoot(row, ltt);
841 lastfooterStatusCB->setChecked(row_set);
842 if (ltt.set && (!ltt.empty || !use_empty)) {
843 lastfooterBorderAboveCB->setChecked(ltt.topDL);
844 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
846 lastfooterBorderAboveCB->setEnabled(false);
847 lastfooterBorderBelowCB->setEnabled(false);
848 lastfooterBorderAboveCB->setChecked(false);
849 lastfooterBorderBelowCB->setChecked(false);
851 lastfooterNoContentsCB->setChecked(ltt.empty);
853 lastfooterStatusCB->setEnabled(false);
856 newpageCB->setChecked(tabular_.getLTNewPage(row));
860 void GuiTabular::closeGUI()
862 // ugly hack to auto-apply the stuff that hasn't been
863 // yet. don't let this continue to exist ...
865 // Subtle here, we must /not/ apply any changes and
866 // then refer to tabular, as it will have been freed
867 // since the changes update the actual tabular_
869 // apply the fixed width values
870 size_t const cell = getActiveCell();
871 bool const multicol = tabular_.isMultiColumn(cell);
872 string width = widgetsToLength(widthED, widthUnit);
875 Length llen = getColumnPWidth(tabular_, cell);
876 Length llenMulti = getMColumnPWidth(tabular_, cell);
878 if (multicol && !llenMulti.zero())
879 width2 = llenMulti.asString();
880 else if (!multicol && !llen.zero())
881 width2 = llen.asString();
883 // apply the special alignment
884 docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text());
888 sa2 = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_MULTI);
890 sa2 = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_COLUMN);
894 set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
896 set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
899 if (width != width2) {
901 set(Tabular::SET_MPWIDTH, width);
903 set(Tabular::SET_PWIDTH, width);
907 switch (topspaceCO->currentIndex()) {
909 set(Tabular::SET_TOP_SPACE, "");
912 set(Tabular::SET_TOP_SPACE, "default");
915 set(Tabular::SET_TOP_SPACE,
916 widgetsToLength(topspaceED, topspaceUnit));
920 switch (bottomspaceCO->currentIndex()) {
922 set(Tabular::SET_BOTTOM_SPACE, "");
925 set(Tabular::SET_BOTTOM_SPACE, "default");
928 set(Tabular::SET_BOTTOM_SPACE,
929 widgetsToLength(bottomspaceED, bottomspaceUnit));
933 switch (interlinespaceCO->currentIndex()) {
935 set(Tabular::SET_INTERLINE_SPACE, "");
938 set(Tabular::SET_INTERLINE_SPACE, "default");
941 set(Tabular::SET_INTERLINE_SPACE,
942 widgetsToLength(interlinespaceED, interlinespaceUnit));
949 bool GuiTabular::initialiseParams(string const & data)
951 // try to get the current cell
952 BufferView const * const bv = bufferview();
953 InsetTabular const * current_inset = 0;
955 Cursor const & cur = bv->cursor();
956 // get the innermost tabular inset;
957 // assume that it is "ours"
958 for (int i = cur.depth() - 1; i >= 0; --i)
959 if (cur[i].inset().lyxCode() == TABULAR_CODE) {
960 current_inset = static_cast<InsetTabular const *>(&cur[i].inset());
961 active_cell_ = cur[i].idx();
966 if (current_inset && data.empty()) {
967 tabular_ = Tabular(current_inset->tabular);
971 InsetTabular tmp(const_cast<Buffer &>(buffer()));
972 InsetTabular::string2params(data, tmp);
973 tabular_ = Tabular(tmp.tabular);
978 void GuiTabular::clearParams()
980 InsetTabular tmp(const_cast<Buffer &>(buffer()));
981 tabular_ = tmp.tabular;
982 active_cell_ = Tabular::npos;
986 Tabular::idx_type GuiTabular::getActiveCell() const
992 void GuiTabular::set(Tabular::Feature f, string const & arg)
994 string const data = featureAsString(f) + ' ' + arg;
995 dispatch(FuncRequest(getLfun(), data));
999 bool GuiTabular::useMetricUnits() const
1001 return lyxrc.default_papersize > PAPER_USEXECUTIVE;
1005 void GuiTabular::setSpecial(string const & special)
1007 if (tabular_.isMultiColumn(getActiveCell()))
1008 set(Tabular::SET_SPECIAL_MULTI, special);
1010 set(Tabular::SET_SPECIAL_COLUMN, special);
1014 void GuiTabular::setWidth(string const & width)
1016 if (tabular_.isMultiColumn(getActiveCell()))
1017 set(Tabular::SET_MPWIDTH, width);
1019 set(Tabular::SET_PWIDTH, width);
1025 void GuiTabular::toggleMultiColumn()
1027 set(Tabular::MULTICOLUMN);
1032 void GuiTabular::rotateTabular(bool yes)
1035 set(Tabular::SET_ROTATE_TABULAR);
1037 set(Tabular::UNSET_ROTATE_TABULAR);
1041 void GuiTabular::rotateCell(bool yes)
1044 set(Tabular::SET_ROTATE_CELL);
1046 set(Tabular::UNSET_ROTATE_CELL);
1050 void GuiTabular::halign(GuiTabular::HALIGN h)
1052 Tabular::Feature num = Tabular::ALIGN_LEFT;
1053 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
1057 num = Tabular::ALIGN_LEFT;
1058 multi_num = Tabular::M_ALIGN_LEFT;
1061 num = Tabular::ALIGN_CENTER;
1062 multi_num = Tabular::M_ALIGN_CENTER;
1065 num = Tabular::ALIGN_RIGHT;
1066 multi_num = Tabular::M_ALIGN_RIGHT;
1069 num = Tabular::ALIGN_BLOCK;
1070 //multi_num: no equivalent
1074 if (tabular_.isMultiColumn(getActiveCell()))
1081 void GuiTabular::valign(GuiTabular::VALIGN v)
1083 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
1084 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
1088 num = Tabular::VALIGN_TOP;
1089 multi_num = Tabular::M_VALIGN_TOP;
1092 num = Tabular::VALIGN_MIDDLE;
1093 multi_num = Tabular::M_VALIGN_MIDDLE;
1096 num = Tabular::VALIGN_BOTTOM;
1097 multi_num = Tabular::M_VALIGN_BOTTOM;
1101 if (tabular_.isMultiColumn(getActiveCell()))
1108 void GuiTabular::booktabs(bool yes)
1111 set(Tabular::SET_BOOKTABS);
1113 set(Tabular::UNSET_BOOKTABS);
1117 void GuiTabular::longTabular(bool yes)
1120 set(Tabular::SET_LONGTABULAR);
1122 set(Tabular::UNSET_LONGTABULAR);
1126 Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); }
1129 } // namespace frontend
1132 #include "moc_GuiTabular.cpp"