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(newpageCB, SIGNAL(clicked()),
100 this, SLOT(ltNewpage_clicked()));
101 connect(headerStatusCB, SIGNAL(clicked()),
102 this, SLOT(ltHeaderStatus_clicked()));
103 connect(headerBorderAboveCB, SIGNAL(clicked()),
104 this, SLOT(ltHeaderBorderAbove_clicked()));
105 connect(headerBorderBelowCB, SIGNAL(clicked()),
106 this, SLOT(ltHeaderBorderBelow_clicked()));
107 connect(firstheaderStatusCB, SIGNAL(clicked()),
108 this, SLOT(ltFirstHeaderStatus_clicked()));
109 connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
110 this, SLOT(ltFirstHeaderBorderAbove_clicked()));
111 connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
112 this, SLOT(ltFirstHeaderBorderBelow_clicked()));
113 connect(firstheaderNoContentsCB, SIGNAL(clicked()),
114 this, SLOT(ltFirstHeaderEmpty_clicked()));
115 connect(footerStatusCB, SIGNAL(clicked()),
116 this, SLOT(ltFooterStatus_clicked()));
117 connect(footerBorderAboveCB, SIGNAL(clicked()),
118 this, SLOT(ltFooterBorderAbove_clicked()));
119 connect(footerBorderBelowCB, SIGNAL(clicked()),
120 this, SLOT(ltFooterBorderBelow_clicked()));
121 connect(lastfooterStatusCB, SIGNAL(clicked()),
122 this, SLOT(ltLastFooterStatus_clicked()));
123 connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
124 this, SLOT(ltLastFooterBorderAbove_clicked()));
125 connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
126 this, SLOT(ltLastFooterBorderBelow_clicked()));
127 connect(lastfooterNoContentsCB, SIGNAL(clicked()),
128 this, SLOT(ltLastFooterEmpty_clicked()));
129 connect(specialAlignmentED, SIGNAL(returnPressed()),
130 this, SLOT(specialAlignment_changed()));
131 connect(widthED, SIGNAL(editingFinished()),
132 this, SLOT(width_changed()));
133 connect(widthUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
134 this, SLOT(width_changed()));
135 connect(closePB, SIGNAL(clicked()),
136 this, SLOT(close_clicked()));
137 connect(borders, SIGNAL(topSet(bool)),
138 this, SLOT(topBorder_changed()));
139 connect(borders, SIGNAL(bottomSet(bool)),
140 this, SLOT(bottomBorder_changed()));
141 connect(borders, SIGNAL(rightSet(bool)),
142 this, SLOT(rightBorder_changed()));
143 connect(borders, SIGNAL(leftSet(bool)),
144 this, SLOT(leftBorder_changed()));
145 connect(rotateTabularCB, SIGNAL(clicked()),
146 this, SLOT(rotateTabular()));
147 connect(rotateCellCB, SIGNAL(clicked()),
148 this, SLOT(rotateCell()));
149 connect(TableAlignCB, SIGNAL(activated(int)),
150 this, SLOT(tableAlignment_changed(int)));
151 connect(longTabularCB, SIGNAL(clicked()),
152 this, SLOT(longTabular()));
153 connect(leftRB, SIGNAL(clicked()),
154 this, SLOT(ltAlignment_clicked()));
155 connect(centerRB, SIGNAL(clicked()),
156 this, SLOT(ltAlignment_clicked()));
157 connect(rightRB, SIGNAL(clicked()),
158 this, SLOT(ltAlignment_clicked()));
160 bc().setPolicy(ButtonPolicy::IgnorantPolicy);
162 bc().addReadOnly(topspaceED);
163 bc().addReadOnly(topspaceUnit);
164 bc().addReadOnly(topspaceCO);
165 bc().addReadOnly(bottomspaceED);
166 bc().addReadOnly(bottomspaceUnit);
167 bc().addReadOnly(bottomspaceCO);
168 bc().addReadOnly(interlinespaceED);
169 bc().addReadOnly(interlinespaceUnit);
170 bc().addReadOnly(interlinespaceCO);
171 bc().addReadOnly(borderDefaultRB);
172 bc().addReadOnly(booktabsRB);
174 bc().addReadOnly(multicolumnCB);
175 bc().addReadOnly(rotateCellCB);
176 bc().addReadOnly(rotateTabularCB);
177 bc().addReadOnly(specialAlignmentED);
178 bc().addReadOnly(widthED);
179 bc().addReadOnly(widthUnitCB);
180 bc().addReadOnly(hAlignCB);
181 bc().addReadOnly(vAlignCB);
182 bc().addReadOnly(TableAlignCB);
183 bc().addReadOnly(borderSetPB);
184 bc().addReadOnly(borderUnsetPB);
185 bc().addReadOnly(borders);
186 bc().addReadOnly(longTabularCB);
187 bc().addReadOnly(headerStatusCB);
188 bc().addReadOnly(headerBorderAboveCB);
189 bc().addReadOnly(headerBorderBelowCB);
190 bc().addReadOnly(firstheaderStatusCB);
191 bc().addReadOnly(firstheaderBorderAboveCB);
192 bc().addReadOnly(firstheaderBorderBelowCB);
193 bc().addReadOnly(firstheaderNoContentsCB);
194 bc().addReadOnly(footerStatusCB);
195 bc().addReadOnly(footerBorderAboveCB);
196 bc().addReadOnly(footerBorderBelowCB);
197 bc().addReadOnly(lastfooterStatusCB);
198 bc().addReadOnly(lastfooterBorderAboveCB);
199 bc().addReadOnly(lastfooterBorderBelowCB);
200 bc().addReadOnly(lastfooterNoContentsCB);
201 bc().addReadOnly(newpageCB);
202 bc().addReadOnly(leftRB);
203 bc().addReadOnly(centerRB);
204 bc().addReadOnly(rightRB);
206 // initialize the length validator
207 bc().addCheckedLineEdit(widthED, fixedWidthColLA);
208 bc().addCheckedLineEdit(topspaceED, topspaceLA);
209 bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA);
210 bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA);
214 GuiTabular::~GuiTabular()
219 void GuiTabular::change_adaptor()
225 void GuiTabular::booktabsChanged(bool)
228 booktabs(booktabsRB->isChecked());
233 void GuiTabular::topspace_changed()
235 switch (topspaceCO->currentIndex()) {
237 set(Tabular::SET_TOP_SPACE, "");
238 topspaceED->setEnabled(false);
239 topspaceUnit->setEnabled(false);
243 set(Tabular::SET_TOP_SPACE, "default");
244 topspaceED->setEnabled(false);
245 topspaceUnit->setEnabled(false);
249 if (!topspaceED->text().isEmpty())
250 set(Tabular::SET_TOP_SPACE,
251 widgetsToLength(topspaceED,
253 if (!bc().policy().isReadOnly()) {
254 topspaceED->setEnabled(true);
255 topspaceUnit->setEnabled(true);
264 void GuiTabular::bottomspace_changed()
266 switch (bottomspaceCO->currentIndex()) {
268 set(Tabular::SET_BOTTOM_SPACE, "");
269 bottomspaceED->setEnabled(false);
270 bottomspaceUnit->setEnabled(false);
274 set(Tabular::SET_BOTTOM_SPACE, "default");
275 bottomspaceED->setEnabled(false);
276 bottomspaceUnit->setEnabled(false);
280 if (!bottomspaceED->text().isEmpty())
281 set(Tabular::SET_BOTTOM_SPACE,
282 widgetsToLength(bottomspaceED,
284 if (!bc().policy().isReadOnly()) {
285 bottomspaceED->setEnabled(true);
286 bottomspaceUnit->setEnabled(true);
295 void GuiTabular::interlinespace_changed()
297 switch (interlinespaceCO->currentIndex()) {
299 set(Tabular::SET_INTERLINE_SPACE, "");
300 interlinespaceED->setEnabled(false);
301 interlinespaceUnit->setEnabled(false);
305 set(Tabular::SET_INTERLINE_SPACE, "default");
306 interlinespaceED->setEnabled(false);
307 interlinespaceUnit->setEnabled(false);
311 if (!interlinespaceED->text().isEmpty())
312 set(Tabular::SET_INTERLINE_SPACE,
313 widgetsToLength(interlinespaceED,
314 interlinespaceUnit));
315 if (!bc().policy().isReadOnly()) {
316 interlinespaceED->setEnabled(true);
317 interlinespaceUnit->setEnabled(true);
326 void GuiTabular::close_clicked()
333 void GuiTabular::borderSet_clicked()
335 set(Tabular::SET_ALL_LINES);
341 void GuiTabular::borderUnset_clicked()
343 set(Tabular::UNSET_ALL_LINES);
349 void GuiTabular::leftBorder_changed()
351 set(Tabular::TOGGLE_LINE_LEFT);
356 void GuiTabular::rightBorder_changed()
358 set(Tabular::TOGGLE_LINE_RIGHT);
363 void GuiTabular::topBorder_changed()
365 set(Tabular::TOGGLE_LINE_TOP);
370 void GuiTabular::bottomBorder_changed()
372 set(Tabular::TOGGLE_LINE_BOTTOM);
377 void GuiTabular::specialAlignment_changed()
379 string special = fromqstr(specialAlignmentED->text());
385 void GuiTabular::width_changed()
388 string const width = widgetsToLength(widthED, widthUnitCB);
393 void GuiTabular::multicolumn_clicked()
400 void GuiTabular::rotateTabular()
402 rotateTabular(rotateTabularCB->isChecked());
407 void GuiTabular::rotateCell()
409 rotateCell(rotateCellCB->isChecked());
414 void GuiTabular::hAlign_changed(int align)
416 GuiTabular::HALIGN h = GuiTabular::LEFT;
419 case 0: h = GuiTabular::LEFT; break;
420 case 1: h = GuiTabular::CENTER; break;
421 case 2: h = GuiTabular::RIGHT; break;
422 case 3: h = GuiTabular::BLOCK; break;
429 void GuiTabular::vAlign_changed(int align)
431 GuiTabular::VALIGN v = GuiTabular::TOP;
434 case 0: v = GuiTabular::TOP; break;
435 case 1: v = GuiTabular::MIDDLE; break;
436 case 2: v = GuiTabular::BOTTOM; break;
443 void GuiTabular::tableAlignment_changed(int align)
446 case 0: set(Tabular::TABULAR_VALIGN_TOP);
448 case 1: set(Tabular::TABULAR_VALIGN_MIDDLE);
450 case 2: set(Tabular::TABULAR_VALIGN_BOTTOM);
456 void GuiTabular::longTabular()
458 longTabular(longTabularCB->isChecked());
463 void GuiTabular::ltNewpage_clicked()
465 set(Tabular::SET_LTNEWPAGE);
470 void GuiTabular::on_captionStatusCB_toggled()
472 set(Tabular::TOGGLE_LTCAPTION);
477 void GuiTabular::ltHeaderStatus_clicked()
479 bool enable = headerStatusCB->isChecked();
481 set(Tabular::SET_LTHEAD, "");
483 set(Tabular::UNSET_LTHEAD, "");
488 void GuiTabular::ltHeaderBorderAbove_clicked()
490 if (headerBorderAboveCB->isChecked())
491 set(Tabular::SET_LTHEAD, "dl_above");
493 set(Tabular::UNSET_LTHEAD, "dl_above");
498 void GuiTabular::ltHeaderBorderBelow_clicked()
500 if (headerBorderBelowCB->isChecked())
501 set(Tabular::SET_LTHEAD, "dl_below");
503 set(Tabular::UNSET_LTHEAD, "dl_below");
508 void GuiTabular::ltFirstHeaderBorderAbove_clicked()
510 if (firstheaderBorderAboveCB->isChecked())
511 set(Tabular::SET_LTFIRSTHEAD, "dl_above");
513 set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
518 void GuiTabular::ltFirstHeaderBorderBelow_clicked()
520 if (firstheaderBorderBelowCB->isChecked())
521 set(Tabular::SET_LTFIRSTHEAD, "dl_below");
523 set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
528 void GuiTabular::ltFirstHeaderStatus_clicked()
530 bool enable = firstheaderStatusCB->isChecked();
532 set(Tabular::SET_LTFIRSTHEAD, "");
534 set(Tabular::UNSET_LTFIRSTHEAD, "");
539 void GuiTabular::ltFirstHeaderEmpty_clicked()
541 bool enable = firstheaderNoContentsCB->isChecked();
543 set(Tabular::SET_LTFIRSTHEAD, "empty");
545 set(Tabular::UNSET_LTFIRSTHEAD, "empty");
550 void GuiTabular::ltFooterStatus_clicked()
552 bool enable = footerStatusCB->isChecked();
554 set(Tabular::SET_LTFOOT, "");
556 set(Tabular::UNSET_LTFOOT, "");
561 void GuiTabular::ltFooterBorderAbove_clicked()
563 if (footerBorderAboveCB->isChecked())
564 set(Tabular::SET_LTFOOT, "dl_above");
566 set(Tabular::UNSET_LTFOOT, "dl_above");
571 void GuiTabular::ltFooterBorderBelow_clicked()
573 if (footerBorderBelowCB->isChecked())
574 set(Tabular::SET_LTFOOT, "dl_below");
576 set(Tabular::UNSET_LTFOOT, "dl_below");
581 void GuiTabular::ltLastFooterStatus_clicked()
583 bool enable = lastfooterStatusCB->isChecked();
585 set(Tabular::SET_LTLASTFOOT, "");
587 set(Tabular::UNSET_LTLASTFOOT, "");
592 void GuiTabular::ltLastFooterBorderAbove_clicked()
594 if (lastfooterBorderAboveCB->isChecked())
595 set(Tabular::SET_LTLASTFOOT, "dl_above");
597 set(Tabular::UNSET_LTLASTFOOT, "dl_above");
602 void GuiTabular::ltLastFooterBorderBelow_clicked()
604 if (lastfooterBorderBelowCB->isChecked())
605 set(Tabular::SET_LTLASTFOOT, "dl_below");
607 set(Tabular::UNSET_LTLASTFOOT, "dl_below");
612 void GuiTabular::ltLastFooterEmpty_clicked()
614 bool enable = lastfooterNoContentsCB->isChecked();
616 set(Tabular::SET_LTLASTFOOT, "empty");
618 set(Tabular::UNSET_LTLASTFOOT, "empty");
623 void GuiTabular::ltAlignment_clicked()
625 if (leftRB->isChecked())
626 set(Tabular::LONGTABULAR_ALIGN_LEFT);
627 else if (centerRB->isChecked())
628 set(Tabular::LONGTABULAR_ALIGN_CENTER);
629 else if (rightRB->isChecked())
630 set(Tabular::LONGTABULAR_ALIGN_RIGHT);
635 void GuiTabular::update_borders()
637 Tabular::idx_type const cell = getActiveCell();
638 borders->setTop(tabular_.topLine(cell));
639 borders->setBottom(tabular_.bottomLine(cell));
640 borders->setLeft(tabular_.leftLine(cell));
641 borders->setRight(tabular_.rightLine(cell));
642 // repaint the setborder widget
649 Length getColumnPWidth(Tabular const & t, size_t cell)
651 return t.column_info[t.cellColumn(cell)].p_width;
655 Length getMColumnPWidth(Tabular const & t, size_t cell)
657 if (t.isMultiColumn(cell))
658 return t.cellInfo(cell).p_width;
663 docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
665 if (what == Tabular::SET_SPECIAL_MULTI)
666 return t.cellInfo(cell).align_special;
667 return t.column_info[t.cellColumn(cell)].align_special;
674 void GuiTabular::updateContents()
676 initialiseParams(string());
678 size_t const cell = getActiveCell();
680 Tabular::row_type const row = tabular_.cellRow(cell);
681 Tabular::col_type const col = tabular_.cellColumn(cell);
683 tabularRowED->setText(QString::number(row + 1));
684 tabularColumnED->setText(QString::number(col + 1));
686 bool const multicol(tabular_.isMultiColumn(cell));
688 multicolumnCB->setChecked(multicol);
690 rotateCellCB->setChecked(tabular_.getRotateCell(cell));
691 rotateTabularCB->setChecked(tabular_.rotate);
693 longTabularCB->setChecked(tabular_.is_long_tabular);
701 special = getAlignSpecial(tabular_, cell,
702 Tabular::SET_SPECIAL_MULTI);
703 pwidth = getMColumnPWidth(tabular_, cell);
705 special = getAlignSpecial(tabular_, cell,
706 Tabular::SET_SPECIAL_COLUMN);
707 pwidth = getColumnPWidth(tabular_, cell);
710 specialAlignmentED->setText(toqstr(special));
712 bool const isReadonly = bc().policy().isReadOnly();
713 specialAlignmentED->setEnabled(!isReadonly);
715 Length::UNIT const default_unit = Length::defaultUnit();
717 borderDefaultRB->setChecked(!tabular_.use_booktabs);
718 booktabsRB->setChecked(tabular_.use_booktabs);
720 if (tabular_.row_info[row].top_space.empty()
721 && !tabular_.row_info[row].top_space_default) {
722 topspaceCO->setCurrentIndex(0);
723 } else if (tabular_.row_info[row].top_space_default) {
724 topspaceCO->setCurrentIndex(1);
726 topspaceCO->setCurrentIndex(2);
727 lengthToWidgets(topspaceED,
729 tabular_.row_info[row].top_space.asString(),
732 topspaceED->setEnabled(!isReadonly
733 && (topspaceCO->currentIndex() == 2));
734 topspaceUnit->setEnabled(!isReadonly
735 && (topspaceCO->currentIndex() == 2));
736 topspaceCO->setEnabled(!isReadonly);
738 if (tabular_.row_info[row].bottom_space.empty()
739 && !tabular_.row_info[row].bottom_space_default) {
740 bottomspaceCO->setCurrentIndex(0);
741 } else if (tabular_.row_info[row].bottom_space_default) {
742 bottomspaceCO->setCurrentIndex(1);
744 bottomspaceCO->setCurrentIndex(2);
745 lengthToWidgets(bottomspaceED,
747 tabular_.row_info[row].bottom_space.asString(),
750 bottomspaceED->setEnabled(!isReadonly
751 && (bottomspaceCO->currentIndex() == 2));
752 bottomspaceUnit->setEnabled(!isReadonly
753 && (bottomspaceCO->currentIndex() == 2));
754 bottomspaceCO->setEnabled(!isReadonly);
756 if (tabular_.row_info[row].interline_space.empty()
757 && !tabular_.row_info[row].interline_space_default) {
758 interlinespaceCO->setCurrentIndex(0);
759 } else if (tabular_.row_info[row].interline_space_default) {
760 interlinespaceCO->setCurrentIndex(1);
762 interlinespaceCO->setCurrentIndex(2);
763 lengthToWidgets(interlinespaceED,
765 tabular_.row_info[row].interline_space.asString(),
768 interlinespaceED->setEnabled(!isReadonly
769 && (interlinespaceCO->currentIndex() == 2));
770 interlinespaceUnit->setEnabled(!isReadonly
771 && (interlinespaceCO->currentIndex() == 2));
772 interlinespaceCO->setEnabled(!isReadonly);
775 if (!pwidth.zero()) {
776 colwidth = pwidth.asString();
778 lengthToWidgets(widthED, widthUnitCB,
779 colwidth, default_unit);
782 widthED->setEnabled(!isReadonly);
783 widthUnitCB->setEnabled(!isReadonly);
786 hAlignCB->addItem(qt_("Left"));
787 hAlignCB->addItem(qt_("Center"));
788 hAlignCB->addItem(qt_("Right"));
789 if (!multicol && !pwidth.zero())
790 hAlignCB->addItem(qt_("Justified"));
793 switch (tabular_.getAlignment(cell)) {
797 case LYX_ALIGN_CENTER:
800 case LYX_ALIGN_RIGHT:
803 case LYX_ALIGN_BLOCK:
805 if (!multicol && !pwidth.zero())
813 hAlignCB->setCurrentIndex(align);
816 switch (tabular_.getVAlignment(cell)) {
817 case Tabular::LYX_VALIGN_TOP:
820 case Tabular::LYX_VALIGN_MIDDLE:
823 case Tabular::LYX_VALIGN_BOTTOM:
832 vAlignCB->setCurrentIndex(valign);
834 hAlignCB->setEnabled(true);
835 vAlignCB->setEnabled(!pwidth.zero());
838 switch (tabular_.tabular_valignment) {
839 case Tabular::LYX_VALIGN_TOP:
842 case Tabular::LYX_VALIGN_MIDDLE:
845 case Tabular::LYX_VALIGN_BOTTOM:
852 TableAlignCB->setCurrentIndex(tableValign);
854 if (!tabular_.is_long_tabular) {
855 headerStatusCB->setChecked(false);
856 headerBorderAboveCB->setChecked(false);
857 headerBorderBelowCB->setChecked(false);
858 firstheaderStatusCB->setChecked(false);
859 firstheaderBorderAboveCB->setChecked(false);
860 firstheaderBorderBelowCB->setChecked(false);
861 firstheaderNoContentsCB->setChecked(false);
862 footerStatusCB->setChecked(false);
863 footerBorderAboveCB->setChecked(false);
864 footerBorderBelowCB->setChecked(false);
865 lastfooterStatusCB->setChecked(false);
866 lastfooterBorderAboveCB->setChecked(false);
867 lastfooterBorderBelowCB->setChecked(false);
868 lastfooterNoContentsCB->setChecked(false);
869 newpageCB->setChecked(false);
870 newpageCB->setEnabled(false);
871 captionStatusCB->blockSignals(true);
872 captionStatusCB->setChecked(false);
873 captionStatusCB->blockSignals(false);
876 // longtables cannot have a vertical alignment
877 TableAlignCB->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
879 switch (tabular_.longtabular_alignment) {
880 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
881 leftRB->setChecked(true);
883 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
884 centerRB->setChecked(true);
886 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
887 rightRB->setChecked(true);
890 centerRB->setChecked(true);
893 captionStatusCB->blockSignals(true);
894 captionStatusCB->setChecked(tabular_.ltCaption(row));
895 captionStatusCB->blockSignals(false);
897 // FIXME: shouldn't this be handled by GuiDialog?
898 // FIXME: Some of them should be handled directly in TabularUI.ui
899 firstheaderBorderAboveCB->setEnabled(
900 funcEnabled(Tabular::SET_LTFIRSTHEAD));
901 firstheaderBorderBelowCB->setEnabled(
902 funcEnabled(Tabular::SET_LTFIRSTHEAD));
903 // first header can only be suppressed when there is a header
904 firstheaderNoContentsCB->setEnabled(tabular_.haveLTHead()
905 && !tabular_.haveLTFirstHead());
907 //firstheaderStatusCB->setEnabled(
908 // !firstheaderNoContentsCB->isChecked());
909 headerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
910 headerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
911 headerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
913 footerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
914 footerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
915 footerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
917 lastfooterBorderAboveCB->setEnabled(
918 funcEnabled(Tabular::SET_LTLASTFOOT));
919 lastfooterBorderBelowCB->setEnabled(
920 funcEnabled(Tabular::SET_LTLASTFOOT));
921 // last footer can only be suppressed when there is a footer
922 lastfooterNoContentsCB->setEnabled(tabular_.haveLTFoot()
923 && !tabular_.haveLTLastFoot());
925 captionStatusCB->setEnabled(
926 funcEnabled(Tabular::TOGGLE_LTCAPTION));
927 // When a row is set as longtable caption, it must not be allowed
928 // to unset that this row is a multicolumn.
929 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
933 bool row_set = tabular_.getRowOfLTHead(row, ltt);
934 headerStatusCB->setChecked(row_set);
936 headerBorderAboveCB->setChecked(ltt.topDL);
937 headerBorderBelowCB->setChecked(ltt.bottomDL);
940 headerBorderAboveCB->setChecked(false);
941 headerBorderBelowCB->setChecked(false);
942 headerBorderAboveCB->setEnabled(false);
943 headerBorderBelowCB->setEnabled(false);
944 firstheaderNoContentsCB->setChecked(false);
945 firstheaderNoContentsCB->setEnabled(false);
949 row_set = tabular_.getRowOfLTFirstHead(row, ltt);
950 // check if setting a first header is allowed
951 // additionally check firstheaderNoContentsCB because when this is
952 // the case a first header makes no sense
953 firstheaderStatusCB->setEnabled(
954 funcEnabled(Tabular::SET_LTFIRSTHEAD)
955 && !firstheaderNoContentsCB->isChecked());
956 firstheaderStatusCB->setChecked(row_set);
957 if (ltt.set && (!ltt.empty || !use_empty)) {
958 firstheaderBorderAboveCB->setChecked(ltt.topDL);
959 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
961 firstheaderBorderAboveCB->setEnabled(false);
962 firstheaderBorderBelowCB->setEnabled(false);
963 firstheaderBorderAboveCB->setChecked(false);
964 firstheaderBorderBelowCB->setChecked(false);
967 firstheaderStatusCB->setEnabled(false);
971 row_set = tabular_.getRowOfLTFoot(row, ltt);
972 footerStatusCB->setChecked(row_set);
974 footerBorderAboveCB->setChecked(ltt.topDL);
975 footerBorderBelowCB->setChecked(ltt.bottomDL);
978 footerBorderAboveCB->setChecked(false);
979 footerBorderBelowCB->setChecked(false);
980 footerBorderAboveCB->setEnabled(false);
981 footerBorderBelowCB->setEnabled(false);
982 lastfooterNoContentsCB->setChecked(false);
983 lastfooterNoContentsCB->setEnabled(false);
987 row_set = tabular_.getRowOfLTLastFoot(row, ltt);
988 // check if setting a last footer is allowed
989 // additionally check lastfooterNoContentsCB because when this is
990 // the case a last footer makes no sense
991 lastfooterStatusCB->setEnabled(
992 funcEnabled(Tabular::SET_LTLASTFOOT)
993 && !lastfooterNoContentsCB->isChecked());
994 lastfooterStatusCB->setChecked(row_set);
995 if (ltt.set && (!ltt.empty || !use_empty)) {
996 lastfooterBorderAboveCB->setChecked(ltt.topDL);
997 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
999 lastfooterBorderAboveCB->setEnabled(false);
1000 lastfooterBorderBelowCB->setEnabled(false);
1001 lastfooterBorderAboveCB->setChecked(false);
1002 lastfooterBorderBelowCB->setChecked(false);
1005 lastfooterStatusCB->setEnabled(false);
1008 newpageCB->setChecked(tabular_.getLTNewPage(row));
1012 void GuiTabular::closeGUI()
1014 // ugly hack to auto-apply the stuff that hasn't been
1015 // yet. don't let this continue to exist ...
1017 // Subtle here, we must /not/ apply any changes and
1018 // then refer to tabular, as it will have been freed
1019 // since the changes update the actual tabular_
1021 // apply the fixed width values
1022 size_t const cell = getActiveCell();
1023 bool const multicol = tabular_.isMultiColumn(cell);
1024 string width = widgetsToLength(widthED, widthUnitCB);
1027 Length llen = getColumnPWidth(tabular_, cell);
1028 Length llenMulti = getMColumnPWidth(tabular_, cell);
1030 if (multicol && !llenMulti.zero())
1031 width2 = llenMulti.asString();
1032 else if (!multicol && !llen.zero())
1033 width2 = llen.asString();
1035 // apply the special alignment
1036 docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text());
1040 sa2 = getAlignSpecial(tabular_, cell,
1041 Tabular::SET_SPECIAL_MULTI);
1043 sa2 = getAlignSpecial(tabular_, cell,
1044 Tabular::SET_SPECIAL_COLUMN);
1048 set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
1050 set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
1053 if (width != width2) {
1055 set(Tabular::SET_MPWIDTH, width);
1057 set(Tabular::SET_PWIDTH, width);
1061 switch (topspaceCO->currentIndex()) {
1063 set(Tabular::SET_TOP_SPACE, "");
1066 set(Tabular::SET_TOP_SPACE, "default");
1069 set(Tabular::SET_TOP_SPACE,
1070 widgetsToLength(topspaceED,
1075 switch (bottomspaceCO->currentIndex()) {
1077 set(Tabular::SET_BOTTOM_SPACE, "");
1080 set(Tabular::SET_BOTTOM_SPACE, "default");
1083 set(Tabular::SET_BOTTOM_SPACE,
1084 widgetsToLength(bottomspaceED,
1089 switch (interlinespaceCO->currentIndex()) {
1091 set(Tabular::SET_INTERLINE_SPACE, "");
1094 set(Tabular::SET_INTERLINE_SPACE, "default");
1097 set(Tabular::SET_INTERLINE_SPACE,
1098 widgetsToLength(interlinespaceED,
1099 interlinespaceUnit));
1106 bool GuiTabular::initialiseParams(string const & data)
1108 // try to get the current cell
1109 BufferView const * const bv = bufferview();
1110 InsetTabular const * current_inset = 0;
1112 Cursor const & cur = bv->cursor();
1113 // get the innermost tabular inset;
1114 // assume that it is "ours"
1115 for (int i = cur.depth() - 1; i >= 0; --i)
1116 if (cur[i].inset().lyxCode() == TABULAR_CODE) {
1118 static_cast<InsetTabular const *>(&cur[i].inset());
1119 active_cell_ = cur[i].idx();
1124 if (current_inset && data.empty()) {
1125 tabular_ = Tabular(current_inset->tabular);
1129 InsetTabular tmp(const_cast<Buffer *>(&buffer()));
1130 InsetTabular::string2params(data, tmp);
1131 tabular_ = Tabular(tmp.tabular);
1136 void GuiTabular::clearParams()
1138 // This function is also called when LyX is closing and the dialog
1139 // is still open. At that time, the buffer might not be available
1141 if (isBufferAvailable()) {
1142 InsetTabular tmp(const_cast<Buffer *>(&buffer()));
1143 tabular_ = tmp.tabular;
1145 active_cell_ = Tabular::npos;
1149 Tabular::idx_type GuiTabular::getActiveCell() const
1151 return active_cell_;
1155 void GuiTabular::set(Tabular::Feature f, string const & arg)
1157 string const data = featureAsString(f) + ' ' + arg;
1158 dispatch(FuncRequest(getLfun(), data));
1162 void GuiTabular::setSpecial(string const & special)
1164 if (tabular_.isMultiColumn(getActiveCell()))
1165 set(Tabular::SET_SPECIAL_MULTI, special);
1167 set(Tabular::SET_SPECIAL_COLUMN, special);
1171 void GuiTabular::setWidth(string const & width)
1173 if (tabular_.isMultiColumn(getActiveCell()))
1174 set(Tabular::SET_MPWIDTH, width);
1176 set(Tabular::SET_PWIDTH, width);
1182 void GuiTabular::toggleMultiColumn()
1184 set(Tabular::MULTICOLUMN);
1189 void GuiTabular::rotateTabular(bool yes)
1192 set(Tabular::SET_ROTATE_TABULAR);
1194 set(Tabular::UNSET_ROTATE_TABULAR);
1198 void GuiTabular::rotateCell(bool yes)
1201 set(Tabular::SET_ROTATE_CELL);
1203 set(Tabular::UNSET_ROTATE_CELL);
1207 void GuiTabular::halign(GuiTabular::HALIGN h)
1209 Tabular::Feature num = Tabular::ALIGN_LEFT;
1210 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
1214 num = Tabular::ALIGN_LEFT;
1215 multi_num = Tabular::M_ALIGN_LEFT;
1218 num = Tabular::ALIGN_CENTER;
1219 multi_num = Tabular::M_ALIGN_CENTER;
1222 num = Tabular::ALIGN_RIGHT;
1223 multi_num = Tabular::M_ALIGN_RIGHT;
1226 num = Tabular::ALIGN_BLOCK;
1227 //multi_num: no equivalent
1231 if (tabular_.isMultiColumn(getActiveCell()))
1238 void GuiTabular::valign(GuiTabular::VALIGN v)
1240 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
1241 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
1245 num = Tabular::VALIGN_TOP;
1246 multi_num = Tabular::M_VALIGN_TOP;
1249 num = Tabular::VALIGN_MIDDLE;
1250 multi_num = Tabular::M_VALIGN_MIDDLE;
1253 num = Tabular::VALIGN_BOTTOM;
1254 multi_num = Tabular::M_VALIGN_BOTTOM;
1258 if (tabular_.isMultiColumn(getActiveCell()))
1265 void GuiTabular::booktabs(bool yes)
1268 set(Tabular::SET_BOOKTABS);
1270 set(Tabular::UNSET_BOOKTABS);
1274 void GuiTabular::longTabular(bool yes)
1277 set(Tabular::SET_LONGTABULAR);
1279 set(Tabular::UNSET_LONGTABULAR);
1283 // to get the status of the longtable row settings
1284 bool GuiTabular::funcEnabled(Tabular::Feature f) const
1287 FuncRequest(getLfun(), featureAsString(f))).enabled();
1291 Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); }
1294 } // namespace frontend
1297 #include "moc_GuiTabular.cpp"