]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiBox.cpp
Revert the box alignment part of 8010b90c
[lyx.git] / src / frontends / qt4 / GuiBox.cpp
1 /**
2  * \file GuiBox.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna (Minipage stuff)
7  * \author Martin Vermeer
8  * \author Jürgen Spitzmüller
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 "GuiBox.h"
17
18 #include "GuiApplication.h"
19 #include "ColorCache.h"
20 #include "ColorSet.h"
21 #include "LengthCombo.h"
22 #include "Length.h"
23 #include "qt_helpers.h"
24 #include "Validator.h"
25
26 #include "insets/InsetBox.h"
27
28 #include "support/gettext.h"
29 #include "support/foreach.h"
30 #include "support/lstrings.h"
31
32 #include <QComboBox>
33 #include <QLineEdit>
34 #include <QPushButton>
35
36 #ifdef IN
37 #undef IN
38 #endif
39
40 using namespace std;
41
42
43 namespace lyx {
44 namespace frontend {
45
46 static QStringList boxGuiIds()
47 {
48         return QStringList()
49                 << "Frameless" << "Boxed"
50                 << "ovalbox" << "Ovalbox"
51                 << "Shadowbox" << "Shaded"
52                 << "Doublebox";
53 }
54
55
56 static QStringList boxGuiNames()
57 {
58         return QStringList()
59                 << qt_("No frame") << qt_("Simple rectangular frame")
60                 << qt_("Oval frame, thin") << qt_("Oval frame, thick")
61                 << qt_("Drop shadow") << qt_("Shaded background")
62                 << qt_("Double rectangular frame");
63 }
64
65
66 static QStringList boxGuiSpecialLengthIds()
67 {
68         return QStringList() << "height" << "depth"
69                 << "totalheight" << "width";
70 }
71
72
73 static QStringList boxGuiSpecialLengthNames()
74 {
75         return QStringList() << qt_("Height") << qt_("Depth")
76                 << qt_("Total Height") << qt_("Width");
77 }
78
79
80 static QList<ColorCode> colors()
81 {
82         QList<ColorCode> colors;
83         colors << Color_black;
84         colors << Color_white;
85         colors << Color_blue;
86         colors << Color_brown;
87         colors << Color_cyan;
88         colors << Color_darkgray;
89         colors << Color_gray;
90         colors << Color_green;
91         colors << Color_lightgray;
92         colors << Color_lime;
93         colors << Color_magenta;
94         colors << Color_olive;
95         colors << Color_orange;
96         colors << Color_pink;
97         colors << Color_purple;
98         colors << Color_red;
99         colors << Color_teal;
100         colors << Color_violet;
101         colors << Color_yellow;
102         return colors;
103 }
104
105
106 namespace {
107
108 bool ColorSorter(ColorCode lhs, ColorCode rhs)
109 {
110         return support::compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
111 }
112
113 } // namespace anon
114
115
116 GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
117 {
118         setupUi(this);
119
120         // fill the box type choice
121         ids_ = boxGuiIds();
122         gui_names_ = boxGuiNames();
123         for (int i = 0; i != ids_.size(); ++i)
124                 typeCO->addItem(gui_names_[i], ids_[i]);
125
126         // add the special units to the height choice
127         // width needs different handling
128         ids_spec_ = boxGuiSpecialLengthIds();
129         gui_names_spec_ = boxGuiSpecialLengthNames();
130         for (int i = 0; i != ids_spec_.size(); ++i)
131                 heightUnitsLC->addItem(gui_names_spec_[i], ids_spec_[i]);
132
133         connect(widthED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
134         connect(widthUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
135                 this, SIGNAL(changed()));
136         connect(valignCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed()));
137         connect(heightED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
138         connect(heightUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
139                 this, SIGNAL(changed()));
140         connect(halignCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
141         connect(ialignCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
142         connect(thicknessED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
143         connect(thicknessUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
144                 this, SIGNAL(changed()));
145         connect(separationED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
146         connect(separationUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
147                 this, SIGNAL(changed()));
148         connect(shadowsizeED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
149         connect(shadowsizeUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
150                 this, SIGNAL(changed()));
151         connect(backgroundColorCO, SIGNAL(currentIndexChanged(int)),
152                 this, SIGNAL(changed()));
153
154         heightED->setValidator(unsignedLengthValidator(heightED));
155         widthED->setValidator(unsignedLengthValidator(widthED));
156         thicknessED->setValidator(unsignedLengthValidator(thicknessED));
157         separationED->setValidator(unsignedLengthValidator(separationED));
158         shadowsizeED->setValidator(unsignedLengthValidator(shadowsizeED));
159
160         // initialize the length validator
161         addCheckedWidget(widthED, widthCB);
162         addCheckedWidget(heightED, heightCB);
163         addCheckedWidget(thicknessED, thicknessLA);
164         addCheckedWidget(separationED, separationLA);
165         addCheckedWidget(shadowsizeED, shadowsizeLA);
166
167         // the background can be uncolored while the frame cannot
168         color_codes_ = colors();
169         qSort(color_codes_.begin(), color_codes_.end(), ColorSorter);
170         fillComboColor(backgroundColorCO, true);
171         fillComboColor(frameColorCO, false);
172
173         initDialog();
174 }
175
176
177 void GuiBox::fillComboColor(QComboBox * combo, bool const is_none)
178 {
179         combo->clear();
180         QPixmap coloritem(32, 32);
181         QColor color;
182         // frameColorCO cannot be uncolored
183         if (is_none)
184                 combo->addItem(toqstr(translateIfPossible(lcolor.getGUIName(Color_none))),
185                                toqstr(lcolor.getLaTeXName(Color_none)));
186         QList<ColorCode>::const_iterator cit = color_codes_.begin();
187         for (; cit != color_codes_.end(); ++cit) {
188                 QString const latexname = toqstr(lcolor.getLaTeXName(*cit));
189                 QString const guiname = toqstr(translateIfPossible(lcolor.getGUIName(*cit)));
190                 color = QColor(guiApp->colorCache().get(*cit, false));
191                 coloritem.fill(color);
192                 combo->addItem(QIcon(coloritem), guiname, latexname);
193         }
194 }
195
196
197 void GuiBox::on_innerBoxCO_activated(int index)
198 {
199         QString itype = innerBoxCO->itemData(index).toString();
200         // handle parbox and minipage the same way
201         bool const ibox = (itype != "none" && itype != "makebox");
202         if (heightCB->isChecked() && !ibox)
203                 heightCB->setChecked(false);
204         widthCB->setChecked(!widthED->text().isEmpty());
205         setSpecial(ibox);
206         changed();
207 }
208
209
210 void GuiBox::on_typeCO_activated(int index)
211 {
212         QString const type =
213                 typeCO->itemData(index).toString();
214         bool const frameless = (type == "Frameless");
215         QString itype =
216                 innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
217         setInnerType(frameless, itype);
218         // refresh itype because it might have been changed in setInnerType
219         itype =
220                 innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
221         // handle parbox and minipage the same way
222         bool const ibox = (itype != "none" && itype != "makebox");
223         if (frameless && itype != "makebox") {
224                 if (heightCB->isChecked() && !ibox)
225                         heightCB->setChecked(false);
226                 setSpecial(ibox);
227         }
228         if (type != "Boxed") {
229                 if (type != "Frameless")
230                         widthCB->setChecked(itype != "none");
231                 pagebreakCB->setChecked(false);
232         }
233         // assure that the frame color is black for frameless boxes to
234         // provide the color "none"
235         int const b = frameColorCO->findData("black");
236         if (frameless && frameColorCO->currentIndex() != b)
237                 frameColorCO->setCurrentIndex(b);
238         changed();
239 }
240
241
242 void GuiBox::on_frameColorCO_currentIndexChanged(int index)
243 {
244         // if there is a non-black frame color the background cannot be uncolored
245         // therefore remove the entry "none" in this case
246         int const n = backgroundColorCO->findData("none");
247         if (index != frameColorCO->findData("black")) {
248                 if (n != -1) {
249                         if (backgroundColorCO->currentIndex() == n)
250                                 backgroundColorCO->setCurrentIndex(
251                                             backgroundColorCO->findData("white"));
252                         backgroundColorCO->removeItem(n);
253                 }
254         } else {
255                 if (n == -1)
256                         backgroundColorCO->insertItem(0, toqstr(translateIfPossible((lcolor.getGUIName(Color_none)))),
257                                                       toqstr(lcolor.getLaTeXName(Color_none)));
258         }
259         changed();
260 }
261
262
263 void GuiBox::initDialog()
264 {
265         setInnerType(true, toqstr("minipage"));
266         widthED->setText("100");
267         widthCB->setChecked(true);
268         widthCB->setEnabled(false);
269         widthUnitsLC->setCurrentItem(Length::PCW);
270         heightED->setText("1");
271         heightUnitsLC->setCurrentItem("totalheight");
272         // LaTeX's default for \fboxrule is 0.4 pt
273         thicknessED->setText("0.4");
274         thicknessUnitsLC->setCurrentItem(Length::PT);
275         // LaTeX's default for \fboxsep is 3 pt
276         separationED->setText("3");
277         separationUnitsLC->setCurrentItem(Length::PT);
278         // LaTeX's default for \shadowsize is 4 pt
279         shadowsizeED->setText("4");
280         shadowsizeUnitsLC->setCurrentItem(Length::PT);
281 }
282
283
284 void GuiBox::on_widthCB_stateChanged(int)
285 {
286         changed();
287 }
288
289
290 void GuiBox::on_heightCB_stateChanged(int /*state*/)
291 {
292         changed();
293 }
294
295
296 void GuiBox::on_pagebreakCB_stateChanged()
297 {
298         bool pbreak = (pagebreakCB->checkState() == Qt::Checked);
299         if (pbreak)
300                 widthCB->setChecked(!pbreak);
301         if (!pbreak) {
302                 on_typeCO_activated(typeCO->currentIndex());
303                 return;
304         }
305         setSpecial(false);
306         changed();
307 }
308
309
310 void GuiBox::paramsToDialog(Inset const * inset)
311 {
312         InsetBox const * box = static_cast<InsetBox const *>(inset);
313         InsetBoxParams const & params = box->params();
314         QString type = toqstr(params.type);
315         if (type == "Framed") {
316                 pagebreakCB->setChecked(true);
317                 type = "Boxed";
318         } else {
319                 pagebreakCB->setChecked(false);
320         }
321
322         typeCO->setCurrentIndex(typeCO->findData(type));
323
324         // default: minipage
325         QString inner_type = "minipage";
326         if (!params.inner_box)
327                 inner_type = "none";
328         if (params.use_parbox)
329                 inner_type = "parbox";
330         if (params.use_makebox)
331                 inner_type = "makebox";
332         bool const frameless = (params.type == "Frameless");
333         setInnerType(frameless, inner_type);
334
335         char c = params.pos;
336         valignCO->setCurrentIndex(string("tcb").find(c, 0));
337         c = params.inner_pos;
338         ialignCO->setCurrentIndex(string("tcbs").find(c, 0));
339         c = params.hor_pos;
340         halignCO->setCurrentIndex(string("lcrs").find(c, 0));
341
342         bool ibox = (params.inner_box && !params.use_makebox);
343         valignCO->setEnabled(ibox);
344         ialignCO->setEnabled(ibox);
345         setSpecial(ibox);
346
347         // halign is only allowed without inner box and if a width is used and if
348         // pagebreak is not used
349         halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
350                              && ((!ibox && type == "Boxed") || inner_type == "makebox"));
351         // add the entry "Stretch" if the box is \makebox or \framebox and if not already there
352         if ((inner_type == "makebox" || (type == "Boxed" && inner_type == "none"))
353                 && halignCO->count() < 4)
354                 halignCO->addItem(toqstr("Stretch"));
355         else if (inner_type != "makebox" && (type != "Boxed" && inner_type != "none"))
356                 halignCO->removeItem(3); 
357         // pagebreak is only allowed for Boxed without inner box
358         pagebreakCB->setEnabled(!ibox && type == "Boxed");
359
360         Length::UNIT const default_unit = Length::defaultUnit();
361
362         // the width can only be selected for makebox or framebox
363         widthCB->setEnabled(inner_type == "makebox"
364                             || (type == "Boxed"
365                                 && !ibox && !pagebreakCB->isChecked()));
366         if (params.width.empty()) {
367                 widthCB->setChecked(false);
368                 lengthToWidgets(widthED, widthUnitsLC,
369                         params.width, default_unit);
370         } else {
371                 widthCB->setChecked(true);
372                 lengthToWidgets(widthED, widthUnitsLC,
373                         params.width, default_unit);
374                 QString const special = toqstr(params.special);
375                 if (!special.isEmpty() && special != "none")
376                         widthUnitsLC->setCurrentItem(special);
377         }
378
379         widthED->setEnabled(widthCB->isChecked());
380         widthUnitsLC->setEnabled(widthCB->isChecked());
381
382         lengthToWidgets(heightED, heightUnitsLC,
383                 (params.height).asString(), default_unit);
384
385         QString const height_special = toqstr(params.height_special);
386         if (!height_special.isEmpty() && height_special != "none")
387                 heightUnitsLC->setCurrentItem(height_special);
388         // set no optional height if the value is the default "1\height"
389         // (special units like \height are handled as "in",
390         // FIXME: this is a very bad UI, this check box should be disabled in
391         // this case, not forced to 'unchecked' state.
392         if (height_special == "totalheight" && params.height == Length("1in"))
393                 heightCB->setCheckState(Qt::Unchecked);
394         else
395                 heightCB->setCheckState(Qt::Checked);
396
397         heightCB->setEnabled(ibox);
398
399         // enable line thickness only for the rectangular frame types and drop shadow
400         thicknessED->setEnabled(type == "Boxed" || type == "Doublebox" || type == "Shadowbox");
401         thicknessUnitsLC->setEnabled(type == "Boxed" || type == "Doublebox" || type == "Shadowbox");
402         lengthToWidgets(thicknessED, thicknessUnitsLC,
403                 (params.thickness).asString(), default_unit);
404         // enable line separation for the allowed frame types
405         separationED->setEnabled(type == "Boxed" || type == "ovalbox" || type == "Ovalbox"
406                 || type == "Doublebox" || type == "Shadowbox");
407         separationUnitsLC->setEnabled(type == "Boxed" || type == "ovalbox" || type == "Ovalbox"
408                 || type == "Doublebox" || type == "Shadowbox");
409         lengthToWidgets(separationED, separationUnitsLC,
410                 (params.separation).asString(), default_unit);
411         // enable shadow size for drop shadow
412         shadowsizeED->setEnabled(type == "Shadowbox");
413         shadowsizeUnitsLC->setEnabled(type == "Shadowbox");
414         lengthToWidgets(shadowsizeED, shadowsizeUnitsLC,
415                 (params.shadowsize).asString(), default_unit);
416         // set color
417         frameColorCO->setCurrentIndex(frameColorCO->findData(toqstr(params.framecolor)));
418         backgroundColorCO->setCurrentIndex(backgroundColorCO->findData(toqstr(params.backgroundcolor)));
419 }
420
421
422 docstring GuiBox::dialogToParams() const
423 {
424         bool const pagebreak =
425                 pagebreakCB->isEnabled() && pagebreakCB->isChecked();
426         string box_type;
427         if (pagebreak)
428                 box_type = "Framed";
429         else
430                 box_type = fromqstr(typeCO->itemData(
431                                 typeCO->currentIndex()).toString());
432
433         InsetBoxParams params(box_type);
434         params.inner_box =
435                 (!pagebreak && innerBoxCO->currentText() != qt_("None"));
436         params.use_parbox =
437                 (!pagebreak && innerBoxCO->currentText() == qt_("Parbox"));
438         params.use_makebox =
439                 (!pagebreak && innerBoxCO->currentText() == qt_("Makebox"));
440
441         params.pos = "tcb"[valignCO->currentIndex()];
442         params.inner_pos = "tcbs"[ialignCO->currentIndex()];
443         params.hor_pos = "lcrs"[halignCO->currentIndex()];
444
445         QString unit =
446                 widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString();
447         QString value = widthED->text();
448
449         if (widthED->isEnabled()) {
450                 if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
451                         params.special = fromqstr(unit);
452                         // Note: the unit is simply ignored in this case
453                         params.width = Length(value.toDouble(), Length::IN);
454                 } else {
455                         params.special = "none";
456                         // we must specify a valid length in this case
457                         if (value.isEmpty())
458                                 widthED->setText("0");
459                         params.width = Length(widgetsToLength(widthED, widthUnitsLC));
460                 }
461         } else {
462                 params.special = "none";
463                 params.width = Length();
464         }
465
466         // the height parameter is omitted if the value
467         // is "1in" and "Total Height" is used as unit.
468         // 1in + "Total Height" means "1\height" which is the LaTeX default
469         // if no height is given
470         if (heightCB->checkState() == Qt::Unchecked) {
471                 params.height = Length("1in");
472                 params.height_special = "totalheight";
473         } else {
474                 unit = heightUnitsLC->itemData(heightUnitsLC->currentIndex()).toString();
475                 value = heightED->text();
476                 if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
477                         params.height_special = fromqstr(unit);
478                         // Note: the unit is simply ignored in this case
479                         params.height = Length(value.toDouble(), Length::IN);
480                 } else {
481                         params.height_special = "none";
482                         params.height =
483                                 Length(widgetsToLength(heightED, heightUnitsLC));
484                 }
485         }
486
487         // handle the line thickness, line separation and shadow size
488         if (thicknessED->isEnabled())
489                 params.thickness = Length(widgetsToLength(thicknessED, thicknessUnitsLC));
490         else
491                 params.thickness = Length("0.4pt");
492         if (separationED->isEnabled())
493                 params.separation = Length(widgetsToLength(separationED, separationUnitsLC));
494         else
495                 params.separation = Length("3pt");
496         if (separationED->isEnabled())
497                 params.shadowsize = Length(widgetsToLength(shadowsizeED, shadowsizeUnitsLC));
498         else
499                 params.shadowsize = Length("4pt");
500         if (frameColorCO->isEnabled())
501                 params.framecolor =
502                         fromqstr(frameColorCO->itemData(frameColorCO->currentIndex()).toString());
503         else
504                 params.framecolor = "black";
505         if (backgroundColorCO->isEnabled())
506                 params.backgroundcolor =
507                         fromqstr(backgroundColorCO->itemData(backgroundColorCO->currentIndex()).toString());
508         else
509                 params.backgroundcolor = "none";
510
511         return from_ascii(InsetBox::params2string(params));
512 }
513
514
515 bool GuiBox::checkWidgets(bool readonly) const
516 {
517         typeCO->setEnabled(!readonly);
518
519         if (readonly) {
520                 pagebreakCB->setEnabled(false);
521                 innerBoxCO->setEnabled(false);
522                 valignCO->setEnabled(false);
523                 ialignCO->setEnabled(false);
524                 halignCO->setEnabled(false);
525                 widthCB->setEnabled(false);
526                 widthED->setEnabled(false);
527                 widthUnitsLC->setEnabled(false);
528                 heightED->setEnabled(false);
529                 heightUnitsLC->setEnabled(false);
530                 heightCB->setEnabled(false);
531                 thicknessED->setEnabled(false);
532                 thicknessUnitsLC->setEnabled(false);
533                 separationED->setEnabled(false);
534                 separationUnitsLC->setEnabled(false);
535                 shadowsizeED->setEnabled(false);
536                 shadowsizeUnitsLC->setEnabled(false);
537         } else {
538                 QString const outer =
539                         typeCO->itemData(typeCO->currentIndex()).toString();
540                 QString const itype =
541                         innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
542                 bool const ibox = (itype != "none" && itype != "makebox");
543                 valignCO->setEnabled(ibox);
544                 ialignCO->setEnabled(ibox);
545                 if (heightCB->isChecked() && !ibox)
546                         heightCB->setChecked(false);
547                 heightCB->setEnabled(ibox);
548                 // the width can only be selected for makebox or framebox
549                 widthCB->setEnabled(itype == "makebox"
550                         || (outer == "Boxed" && itype == "none" && !pagebreakCB->isChecked()));
551                 // except for Frameless and Boxed, the width cannot be specified if
552                 // there is no inner box
553                 bool const width_enabled =
554                         ibox || outer == "Frameless" || (outer == "Boxed" && !pagebreakCB->isChecked());
555                 // enable if width_enabled
556                 widthED->setEnabled(width_enabled);
557                 widthUnitsLC->setEnabled(width_enabled);
558                 if (!widthCB->isChecked() && widthCB->isEnabled()) {
559                         widthED->setEnabled(false);
560                         widthUnitsLC->setEnabled(false);
561                 }
562                 // halign is only allowed without inner box and if a width is used and if
563                 // pagebreak is not used
564                 halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
565                                      && ((!ibox && outer == "Boxed") || itype == "makebox"));
566                 // add the entry "Stretch" if the box is \makebox or \framebox and if not already there
567                 if ((itype == "makebox" || (outer == "Boxed" && itype == "none"))
568                         && halignCO->count() < 4)
569                         halignCO->addItem(toqstr("Stretch"));
570                 else if (itype != "makebox" && (outer != "Boxed" && itype != "none"))
571                         halignCO->removeItem(3);
572                 // pagebreak is only allowed for Boxed without inner box
573                 pagebreakCB->setEnabled(!ibox && outer == "Boxed");
574
575                 heightED->setEnabled(itype != "none" && heightCB->isChecked());
576                 heightUnitsLC->setEnabled(itype != "none" && heightCB->isChecked());
577                 heightCB->setEnabled(ibox);
578
579                 // enable line thickness for the rectangular frame types and drop shadow
580                 thicknessED->setEnabled(outer == "Boxed" || outer == "Doublebox" || outer == "Shadowbox");
581                 thicknessUnitsLC->setEnabled(outer == "Boxed" || outer == "Doublebox" || outer == "Shadowbox");
582                 // set default values if empty
583                 if (thicknessED->text().isEmpty() && thicknessED->isEnabled()) {
584                         thicknessED->setText("0.4");
585                         thicknessUnitsLC->setCurrentItem(Length::PT);
586                 }
587                 // enable line separation for the allowed frame types
588                 separationED->setEnabled(outer == "Boxed" || outer == "ovalbox" || outer == "Ovalbox"
589                         || outer == "Doublebox" || outer == "Shadowbox");
590                 separationUnitsLC->setEnabled(outer == "Boxed" || outer == "ovalbox" || outer == "Ovalbox"
591                         || outer == "Doublebox" || outer == "Shadowbox");
592                 // set default values if empty
593                 if (separationED->text().isEmpty() && separationED->isEnabled()) {
594                         separationED->setText("3");
595                         separationUnitsLC->setCurrentItem(Length::PT);
596                 }
597                 // enable shadow size for drop shadow
598                 shadowsizeED->setEnabled(outer == "Shadowbox");
599                 shadowsizeUnitsLC->setEnabled(outer == "Shadowbox");
600                 // set default values if empty
601                 if (shadowsizeED->text().isEmpty() && shadowsizeED->isEnabled()) {
602                         shadowsizeED->setText("4");
603                         shadowsizeUnitsLC->setCurrentItem(Length::PT);
604                 }
605                 // \fboxcolor and \colorbox cannot be used for fancybox boxes
606                 frameColorCO->setEnabled(!pagebreakCB->isChecked() && outer == "Boxed");
607                 backgroundColorCO->setEnabled(!pagebreakCB->isChecked() && (frameColorCO->isEnabled() || outer == "Frameless"));
608         }
609
610         return InsetParamsWidget::checkWidgets();
611 }
612
613
614 void GuiBox::setSpecial(bool ibox)
615 {
616         QString const last_item =
617                 widthUnitsLC->itemData(heightUnitsLC->currentIndex()).toString();
618
619         // check if the widget contains the special units
620         bool const has_special = (widthUnitsLC->findData("totalheight") != -1);
621         // insert 'em if needed...
622         if (!ibox && !has_special) {
623                 for (int i = 1; i < ids_spec_.size(); ++i)
624                         widthUnitsLC->addItem(gui_names_spec_[i], ids_spec_[i]);
625         // ... or remove 'em if needed
626         } else if (ibox && has_special) {
627                 for (int i = 1; i < ids_spec_.size(); ++i) {
628                         int n = widthUnitsLC->findData(ids_spec_[i]);
629                         if (n != -1)
630                                 widthUnitsLC->removeItem(n);
631                 }
632         }
633         // restore selected text, if possible
634         widthUnitsLC->setCurrentItem(last_item);
635 }
636
637
638 void GuiBox::setInnerType(bool frameless, QString const & type)
639 {
640         // with "frameless" boxes, inner box is mandatory
641         // (i.e. is the actual box)
642         // we have to remove "none" then and adjust the combo
643         innerBoxCO->clear();
644         if (!frameless)
645                 innerBoxCO->addItem(qt_("None"), toqstr("none"));
646         else
647                 innerBoxCO->addItem(qt_("Makebox"), toqstr("makebox"));
648         innerBoxCO->addItem(qt_("Parbox"), toqstr("parbox"));
649         innerBoxCO->addItem(qt_("Minipage"), toqstr("minipage"));
650         int i = (innerBoxCO->findData(type) != -1)
651                 ? innerBoxCO->findData(type) : 0;
652         innerBoxCO->setCurrentIndex(i);
653 }
654
655 } // namespace frontend
656 } // namespace lyx
657
658
659 #include "moc_GuiBox.cpp"