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