3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Juergen Spitzmueller
10 * Full author contact details are available in file CREDITS
16 #pragma implementation
19 #include "ControlTabular.h"
20 #include "insets/insettabular.h"
21 #include "qt_helpers.h"
22 #include "support/lstrings.h"
25 #include "QTabularDialog.h"
29 #include <qpushbutton.h>
30 #include <qlineedit.h>
31 #include <qcheckbox.h>
32 #include "lengthcombo.h"
33 #include "qsetborder.h"
35 typedef Qt2CB<ControlTabular, Qt2DB<QTabularDialog> > base_class;
38 : base_class(qt_("LyX: Edit Table"))
43 void QTabular::build_dialog()
45 dialog_.reset(new QTabularDialog(this));
47 bc().setCancel(dialog_->closePB);
49 bc().addReadOnly(dialog_->multicolumnCB);
50 bc().addReadOnly(dialog_->rotateCellCB);
51 bc().addReadOnly(dialog_->rotateTabularCB);
52 bc().addReadOnly(dialog_->specialAlignmentED);
53 bc().addReadOnly(dialog_->widthED);
54 bc().addReadOnly(dialog_->widthUnit);
55 bc().addReadOnly(dialog_->hAlignCB);
56 bc().addReadOnly(dialog_->vAlignCB);
57 bc().addReadOnly(dialog_->columnAddPB);
58 bc().addReadOnly(dialog_->columnDeletePB);
59 bc().addReadOnly(dialog_->rowAddPB);
60 bc().addReadOnly(dialog_->rowDeletePB);
61 bc().addReadOnly(dialog_->borderSetPB);
62 bc().addReadOnly(dialog_->borderUnsetPB);
63 bc().addReadOnly(dialog_->borders);
64 bc().addReadOnly(dialog_->longTabularCB);
65 bc().addReadOnly(dialog_->headerStatusCB);
66 bc().addReadOnly(dialog_->headerBorderAboveCB);
67 bc().addReadOnly(dialog_->headerBorderBelowCB);
68 bc().addReadOnly(dialog_->firstheaderStatusCB);
69 bc().addReadOnly(dialog_->firstheaderBorderAboveCB);
70 bc().addReadOnly(dialog_->firstheaderBorderBelowCB);
71 bc().addReadOnly(dialog_->firstheaderNoContentsCB);
72 bc().addReadOnly(dialog_->footerStatusCB);
73 bc().addReadOnly(dialog_->footerBorderAboveCB);
74 bc().addReadOnly(dialog_->footerBorderBelowCB);
75 bc().addReadOnly(dialog_->lastfooterStatusCB);
76 bc().addReadOnly(dialog_->lastfooterBorderAboveCB);
77 bc().addReadOnly(dialog_->lastfooterBorderBelowCB);
78 bc().addReadOnly(dialog_->lastfooterNoContentsCB);
79 bc().addReadOnly(dialog_->newpageCB);
83 bool QTabular::isValid()
89 void QTabular::update_borders()
91 LyXTabular * tabular(controller().tabular());
92 int cell(controller().inset()->getActCell());
94 if (!controller().isMulticolumnCell()) {
95 dialog_->borders->setLeftEnabled(true);
96 dialog_->borders->setRightEnabled(true);
97 dialog_->borders->setTop(tabular->TopLine(cell, true));
98 dialog_->borders->setBottom(tabular->BottomLine(cell, true));
99 dialog_->borders->setLeft(tabular->LeftLine(cell, true));
100 dialog_->borders->setRight(tabular->RightLine(cell, true));
101 // repaint the setborder widget
102 dialog_->borders->repaint();
106 dialog_->borders->setTop(tabular->TopLine(cell));
107 dialog_->borders->setBottom(tabular->BottomLine(cell));
108 // pay attention to left/right lines: they are only allowed
109 // to set if we are in first/last cell of row or if the left/right
110 // cell is also a multicolumn.
111 if (tabular->IsFirstCellInRow(cell) || tabular->IsMultiColumn(cell - 1)) {
112 dialog_->borders->setLeftEnabled(true);
113 dialog_->borders->setLeft(tabular->LeftLine(cell));
115 dialog_->borders->setLeft(false);
116 dialog_->borders->setLeftEnabled(false);
118 if (tabular->IsLastCellInRow(cell) || tabular->IsMultiColumn(cell + 1)) {
119 dialog_->borders->setRightEnabled(true);
120 dialog_->borders->setRight(tabular->RightLine(cell));
122 dialog_->borders->setRight(false);
123 dialog_->borders->setRightEnabled(false);
125 // repaint the setborder widget
126 dialog_->borders->repaint();
130 void QTabular::update_contents()
132 LyXTabular * tabular(controller().tabular());
133 int cell(controller().inset()->getActCell());
135 int const row(tabular->row_of_cell(cell));
136 int const col(tabular->column_of_cell(cell));
138 dialog_->tabularRowED->setText(toqstr(tostr(row + 1)));
139 dialog_->tabularColumnED->setText(toqstr(tostr(col + 1)));
141 bool const multicol(controller().isMulticolumnCell());
143 dialog_->multicolumnCB->setChecked(multicol);
145 dialog_->rotateCellCB->setChecked(tabular->GetRotateCell(cell));
146 dialog_->rotateTabularCB->setChecked(tabular->GetRotateTabular());
148 dialog_->longTabularCB->setChecked(tabular->IsLongTabular());
156 special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
157 pwidth = tabular->GetMColumnPWidth(cell);
159 special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
160 pwidth = tabular->GetColumnPWidth(cell);
163 dialog_->specialAlignmentED->setText(toqstr(special));
165 bool const isReadonly = bc().bp().isReadOnly();
166 dialog_->specialAlignmentED->setEnabled(!isReadonly);
168 LyXLength::UNIT default_unit = controller().metric() ? LyXLength::CM : LyXLength::IN;
169 if (!pwidth.zero()) {
170 dialog_->widthED->setText(toqstr(tostr(pwidth.value())));
171 dialog_->widthUnit->setCurrentItem(pwidth.unit());
173 dialog_->widthED->setText("");
174 dialog_->widthUnit->setCurrentItem(default_unit);
176 dialog_->widthED->setEnabled(!isReadonly);
177 dialog_->widthUnit->setEnabled(!isReadonly);
179 dialog_->hAlignCB->clear();
180 dialog_->hAlignCB->insertItem(qt_("Left"));
181 dialog_->hAlignCB->insertItem(qt_("Center"));
182 dialog_->hAlignCB->insertItem(qt_("Right"));
183 if (!multicol && !pwidth.zero())
184 dialog_->hAlignCB->insertItem(qt_("Block"));
187 switch (tabular->GetAlignment(cell)) {
191 case LYX_ALIGN_CENTER:
194 case LYX_ALIGN_RIGHT:
197 case LYX_ALIGN_BLOCK:
199 if (!multicol && !pwidth.zero())
207 dialog_->hAlignCB->setCurrentItem(align);
210 switch (tabular->GetVAlignment(cell)) {
211 case LyXTabular::LYX_VALIGN_TOP:
214 case LyXTabular::LYX_VALIGN_CENTER:
217 case LyXTabular::LYX_VALIGN_BOTTOM:
226 dialog_->vAlignCB->setCurrentItem(valign);
228 dialog_->hAlignCB->setEnabled(true);
229 dialog_->vAlignCB->setEnabled(!pwidth.zero());
231 if (!tabular->IsLongTabular()) {
232 dialog_->headerStatusCB->setChecked(false);
233 dialog_->headerBorderAboveCB->setChecked(false);
234 dialog_->headerBorderBelowCB->setChecked(false);
235 dialog_->firstheaderStatusCB->setChecked(false);
236 dialog_->firstheaderBorderAboveCB->setChecked(false);
237 dialog_->firstheaderBorderBelowCB->setChecked(false);
238 dialog_->firstheaderNoContentsCB->setChecked(false);
239 dialog_->footerStatusCB->setChecked(false);
240 dialog_->footerBorderAboveCB->setChecked(false);
241 dialog_->footerBorderBelowCB->setChecked(false);
242 dialog_->lastfooterStatusCB->setChecked(false);
243 dialog_->lastfooterBorderAboveCB->setChecked(false);
244 dialog_->lastfooterBorderBelowCB->setChecked(false);
245 dialog_->lastfooterNoContentsCB->setChecked(false);
246 dialog_->newpageCB->setChecked(false);
250 LyXTabular::ltType ltt;
252 bool row_set = tabular->GetRowOfLTHead(row, ltt);
253 dialog_->headerStatusCB->setChecked(row_set);
255 dialog_->headerBorderAboveCB->setChecked(ltt.topDL);
256 dialog_->headerBorderBelowCB->setChecked(ltt.bottomDL);
259 dialog_->headerBorderAboveCB->setChecked(false);
260 dialog_->headerBorderBelowCB->setChecked(false);
261 dialog_->headerBorderAboveCB->setEnabled(false);
262 dialog_->headerBorderBelowCB->setEnabled(false);
263 dialog_->firstheaderNoContentsCB->setChecked(false);
264 dialog_->firstheaderNoContentsCB->setEnabled(false);
268 row_set = tabular->GetRowOfLTFirstHead(row, ltt);
269 dialog_->firstheaderStatusCB->setChecked(row_set);
270 if (ltt.set && (!ltt.empty || !use_empty)) {
271 dialog_->firstheaderBorderAboveCB->setChecked(ltt.topDL);
272 dialog_->firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
274 dialog_->firstheaderBorderAboveCB->setEnabled(false);
275 dialog_->firstheaderBorderBelowCB->setEnabled(false);
276 dialog_->firstheaderBorderAboveCB->setChecked(false);
277 dialog_->firstheaderBorderBelowCB->setChecked(false);
279 dialog_->firstheaderNoContentsCB->setChecked(ltt.empty);
281 dialog_->firstheaderStatusCB->setEnabled(false);
285 row_set = tabular->GetRowOfLTFoot(row, ltt);
286 dialog_->footerStatusCB->setChecked(row_set);
288 dialog_->footerBorderAboveCB->setChecked(ltt.topDL);
289 dialog_->footerBorderBelowCB->setChecked(ltt.bottomDL);
292 dialog_->footerBorderAboveCB->setChecked(false);
293 dialog_->footerBorderBelowCB->setChecked(false);
294 dialog_->footerBorderAboveCB->setEnabled(false);
295 dialog_->footerBorderBelowCB->setEnabled(false);
296 dialog_->lastfooterNoContentsCB->setChecked(false);
297 dialog_->lastfooterNoContentsCB->setEnabled(false);
301 row_set = tabular->GetRowOfLTLastFoot(row, ltt);
302 dialog_->lastfooterStatusCB->setChecked(row_set);
303 if (ltt.set && (!ltt.empty || !use_empty)) {
304 dialog_->lastfooterBorderAboveCB->setChecked(ltt.topDL);
305 dialog_->lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
307 dialog_->lastfooterBorderAboveCB->setEnabled(false);
308 dialog_->lastfooterBorderBelowCB->setEnabled(false);
309 dialog_->lastfooterBorderAboveCB->setChecked(false);
310 dialog_->lastfooterBorderBelowCB->setChecked(false);
312 dialog_->lastfooterNoContentsCB->setChecked(ltt.empty);
314 dialog_->lastfooterStatusCB->setEnabled(false);
317 dialog_->newpageCB->setChecked(tabular->GetLTNewPage(row));
321 void QTabular::closeGUI()
323 // ugly hack to auto-apply the stuff that hasn't been
324 // yet. don't let this continue to exist ...
326 InsetTabular * inset(controller().inset());
327 LyXTabular * tabular(controller().tabular());
329 // apply the fixed width values
330 int cell = inset->getActCell();
331 bool const multicol(controller().isMulticolumnCell());
332 string str1 = widgetsToLength(dialog_->widthED, dialog_->widthUnit);
335 LyXLength llen(tabular->GetColumnPWidth(cell));
336 LyXLength llenMulti(tabular->GetMColumnPWidth(cell));
338 if (multicol && !llenMulti.zero())
339 str2 = llenMulti.asString();
340 else if (!multicol && !llen.zero())
341 str2 = llen.asString();
345 controller().set(LyXTabular::SET_MPWIDTH, str1);
347 controller().set(LyXTabular::SET_PWIDTH, str1);
350 // apply the special alignment
351 str1 = fromqstr(dialog_->specialAlignmentED->text());
353 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
355 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
359 controller().set(LyXTabular::SET_SPECIAL_MULTI, str1);
361 controller().set(LyXTabular::SET_SPECIAL_COLUMN, str1);