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"
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(_("LyX: Edit Table"))
43 void QTabular::build_dialog()
45 dialog_.reset(new QTabularDialog(this));
47 bc().setCancel(dialog_->closePB);
49 // FIXME: add widgets to read only
53 bool QTabular::isValid()
59 void QTabular::update_borders()
61 LyXTabular * tabular(controller().tabular());
62 int cell(controller().inset()->getActCell());
64 if (!controller().isMulticolumnCell()) {
65 dialog_->borders->setTop(tabular->TopLine(cell, true));
66 dialog_->borders->setBottom(tabular->BottomLine(cell, true));
67 dialog_->borders->setLeft(tabular->LeftLine(cell, true));
68 dialog_->borders->setRight(tabular->RightLine(cell, true));
72 dialog_->borders->setTop(tabular->TopLine(cell));
73 dialog_->borders->setBottom(tabular->BottomLine(cell));
74 dialog_->borders->setLeft(tabular->LeftLine(cell));
75 dialog_->borders->setRight(tabular->RightLine(cell));
79 void QTabular::update_contents()
81 LyXTabular * tabular(controller().tabular());
82 int cell(controller().inset()->getActCell());
84 int const row(tabular->row_of_cell(cell));
85 int const col(tabular->column_of_cell(cell));
87 dialog_->tabularRowED->setText(tostr(row + 1).c_str());
88 dialog_->tabularColumnED->setText(tostr(col + 1).c_str());
90 bool const multicol(controller().isMulticolumnCell());
92 dialog_->multicolumnCB->setChecked(multicol);
94 dialog_->rotateCellCB->setChecked(tabular->GetRotateCell(cell));
95 dialog_->rotateTabularCB->setChecked(tabular->GetRotateTabular());
97 dialog_->longTabularCB->setChecked(tabular->IsLongTabular());
105 special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
106 pwidth = tabular->GetMColumnPWidth(cell);
108 special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
109 pwidth = tabular->GetColumnPWidth(cell);
112 dialog_->specialAlignmentED->setText(special.c_str());
114 bool const isReadonly = bc().bp().isReadOnly();
115 dialog_->specialAlignmentED->setEnabled(!isReadonly);
117 LyXLength::UNIT default_unit = controller().metric() ? LyXLength::CM : LyXLength::IN;
118 if (!pwidth.zero()) {
119 dialog_->widthED->setText(tostr(pwidth.value()).c_str());
120 dialog_->widthUnit->setCurrentItem(pwidth.unit());
122 dialog_->widthED->setText("");
123 dialog_->widthUnit->setCurrentItem(default_unit);
125 dialog_->widthED->setEnabled(!isReadonly);
126 dialog_->widthUnit->setEnabled(!isReadonly);
128 dialog_->hAlignCB->clear();
129 dialog_->hAlignCB->insertItem(_("Left"));
130 dialog_->hAlignCB->insertItem(_("Center"));
131 dialog_->hAlignCB->insertItem(_("Right"));
132 if (!multicol && !pwidth.zero())
133 dialog_->hAlignCB->insertItem(_("Block"));
136 switch (tabular->GetAlignment(cell)) {
140 case LYX_ALIGN_CENTER:
143 case LYX_ALIGN_RIGHT:
146 case LYX_ALIGN_BLOCK:
148 if (!multicol && !pwidth.zero())
156 dialog_->hAlignCB->setCurrentItem(align);
159 switch (tabular->GetVAlignment(cell)) {
160 case LyXTabular::LYX_VALIGN_TOP:
163 case LyXTabular::LYX_VALIGN_CENTER:
166 case LyXTabular::LYX_VALIGN_BOTTOM:
175 dialog_->vAlignCB->setCurrentItem(valign);
177 dialog_->hAlignCB->setEnabled(true);
178 dialog_->vAlignCB->setEnabled(!pwidth.zero());
180 if (!tabular->IsLongTabular()) {
181 dialog_->headerStatusCB->setChecked(false);
182 dialog_->headerBorderAboveCB->setChecked(false);
183 dialog_->headerBorderBelowCB->setChecked(false);
184 dialog_->firstheaderStatusCB->setChecked(false);
185 dialog_->firstheaderBorderAboveCB->setChecked(false);
186 dialog_->firstheaderBorderBelowCB->setChecked(false);
187 dialog_->firstheaderNoContentsCB->setChecked(false);
188 dialog_->footerStatusCB->setChecked(false);
189 dialog_->footerBorderAboveCB->setChecked(false);
190 dialog_->footerBorderBelowCB->setChecked(false);
191 dialog_->lastfooterStatusCB->setChecked(false);
192 dialog_->lastfooterBorderAboveCB->setChecked(false);
193 dialog_->lastfooterBorderBelowCB->setChecked(false);
194 dialog_->lastfooterNoContentsCB->setChecked(false);
195 dialog_->newpageCB->setChecked(false);
199 LyXTabular::ltType ltt;
201 bool row_set = tabular->GetRowOfLTHead(row, ltt);
202 dialog_->headerStatusCB->setChecked(row_set);
204 dialog_->headerBorderAboveCB->setChecked(ltt.topDL);
205 dialog_->headerBorderBelowCB->setChecked(ltt.bottomDL);
208 dialog_->headerBorderAboveCB->setChecked(false);
209 dialog_->headerBorderBelowCB->setChecked(false);
210 dialog_->headerBorderAboveCB->setEnabled(false);
211 dialog_->headerBorderBelowCB->setEnabled(false);
212 dialog_->firstheaderNoContentsCB->setChecked(false);
213 dialog_->firstheaderNoContentsCB->setEnabled(false);
217 row_set = tabular->GetRowOfLTFirstHead(row, ltt);
218 dialog_->firstheaderStatusCB->setChecked(row_set);
219 if (ltt.set && (!ltt.empty || !use_empty)) {
220 dialog_->firstheaderBorderAboveCB->setChecked(ltt.topDL);
221 dialog_->firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
223 dialog_->firstheaderBorderAboveCB->setEnabled(false);
224 dialog_->firstheaderBorderBelowCB->setEnabled(false);
225 dialog_->firstheaderBorderAboveCB->setChecked(false);
226 dialog_->firstheaderBorderBelowCB->setChecked(false);
228 dialog_->firstheaderNoContentsCB->setChecked(ltt.empty);
230 dialog_->firstheaderStatusCB->setEnabled(false);
234 row_set = tabular->GetRowOfLTFoot(row, ltt);
235 dialog_->footerStatusCB->setChecked(row_set);
237 dialog_->footerBorderAboveCB->setChecked(ltt.topDL);
238 dialog_->footerBorderBelowCB->setChecked(ltt.bottomDL);
241 dialog_->footerBorderAboveCB->setChecked(false);
242 dialog_->footerBorderBelowCB->setChecked(false);
243 dialog_->footerBorderAboveCB->setEnabled(false);
244 dialog_->footerBorderBelowCB->setEnabled(false);
245 dialog_->lastfooterNoContentsCB->setChecked(false);
246 dialog_->lastfooterNoContentsCB->setEnabled(false);
250 row_set = tabular->GetRowOfLTLastFoot(row, ltt);
251 dialog_->lastfooterStatusCB->setChecked(row_set);
252 if (ltt.set && (!ltt.empty || !use_empty)) {
253 dialog_->lastfooterBorderAboveCB->setChecked(ltt.topDL);
254 dialog_->lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
256 dialog_->lastfooterBorderAboveCB->setEnabled(false);
257 dialog_->lastfooterBorderBelowCB->setEnabled(false);
258 dialog_->lastfooterBorderAboveCB->setChecked(false);
259 dialog_->lastfooterBorderBelowCB->setChecked(false);
261 dialog_->lastfooterNoContentsCB->setChecked(ltt.empty);
263 dialog_->lastfooterStatusCB->setEnabled(false);
266 dialog_->newpageCB->setChecked(tabular->GetLTNewPage(row));
270 void QTabular::closeGUI()
272 // ugly hack to auto-apply the stuff that hasn't been
273 // yet. don't let this continue to exist ...
275 InsetTabular * inset(controller().inset());
276 LyXTabular * tabular(controller().tabular());
278 // apply the fixed width values
279 int cell = inset->getActCell();
280 string str1 = LyXLength(dialog_->widthED->text().toDouble(),
281 dialog_->widthUnit->currentLengthItem()).asString();
283 LyXLength llen(tabular->GetColumnPWidth(cell));
287 str2 = llen.asString();
290 if (controller().isMulticolumnCell())
291 controller().set(LyXTabular::SET_MPWIDTH, str1);
293 controller().set(LyXTabular::SET_PWIDTH, str1);
296 // apply the special alignment
297 str1 = dialog_->specialAlignmentED->text().latin1();
298 if (controller().isMulticolumnCell())
299 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
301 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
304 if (controller().isMulticolumnCell())
305 controller().set(LyXTabular::SET_SPECIAL_MULTI, str1);
307 controller().set(LyXTabular::SET_SPECIAL_COLUMN, str1);