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