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 // longtables cannot have a vertical alignment
88 connect(longTabularCB, SIGNAL(toggled(bool)),
89 TableAlignCB, SLOT(setDisabled(bool)));
90 connect(hAlignCB, SIGNAL(activated(int)),
91 this, SLOT(hAlign_changed(int)));
92 connect(vAlignCB, SIGNAL(activated(int)),
93 this, SLOT(vAlign_changed(int)));
94 connect(multicolumnCB, SIGNAL(clicked()),
95 this, SLOT(multicolumn_clicked()));
96 connect(newpageCB, SIGNAL(clicked()),
97 this, SLOT(ltNewpage_clicked()));
98 connect(headerStatusCB, SIGNAL(clicked()),
99 this, SLOT(ltHeaderStatus_clicked()));
100 connect(headerBorderAboveCB, SIGNAL(clicked()),
101 this, SLOT(ltHeaderBorderAbove_clicked()));
102 connect(headerBorderBelowCB, SIGNAL(clicked()),
103 this, SLOT(ltHeaderBorderBelow_clicked()));
104 connect(firstheaderStatusCB, SIGNAL(clicked()),
105 this, SLOT(ltFirstHeaderStatus_clicked()));
106 connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
107 this, SLOT(ltFirstHeaderBorderAbove_clicked()));
108 connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
109 this, SLOT(ltFirstHeaderBorderBelow_clicked()));
110 connect(firstheaderNoContentsCB, SIGNAL(clicked()),
111 this, SLOT(ltFirstHeaderEmpty_clicked()));
112 connect(footerStatusCB, SIGNAL(clicked()),
113 this, SLOT(ltFooterStatus_clicked()));
114 connect(footerBorderAboveCB, SIGNAL(clicked()),
115 this, SLOT(ltFooterBorderAbove_clicked()));
116 connect(footerBorderBelowCB, SIGNAL(clicked()),
117 this, SLOT(ltFooterBorderBelow_clicked()));
118 connect(lastfooterStatusCB, SIGNAL(clicked()),
119 this, SLOT(ltLastFooterStatus_clicked()));
120 connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
121 this, SLOT(ltLastFooterBorderAbove_clicked()));
122 connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
123 this, SLOT(ltLastFooterBorderBelow_clicked()));
124 connect(lastfooterNoContentsCB, SIGNAL(clicked()),
125 this, SLOT(ltLastFooterEmpty_clicked()));
126 connect(specialAlignmentED, SIGNAL(returnPressed()),
127 this, SLOT(specialAlignment_changed()));
128 connect(widthED, SIGNAL(editingFinished()),
129 this, SLOT(width_changed()));
130 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
131 this, SLOT(width_changed()));
132 connect(closePB, SIGNAL(clicked()),
133 this, SLOT(close_clicked()));
134 connect(borders, SIGNAL(topSet(bool)),
135 this, SLOT(topBorder_changed()));
136 connect(borders, SIGNAL(bottomSet(bool)),
137 this, SLOT(bottomBorder_changed()));
138 connect(borders, SIGNAL(rightSet(bool)),
139 this, SLOT(rightBorder_changed()));
140 connect(borders, SIGNAL(leftSet(bool)),
141 this, SLOT(leftBorder_changed()));
142 connect(rotateTabularCB, SIGNAL(clicked()),
143 this, SLOT(rotateTabular()));
144 connect(rotateCellCB, SIGNAL(clicked()),
145 this, SLOT(rotateCell()));
146 connect(TableAlignCB, SIGNAL(activated(int)),
147 this, SLOT(tableAlignment_changed(int)));
148 connect(longTabularCB, SIGNAL(clicked()),
149 this, SLOT(longTabular()));
150 connect(leftRB, SIGNAL(clicked()),
151 this, SLOT(ltAlignment_clicked()));
152 connect(centerRB, SIGNAL(clicked()),
153 this, SLOT(ltAlignment_clicked()));
154 connect(rightRB, SIGNAL(clicked()),
155 this, SLOT(ltAlignment_clicked()));
157 bc().setPolicy(ButtonPolicy::IgnorantPolicy);
159 bc().addReadOnly(topspaceED);
160 bc().addReadOnly(topspaceUnit);
161 bc().addReadOnly(topspaceCO);
162 bc().addReadOnly(bottomspaceED);
163 bc().addReadOnly(bottomspaceUnit);
164 bc().addReadOnly(bottomspaceCO);
165 bc().addReadOnly(interlinespaceED);
166 bc().addReadOnly(interlinespaceUnit);
167 bc().addReadOnly(interlinespaceCO);
168 bc().addReadOnly(borderDefaultRB);
169 bc().addReadOnly(booktabsRB);
171 bc().addReadOnly(multicolumnCB);
172 bc().addReadOnly(rotateCellCB);
173 bc().addReadOnly(rotateTabularCB);
174 bc().addReadOnly(specialAlignmentED);
175 bc().addReadOnly(widthED);
176 bc().addReadOnly(widthUnit);
177 bc().addReadOnly(hAlignCB);
178 bc().addReadOnly(vAlignCB);
179 bc().addReadOnly(TableAlignCB);
180 bc().addReadOnly(borderSetPB);
181 bc().addReadOnly(borderUnsetPB);
182 bc().addReadOnly(borders);
183 bc().addReadOnly(longTabularCB);
184 bc().addReadOnly(headerStatusCB);
185 bc().addReadOnly(headerBorderAboveCB);
186 bc().addReadOnly(headerBorderBelowCB);
187 bc().addReadOnly(firstheaderStatusCB);
188 bc().addReadOnly(firstheaderBorderAboveCB);
189 bc().addReadOnly(firstheaderBorderBelowCB);
190 bc().addReadOnly(firstheaderNoContentsCB);
191 bc().addReadOnly(footerStatusCB);
192 bc().addReadOnly(footerBorderAboveCB);
193 bc().addReadOnly(footerBorderBelowCB);
194 bc().addReadOnly(lastfooterStatusCB);
195 bc().addReadOnly(lastfooterBorderAboveCB);
196 bc().addReadOnly(lastfooterBorderBelowCB);
197 bc().addReadOnly(lastfooterNoContentsCB);
198 bc().addReadOnly(newpageCB);
199 bc().addReadOnly(leftRB);
200 bc().addReadOnly(centerRB);
201 bc().addReadOnly(rightRB);
203 // initialize the length validator
204 bc().addCheckedLineEdit(widthED, fixedWidthColLA);
205 bc().addCheckedLineEdit(topspaceED, topspaceLA);
206 bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA);
207 bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA);
211 GuiTabular::~GuiTabular()
216 void GuiTabular::change_adaptor()
222 void GuiTabular::booktabsChanged(bool)
225 booktabs(booktabsRB->isChecked());
230 void GuiTabular::topspace_changed()
232 switch (topspaceCO->currentIndex()) {
234 set(Tabular::SET_TOP_SPACE, "");
235 topspaceED->setEnabled(false);
236 topspaceUnit->setEnabled(false);
240 set(Tabular::SET_TOP_SPACE, "default");
241 topspaceED->setEnabled(false);
242 topspaceUnit->setEnabled(false);
246 if (!topspaceED->text().isEmpty())
247 set(Tabular::SET_TOP_SPACE,
248 widgetsToLength(topspaceED,
250 if (!bc().policy().isReadOnly()) {
251 topspaceED->setEnabled(true);
252 topspaceUnit->setEnabled(true);
261 void GuiTabular::bottomspace_changed()
263 switch (bottomspaceCO->currentIndex()) {
265 set(Tabular::SET_BOTTOM_SPACE, "");
266 bottomspaceED->setEnabled(false);
267 bottomspaceUnit->setEnabled(false);
271 set(Tabular::SET_BOTTOM_SPACE, "default");
272 bottomspaceED->setEnabled(false);
273 bottomspaceUnit->setEnabled(false);
277 if (!bottomspaceED->text().isEmpty())
278 set(Tabular::SET_BOTTOM_SPACE,
279 widgetsToLength(bottomspaceED,
281 if (!bc().policy().isReadOnly()) {
282 bottomspaceED->setEnabled(true);
283 bottomspaceUnit->setEnabled(true);
292 void GuiTabular::interlinespace_changed()
294 switch (interlinespaceCO->currentIndex()) {
296 set(Tabular::SET_INTERLINE_SPACE, "");
297 interlinespaceED->setEnabled(false);
298 interlinespaceUnit->setEnabled(false);
302 set(Tabular::SET_INTERLINE_SPACE, "default");
303 interlinespaceED->setEnabled(false);
304 interlinespaceUnit->setEnabled(false);
308 if (!interlinespaceED->text().isEmpty())
309 set(Tabular::SET_INTERLINE_SPACE,
310 widgetsToLength(interlinespaceED,
311 interlinespaceUnit));
312 if (!bc().policy().isReadOnly()) {
313 interlinespaceED->setEnabled(true);
314 interlinespaceUnit->setEnabled(true);
323 void GuiTabular::close_clicked()
330 void GuiTabular::borderSet_clicked()
332 set(Tabular::SET_ALL_LINES);
338 void GuiTabular::borderUnset_clicked()
340 set(Tabular::UNSET_ALL_LINES);
346 void GuiTabular::leftBorder_changed()
348 set(Tabular::TOGGLE_LINE_LEFT);
353 void GuiTabular::rightBorder_changed()
355 set(Tabular::TOGGLE_LINE_RIGHT);
360 void GuiTabular::topBorder_changed()
362 set(Tabular::TOGGLE_LINE_TOP);
367 void GuiTabular::bottomBorder_changed()
369 set(Tabular::TOGGLE_LINE_BOTTOM);
374 void GuiTabular::specialAlignment_changed()
376 string special = fromqstr(specialAlignmentED->text());
382 void GuiTabular::width_changed()
385 string const width = widgetsToLength(widthED, widthUnit);
390 void GuiTabular::multicolumn_clicked()
397 void GuiTabular::rotateTabular()
399 rotateTabular(rotateTabularCB->isChecked());
404 void GuiTabular::rotateCell()
406 rotateCell(rotateCellCB->isChecked());
411 void GuiTabular::hAlign_changed(int align)
413 GuiTabular::HALIGN h = GuiTabular::LEFT;
416 case 0: h = GuiTabular::LEFT; break;
417 case 1: h = GuiTabular::CENTER; break;
418 case 2: h = GuiTabular::RIGHT; break;
419 case 3: h = GuiTabular::BLOCK; break;
426 void GuiTabular::vAlign_changed(int align)
428 GuiTabular::VALIGN v = GuiTabular::TOP;
431 case 0: v = GuiTabular::TOP; break;
432 case 1: v = GuiTabular::MIDDLE; break;
433 case 2: v = GuiTabular::BOTTOM; break;
440 void GuiTabular::tableAlignment_changed(int align)
443 case 0: set(Tabular::TABULAR_VALIGN_TOP);
445 case 1: set(Tabular::TABULAR_VALIGN_MIDDLE);
447 case 2: set(Tabular::TABULAR_VALIGN_BOTTOM);
453 void GuiTabular::longTabular()
455 longTabular(longTabularCB->isChecked());
460 void GuiTabular::ltNewpage_clicked()
462 set(Tabular::SET_LTNEWPAGE);
467 void GuiTabular::on_captionStatusCB_toggled()
469 set(Tabular::TOGGLE_LTCAPTION);
474 void GuiTabular::ltHeaderStatus_clicked()
476 bool enable = headerStatusCB->isChecked();
478 set(Tabular::SET_LTHEAD, "");
480 set(Tabular::UNSET_LTHEAD, "");
485 void GuiTabular::ltHeaderBorderAbove_clicked()
487 if (headerBorderAboveCB->isChecked())
488 set(Tabular::SET_LTHEAD, "dl_above");
490 set(Tabular::UNSET_LTHEAD, "dl_above");
495 void GuiTabular::ltHeaderBorderBelow_clicked()
497 if (headerBorderBelowCB->isChecked())
498 set(Tabular::SET_LTHEAD, "dl_below");
500 set(Tabular::UNSET_LTHEAD, "dl_below");
505 void GuiTabular::ltFirstHeaderBorderAbove_clicked()
507 if (firstheaderBorderAboveCB->isChecked())
508 set(Tabular::SET_LTFIRSTHEAD, "dl_above");
510 set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
515 void GuiTabular::ltFirstHeaderBorderBelow_clicked()
517 if (firstheaderBorderBelowCB->isChecked())
518 set(Tabular::SET_LTFIRSTHEAD, "dl_below");
520 set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
525 void GuiTabular::ltFirstHeaderStatus_clicked()
527 bool enable = firstheaderStatusCB->isChecked();
529 set(Tabular::SET_LTFIRSTHEAD, "");
531 set(Tabular::UNSET_LTFIRSTHEAD, "");
536 void GuiTabular::ltFirstHeaderEmpty_clicked()
538 bool enable = firstheaderNoContentsCB->isChecked();
540 set(Tabular::SET_LTFIRSTHEAD, "empty");
542 set(Tabular::UNSET_LTFIRSTHEAD, "empty");
547 void GuiTabular::ltFooterStatus_clicked()
549 bool enable = footerStatusCB->isChecked();
551 set(Tabular::SET_LTFOOT, "");
553 set(Tabular::UNSET_LTFOOT, "");
558 void GuiTabular::ltFooterBorderAbove_clicked()
560 if (footerBorderAboveCB->isChecked())
561 set(Tabular::SET_LTFOOT, "dl_above");
563 set(Tabular::UNSET_LTFOOT, "dl_above");
568 void GuiTabular::ltFooterBorderBelow_clicked()
570 if (footerBorderBelowCB->isChecked())
571 set(Tabular::SET_LTFOOT, "dl_below");
573 set(Tabular::UNSET_LTFOOT, "dl_below");
578 void GuiTabular::ltLastFooterStatus_clicked()
580 bool enable = lastfooterStatusCB->isChecked();
582 set(Tabular::SET_LTLASTFOOT, "");
584 set(Tabular::UNSET_LTLASTFOOT, "");
589 void GuiTabular::ltLastFooterBorderAbove_clicked()
591 if (lastfooterBorderAboveCB->isChecked())
592 set(Tabular::SET_LTLASTFOOT, "dl_above");
594 set(Tabular::UNSET_LTLASTFOOT, "dl_above");
599 void GuiTabular::ltLastFooterBorderBelow_clicked()
601 if (lastfooterBorderBelowCB->isChecked())
602 set(Tabular::SET_LTLASTFOOT, "dl_below");
604 set(Tabular::UNSET_LTLASTFOOT, "dl_below");
609 void GuiTabular::ltLastFooterEmpty_clicked()
611 bool enable = lastfooterNoContentsCB->isChecked();
613 set(Tabular::SET_LTLASTFOOT, "empty");
615 set(Tabular::UNSET_LTLASTFOOT, "empty");
620 void GuiTabular::ltAlignment_clicked()
622 if (leftRB->isChecked())
623 set(Tabular::LONGTABULAR_ALIGN_LEFT);
624 else if (centerRB->isChecked())
625 set(Tabular::LONGTABULAR_ALIGN_CENTER);
626 else if (rightRB->isChecked())
627 set(Tabular::LONGTABULAR_ALIGN_RIGHT);
632 void GuiTabular::update_borders()
634 Tabular::idx_type const cell = getActiveCell();
635 borders->setTop(tabular_.topLine(cell));
636 borders->setBottom(tabular_.bottomLine(cell));
637 borders->setLeft(tabular_.leftLine(cell));
638 borders->setRight(tabular_.rightLine(cell));
639 // repaint the setborder widget
646 Length getColumnPWidth(Tabular const & t, size_t cell)
648 return t.column_info[t.cellColumn(cell)].p_width;
652 Length getMColumnPWidth(Tabular const & t, size_t cell)
654 if (t.isMultiColumn(cell))
655 return t.cellInfo(cell).p_width;
660 docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
662 if (what == Tabular::SET_SPECIAL_MULTI)
663 return t.cellInfo(cell).align_special;
664 return t.column_info[t.cellColumn(cell)].align_special;
671 void GuiTabular::updateContents()
673 initialiseParams(string());
675 size_t const cell = getActiveCell();
677 Tabular::row_type const row = tabular_.cellRow(cell);
678 Tabular::col_type const col = tabular_.cellColumn(cell);
680 tabularRowED->setText(QString::number(row + 1));
681 tabularColumnED->setText(QString::number(col + 1));
683 bool const multicol(tabular_.isMultiColumn(cell));
685 multicolumnCB->setChecked(multicol);
687 rotateCellCB->setChecked(tabular_.getRotateCell(cell));
688 rotateTabularCB->setChecked(tabular_.rotate);
690 longTabularCB->setChecked(tabular_.is_long_tabular);
698 special = getAlignSpecial(tabular_, cell,
699 Tabular::SET_SPECIAL_MULTI);
700 pwidth = getMColumnPWidth(tabular_, cell);
702 special = getAlignSpecial(tabular_, cell,
703 Tabular::SET_SPECIAL_COLUMN);
704 pwidth = getColumnPWidth(tabular_, cell);
707 specialAlignmentED->setText(toqstr(special));
709 bool const isReadonly = bc().policy().isReadOnly();
710 specialAlignmentED->setEnabled(!isReadonly);
712 Length::UNIT const default_unit = Length::defaultUnit();
714 borderDefaultRB->setChecked(!tabular_.use_booktabs);
715 booktabsRB->setChecked(tabular_.use_booktabs);
717 if (tabular_.row_info[row].top_space.empty()
718 && !tabular_.row_info[row].top_space_default) {
719 topspaceCO->setCurrentIndex(0);
720 } else if (tabular_.row_info[row].top_space_default) {
721 topspaceCO->setCurrentIndex(1);
723 topspaceCO->setCurrentIndex(2);
724 lengthToWidgets(topspaceED,
726 tabular_.row_info[row].top_space.asString(),
729 topspaceED->setEnabled(!isReadonly
730 && (topspaceCO->currentIndex() == 2));
731 topspaceUnit->setEnabled(!isReadonly
732 && (topspaceCO->currentIndex() == 2));
733 topspaceCO->setEnabled(!isReadonly);
735 if (tabular_.row_info[row].bottom_space.empty()
736 && !tabular_.row_info[row].bottom_space_default) {
737 bottomspaceCO->setCurrentIndex(0);
738 } else if (tabular_.row_info[row].bottom_space_default) {
739 bottomspaceCO->setCurrentIndex(1);
741 bottomspaceCO->setCurrentIndex(2);
742 lengthToWidgets(bottomspaceED,
744 tabular_.row_info[row].bottom_space.asString(),
747 bottomspaceED->setEnabled(!isReadonly
748 && (bottomspaceCO->currentIndex() == 2));
749 bottomspaceUnit->setEnabled(!isReadonly
750 && (bottomspaceCO->currentIndex() == 2));
751 bottomspaceCO->setEnabled(!isReadonly);
753 if (tabular_.row_info[row].interline_space.empty()
754 && !tabular_.row_info[row].interline_space_default) {
755 interlinespaceCO->setCurrentIndex(0);
756 } else if (tabular_.row_info[row].interline_space_default) {
757 interlinespaceCO->setCurrentIndex(1);
759 interlinespaceCO->setCurrentIndex(2);
760 lengthToWidgets(interlinespaceED,
762 tabular_.row_info[row].interline_space.asString(),
765 interlinespaceED->setEnabled(!isReadonly
766 && (interlinespaceCO->currentIndex() == 2));
767 interlinespaceUnit->setEnabled(!isReadonly
768 && (interlinespaceCO->currentIndex() == 2));
769 interlinespaceCO->setEnabled(!isReadonly);
773 colwidth = pwidth.asString();
774 lengthToWidgets(widthED, widthUnit,
775 colwidth, default_unit);
777 widthED->setEnabled(!isReadonly);
778 widthUnit->setEnabled(!isReadonly);
781 hAlignCB->addItem(qt_("Left"));
782 hAlignCB->addItem(qt_("Center"));
783 hAlignCB->addItem(qt_("Right"));
784 if (!multicol && !pwidth.zero())
785 hAlignCB->addItem(qt_("Justified"));
788 switch (tabular_.getAlignment(cell)) {
792 case LYX_ALIGN_CENTER:
795 case LYX_ALIGN_RIGHT:
798 case LYX_ALIGN_BLOCK:
800 if (!multicol && !pwidth.zero())
808 hAlignCB->setCurrentIndex(align);
811 switch (tabular_.getVAlignment(cell)) {
812 case Tabular::LYX_VALIGN_TOP:
815 case Tabular::LYX_VALIGN_MIDDLE:
818 case Tabular::LYX_VALIGN_BOTTOM:
827 vAlignCB->setCurrentIndex(valign);
829 hAlignCB->setEnabled(true);
830 vAlignCB->setEnabled(!pwidth.zero());
833 switch (tabular_.tabular_valignment) {
834 case Tabular::LYX_VALIGN_TOP:
837 case Tabular::LYX_VALIGN_MIDDLE:
840 case Tabular::LYX_VALIGN_BOTTOM:
847 TableAlignCB->setCurrentIndex(tableValign);
849 if (!tabular_.is_long_tabular) {
850 headerStatusCB->setChecked(false);
851 headerBorderAboveCB->setChecked(false);
852 headerBorderBelowCB->setChecked(false);
853 firstheaderStatusCB->setChecked(false);
854 firstheaderBorderAboveCB->setChecked(false);
855 firstheaderBorderBelowCB->setChecked(false);
856 firstheaderNoContentsCB->setChecked(false);
857 footerStatusCB->setChecked(false);
858 footerBorderAboveCB->setChecked(false);
859 footerBorderBelowCB->setChecked(false);
860 lastfooterStatusCB->setChecked(false);
861 lastfooterBorderAboveCB->setChecked(false);
862 lastfooterBorderBelowCB->setChecked(false);
863 lastfooterNoContentsCB->setChecked(false);
864 newpageCB->setChecked(false);
865 newpageCB->setEnabled(false);
866 captionStatusCB->blockSignals(true);
867 captionStatusCB->setChecked(false);
868 captionStatusCB->blockSignals(false);
871 // longtables cannot have a vertical alignment
872 TableAlignCB->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
874 switch (tabular_.longtabular_alignment) {
875 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
876 leftRB->setChecked(true);
878 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
879 centerRB->setChecked(true);
881 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
882 rightRB->setChecked(true);
885 centerRB->setChecked(true);
888 captionStatusCB->blockSignals(true);
889 captionStatusCB->setChecked(tabular_.ltCaption(row));
890 captionStatusCB->blockSignals(false);
892 // FIXME: shouldn't this be handled by GuiDialog?
893 // FIXME: Some of them should be handled directly in TabularUI.ui
894 firstheaderBorderAboveCB->setEnabled(
895 funcEnabled(Tabular::SET_LTFIRSTHEAD));
896 firstheaderBorderBelowCB->setEnabled(
897 funcEnabled(Tabular::SET_LTFIRSTHEAD));
898 // first header can only be suppressed when there is a header
899 firstheaderNoContentsCB->setEnabled(tabular_.haveLTHead()
900 && !tabular_.haveLTFirstHead());
902 //firstheaderStatusCB->setEnabled(
903 // !firstheaderNoContentsCB->isChecked());
904 headerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
905 headerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
906 headerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
908 footerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
909 footerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
910 footerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
912 lastfooterBorderAboveCB->setEnabled(
913 funcEnabled(Tabular::SET_LTLASTFOOT));
914 lastfooterBorderBelowCB->setEnabled(
915 funcEnabled(Tabular::SET_LTLASTFOOT));
916 // last footer can only be suppressed when there is a footer
917 lastfooterNoContentsCB->setEnabled(tabular_.haveLTFoot()
918 && !tabular_.haveLTLastFoot());
920 captionStatusCB->setEnabled(
921 funcEnabled(Tabular::TOGGLE_LTCAPTION));
922 // When a row is set as longtable caption, it must not be allowed
923 // to unset that this row is a multicolumn.
924 multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
928 bool row_set = tabular_.getRowOfLTHead(row, ltt);
929 headerStatusCB->setChecked(row_set);
931 headerBorderAboveCB->setChecked(ltt.topDL);
932 headerBorderBelowCB->setChecked(ltt.bottomDL);
935 headerBorderAboveCB->setChecked(false);
936 headerBorderBelowCB->setChecked(false);
937 headerBorderAboveCB->setEnabled(false);
938 headerBorderBelowCB->setEnabled(false);
939 firstheaderNoContentsCB->setChecked(false);
940 firstheaderNoContentsCB->setEnabled(false);
944 row_set = tabular_.getRowOfLTFirstHead(row, ltt);
945 // check if setting a first header is allowed
946 // additionally check firstheaderNoContentsCB because when this is
947 // the case a first header makes no sense
948 firstheaderStatusCB->setEnabled(
949 funcEnabled(Tabular::SET_LTFIRSTHEAD)
950 && !firstheaderNoContentsCB->isChecked());
951 firstheaderStatusCB->setChecked(row_set);
952 if (ltt.set && (!ltt.empty || !use_empty)) {
953 firstheaderBorderAboveCB->setChecked(ltt.topDL);
954 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
956 firstheaderBorderAboveCB->setEnabled(false);
957 firstheaderBorderBelowCB->setEnabled(false);
958 firstheaderBorderAboveCB->setChecked(false);
959 firstheaderBorderBelowCB->setChecked(false);
962 firstheaderStatusCB->setEnabled(false);
966 row_set = tabular_.getRowOfLTFoot(row, ltt);
967 footerStatusCB->setChecked(row_set);
969 footerBorderAboveCB->setChecked(ltt.topDL);
970 footerBorderBelowCB->setChecked(ltt.bottomDL);
973 footerBorderAboveCB->setChecked(false);
974 footerBorderBelowCB->setChecked(false);
975 footerBorderAboveCB->setEnabled(false);
976 footerBorderBelowCB->setEnabled(false);
977 lastfooterNoContentsCB->setChecked(false);
978 lastfooterNoContentsCB->setEnabled(false);
982 row_set = tabular_.getRowOfLTLastFoot(row, ltt);
983 // check if setting a last footer is allowed
984 // additionally check lastfooterNoContentsCB because when this is
985 // the case a last footer makes no sense
986 lastfooterStatusCB->setEnabled(
987 funcEnabled(Tabular::SET_LTLASTFOOT)
988 && !lastfooterNoContentsCB->isChecked());
989 lastfooterStatusCB->setChecked(row_set);
990 if (ltt.set && (!ltt.empty || !use_empty)) {
991 lastfooterBorderAboveCB->setChecked(ltt.topDL);
992 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
994 lastfooterBorderAboveCB->setEnabled(false);
995 lastfooterBorderBelowCB->setEnabled(false);
996 lastfooterBorderAboveCB->setChecked(false);
997 lastfooterBorderBelowCB->setChecked(false);
1000 lastfooterStatusCB->setEnabled(false);
1003 newpageCB->setChecked(tabular_.getLTNewPage(row));
1007 void GuiTabular::closeGUI()
1009 // ugly hack to auto-apply the stuff that hasn't been
1010 // yet. don't let this continue to exist ...
1012 // Subtle here, we must /not/ apply any changes and
1013 // then refer to tabular, as it will have been freed
1014 // since the changes update the actual tabular_
1016 // apply the fixed width values
1017 size_t const cell = getActiveCell();
1018 bool const multicol = tabular_.isMultiColumn(cell);
1019 string width = widgetsToLength(widthED, widthUnit);
1022 Length llen = getColumnPWidth(tabular_, cell);
1023 Length llenMulti = getMColumnPWidth(tabular_, cell);
1025 if (multicol && !llenMulti.zero())
1026 width2 = llenMulti.asString();
1027 else if (!multicol && !llen.zero())
1028 width2 = llen.asString();
1030 // apply the special alignment
1031 docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text());
1035 sa2 = getAlignSpecial(tabular_, cell,
1036 Tabular::SET_SPECIAL_MULTI);
1038 sa2 = getAlignSpecial(tabular_, cell,
1039 Tabular::SET_SPECIAL_COLUMN);
1043 set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
1045 set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
1048 if (width != width2) {
1050 set(Tabular::SET_MPWIDTH, width);
1052 set(Tabular::SET_PWIDTH, width);
1056 switch (topspaceCO->currentIndex()) {
1058 set(Tabular::SET_TOP_SPACE, "");
1061 set(Tabular::SET_TOP_SPACE, "default");
1064 set(Tabular::SET_TOP_SPACE,
1065 widgetsToLength(topspaceED,
1070 switch (bottomspaceCO->currentIndex()) {
1072 set(Tabular::SET_BOTTOM_SPACE, "");
1075 set(Tabular::SET_BOTTOM_SPACE, "default");
1078 set(Tabular::SET_BOTTOM_SPACE,
1079 widgetsToLength(bottomspaceED,
1084 switch (interlinespaceCO->currentIndex()) {
1086 set(Tabular::SET_INTERLINE_SPACE, "");
1089 set(Tabular::SET_INTERLINE_SPACE, "default");
1092 set(Tabular::SET_INTERLINE_SPACE,
1093 widgetsToLength(interlinespaceED,
1094 interlinespaceUnit));
1101 bool GuiTabular::initialiseParams(string const & data)
1103 // try to get the current cell
1104 BufferView const * const bv = bufferview();
1105 InsetTabular const * current_inset = 0;
1107 Cursor const & cur = bv->cursor();
1108 // get the innermost tabular inset;
1109 // assume that it is "ours"
1110 for (int i = cur.depth() - 1; i >= 0; --i)
1111 if (cur[i].inset().lyxCode() == TABULAR_CODE) {
1113 static_cast<InsetTabular const *>(&cur[i].inset());
1114 active_cell_ = cur[i].idx();
1119 if (current_inset && data.empty()) {
1120 tabular_ = Tabular(current_inset->tabular);
1124 InsetTabular tmp(const_cast<Buffer &>(buffer()));
1125 InsetTabular::string2params(data, tmp);
1126 tabular_ = Tabular(tmp.tabular);
1131 void GuiTabular::clearParams()
1133 // This function is also called when LyX is closing and the dialog
1134 // is still open. At that time, the buffer might not be available
1136 if (isBufferAvailable()) {
1137 InsetTabular tmp(const_cast<Buffer &>(buffer()));
1138 tabular_ = tmp.tabular;
1140 active_cell_ = Tabular::npos;
1144 Tabular::idx_type GuiTabular::getActiveCell() const
1146 return active_cell_;
1150 void GuiTabular::set(Tabular::Feature f, string const & arg)
1152 string const data = featureAsString(f) + ' ' + arg;
1153 dispatch(FuncRequest(getLfun(), data));
1157 void GuiTabular::setSpecial(string const & special)
1159 if (tabular_.isMultiColumn(getActiveCell()))
1160 set(Tabular::SET_SPECIAL_MULTI, special);
1162 set(Tabular::SET_SPECIAL_COLUMN, special);
1166 void GuiTabular::setWidth(string const & width)
1168 if (tabular_.isMultiColumn(getActiveCell()))
1169 set(Tabular::SET_MPWIDTH, width);
1171 set(Tabular::SET_PWIDTH, width);
1177 void GuiTabular::toggleMultiColumn()
1179 set(Tabular::MULTICOLUMN);
1184 void GuiTabular::rotateTabular(bool yes)
1187 set(Tabular::SET_ROTATE_TABULAR);
1189 set(Tabular::UNSET_ROTATE_TABULAR);
1193 void GuiTabular::rotateCell(bool yes)
1196 set(Tabular::SET_ROTATE_CELL);
1198 set(Tabular::UNSET_ROTATE_CELL);
1202 void GuiTabular::halign(GuiTabular::HALIGN h)
1204 Tabular::Feature num = Tabular::ALIGN_LEFT;
1205 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
1209 num = Tabular::ALIGN_LEFT;
1210 multi_num = Tabular::M_ALIGN_LEFT;
1213 num = Tabular::ALIGN_CENTER;
1214 multi_num = Tabular::M_ALIGN_CENTER;
1217 num = Tabular::ALIGN_RIGHT;
1218 multi_num = Tabular::M_ALIGN_RIGHT;
1221 num = Tabular::ALIGN_BLOCK;
1222 //multi_num: no equivalent
1226 if (tabular_.isMultiColumn(getActiveCell()))
1233 void GuiTabular::valign(GuiTabular::VALIGN v)
1235 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
1236 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
1240 num = Tabular::VALIGN_TOP;
1241 multi_num = Tabular::M_VALIGN_TOP;
1244 num = Tabular::VALIGN_MIDDLE;
1245 multi_num = Tabular::M_VALIGN_MIDDLE;
1248 num = Tabular::VALIGN_BOTTOM;
1249 multi_num = Tabular::M_VALIGN_BOTTOM;
1253 if (tabular_.isMultiColumn(getActiveCell()))
1260 void GuiTabular::booktabs(bool yes)
1263 set(Tabular::SET_BOOKTABS);
1265 set(Tabular::UNSET_BOOKTABS);
1269 void GuiTabular::longTabular(bool yes)
1272 set(Tabular::SET_LONGTABULAR);
1274 set(Tabular::UNSET_LONGTABULAR);
1278 // to get the status of the longtable row settings
1279 bool GuiTabular::funcEnabled(Tabular::Feature f) const
1282 FuncRequest(getLfun(), featureAsString(f))).enabled();
1286 Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); }
1289 } // namespace frontend
1292 #include "moc_GuiTabular.cpp"