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