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 "GuiSetBorder.h"
20 #include "LengthCombo.h"
21 #include "qt_helpers.h"
22 #include "Validator.h"
24 #include "BufferView.h"
26 #include "FuncRequest.h"
27 #include "FuncStatus.h"
30 #include "insets/InsetTabular.h"
33 #include <QPushButton>
34 #include <QRadioButton>
42 GuiTabular::GuiTabular(GuiView & lv)
43 : GuiDialog(lv, "tabular", qt_("Table Settings")),
44 // tabular_ is initialised at dialog construction in initialiseParams()
45 tabular_(*lv.buffer(), 0, 0)
47 active_cell_ = Tabular::npos;
51 widthED->setValidator(unsignedLengthValidator(widthED));
52 topspaceED->setValidator(new LengthValidator(topspaceED));
53 bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
54 interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
56 connect(topspaceED, SIGNAL(returnPressed()),
57 this, SLOT(topspace_changed()));
58 connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
59 this, SLOT(topspace_changed()));
60 connect(topspaceCO, SIGNAL(activated(int)),
61 this, SLOT(topspace_changed()));
62 connect(bottomspaceED, SIGNAL(returnPressed()),
63 this, SLOT(bottomspace_changed()));
64 connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
65 this, SLOT(bottomspace_changed()));
66 connect(bottomspaceCO, SIGNAL(activated(int)),
67 this, SLOT(bottomspace_changed()));
68 connect(interlinespaceED, SIGNAL(returnPressed()),
69 this, SLOT(interlinespace_changed()));
70 connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
71 this, SLOT(interlinespace_changed()));
72 connect(interlinespaceCO, SIGNAL(activated(int)),
73 this, SLOT(interlinespace_changed()));
74 connect(booktabsRB, SIGNAL(clicked(bool)),
75 this, SLOT(booktabsChanged(bool)));
76 connect(borderDefaultRB, SIGNAL(clicked(bool)),
77 this, SLOT(booktabsChanged(bool)));
78 connect(borderSetPB, SIGNAL(clicked()),
79 this, SLOT(borderSet_clicked()));
80 connect(borderUnsetPB, SIGNAL(clicked()),
81 this, SLOT(borderUnset_clicked()));
82 connect(longTabularCB, SIGNAL(toggled(bool)),
83 longtableGB, SLOT(setEnabled(bool)));
84 connect(longTabularCB, SIGNAL(toggled(bool)),
85 newpageCB, SLOT(setEnabled(bool)));
86 connect(longTabularCB, SIGNAL(toggled(bool)),
87 alignmentGB, SLOT(setEnabled(bool)));
88 // longtables cannot have a vertical alignment
89 connect(longTabularCB, SIGNAL(toggled(bool)),
90 TableAlignCB, SLOT(setDisabled(bool)));
91 connect(hAlignCB, SIGNAL(activated(int)),
92 this, SLOT(hAlign_changed(int)));
93 connect(vAlignCB, SIGNAL(activated(int)),
94 this, SLOT(vAlign_changed(int)));
95 connect(multicolumnCB, SIGNAL(clicked()),
96 this, SLOT(multicolumn_clicked()));
97 connect(newpageCB, SIGNAL(clicked()),
98 this, SLOT(ltNewpage_clicked()));
99 connect(headerStatusCB, SIGNAL(clicked()),
100 this, SLOT(ltHeaderStatus_clicked()));
101 connect(headerBorderAboveCB, SIGNAL(clicked()),
102 this, SLOT(ltHeaderBorderAbove_clicked()));
103 connect(headerBorderBelowCB, SIGNAL(clicked()),
104 this, SLOT(ltHeaderBorderBelow_clicked()));
105 connect(firstheaderStatusCB, SIGNAL(clicked()),
106 this, SLOT(ltFirstHeaderStatus_clicked()));
107 connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
108 this, SLOT(ltFirstHeaderBorderAbove_clicked()));
109 connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
110 this, SLOT(ltFirstHeaderBorderBelow_clicked()));
111 connect(firstheaderNoContentsCB, SIGNAL(clicked()),
112 this, SLOT(ltFirstHeaderEmpty_clicked()));
113 connect(footerStatusCB, SIGNAL(clicked()),
114 this, SLOT(ltFooterStatus_clicked()));
115 connect(footerBorderAboveCB, SIGNAL(clicked()),
116 this, SLOT(ltFooterBorderAbove_clicked()));
117 connect(footerBorderBelowCB, SIGNAL(clicked()),
118 this, SLOT(ltFooterBorderBelow_clicked()));
119 connect(lastfooterStatusCB, SIGNAL(clicked()),
120 this, SLOT(ltLastFooterStatus_clicked()));
121 connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
122 this, SLOT(ltLastFooterBorderAbove_clicked()));
123 connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
124 this, SLOT(ltLastFooterBorderBelow_clicked()));
125 connect(lastfooterNoContentsCB, SIGNAL(clicked()),
126 this, SLOT(ltLastFooterEmpty_clicked()));
127 connect(specialAlignmentED, SIGNAL(returnPressed()),
128 this, SLOT(specialAlignment_changed()));
129 connect(widthED, SIGNAL(editingFinished()),
130 this, SLOT(width_changed()));
131 connect(widthUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
132 this, SLOT(width_changed()));
133 connect(closePB, SIGNAL(clicked()),
134 this, SLOT(close_clicked()));
135 connect(borders, SIGNAL(topSet(bool)),
136 this, SLOT(topBorder_changed()));
137 connect(borders, SIGNAL(bottomSet(bool)),
138 this, SLOT(bottomBorder_changed()));
139 connect(borders, SIGNAL(rightSet(bool)),
140 this, SLOT(rightBorder_changed()));
141 connect(borders, SIGNAL(leftSet(bool)),
142 this, SLOT(leftBorder_changed()));
143 connect(rotateTabularCB, SIGNAL(clicked()),
144 this, SLOT(rotateTabular()));
145 connect(rotateCellCB, SIGNAL(clicked()),
146 this, SLOT(rotateCell()));
147 connect(TableAlignCB, SIGNAL(activated(int)),
148 this, SLOT(tableAlignment_changed(int)));
149 connect(longTabularCB, SIGNAL(clicked()),
150 this, SLOT(longTabular()));
151 connect(leftRB, SIGNAL(clicked()),
152 this, SLOT(ltAlignment_clicked()));
153 connect(centerRB, SIGNAL(clicked()),
154 this, SLOT(ltAlignment_clicked()));
155 connect(rightRB, SIGNAL(clicked()),
156 this, SLOT(ltAlignment_clicked()));
158 bc().setPolicy(ButtonPolicy::IgnorantPolicy);
160 bc().addReadOnly(topspaceED);
161 bc().addReadOnly(topspaceUnit);
162 bc().addReadOnly(topspaceCO);
163 bc().addReadOnly(bottomspaceED);
164 bc().addReadOnly(bottomspaceUnit);
165 bc().addReadOnly(bottomspaceCO);
166 bc().addReadOnly(interlinespaceED);
167 bc().addReadOnly(interlinespaceUnit);
168 bc().addReadOnly(interlinespaceCO);
169 bc().addReadOnly(borderDefaultRB);
170 bc().addReadOnly(booktabsRB);
172 bc().addReadOnly(multicolumnCB);
173 bc().addReadOnly(rotateCellCB);
174 bc().addReadOnly(rotateTabularCB);
175 bc().addReadOnly(specialAlignmentED);
176 bc().addReadOnly(widthED);
177 bc().addReadOnly(widthUnitCB);
178 bc().addReadOnly(hAlignCB);
179 bc().addReadOnly(vAlignCB);
180 bc().addReadOnly(TableAlignCB);
181 bc().addReadOnly(borderSetPB);
182 bc().addReadOnly(borderUnsetPB);
183 bc().addReadOnly(borders);
184 bc().addReadOnly(longTabularCB);
185 bc().addReadOnly(headerStatusCB);
186 bc().addReadOnly(headerBorderAboveCB);
187 bc().addReadOnly(headerBorderBelowCB);
188 bc().addReadOnly(firstheaderStatusCB);
189 bc().addReadOnly(firstheaderBorderAboveCB);
190 bc().addReadOnly(firstheaderBorderBelowCB);
191 bc().addReadOnly(firstheaderNoContentsCB);
192 bc().addReadOnly(footerStatusCB);
193 bc().addReadOnly(footerBorderAboveCB);
194 bc().addReadOnly(footerBorderBelowCB);
195 bc().addReadOnly(lastfooterStatusCB);
196 bc().addReadOnly(lastfooterBorderAboveCB);
197 bc().addReadOnly(lastfooterBorderBelowCB);
198 bc().addReadOnly(lastfooterNoContentsCB);
199 bc().addReadOnly(newpageCB);
200 bc().addReadOnly(leftRB);
201 bc().addReadOnly(centerRB);
202 bc().addReadOnly(rightRB);
204 // initialize the length validator
205 bc().addCheckedLineEdit(widthED, fixedWidthColLA);
206 bc().addCheckedLineEdit(topspaceED, topspaceLA);
207 bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA);
208 bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA);
212 GuiTabular::~GuiTabular()
217 void GuiTabular::change_adaptor()
223 void GuiTabular::booktabsChanged(bool)
226 booktabs(booktabsRB->isChecked());
231 void GuiTabular::topspace_changed()
233 switch (topspaceCO->currentIndex()) {
235 set(Tabular::SET_TOP_SPACE, "");
236 topspaceED->setEnabled(false);
237 topspaceUnit->setEnabled(false);
241 set(Tabular::SET_TOP_SPACE, "default");
242 topspaceED->setEnabled(false);
243 topspaceUnit->setEnabled(false);
247 if (!topspaceED->text().isEmpty())
248 set(Tabular::SET_TOP_SPACE,
249 widgetsToLength(topspaceED,
251 if (!bc().policy().isReadOnly()) {
252 topspaceED->setEnabled(true);
253 topspaceUnit->setEnabled(true);
262 void GuiTabular::bottomspace_changed()
264 switch (bottomspaceCO->currentIndex()) {
266 set(Tabular::SET_BOTTOM_SPACE, "");
267 bottomspaceED->setEnabled(false);
268 bottomspaceUnit->setEnabled(false);
272 set(Tabular::SET_BOTTOM_SPACE, "default");
273 bottomspaceED->setEnabled(false);
274 bottomspaceUnit->setEnabled(false);
278 if (!bottomspaceED->text().isEmpty())
279 set(Tabular::SET_BOTTOM_SPACE,
280 widgetsToLength(bottomspaceED,
282 if (!bc().policy().isReadOnly()) {
283 bottomspaceED->setEnabled(true);
284 bottomspaceUnit->setEnabled(true);
293 void GuiTabular::interlinespace_changed()
295 switch (interlinespaceCO->currentIndex()) {
297 set(Tabular::SET_INTERLINE_SPACE, "");
298 interlinespaceED->setEnabled(false);
299 interlinespaceUnit->setEnabled(false);
303 set(Tabular::SET_INTERLINE_SPACE, "default");
304 interlinespaceED->setEnabled(false);
305 interlinespaceUnit->setEnabled(false);
309 if (!interlinespaceED->text().isEmpty())
310 set(Tabular::SET_INTERLINE_SPACE,
311 widgetsToLength(interlinespaceED,
312 interlinespaceUnit));
313 if (!bc().policy().isReadOnly()) {
314 interlinespaceED->setEnabled(true);
315 interlinespaceUnit->setEnabled(true);
324 void GuiTabular::close_clicked()
331 void GuiTabular::borderSet_clicked()
333 set(Tabular::SET_ALL_LINES);
339 void GuiTabular::borderUnset_clicked()
341 set(Tabular::UNSET_ALL_LINES);
347 void GuiTabular::leftBorder_changed()
349 set(Tabular::TOGGLE_LINE_LEFT);
354 void GuiTabular::rightBorder_changed()
356 set(Tabular::TOGGLE_LINE_RIGHT);
361 void GuiTabular::topBorder_changed()
363 set(Tabular::TOGGLE_LINE_TOP);
368 void GuiTabular::bottomBorder_changed()
370 set(Tabular::TOGGLE_LINE_BOTTOM);
375 void GuiTabular::specialAlignment_changed()
377 string special = fromqstr(specialAlignmentED->text());
383 void GuiTabular::width_changed()
386 string const width = widgetsToLength(widthED, widthUnitCB);
391 void GuiTabular::multicolumn_clicked()
398 void GuiTabular::rotateTabular()
400 rotateTabular(rotateTabularCB->isChecked());
405 void GuiTabular::rotateCell()
407 rotateCell(rotateCellCB->isChecked());
412 void GuiTabular::hAlign_changed(int align)
414 GuiTabular::HALIGN h = GuiTabular::LEFT;
417 case 0: h = GuiTabular::LEFT; break;
418 case 1: h = GuiTabular::CENTER; break;
419 case 2: h = GuiTabular::RIGHT; break;
420 case 3: h = GuiTabular::BLOCK; break;
427 void GuiTabular::vAlign_changed(int align)
429 GuiTabular::VALIGN v = GuiTabular::TOP;
432 case 0: v = GuiTabular::TOP; break;
433 case 1: v = GuiTabular::MIDDLE; break;
434 case 2: v = GuiTabular::BOTTOM; break;
441 void GuiTabular::tableAlignment_changed(int align)
444 case 0: set(Tabular::TABULAR_VALIGN_TOP);
446 case 1: set(Tabular::TABULAR_VALIGN_MIDDLE);
448 case 2: set(Tabular::TABULAR_VALIGN_BOTTOM);
454 void GuiTabular::longTabular()
456 longTabular(longTabularCB->isChecked());
461 void GuiTabular::ltNewpage_clicked()
463 set(Tabular::SET_LTNEWPAGE);
468 void GuiTabular::on_captionStatusCB_toggled()
470 set(Tabular::TOGGLE_LTCAPTION);
475 void GuiTabular::ltHeaderStatus_clicked()
477 bool enable = headerStatusCB->isChecked();
479 set(Tabular::SET_LTHEAD, "");
481 set(Tabular::UNSET_LTHEAD, "");
486 void GuiTabular::ltHeaderBorderAbove_clicked()
488 if (headerBorderAboveCB->isChecked())
489 set(Tabular::SET_LTHEAD, "dl_above");
491 set(Tabular::UNSET_LTHEAD, "dl_above");
496 void GuiTabular::ltHeaderBorderBelow_clicked()
498 if (headerBorderBelowCB->isChecked())
499 set(Tabular::SET_LTHEAD, "dl_below");
501 set(Tabular::UNSET_LTHEAD, "dl_below");
506 void GuiTabular::ltFirstHeaderBorderAbove_clicked()
508 if (firstheaderBorderAboveCB->isChecked())
509 set(Tabular::SET_LTFIRSTHEAD, "dl_above");
511 set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
516 void GuiTabular::ltFirstHeaderBorderBelow_clicked()
518 if (firstheaderBorderBelowCB->isChecked())
519 set(Tabular::SET_LTFIRSTHEAD, "dl_below");
521 set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
526 void GuiTabular::ltFirstHeaderStatus_clicked()
528 bool enable = firstheaderStatusCB->isChecked();
530 set(Tabular::SET_LTFIRSTHEAD, "");
532 set(Tabular::UNSET_LTFIRSTHEAD, "");
537 void GuiTabular::ltFirstHeaderEmpty_clicked()
539 bool enable = firstheaderNoContentsCB->isChecked();
541 set(Tabular::SET_LTFIRSTHEAD, "empty");
543 set(Tabular::UNSET_LTFIRSTHEAD, "empty");
548 void GuiTabular::ltFooterStatus_clicked()
550 bool enable = footerStatusCB->isChecked();
552 set(Tabular::SET_LTFOOT, "");
554 set(Tabular::UNSET_LTFOOT, "");
559 void GuiTabular::ltFooterBorderAbove_clicked()
561 if (footerBorderAboveCB->isChecked())
562 set(Tabular::SET_LTFOOT, "dl_above");
564 set(Tabular::UNSET_LTFOOT, "dl_above");
569 void GuiTabular::ltFooterBorderBelow_clicked()
571 if (footerBorderBelowCB->isChecked())
572 set(Tabular::SET_LTFOOT, "dl_below");
574 set(Tabular::UNSET_LTFOOT, "dl_below");
579 void GuiTabular::ltLastFooterStatus_clicked()
581 bool enable = lastfooterStatusCB->isChecked();
583 set(Tabular::SET_LTLASTFOOT, "");
585 set(Tabular::UNSET_LTLASTFOOT, "");
590 void GuiTabular::ltLastFooterBorderAbove_clicked()
592 if (lastfooterBorderAboveCB->isChecked())
593 set(Tabular::SET_LTLASTFOOT, "dl_above");
595 set(Tabular::UNSET_LTLASTFOOT, "dl_above");
600 void GuiTabular::ltLastFooterBorderBelow_clicked()
602 if (lastfooterBorderBelowCB->isChecked())
603 set(Tabular::SET_LTLASTFOOT, "dl_below");
605 set(Tabular::UNSET_LTLASTFOOT, "dl_below");
610 void GuiTabular::ltLastFooterEmpty_clicked()
612 bool enable = lastfooterNoContentsCB->isChecked();
614 set(Tabular::SET_LTLASTFOOT, "empty");
616 set(Tabular::UNSET_LTLASTFOOT, "empty");
621 void GuiTabular::ltAlignment_clicked()
623 if (leftRB->isChecked())
624 set(Tabular::LONGTABULAR_ALIGN_LEFT);
625 else if (centerRB->isChecked())
626 set(Tabular::LONGTABULAR_ALIGN_CENTER);
627 else if (rightRB->isChecked())
628 set(Tabular::LONGTABULAR_ALIGN_RIGHT);
633 void GuiTabular::update_borders()
635 Tabular::idx_type const cell = getActiveCell();
636 borders->setTop(tabular_.topLine(cell));
637 borders->setBottom(tabular_.bottomLine(cell));
638 borders->setLeft(tabular_.leftLine(cell));
639 borders->setRight(tabular_.rightLine(cell));
640 // repaint the setborder widget
647 Length getColumnPWidth(Tabular const & t, size_t cell)
649 return t.column_info[t.cellColumn(cell)].p_width;
653 Length getMColumnPWidth(Tabular const & t, size_t cell)
655 if (t.isMultiColumn(cell))
656 return t.cellInfo(cell).p_width;
661 docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
663 if (what == Tabular::SET_SPECIAL_MULTI)
664 return t.cellInfo(cell).align_special;
665 return t.column_info[t.cellColumn(cell)].align_special;
672 void GuiTabular::updateContents()
674 initialiseParams(string());
676 size_t const cell = getActiveCell();
678 Tabular::row_type const row = tabular_.cellRow(cell);
679 Tabular::col_type const col = tabular_.cellColumn(cell);
681 tabularRowED->setText(QString::number(row + 1));
682 tabularColumnED->setText(QString::number(col + 1));
684 bool const multicol(tabular_.isMultiColumn(cell));
686 multicolumnCB->setChecked(multicol);
688 rotateCellCB->setChecked(tabular_.getRotateCell(cell));
689 rotateTabularCB->setChecked(tabular_.rotate);
691 longTabularCB->setChecked(tabular_.is_long_tabular);
699 special = getAlignSpecial(tabular_, cell,
700 Tabular::SET_SPECIAL_MULTI);
701 pwidth = getMColumnPWidth(tabular_, cell);
703 special = getAlignSpecial(tabular_, cell,
704 Tabular::SET_SPECIAL_COLUMN);
705 pwidth = getColumnPWidth(tabular_, cell);
708 specialAlignmentED->setText(toqstr(special));
710 bool const isReadonly = bc().policy().isReadOnly();
711 specialAlignmentED->setEnabled(!isReadonly);
713 Length::UNIT const default_unit = Length::defaultUnit();
715 borderDefaultRB->setChecked(!tabular_.use_booktabs);
716 booktabsRB->setChecked(tabular_.use_booktabs);
718 if (tabular_.row_info[row].top_space.empty()
719 && !tabular_.row_info[row].top_space_default) {
720 topspaceCO->setCurrentIndex(0);
721 } else if (tabular_.row_info[row].top_space_default) {
722 topspaceCO->setCurrentIndex(1);
724 topspaceCO->setCurrentIndex(2);
725 lengthToWidgets(topspaceED,
727 tabular_.row_info[row].top_space.asString(),
730 topspaceED->setEnabled(!isReadonly
731 && (topspaceCO->currentIndex() == 2));
732 topspaceUnit->setEnabled(!isReadonly
733 && (topspaceCO->currentIndex() == 2));
734 topspaceCO->setEnabled(!isReadonly);
736 if (tabular_.row_info[row].bottom_space.empty()
737 && !tabular_.row_info[row].bottom_space_default) {
738 bottomspaceCO->setCurrentIndex(0);
739 } else if (tabular_.row_info[row].bottom_space_default) {
740 bottomspaceCO->setCurrentIndex(1);
742 bottomspaceCO->setCurrentIndex(2);
743 lengthToWidgets(bottomspaceED,
745 tabular_.row_info[row].bottom_space.asString(),
748 bottomspaceED->setEnabled(!isReadonly
749 && (bottomspaceCO->currentIndex() == 2));
750 bottomspaceUnit->setEnabled(!isReadonly
751 && (bottomspaceCO->currentIndex() == 2));
752 bottomspaceCO->setEnabled(!isReadonly);
754 if (tabular_.row_info[row].interline_space.empty()
755 && !tabular_.row_info[row].interline_space_default) {
756 interlinespaceCO->setCurrentIndex(0);
757 } else if (tabular_.row_info[row].interline_space_default) {
758 interlinespaceCO->setCurrentIndex(1);
760 interlinespaceCO->setCurrentIndex(2);
761 lengthToWidgets(interlinespaceED,
763 tabular_.row_info[row].interline_space.asString(),
766 interlinespaceED->setEnabled(!isReadonly
767 && (interlinespaceCO->currentIndex() == 2));
768 interlinespaceUnit->setEnabled(!isReadonly
769 && (interlinespaceCO->currentIndex() == 2));
770 interlinespaceCO->setEnabled(!isReadonly);
774 colwidth = pwidth.asString();
775 lengthToWidgets(widthED, widthUnitCB,
776 colwidth, default_unit);
778 widthED->setEnabled(!isReadonly);
779 widthUnitCB->setEnabled(!isReadonly);
782 hAlignCB->addItem(qt_("Left"));
783 hAlignCB->addItem(qt_("Center"));
784 hAlignCB->addItem(qt_("Right"));
785 if (!multicol && !pwidth.zero())
786 hAlignCB->addItem(qt_("Justified"));
789 switch (tabular_.getAlignment(cell)) {
793 case LYX_ALIGN_CENTER:
796 case LYX_ALIGN_RIGHT:
799 case LYX_ALIGN_BLOCK:
801 if (!multicol && !pwidth.zero())
809 hAlignCB->setCurrentIndex(align);
812 switch (tabular_.getVAlignment(cell)) {
813 case Tabular::LYX_VALIGN_TOP:
816 case Tabular::LYX_VALIGN_MIDDLE:
819 case Tabular::LYX_VALIGN_BOTTOM:
828 vAlignCB->setCurrentIndex(valign);
830 hAlignCB->setEnabled(true);
831 vAlignCB->setEnabled(!pwidth.zero());
834 switch (tabular_.tabular_valignment) {
835 case Tabular::LYX_VALIGN_TOP:
838 case Tabular::LYX_VALIGN_MIDDLE:
841 case Tabular::LYX_VALIGN_BOTTOM:
848 TableAlignCB->setCurrentIndex(tableValign);
850 if (!tabular_.is_long_tabular) {
851 headerStatusCB->setChecked(false);
852 headerBorderAboveCB->setChecked(false);
853 headerBorderBelowCB->setChecked(false);
854 firstheaderStatusCB->setChecked(false);
855 firstheaderBorderAboveCB->setChecked(false);
856 firstheaderBorderBelowCB->setChecked(false);
857 firstheaderNoContentsCB->setChecked(false);
858 footerStatusCB->setChecked(false);
859 footerBorderAboveCB->setChecked(false);
860 footerBorderBelowCB->setChecked(false);
861 lastfooterStatusCB->setChecked(false);
862 lastfooterBorderAboveCB->setChecked(false);
863 lastfooterBorderBelowCB->setChecked(false);
864 lastfooterNoContentsCB->setChecked(false);
865 newpageCB->setChecked(false);
866 newpageCB->setEnabled(false);
867 captionStatusCB->blockSignals(true);
868 captionStatusCB->setChecked(false);
869 captionStatusCB->blockSignals(false);
872 // longtables cannot have a vertical alignment
873 TableAlignCB->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
875 switch (tabular_.longtabular_alignment) {
876 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
877 leftRB->setChecked(true);
879 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
880 centerRB->setChecked(true);
882 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
883 rightRB->setChecked(true);
886 centerRB->setChecked(true);
889 captionStatusCB->blockSignals(true);
890 captionStatusCB->setChecked(tabular_.ltCaption(row));
891 captionStatusCB->blockSignals(false);
893 // FIXME: shouldn't this be handled by GuiDialog?
894 // FIXME: Some of them should be handled directly in TabularUI.ui
895 firstheaderBorderAboveCB->setEnabled(
896 funcEnabled(Tabular::SET_LTFIRSTHEAD));
897 firstheaderBorderBelowCB->setEnabled(
898 funcEnabled(Tabular::SET_LTFIRSTHEAD));
899 // first header can only be suppressed when there is a header
900 firstheaderNoContentsCB->setEnabled(tabular_.haveLTHead()
901 && !tabular_.haveLTFirstHead());
903 //firstheaderStatusCB->setEnabled(
904 // !firstheaderNoContentsCB->isChecked());
905 headerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
906 headerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
907 headerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
909 footerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
910 footerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
911 footerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
913 lastfooterBorderAboveCB->setEnabled(
914 funcEnabled(Tabular::SET_LTLASTFOOT));
915 lastfooterBorderBelowCB->setEnabled(
916 funcEnabled(Tabular::SET_LTLASTFOOT));
917 // last footer can only be suppressed when there is a footer
918 lastfooterNoContentsCB->setEnabled(tabular_.haveLTFoot()
919 && !tabular_.haveLTLastFoot());
921 captionStatusCB->setEnabled(
922 funcEnabled(Tabular::TOGGLE_LTCAPTION));
923 // When a row is set as longtable caption, it must not be allowed
924 // to unset that this row is a multicolumn.
925 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
929 bool row_set = tabular_.getRowOfLTHead(row, ltt);
930 headerStatusCB->setChecked(row_set);
932 headerBorderAboveCB->setChecked(ltt.topDL);
933 headerBorderBelowCB->setChecked(ltt.bottomDL);
936 headerBorderAboveCB->setChecked(false);
937 headerBorderBelowCB->setChecked(false);
938 headerBorderAboveCB->setEnabled(false);
939 headerBorderBelowCB->setEnabled(false);
940 firstheaderNoContentsCB->setChecked(false);
941 firstheaderNoContentsCB->setEnabled(false);
945 row_set = tabular_.getRowOfLTFirstHead(row, ltt);
946 // check if setting a first header is allowed
947 // additionally check firstheaderNoContentsCB because when this is
948 // the case a first header makes no sense
949 firstheaderStatusCB->setEnabled(
950 funcEnabled(Tabular::SET_LTFIRSTHEAD)
951 && !firstheaderNoContentsCB->isChecked());
952 firstheaderStatusCB->setChecked(row_set);
953 if (ltt.set && (!ltt.empty || !use_empty)) {
954 firstheaderBorderAboveCB->setChecked(ltt.topDL);
955 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
957 firstheaderBorderAboveCB->setEnabled(false);
958 firstheaderBorderBelowCB->setEnabled(false);
959 firstheaderBorderAboveCB->setChecked(false);
960 firstheaderBorderBelowCB->setChecked(false);
963 firstheaderStatusCB->setEnabled(false);
967 row_set = tabular_.getRowOfLTFoot(row, ltt);
968 footerStatusCB->setChecked(row_set);
970 footerBorderAboveCB->setChecked(ltt.topDL);
971 footerBorderBelowCB->setChecked(ltt.bottomDL);
974 footerBorderAboveCB->setChecked(false);
975 footerBorderBelowCB->setChecked(false);
976 footerBorderAboveCB->setEnabled(false);
977 footerBorderBelowCB->setEnabled(false);
978 lastfooterNoContentsCB->setChecked(false);
979 lastfooterNoContentsCB->setEnabled(false);
983 row_set = tabular_.getRowOfLTLastFoot(row, ltt);
984 // check if setting a last footer is allowed
985 // additionally check lastfooterNoContentsCB because when this is
986 // the case a last footer makes no sense
987 lastfooterStatusCB->setEnabled(
988 funcEnabled(Tabular::SET_LTLASTFOOT)
989 && !lastfooterNoContentsCB->isChecked());
990 lastfooterStatusCB->setChecked(row_set);
991 if (ltt.set && (!ltt.empty || !use_empty)) {
992 lastfooterBorderAboveCB->setChecked(ltt.topDL);
993 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
995 lastfooterBorderAboveCB->setEnabled(false);
996 lastfooterBorderBelowCB->setEnabled(false);
997 lastfooterBorderAboveCB->setChecked(false);
998 lastfooterBorderBelowCB->setChecked(false);
1001 lastfooterStatusCB->setEnabled(false);
1004 newpageCB->setChecked(tabular_.getLTNewPage(row));
1008 void GuiTabular::closeGUI()
1010 // ugly hack to auto-apply the stuff that hasn't been
1011 // yet. don't let this continue to exist ...
1013 // Subtle here, we must /not/ apply any changes and
1014 // then refer to tabular, as it will have been freed
1015 // since the changes update the actual tabular_
1017 // apply the fixed width values
1018 size_t const cell = getActiveCell();
1019 bool const multicol = tabular_.isMultiColumn(cell);
1020 string width = widgetsToLength(widthED, widthUnitCB);
1023 Length llen = getColumnPWidth(tabular_, cell);
1024 Length llenMulti = getMColumnPWidth(tabular_, cell);
1026 if (multicol && !llenMulti.zero())
1027 width2 = llenMulti.asString();
1028 else if (!multicol && !llen.zero())
1029 width2 = llen.asString();
1031 // apply the special alignment
1032 docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text());
1036 sa2 = getAlignSpecial(tabular_, cell,
1037 Tabular::SET_SPECIAL_MULTI);
1039 sa2 = getAlignSpecial(tabular_, cell,
1040 Tabular::SET_SPECIAL_COLUMN);
1044 set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
1046 set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
1049 if (width != width2) {
1051 set(Tabular::SET_MPWIDTH, width);
1053 set(Tabular::SET_PWIDTH, width);
1057 switch (topspaceCO->currentIndex()) {
1059 set(Tabular::SET_TOP_SPACE, "");
1062 set(Tabular::SET_TOP_SPACE, "default");
1065 set(Tabular::SET_TOP_SPACE,
1066 widgetsToLength(topspaceED,
1071 switch (bottomspaceCO->currentIndex()) {
1073 set(Tabular::SET_BOTTOM_SPACE, "");
1076 set(Tabular::SET_BOTTOM_SPACE, "default");
1079 set(Tabular::SET_BOTTOM_SPACE,
1080 widgetsToLength(bottomspaceED,
1085 switch (interlinespaceCO->currentIndex()) {
1087 set(Tabular::SET_INTERLINE_SPACE, "");
1090 set(Tabular::SET_INTERLINE_SPACE, "default");
1093 set(Tabular::SET_INTERLINE_SPACE,
1094 widgetsToLength(interlinespaceED,
1095 interlinespaceUnit));
1102 bool GuiTabular::initialiseParams(string const & data)
1104 // try to get the current cell
1105 BufferView const * const bv = bufferview();
1106 InsetTabular const * current_inset = 0;
1108 Cursor const & cur = bv->cursor();
1109 // get the innermost tabular inset;
1110 // assume that it is "ours"
1111 for (int i = cur.depth() - 1; i >= 0; --i)
1112 if (cur[i].inset().lyxCode() == TABULAR_CODE) {
1114 static_cast<InsetTabular const *>(&cur[i].inset());
1115 active_cell_ = cur[i].idx();
1120 if (current_inset && data.empty()) {
1121 tabular_ = Tabular(current_inset->tabular);
1125 InsetTabular tmp(const_cast<Buffer &>(buffer()));
1126 InsetTabular::string2params(data, tmp);
1127 tabular_ = Tabular(tmp.tabular);
1132 void GuiTabular::clearParams()
1134 // This function is also called when LyX is closing and the dialog
1135 // is still open. At that time, the buffer might not be available
1137 if (isBufferAvailable()) {
1138 InsetTabular tmp(const_cast<Buffer &>(buffer()));
1139 tabular_ = tmp.tabular;
1141 active_cell_ = Tabular::npos;
1145 Tabular::idx_type GuiTabular::getActiveCell() const
1147 return active_cell_;
1151 void GuiTabular::set(Tabular::Feature f, string const & arg)
1153 string const data = featureAsString(f) + ' ' + arg;
1154 dispatch(FuncRequest(getLfun(), data));
1158 void GuiTabular::setSpecial(string const & special)
1160 if (tabular_.isMultiColumn(getActiveCell()))
1161 set(Tabular::SET_SPECIAL_MULTI, special);
1163 set(Tabular::SET_SPECIAL_COLUMN, special);
1167 void GuiTabular::setWidth(string const & width)
1169 if (tabular_.isMultiColumn(getActiveCell()))
1170 set(Tabular::SET_MPWIDTH, width);
1172 set(Tabular::SET_PWIDTH, width);
1178 void GuiTabular::toggleMultiColumn()
1180 set(Tabular::MULTICOLUMN);
1185 void GuiTabular::rotateTabular(bool yes)
1188 set(Tabular::SET_ROTATE_TABULAR);
1190 set(Tabular::UNSET_ROTATE_TABULAR);
1194 void GuiTabular::rotateCell(bool yes)
1197 set(Tabular::SET_ROTATE_CELL);
1199 set(Tabular::UNSET_ROTATE_CELL);
1203 void GuiTabular::halign(GuiTabular::HALIGN h)
1205 Tabular::Feature num = Tabular::ALIGN_LEFT;
1206 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
1210 num = Tabular::ALIGN_LEFT;
1211 multi_num = Tabular::M_ALIGN_LEFT;
1214 num = Tabular::ALIGN_CENTER;
1215 multi_num = Tabular::M_ALIGN_CENTER;
1218 num = Tabular::ALIGN_RIGHT;
1219 multi_num = Tabular::M_ALIGN_RIGHT;
1222 num = Tabular::ALIGN_BLOCK;
1223 //multi_num: no equivalent
1227 if (tabular_.isMultiColumn(getActiveCell()))
1234 void GuiTabular::valign(GuiTabular::VALIGN v)
1236 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
1237 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
1241 num = Tabular::VALIGN_TOP;
1242 multi_num = Tabular::M_VALIGN_TOP;
1245 num = Tabular::VALIGN_MIDDLE;
1246 multi_num = Tabular::M_VALIGN_MIDDLE;
1249 num = Tabular::VALIGN_BOTTOM;
1250 multi_num = Tabular::M_VALIGN_BOTTOM;
1254 if (tabular_.isMultiColumn(getActiveCell()))
1261 void GuiTabular::booktabs(bool yes)
1264 set(Tabular::SET_BOOKTABS);
1266 set(Tabular::UNSET_BOOKTABS);
1270 void GuiTabular::longTabular(bool yes)
1273 set(Tabular::SET_LONGTABULAR);
1275 set(Tabular::UNSET_LONGTABULAR);
1279 // to get the status of the longtable row settings
1280 bool GuiTabular::funcEnabled(Tabular::Feature f) const
1283 FuncRequest(getLfun(), featureAsString(f))).enabled();
1287 Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); }
1290 } // namespace frontend
1293 #include "moc_GuiTabular.cpp"