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