]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiBox.cpp
GuiBox: remove none from the static color list
[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 GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
107 {
108         setupUi(this);
109
110         // fill the box type choice
111         ids_ = boxGuiIds();
112         gui_names_ = boxGuiNames();
113         for (int i = 0; i != ids_.size(); ++i)
114                 typeCO->addItem(gui_names_[i], ids_[i]);
115
116         // add the special units to the height choice
117         // width needs different handling
118         ids_spec_ = boxGuiSpecialLengthIds();
119         gui_names_spec_ = boxGuiSpecialLengthNames();
120         for (int i = 0; i != ids_spec_.size(); ++i)
121                 heightUnitsLC->addItem(gui_names_spec_[i], ids_spec_[i]);
122
123         connect(widthED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
124         connect(widthUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
125                 this, SIGNAL(changed()));
126         connect(valignCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed()));
127         connect(heightED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
128         connect(heightUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
129                 this, SIGNAL(changed()));
130         connect(halignCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
131         connect(ialignCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
132         connect(thicknessED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
133         connect(thicknessUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
134                 this, SIGNAL(changed()));
135         connect(separationED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
136         connect(separationUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
137                 this, SIGNAL(changed()));
138         connect(shadowsizeED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
139         connect(shadowsizeUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
140                 this, SIGNAL(changed()));
141         connect(frameColorCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed()));
142         connect(backgroundColorCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed()));
143
144         heightED->setValidator(unsignedLengthValidator(heightED));
145         widthED->setValidator(unsignedLengthValidator(widthED));
146         thicknessED->setValidator(unsignedLengthValidator(thicknessED));
147         separationED->setValidator(unsignedLengthValidator(separationED));
148         shadowsizeED->setValidator(unsignedLengthValidator(shadowsizeED));
149
150         // initialize the length validator
151         addCheckedWidget(widthED, widthCB);
152         addCheckedWidget(heightED, heightCB);
153         addCheckedWidget(thicknessED, thicknessLA);
154         addCheckedWidget(separationED, separationLA);
155         addCheckedWidget(shadowsizeED, shadowsizeLA);
156
157         // the background can be uncolored while the frame cannot
158         color_codes_ = colors();
159         fillComboColor(backgroundColorCO, true);
160         fillComboColor(frameColorCO, false);
161
162         initDialog();
163 }
164
165
166 void GuiBox::fillComboColor(QComboBox * combo, bool const is_none)
167 {
168         combo->clear();
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();
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 = innerBoxCO->itemData(index).toString();
189         // handle parbox and minipage the same way
190         bool const ibox = (itype != "none" && itype != "makebox");
191         if (heightCB->isChecked() && !ibox)
192                 heightCB->setChecked(false);
193         widthCB->setChecked(!widthED->text().isEmpty());
194         setSpecial(ibox);
195         changed();
196 }
197
198
199 void GuiBox::on_typeCO_activated(int index)
200 {
201         QString const type =
202                 typeCO->itemData(index).toString();
203         bool const frameless = (type == "Frameless");
204         QString itype =
205                 innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
206         setInnerType(frameless, itype);
207         // refresh itype because it might have been changed in setInnerType
208         itype =
209                 innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
210         // handle parbox and minipage the same way
211         bool const ibox = (itype != "none" && itype != "makebox");
212         if (frameless && itype != "makebox") {
213                 if (heightCB->isChecked() && !ibox)
214                         heightCB->setChecked(false);
215                 setSpecial(ibox);
216         }
217         if (type != "Boxed") {
218                 if (type != "Frameless")
219                         widthCB->setChecked(itype != "none");
220                 pagebreakCB->setChecked(false);
221         }
222         // assure that the frame color is black for frameless boxes to
223         // provide the color "none"
224         int const b = frameColorCO->findData("black");
225         if (frameless && frameColorCO->currentIndex() != b)
226                 frameColorCO->setCurrentIndex(b);
227         changed();
228 }
229
230
231 void GuiBox::on_frameColorCO_currentIndexChanged(int index)
232 {
233         // if there is a non-black frame color the background cannot be uncolored
234         // therefore remove the entry "none" in this case
235         if (index != frameColorCO->findData("black")) {
236                 int const n = backgroundColorCO->findData("none");
237                 if (n != -1) {
238                         if (backgroundColorCO->currentIndex() == n)
239                                 backgroundColorCO->setCurrentIndex(
240                                             backgroundColorCO->findData("white"));
241                         backgroundColorCO->removeItem(n);
242                 }
243         } else {
244                 if (backgroundColorCO->count() == color_codes_.count() - 1)
245                         backgroundColorCO->insertItem(0, toqstr(translateIfPossible((lcolor.getGUIName(Color_none)))),
246                                                       toqstr(lcolor.getLaTeXName(Color_none)));
247         }
248         changed();
249 }
250
251
252 void GuiBox::initDialog()
253 {
254         setInnerType(true, toqstr("minipage"));
255         widthED->setText("100");
256         widthCB->setChecked(true);
257         widthCB->setEnabled(false);
258         widthUnitsLC->setCurrentItem(Length::PCW);
259         heightED->setText("1");
260         heightUnitsLC->setCurrentItem("totalheight");
261         // LaTeX's default for \fboxrule is 0.4 pt
262         thicknessED->setText("0.4");
263         thicknessUnitsLC->setCurrentItem(Length::PT);
264         // LaTeX's default for \fboxsep is 3 pt
265         separationED->setText("3");
266         separationUnitsLC->setCurrentItem(Length::PT);
267         // LaTeX's default for \shadowsize is 4 pt
268         shadowsizeED->setText("4");
269         shadowsizeUnitsLC->setCurrentItem(Length::PT);
270 }
271
272
273 void GuiBox::on_widthCB_stateChanged(int)
274 {
275         changed();
276 }
277
278
279 void GuiBox::on_heightCB_stateChanged(int /*state*/)
280 {
281         changed();
282 }
283
284
285 void GuiBox::on_pagebreakCB_stateChanged()
286 {
287         bool pbreak = (pagebreakCB->checkState() == Qt::Checked);
288         if (pbreak)
289                 widthCB->setChecked(!pbreak);
290         if (!pbreak) {
291                 on_typeCO_activated(typeCO->currentIndex());
292                 return;
293         }
294         setSpecial(false);
295         changed();
296 }
297
298
299 void GuiBox::paramsToDialog(Inset const * inset)
300 {
301         InsetBox const * box = static_cast<InsetBox const *>(inset);
302         InsetBoxParams const & params = box->params();
303         QString type = toqstr(params.type);
304         if (type == "Framed") {
305                 pagebreakCB->setChecked(true);
306                 type = "Boxed";
307         } else {
308                 pagebreakCB->setChecked(false);
309         }
310
311         typeCO->setCurrentIndex(typeCO->findData(type));
312
313         // default: minipage
314         QString inner_type = "minipage";
315         if (!params.inner_box)
316                 inner_type = "none";
317         if (params.use_parbox)
318                 inner_type = "parbox";
319         if (params.use_makebox)
320                 inner_type = "makebox";
321         bool const frameless = (params.type == "Frameless");
322         setInnerType(frameless, inner_type);
323
324         char c = params.pos;
325         valignCO->setCurrentIndex(string("tcb").find(c, 0));
326         c = params.inner_pos;
327         ialignCO->setCurrentIndex(string("tcbs").find(c, 0));
328         c = params.hor_pos;
329         halignCO->setCurrentIndex(string("lcrs").find(c, 0));
330
331         bool ibox = (params.inner_box && !params.use_makebox);
332         valignCO->setEnabled(ibox);
333         ialignCO->setEnabled(ibox);
334         setSpecial(ibox);
335
336         // halign is only allowed if a width is used
337         halignCO->setEnabled(widthCB->isChecked());
338         // add the entry "Stretch" if the box is \makebox or \framebox and if not already there
339         if ((inner_type == "makebox" || (type == "Boxed" && inner_type == "none"))
340                 && halignCO->count() < 4)
341                 halignCO->addItem(toqstr("Stretch"));
342         else if (inner_type != "makebox" && (type != "Boxed" && inner_type != "none"))
343                 halignCO->removeItem(3); 
344         // pagebreak is only allowed for Boxed without inner box
345         pagebreakCB->setEnabled(!ibox && type == "Boxed");
346
347         Length::UNIT const default_unit = Length::defaultUnit();
348
349         // the width can only be selected for makebox or framebox
350         widthCB->setEnabled(inner_type == "makebox"
351                             || (type == "Boxed"
352                                 && !ibox && !pagebreakCB->isChecked()));
353         if (params.width.empty()) {
354                 widthCB->setChecked(false);
355                 lengthToWidgets(widthED, widthUnitsLC,
356                         params.width, default_unit);
357         } else {
358                 widthCB->setChecked(true);
359                 lengthToWidgets(widthED, widthUnitsLC,
360                         params.width, default_unit);
361                 QString const special = toqstr(params.special);
362                 if (!special.isEmpty() && special != "none")
363                         widthUnitsLC->setCurrentItem(special);
364         }
365
366         widthED->setEnabled(widthCB->isChecked());
367         widthUnitsLC->setEnabled(widthCB->isChecked());
368
369         lengthToWidgets(heightED, heightUnitsLC,
370                 (params.height).asString(), default_unit);
371
372         QString const height_special = toqstr(params.height_special);
373         if (!height_special.isEmpty() && height_special != "none")
374                 heightUnitsLC->setCurrentItem(height_special);
375         // set no optional height if the value is the default "1\height"
376         // (special units like \height are handled as "in",
377         // FIXME: this is a very bad UI, this check box should be disabled in
378         // this case, not forced to 'unchecked' state.
379         if (height_special == "totalheight" && params.height == Length("1in"))
380                 heightCB->setCheckState(Qt::Unchecked);
381         else
382                 heightCB->setCheckState(Qt::Checked);
383
384         heightCB->setEnabled(ibox);
385
386         // enable line thickness only for the rectangular frame types and drop shadow
387         thicknessED->setEnabled(type == "Boxed" || type == "Doublebox" || type == "Shadowbox");
388         thicknessUnitsLC->setEnabled(type == "Boxed" || type == "Doublebox" || type == "Shadowbox");
389         lengthToWidgets(thicknessED, thicknessUnitsLC,
390                 (params.thickness).asString(), default_unit);
391         // enable line separation for the allowed frame types
392         separationED->setEnabled(type == "Boxed" || type == "ovalbox" || type == "Ovalbox"
393                 || type == "Doublebox" || type == "Shadowbox");
394         separationUnitsLC->setEnabled(type == "Boxed" || type == "ovalbox" || type == "Ovalbox"
395                 || type == "Doublebox" || type == "Shadowbox");
396         lengthToWidgets(separationED, separationUnitsLC,
397                 (params.separation).asString(), default_unit);
398         // enable shadow size for drop shadow
399         shadowsizeED->setEnabled(type == "Shadowbox");
400         shadowsizeUnitsLC->setEnabled(type == "Shadowbox");
401         lengthToWidgets(shadowsizeED, shadowsizeUnitsLC,
402                 (params.shadowsize).asString(), default_unit);
403         // set color
404         frameColorCO->setCurrentIndex(frameColorCO->findData(toqstr(params.framecolor)));
405         backgroundColorCO->setCurrentIndex(backgroundColorCO->findData(toqstr(params.backgroundcolor)));
406 }
407
408
409 docstring GuiBox::dialogToParams() const
410 {
411         bool const pagebreak =
412                 pagebreakCB->isEnabled() && pagebreakCB->isChecked();
413         string box_type;
414         if (pagebreak)
415                 box_type = "Framed";
416         else
417                 box_type = fromqstr(typeCO->itemData(
418                                 typeCO->currentIndex()).toString());
419
420         InsetBoxParams params(box_type);
421         params.inner_box =
422                 (!pagebreak && innerBoxCO->currentText() != qt_("None"));
423         params.use_parbox =
424                 (!pagebreak && innerBoxCO->currentText() == qt_("Parbox"));
425         params.use_makebox =
426                 (!pagebreak && innerBoxCO->currentText() == qt_("Makebox"));
427
428         params.pos = "tcb"[valignCO->currentIndex()];
429         params.inner_pos = "tcbs"[ialignCO->currentIndex()];
430         params.hor_pos = "lcrs"[halignCO->currentIndex()];
431
432         QString unit =
433                 widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString();
434         QString value = widthED->text();
435
436         if (widthED->isEnabled()) {
437                 if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
438                         params.special = fromqstr(unit);
439                         // Note: the unit is simply ignored in this case
440                         params.width = Length(value.toDouble(), Length::IN);
441                 } else {
442                         params.special = "none";
443                         // we must specify a valid length in this case
444                         if (value.isEmpty())
445                                 widthED->setText("0");
446                         params.width = Length(widgetsToLength(widthED, widthUnitsLC));
447                 }
448         } else {
449                 params.special = "none";
450                 params.width = Length();
451         }
452
453         // the height parameter is omitted if the value
454         // is "1in" and "Total Height" is used as unit.
455         // 1in + "Total Height" means "1\height" which is the LaTeX default
456         // if no height is given
457         if (heightCB->checkState() == Qt::Unchecked) {
458                 params.height = Length("1in");
459                 params.height_special = "totalheight";
460         } else {
461                 unit = heightUnitsLC->itemData(heightUnitsLC->currentIndex()).toString();
462                 value = heightED->text();
463                 if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
464                         params.height_special = fromqstr(unit);
465                         // Note: the unit is simply ignored in this case
466                         params.height = Length(value.toDouble(), Length::IN);
467                 } else {
468                         params.height_special = "none";
469                         params.height =
470                                 Length(widgetsToLength(heightED, heightUnitsLC));
471                 }
472         }
473
474         // handle the line thickness, line separation and shadow size
475         if (thicknessED->isEnabled())
476                 params.thickness = Length(widgetsToLength(thicknessED, thicknessUnitsLC));
477         else
478                 params.thickness = Length("0.4pt");
479         if (separationED->isEnabled())
480                 params.separation = Length(widgetsToLength(separationED, separationUnitsLC));
481         else
482                 params.separation = Length("3pt");
483         if (separationED->isEnabled())
484                 params.shadowsize = Length(widgetsToLength(shadowsizeED, shadowsizeUnitsLC));
485         else
486                 params.shadowsize = Length("4pt");
487         if (frameColorCO->isEnabled())
488                 params.framecolor =
489                         fromqstr(frameColorCO->itemData(frameColorCO->currentIndex()).toString());
490         else
491                 params.framecolor = "black";
492         if (backgroundColorCO->isEnabled())
493                 params.backgroundcolor =
494                         fromqstr(backgroundColorCO->itemData(backgroundColorCO->currentIndex()).toString());
495         else
496                 params.backgroundcolor = "none";
497
498         return from_ascii(InsetBox::params2string(params));
499 }
500
501
502 bool GuiBox::checkWidgets(bool readonly) const
503 {
504         typeCO->setEnabled(!readonly);
505
506         if (readonly) {
507                 pagebreakCB->setEnabled(false);
508                 innerBoxCO->setEnabled(false);
509                 valignCO->setEnabled(false);
510                 ialignCO->setEnabled(false);
511                 halignCO->setEnabled(false);
512                 widthCB->setEnabled(false);
513                 widthED->setEnabled(false);
514                 widthUnitsLC->setEnabled(false);
515                 heightED->setEnabled(false);
516                 heightUnitsLC->setEnabled(false);
517                 heightCB->setEnabled(false);
518                 thicknessED->setEnabled(false);
519                 thicknessUnitsLC->setEnabled(false);
520                 separationED->setEnabled(false);
521                 separationUnitsLC->setEnabled(false);
522                 shadowsizeED->setEnabled(false);
523                 shadowsizeUnitsLC->setEnabled(false);
524         } else {
525                 QString const outer =
526                         typeCO->itemData(typeCO->currentIndex()).toString();
527                 QString const itype =
528                         innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
529                 bool const ibox = (itype != "none" && itype != "makebox");
530                 valignCO->setEnabled(ibox);
531                 ialignCO->setEnabled(ibox);
532                 if (heightCB->isChecked() && !ibox)
533                         heightCB->setChecked(false);
534                 heightCB->setEnabled(ibox);
535                 // the width can only be selected for makebox or framebox
536                 widthCB->setEnabled(itype == "makebox"
537                         || (outer == "Boxed" && itype == "none" && !pagebreakCB->isChecked()));
538                 // except for Frameless and Boxed, the width cannot be specified if
539                 // there is no inner box
540                 bool const width_enabled =
541                         ibox || outer == "Frameless" || (outer == "Boxed" && !pagebreakCB->isChecked());
542                 // enable if width_enabled
543                 widthED->setEnabled(width_enabled);
544                 widthUnitsLC->setEnabled(width_enabled);
545                 if (!widthCB->isChecked() && widthCB->isEnabled()) {
546                         widthED->setEnabled(false);
547                         widthUnitsLC->setEnabled(false);
548                 }
549                 // halign is only allowed if a width is used
550                 halignCO->setEnabled(widthCB->isChecked());
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(toqstr("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"