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