]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiBox.cpp
GuiBox.cpp: add a comment and a string conversion
[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 "LengthCombo.h"
21 #include "Length.h"
22 #include "qt_helpers.h"
23 #include "Validator.h"
24
25 #include "insets/InsetBox.h"
26
27 #include "support/gettext.h"
28 #include "support/foreach.h"
29 #include "support/lstrings.h"
30
31 #include <QComboBox>
32 #include <QLineEdit>
33 #include <QPushButton>
34
35 #ifdef IN
36 #undef IN
37 #endif
38
39 using namespace std;
40
41
42 namespace lyx {
43 namespace frontend {
44
45 static QStringList boxGuiIds()
46 {
47         return QStringList()
48                 << "Frameless" << "Boxed"
49                 << "ovalbox" << "Ovalbox"
50                 << "Shadowbox" << "Shaded"
51                 << "Doublebox";
52 }
53
54
55 static QStringList boxGuiNames()
56 {
57         return QStringList()
58                 << qt_("No frame") << qt_("Simple rectangular frame")
59                 << qt_("Oval frame, thin") << qt_("Oval frame, thick")
60                 << qt_("Drop shadow") << qt_("Shaded background")
61                 << qt_("Double rectangular frame");
62 }
63
64
65 static QStringList boxGuiSpecialLengthIds()
66 {
67         return QStringList() << "height" << "depth"
68                 << "totalheight" << "width";
69 }
70
71
72 static QStringList boxGuiSpecialLengthNames()
73 {
74         return QStringList() << qt_("Height") << qt_("Depth")
75                 << qt_("Total Height") << qt_("Width");
76 }
77
78
79 static QList<ColorPair> colorData()
80 {
81         QList<ColorPair> colors;
82         colors << ColorPair(qt_("none"), Color_none);
83         colors << ColorPair(qt_("black"), Color_black);
84         colors << ColorPair(qt_("white"), Color_white);
85         colors << ColorPair(qt_("blue"), Color_blue);
86         colors << ColorPair(qt_("brown"), Color_brown);
87         colors << ColorPair(qt_("cyan"), Color_cyan);
88         colors << ColorPair(qt_("darkgray"), Color_darkgray);
89         colors << ColorPair(qt_("gray"), Color_gray);
90         colors << ColorPair(qt_("green"), Color_green);
91         colors << ColorPair(qt_("lightgray"), Color_lightgray);
92         colors << ColorPair(qt_("lime"), Color_lime);
93         colors << ColorPair(qt_("magenta"), Color_magenta);
94         colors << ColorPair(qt_("olive"), Color_olive);
95         colors << ColorPair(qt_("orange"), Color_orange);
96         colors << ColorPair(qt_("pink"), Color_pink);
97         colors << ColorPair(qt_("purple"), Color_purple);
98         colors << ColorPair(qt_("red"), Color_red);
99         colors << ColorPair(qt_("teal"), Color_teal);
100         colors << ColorPair(qt_("violet"), Color_violet);
101         colors << ColorPair(qt_("yellow"), Color_yellow);
102         return colors;
103 }
104
105
106 template<typename T>
107 void fillComboColor(QComboBox * combo, QList<T> const & list, bool const is_none)
108 {
109         QPixmap coloritem(32, 32);
110         QColor color;
111         // frameColorCO cannot be uncolored
112         if (is_none)
113                 combo->addItem(qt_("none"));
114         typename QList<T>::const_iterator cit = list.begin() + 1;
115         for (; cit != list.end(); ++cit) {
116                 color = QColor(guiApp->colorCache().get(cit->second, false));
117                 coloritem.fill(color);
118                 combo->addItem(QIcon(coloritem), cit->first);
119         }
120 }
121
122
123 template<class P>
124 static int findPos2nd(QList<P> const & vec, QString val)
125 {
126         for (int i = 0; i != vec.size(); ++i)
127                 if (vec[i].first == val)
128                         return i;
129         return 0;
130 }
131
132
133 GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
134 {
135         setupUi(this);
136
137         // fill the box type choice
138         ids_ = boxGuiIds();
139         gui_names_ = boxGuiNames();
140         for (int i = 0; i != ids_.size(); ++i)
141                 typeCO->addItem(gui_names_[i], ids_[i]);
142
143         // add the special units to the height choice
144         // width needs different handling
145         ids_spec_ = boxGuiSpecialLengthIds();
146         gui_names_spec_ = boxGuiSpecialLengthNames();
147         for (int i = 0; i != ids_spec_.size(); ++i)
148                 heightUnitsLC->addItem(gui_names_spec_[i], ids_spec_[i]);
149
150         connect(widthED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
151         connect(widthUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
152                 this, SIGNAL(changed()));
153         connect(valignCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed()));
154         connect(heightED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
155         connect(heightUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
156                 this, SIGNAL(changed()));
157         connect(halignCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
158         connect(ialignCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
159         connect(thicknessED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
160         connect(thicknessUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
161                 this, SIGNAL(changed()));
162         connect(separationED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
163         connect(separationUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
164                 this, SIGNAL(changed()));
165         connect(shadowsizeED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
166         connect(shadowsizeUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
167                 this, SIGNAL(changed()));
168         connect(frameColorCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed()));
169         connect(backgroundColorCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed()));
170
171         heightED->setValidator(unsignedLengthValidator(heightED));
172         widthED->setValidator(unsignedLengthValidator(widthED));
173         thicknessED->setValidator(unsignedLengthValidator(thicknessED));
174         separationED->setValidator(unsignedLengthValidator(separationED));
175         shadowsizeED->setValidator(unsignedLengthValidator(shadowsizeED));
176
177         // initialize the length validator
178         addCheckedWidget(widthED, widthCB);
179         addCheckedWidget(heightED, heightCB);
180         addCheckedWidget(thicknessED, thicknessLA);
181         addCheckedWidget(separationED, separationLA);
182         addCheckedWidget(shadowsizeED, shadowsizeLA);
183
184         // initialize colors
185         color = colorData();
186         // the background can be uncolored while the frame cannot
187         fillComboColor(frameColorCO, color, false);
188         fillComboColor(backgroundColorCO, color, true);
189
190         initDialog();
191 }
192
193
194 void GuiBox::on_innerBoxCO_activated(int /* index */)
195 {
196         QString itype =
197                 innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
198         // handle parbox and minipage the same way
199         bool const ibox = (itype != "none" && itype != "makebox");
200         if (heightCB->isChecked() && !ibox)
201                 heightCB->setChecked(false);
202         widthCB->setChecked(!widthED->text().isEmpty());
203         setSpecial(ibox);
204         changed();
205 }
206
207
208 void GuiBox::on_typeCO_activated(int index)
209 {
210         QString const type =
211                 typeCO->itemData(index).toString();
212         bool const frameless = (type == "Frameless");
213         QString itype =
214                 innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
215         setInnerType(frameless, itype);
216         // refresh itype because it might have been changed in setInnerType
217         itype =
218                 innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
219         // handle parbox and minipage the same way
220         bool const ibox = (itype != "none" && itype != "makebox");
221         if (frameless && itype != "makebox") {
222                 if (heightCB->isChecked() && !ibox)
223                         heightCB->setChecked(false);
224                 setSpecial(ibox);
225         }
226         if (type != "Boxed") {
227                 if (type != "Frameless")
228                         widthCB->setChecked(itype != "none");
229                 pagebreakCB->setChecked(false);
230         }
231         // assure that the frame color is black for frameless boxes to
232         // provide the color "none"
233         if (frameless && frameColorCO->currentText() != qt_("black"))
234                 frameColorCO->setCurrentIndex(0);
235         changed();
236 }
237
238
239 void GuiBox::on_frameColorCO_currentIndexChanged(int /* index */)
240 {
241         // if there is a special frme color the background canot be uncolored
242         if (frameColorCO->currentText() != qt_("black")) {
243                 if (backgroundColorCO->currentText() == qt_("none"))
244                         backgroundColorCO->setCurrentIndex(findPos2nd(color, qt_("white")));
245                 if (backgroundColorCO->itemText(0) == qt_("none"))
246                         backgroundColorCO->removeItem(0);
247         } else {
248                 if (backgroundColorCO->itemText(0) != qt_("none"))
249                         backgroundColorCO->insertItem(0, qt_("none"));
250         }
251         changed();
252 }
253
254
255 void GuiBox::initDialog()
256 {
257         setInnerType(true, toqstr("minipage"));
258         widthED->setText("100");
259         widthCB->setChecked(true);
260         widthCB->setEnabled(false);
261         widthUnitsLC->setCurrentItem(Length::PCW);
262         heightED->setText("1");
263         heightUnitsLC->setCurrentItem("totalheight");
264         // LaTeX's default for \fboxrule is 0.4 pt
265         thicknessED->setText("0.4");
266         thicknessUnitsLC->setCurrentItem(Length::PT);
267         // LaTeX's default for \fboxsep is 3 pt
268         separationED->setText("3");
269         separationUnitsLC->setCurrentItem(Length::PT);
270         // LaTeX's default for \shadowsize is 4 pt
271         shadowsizeED->setText("4");
272         shadowsizeUnitsLC->setCurrentItem(Length::PT);
273         // the default color is black and none
274         frameColorCO->setCurrentIndex(findPos2nd(color, qt_("black")) - 1);
275         backgroundColorCO->setCurrentIndex(findPos2nd(color, qt_("none")));
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         if (frameColorCO->currentText() != qt_("black"))
412                 backgroundColorCO->setCurrentIndex(findPos2nd(color, qt_(params.backgroundcolor)) - 1);
413         else
414                 backgroundColorCO->setCurrentIndex(findPos2nd(color, qt_(params.backgroundcolor)));
415 }
416
417
418 docstring GuiBox::dialogToParams() const
419 {
420         bool const pagebreak =
421                 pagebreakCB->isEnabled() && pagebreakCB->isChecked();
422         string box_type;
423         if (pagebreak)
424                 box_type = "Framed";
425         else
426                 box_type = fromqstr(typeCO->itemData(
427                                 typeCO->currentIndex()).toString());
428
429         InsetBoxParams params(box_type);
430         params.inner_box =
431                 (!pagebreak && innerBoxCO->currentText() != qt_("None"));
432         params.use_parbox =
433                 (!pagebreak && innerBoxCO->currentText() == qt_("Parbox"));
434         params.use_makebox =
435                 (!pagebreak && innerBoxCO->currentText() == qt_("Makebox"));
436
437         params.pos = "tcb"[valignCO->currentIndex()];
438         params.inner_pos = "tcbs"[ialignCO->currentIndex()];
439         params.hor_pos = "lcrs"[halignCO->currentIndex()];
440
441         QString unit =
442                 widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString();
443         QString value = widthED->text();
444
445         if (widthED->isEnabled()) {
446                 if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
447                         params.special = fromqstr(unit);
448                         // Note: the unit is simply ignored in this case
449                         params.width = Length(value.toDouble(), Length::IN);
450                 } else {
451                         params.special = "none";
452                         // we must specify a valid length in this case
453                         if (value.isEmpty())
454                                 widthED->setText("0");
455                         params.width = Length(widgetsToLength(widthED, widthUnitsLC));
456                 }
457         } else {
458                 params.special = "none";
459                 params.width = Length();
460         }
461
462         // the height parameter is omitted if the value
463         // is "1in" and "Total Height" is used as unit.
464         // 1in + "Total Height" means "1\height" which is the LaTeX default
465         // if no height is given
466         if (heightCB->checkState() == Qt::Unchecked) {
467                 params.height = Length("1in");
468                 params.height_special = "totalheight";
469         } else {
470                 unit = heightUnitsLC->itemData(heightUnitsLC->currentIndex()).toString();
471                 value = heightED->text();
472                 if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
473                         params.height_special = fromqstr(unit);
474                         // Note: the unit is simply ignored in this case
475                         params.height = Length(value.toDouble(), Length::IN);
476                 } else {
477                         params.height_special = "none";
478                         params.height =
479                                 Length(widgetsToLength(heightED, heightUnitsLC));
480                 }
481         }
482
483         // handle the line thickness, line separation and shadow size
484         if (thicknessED->isEnabled())
485                 params.thickness = Length(widgetsToLength(thicknessED, thicknessUnitsLC));
486         else
487                 params.thickness = Length("0.4pt");
488         if (separationED->isEnabled())
489                 params.separation = Length(widgetsToLength(separationED, separationUnitsLC));
490         else
491                 params.separation = Length("3pt");
492         if (separationED->isEnabled())
493                 params.shadowsize = Length(widgetsToLength(shadowsizeED, shadowsizeUnitsLC));
494         else
495                 params.shadowsize = Length("4pt");
496         if (frameColorCO->isEnabled())
497                 params.framecolor = fromqstr(color[frameColorCO->currentIndex() + 1].first);
498         else
499                 params.framecolor = "black";
500         if (backgroundColorCO->isEnabled()) {
501                 // only if the framecolor is black the backgroundcolor has the entry "none"
502                 if (frameColorCO->currentText() != qt_("black"))
503                         params.backgroundcolor = fromqstr(color[backgroundColorCO->currentIndex() + 1].first);
504                 else
505                         params.backgroundcolor = fromqstr(color[backgroundColorCO->currentIndex()].first);
506         } else
507                 params.backgroundcolor = "none";
508
509         return from_ascii(InsetBox::params2string(params));
510 }
511
512
513 bool GuiBox::checkWidgets(bool readonly) const
514 {
515         typeCO->setEnabled(!readonly);
516
517         if (readonly) {
518                 pagebreakCB->setEnabled(false);
519                 innerBoxCO->setEnabled(false);
520                 valignCO->setEnabled(false);
521                 ialignCO->setEnabled(false);
522                 halignCO->setEnabled(false);
523                 widthCB->setEnabled(false);
524                 widthED->setEnabled(false);
525                 widthUnitsLC->setEnabled(false);
526                 heightED->setEnabled(false);
527                 heightUnitsLC->setEnabled(false);
528                 heightCB->setEnabled(false);
529                 thicknessED->setEnabled(false);
530                 thicknessUnitsLC->setEnabled(false);
531                 separationED->setEnabled(false);
532                 separationUnitsLC->setEnabled(false);
533                 shadowsizeED->setEnabled(false);
534                 shadowsizeUnitsLC->setEnabled(false);
535         } else {
536                 QString const outer =
537                         typeCO->itemData(typeCO->currentIndex()).toString();
538                 QString const itype =
539                         innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
540                 bool const ibox = (itype != "none" && itype != "makebox");
541                 valignCO->setEnabled(ibox);
542                 ialignCO->setEnabled(ibox);
543                 if (heightCB->isChecked() && !ibox)
544                         heightCB->setChecked(false);
545                 heightCB->setEnabled(ibox);
546                 // the width can only be selected for makebox or framebox
547                 widthCB->setEnabled(itype == "makebox"
548                         || (outer == "Boxed" && itype == "none" && !pagebreakCB->isChecked()));
549                 // except for Frameless and Boxed, the width cannot be specified if
550                 // there is no inner box
551                 bool const width_enabled =
552                         ibox || outer == "Frameless" || (outer == "Boxed" && !pagebreakCB->isChecked());
553                 // enable if width_enabled
554                 widthED->setEnabled(width_enabled);
555                 widthUnitsLC->setEnabled(width_enabled);
556                 if (!widthCB->isChecked() && widthCB->isEnabled()) {
557                         widthED->setEnabled(false);
558                         widthUnitsLC->setEnabled(false);
559                 }
560                 // halign is only allowed if a width is used
561                 halignCO->setEnabled(widthCB->isChecked());
562                 // add the entry "Stretch" if the box is \makebox or \framebox and if not already there
563                 if ((itype == "makebox" || (outer == "Boxed" && itype == "none"))
564                         && halignCO->count() < 4)
565                         halignCO->addItem(toqstr("Stretch"));
566                 else if (itype != "makebox" && (outer != "Boxed" && itype != "none"))
567                         halignCO->removeItem(3);
568                 // pagebreak is only allowed for Boxed without inner box
569                 pagebreakCB->setEnabled(!ibox && outer == "Boxed");
570
571                 heightED->setEnabled(itype != "none" && heightCB->isChecked());
572                 heightUnitsLC->setEnabled(itype != "none" && heightCB->isChecked());
573                 heightCB->setEnabled(ibox);
574
575                 // enable line thickness for the rectangular frame types and drop shadow
576                 thicknessED->setEnabled(outer == "Boxed" || outer == "Doublebox" || outer == "Shadowbox");
577                 thicknessUnitsLC->setEnabled(outer == "Boxed" || outer == "Doublebox" || outer == "Shadowbox");
578                 // set default values if empty
579                 if (thicknessED->text().isEmpty() && thicknessED->isEnabled()) {
580                         thicknessED->setText("0.4");
581                         thicknessUnitsLC->setCurrentItem(Length::PT);
582                 }
583                 // enable line separation for the allowed frame types
584                 separationED->setEnabled(outer == "Boxed" || outer == "ovalbox" || outer == "Ovalbox"
585                         || outer == "Doublebox" || outer == "Shadowbox");
586                 separationUnitsLC->setEnabled(outer == "Boxed" || outer == "ovalbox" || outer == "Ovalbox"
587                         || outer == "Doublebox" || outer == "Shadowbox");
588                 // set default values if empty
589                 if (separationED->text().isEmpty() && separationED->isEnabled()) {
590                         separationED->setText("3");
591                         separationUnitsLC->setCurrentItem(Length::PT);
592                 }
593                 // enable shadow size for drop shadow
594                 shadowsizeED->setEnabled(outer == "Shadowbox");
595                 shadowsizeUnitsLC->setEnabled(outer == "Shadowbox");
596                 // set default values if empty
597                 if (shadowsizeED->text().isEmpty() && shadowsizeED->isEnabled()) {
598                         shadowsizeED->setText("4");
599                         shadowsizeUnitsLC->setCurrentItem(Length::PT);
600                 }
601                 // \fboxcolor and \colorbox cannot be used for fancybox boxes
602                 frameColorCO->setEnabled(!pagebreakCB->isChecked() && outer == "Boxed");
603                 backgroundColorCO->setEnabled(!pagebreakCB->isChecked() && (frameColorCO->isEnabled() || outer == "Frameless"));
604         }
605
606         return InsetParamsWidget::checkWidgets();
607 }
608
609
610 void GuiBox::setSpecial(bool ibox)
611 {
612         QString const last_item =
613                 widthUnitsLC->itemData(heightUnitsLC->currentIndex()).toString();
614
615         // check if the widget contains the special units
616         bool const has_special = (widthUnitsLC->findData("totalheight") != -1);
617         // insert 'em if needed...
618         if (!ibox && !has_special) {
619                 for (int i = 1; i < ids_spec_.size(); ++i)
620                         widthUnitsLC->addItem(gui_names_spec_[i], ids_spec_[i]);
621         // ... or remove 'em if needed
622         } else if (ibox && has_special) {
623                 for (int i = 1; i < ids_spec_.size(); ++i) {
624                         int n = widthUnitsLC->findData(ids_spec_[i]);
625                         if (n != -1)
626                                 widthUnitsLC->removeItem(n);
627                 }
628         }
629         // restore selected text, if possible
630         widthUnitsLC->setCurrentItem(last_item);
631 }
632
633
634 void GuiBox::setInnerType(bool frameless, QString const & type)
635 {
636         // with "frameless" boxes, inner box is mandatory
637         // (i.e. is the actual box)
638         // we have to remove "none" then and adjust the combo
639         innerBoxCO->clear();
640         if (!frameless)
641                 innerBoxCO->addItem(qt_("None"), toqstr("none"));
642         else
643                 innerBoxCO->addItem(qt_("Makebox"), toqstr("makebox"));
644         innerBoxCO->addItem(qt_("Parbox"), toqstr("parbox"));
645         innerBoxCO->addItem(qt_("Minipage"), toqstr("minipage"));
646         int i = (innerBoxCO->findData(type) != -1)
647                 ? innerBoxCO->findData(type) : 0;
648         innerBoxCO->setCurrentIndex(i);
649 }
650
651 } // namespace frontend
652 } // namespace lyx
653
654
655 #include "moc_GuiBox.cpp"