]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiTabular.cpp
xpdf support for forward view via synctex. This is quite powerful tool.
[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  * \author Uwe Stöhr
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "GuiTabular.h"
17
18 #include "GuiApplication.h"
19 #include "GuiSetBorder.h"
20 #include "GuiView.h"
21 #include "LengthCombo.h"
22 #include "qt_helpers.h"
23 #include "Validator.h"
24
25 #include "BufferView.h"
26 #include "Cursor.h"
27 #include "FuncRequest.h"
28 #include "FuncStatus.h"
29 #include "LyX.h"
30
31 #include "insets/InsetTabular.h"
32
33 #include "support/debug.h"
34
35 #include <QCheckBox>
36 #include <QPushButton>
37 #include <QRadioButton>
38 #include <QLineEdit>
39
40 using namespace std;
41
42 namespace lyx {
43 namespace frontend {
44
45 GuiTabular::GuiTabular(QWidget * parent)
46         : InsetParamsWidget(parent)
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         widthUnitCB->setCurrentItem(Length::defaultUnit());
56
57         connect(topspaceED, SIGNAL(returnPressed()),
58                 this, SLOT(checkEnabled()));
59         connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
60                 this, SLOT(checkEnabled()));
61         connect(topspaceCO, SIGNAL(activated(int)),
62                 this, SLOT(checkEnabled()));
63         connect(bottomspaceED, SIGNAL(returnPressed()),
64                 this, SLOT(checkEnabled()));
65         connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
66                 this, SLOT(checkEnabled()));
67         connect(bottomspaceCO, SIGNAL(activated(int)),
68                 this, SLOT(checkEnabled()));
69         connect(interlinespaceED, SIGNAL(returnPressed()),
70                 this, SLOT(checkEnabled()));
71         connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
72                 this, SLOT(checkEnabled()));
73         connect(interlinespaceCO, SIGNAL(activated(int)),
74                 this, SLOT(checkEnabled()));
75         connect(booktabsRB, SIGNAL(clicked(bool)),
76                 this, SLOT(checkEnabled()));
77         connect(borderDefaultRB, SIGNAL(clicked(bool)),
78                 this, SLOT(checkEnabled()));
79         connect(borderSetPB, SIGNAL(clicked()),
80                 this, SLOT(borderSet_clicked()));
81         connect(borderUnsetPB, SIGNAL(clicked()), 
82                 this, SLOT(borderUnset_clicked()));
83         connect(hAlignCB, SIGNAL(activated(int)),
84                 this, SLOT(checkEnabled()));
85         connect(vAlignCB, SIGNAL(activated(int)),
86                 this, SLOT(checkEnabled()));
87         connect(multicolumnCB, SIGNAL(clicked()),
88                 this, SLOT(checkEnabled()));
89         connect(multirowCB, SIGNAL(clicked()),
90                 this, SLOT(checkEnabled()));
91         connect(newpageCB, SIGNAL(clicked()),
92                 this, SLOT(checkEnabled()));
93         connect(headerStatusCB, SIGNAL(clicked()),
94                 this, SLOT(checkEnabled()));
95         connect(headerBorderAboveCB, SIGNAL(clicked()),
96                 this, SLOT(checkEnabled()));
97         connect(headerBorderBelowCB, SIGNAL(clicked()),
98                 this, SLOT(checkEnabled()));
99         connect(firstheaderStatusCB, SIGNAL(clicked()),
100                 this, SLOT(checkEnabled()));
101         connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
102                 this, SLOT(checkEnabled()));
103         connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
104                 this, SLOT(checkEnabled()));
105         connect(firstheaderNoContentsCB, SIGNAL(clicked()),
106                 this, SLOT(checkEnabled()));
107         connect(footerStatusCB, SIGNAL(clicked()),
108                 this, SLOT(checkEnabled()));
109         connect(footerBorderAboveCB, SIGNAL(clicked()),
110                 this, SLOT(checkEnabled()));
111         connect(footerBorderBelowCB, SIGNAL(clicked()),
112                 this, SLOT(checkEnabled()));
113         connect(lastfooterStatusCB, SIGNAL(clicked()),
114                 this, SLOT(checkEnabled()));
115         connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
116                 this, SLOT(checkEnabled()));
117         connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
118                 this, SLOT(checkEnabled()));
119         connect(lastfooterNoContentsCB, SIGNAL(clicked()),
120                 this, SLOT(checkEnabled()));
121         connect(specialAlignmentED, SIGNAL(returnPressed()),
122                 this, SLOT(checkEnabled()));
123         connect(widthED, SIGNAL(textEdited(QString)),
124                 this, SLOT(checkEnabled()));
125         connect(widthUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
126                 this, SLOT(checkEnabled()));
127         connect(borders, SIGNAL(topSet(bool)),
128                 this, SLOT(checkEnabled()));
129         connect(borders, SIGNAL(bottomSet(bool)),
130                 this, SLOT(checkEnabled()));
131         connect(borders, SIGNAL(rightSet(bool)),
132                 this, SLOT(checkEnabled()));
133         connect(borders, SIGNAL(leftSet(bool)),
134                 this, SLOT(checkEnabled()));
135         connect(rotateTabularCB, SIGNAL(clicked()),
136                 this, SLOT(checkEnabled()));
137         connect(rotateCellCB, SIGNAL(clicked()),
138                 this, SLOT(checkEnabled()));
139         connect(TableAlignCB, SIGNAL(activated(int)),
140                 this, SLOT(checkEnabled()));
141         connect(longTabularCB, SIGNAL(clicked()),
142                 this, SLOT(checkEnabled()));
143         connect(leftRB, SIGNAL(clicked()),
144                 this, SLOT(checkEnabled()));
145         connect(centerRB, SIGNAL(clicked()),
146                 this, SLOT(checkEnabled()));
147         connect(rightRB, SIGNAL(clicked()),
148                 this, SLOT(checkEnabled()));
149                 
150         
151         // initialize the length validator
152         addCheckedWidget(widthED, fixedWidthColLA);
153         addCheckedWidget(topspaceED, topspaceLA);
154         addCheckedWidget(bottomspaceED, bottomspaceLA);
155         addCheckedWidget(interlinespaceED, interlinespaceLA);
156 }
157
158
159 void GuiTabular::checkEnabled()
160 {
161         hAlignCB->setEnabled(true);
162         vAlignCB->setEnabled(!multirowCB->isChecked() 
163                 && !widgetsToLength(widthED, widthUnitCB).empty());
164
165         topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
166         topspaceUnit->setEnabled(topspaceCO->currentIndex() == 2);
167         bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
168         bottomspaceUnit->setEnabled(bottomspaceCO->currentIndex() == 2);
169         interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
170         interlinespaceUnit->setEnabled(interlinespaceCO->currentIndex() == 2);
171
172         bool const longtabular = longTabularCB->isChecked();
173         longtableGB->setEnabled(true);
174         newpageCB->setEnabled(longtabular);
175         alignmentGB->setEnabled(longtabular);
176         // longtables cannot have a vertical alignment
177         TableAlignCB->setDisabled(longtabular);
178
179         // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
180         // depending on the cursor position is very very unintuitive...
181         // We need some edit boxes to show which rows are header/footer/etc
182         // without having to move the cursor first.
183         headerStatusCB->setEnabled(longtabular);
184         headerBorderAboveCB->setEnabled(longtabular
185                 && headerStatusCB->isChecked());
186         headerBorderBelowCB->setEnabled(longtabular
187                 && headerStatusCB->isChecked());
188
189         // first header can only be suppressed when there is a header
190         // FIXME: old code also checked for
191         //  tabular.haveLTHead() && !tabular.haveLTFirstHead());
192         firstheaderNoContentsCB->setEnabled(longtabular);
193         // check if setting a first header is allowed
194         // additionally check firstheaderNoContentsCB because when this is
195         // the case a first header makes no sense
196         // FIXME: verify that some previous row was not set.
197         firstheaderStatusCB->setEnabled(longtabular
198                 && !firstheaderNoContentsCB->isChecked());
199         firstheaderBorderAboveCB->setEnabled(longtabular
200                 && firstheaderStatusCB->isChecked());
201         firstheaderBorderBelowCB->setEnabled(longtabular
202                 && firstheaderStatusCB->isChecked());
203
204         footerStatusCB->setEnabled(longtabular);
205         footerBorderAboveCB->setEnabled(longtabular
206                 && footerBorderAboveCB->isChecked());
207         footerBorderBelowCB->setEnabled(longtabular
208                 && footerBorderAboveCB->isChecked());
209
210         // last footer can only be suppressed when there is a footer
211         // FIXME: old code also checked for
212         //   tabular.haveLTFoot() && !tabular.haveLTLastFoot());
213         lastfooterNoContentsCB->setEnabled(longtabular);
214         // check if setting a last footer is allowed
215         // additionally check lastfooterNoContentsCB because when this is
216         // the case a last footer makes no sense
217         lastfooterStatusCB->setEnabled(longtabular
218                 && !lastfooterNoContentsCB->isChecked());
219         lastfooterBorderAboveCB->setEnabled(longtabular
220                 && lastfooterBorderAboveCB->isChecked());
221         lastfooterBorderBelowCB->setEnabled(longtabular
222                 && lastfooterBorderAboveCB->isChecked());
223
224         // FIXME: verify if previous row doesn't have a caption already.
225         captionStatusCB->setEnabled(longtabular);
226
227         // When a row is set as longtable caption, it must not be allowed
228         // to unset that this row is a multicolumn.
229         // FIXME: old code also checked for:
230         //    funcEnabled(Tabular::MULTICOLUMN)
231         multicolumnCB->setEnabled(longtabular);
232
233         // FIXME: old code also checked for:
234         //    funcEnabled(Tabular::MULTICOLUMN)
235         multirowCB->setEnabled(longtabular);
236
237         changed();
238 }
239
240
241 void GuiTabular::borderSet_clicked()
242 {
243         borders->setTop(true);
244         borders->setBottom(true);
245         borders->setLeft(true);
246         borders->setRight(true);
247         // repaint the setborder widget
248         borders->update();
249         checkEnabled();
250 }
251
252
253 void GuiTabular::borderUnset_clicked()
254 {
255         borders->setTop(false);
256         borders->setBottom(false);
257         borders->setLeft(false);
258         borders->setRight(false);
259         // repaint the setborder widget
260         borders->update();
261         checkEnabled();
262 }
263
264
265 static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
266 {
267         param_str += ' ';
268         param_str += featureAsString(f) + ' ' + arg;
269 }
270
271
272 void GuiTabular::setHAlign(string & param_str) const
273 {
274         int const align = hAlignCB->currentIndex();
275
276         enum HALIGN { LEFT, RIGHT, CENTER, BLOCK };
277         HALIGN h = LEFT;
278
279         switch (align) {
280                 case 0: h = LEFT; break;
281                 case 1: h = CENTER; break;
282                 case 2: h = RIGHT; break;
283                 case 3: h = BLOCK; break;
284         }
285
286         Tabular::Feature num = Tabular::ALIGN_LEFT;
287         Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
288
289         switch (h) {
290                 case LEFT:
291                         num = Tabular::ALIGN_LEFT;
292                         multi_num = Tabular::M_ALIGN_LEFT;
293                         break;
294                 case CENTER:
295                         num = Tabular::ALIGN_CENTER;
296                         multi_num = Tabular::M_ALIGN_CENTER;
297                         break;
298                 case RIGHT:
299                         num = Tabular::ALIGN_RIGHT;
300                         multi_num = Tabular::M_ALIGN_RIGHT;
301                         break;
302                 case BLOCK:
303                         num = Tabular::ALIGN_BLOCK;
304                         //multi_num: no equivalent
305                         break;
306         }
307
308         if (multicolumnCB->isChecked())
309                 setParam(param_str, multi_num);
310         else
311                 setParam(param_str, num);
312 }
313
314
315 void GuiTabular::setVAlign(string & param_str) const
316 {
317         int const align = vAlignCB->currentIndex();
318         enum VALIGN { TOP, MIDDLE, BOTTOM };
319         VALIGN v = TOP;
320
321         switch (align) {
322                 case 0: v = TOP; break;
323                 case 1: v = MIDDLE; break;
324                 case 2: v = BOTTOM; break;
325         }
326
327         Tabular::Feature num = Tabular::VALIGN_MIDDLE;
328         Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
329
330         switch (v) {
331                 case TOP:
332                         num = Tabular::VALIGN_TOP;
333                         multi_num = Tabular::M_VALIGN_TOP;
334                         break;
335                 case MIDDLE:
336                         num = Tabular::VALIGN_MIDDLE;
337                         multi_num = Tabular::M_VALIGN_MIDDLE;
338                         break;
339                 case BOTTOM:
340                         num = Tabular::VALIGN_BOTTOM;
341                         multi_num = Tabular::M_VALIGN_BOTTOM;
342                         break;
343         }
344         if (multicolumnCB->isChecked() || multirowCB->isChecked())
345                 setParam(param_str, multi_num);
346         else
347                 setParam(param_str, num);
348 }
349
350
351 void GuiTabular::setTableAlignment(string & param_str) const
352 {
353         int const align = TableAlignCB->currentIndex();
354         switch (align) {
355                 case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
356                         break;
357                 case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
358                         break;
359                 case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
360                         break;
361         }
362 }
363
364
365 docstring GuiTabular::dialogToParams() const
366 {
367         // FIXME: We should use Tabular directly.
368         string param_str = "tabular";
369         setHAlign(param_str);
370         setVAlign(param_str);
371         setTableAlignment(param_str);
372         //
373         if (booktabsRB->isChecked())
374                 setParam(param_str, Tabular::SET_BOOKTABS);
375         else
376                 setParam(param_str, Tabular::UNSET_BOOKTABS);
377
378         //
379         switch (topspaceCO->currentIndex()) {
380                 case 0:
381                         setParam(param_str, Tabular::SET_TOP_SPACE, "none");
382                         break;
383                 case 1:
384                         setParam(param_str, Tabular::SET_TOP_SPACE, "default");
385                         break;
386                 case 2:
387                         if (!topspaceED->text().isEmpty())
388                                 setParam(param_str, Tabular::SET_TOP_SPACE,
389                                          widgetsToLength(topspaceED, topspaceUnit));
390                         break;
391         }
392
393         //
394         switch (bottomspaceCO->currentIndex()) {
395                 case 0:
396                         setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
397                         break;
398                 case 1:
399                         setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
400                         break;
401                 case 2:
402                         if (!bottomspaceED->text().isEmpty())
403                                 setParam(param_str, Tabular::SET_BOTTOM_SPACE,
404                                         widgetsToLength(bottomspaceED,
405                                                         bottomspaceUnit));
406                         break;
407         }
408
409         //
410         switch (interlinespaceCO->currentIndex()) {
411                 case 0:
412                         setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
413                         break;
414                 case 1:
415                         setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
416                         break;
417                 case 2:
418                         if (!interlinespaceED->text().isEmpty())
419                                 setParam(param_str, Tabular::SET_INTERLINE_SPACE,
420                                         widgetsToLength(interlinespaceED,
421                                                         interlinespaceUnit));
422                         break;
423         }
424
425         //
426         if (borders->getTop() && borders->getBottom() && borders->getLeft()
427                 && borders->getRight())
428                 setParam(param_str, Tabular::SET_ALL_LINES);
429         else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft()
430                 && !borders->getRight())
431                 setParam(param_str, Tabular::UNSET_ALL_LINES);
432         else {
433                 setParam(param_str, Tabular::SET_LINE_LEFT,
434                          borders->getLeft() ? "true" : "false");
435                 setParam(param_str, Tabular::SET_LINE_RIGHT,
436                          borders->getRight() ? "true" : "false");
437                 setParam(param_str, Tabular::SET_LINE_TOP,
438                          borders->getTop() ? "true" : "false");
439                 setParam(param_str, Tabular::SET_LINE_BOTTOM,
440                          borders->getBottom() ? "true" : "false");
441         }
442
443         // apply the special alignment
444         string special = fromqstr(specialAlignmentED->text());
445         if (special.empty())
446                 special = "none";
447         if (multicolumnCB->isChecked())
448                 setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
449         else if (multirowCB->isChecked())
450                 setParam(param_str, Tabular::SET_SPECIAL_MULTIROW, special);
451         else
452                 setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
453
454         // apply the fixed width values
455         string width = widgetsToLength(widthED, widthUnitCB);
456         if (width.empty())
457                 width = "0pt";
458         if (multicolumnCB->isChecked())
459                 setParam(param_str, Tabular::SET_MPWIDTH, width);
460         else
461                 setParam(param_str, Tabular::SET_PWIDTH, width);
462
463         //
464         if (multicolumnCB->isChecked())
465                 setParam(param_str, Tabular::MULTICOLUMN);
466         //
467         if (multirowCB->isChecked())
468                 setParam(param_str, Tabular::MULTIROW);
469         //
470         if (rotateTabularCB->isChecked())
471                 setParam(param_str, Tabular::SET_ROTATE_TABULAR);
472         else
473                 setParam(param_str, Tabular::UNSET_ROTATE_TABULAR);
474         //
475         if (rotateCellCB->isChecked())
476                 setParam(param_str, Tabular::SET_ROTATE_CELL);
477         else
478                 setParam(param_str, Tabular::UNSET_ROTATE_CELL);
479         //
480         if (longTabularCB->isChecked())
481                 setParam(param_str, Tabular::SET_LONGTABULAR);
482         else
483                 setParam(param_str, Tabular::UNSET_LONGTABULAR);
484         //
485         if (newpageCB->isChecked())
486                 setParam(param_str, Tabular::SET_LTNEWPAGE);
487         //
488         if (captionStatusCB->isChecked())
489                 setParam(param_str, Tabular::TOGGLE_LTCAPTION);
490         //
491         if (headerStatusCB->isChecked())
492                 setParam(param_str, Tabular::SET_LTHEAD, "none");
493         else
494                 setParam(param_str, Tabular::UNSET_LTHEAD, "none");
495         //
496         if (headerBorderAboveCB->isChecked())
497                 setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
498         else
499                 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
500         //
501         if (headerBorderBelowCB->isChecked())
502                 setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
503         else
504                 setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
505         if (firstheaderBorderAboveCB->isChecked())
506                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
507         else
508                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
509         if (firstheaderBorderBelowCB->isChecked())
510                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
511         else
512                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
513         if (firstheaderStatusCB->isChecked())
514                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
515         else
516                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
517         if (firstheaderNoContentsCB->isChecked())
518                 setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
519         else
520                 setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
521         if (footerStatusCB->isChecked())
522                 setParam(param_str, Tabular::SET_LTFOOT, "none");
523         else
524                 setParam(param_str, Tabular::UNSET_LTFOOT, "none");
525         if (footerBorderAboveCB->isChecked())
526                 setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
527         else
528                 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
529         if (footerBorderBelowCB->isChecked())
530                 setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
531         else
532                 setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
533         if (lastfooterStatusCB->isChecked())
534                 setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
535         else
536                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
537         if (lastfooterBorderAboveCB->isChecked())
538                 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
539         else
540                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
541         if (lastfooterBorderBelowCB->isChecked())
542                 setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
543         else
544                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
545         if (lastfooterNoContentsCB->isChecked())
546                 setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
547         else
548                 setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
549
550         if (leftRB->isChecked())
551                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
552         else if (centerRB->isChecked())
553                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
554         else if (rightRB->isChecked())
555                 setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
556
557         return from_utf8(param_str);
558 }
559
560
561 static Length getColumnPWidth(Tabular const & t, size_t cell)
562 {
563         return t.column_info[t.cellColumn(cell)].p_width;
564 }
565
566
567 static Length getMColumnPWidth(Tabular const & t, size_t cell)
568 {
569         if (t.isMultiColumn(cell) || t.isMultiRow(cell))
570                 return t.cellInfo(cell).p_width;
571         return Length();
572 }
573
574
575 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
576 {
577         if (what == Tabular::SET_SPECIAL_MULTICOLUMN
578                 || what == Tabular::SET_SPECIAL_MULTIROW)
579                 return t.cellInfo(cell).align_special;
580         return t.column_info[t.cellColumn(cell)].align_special;
581 }
582
583
584 void GuiTabular::paramsToDialog(Inset const * inset)
585 {
586         InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
587         // Copy Tabular of current inset.
588         Tabular const & tabular = itab->tabular;
589
590         BufferView const * bv = guiApp->currentView()->currentBufferView();
591         size_t const cell = bv->cursor().idx();
592
593         Tabular::row_type const row = tabular.cellRow(cell);
594         Tabular::col_type const col = tabular.cellColumn(cell);
595
596         tabularRowED->setText(QString::number(row + 1));
597         tabularColumnED->setText(QString::number(col + 1));
598
599         bool const multicol = tabular.isMultiColumn(cell);
600         multicolumnCB->setChecked(multicol);
601
602         bool const multirow = tabular.isMultiRow(cell);
603         multirowCB->setChecked(multirow);
604
605         rotateCellCB->setChecked(tabular.getRotateCell(cell));
606         rotateTabularCB->setChecked(tabular.rotate);
607
608         longTabularCB->setChecked(tabular.is_long_tabular);
609
610         borders->setTop(tabular.topLine(cell));
611         borders->setBottom(tabular.bottomLine(cell));
612         borders->setLeft(tabular.leftLine(cell));
613         borders->setRight(tabular.rightLine(cell));
614         // repaint the setborder widget
615         borders->update();
616
617         Length::UNIT const default_unit = Length::defaultUnit();
618
619         ///////////////////////////////////
620         // Set width and alignment
621         Length pwidth;
622         docstring special;
623         if (multicol) {
624                 special = getAlignSpecial(tabular, cell,
625                         Tabular::SET_SPECIAL_MULTICOLUMN);
626                 pwidth = getMColumnPWidth(tabular, cell);
627         } else if (multirow) {
628                 special = getAlignSpecial(tabular, cell,
629                         Tabular::SET_SPECIAL_MULTIROW);
630                 pwidth = getMColumnPWidth(tabular, cell);
631         } else {
632                 special = getAlignSpecial(tabular, cell,
633                         Tabular::SET_SPECIAL_COLUMN);
634                 pwidth = getColumnPWidth(tabular, cell);
635         }
636         string colwidth;
637         if (pwidth.zero())
638                 widthED->clear();
639         else {
640                 colwidth = pwidth.asString();
641                 lengthToWidgets(widthED, widthUnitCB,
642                         colwidth, default_unit);
643         }
644         specialAlignmentED->setText(toqstr(special));
645         ///////////////////////////////////
646
647
648         borderDefaultRB->setChecked(!tabular.use_booktabs);
649         booktabsRB->setChecked(tabular.use_booktabs);
650
651         if (tabular.row_info[row].top_space.empty()
652             && !tabular.row_info[row].top_space_default) {
653                 topspaceCO->setCurrentIndex(0);
654         } else if (tabular.row_info[row].top_space_default) {
655                 topspaceCO->setCurrentIndex(1);
656         } else {
657                 topspaceCO->setCurrentIndex(2);
658                 lengthToWidgets(topspaceED,
659                                 topspaceUnit,
660                                 tabular.row_info[row].top_space.asString(),
661                                 default_unit);
662         }
663
664         if (tabular.row_info[row].bottom_space.empty()
665             && !tabular.row_info[row].bottom_space_default) {
666                 bottomspaceCO->setCurrentIndex(0);
667         } else if (tabular.row_info[row].bottom_space_default) {
668                 bottomspaceCO->setCurrentIndex(1);
669         } else {
670                 bottomspaceCO->setCurrentIndex(2);
671                 lengthToWidgets(bottomspaceED,
672                                 bottomspaceUnit,
673                                 tabular.row_info[row].bottom_space.asString(),
674                                 default_unit);
675         }
676
677         if (tabular.row_info[row].interline_space.empty()
678             && !tabular.row_info[row].interline_space_default) {
679                 interlinespaceCO->setCurrentIndex(0);
680         } else if (tabular.row_info[row].interline_space_default) {
681                 interlinespaceCO->setCurrentIndex(1);
682         } else {
683                 interlinespaceCO->setCurrentIndex(2);
684                 lengthToWidgets(interlinespaceED,
685                                 interlinespaceUnit,
686                                 tabular.row_info[row].interline_space.asString(),
687                                 default_unit);
688         }
689
690         hAlignCB->clear();
691         hAlignCB->addItem(qt_("Left"));
692         hAlignCB->addItem(qt_("Center"));
693         hAlignCB->addItem(qt_("Right"));
694         if (!multicol && !pwidth.zero())
695                 hAlignCB->addItem(qt_("Justified"));
696
697         int align = 0;
698         switch (tabular.getAlignment(cell)) {
699         case LYX_ALIGN_LEFT:
700                 align = 0;
701                 break;
702         case LYX_ALIGN_CENTER:
703                 align = 1;
704                 break;
705         case LYX_ALIGN_RIGHT:
706                 align = 2;
707                 break;
708         case LYX_ALIGN_BLOCK:
709         {
710                 if (!multicol && !pwidth.zero())
711                         align = 3;
712                 break;
713         }
714         default:
715                 align = 0;
716                 break;
717         }
718         hAlignCB->setCurrentIndex(align);
719
720         int valign = 0;
721         switch (tabular.getVAlignment(cell)) {
722         case Tabular::LYX_VALIGN_TOP:
723                 valign = 0;
724                 break;
725         case Tabular::LYX_VALIGN_MIDDLE:
726                 valign = 1;
727                 break;
728         case Tabular::LYX_VALIGN_BOTTOM:
729                 valign = 2;
730                 break;
731         default:
732                 valign = 0;
733                 break;
734         }
735         if (pwidth.zero())
736                 valign = 0;
737         vAlignCB->setCurrentIndex(valign);
738
739         int tableValign = 1;
740         switch (tabular.tabular_valignment) {
741         case Tabular::LYX_VALIGN_TOP:
742                 tableValign = 0;
743                 break;
744         case Tabular::LYX_VALIGN_MIDDLE:
745                 tableValign = 1;
746                 break;
747         case Tabular::LYX_VALIGN_BOTTOM:
748                 tableValign = 2;
749                 break;
750         default:
751                 tableValign = 0;
752                 break;
753         }
754         TableAlignCB->setCurrentIndex(tableValign);
755
756         if (!tabular.is_long_tabular) {
757                 headerStatusCB->setChecked(false);
758                 headerBorderAboveCB->setChecked(false);
759                 headerBorderBelowCB->setChecked(false);
760                 firstheaderStatusCB->setChecked(false);
761                 firstheaderBorderAboveCB->setChecked(false);
762                 firstheaderBorderBelowCB->setChecked(false);
763                 firstheaderNoContentsCB->setChecked(false);
764                 footerStatusCB->setChecked(false);
765                 footerBorderAboveCB->setChecked(false);
766                 footerBorderBelowCB->setChecked(false);
767                 lastfooterStatusCB->setChecked(false);
768                 lastfooterBorderAboveCB->setChecked(false);
769                 lastfooterBorderBelowCB->setChecked(false);
770                 lastfooterNoContentsCB->setChecked(false);
771                 newpageCB->setChecked(false);
772                 captionStatusCB->blockSignals(true);
773                 captionStatusCB->setChecked(false);
774                 captionStatusCB->blockSignals(false);
775                 return;
776         } else {
777                 // longtables cannot have a vertical alignment
778                 TableAlignCB->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
779         }
780         switch (tabular.longtabular_alignment) {
781         case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
782                 leftRB->setChecked(true);
783                 break;
784         case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
785                 centerRB->setChecked(true);
786                 break;
787         case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
788                 rightRB->setChecked(true);
789                 break;
790         default:
791                 centerRB->setChecked(true);
792                 break;
793         }
794         captionStatusCB->blockSignals(true);
795         captionStatusCB->setChecked(tabular.ltCaption(row));
796         captionStatusCB->blockSignals(false);
797
798         Tabular::ltType ltt;
799         bool use_empty;
800         bool row_set = tabular.getRowOfLTHead(row, ltt);
801         headerStatusCB->setChecked(row_set);
802         if (ltt.set) {
803                 headerBorderAboveCB->setChecked(ltt.topDL);
804                 headerBorderBelowCB->setChecked(ltt.bottomDL);
805                 use_empty = true;
806         } else {
807                 headerBorderAboveCB->setChecked(false);
808                 headerBorderBelowCB->setChecked(false);
809                 firstheaderNoContentsCB->setChecked(false);
810                 use_empty = false;
811         }
812
813         row_set = tabular.getRowOfLTFirstHead(row, ltt);
814         firstheaderStatusCB->setChecked(row_set);
815         if (ltt.set && (!ltt.empty || !use_empty)) {
816                 firstheaderBorderAboveCB->setChecked(ltt.topDL);
817                 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
818         } else {
819                 firstheaderBorderAboveCB->setChecked(false);
820                 firstheaderBorderBelowCB->setChecked(false);
821         }
822
823         row_set = tabular.getRowOfLTFoot(row, ltt);
824         footerStatusCB->setChecked(row_set);
825         if (ltt.set) {
826                 footerBorderAboveCB->setChecked(ltt.topDL);
827                 footerBorderBelowCB->setChecked(ltt.bottomDL);
828                 use_empty = true;
829         } else {
830                 footerBorderAboveCB->setChecked(false);
831                 footerBorderBelowCB->setChecked(false);
832                 lastfooterNoContentsCB->setChecked(false);
833                 use_empty = false;
834         }
835
836         row_set = tabular.getRowOfLTLastFoot(row, ltt);
837         lastfooterStatusCB->setChecked(row_set);
838         if (ltt.set && (!ltt.empty || !use_empty)) {
839                 lastfooterBorderAboveCB->setChecked(ltt.topDL);
840                 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
841         } else {
842                 lastfooterBorderAboveCB->setChecked(false);
843                 lastfooterBorderBelowCB->setChecked(false);
844         }
845         newpageCB->setChecked(tabular.getLTNewPage(row));
846 }
847
848
849 } // namespace frontend
850 } // namespace lyx
851
852 #include "moc_GuiTabular.cpp"