]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiTabular.cpp
all CheckedWidgets are line edits...
[lyx.git] / src / frontends / qt4 / GuiTabular.cpp
1 /**
2  * \file GuiTabular.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Jürgen Spitzmüller
8  * \author Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiTabular.h"
16
17 #include "GuiSetBorder.h"
18 #include "Qt2BC.h"
19
20 #include "LengthCombo.h"
21 #include "Validator.h"
22 #include "qt_helpers.h"
23
24 #include "controllers/ButtonController.h"
25
26 #include "support/convert.h"
27
28 #include <QCloseEvent>
29 #include <QCheckBox>
30 #include <QPushButton>
31 #include <QRadioButton>
32 #include <QLineEdit>
33
34 using std::string;
35
36 namespace lyx {
37 namespace frontend {
38
39 /////////////////////////////////////////////////////////////////////
40 //
41 // GuiTabularDialog
42 //
43 /////////////////////////////////////////////////////////////////////
44
45 GuiTabularDialog::GuiTabularDialog(GuiTabular * form)
46         : form_(form)
47 {
48         setupUi(this);
49
50         widthED->setValidator(unsignedLengthValidator(widthED));
51         topspaceED->setValidator(new LengthValidator(topspaceED));
52         bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
53         interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
54
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)), this, SLOT(topspace_changed()));
60         connect(bottomspaceED, SIGNAL(returnPressed()),
61                 this, SLOT(bottomspace_changed()));
62         connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
63                 this, SLOT(bottomspace_changed()));
64         connect(bottomspaceCO, SIGNAL(activated(int)), this, SLOT(bottomspace_changed()));
65         connect(interlinespaceED, SIGNAL(returnPressed()),
66                 this, SLOT(interlinespace_changed()));
67         connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
68                 this, SLOT(interlinespace_changed()));
69         connect(interlinespaceCO, SIGNAL(activated(int)), this, SLOT(interlinespace_changed()));
70         connect(booktabsRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
71         connect(borderDefaultRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
72         connect(borderSetPB, SIGNAL(clicked()), this, SLOT(borderSet_clicked()));
73         connect(borderUnsetPB, SIGNAL(clicked()), this, SLOT(borderUnset_clicked()));
74         connect(longTabularCB, SIGNAL(toggled(bool)), longtableGB, SLOT(setEnabled(bool)));
75         connect(longTabularCB, SIGNAL(toggled(bool)), newpageCB, SLOT(setEnabled(bool)));
76         connect(hAlignCB, SIGNAL(activated(int)), this, SLOT(hAlign_changed(int)));
77         connect(vAlignCB, SIGNAL(activated(int)), this, SLOT(vAlign_changed(int)));
78         connect(multicolumnCB, SIGNAL(clicked()), this, SLOT(multicolumn_clicked()));
79         connect(newpageCB, SIGNAL(clicked()), this, SLOT(ltNewpage_clicked()));
80         connect(headerStatusCB, SIGNAL(clicked()), this, SLOT(ltHeaderStatus_clicked()));
81         connect(headerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderAbove_clicked()));
82         connect(headerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderBelow_clicked()));
83         connect(firstheaderStatusCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderStatus_clicked()));
84         connect(firstheaderBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderAbove_clicked()));
85         connect(firstheaderBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderBelow_clicked()));
86         connect(firstheaderNoContentsCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderEmpty_clicked()));
87         connect(footerStatusCB, SIGNAL(clicked()), this, SLOT(ltFooterStatus_clicked()));
88         connect(footerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderAbove_clicked()));
89         connect(footerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderBelow_clicked()));
90         connect(lastfooterStatusCB, SIGNAL(clicked()), this, SLOT(ltLastFooterStatus_clicked()));
91         connect(lastfooterBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderAbove_clicked()));
92         connect(lastfooterBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderBelow_clicked()));
93         connect(lastfooterNoContentsCB, SIGNAL(clicked()), this, SLOT(ltLastFooterEmpty_clicked()));
94         connect(specialAlignmentED, SIGNAL(returnPressed()), this, SLOT(specialAlignment_changed()));
95         connect(widthED, SIGNAL(returnPressed()), this, SLOT(width_changed()));
96         connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), this, SLOT(width_changed()));
97         connect(closePB, SIGNAL(clicked()), this, SLOT(close_clicked()));
98         connect(borders, SIGNAL(topSet(bool)), this, SLOT(topBorder_changed()));
99         connect(borders, SIGNAL(bottomSet(bool)), this, SLOT(bottomBorder_changed()));
100         connect(borders, SIGNAL(rightSet(bool)), this, SLOT(rightBorder_changed()));
101         connect(borders, SIGNAL(leftSet(bool)), this, SLOT(leftBorder_changed()));
102         connect(rotateTabularCB, SIGNAL(clicked()), this, SLOT(rotateTabular()));
103         connect(rotateCellCB, SIGNAL(clicked()), this, SLOT(rotateCell()));
104         connect(longTabularCB, SIGNAL(clicked()), this, SLOT(longTabular()));
105 }
106
107
108 void GuiTabularDialog::change_adaptor()
109 {
110         form_->changed();
111 }
112
113
114 void GuiTabularDialog::closeEvent(QCloseEvent * e)
115 {
116         form_->slotWMHide();
117         e->accept();
118 }
119
120
121 void GuiTabularDialog::booktabsChanged(bool)
122 {
123         form_->changed();
124         form_->controller().booktabs(booktabsRB->isChecked());
125         form_->update_borders();
126 }
127
128
129 void GuiTabularDialog::topspace_changed()
130 {
131         switch(topspaceCO->currentIndex()) {
132                 case 0: {
133                         form_->controller().set(Tabular::SET_TOP_SPACE, "");
134                                 topspaceED->setEnabled(false);
135                                 topspaceUnit->setEnabled(false);
136                         break;
137                 }
138                 case 1: {
139                         form_->controller().set(Tabular::SET_TOP_SPACE, "default");
140                         topspaceED->setEnabled(false);
141                         topspaceUnit->setEnabled(false);
142                         break;
143                 }
144                 case 2: {
145                         if (!topspaceED->text().isEmpty())
146                                 form_->controller().set(Tabular::SET_TOP_SPACE,
147                                         widgetsToLength(topspaceED, topspaceUnit));
148                         if (!form_->bc().policy().isReadOnly()) {
149                                 topspaceED->setEnabled(true);
150                                 topspaceUnit->setEnabled(true);
151                         }
152                         break;
153                 }
154         }
155         form_->changed();
156 }
157
158
159 void GuiTabularDialog::bottomspace_changed()
160 {
161         switch(bottomspaceCO->currentIndex()) {
162                 case 0: {
163                         form_->controller().set(Tabular::SET_BOTTOM_SPACE, "");
164                                 bottomspaceED->setEnabled(false);
165                                 bottomspaceUnit->setEnabled(false);
166                         break;
167                 }
168                 case 1: {
169                         form_->controller().set(Tabular::SET_BOTTOM_SPACE, "default");
170                         bottomspaceED->setEnabled(false);
171                         bottomspaceUnit->setEnabled(false);
172                         break;
173                 }
174                 case 2: {
175                         if (!bottomspaceED->text().isEmpty())
176                                 form_->controller().set(Tabular::SET_BOTTOM_SPACE,
177                                         widgetsToLength(bottomspaceED, bottomspaceUnit));
178                         if (!form_->bc().policy().isReadOnly()) {
179                                 bottomspaceED->setEnabled(true);
180                                 bottomspaceUnit->setEnabled(true);
181                         }
182                         break;
183                 }
184         }
185         form_->changed();
186 }
187
188
189 void GuiTabularDialog::interlinespace_changed()
190 {
191         switch(interlinespaceCO->currentIndex()) {
192                 case 0: {
193                         form_->controller().set(Tabular::SET_INTERLINE_SPACE, "");
194                                 interlinespaceED->setEnabled(false);
195                                 interlinespaceUnit->setEnabled(false);
196                         break;
197                 }
198                 case 1: {
199                         form_->controller().set(Tabular::SET_INTERLINE_SPACE, "default");
200                         interlinespaceED->setEnabled(false);
201                         interlinespaceUnit->setEnabled(false);
202                         break;
203                 }
204                 case 2: {
205                         if (!interlinespaceED->text().isEmpty())
206                                 form_->controller().set(Tabular::SET_INTERLINE_SPACE,
207                                         widgetsToLength(interlinespaceED, interlinespaceUnit));
208                         if (!form_->bc().policy().isReadOnly()) {
209                                 interlinespaceED->setEnabled(true);
210                                 interlinespaceUnit->setEnabled(true);
211                         }
212                         break;
213                 }
214         }
215         form_->changed();
216 }
217
218
219 void GuiTabularDialog::close_clicked()
220 {
221         form_->closeGUI();
222         form_->slotClose();
223 }
224
225
226 void GuiTabularDialog::borderSet_clicked()
227 {
228         form_->controller().set(Tabular::SET_ALL_LINES);
229         form_->update_borders();
230         form_->changed();
231 }
232
233
234 void GuiTabularDialog::borderUnset_clicked()
235 {
236         form_->controller().set(Tabular::UNSET_ALL_LINES);
237         form_->update_borders();
238         form_->changed();
239 }
240
241
242 void GuiTabularDialog::leftBorder_changed()
243 {
244         form_->controller().toggleLeftLine();
245         form_->changed();
246 }
247
248
249 void GuiTabularDialog::rightBorder_changed()
250 {
251         form_->controller().toggleRightLine();
252         form_->changed();
253 }
254
255
256 void GuiTabularDialog::topBorder_changed()
257 {
258         form_->controller().toggleTopLine();
259         form_->changed();
260 }
261
262
263 void GuiTabularDialog::bottomBorder_changed()
264 {
265         form_->controller().toggleBottomLine();
266         form_->changed();
267 }
268
269
270 void GuiTabularDialog::specialAlignment_changed()
271 {
272         string special = fromqstr(specialAlignmentED->text());
273         form_->controller().setSpecial(special);
274         form_->changed();
275 }
276
277
278 void GuiTabularDialog::width_changed()
279 {
280         form_->changed();
281         string const width = widgetsToLength(widthED, widthUnit);
282         form_->controller().setWidth(width);
283 }
284
285
286 void GuiTabularDialog::multicolumn_clicked()
287 {
288         form_->controller().toggleMultiColumn();
289         form_->changed();
290 }
291
292
293 void GuiTabularDialog::rotateTabular()
294 {
295         form_->controller().rotateTabular(rotateTabularCB->isChecked());
296         form_->changed();
297 }
298
299
300 void GuiTabularDialog::rotateCell()
301 {
302         form_->controller().rotateCell(rotateCellCB->isChecked());
303         form_->changed();
304 }
305
306
307 void GuiTabularDialog::hAlign_changed(int align)
308 {
309         ControlTabular::HALIGN h = ControlTabular::LEFT;
310
311         switch (align) {
312                 case 0: h = ControlTabular::LEFT; break;
313                 case 1: h = ControlTabular::CENTER; break;
314                 case 2: h = ControlTabular::RIGHT; break;
315                 case 3: h = ControlTabular::BLOCK; break;
316         }
317
318         form_->controller().halign(h);
319 }
320
321
322 void GuiTabularDialog::vAlign_changed(int align)
323 {
324         ControlTabular::VALIGN v = ControlTabular::TOP;
325
326         switch (align) {
327                 case 0: v = ControlTabular::TOP; break;
328                 case 1: v = ControlTabular::MIDDLE; break;
329                 case 2: v = ControlTabular::BOTTOM; break;
330         }
331
332         form_->controller().valign(v);
333 }
334
335
336 void GuiTabularDialog::longTabular()
337 {
338         form_->controller().longTabular(longTabularCB->isChecked());
339         form_->changed();
340 }
341
342
343 void GuiTabularDialog::ltNewpage_clicked()
344 {
345         form_->controller().set(Tabular::SET_LTNEWPAGE);
346         form_->changed();
347 }
348
349
350 void GuiTabularDialog::ltHeaderStatus_clicked()
351 {
352         bool enable(headerStatusCB->isChecked());
353         if (enable)
354                 form_->controller().set(Tabular::SET_LTHEAD, "");
355         else
356                 form_->controller().set(Tabular::UNSET_LTHEAD, "");
357         headerBorderAboveCB->setEnabled(enable);
358         headerBorderBelowCB->setEnabled(enable);
359         firstheaderNoContentsCB->setEnabled(enable);
360         form_->changed();
361 }
362
363
364 void GuiTabularDialog::ltHeaderBorderAbove_clicked()
365 {
366         if (headerBorderAboveCB->isChecked())
367                 form_->controller().set(Tabular::SET_LTHEAD, "dl_above");
368         else
369                 form_->controller().set(Tabular::UNSET_LTHEAD, "dl_above");
370         form_->changed();
371 }
372
373
374 void GuiTabularDialog::ltHeaderBorderBelow_clicked()
375 {
376         if (headerBorderBelowCB->isChecked())
377                 form_->controller().set(Tabular::SET_LTHEAD, "dl_below");
378         else
379                 form_->controller().set(Tabular::UNSET_LTHEAD, "dl_below");
380         form_->changed();
381 }
382
383
384 void GuiTabularDialog::ltFirstHeaderBorderAbove_clicked()
385 {
386         if (firstheaderBorderAboveCB->isChecked())
387                 form_->controller().set(Tabular::SET_LTFIRSTHEAD, "dl_above");
388         else
389                 form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
390         form_->changed();
391 }
392
393
394 void GuiTabularDialog::ltFirstHeaderBorderBelow_clicked()
395 {
396         if (firstheaderBorderBelowCB->isChecked())
397                 form_->controller().set(Tabular::SET_LTFIRSTHEAD, "dl_below");
398         else
399                 form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
400         form_->changed();
401 }
402
403
404 void GuiTabularDialog::ltFirstHeaderStatus_clicked()
405 {
406         bool enable(firstheaderStatusCB->isChecked());
407         if (enable)
408                 form_->controller().set(Tabular::SET_LTFIRSTHEAD, "");
409         else
410                 form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "");
411         firstheaderBorderAboveCB->setEnabled(enable);
412         firstheaderBorderBelowCB->setEnabled(enable);
413         form_->changed();
414 }
415
416
417 void GuiTabularDialog::ltFirstHeaderEmpty_clicked()
418 {
419         bool enable(firstheaderNoContentsCB->isChecked());
420         if (enable)
421                 form_->controller().set(Tabular::SET_LTFIRSTHEAD, "empty");
422         else
423                 form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "empty");
424         firstheaderStatusCB->setEnabled(!enable);
425         firstheaderBorderAboveCB->setEnabled(!enable);
426         firstheaderBorderBelowCB->setEnabled(!enable);
427         form_->changed();
428 }
429
430
431 void GuiTabularDialog::ltFooterStatus_clicked()
432 {
433         bool enable(footerStatusCB->isChecked());
434         if (enable)
435                 form_->controller().set(Tabular::SET_LTFOOT, "");
436         else
437                 form_->controller().set(Tabular::UNSET_LTFOOT, "");
438         footerBorderAboveCB->setEnabled(enable);
439         footerBorderBelowCB->setEnabled(enable);
440         lastfooterNoContentsCB->setEnabled(enable);
441         form_->changed();
442 }
443
444
445 void GuiTabularDialog::ltFooterBorderAbove_clicked()
446 {
447         if (footerBorderAboveCB->isChecked())
448                 form_->controller().set(Tabular::SET_LTFOOT, "dl_above");
449         else
450                 form_->controller().set(Tabular::UNSET_LTFOOT, "dl_above");
451         form_->changed();
452 }
453
454
455 void GuiTabularDialog::ltFooterBorderBelow_clicked()
456 {
457         if (footerBorderBelowCB->isChecked())
458                 form_->controller().set(Tabular::SET_LTFOOT, "dl_below");
459         else
460                 form_->controller().set(Tabular::UNSET_LTFOOT, "dl_below");
461         form_->changed();
462 }
463
464
465 void GuiTabularDialog::ltLastFooterStatus_clicked()
466 {
467         bool enable(lastfooterStatusCB->isChecked());
468         if (enable)
469                 form_->controller().set(Tabular::SET_LTLASTFOOT, "");
470         else
471                 form_->controller().set(Tabular::UNSET_LTLASTFOOT, "");
472         lastfooterBorderAboveCB->setEnabled(enable);
473         lastfooterBorderBelowCB->setEnabled(enable);
474         form_->changed();
475 }
476
477
478 void GuiTabularDialog::ltLastFooterBorderAbove_clicked()
479 {
480         if (lastfooterBorderAboveCB->isChecked())
481                 form_->controller().set(Tabular::SET_LTLASTFOOT, "dl_above");
482         else
483                 form_->controller().set(Tabular::UNSET_LTLASTFOOT, "dl_above");
484         form_->changed();
485 }
486
487
488 void GuiTabularDialog::ltLastFooterBorderBelow_clicked()
489 {
490         if (lastfooterBorderBelowCB->isChecked())
491                 form_->controller().set(Tabular::SET_LTLASTFOOT, "dl_below");
492         else
493                 form_->controller().set(Tabular::UNSET_LTLASTFOOT, "dl_below");
494         form_->changed();
495 }
496
497
498 void GuiTabularDialog::ltLastFooterEmpty_clicked()
499 {
500         bool enable(lastfooterNoContentsCB->isChecked());
501         if (enable)
502                 form_->controller().set(Tabular::SET_LTLASTFOOT, "empty");
503         else
504                 form_->controller().set(Tabular::UNSET_LTLASTFOOT, "empty");
505         lastfooterStatusCB->setEnabled(!enable);
506         lastfooterBorderAboveCB->setEnabled(!enable);
507         lastfooterBorderBelowCB->setEnabled(!enable);
508         form_->changed();
509 }
510
511
512 /////////////////////////////////////////////////////////////////////
513 //
514 // GuiTabular
515 //
516 /////////////////////////////////////////////////////////////////////
517
518
519 GuiTabular::GuiTabular(Dialog & parent)
520         : GuiView<GuiTabularDialog>(parent, _("Table Settings"))
521 {
522 }
523
524
525 void GuiTabular::build_dialog()
526 {
527         dialog_.reset(new GuiTabularDialog(this));
528
529         bcview().setCancel(dialog_->closePB);
530
531         bcview().addReadOnly(dialog_->topspaceED);
532         bcview().addReadOnly(dialog_->topspaceUnit);
533         bcview().addReadOnly(dialog_->topspaceCO);
534         bcview().addReadOnly(dialog_->bottomspaceED);
535         bcview().addReadOnly(dialog_->bottomspaceUnit);
536         bcview().addReadOnly(dialog_->bottomspaceCO);
537         bcview().addReadOnly(dialog_->interlinespaceED);
538         bcview().addReadOnly(dialog_->interlinespaceUnit);
539         bcview().addReadOnly(dialog_->interlinespaceCO);
540         bcview().addReadOnly(dialog_->borderDefaultRB);
541         bcview().addReadOnly(dialog_->booktabsRB);
542
543         bcview().addReadOnly(dialog_->multicolumnCB);
544         bcview().addReadOnly(dialog_->rotateCellCB);
545         bcview().addReadOnly(dialog_->rotateTabularCB);
546         bcview().addReadOnly(dialog_->specialAlignmentED);
547         bcview().addReadOnly(dialog_->widthED);
548         bcview().addReadOnly(dialog_->widthUnit);
549         bcview().addReadOnly(dialog_->hAlignCB);
550         bcview().addReadOnly(dialog_->vAlignCB);
551         bcview().addReadOnly(dialog_->borderSetPB);
552         bcview().addReadOnly(dialog_->borderUnsetPB);
553         bcview().addReadOnly(dialog_->borders);
554         bcview().addReadOnly(dialog_->longTabularCB);
555         bcview().addReadOnly(dialog_->headerStatusCB);
556         bcview().addReadOnly(dialog_->headerBorderAboveCB);
557         bcview().addReadOnly(dialog_->headerBorderBelowCB);
558         bcview().addReadOnly(dialog_->firstheaderStatusCB);
559         bcview().addReadOnly(dialog_->firstheaderBorderAboveCB);
560         bcview().addReadOnly(dialog_->firstheaderBorderBelowCB);
561         bcview().addReadOnly(dialog_->firstheaderNoContentsCB);
562         bcview().addReadOnly(dialog_->footerStatusCB);
563         bcview().addReadOnly(dialog_->footerBorderAboveCB);
564         bcview().addReadOnly(dialog_->footerBorderBelowCB);
565         bcview().addReadOnly(dialog_->lastfooterStatusCB);
566         bcview().addReadOnly(dialog_->lastfooterBorderAboveCB);
567         bcview().addReadOnly(dialog_->lastfooterBorderBelowCB);
568         bcview().addReadOnly(dialog_->lastfooterNoContentsCB);
569         bcview().addReadOnly(dialog_->newpageCB);
570
571         // initialize the length validator
572         addCheckedLineEdit(bcview(), dialog_->widthED,
573                 dialog_->fixedWidthColLA);
574         addCheckedLineEdit(bcview(), dialog_->topspaceED,
575                 dialog_->topspaceLA);
576         addCheckedLineEdit(bcview(), dialog_->bottomspaceED,
577                 dialog_->bottomspaceLA);
578         addCheckedLineEdit(bcview(), dialog_->interlinespaceED,
579                 dialog_->interlinespaceLA);
580 }
581
582
583 bool GuiTabular::isValid()
584 {
585         return true;
586 }
587
588
589 void GuiTabular::update_borders()
590 {
591         Tabular const & tabular = controller().tabular();
592         Tabular::idx_type const cell = controller().getActiveCell();
593         bool const isMulticolumnCell = tabular.isMultiColumn(cell);
594
595         if (!isMulticolumnCell) {
596                 dialog_->borders->setLeftEnabled(true);
597                 dialog_->borders->setRightEnabled(true);
598                 dialog_->borders->setTop(tabular.topLine(cell, true));
599                 dialog_->borders->setBottom(tabular.bottomLine(cell, true));
600                 dialog_->borders->setLeft(tabular.leftLine(cell, true));
601                 dialog_->borders->setRight(tabular.rightLine(cell, true));
602                 // repaint the setborder widget
603                 dialog_->borders->update();
604                 return;
605         }
606
607         dialog_->borders->setTop(tabular.topLine(cell));
608         dialog_->borders->setBottom(tabular.bottomLine(cell));
609         // pay attention to left/right lines: they are only allowed
610         // to set if we are in first/last cell of row or if the left/right
611         // cell is also a multicolumn.
612         if (tabular.isFirstCellInRow(cell) || tabular.isMultiColumn(cell - 1)) {
613                 dialog_->borders->setLeftEnabled(true);
614                 dialog_->borders->setLeft(tabular.leftLine(cell));
615         } else {
616                 dialog_->borders->setLeft(false);
617                 dialog_->borders->setLeftEnabled(false);
618         }
619         if (tabular.isLastCellInRow(cell) || tabular.isMultiColumn(cell + 1)) {
620                 dialog_->borders->setRightEnabled(true);
621                 dialog_->borders->setRight(tabular.rightLine(cell));
622         } else {
623                 dialog_->borders->setRight(false);
624                 dialog_->borders->setRightEnabled(false);
625         }
626         // repaint the setborder widget
627         dialog_->borders->update();
628 }
629
630
631 void GuiTabular::update_contents()
632 {
633         controller().initialiseParams(string());
634
635         Tabular const & tabular(controller().tabular());
636         Tabular::idx_type const cell = controller().getActiveCell();
637
638         Tabular::row_type const row(tabular.row_of_cell(cell));
639         Tabular::col_type const col(tabular.column_of_cell(cell));
640
641         dialog_->tabularRowED->setText(toqstr(convert<string>(row + 1)));
642         dialog_->tabularColumnED->setText(toqstr(convert<string>(col + 1)));
643
644         bool const multicol(tabular.isMultiColumn(cell));
645
646         dialog_->multicolumnCB->setChecked(multicol);
647
648         dialog_->rotateCellCB->setChecked(tabular.getRotateCell(cell));
649         dialog_->rotateTabularCB->setChecked(tabular.getRotateTabular());
650
651         dialog_->longTabularCB->setChecked(tabular.isLongTabular());
652
653         update_borders();
654
655         Length pwidth;
656         docstring special;
657
658         if (multicol) {
659                 special = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
660                 pwidth = tabular.getMColumnPWidth(cell);
661         } else {
662                 special = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
663                 pwidth = tabular.getColumnPWidth(cell);
664         }
665
666         dialog_->specialAlignmentED->setText(toqstr(special));
667
668         bool const isReadonly = bc().policy().isReadOnly();
669         dialog_->specialAlignmentED->setEnabled(!isReadonly);
670
671         Length::UNIT default_unit = controller().useMetricUnits() ? Length::CM : Length::IN;
672
673         dialog_->borderDefaultRB->setChecked(!tabular.useBookTabs());
674         dialog_->booktabsRB->setChecked(tabular.useBookTabs());
675
676         if (tabular.row_info[row].top_space.empty()
677             && !tabular.row_info[row].top_space_default) {
678                 dialog_->topspaceCO->setCurrentIndex(0);
679         } else if (tabular.row_info[row].top_space_default) {
680                 dialog_->topspaceCO->setCurrentIndex(1);
681         } else {
682                 dialog_->topspaceCO->setCurrentIndex(2);
683                 lengthToWidgets(dialog_->topspaceED,
684                                 dialog_->topspaceUnit,
685                                 tabular.row_info[row].top_space.asString(),
686                                 default_unit);
687         }
688         dialog_->topspaceED->setEnabled(!isReadonly
689                 && (dialog_->topspaceCO->currentIndex() == 2));
690         dialog_->topspaceUnit->setEnabled(!isReadonly
691                 && (dialog_->topspaceCO->currentIndex() == 2));
692         dialog_->topspaceCO->setEnabled(!isReadonly);
693
694         if (tabular.row_info[row].bottom_space.empty()
695             && !tabular.row_info[row].bottom_space_default) {
696                 dialog_->bottomspaceCO->setCurrentIndex(0);
697         } else if (tabular.row_info[row].bottom_space_default) {
698                 dialog_->bottomspaceCO->setCurrentIndex(1);
699         } else {
700                 dialog_->bottomspaceCO->setCurrentIndex(2);
701                 lengthToWidgets(dialog_->bottomspaceED,
702                                 dialog_->bottomspaceUnit,
703                                 tabular.row_info[row].bottom_space.asString(),
704                                 default_unit);
705         }
706         dialog_->bottomspaceED->setEnabled(!isReadonly
707                 && (dialog_->bottomspaceCO->currentIndex() == 2));
708         dialog_->bottomspaceUnit->setEnabled(!isReadonly
709                 && (dialog_->bottomspaceCO->currentIndex() == 2));
710         dialog_->bottomspaceCO->setEnabled(!isReadonly);
711
712         if (tabular.row_info[row].interline_space.empty()
713             && !tabular.row_info[row].interline_space_default) {
714                 dialog_->interlinespaceCO->setCurrentIndex(0);
715         } else if (tabular.row_info[row].interline_space_default) {
716                 dialog_->interlinespaceCO->setCurrentIndex(1);
717         } else {
718                 dialog_->interlinespaceCO->setCurrentIndex(2);
719                 lengthToWidgets(dialog_->interlinespaceED,
720                                 dialog_->interlinespaceUnit,
721                                 tabular.row_info[row].interline_space.asString(),
722                                 default_unit);
723         }
724         dialog_->interlinespaceED->setEnabled(!isReadonly
725                 && (dialog_->interlinespaceCO->currentIndex() == 2));
726         dialog_->interlinespaceUnit->setEnabled(!isReadonly
727                 && (dialog_->interlinespaceCO->currentIndex() == 2));
728         dialog_->interlinespaceCO->setEnabled(!isReadonly);
729
730         string colwidth;
731         if (!pwidth.zero())
732                 colwidth = pwidth.asString();
733         lengthToWidgets(dialog_->widthED, dialog_->widthUnit,
734                 colwidth, default_unit);
735
736         dialog_->widthED->setEnabled(!isReadonly);
737         dialog_->widthUnit->setEnabled(!isReadonly);
738
739         dialog_->hAlignCB->clear();
740         dialog_->hAlignCB->addItem(qt_("Left"));
741         dialog_->hAlignCB->addItem(qt_("Center"));
742         dialog_->hAlignCB->addItem(qt_("Right"));
743         if (!multicol && !pwidth.zero())
744                 dialog_->hAlignCB->addItem(qt_("Justified"));
745
746         int align = 0;
747         switch (tabular.getAlignment(cell)) {
748         case LYX_ALIGN_LEFT:
749                 align = 0;
750                 break;
751         case LYX_ALIGN_CENTER:
752                 align = 1;
753                 break;
754         case LYX_ALIGN_RIGHT:
755                 align = 2;
756                 break;
757         case LYX_ALIGN_BLOCK:
758         {
759                 if (!multicol && !pwidth.zero())
760                         align = 3;
761                 break;
762         }
763         default:
764                 align = 0;
765                 break;
766         }
767         dialog_->hAlignCB->setCurrentIndex(align);
768
769         int valign = 0;
770         switch (tabular.getVAlignment(cell)) {
771         case Tabular::LYX_VALIGN_TOP:
772                 valign = 0;
773                 break;
774         case Tabular::LYX_VALIGN_MIDDLE:
775                 valign = 1;
776                 break;
777         case Tabular::LYX_VALIGN_BOTTOM:
778                 valign = 2;
779                 break;
780         default:
781                 valign = 1;
782                 break;
783         }
784         if (pwidth.zero())
785                 valign = 1;
786         dialog_->vAlignCB->setCurrentIndex(valign);
787
788         dialog_->hAlignCB->setEnabled(true);
789         dialog_->vAlignCB->setEnabled(!pwidth.zero());
790
791         if (!tabular.isLongTabular()) {
792                 dialog_->headerStatusCB->setChecked(false);
793                 dialog_->headerBorderAboveCB->setChecked(false);
794                 dialog_->headerBorderBelowCB->setChecked(false);
795                 dialog_->firstheaderStatusCB->setChecked(false);
796                 dialog_->firstheaderBorderAboveCB->setChecked(false);
797                 dialog_->firstheaderBorderBelowCB->setChecked(false);
798                 dialog_->firstheaderNoContentsCB->setChecked(false);
799                 dialog_->footerStatusCB->setChecked(false);
800                 dialog_->footerBorderAboveCB->setChecked(false);
801                 dialog_->footerBorderBelowCB->setChecked(false);
802                 dialog_->lastfooterStatusCB->setChecked(false);
803                 dialog_->lastfooterBorderAboveCB->setChecked(false);
804                 dialog_->lastfooterBorderBelowCB->setChecked(false);
805                 dialog_->lastfooterNoContentsCB->setChecked(false);
806                 dialog_->newpageCB->setChecked(false);
807                 dialog_->newpageCB->setEnabled(false);
808                 return;
809         }
810
811         Tabular::ltType ltt;
812         bool use_empty;
813         bool row_set = tabular.getRowOfLTHead(row, ltt);
814         dialog_->headerStatusCB->setChecked(row_set);
815         if (ltt.set) {
816                 dialog_->headerBorderAboveCB->setChecked(ltt.topDL);
817                 dialog_->headerBorderBelowCB->setChecked(ltt.bottomDL);
818                 use_empty = true;
819         } else {
820                 dialog_->headerBorderAboveCB->setChecked(false);
821                 dialog_->headerBorderBelowCB->setChecked(false);
822                 dialog_->headerBorderAboveCB->setEnabled(false);
823                 dialog_->headerBorderBelowCB->setEnabled(false);
824                 dialog_->firstheaderNoContentsCB->setChecked(false);
825                 dialog_->firstheaderNoContentsCB->setEnabled(false);
826                 use_empty = false;
827         }
828
829         row_set = tabular.getRowOfLTFirstHead(row, ltt);
830         dialog_->firstheaderStatusCB->setChecked(row_set);
831         if (ltt.set && (!ltt.empty || !use_empty)) {
832                 dialog_->firstheaderBorderAboveCB->setChecked(ltt.topDL);
833                 dialog_->firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
834         } else {
835                 dialog_->firstheaderBorderAboveCB->setEnabled(false);
836                 dialog_->firstheaderBorderBelowCB->setEnabled(false);
837                 dialog_->firstheaderBorderAboveCB->setChecked(false);
838                 dialog_->firstheaderBorderBelowCB->setChecked(false);
839                 if (use_empty) {
840                         dialog_->firstheaderNoContentsCB->setChecked(ltt.empty);
841                         if (ltt.empty)
842                                 dialog_->firstheaderStatusCB->setEnabled(false);
843                 }
844         }
845
846         row_set = tabular.getRowOfLTFoot(row, ltt);
847         dialog_->footerStatusCB->setChecked(row_set);
848         if (ltt.set) {
849                 dialog_->footerBorderAboveCB->setChecked(ltt.topDL);
850                 dialog_->footerBorderBelowCB->setChecked(ltt.bottomDL);
851                 use_empty = true;
852         } else {
853                 dialog_->footerBorderAboveCB->setChecked(false);
854                 dialog_->footerBorderBelowCB->setChecked(false);
855                 dialog_->footerBorderAboveCB->setEnabled(false);
856                 dialog_->footerBorderBelowCB->setEnabled(false);
857                 dialog_->lastfooterNoContentsCB->setChecked(false);
858                 dialog_->lastfooterNoContentsCB->setEnabled(false);
859                 use_empty = false;
860         }
861
862         row_set = tabular.getRowOfLTLastFoot(row, ltt);
863                 dialog_->lastfooterStatusCB->setChecked(row_set);
864         if (ltt.set && (!ltt.empty || !use_empty)) {
865                 dialog_->lastfooterBorderAboveCB->setChecked(ltt.topDL);
866                 dialog_->lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
867         } else {
868                 dialog_->lastfooterBorderAboveCB->setEnabled(false);
869                 dialog_->lastfooterBorderBelowCB->setEnabled(false);
870                 dialog_->lastfooterBorderAboveCB->setChecked(false);
871                 dialog_->lastfooterBorderBelowCB->setChecked(false);
872                 if (use_empty) {
873                         dialog_->lastfooterNoContentsCB->setChecked(ltt.empty);
874                         if (ltt.empty)
875                                 dialog_->lastfooterStatusCB->setEnabled(false);
876                 }
877         }
878         dialog_->newpageCB->setChecked(tabular.getLTNewPage(row));
879 }
880
881
882 void GuiTabular::closeGUI()
883 {
884         // ugly hack to auto-apply the stuff that hasn't been
885         // yet. don't let this continue to exist ...
886
887         // Subtle here, we must /not/ apply any changes and
888         // then refer to tabular, as it will have been freed
889         // since the changes update the actual controller().tabular()
890         Tabular const & tabular(controller().tabular());
891
892         // apply the fixed width values
893         Tabular::idx_type const cell = controller().getActiveCell();
894         bool const multicol = tabular.isMultiColumn(cell);
895         string width = widgetsToLength(dialog_->widthED, dialog_->widthUnit);
896         string width2;
897
898         Length llen = tabular.getColumnPWidth(cell);
899         Length llenMulti = tabular.getMColumnPWidth(cell);
900
901         if (multicol && !llenMulti.zero())
902                         width2 = llenMulti.asString();
903         else if (!multicol && !llen.zero())
904                         width2 = llen.asString();
905
906         // apply the special alignment
907         docstring const sa1 = qstring_to_ucs4(dialog_->specialAlignmentED->text());
908         docstring sa2;
909
910         if (multicol)
911                 sa2 = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
912         else
913                 sa2 = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
914
915         if (sa1 != sa2) {
916                 if (multicol)
917                         controller().set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
918                 else
919                         controller().set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
920         }
921
922         if (width != width2) {
923                 if (multicol)
924                         controller().set(Tabular::SET_MPWIDTH, width);
925                 else
926                         controller().set(Tabular::SET_PWIDTH, width);
927         }
928
929         /* DO WE NEED THIS?
930         switch (dialog_->topspaceCO->currentIndex()) {
931                 case 0:
932                         controller().set(Tabular::SET_TOP_SPACE, "");
933                         break;
934                 case 1:
935                         controller().set(Tabular::SET_TOP_SPACE, "default");
936                         break;
937                 case 2:
938                         controller().set(Tabular::SET_TOP_SPACE,
939                                 widgetsToLength(dialog_->topspaceED,
940                                         dialog_->topspaceUnit));
941                         break;
942         }
943
944         switch (dialog_->bottomspaceCO->currentIndex()) {
945                 case 0:
946                         controller().set(Tabular::SET_BOTTOM_SPACE, "");
947                         break;
948                 case 1:
949                         controller().set(Tabular::SET_BOTTOM_SPACE, "default");
950                         break;
951                 case 2:
952                         controller().set(Tabular::SET_BOTTOM_SPACE,
953                                 widgetsToLength(dialog_->bottomspaceED,
954                                         dialog_->bottomspaceUnit));
955                         break;
956         }
957
958         switch (dialog_->interlinespaceCO->currentIndex()) {
959                 case 0:
960                         controller().set(Tabular::SET_INTERLINE_SPACE, "");
961                         break;
962                 case 1:
963                         controller().set(Tabular::SET_INTERLINE_SPACE, "default");
964                         break;
965                 case 2:
966                         controller().set(Tabular::SET_INTERLINE_SPACE,
967                                 widgetsToLength(dialog_->interlinespaceED,
968                                         dialog_->interlinespaceUnit));
969                         break;
970         }
971 */
972 }
973
974 } // namespace frontend
975 } // namespace lyx
976
977 #include "GuiTabular_moc.cpp"