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