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"
26 #include "FuncStatus.h"
29 #include "insets/InsetTabular.h"
32 #include <QPushButton>
33 #include <QRadioButton>
41 GuiTabular::GuiTabular(GuiView & lv)
42 : GuiDialog(lv, "tabular", qt_("Table Settings")),
43 // tabular_ is initialised at dialog construction in initialiseParams()
44 tabular_(*lv.buffer(), 0, 0)
46 active_cell_ = Tabular::npos;
50 widthED->setValidator(unsignedLengthValidator(widthED));
51 topspaceED->setValidator(new LengthValidator(topspaceED));
52 bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
53 interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
55 connect(topspaceED, SIGNAL(returnPressed()),
56 this, SLOT(topspace_changed()));
57 connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
58 this, SLOT(topspace_changed()));
59 connect(topspaceCO, SIGNAL(activated(int)),
60 this, SLOT(topspace_changed()));
61 connect(bottomspaceED, SIGNAL(returnPressed()),
62 this, SLOT(bottomspace_changed()));
63 connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
64 this, SLOT(bottomspace_changed()));
65 connect(bottomspaceCO, SIGNAL(activated(int)),
66 this, SLOT(bottomspace_changed()));
67 connect(interlinespaceED, SIGNAL(returnPressed()),
68 this, SLOT(interlinespace_changed()));
69 connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
70 this, SLOT(interlinespace_changed()));
71 connect(interlinespaceCO, SIGNAL(activated(int)),
72 this, SLOT(interlinespace_changed()));
73 connect(booktabsRB, SIGNAL(clicked(bool)),
74 this, SLOT(booktabsChanged(bool)));
75 connect(borderDefaultRB, SIGNAL(clicked(bool)),
76 this, SLOT(booktabsChanged(bool)));
77 connect(borderSetPB, SIGNAL(clicked()),
78 this, SLOT(borderSet_clicked()));
79 connect(borderUnsetPB, SIGNAL(clicked()),
80 this, SLOT(borderUnset_clicked()));
81 connect(longTabularCB, SIGNAL(toggled(bool)),
82 longtableGB, SLOT(setEnabled(bool)));
83 connect(longTabularCB, SIGNAL(toggled(bool)),
84 newpageCB, SLOT(setEnabled(bool)));
85 connect(longTabularCB, SIGNAL(toggled(bool)),
86 alignmentGB, SLOT(setEnabled(bool)));
87 connect(hAlignCB, SIGNAL(activated(int)),
88 this, SLOT(hAlign_changed(int)));
89 connect(vAlignCB, SIGNAL(activated(int)),
90 this, SLOT(vAlign_changed(int)));
91 connect(multicolumnCB, SIGNAL(clicked()),
92 this, SLOT(multicolumn_clicked()));
93 connect(newpageCB, SIGNAL(clicked()),
94 this, SLOT(ltNewpage_clicked()));
95 connect(headerStatusCB, SIGNAL(clicked()),
96 this, SLOT(ltHeaderStatus_clicked()));
97 connect(headerBorderAboveCB, SIGNAL(clicked()),
98 this, SLOT(ltHeaderBorderAbove_clicked()));
99 connect(headerBorderBelowCB, SIGNAL(clicked()),
100 this, SLOT(ltHeaderBorderBelow_clicked()));
101 connect(firstheaderStatusCB, SIGNAL(clicked()),
102 this, SLOT(ltFirstHeaderStatus_clicked()));
103 connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
104 this, SLOT(ltFirstHeaderBorderAbove_clicked()));
105 connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
106 this, SLOT(ltFirstHeaderBorderBelow_clicked()));
107 connect(firstheaderNoContentsCB, SIGNAL(clicked()),
108 this, SLOT(ltFirstHeaderEmpty_clicked()));
109 connect(footerStatusCB, SIGNAL(clicked()),
110 this, SLOT(ltFooterStatus_clicked()));
111 connect(footerBorderAboveCB, SIGNAL(clicked()),
112 this, SLOT(ltFooterBorderAbove_clicked()));
113 connect(footerBorderBelowCB, SIGNAL(clicked()),
114 this, SLOT(ltFooterBorderBelow_clicked()));
115 connect(lastfooterStatusCB, SIGNAL(clicked()),
116 this, SLOT(ltLastFooterStatus_clicked()));
117 connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
118 this, SLOT(ltLastFooterBorderAbove_clicked()));
119 connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
120 this, SLOT(ltLastFooterBorderBelow_clicked()));
121 connect(lastfooterNoContentsCB, SIGNAL(clicked()),
122 this, SLOT(ltLastFooterEmpty_clicked()));
123 connect(specialAlignmentED, SIGNAL(returnPressed()),
124 this, SLOT(specialAlignment_changed()));
125 connect(widthED, SIGNAL(editingFinished()),
126 this, SLOT(width_changed()));
127 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
128 this, SLOT(width_changed()));
129 connect(closePB, SIGNAL(clicked()),
130 this, SLOT(close_clicked()));
131 connect(borders, SIGNAL(topSet(bool)),
132 this, SLOT(topBorder_changed()));
133 connect(borders, SIGNAL(bottomSet(bool)),
134 this, SLOT(bottomBorder_changed()));
135 connect(borders, SIGNAL(rightSet(bool)),
136 this, SLOT(rightBorder_changed()));
137 connect(borders, SIGNAL(leftSet(bool)),
138 this, SLOT(leftBorder_changed()));
139 connect(rotateTabularCB, SIGNAL(clicked()),
140 this, SLOT(rotateTabular()));
141 connect(rotateCellCB, SIGNAL(clicked()),
142 this, SLOT(rotateCell()));
143 connect(TableAlignCB, SIGNAL(activated(int)),
144 this, SLOT(tableAlignment_changed(int)));
145 connect(longTabularCB, SIGNAL(clicked()),
146 this, SLOT(longTabular()));
147 connect(leftRB, SIGNAL(clicked()),
148 this, SLOT(ltAlignment_clicked()));
149 connect(centerRB, SIGNAL(clicked()),
150 this, SLOT(ltAlignment_clicked()));
151 connect(rightRB, SIGNAL(clicked()),
152 this, SLOT(ltAlignment_clicked()));
154 bc().setPolicy(ButtonPolicy::IgnorantPolicy);
156 bc().addReadOnly(topspaceED);
157 bc().addReadOnly(topspaceUnit);
158 bc().addReadOnly(topspaceCO);
159 bc().addReadOnly(bottomspaceED);
160 bc().addReadOnly(bottomspaceUnit);
161 bc().addReadOnly(bottomspaceCO);
162 bc().addReadOnly(interlinespaceED);
163 bc().addReadOnly(interlinespaceUnit);
164 bc().addReadOnly(interlinespaceCO);
165 bc().addReadOnly(borderDefaultRB);
166 bc().addReadOnly(booktabsRB);
168 bc().addReadOnly(multicolumnCB);
169 bc().addReadOnly(rotateCellCB);
170 bc().addReadOnly(rotateTabularCB);
171 bc().addReadOnly(specialAlignmentED);
172 bc().addReadOnly(widthED);
173 bc().addReadOnly(widthUnit);
174 bc().addReadOnly(hAlignCB);
175 bc().addReadOnly(vAlignCB);
176 bc().addReadOnly(TableAlignCB);
177 bc().addReadOnly(borderSetPB);
178 bc().addReadOnly(borderUnsetPB);
179 bc().addReadOnly(borders);
180 bc().addReadOnly(longTabularCB);
181 bc().addReadOnly(headerStatusCB);
182 bc().addReadOnly(headerBorderAboveCB);
183 bc().addReadOnly(headerBorderBelowCB);
184 bc().addReadOnly(firstheaderStatusCB);
185 bc().addReadOnly(firstheaderBorderAboveCB);
186 bc().addReadOnly(firstheaderBorderBelowCB);
187 bc().addReadOnly(firstheaderNoContentsCB);
188 bc().addReadOnly(footerStatusCB);
189 bc().addReadOnly(footerBorderAboveCB);
190 bc().addReadOnly(footerBorderBelowCB);
191 bc().addReadOnly(lastfooterStatusCB);
192 bc().addReadOnly(lastfooterBorderAboveCB);
193 bc().addReadOnly(lastfooterBorderBelowCB);
194 bc().addReadOnly(lastfooterNoContentsCB);
195 bc().addReadOnly(newpageCB);
196 bc().addReadOnly(leftRB);
197 bc().addReadOnly(centerRB);
198 bc().addReadOnly(rightRB);
200 // initialize the length validator
201 bc().addCheckedLineEdit(widthED, fixedWidthColLA);
202 bc().addCheckedLineEdit(topspaceED, topspaceLA);
203 bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA);
204 bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA);
208 GuiTabular::~GuiTabular()
213 void GuiTabular::change_adaptor()
219 void GuiTabular::booktabsChanged(bool)
222 booktabs(booktabsRB->isChecked());
227 void GuiTabular::topspace_changed()
229 switch (topspaceCO->currentIndex()) {
231 set(Tabular::SET_TOP_SPACE, "");
232 topspaceED->setEnabled(false);
233 topspaceUnit->setEnabled(false);
237 set(Tabular::SET_TOP_SPACE, "default");
238 topspaceED->setEnabled(false);
239 topspaceUnit->setEnabled(false);
243 if (!topspaceED->text().isEmpty())
244 set(Tabular::SET_TOP_SPACE,
245 widgetsToLength(topspaceED,
247 if (!bc().policy().isReadOnly()) {
248 topspaceED->setEnabled(true);
249 topspaceUnit->setEnabled(true);
258 void GuiTabular::bottomspace_changed()
260 switch (bottomspaceCO->currentIndex()) {
262 set(Tabular::SET_BOTTOM_SPACE, "");
263 bottomspaceED->setEnabled(false);
264 bottomspaceUnit->setEnabled(false);
268 set(Tabular::SET_BOTTOM_SPACE, "default");
269 bottomspaceED->setEnabled(false);
270 bottomspaceUnit->setEnabled(false);
274 if (!bottomspaceED->text().isEmpty())
275 set(Tabular::SET_BOTTOM_SPACE,
276 widgetsToLength(bottomspaceED,
278 if (!bc().policy().isReadOnly()) {
279 bottomspaceED->setEnabled(true);
280 bottomspaceUnit->setEnabled(true);
289 void GuiTabular::interlinespace_changed()
291 switch (interlinespaceCO->currentIndex()) {
293 set(Tabular::SET_INTERLINE_SPACE, "");
294 interlinespaceED->setEnabled(false);
295 interlinespaceUnit->setEnabled(false);
299 set(Tabular::SET_INTERLINE_SPACE, "default");
300 interlinespaceED->setEnabled(false);
301 interlinespaceUnit->setEnabled(false);
305 if (!interlinespaceED->text().isEmpty())
306 set(Tabular::SET_INTERLINE_SPACE,
307 widgetsToLength(interlinespaceED,
308 interlinespaceUnit));
309 if (!bc().policy().isReadOnly()) {
310 interlinespaceED->setEnabled(true);
311 interlinespaceUnit->setEnabled(true);
320 void GuiTabular::close_clicked()
327 void GuiTabular::borderSet_clicked()
329 set(Tabular::SET_ALL_LINES);
335 void GuiTabular::borderUnset_clicked()
337 set(Tabular::UNSET_ALL_LINES);
343 void GuiTabular::leftBorder_changed()
345 set(Tabular::TOGGLE_LINE_LEFT);
350 void GuiTabular::rightBorder_changed()
352 set(Tabular::TOGGLE_LINE_RIGHT);
357 void GuiTabular::topBorder_changed()
359 set(Tabular::TOGGLE_LINE_TOP);
364 void GuiTabular::bottomBorder_changed()
366 set(Tabular::TOGGLE_LINE_BOTTOM);
371 void GuiTabular::specialAlignment_changed()
373 string special = fromqstr(specialAlignmentED->text());
379 void GuiTabular::width_changed()
382 string const width = widgetsToLength(widthED, widthUnit);
387 void GuiTabular::multicolumn_clicked()
394 void GuiTabular::rotateTabular()
396 rotateTabular(rotateTabularCB->isChecked());
401 void GuiTabular::rotateCell()
403 rotateCell(rotateCellCB->isChecked());
408 void GuiTabular::hAlign_changed(int align)
410 GuiTabular::HALIGN h = GuiTabular::LEFT;
413 case 0: h = GuiTabular::LEFT; break;
414 case 1: h = GuiTabular::CENTER; break;
415 case 2: h = GuiTabular::RIGHT; break;
416 case 3: h = GuiTabular::BLOCK; break;
423 void GuiTabular::vAlign_changed(int align)
425 GuiTabular::VALIGN v = GuiTabular::TOP;
428 case 0: v = GuiTabular::TOP; break;
429 case 1: v = GuiTabular::MIDDLE; break;
430 case 2: v = GuiTabular::BOTTOM; break;
437 void GuiTabular::tableAlignment_changed(int align)
440 case 0: set(Tabular::TABULAR_VALIGN_TOP);
442 case 1: set(Tabular::TABULAR_VALIGN_MIDDLE);
444 case 2: set(Tabular::TABULAR_VALIGN_BOTTOM);
450 void GuiTabular::longTabular()
452 longTabular(longTabularCB->isChecked());
457 void GuiTabular::ltNewpage_clicked()
459 set(Tabular::SET_LTNEWPAGE);
464 void GuiTabular::on_captionStatusCB_toggled()
466 set(Tabular::TOGGLE_LTCAPTION);
471 void GuiTabular::ltHeaderStatus_clicked()
473 bool enable = headerStatusCB->isChecked();
475 set(Tabular::SET_LTHEAD, "");
477 set(Tabular::UNSET_LTHEAD, "");
482 void GuiTabular::ltHeaderBorderAbove_clicked()
484 if (headerBorderAboveCB->isChecked())
485 set(Tabular::SET_LTHEAD, "dl_above");
487 set(Tabular::UNSET_LTHEAD, "dl_above");
492 void GuiTabular::ltHeaderBorderBelow_clicked()
494 if (headerBorderBelowCB->isChecked())
495 set(Tabular::SET_LTHEAD, "dl_below");
497 set(Tabular::UNSET_LTHEAD, "dl_below");
502 void GuiTabular::ltFirstHeaderBorderAbove_clicked()
504 if (firstheaderBorderAboveCB->isChecked())
505 set(Tabular::SET_LTFIRSTHEAD, "dl_above");
507 set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
512 void GuiTabular::ltFirstHeaderBorderBelow_clicked()
514 if (firstheaderBorderBelowCB->isChecked())
515 set(Tabular::SET_LTFIRSTHEAD, "dl_below");
517 set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
522 void GuiTabular::ltFirstHeaderStatus_clicked()
524 bool enable = firstheaderStatusCB->isChecked();
526 set(Tabular::SET_LTFIRSTHEAD, "");
528 set(Tabular::UNSET_LTFIRSTHEAD, "");
533 void GuiTabular::ltFirstHeaderEmpty_clicked()
535 bool enable = firstheaderNoContentsCB->isChecked();
537 set(Tabular::SET_LTFIRSTHEAD, "empty");
539 set(Tabular::UNSET_LTFIRSTHEAD, "empty");
544 void GuiTabular::ltFooterStatus_clicked()
546 bool enable = footerStatusCB->isChecked();
548 set(Tabular::SET_LTFOOT, "");
550 set(Tabular::UNSET_LTFOOT, "");
555 void GuiTabular::ltFooterBorderAbove_clicked()
557 if (footerBorderAboveCB->isChecked())
558 set(Tabular::SET_LTFOOT, "dl_above");
560 set(Tabular::UNSET_LTFOOT, "dl_above");
565 void GuiTabular::ltFooterBorderBelow_clicked()
567 if (footerBorderBelowCB->isChecked())
568 set(Tabular::SET_LTFOOT, "dl_below");
570 set(Tabular::UNSET_LTFOOT, "dl_below");
575 void GuiTabular::ltLastFooterStatus_clicked()
577 bool enable = lastfooterStatusCB->isChecked();
579 set(Tabular::SET_LTLASTFOOT, "");
581 set(Tabular::UNSET_LTLASTFOOT, "");
586 void GuiTabular::ltLastFooterBorderAbove_clicked()
588 if (lastfooterBorderAboveCB->isChecked())
589 set(Tabular::SET_LTLASTFOOT, "dl_above");
591 set(Tabular::UNSET_LTLASTFOOT, "dl_above");
596 void GuiTabular::ltLastFooterBorderBelow_clicked()
598 if (lastfooterBorderBelowCB->isChecked())
599 set(Tabular::SET_LTLASTFOOT, "dl_below");
601 set(Tabular::UNSET_LTLASTFOOT, "dl_below");
606 void GuiTabular::ltLastFooterEmpty_clicked()
608 bool enable = lastfooterNoContentsCB->isChecked();
610 set(Tabular::SET_LTLASTFOOT, "empty");
612 set(Tabular::UNSET_LTLASTFOOT, "empty");
617 void GuiTabular::ltAlignment_clicked()
619 if (leftRB->isChecked())
620 set(Tabular::LONGTABULAR_ALIGN_LEFT);
621 else if (centerRB->isChecked())
622 set(Tabular::LONGTABULAR_ALIGN_CENTER);
623 else if (rightRB->isChecked())
624 set(Tabular::LONGTABULAR_ALIGN_RIGHT);
629 void GuiTabular::update_borders()
631 Tabular::idx_type const cell = getActiveCell();
632 borders->setTop(tabular_.topLine(cell));
633 borders->setBottom(tabular_.bottomLine(cell));
634 borders->setLeft(tabular_.leftLine(cell));
635 borders->setRight(tabular_.rightLine(cell));
636 // repaint the setborder widget
643 Length getColumnPWidth(Tabular const & t, size_t cell)
645 return t.column_info[t.cellColumn(cell)].p_width;
649 Length getMColumnPWidth(Tabular const & t, size_t cell)
651 if (t.isMultiColumn(cell))
652 return t.cellInfo(cell).p_width;
657 docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
659 if (what == Tabular::SET_SPECIAL_MULTI)
660 return t.cellInfo(cell).align_special;
661 return t.column_info[t.cellColumn(cell)].align_special;
668 void GuiTabular::updateContents()
670 initialiseParams(string());
672 size_t const cell = getActiveCell();
674 Tabular::row_type const row = tabular_.cellRow(cell);
675 Tabular::col_type const col = tabular_.cellColumn(cell);
677 tabularRowED->setText(QString::number(row + 1));
678 tabularColumnED->setText(QString::number(col + 1));
680 bool const multicol(tabular_.isMultiColumn(cell));
682 multicolumnCB->setChecked(multicol);
684 rotateCellCB->setChecked(tabular_.getRotateCell(cell));
685 rotateTabularCB->setChecked(tabular_.rotate);
687 longTabularCB->setChecked(tabular_.is_long_tabular);
695 special = getAlignSpecial(tabular_, cell,
696 Tabular::SET_SPECIAL_MULTI);
697 pwidth = getMColumnPWidth(tabular_, cell);
699 special = getAlignSpecial(tabular_, cell,
700 Tabular::SET_SPECIAL_COLUMN);
701 pwidth = getColumnPWidth(tabular_, cell);
704 specialAlignmentED->setText(toqstr(special));
706 bool const isReadonly = bc().policy().isReadOnly();
707 specialAlignmentED->setEnabled(!isReadonly);
709 Length::UNIT const default_unit = Length::defaultUnit();
711 borderDefaultRB->setChecked(!tabular_.use_booktabs);
712 booktabsRB->setChecked(tabular_.use_booktabs);
714 if (tabular_.row_info[row].top_space.empty()
715 && !tabular_.row_info[row].top_space_default) {
716 topspaceCO->setCurrentIndex(0);
717 } else if (tabular_.row_info[row].top_space_default) {
718 topspaceCO->setCurrentIndex(1);
720 topspaceCO->setCurrentIndex(2);
721 lengthToWidgets(topspaceED,
723 tabular_.row_info[row].top_space.asString(),
726 topspaceED->setEnabled(!isReadonly
727 && (topspaceCO->currentIndex() == 2));
728 topspaceUnit->setEnabled(!isReadonly
729 && (topspaceCO->currentIndex() == 2));
730 topspaceCO->setEnabled(!isReadonly);
732 if (tabular_.row_info[row].bottom_space.empty()
733 && !tabular_.row_info[row].bottom_space_default) {
734 bottomspaceCO->setCurrentIndex(0);
735 } else if (tabular_.row_info[row].bottom_space_default) {
736 bottomspaceCO->setCurrentIndex(1);
738 bottomspaceCO->setCurrentIndex(2);
739 lengthToWidgets(bottomspaceED,
741 tabular_.row_info[row].bottom_space.asString(),
744 bottomspaceED->setEnabled(!isReadonly
745 && (bottomspaceCO->currentIndex() == 2));
746 bottomspaceUnit->setEnabled(!isReadonly
747 && (bottomspaceCO->currentIndex() == 2));
748 bottomspaceCO->setEnabled(!isReadonly);
750 if (tabular_.row_info[row].interline_space.empty()
751 && !tabular_.row_info[row].interline_space_default) {
752 interlinespaceCO->setCurrentIndex(0);
753 } else if (tabular_.row_info[row].interline_space_default) {
754 interlinespaceCO->setCurrentIndex(1);
756 interlinespaceCO->setCurrentIndex(2);
757 lengthToWidgets(interlinespaceED,
759 tabular_.row_info[row].interline_space.asString(),
762 interlinespaceED->setEnabled(!isReadonly
763 && (interlinespaceCO->currentIndex() == 2));
764 interlinespaceUnit->setEnabled(!isReadonly
765 && (interlinespaceCO->currentIndex() == 2));
766 interlinespaceCO->setEnabled(!isReadonly);
770 colwidth = pwidth.asString();
771 lengthToWidgets(widthED, widthUnit,
772 colwidth, default_unit);
774 widthED->setEnabled(!isReadonly);
775 widthUnit->setEnabled(!isReadonly);
778 hAlignCB->addItem(qt_("Left"));
779 hAlignCB->addItem(qt_("Center"));
780 hAlignCB->addItem(qt_("Right"));
781 if (!multicol && !pwidth.zero())
782 hAlignCB->addItem(qt_("Justified"));
785 switch (tabular_.getAlignment(cell)) {
789 case LYX_ALIGN_CENTER:
792 case LYX_ALIGN_RIGHT:
795 case LYX_ALIGN_BLOCK:
797 if (!multicol && !pwidth.zero())
805 hAlignCB->setCurrentIndex(align);
808 switch (tabular_.getVAlignment(cell)) {
809 case Tabular::LYX_VALIGN_TOP:
812 case Tabular::LYX_VALIGN_MIDDLE:
815 case Tabular::LYX_VALIGN_BOTTOM:
824 vAlignCB->setCurrentIndex(valign);
826 hAlignCB->setEnabled(true);
827 vAlignCB->setEnabled(!pwidth.zero());
830 switch (tabular_.tabular_valignment) {
831 case Tabular::LYX_VALIGN_TOP:
834 case Tabular::LYX_VALIGN_MIDDLE:
837 case Tabular::LYX_VALIGN_BOTTOM:
844 TableAlignCB->setCurrentIndex(tableValign);
846 if (!tabular_.is_long_tabular) {
847 headerStatusCB->setChecked(false);
848 headerBorderAboveCB->setChecked(false);
849 headerBorderBelowCB->setChecked(false);
850 firstheaderStatusCB->setChecked(false);
851 firstheaderBorderAboveCB->setChecked(false);
852 firstheaderBorderBelowCB->setChecked(false);
853 firstheaderNoContentsCB->setChecked(false);
854 footerStatusCB->setChecked(false);
855 footerBorderAboveCB->setChecked(false);
856 footerBorderBelowCB->setChecked(false);
857 lastfooterStatusCB->setChecked(false);
858 lastfooterBorderAboveCB->setChecked(false);
859 lastfooterBorderBelowCB->setChecked(false);
860 lastfooterNoContentsCB->setChecked(false);
861 newpageCB->setChecked(false);
862 newpageCB->setEnabled(false);
863 captionStatusCB->blockSignals(true);
864 captionStatusCB->setChecked(false);
865 captionStatusCB->blockSignals(false);
869 switch (tabular_.longtabular_alignment) {
870 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
871 leftRB->setChecked(true);
873 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
874 centerRB->setChecked(true);
876 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
877 rightRB->setChecked(true);
880 centerRB->setChecked(true);
883 captionStatusCB->blockSignals(true);
884 captionStatusCB->setChecked(tabular_.ltCaption(row));
885 captionStatusCB->blockSignals(false);
887 // FIXME: shouldn't this be handled by GuiDialog?
888 // FIXME: Some of them should be handled directly in TabularUI.ui
889 firstheaderBorderAboveCB->setEnabled(
890 funcEnabled(Tabular::SET_LTFIRSTHEAD));
891 firstheaderBorderBelowCB->setEnabled(
892 funcEnabled(Tabular::SET_LTFIRSTHEAD));
893 // first header can only be suppressed when there is a header
894 firstheaderNoContentsCB->setEnabled(tabular_.haveLTHead()
895 && !tabular_.haveLTFirstHead());
897 //firstheaderStatusCB->setEnabled(
898 // !firstheaderNoContentsCB->isChecked());
899 headerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
900 headerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
901 headerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
903 footerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
904 footerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
905 footerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
907 lastfooterBorderAboveCB->setEnabled(
908 funcEnabled(Tabular::SET_LTLASTFOOT));
909 lastfooterBorderBelowCB->setEnabled(
910 funcEnabled(Tabular::SET_LTLASTFOOT));
911 // last footer can only be suppressed when there is a footer
912 lastfooterNoContentsCB->setEnabled(tabular_.haveLTFoot()
913 && !tabular_.haveLTLastFoot());
915 captionStatusCB->setEnabled(
916 funcEnabled(Tabular::TOGGLE_LTCAPTION));
917 // When a row is set as longtable caption, it must not be allowed
918 // to unset that this row is a multicolumn.
919 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
923 bool row_set = tabular_.getRowOfLTHead(row, ltt);
924 headerStatusCB->setChecked(row_set);
926 headerBorderAboveCB->setChecked(ltt.topDL);
927 headerBorderBelowCB->setChecked(ltt.bottomDL);
930 headerBorderAboveCB->setChecked(false);
931 headerBorderBelowCB->setChecked(false);
932 headerBorderAboveCB->setEnabled(false);
933 headerBorderBelowCB->setEnabled(false);
934 firstheaderNoContentsCB->setChecked(false);
935 firstheaderNoContentsCB->setEnabled(false);
939 row_set = tabular_.getRowOfLTFirstHead(row, ltt);
940 // check if setting a first header is allowed
941 // additionally check firstheaderNoContentsCB because when this is
942 // the case a first header makes no sense
943 firstheaderStatusCB->setEnabled(
944 funcEnabled(Tabular::SET_LTFIRSTHEAD)
945 && !firstheaderNoContentsCB->isChecked());
946 firstheaderStatusCB->setChecked(row_set);
947 if (ltt.set && (!ltt.empty || !use_empty)) {
948 firstheaderBorderAboveCB->setChecked(ltt.topDL);
949 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
951 firstheaderBorderAboveCB->setEnabled(false);
952 firstheaderBorderBelowCB->setEnabled(false);
953 firstheaderBorderAboveCB->setChecked(false);
954 firstheaderBorderBelowCB->setChecked(false);
957 firstheaderStatusCB->setEnabled(false);
961 row_set = tabular_.getRowOfLTFoot(row, ltt);
962 footerStatusCB->setChecked(row_set);
964 footerBorderAboveCB->setChecked(ltt.topDL);
965 footerBorderBelowCB->setChecked(ltt.bottomDL);
968 footerBorderAboveCB->setChecked(false);
969 footerBorderBelowCB->setChecked(false);
970 footerBorderAboveCB->setEnabled(false);
971 footerBorderBelowCB->setEnabled(false);
972 lastfooterNoContentsCB->setChecked(false);
973 lastfooterNoContentsCB->setEnabled(false);
977 row_set = tabular_.getRowOfLTLastFoot(row, ltt);
978 // check if setting a last footer is allowed
979 // additionally check lastfooterNoContentsCB because when this is
980 // the case a last footer makes no sense
981 lastfooterStatusCB->setEnabled(
982 funcEnabled(Tabular::SET_LTLASTFOOT)
983 && !lastfooterNoContentsCB->isChecked());
984 lastfooterStatusCB->setChecked(row_set);
985 if (ltt.set && (!ltt.empty || !use_empty)) {
986 lastfooterBorderAboveCB->setChecked(ltt.topDL);
987 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
989 lastfooterBorderAboveCB->setEnabled(false);
990 lastfooterBorderBelowCB->setEnabled(false);
991 lastfooterBorderAboveCB->setChecked(false);
992 lastfooterBorderBelowCB->setChecked(false);
995 lastfooterStatusCB->setEnabled(false);
998 newpageCB->setChecked(tabular_.getLTNewPage(row));
1002 void GuiTabular::closeGUI()
1004 // ugly hack to auto-apply the stuff that hasn't been
1005 // yet. don't let this continue to exist ...
1007 // Subtle here, we must /not/ apply any changes and
1008 // then refer to tabular, as it will have been freed
1009 // since the changes update the actual tabular_
1011 // apply the fixed width values
1012 size_t const cell = getActiveCell();
1013 bool const multicol = tabular_.isMultiColumn(cell);
1014 string width = widgetsToLength(widthED, widthUnit);
1017 Length llen = getColumnPWidth(tabular_, cell);
1018 Length llenMulti = getMColumnPWidth(tabular_, cell);
1020 if (multicol && !llenMulti.zero())
1021 width2 = llenMulti.asString();
1022 else if (!multicol && !llen.zero())
1023 width2 = llen.asString();
1025 // apply the special alignment
1026 docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text());
1030 sa2 = getAlignSpecial(tabular_, cell,
1031 Tabular::SET_SPECIAL_MULTI);
1033 sa2 = getAlignSpecial(tabular_, cell,
1034 Tabular::SET_SPECIAL_COLUMN);
1038 set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
1040 set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
1043 if (width != width2) {
1045 set(Tabular::SET_MPWIDTH, width);
1047 set(Tabular::SET_PWIDTH, width);
1051 switch (topspaceCO->currentIndex()) {
1053 set(Tabular::SET_TOP_SPACE, "");
1056 set(Tabular::SET_TOP_SPACE, "default");
1059 set(Tabular::SET_TOP_SPACE,
1060 widgetsToLength(topspaceED,
1065 switch (bottomspaceCO->currentIndex()) {
1067 set(Tabular::SET_BOTTOM_SPACE, "");
1070 set(Tabular::SET_BOTTOM_SPACE, "default");
1073 set(Tabular::SET_BOTTOM_SPACE,
1074 widgetsToLength(bottomspaceED,
1079 switch (interlinespaceCO->currentIndex()) {
1081 set(Tabular::SET_INTERLINE_SPACE, "");
1084 set(Tabular::SET_INTERLINE_SPACE, "default");
1087 set(Tabular::SET_INTERLINE_SPACE,
1088 widgetsToLength(interlinespaceED,
1089 interlinespaceUnit));
1096 bool GuiTabular::initialiseParams(string const & data)
1098 // try to get the current cell
1099 BufferView const * const bv = bufferview();
1100 InsetTabular const * current_inset = 0;
1102 Cursor const & cur = bv->cursor();
1103 // get the innermost tabular inset;
1104 // assume that it is "ours"
1105 for (int i = cur.depth() - 1; i >= 0; --i)
1106 if (cur[i].inset().lyxCode() == TABULAR_CODE) {
1108 static_cast<InsetTabular const *>(&cur[i].inset());
1109 active_cell_ = cur[i].idx();
1114 if (current_inset && data.empty()) {
1115 tabular_ = Tabular(current_inset->tabular);
1119 InsetTabular tmp(const_cast<Buffer &>(buffer()));
1120 InsetTabular::string2params(data, tmp);
1121 tabular_ = Tabular(tmp.tabular);
1126 void GuiTabular::clearParams()
1128 // This function is also called when LyX is closing and the dialog
1129 // is still open. At that time, the buffer might not be available
1131 if (isBufferAvailable()) {
1132 InsetTabular tmp(const_cast<Buffer &>(buffer()));
1133 tabular_ = tmp.tabular;
1135 active_cell_ = Tabular::npos;
1139 Tabular::idx_type GuiTabular::getActiveCell() const
1141 return active_cell_;
1145 void GuiTabular::set(Tabular::Feature f, string const & arg)
1147 string const data = featureAsString(f) + ' ' + arg;
1148 dispatch(FuncRequest(getLfun(), data));
1152 void GuiTabular::setSpecial(string const & special)
1154 if (tabular_.isMultiColumn(getActiveCell()))
1155 set(Tabular::SET_SPECIAL_MULTI, special);
1157 set(Tabular::SET_SPECIAL_COLUMN, special);
1161 void GuiTabular::setWidth(string const & width)
1163 if (tabular_.isMultiColumn(getActiveCell()))
1164 set(Tabular::SET_MPWIDTH, width);
1166 set(Tabular::SET_PWIDTH, width);
1172 void GuiTabular::toggleMultiColumn()
1174 set(Tabular::MULTICOLUMN);
1179 void GuiTabular::rotateTabular(bool yes)
1182 set(Tabular::SET_ROTATE_TABULAR);
1184 set(Tabular::UNSET_ROTATE_TABULAR);
1188 void GuiTabular::rotateCell(bool yes)
1191 set(Tabular::SET_ROTATE_CELL);
1193 set(Tabular::UNSET_ROTATE_CELL);
1197 void GuiTabular::halign(GuiTabular::HALIGN h)
1199 Tabular::Feature num = Tabular::ALIGN_LEFT;
1200 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
1204 num = Tabular::ALIGN_LEFT;
1205 multi_num = Tabular::M_ALIGN_LEFT;
1208 num = Tabular::ALIGN_CENTER;
1209 multi_num = Tabular::M_ALIGN_CENTER;
1212 num = Tabular::ALIGN_RIGHT;
1213 multi_num = Tabular::M_ALIGN_RIGHT;
1216 num = Tabular::ALIGN_BLOCK;
1217 //multi_num: no equivalent
1221 if (tabular_.isMultiColumn(getActiveCell()))
1228 void GuiTabular::valign(GuiTabular::VALIGN v)
1230 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
1231 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
1235 num = Tabular::VALIGN_TOP;
1236 multi_num = Tabular::M_VALIGN_TOP;
1239 num = Tabular::VALIGN_MIDDLE;
1240 multi_num = Tabular::M_VALIGN_MIDDLE;
1243 num = Tabular::VALIGN_BOTTOM;
1244 multi_num = Tabular::M_VALIGN_BOTTOM;
1248 if (tabular_.isMultiColumn(getActiveCell()))
1255 void GuiTabular::booktabs(bool yes)
1258 set(Tabular::SET_BOOKTABS);
1260 set(Tabular::UNSET_BOOKTABS);
1264 void GuiTabular::longTabular(bool yes)
1267 set(Tabular::SET_LONGTABULAR);
1269 set(Tabular::UNSET_LONGTABULAR);
1273 // to get the status of the longtable row settings
1274 bool GuiTabular::funcEnabled(Tabular::Feature f) const
1277 FuncRequest(getLfun(), featureAsString(f))).enabled();
1281 Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); }
1284 } // namespace frontend
1287 #include "moc_GuiTabular.cpp"