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);
129 switch (tabular->GetAlignment(cell)) {
133 case LYX_ALIGN_CENTER:
136 case LYX_ALIGN_RIGHT:
143 dialog_->hAlignCB->setCurrentItem(align);
146 switch (tabular->GetVAlignment(cell)) {
147 case LyXTabular::LYX_VALIGN_TOP:
150 case LyXTabular::LYX_VALIGN_CENTER:
153 case LyXTabular::LYX_VALIGN_BOTTOM:
162 dialog_->vAlignCB->setCurrentItem(valign);
164 dialog_->hAlignCB->setEnabled(true);
165 dialog_->vAlignCB->setEnabled(!pwidth.zero());
167 if (!tabular->IsLongTabular()) {
168 dialog_->headerStatusCB->setChecked(false);
169 dialog_->headerBorderAboveCB->setChecked(false);
170 dialog_->headerBorderBelowCB->setChecked(false);
171 dialog_->firstheaderStatusCB->setChecked(false);
172 dialog_->firstheaderBorderAboveCB->setChecked(false);
173 dialog_->firstheaderBorderBelowCB->setChecked(false);
174 dialog_->firstheaderNoContentsCB->setChecked(false);
175 dialog_->footerStatusCB->setChecked(false);
176 dialog_->footerBorderAboveCB->setChecked(false);
177 dialog_->footerBorderBelowCB->setChecked(false);
178 dialog_->lastfooterStatusCB->setChecked(false);
179 dialog_->lastfooterBorderAboveCB->setChecked(false);
180 dialog_->lastfooterBorderBelowCB->setChecked(false);
181 dialog_->lastfooterNoContentsCB->setChecked(false);
182 dialog_->newpageCB->setChecked(false);
186 LyXTabular::ltType ltt;
188 bool row_set = tabular->GetRowOfLTHead(row, ltt);
189 dialog_->headerStatusCB->setChecked(row_set);
191 dialog_->headerBorderAboveCB->setChecked(ltt.topDL);
192 dialog_->headerBorderBelowCB->setChecked(ltt.bottomDL);
195 dialog_->headerBorderAboveCB->setChecked(false);
196 dialog_->headerBorderBelowCB->setChecked(false);
197 dialog_->headerBorderAboveCB->setEnabled(false);
198 dialog_->headerBorderBelowCB->setEnabled(false);
199 dialog_->firstheaderNoContentsCB->setChecked(false);
200 dialog_->firstheaderNoContentsCB->setEnabled(false);
204 row_set = tabular->GetRowOfLTFirstHead(row, ltt);
205 dialog_->firstheaderStatusCB->setChecked(row_set);
206 if (ltt.set && (!ltt.empty || !use_empty)) {
207 dialog_->firstheaderBorderAboveCB->setChecked(ltt.topDL);
208 dialog_->firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
210 dialog_->firstheaderBorderAboveCB->setEnabled(false);
211 dialog_->firstheaderBorderBelowCB->setEnabled(false);
212 dialog_->firstheaderBorderAboveCB->setChecked(false);
213 dialog_->firstheaderBorderBelowCB->setChecked(false);
215 dialog_->firstheaderNoContentsCB->setChecked(ltt.empty);
217 dialog_->firstheaderStatusCB->setEnabled(false);
221 row_set = tabular->GetRowOfLTFoot(row, ltt);
222 dialog_->footerStatusCB->setChecked(row_set);
224 dialog_->footerBorderAboveCB->setChecked(ltt.topDL);
225 dialog_->footerBorderBelowCB->setChecked(ltt.bottomDL);
228 dialog_->footerBorderAboveCB->setChecked(false);
229 dialog_->footerBorderBelowCB->setChecked(false);
230 dialog_->footerBorderAboveCB->setEnabled(false);
231 dialog_->footerBorderBelowCB->setEnabled(false);
232 dialog_->lastfooterNoContentsCB->setChecked(false);
233 dialog_->lastfooterNoContentsCB->setEnabled(false);
237 row_set = tabular->GetRowOfLTLastFoot(row, ltt);
238 dialog_->lastfooterStatusCB->setChecked(row_set);
239 if (ltt.set && (!ltt.empty || !use_empty)) {
240 dialog_->lastfooterBorderAboveCB->setChecked(ltt.topDL);
241 dialog_->lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
243 dialog_->lastfooterBorderAboveCB->setEnabled(false);
244 dialog_->lastfooterBorderBelowCB->setEnabled(false);
245 dialog_->lastfooterBorderAboveCB->setChecked(false);
246 dialog_->lastfooterBorderBelowCB->setChecked(false);
248 dialog_->lastfooterNoContentsCB->setChecked(ltt.empty);
250 dialog_->lastfooterStatusCB->setEnabled(false);
253 dialog_->newpageCB->setChecked(tabular->GetLTNewPage(row));
257 void QTabular::closeGUI()
259 // ugly hack to auto-apply the stuff that hasn't been
260 // yet. don't let this continue to exist ...
262 InsetTabular * inset(controller().inset());
263 LyXTabular * tabular(controller().tabular());
265 // apply the fixed width values
266 int cell = inset->getActCell();
267 string str1 = LyXLength(dialog_->widthED->text().toDouble(),
268 dialog_->widthUnit->currentLengthItem()).asString();
270 LyXLength llen(tabular->GetColumnPWidth(cell));
274 str2 = llen.asString();
277 if (controller().isMulticolumnCell())
278 controller().set(LyXTabular::SET_MPWIDTH, str1);
280 controller().set(LyXTabular::SET_PWIDTH, str1);
283 // apply the special alignment
284 str1 = dialog_->specialAlignmentED->text().latin1();
285 if (controller().isMulticolumnCell())
286 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
288 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
291 if (controller().isMulticolumnCell())
292 controller().set(LyXTabular::SET_SPECIAL_MULTI, str1);
294 controller().set(LyXTabular::SET_SPECIAL_COLUMN, str1);