]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiBox.cpp
GuiBox.cpp: fix bug introduced by [bec3f7bc/lyxgit]
[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->count() == color_codes_.count() - 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         frameColorCO->setCurrentIndex(frameColorCO->findData(toqstr(params.framecolor)));
406         backgroundColorCO->setCurrentIndex(backgroundColorCO->findData(toqstr(params.backgroundcolor)));
407 }
408
409
410 docstring GuiBox::dialogToParams() const
411 {
412         bool const pagebreak =
413                 pagebreakCB->isEnabled() && pagebreakCB->isChecked();
414         string box_type;
415         if (pagebreak)
416                 box_type = "Framed";
417         else
418                 box_type = fromqstr(typeCO->itemData(
419                                 typeCO->currentIndex()).toString());
420
421         InsetBoxParams params(box_type);
422         params.inner_box =
423                 (!pagebreak && innerBoxCO->currentText() != qt_("None"));
424         params.use_parbox =
425                 (!pagebreak && innerBoxCO->currentText() == qt_("Parbox"));
426         params.use_makebox =
427                 (!pagebreak && innerBoxCO->currentText() == qt_("Makebox"));
428
429         params.pos = "tcb"[valignCO->currentIndex()];
430         params.inner_pos = "tcbs"[ialignCO->currentIndex()];
431         params.hor_pos = "lcrs"[halignCO->currentIndex()];
432
433         QString unit =
434                 widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString();
435         QString value = widthED->text();
436
437         if (widthED->isEnabled()) {
438                 if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
439                         params.special = fromqstr(unit);
440                         // Note: the unit is simply ignored in this case
441                         params.width = Length(value.toDouble(), Length::IN);
442                 } else {
443                         params.special = "none";
444                         // we must specify a valid length in this case
445                         if (value.isEmpty())
446                                 widthED->setText("0");
447                         params.width = Length(widgetsToLength(widthED, widthUnitsLC));
448                 }
449         } else {
450                 params.special = "none";
451                 params.width = Length();
452         }
453
454         // the height parameter is omitted if the value
455         // is "1in" and "Total Height" is used as unit.
456         // 1in + "Total Height" means "1\height" which is the LaTeX default
457         // if no height is given
458         if (heightCB->checkState() == Qt::Unchecked) {
459                 params.height = Length("1in");
460                 params.height_special = "totalheight";
461         } else {
462                 unit = heightUnitsLC->itemData(heightUnitsLC->currentIndex()).toString();
463                 value = heightED->text();
464                 if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
465                         params.height_special = fromqstr(unit);
466                         // Note: the unit is simply ignored in this case
467                         params.height = Length(value.toDouble(), Length::IN);
468                 } else {
469                         params.height_special = "none";
470                         params.height =
471                                 Length(widgetsToLength(heightED, heightUnitsLC));
472                 }
473         }
474
475         // handle the line thickness, line separation and shadow size
476         if (thicknessED->isEnabled())
477                 params.thickness = Length(widgetsToLength(thicknessED, thicknessUnitsLC));
478         else
479                 params.thickness = Length("0.4pt");
480         if (separationED->isEnabled())
481                 params.separation = Length(widgetsToLength(separationED, separationUnitsLC));
482         else
483                 params.separation = Length("3pt");
484         if (separationED->isEnabled())
485                 params.shadowsize = Length(widgetsToLength(shadowsizeED, shadowsizeUnitsLC));
486         else
487                 params.shadowsize = Length("4pt");
488         if (frameColorCO->isEnabled())
489                 params.framecolor =
490                         fromqstr(frameColorCO->itemData(frameColorCO->currentIndex()).toString());
491         else
492                 params.framecolor = "black";
493         if (backgroundColorCO->isEnabled())
494                 params.backgroundcolor =
495                         fromqstr(backgroundColorCO->itemData(backgroundColorCO->currentIndex()).toString());
496         else
497                 params.backgroundcolor = "none";
498
499         return from_ascii(InsetBox::params2string(params));
500 }
501
502
503 bool GuiBox::checkWidgets(bool readonly) const
504 {
505         typeCO->setEnabled(!readonly);
506
507         if (readonly) {
508                 pagebreakCB->setEnabled(false);
509                 innerBoxCO->setEnabled(false);
510                 valignCO->setEnabled(false);
511                 ialignCO->setEnabled(false);
512                 halignCO->setEnabled(false);
513                 widthCB->setEnabled(false);
514                 widthED->setEnabled(false);
515                 widthUnitsLC->setEnabled(false);
516                 heightED->setEnabled(false);
517                 heightUnitsLC->setEnabled(false);
518                 heightCB->setEnabled(false);
519                 thicknessED->setEnabled(false);
520                 thicknessUnitsLC->setEnabled(false);
521                 separationED->setEnabled(false);
522                 separationUnitsLC->setEnabled(false);
523                 shadowsizeED->setEnabled(false);
524                 shadowsizeUnitsLC->setEnabled(false);
525         } else {
526                 QString const outer =
527                         typeCO->itemData(typeCO->currentIndex()).toString();
528                 QString const itype =
529                         innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
530                 bool const ibox = (itype != "none" && itype != "makebox");
531                 valignCO->setEnabled(ibox);
532                 ialignCO->setEnabled(ibox);
533                 if (heightCB->isChecked() && !ibox)
534                         heightCB->setChecked(false);
535                 heightCB->setEnabled(ibox);
536                 // the width can only be selected for makebox or framebox
537                 widthCB->setEnabled(itype == "makebox"
538                         || (outer == "Boxed" && itype == "none" && !pagebreakCB->isChecked()));
539                 // except for Frameless and Boxed, the width cannot be specified if
540                 // there is no inner box
541                 bool const width_enabled =
542                         ibox || outer == "Frameless" || (outer == "Boxed" && !pagebreakCB->isChecked());
543                 // enable if width_enabled
544                 widthED->setEnabled(width_enabled);
545                 widthUnitsLC->setEnabled(width_enabled);
546                 if (!widthCB->isChecked() && widthCB->isEnabled()) {
547                         widthED->setEnabled(false);
548                         widthUnitsLC->setEnabled(false);
549                 }
550                 // halign is only allowed if a width is used
551                 halignCO->setEnabled(widthCB->isChecked());
552                 // add the entry "Stretch" if the box is \makebox or \framebox and if not already there
553                 if ((itype == "makebox" || (outer == "Boxed" && itype == "none"))
554                         && halignCO->count() < 4)
555                         halignCO->addItem(toqstr("Stretch"));
556                 else if (itype != "makebox" && (outer != "Boxed" && itype != "none"))
557                         halignCO->removeItem(3);
558                 // pagebreak is only allowed for Boxed without inner box
559                 pagebreakCB->setEnabled(!ibox && outer == "Boxed");
560
561                 heightED->setEnabled(itype != "none" && heightCB->isChecked());
562                 heightUnitsLC->setEnabled(itype != "none" && heightCB->isChecked());
563                 heightCB->setEnabled(ibox);
564
565                 // enable line thickness for the rectangular frame types and drop shadow
566                 thicknessED->setEnabled(outer == "Boxed" || outer == "Doublebox" || outer == "Shadowbox");
567                 thicknessUnitsLC->setEnabled(outer == "Boxed" || outer == "Doublebox" || outer == "Shadowbox");
568                 // set default values if empty
569                 if (thicknessED->text().isEmpty() && thicknessED->isEnabled()) {
570                         thicknessED->setText("0.4");
571                         thicknessUnitsLC->setCurrentItem(Length::PT);
572                 }
573                 // enable line separation for the allowed frame types
574                 separationED->setEnabled(outer == "Boxed" || outer == "ovalbox" || outer == "Ovalbox"
575                         || outer == "Doublebox" || outer == "Shadowbox");
576                 separationUnitsLC->setEnabled(outer == "Boxed" || outer == "ovalbox" || outer == "Ovalbox"
577                         || outer == "Doublebox" || outer == "Shadowbox");
578                 // set default values if empty
579                 if (separationED->text().isEmpty() && separationED->isEnabled()) {
580                         separationED->setText("3");
581                         separationUnitsLC->setCurrentItem(Length::PT);
582                 }
583                 // enable shadow size for drop shadow
584                 shadowsizeED->setEnabled(outer == "Shadowbox");
585                 shadowsizeUnitsLC->setEnabled(outer == "Shadowbox");
586                 // set default values if empty
587                 if (shadowsizeED->text().isEmpty() && shadowsizeED->isEnabled()) {
588                         shadowsizeED->setText("4");
589                         shadowsizeUnitsLC->setCurrentItem(Length::PT);
590                 }
591                 // \fboxcolor and \colorbox cannot be used for fancybox boxes
592                 frameColorCO->setEnabled(!pagebreakCB->isChecked() && outer == "Boxed");
593                 backgroundColorCO->setEnabled(!pagebreakCB->isChecked() && (frameColorCO->isEnabled() || outer == "Frameless"));
594         }
595
596         return InsetParamsWidget::checkWidgets();
597 }
598
599
600 void GuiBox::setSpecial(bool ibox)
601 {
602         QString const last_item =
603                 widthUnitsLC->itemData(heightUnitsLC->currentIndex()).toString();
604
605         // check if the widget contains the special units
606         bool const has_special = (widthUnitsLC->findData("totalheight") != -1);
607         // insert 'em if needed...
608         if (!ibox && !has_special) {
609                 for (int i = 1; i < ids_spec_.size(); ++i)
610                         widthUnitsLC->addItem(gui_names_spec_[i], ids_spec_[i]);
611         // ... or remove 'em if needed
612         } else if (ibox && has_special) {
613                 for (int i = 1; i < ids_spec_.size(); ++i) {
614                         int n = widthUnitsLC->findData(ids_spec_[i]);
615                         if (n != -1)
616                                 widthUnitsLC->removeItem(n);
617                 }
618         }
619         // restore selected text, if possible
620         widthUnitsLC->setCurrentItem(last_item);
621 }
622
623
624 void GuiBox::setInnerType(bool frameless, QString const & type)
625 {
626         // with "frameless" boxes, inner box is mandatory
627         // (i.e. is the actual box)
628         // we have to remove "none" then and adjust the combo
629         innerBoxCO->clear();
630         if (!frameless)
631                 innerBoxCO->addItem(qt_("None"), toqstr("none"));
632         else
633                 innerBoxCO->addItem(qt_("Makebox"), toqstr("makebox"));
634         innerBoxCO->addItem(qt_("Parbox"), toqstr("parbox"));
635         innerBoxCO->addItem(qt_("Minipage"), toqstr("minipage"));
636         int i = (innerBoxCO->findData(type) != -1)
637                 ? innerBoxCO->findData(type) : 0;
638         innerBoxCO->setCurrentIndex(i);
639 }
640
641 } // namespace frontend
642 } // namespace lyx
643
644
645 #include "moc_GuiBox.cpp"