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.currentBufferView()->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 widthUnitCB->setCurrentItem(Length::defaultUnit());
58 connect(topspaceED, SIGNAL(returnPressed()),
59 this, SLOT(topspace_changed()));
60 connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
61 this, SLOT(topspace_changed()));
62 connect(topspaceCO, SIGNAL(activated(int)),
63 this, SLOT(topspace_changed()));
64 connect(bottomspaceED, SIGNAL(returnPressed()),
65 this, SLOT(bottomspace_changed()));
66 connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
67 this, SLOT(bottomspace_changed()));
68 connect(bottomspaceCO, SIGNAL(activated(int)),
69 this, SLOT(bottomspace_changed()));
70 connect(interlinespaceED, SIGNAL(returnPressed()),
71 this, SLOT(interlinespace_changed()));
72 connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
73 this, SLOT(interlinespace_changed()));
74 connect(interlinespaceCO, SIGNAL(activated(int)),
75 this, SLOT(interlinespace_changed()));
76 connect(booktabsRB, SIGNAL(clicked(bool)),
77 this, SLOT(booktabsChanged(bool)));
78 connect(borderDefaultRB, SIGNAL(clicked(bool)),
79 this, SLOT(booktabsChanged(bool)));
80 connect(borderSetPB, SIGNAL(clicked()),
81 this, SLOT(borderSet_clicked()));
82 connect(borderUnsetPB, SIGNAL(clicked()),
83 this, SLOT(borderUnset_clicked()));
84 connect(longTabularCB, SIGNAL(toggled(bool)),
85 longtableGB, SLOT(setEnabled(bool)));
86 connect(longTabularCB, SIGNAL(toggled(bool)),
87 newpageCB, SLOT(setEnabled(bool)));
88 connect(longTabularCB, SIGNAL(toggled(bool)),
89 alignmentGB, SLOT(setEnabled(bool)));
90 // longtables cannot have a vertical alignment
91 connect(longTabularCB, SIGNAL(toggled(bool)),
92 TableAlignCB, SLOT(setDisabled(bool)));
93 connect(hAlignCB, SIGNAL(activated(int)),
94 this, SLOT(hAlign_changed(int)));
95 connect(vAlignCB, SIGNAL(activated(int)),
96 this, SLOT(vAlign_changed(int)));
97 connect(multicolumnCB, SIGNAL(clicked()),
98 this, SLOT(multicolumn_clicked()));
99 connect(multirowCB, SIGNAL(clicked()),
100 this, SLOT(multirow_clicked()));
101 connect(newpageCB, SIGNAL(clicked()),
102 this, SLOT(ltNewpage_clicked()));
103 connect(headerStatusCB, SIGNAL(clicked()),
104 this, SLOT(ltHeaderStatus_clicked()));
105 connect(headerBorderAboveCB, SIGNAL(clicked()),
106 this, SLOT(ltHeaderBorderAbove_clicked()));
107 connect(headerBorderBelowCB, SIGNAL(clicked()),
108 this, SLOT(ltHeaderBorderBelow_clicked()));
109 connect(firstheaderStatusCB, SIGNAL(clicked()),
110 this, SLOT(ltFirstHeaderStatus_clicked()));
111 connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
112 this, SLOT(ltFirstHeaderBorderAbove_clicked()));
113 connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
114 this, SLOT(ltFirstHeaderBorderBelow_clicked()));
115 connect(firstheaderNoContentsCB, SIGNAL(clicked()),
116 this, SLOT(ltFirstHeaderEmpty_clicked()));
117 connect(footerStatusCB, SIGNAL(clicked()),
118 this, SLOT(ltFooterStatus_clicked()));
119 connect(footerBorderAboveCB, SIGNAL(clicked()),
120 this, SLOT(ltFooterBorderAbove_clicked()));
121 connect(footerBorderBelowCB, SIGNAL(clicked()),
122 this, SLOT(ltFooterBorderBelow_clicked()));
123 connect(lastfooterStatusCB, SIGNAL(clicked()),
124 this, SLOT(ltLastFooterStatus_clicked()));
125 connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
126 this, SLOT(ltLastFooterBorderAbove_clicked()));
127 connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
128 this, SLOT(ltLastFooterBorderBelow_clicked()));
129 connect(lastfooterNoContentsCB, SIGNAL(clicked()),
130 this, SLOT(ltLastFooterEmpty_clicked()));
131 connect(specialAlignmentED, SIGNAL(returnPressed()),
132 this, SLOT(specialAlignment_changed()));
133 connect(widthED, SIGNAL(editingFinished()),
134 this, SLOT(width_changed()));
135 connect(widthUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
136 this, SLOT(width_changed()));
137 connect(closePB, SIGNAL(clicked()),
138 this, SLOT(close_clicked()));
139 connect(borders, SIGNAL(topSet(bool)),
140 this, SLOT(topBorder_changed()));
141 connect(borders, SIGNAL(bottomSet(bool)),
142 this, SLOT(bottomBorder_changed()));
143 connect(borders, SIGNAL(rightSet(bool)),
144 this, SLOT(rightBorder_changed()));
145 connect(borders, SIGNAL(leftSet(bool)),
146 this, SLOT(leftBorder_changed()));
147 connect(rotateTabularCB, SIGNAL(clicked()),
148 this, SLOT(rotateTabular()));
149 connect(rotateCellCB, SIGNAL(clicked()),
150 this, SLOT(rotateCell()));
151 connect(TableAlignCB, SIGNAL(activated(int)),
152 this, SLOT(tableAlignment_changed(int)));
153 connect(longTabularCB, SIGNAL(clicked()),
154 this, SLOT(longTabular()));
155 connect(leftRB, SIGNAL(clicked()),
156 this, SLOT(ltAlignment_clicked()));
157 connect(centerRB, SIGNAL(clicked()),
158 this, SLOT(ltAlignment_clicked()));
159 connect(rightRB, SIGNAL(clicked()),
160 this, SLOT(ltAlignment_clicked()));
162 bc().setPolicy(ButtonPolicy::IgnorantPolicy);
164 bc().addReadOnly(topspaceED);
165 bc().addReadOnly(topspaceUnit);
166 bc().addReadOnly(topspaceCO);
167 bc().addReadOnly(bottomspaceED);
168 bc().addReadOnly(bottomspaceUnit);
169 bc().addReadOnly(bottomspaceCO);
170 bc().addReadOnly(interlinespaceED);
171 bc().addReadOnly(interlinespaceUnit);
172 bc().addReadOnly(interlinespaceCO);
173 bc().addReadOnly(borderDefaultRB);
174 bc().addReadOnly(booktabsRB);
176 bc().addReadOnly(multicolumnCB);
177 bc().addReadOnly(multirowCB);
178 bc().addReadOnly(rotateCellCB);
179 bc().addReadOnly(rotateTabularCB);
180 bc().addReadOnly(specialAlignmentED);
181 bc().addReadOnly(widthED);
182 bc().addReadOnly(widthUnitCB);
183 bc().addReadOnly(hAlignCB);
184 bc().addReadOnly(vAlignCB);
185 bc().addReadOnly(TableAlignCB);
186 bc().addReadOnly(borderSetPB);
187 bc().addReadOnly(borderUnsetPB);
188 bc().addReadOnly(borders);
189 bc().addReadOnly(longTabularCB);
190 bc().addReadOnly(headerStatusCB);
191 bc().addReadOnly(headerBorderAboveCB);
192 bc().addReadOnly(headerBorderBelowCB);
193 bc().addReadOnly(firstheaderStatusCB);
194 bc().addReadOnly(firstheaderBorderAboveCB);
195 bc().addReadOnly(firstheaderBorderBelowCB);
196 bc().addReadOnly(firstheaderNoContentsCB);
197 bc().addReadOnly(footerStatusCB);
198 bc().addReadOnly(footerBorderAboveCB);
199 bc().addReadOnly(footerBorderBelowCB);
200 bc().addReadOnly(lastfooterStatusCB);
201 bc().addReadOnly(lastfooterBorderAboveCB);
202 bc().addReadOnly(lastfooterBorderBelowCB);
203 bc().addReadOnly(lastfooterNoContentsCB);
204 bc().addReadOnly(newpageCB);
205 bc().addReadOnly(leftRB);
206 bc().addReadOnly(centerRB);
207 bc().addReadOnly(rightRB);
209 // initialize the length validator
210 bc().addCheckedLineEdit(widthED, fixedWidthColLA);
211 bc().addCheckedLineEdit(topspaceED, topspaceLA);
212 bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA);
213 bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA);
217 GuiTabular::~GuiTabular()
222 void GuiTabular::change_adaptor()
228 void GuiTabular::booktabsChanged(bool)
231 booktabs(booktabsRB->isChecked());
232 updateBorders(tabular_);
236 void GuiTabular::topspace_changed()
238 switch (topspaceCO->currentIndex()) {
240 set(Tabular::SET_TOP_SPACE, "");
241 topspaceED->setEnabled(false);
242 topspaceUnit->setEnabled(false);
246 set(Tabular::SET_TOP_SPACE, "default");
247 topspaceED->setEnabled(false);
248 topspaceUnit->setEnabled(false);
252 if (!topspaceED->text().isEmpty())
253 set(Tabular::SET_TOP_SPACE,
254 widgetsToLength(topspaceED,
256 if (!bc().policy().isReadOnly()) {
257 topspaceED->setEnabled(true);
258 topspaceUnit->setEnabled(true);
267 void GuiTabular::bottomspace_changed()
269 switch (bottomspaceCO->currentIndex()) {
271 set(Tabular::SET_BOTTOM_SPACE, "");
272 bottomspaceED->setEnabled(false);
273 bottomspaceUnit->setEnabled(false);
277 set(Tabular::SET_BOTTOM_SPACE, "default");
278 bottomspaceED->setEnabled(false);
279 bottomspaceUnit->setEnabled(false);
283 if (!bottomspaceED->text().isEmpty())
284 set(Tabular::SET_BOTTOM_SPACE,
285 widgetsToLength(bottomspaceED,
287 if (!bc().policy().isReadOnly()) {
288 bottomspaceED->setEnabled(true);
289 bottomspaceUnit->setEnabled(true);
298 void GuiTabular::interlinespace_changed()
300 switch (interlinespaceCO->currentIndex()) {
302 set(Tabular::SET_INTERLINE_SPACE, "");
303 interlinespaceED->setEnabled(false);
304 interlinespaceUnit->setEnabled(false);
308 set(Tabular::SET_INTERLINE_SPACE, "default");
309 interlinespaceED->setEnabled(false);
310 interlinespaceUnit->setEnabled(false);
314 if (!interlinespaceED->text().isEmpty())
315 set(Tabular::SET_INTERLINE_SPACE,
316 widgetsToLength(interlinespaceED,
317 interlinespaceUnit));
318 if (!bc().policy().isReadOnly()) {
319 interlinespaceED->setEnabled(true);
320 interlinespaceUnit->setEnabled(true);
329 void GuiTabular::close_clicked()
336 void GuiTabular::borderSet_clicked()
338 set(Tabular::SET_ALL_LINES);
339 updateBorders(tabular_);
344 void GuiTabular::borderUnset_clicked()
346 set(Tabular::UNSET_ALL_LINES);
347 updateBorders(tabular_);
352 void GuiTabular::leftBorder_changed()
354 set(Tabular::TOGGLE_LINE_LEFT);
359 void GuiTabular::rightBorder_changed()
361 set(Tabular::TOGGLE_LINE_RIGHT);
366 void GuiTabular::topBorder_changed()
368 set(Tabular::TOGGLE_LINE_TOP);
373 void GuiTabular::bottomBorder_changed()
375 set(Tabular::TOGGLE_LINE_BOTTOM);
380 void GuiTabular::specialAlignment_changed()
382 string special = fromqstr(specialAlignmentED->text());
383 setSpecial(tabular_, special);
388 void GuiTabular::width_changed()
391 string const width = widgetsToLength(widthED, widthUnitCB);
392 setWidth(tabular_, width);
396 void GuiTabular::multicolumn_clicked()
402 void GuiTabular::multirow_clicked()
409 void GuiTabular::rotateTabular()
411 rotateTabular(rotateTabularCB->isChecked());
416 void GuiTabular::rotateCell()
418 rotateCell(rotateCellCB->isChecked());
423 void GuiTabular::hAlign_changed(int align)
425 GuiTabular::HALIGN h = GuiTabular::LEFT;
428 case 0: h = GuiTabular::LEFT; break;
429 case 1: h = GuiTabular::CENTER; break;
430 case 2: h = GuiTabular::RIGHT; break;
431 case 3: h = GuiTabular::BLOCK; break;
438 void GuiTabular::vAlign_changed(int align)
440 GuiTabular::VALIGN v = GuiTabular::TOP;
443 case 0: v = GuiTabular::TOP; break;
444 case 1: v = GuiTabular::MIDDLE; break;
445 case 2: v = GuiTabular::BOTTOM; break;
452 void GuiTabular::tableAlignment_changed(int align)
455 case 0: set(Tabular::TABULAR_VALIGN_TOP);
457 case 1: set(Tabular::TABULAR_VALIGN_MIDDLE);
459 case 2: set(Tabular::TABULAR_VALIGN_BOTTOM);
465 void GuiTabular::longTabular()
467 longTabular(longTabularCB->isChecked());
472 void GuiTabular::ltNewpage_clicked()
474 set(Tabular::SET_LTNEWPAGE);
479 void GuiTabular::on_captionStatusCB_toggled()
481 set(Tabular::TOGGLE_LTCAPTION);
486 void GuiTabular::ltHeaderStatus_clicked()
488 bool enable = headerStatusCB->isChecked();
490 set(Tabular::SET_LTHEAD, "");
492 set(Tabular::UNSET_LTHEAD, "");
497 void GuiTabular::ltHeaderBorderAbove_clicked()
499 if (headerBorderAboveCB->isChecked())
500 set(Tabular::SET_LTHEAD, "dl_above");
502 set(Tabular::UNSET_LTHEAD, "dl_above");
507 void GuiTabular::ltHeaderBorderBelow_clicked()
509 if (headerBorderBelowCB->isChecked())
510 set(Tabular::SET_LTHEAD, "dl_below");
512 set(Tabular::UNSET_LTHEAD, "dl_below");
517 void GuiTabular::ltFirstHeaderBorderAbove_clicked()
519 if (firstheaderBorderAboveCB->isChecked())
520 set(Tabular::SET_LTFIRSTHEAD, "dl_above");
522 set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
527 void GuiTabular::ltFirstHeaderBorderBelow_clicked()
529 if (firstheaderBorderBelowCB->isChecked())
530 set(Tabular::SET_LTFIRSTHEAD, "dl_below");
532 set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
537 void GuiTabular::ltFirstHeaderStatus_clicked()
539 bool enable = firstheaderStatusCB->isChecked();
541 set(Tabular::SET_LTFIRSTHEAD, "");
543 set(Tabular::UNSET_LTFIRSTHEAD, "");
548 void GuiTabular::ltFirstHeaderEmpty_clicked()
550 bool enable = firstheaderNoContentsCB->isChecked();
552 set(Tabular::SET_LTFIRSTHEAD, "empty");
554 set(Tabular::UNSET_LTFIRSTHEAD, "empty");
559 void GuiTabular::ltFooterStatus_clicked()
561 bool enable = footerStatusCB->isChecked();
563 set(Tabular::SET_LTFOOT, "");
565 set(Tabular::UNSET_LTFOOT, "");
570 void GuiTabular::ltFooterBorderAbove_clicked()
572 if (footerBorderAboveCB->isChecked())
573 set(Tabular::SET_LTFOOT, "dl_above");
575 set(Tabular::UNSET_LTFOOT, "dl_above");
580 void GuiTabular::ltFooterBorderBelow_clicked()
582 if (footerBorderBelowCB->isChecked())
583 set(Tabular::SET_LTFOOT, "dl_below");
585 set(Tabular::UNSET_LTFOOT, "dl_below");
590 void GuiTabular::ltLastFooterStatus_clicked()
592 bool enable = lastfooterStatusCB->isChecked();
594 set(Tabular::SET_LTLASTFOOT, "");
596 set(Tabular::UNSET_LTLASTFOOT, "");
601 void GuiTabular::ltLastFooterBorderAbove_clicked()
603 if (lastfooterBorderAboveCB->isChecked())
604 set(Tabular::SET_LTLASTFOOT, "dl_above");
606 set(Tabular::UNSET_LTLASTFOOT, "dl_above");
611 void GuiTabular::ltLastFooterBorderBelow_clicked()
613 if (lastfooterBorderBelowCB->isChecked())
614 set(Tabular::SET_LTLASTFOOT, "dl_below");
616 set(Tabular::UNSET_LTLASTFOOT, "dl_below");
621 void GuiTabular::ltLastFooterEmpty_clicked()
623 bool enable = lastfooterNoContentsCB->isChecked();
625 set(Tabular::SET_LTLASTFOOT, "empty");
627 set(Tabular::UNSET_LTLASTFOOT, "empty");
632 void GuiTabular::ltAlignment_clicked()
634 if (leftRB->isChecked())
635 set(Tabular::LONGTABULAR_ALIGN_LEFT);
636 else if (centerRB->isChecked())
637 set(Tabular::LONGTABULAR_ALIGN_CENTER);
638 else if (rightRB->isChecked())
639 set(Tabular::LONGTABULAR_ALIGN_RIGHT);
644 void GuiTabular::updateBorders(Tabular const & tabular)
646 Tabular::idx_type const cell = getActiveCell();
647 borders->setTop(tabular.topLine(cell));
648 borders->setBottom(tabular.bottomLine(cell));
649 borders->setLeft(tabular.leftLine(cell));
650 borders->setRight(tabular.rightLine(cell));
651 // repaint the setborder widget
658 Length getColumnPWidth(Tabular const & t, size_t cell)
660 return t.column_info[t.cellColumn(cell)].p_width;
664 Length getMColumnPWidth(Tabular const & t, size_t cell)
666 if (t.isMultiColumn(cell) || t.isMultiRow(cell))
667 return t.cellInfo(cell).p_width;
672 docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
674 if (what == Tabular::SET_SPECIAL_MULTICOLUMN
675 || what == Tabular::SET_SPECIAL_MULTIROW)
676 return t.cellInfo(cell).align_special;
677 return t.column_info[t.cellColumn(cell)].align_special;
683 void GuiTabular::updateContents()
685 initialiseParams(string());
686 paramsToDialog(tabular_);
690 void GuiTabular::paramsToDialog(Tabular const & tabular)
692 size_t const cell = getActiveCell();
694 Tabular::row_type const row = tabular.cellRow(cell);
695 Tabular::col_type const col = tabular.cellColumn(cell);
697 tabularRowED->setText(QString::number(row + 1));
698 tabularColumnED->setText(QString::number(col + 1));
700 bool const multicol(tabular.isMultiColumn(cell));
701 multicolumnCB->setChecked(multicol);
703 bool const multirow(tabular.isMultiRow(cell));
704 multirowCB->setChecked(multirow);
706 rotateCellCB->setChecked(tabular.getRotateCell(cell));
707 rotateTabularCB->setChecked(tabular.rotate);
709 longTabularCB->setChecked(tabular.is_long_tabular);
711 updateBorders(tabular);
717 special = getAlignSpecial(tabular, cell,
718 Tabular::SET_SPECIAL_MULTICOLUMN);
719 pwidth = getMColumnPWidth(tabular, cell);
720 } else if (multirow) {
721 special = getAlignSpecial(tabular, cell,
722 Tabular::SET_SPECIAL_MULTIROW);
723 pwidth = getMColumnPWidth(tabular, cell);
725 special = getAlignSpecial(tabular, cell,
726 Tabular::SET_SPECIAL_COLUMN);
727 pwidth = getColumnPWidth(tabular, cell);
730 specialAlignmentED->setText(toqstr(special));
732 bool const isReadonly = bc().policy().isReadOnly();
733 specialAlignmentED->setEnabled(!isReadonly);
735 Length::UNIT const default_unit = Length::defaultUnit();
737 borderDefaultRB->setChecked(!tabular.use_booktabs);
738 booktabsRB->setChecked(tabular.use_booktabs);
740 if (tabular.row_info[row].top_space.empty()
741 && !tabular.row_info[row].top_space_default) {
742 topspaceCO->setCurrentIndex(0);
743 } else if (tabular.row_info[row].top_space_default) {
744 topspaceCO->setCurrentIndex(1);
746 topspaceCO->setCurrentIndex(2);
747 lengthToWidgets(topspaceED,
749 tabular.row_info[row].top_space.asString(),
752 topspaceED->setEnabled(!isReadonly
753 && (topspaceCO->currentIndex() == 2));
754 topspaceUnit->setEnabled(!isReadonly
755 && (topspaceCO->currentIndex() == 2));
756 topspaceCO->setEnabled(!isReadonly);
758 if (tabular.row_info[row].bottom_space.empty()
759 && !tabular.row_info[row].bottom_space_default) {
760 bottomspaceCO->setCurrentIndex(0);
761 } else if (tabular.row_info[row].bottom_space_default) {
762 bottomspaceCO->setCurrentIndex(1);
764 bottomspaceCO->setCurrentIndex(2);
765 lengthToWidgets(bottomspaceED,
767 tabular.row_info[row].bottom_space.asString(),
770 bottomspaceED->setEnabled(!isReadonly
771 && (bottomspaceCO->currentIndex() == 2));
772 bottomspaceUnit->setEnabled(!isReadonly
773 && (bottomspaceCO->currentIndex() == 2));
774 bottomspaceCO->setEnabled(!isReadonly);
776 if (tabular.row_info[row].interline_space.empty()
777 && !tabular.row_info[row].interline_space_default) {
778 interlinespaceCO->setCurrentIndex(0);
779 } else if (tabular.row_info[row].interline_space_default) {
780 interlinespaceCO->setCurrentIndex(1);
782 interlinespaceCO->setCurrentIndex(2);
783 lengthToWidgets(interlinespaceED,
785 tabular.row_info[row].interline_space.asString(),
788 interlinespaceED->setEnabled(!isReadonly
789 && (interlinespaceCO->currentIndex() == 2));
790 interlinespaceUnit->setEnabled(!isReadonly
791 && (interlinespaceCO->currentIndex() == 2));
792 interlinespaceCO->setEnabled(!isReadonly);
795 if (!pwidth.zero()) {
796 colwidth = pwidth.asString();
798 lengthToWidgets(widthED, widthUnitCB,
799 colwidth, default_unit);
802 widthED->setEnabled(!isReadonly);
803 widthUnitCB->setEnabled(!isReadonly);
806 hAlignCB->addItem(qt_("Left"));
807 hAlignCB->addItem(qt_("Center"));
808 hAlignCB->addItem(qt_("Right"));
809 if (!multicol && !pwidth.zero())
810 hAlignCB->addItem(qt_("Justified"));
813 switch (tabular.getAlignment(cell)) {
817 case LYX_ALIGN_CENTER:
820 case LYX_ALIGN_RIGHT:
823 case LYX_ALIGN_BLOCK:
825 if (!multicol && !pwidth.zero())
833 hAlignCB->setCurrentIndex(align);
836 switch (tabular.getVAlignment(cell)) {
837 case Tabular::LYX_VALIGN_TOP:
840 case Tabular::LYX_VALIGN_MIDDLE:
843 case Tabular::LYX_VALIGN_BOTTOM:
852 vAlignCB->setCurrentIndex(valign);
854 hAlignCB->setEnabled(true);
855 if (!multirow && !pwidth.zero())
856 vAlignCB->setEnabled(true);
859 switch (tabular.tabular_valignment) {
860 case Tabular::LYX_VALIGN_TOP:
863 case Tabular::LYX_VALIGN_MIDDLE:
866 case Tabular::LYX_VALIGN_BOTTOM:
873 TableAlignCB->setCurrentIndex(tableValign);
875 if (!tabular.is_long_tabular) {
876 headerStatusCB->setChecked(false);
877 headerBorderAboveCB->setChecked(false);
878 headerBorderBelowCB->setChecked(false);
879 firstheaderStatusCB->setChecked(false);
880 firstheaderBorderAboveCB->setChecked(false);
881 firstheaderBorderBelowCB->setChecked(false);
882 firstheaderNoContentsCB->setChecked(false);
883 footerStatusCB->setChecked(false);
884 footerBorderAboveCB->setChecked(false);
885 footerBorderBelowCB->setChecked(false);
886 lastfooterStatusCB->setChecked(false);
887 lastfooterBorderAboveCB->setChecked(false);
888 lastfooterBorderBelowCB->setChecked(false);
889 lastfooterNoContentsCB->setChecked(false);
890 newpageCB->setChecked(false);
891 newpageCB->setEnabled(false);
892 captionStatusCB->blockSignals(true);
893 captionStatusCB->setChecked(false);
894 captionStatusCB->blockSignals(false);
897 // longtables cannot have a vertical alignment
898 TableAlignCB->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
900 switch (tabular.longtabular_alignment) {
901 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
902 leftRB->setChecked(true);
904 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
905 centerRB->setChecked(true);
907 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
908 rightRB->setChecked(true);
911 centerRB->setChecked(true);
914 captionStatusCB->blockSignals(true);
915 captionStatusCB->setChecked(tabular.ltCaption(row));
916 captionStatusCB->blockSignals(false);
918 // FIXME: shouldn't this be handled by GuiDialog?
919 // FIXME: Some of them should be handled directly in TabularUI.ui
920 firstheaderBorderAboveCB->setEnabled(
921 funcEnabled(Tabular::SET_LTFIRSTHEAD));
922 firstheaderBorderBelowCB->setEnabled(
923 funcEnabled(Tabular::SET_LTFIRSTHEAD));
924 // first header can only be suppressed when there is a header
925 firstheaderNoContentsCB->setEnabled(tabular.haveLTHead()
926 && !tabular.haveLTFirstHead());
928 //firstheaderStatusCB->setEnabled(
929 // !firstheaderNoContentsCB->isChecked());
930 headerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
931 headerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
932 headerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
934 footerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
935 footerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
936 footerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
938 lastfooterBorderAboveCB->setEnabled(
939 funcEnabled(Tabular::SET_LTLASTFOOT));
940 lastfooterBorderBelowCB->setEnabled(
941 funcEnabled(Tabular::SET_LTLASTFOOT));
942 // last footer can only be suppressed when there is a footer
943 lastfooterNoContentsCB->setEnabled(tabular.haveLTFoot()
944 && !tabular.haveLTLastFoot());
946 captionStatusCB->setEnabled(
947 funcEnabled(Tabular::TOGGLE_LTCAPTION));
948 // When a row is set as longtable caption, it must not be allowed
949 // to unset that this row is a multicolumn.
950 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
951 multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW));
955 bool row_set = tabular.getRowOfLTHead(row, ltt);
956 headerStatusCB->setChecked(row_set);
958 headerBorderAboveCB->setChecked(ltt.topDL);
959 headerBorderBelowCB->setChecked(ltt.bottomDL);
962 headerBorderAboveCB->setChecked(false);
963 headerBorderBelowCB->setChecked(false);
964 headerBorderAboveCB->setEnabled(false);
965 headerBorderBelowCB->setEnabled(false);
966 firstheaderNoContentsCB->setChecked(false);
967 firstheaderNoContentsCB->setEnabled(false);
971 row_set = tabular.getRowOfLTFirstHead(row, ltt);
972 // check if setting a first header is allowed
973 // additionally check firstheaderNoContentsCB because when this is
974 // the case a first header makes no sense
975 firstheaderStatusCB->setEnabled(
976 funcEnabled(Tabular::SET_LTFIRSTHEAD)
977 && !firstheaderNoContentsCB->isChecked());
978 firstheaderStatusCB->setChecked(row_set);
979 if (ltt.set && (!ltt.empty || !use_empty)) {
980 firstheaderBorderAboveCB->setChecked(ltt.topDL);
981 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
983 firstheaderBorderAboveCB->setEnabled(false);
984 firstheaderBorderBelowCB->setEnabled(false);
985 firstheaderBorderAboveCB->setChecked(false);
986 firstheaderBorderBelowCB->setChecked(false);
989 firstheaderStatusCB->setEnabled(false);
993 row_set = tabular.getRowOfLTFoot(row, ltt);
994 footerStatusCB->setChecked(row_set);
996 footerBorderAboveCB->setChecked(ltt.topDL);
997 footerBorderBelowCB->setChecked(ltt.bottomDL);
1000 footerBorderAboveCB->setChecked(false);
1001 footerBorderBelowCB->setChecked(false);
1002 footerBorderAboveCB->setEnabled(false);
1003 footerBorderBelowCB->setEnabled(false);
1004 lastfooterNoContentsCB->setChecked(false);
1005 lastfooterNoContentsCB->setEnabled(false);
1009 row_set = tabular.getRowOfLTLastFoot(row, ltt);
1010 // check if setting a last footer is allowed
1011 // additionally check lastfooterNoContentsCB because when this is
1012 // the case a last footer makes no sense
1013 lastfooterStatusCB->setEnabled(
1014 funcEnabled(Tabular::SET_LTLASTFOOT)
1015 && !lastfooterNoContentsCB->isChecked());
1016 lastfooterStatusCB->setChecked(row_set);
1017 if (ltt.set && (!ltt.empty || !use_empty)) {
1018 lastfooterBorderAboveCB->setChecked(ltt.topDL);
1019 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
1021 lastfooterBorderAboveCB->setEnabled(false);
1022 lastfooterBorderBelowCB->setEnabled(false);
1023 lastfooterBorderAboveCB->setChecked(false);
1024 lastfooterBorderBelowCB->setChecked(false);
1027 lastfooterStatusCB->setEnabled(false);
1030 newpageCB->setChecked(tabular.getLTNewPage(row));
1034 void GuiTabular::closeGUI(Tabular const & tabular)
1036 // ugly hack to auto-apply the stuff that hasn't been
1037 // yet. don't let this continue to exist ...
1039 // Subtle here, we must /not/ apply any changes and
1040 // then refer to tabular, as it will have been freed
1041 // since the changes update the actual tabular_
1043 // apply the fixed width values
1044 size_t const cell = getActiveCell();
1045 bool const multicol = tabular.isMultiColumn(cell);
1046 bool const multirow = tabular.isMultiRow(cell);
1047 string width = widgetsToLength(widthED, widthUnitCB);
1050 Length llen = getColumnPWidth(tabular, cell);
1051 Length llenMulti = getMColumnPWidth(tabular, cell);
1053 if (multicol && multirow && !llenMulti.zero())
1054 width2 = llenMulti.asString();
1055 else if (!multicol && !multirow && !llen.zero())
1056 width2 = llen.asString();
1058 // apply the special alignment
1059 docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text());
1063 sa2 = getAlignSpecial(tabular, cell,
1064 Tabular::SET_SPECIAL_MULTICOLUMN);
1066 sa2 = getAlignSpecial(tabular, cell,
1067 Tabular::SET_SPECIAL_MULTIROW);
1069 sa2 = getAlignSpecial(tabular, cell,
1070 Tabular::SET_SPECIAL_COLUMN);
1074 set(Tabular::SET_SPECIAL_MULTICOLUMN, to_utf8(sa1));
1076 set(Tabular::SET_SPECIAL_MULTIROW, to_utf8(sa1));
1078 set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
1081 if (width != width2) {
1083 set(Tabular::SET_MPWIDTH, width);
1085 set(Tabular::SET_PWIDTH, width);
1089 switch (topspaceCO->currentIndex()) {
1091 set(Tabular::SET_TOP_SPACE, "");
1094 set(Tabular::SET_TOP_SPACE, "default");
1097 set(Tabular::SET_TOP_SPACE,
1098 widgetsToLength(topspaceED,
1103 switch (bottomspaceCO->currentIndex()) {
1105 set(Tabular::SET_BOTTOM_SPACE, "");
1108 set(Tabular::SET_BOTTOM_SPACE, "default");
1111 set(Tabular::SET_BOTTOM_SPACE,
1112 widgetsToLength(bottomspaceED,
1117 switch (interlinespaceCO->currentIndex()) {
1119 set(Tabular::SET_INTERLINE_SPACE, "");
1122 set(Tabular::SET_INTERLINE_SPACE, "default");
1125 set(Tabular::SET_INTERLINE_SPACE,
1126 widgetsToLength(interlinespaceED,
1127 interlinespaceUnit));
1134 bool GuiTabular::initialiseParams(string const & data)
1136 // try to get the current cell
1137 BufferView const * const bv = bufferview();
1138 InsetTabular const * current_inset = 0;
1140 Cursor const & cur = bv->cursor();
1141 // get the innermost tabular inset;
1142 // assume that it is "ours"
1143 for (int i = cur.depth() - 1; i >= 0; --i)
1144 if (cur[i].inset().lyxCode() == TABULAR_CODE) {
1146 static_cast<InsetTabular const *>(&cur[i].inset());
1147 active_cell_ = cur[i].idx();
1152 if (current_inset && data.empty()) {
1153 tabular_ = Tabular(current_inset->tabular);
1157 InsetTabular tmp(const_cast<Buffer *>(&buffer()));
1158 InsetTabular::string2params(data, tmp);
1159 tabular_ = Tabular(tmp.tabular);
1164 void GuiTabular::clearParams()
1166 // This function is also called when LyX is closing and the dialog
1167 // is still open. At that time, the buffer might not be available
1169 if (isBufferAvailable()) {
1170 InsetTabular tmp(const_cast<Buffer *>(&buffer()));
1171 tabular_ = tmp.tabular;
1173 active_cell_ = Tabular::npos;
1177 Tabular::idx_type GuiTabular::getActiveCell() const
1179 return active_cell_;
1183 void GuiTabular::set(Tabular::Feature f, string const & arg)
1185 string const data = featureAsString(f) + ' ' + arg;
1186 dispatch(FuncRequest(getLfun(), data));
1190 void GuiTabular::setSpecial(Tabular const & tabular, string const & special)
1192 if (tabular.isMultiColumn(getActiveCell()))
1193 set(Tabular::SET_SPECIAL_MULTICOLUMN, special);
1194 else if (tabular.isMultiRow(getActiveCell()))
1195 set(Tabular::SET_SPECIAL_MULTIROW, special);
1197 set(Tabular::SET_SPECIAL_COLUMN, special);
1201 void GuiTabular::setWidth(Tabular const & tabular, string const & width)
1203 if (tabular.isMultiColumn(getActiveCell()))
1204 set(Tabular::SET_MPWIDTH, width);
1206 set(Tabular::SET_PWIDTH, width);
1212 void GuiTabular::toggleMultiColumn()
1214 set(Tabular::MULTICOLUMN);
1219 void GuiTabular::toggleMultiRow()
1221 set(Tabular::MULTIROW);
1226 void GuiTabular::rotateTabular(bool yes)
1229 set(Tabular::SET_ROTATE_TABULAR);
1231 set(Tabular::UNSET_ROTATE_TABULAR);
1235 void GuiTabular::rotateCell(bool yes)
1238 set(Tabular::SET_ROTATE_CELL);
1240 set(Tabular::UNSET_ROTATE_CELL);
1244 void GuiTabular::halign(Tabular const & tabular, GuiTabular::HALIGN h)
1246 Tabular::Feature num = Tabular::ALIGN_LEFT;
1247 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
1251 num = Tabular::ALIGN_LEFT;
1252 multi_num = Tabular::M_ALIGN_LEFT;
1255 num = Tabular::ALIGN_CENTER;
1256 multi_num = Tabular::M_ALIGN_CENTER;
1259 num = Tabular::ALIGN_RIGHT;
1260 multi_num = Tabular::M_ALIGN_RIGHT;
1263 num = Tabular::ALIGN_BLOCK;
1264 //multi_num: no equivalent
1268 if (tabular.isMultiColumn(getActiveCell()))
1275 void GuiTabular::valign(Tabular const & tabular, GuiTabular::VALIGN v)
1277 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
1278 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
1282 num = Tabular::VALIGN_TOP;
1283 multi_num = Tabular::M_VALIGN_TOP;
1286 num = Tabular::VALIGN_MIDDLE;
1287 multi_num = Tabular::M_VALIGN_MIDDLE;
1290 num = Tabular::VALIGN_BOTTOM;
1291 multi_num = Tabular::M_VALIGN_BOTTOM;
1295 if (tabular.isMultiColumn(getActiveCell())
1296 || tabular.isMultiRow(getActiveCell()))
1303 void GuiTabular::booktabs(bool yes)
1306 set(Tabular::SET_BOOKTABS);
1308 set(Tabular::UNSET_BOOKTABS);
1312 void GuiTabular::longTabular(bool yes)
1315 set(Tabular::SET_LONGTABULAR);
1317 set(Tabular::UNSET_LONGTABULAR);
1321 // to get the status of the longtable row settings
1322 bool GuiTabular::funcEnabled(Tabular::Feature f) const
1325 FuncRequest(getLfun(), featureAsString(f))).enabled();
1329 Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); }
1332 } // namespace frontend
1335 #include "moc_GuiTabular.cpp"