]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiBox.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / GuiBox.cpp
index f112998c08604ec722a51942b7b9a490b20547f6..d3bd8e86c06320a6b4dc7db3698f0fd05071db68 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "GuiBox.h"
 
-#include "FuncRequest.h"
 #include "LengthCombo.h"
 #include "Length.h"
 #include "qt_helpers.h"
@@ -104,14 +103,14 @@ GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
        widthED->setValidator(unsignedLengthValidator(widthED));
 
        // initialize the length validator
-       addCheckedWidget(widthED, widthLA);
+       addCheckedWidget(widthED, widthCB);
        addCheckedWidget(heightED, heightCB);
 
        initDialog();
 }
 
 
-void GuiBox::on_innerBoxCO_activated(int index)
+void GuiBox::on_innerBoxCO_activated(int /* index */)
 {
        QString itype =
                innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
@@ -126,15 +125,25 @@ void GuiBox::on_innerBoxCO_activated(int index)
        if (heightCB->isChecked() && !ibox)
                heightCB->setChecked(false);
        heightCB->setEnabled(ibox);
+       // the width can only be selected for makebox or framebox
+       widthCB->setEnabled(itype == "makebox"
+                           || (outer == "Boxed" && itype == "none"));
+       widthCB->setChecked(!widthED->text().isEmpty());
        // 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"));
+       // enable if width_enabled, except if checkbaox is active but unset
+       widthED->setEnabled(width_enabled || (widthCB->isEnabled() && widthCB->isChecked()));
+       widthUnitsLC->setEnabled(width_enabled || (widthCB->isEnabled() && widthCB->isChecked()));
+       if (!widthCB->isChecked() && widthCB->isEnabled()) {
+               widthED->setEnabled(false);
+               widthUnitsLC->setEnabled(false);
+       }
+       // halign is only allowed without inner box and if a width is used and if
+       // pagebreak is not used
+       halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
+                            && ((!ibox && outer == "Boxed") || itype == "makebox"));
        // pagebreak is only allowed for Boxed without inner box
        pagebreakCB->setEnabled(!ibox && outer == "Boxed");
        setSpecial(ibox);
@@ -165,16 +174,29 @@ void GuiBox::on_typeCO_activated(int index)
                heightCB->setEnabled(ibox);
                setSpecial(ibox);
        }
+       // the width can only be selected for makebox or framebox
+       widthCB->setEnabled(itype == "makebox"
+                           || (type == "Boxed" && itype == "none"));
+       widthCB->setChecked(itype != "none" && !widthCB->isEnabled());
        // except for frameless and boxed, the width cannot be specified if
        // there is no inner box
-       bool const width_enabled = 
+       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"));
+       // enable if width_enabled, except if checkbaox is active but unset
+       widthED->setEnabled(width_enabled || (widthCB->isEnabled() && widthCB->isChecked()));
+       widthUnitsLC->setEnabled(width_enabled || (widthCB->isEnabled() && widthCB->isChecked()));
+       if (!widthCB->isChecked() && widthCB->isEnabled()) {
+               widthED->setEnabled(false);
+               widthUnitsLC->setEnabled(false);
+       }
+       // halign is only allowed without inner box and if a width is used and if
+       // pagebreak is not used
+       halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
+                            && ((itype == "none" && type == "Boxed") || itype == "makebox"));
        // pagebreak is only allowed for Boxed without inner box
        pagebreakCB->setEnabled(type == "Boxed" && itype == "none");
+       if (type != "Boxed")
+               pagebreakCB->setChecked(false);
        changed();
 }
 
@@ -183,12 +205,25 @@ void GuiBox::initDialog()
 {
        setInnerType(true, toqstr("minipage"));
        widthED->setText("100");
+       widthCB->setChecked(true);
+       widthCB->setEnabled(false);
        widthUnitsLC->setCurrentItem(Length::PCW);
        heightED->setText("1");
        heightUnitsLC->setCurrentItem("totalheight");
 }
 
 
+void GuiBox::on_widthCB_stateChanged(int)
+{
+       if (widthCB->isEnabled()) {
+               widthED->setEnabled(widthCB->isChecked());
+               widthUnitsLC->setEnabled(widthCB->isChecked());
+               halignCO->setEnabled(widthCB->isChecked());
+       }
+       changed();
+}
+
+
 void GuiBox::on_heightCB_stateChanged(int state)
 {
        bool const enable = (innerBoxCO->currentText() != qt_("None"))
@@ -203,6 +238,9 @@ void GuiBox::on_pagebreakCB_stateChanged()
 {
        bool pbreak = (pagebreakCB->checkState() == Qt::Checked);
        innerBoxCO->setEnabled(!pbreak);
+       widthCB->setEnabled(!pbreak);
+       if (pbreak)
+               widthCB->setChecked(!pbreak);
        widthED->setEnabled(!pbreak);
        widthUnitsLC->setEnabled(!pbreak);
        if (!pbreak) {
@@ -257,29 +295,38 @@ void GuiBox::paramsToDialog(Inset const * inset)
        ialignCO->setEnabled(ibox);
        setSpecial(ibox);
 
-       // halign and pagebreak are only allowed for Boxed without inner box
-       halignCO->setEnabled((!ibox && type == "Boxed") || (params.use_makebox));
+       // halign is only allowed without inner box and if a width is used and if
+       // pagebreak is not used
+       halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
+                            && ((!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,
-               (params.width).asString(), default_unit);
+       // the width can only be selected for makebox or framebox
+       widthCB->setEnabled(inner_type == "makebox"
+                           || (type == "Boxed"
+                               && !ibox && !pagebreakCB->isChecked()));
+       if (params.width.empty()) {
+               widthCB->setChecked(false);
+               lengthToWidgets(widthED, widthUnitsLC,
+                       params.width, default_unit);
+       } else {
+               widthCB->setChecked(true);
+               lengthToWidgets(widthED, widthUnitsLC,
+                       params.width, default_unit);
+               QString const special = toqstr(params.special);
+               if (!special.isEmpty() && special != "none")
+                       widthUnitsLC->setCurrentItem(special);
+       }
 
-       QString const special = toqstr(params.special);
-       if (!special.isEmpty() && special != "none")
-               widthUnitsLC->setCurrentItem(special);
+       widthED->setEnabled(widthCB->isChecked());
+       widthUnitsLC->setEnabled(widthCB->isChecked());
 
        lengthToWidgets(heightED, heightUnitsLC,
                (params.height).asString(), default_unit);
-       
+
        QString const height_special = toqstr(params.height_special);
        if (!height_special.isEmpty() && height_special != "none")
                heightUnitsLC->setCurrentItem(height_special);
@@ -322,13 +369,22 @@ docstring GuiBox::dialogToParams() const
        QString unit =
                widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString();
        QString value = widthED->text();
-       if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
-               params.special = fromqstr(unit);
-               // Note: the unit is simply ignored in this case
-               params.width = Length(value.toDouble(), Length::IN);
+
+       if (widthED->isEnabled()) {
+               if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
+                       params.special = fromqstr(unit);
+                       // Note: the unit is simply ignored in this case
+                       params.width = Length(value.toDouble(), Length::IN);
+               } else {
+                       params.special = "none";
+                       // we must specify a valid length in this case
+                       if (value.isEmpty())
+                               widthED->setText("0");
+                       params.width = Length(widgetsToLength(widthED, widthUnitsLC));
+               }
        } else {
                params.special = "none";
-               params.width = Length(widgetsToLength(widthED, widthUnitsLC));
+               params.width = Length();
        }
 
        // the height parameter is omitted if the value