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