#include "GuiBox.h"
-#include "FuncRequest.h"
#include "LengthCombo.h"
#include "Length.h"
#include "qt_helpers.h"
// fill the box type choice
ids_ = boxGuiIds();
gui_names_ = boxGuiNames();
- foreach (QString const & str, gui_names_)
- typeCO->addItem(str);
+ for (int i = 0; i != ids_.size(); ++i)
+ typeCO->addItem(gui_names_[i], ids_[i]);
// add the special units to the height choice
// width needs different handling
}
-void GuiBox::on_innerBoxCO_activated(QString const & str)
+void GuiBox::on_innerBoxCO_activated(int /* index */)
{
- bool const ibox = (str != qt_("None"));
+ QString itype =
+ innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
+ // handle parbox and minipage the same way
+ bool const ibox =
+ (itype != "none"
+ && itype != "makebox");
+ QString const outer =
+ typeCO->itemData(typeCO->currentIndex()).toString();
valignCO->setEnabled(ibox);
ialignCO->setEnabled(ibox);
- halignCO->setEnabled(!ibox);
+ if (heightCB->isChecked() && !ibox)
+ heightCB->setChecked(false);
heightCB->setEnabled(ibox);
- pagebreakCB->setEnabled(!ibox && typeCO->currentIndex() == 1);
+ // except for frameless and boxed, the width cannot be specified if
+ // there is no inner box
+ bool const width_enabled =
+ ibox || outer == "Frameless" || outer == "Boxed";
+ widthED->setEnabled(width_enabled);
+ widthUnitsLC->setEnabled(width_enabled);
+ // halign is only allowed for Boxed without inner box or for makebox
+ halignCO->setEnabled((!ibox && outer == "Boxed")
+ || (itype == "makebox"));
+ // pagebreak is only allowed for Boxed without inner box
+ pagebreakCB->setEnabled(!ibox && outer == "Boxed");
setSpecial(ibox);
changed();
}
void GuiBox::on_typeCO_activated(int index)
{
- bool const frameless = (index == 0);
- if (frameless) {
- valignCO->setEnabled(true);
- ialignCO->setEnabled(true);
- halignCO->setEnabled(false);
- heightCB->setEnabled(true);
- setSpecial(true);
- }
- if (index != 1)
- pagebreakCB->setChecked(false);
- int itype = innerBoxCO->currentIndex();
- if (innerBoxCO->count() == 2)
- ++itype;
- pagebreakCB->setEnabled(index == 1 && itype == 0);
- widthED->setEnabled(index != 5);
- widthUnitsLC->setEnabled(index != 5);
+ QString const type =
+ typeCO->itemData(index).toString();
+ bool const frameless = (type == "Frameless");
+ QString itype =
+ innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
setInnerType(frameless, itype);
+ // refresh itype because it might have been changed in setInnerType
+ itype =
+ innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
+ // handle parbox and minipage the same way
+ bool const ibox =
+ (itype != "none"
+ && itype != "makebox");
+ if (frameless && itype != "makebox") {
+ valignCO->setEnabled(ibox);
+ ialignCO->setEnabled(ibox);
+ if (heightCB->isChecked() && !ibox)
+ heightCB->setChecked(false);
+ heightCB->setEnabled(ibox);
+ setSpecial(ibox);
+ }
+ // except for frameless and boxed, the width cannot be specified if
+ // there is no inner box
+ bool const width_enabled =
+ itype != "none" || frameless || type == "Boxed";
+ widthED->setEnabled(width_enabled);
+ widthUnitsLC->setEnabled(width_enabled);
+ // halign is only allowed for Boxed without inner box or for makebox
+ halignCO->setEnabled((type == "Boxed" && itype == "none") || (itype == "makebox"));
+ // pagebreak is only allowed for Boxed without inner box
+ pagebreakCB->setEnabled(type == "Boxed" && itype == "none");
changed();
}
void GuiBox::initDialog()
{
- setInnerType(true, 2);
+ setInnerType(true, toqstr("minipage"));
widthED->setText("100");
widthUnitsLC->setCurrentItem(Length::PCW);
- heightCB->setCheckState(Qt::Checked);
heightED->setText("1");
heightUnitsLC->setCurrentItem("totalheight");
}
pagebreakCB->setChecked(false);
}
- pagebreakCB->setEnabled(type == "Boxed" && !params.inner_box);
-
- for (int i = 0; i != gui_names_.size(); ++i) {
- if (type == ids_[i])
- typeCO->setCurrentIndex(i);
- }
+ typeCO->setCurrentIndex(typeCO->findData(type));
// default: minipage
- int inner_type = 2;
+ QString inner_type = "minipage";
if (!params.inner_box)
- // none
- inner_type = 0;
+ inner_type = "none";
if (params.use_parbox)
- // parbox
- inner_type = 1;
- bool frameless = (params.type == "Frameless");
+ inner_type = "parbox";
+ if (params.use_makebox)
+ inner_type = "makebox";
+ bool const frameless = (params.type == "Frameless");
setInnerType(frameless, inner_type);
char c = params.pos;
c = params.hor_pos;
halignCO->setCurrentIndex(string("lcrs").find(c, 0));
- bool ibox = params.inner_box;
+ bool ibox = (params.inner_box && !params.use_makebox);
valignCO->setEnabled(ibox);
ialignCO->setEnabled(ibox);
- halignCO->setEnabled(!ibox);
setSpecial(ibox);
+ // halign and pagebreak are only allowed for Boxed without inner box
+ halignCO->setEnabled((!ibox && type == "Boxed") || (params.use_makebox));
+ // pagebreak is only allowed for Boxed without inner box
+ pagebreakCB->setEnabled(!ibox && type == "Boxed");
+
+ // except for frameless and boxed, the width cannot be specified if
+ // there is no inner box
+ bool const width_enabled = (ibox || frameless || type == "Boxed");
+ widthED->setEnabled(width_enabled);
+ widthUnitsLC->setEnabled(width_enabled);
+
Length::UNIT const default_unit = Length::defaultUnit();
lengthToWidgets(widthED, widthUnitsLC,
if (pagebreak)
box_type = "Framed";
else
- box_type = fromqstr(ids_[typeCO->currentIndex()]);
+ box_type = fromqstr(typeCO->itemData(
+ typeCO->currentIndex()).toString());
InsetBoxParams params(box_type);
params.inner_box =
(!pagebreak && innerBoxCO->currentText() != qt_("None"));
params.use_parbox =
(!pagebreak && innerBoxCO->currentText() == qt_("Parbox"));
+ params.use_makebox =
+ (!pagebreak && innerBoxCO->currentText() == qt_("Makebox"));
params.pos = "tcb"[valignCO->currentIndex()];
params.inner_pos = "tcbs"[ialignCO->currentIndex()];
}
-void GuiBox::setInnerType(bool frameless, int i)
+void GuiBox::setInnerType(bool frameless, QString const & type)
{
- // with "frameless" boxes, inner box is mandatory (i.e. is the actual box)
+ // with "frameless" boxes, inner box is mandatory
+ // (i.e. is the actual box)
// we have to remove "none" then and adjust the combo
- if (frameless) {
- innerBoxCO->clear();
- innerBoxCO->addItem(qt_("Parbox"));
- innerBoxCO->addItem(qt_("Minipage"));
- if (i != 0)
- innerBoxCO->setCurrentIndex(i - 1);
- else
- innerBoxCO->setCurrentIndex(i);
- } else {
- innerBoxCO->clear();
- innerBoxCO->addItem(qt_("None"));
- innerBoxCO->addItem(qt_("Parbox"));
- innerBoxCO->addItem(qt_("Minipage"));
- innerBoxCO->setCurrentIndex(i);
- }
+ innerBoxCO->clear();
+ if (!frameless)
+ innerBoxCO->addItem(qt_("None"), toqstr("none"));
+ else
+ innerBoxCO->addItem(qt_("Makebox"), toqstr("makebox"));
+ innerBoxCO->addItem(qt_("Parbox"), toqstr("parbox"));
+ innerBoxCO->addItem(qt_("Minipage"), toqstr("minipage"));
+ int i = (innerBoxCO->findData(type) != -1)
+ ? innerBoxCO->findData(type) : 0;
+ innerBoxCO->setCurrentIndex(i);
}
} // namespace frontend