]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiHSpace.cpp
Properly track the lifetime of signals2::slots (#8261)
[lyx.git] / src / frontends / qt4 / GuiHSpace.cpp
index e2dcfc9961fe87e7a89fccba47d5886c9b37a60b..ad829ecd814df0e7cae334838aedc110c03622c4 100644 (file)
@@ -42,29 +42,30 @@ GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
 
        spacingCO->clear();
        if (math_mode_) {
-               spacingCO->addItem(qt_("Thin Space"), toqstr("thinspace"));
-               spacingCO->addItem(qt_("Medium Space"), toqstr("medspace"));
-               spacingCO->addItem(qt_("Thick Space"), toqstr("thickspace"));
-               spacingCO->addItem(qt_("Negative Thin Space"), toqstr("negthinspace"));
-               spacingCO->addItem(qt_("Negative Medium Space"), toqstr("negmedspace"));
-               spacingCO->addItem(qt_("Negative Thick Space"), toqstr("negthickspace"));
-               spacingCO->addItem(qt_("Half Quad (0.5 em)"), toqstr("halfquad"));
-               spacingCO->addItem(qt_("Quad (1 em)"), toqstr("quad"));
-               spacingCO->addItem(qt_("Double Quad (2 em)"), toqstr("qquad"));
-               spacingCO->addItem(qt_("Horizontal Fill"), toqstr("hfill"));
-               spacingCO->addItem(qt_("Custom"), toqstr("custom"));
+               spacingCO->addItem(qt_("Interword Space"), "normal");
+               spacingCO->addItem(qt_("Thin Space"), "thinspace");
+               spacingCO->addItem(qt_("Medium Space"), "medspace");
+               spacingCO->addItem(qt_("Thick Space"), "thickspace");
+               spacingCO->addItem(qt_("Negative Thin Space"), "negthinspace");
+               spacingCO->addItem(qt_("Negative Medium Space"), "negmedspace");
+               spacingCO->addItem(qt_("Negative Thick Space"), "negthickspace");
+               spacingCO->addItem(qt_("Half Quad (0.5 em)"), "halfquad");
+               spacingCO->addItem(qt_("Quad (1 em)"), "quad");
+               spacingCO->addItem(qt_("Double Quad (2 em)"), "qquad");
+               spacingCO->addItem(qt_("Horizontal Fill"), "hfill");
+               spacingCO->addItem(qt_("Custom"), "custom");
        } else {
-               spacingCO->addItem(qt_("Interword Space"), toqstr("normal"));
-               spacingCO->addItem(qt_("Thin Space"), toqstr("thinspace"));
-               spacingCO->addItem(qt_("Negative Thin Space"), toqstr("negthinspace"));
-               spacingCO->addItem(qt_("Negative Medium Space"), toqstr("negmedspace"));
-               spacingCO->addItem(qt_("Negative Thick Space"), toqstr("negthickspace"));
-               spacingCO->addItem(qt_("Half Quad (0.5 em)"), toqstr("halfquad"));
-               spacingCO->addItem(qt_("Quad (1 em)"), toqstr("quad"));
-               spacingCO->addItem(qt_("Double Quad (2 em)"), toqstr("qquad"));
-               spacingCO->addItem(qt_("Horizontal Fill"), toqstr("hfill"));
-               spacingCO->addItem(qt_("Custom"), toqstr("custom"));
-               spacingCO->addItem(qt_("Visible Space"), toqstr("visible"));
+               spacingCO->addItem(qt_("Interword Space"), "normal");
+               spacingCO->addItem(qt_("Thin Space"), "thinspace");
+               spacingCO->addItem(qt_("Negative Thin Space"), "negthinspace");
+               spacingCO->addItem(qt_("Negative Medium Space"), "negmedspace");
+               spacingCO->addItem(qt_("Negative Thick Space"), "negthickspace");
+               spacingCO->addItem(qt_("Half Quad (0.5 em)"), "halfquad");
+               spacingCO->addItem(qt_("Quad (1 em)"), "quad");
+               spacingCO->addItem(qt_("Double Quad (2 em)"), "qquad");
+               spacingCO->addItem(qt_("Horizontal Fill"), "hfill");
+               spacingCO->addItem(qt_("Custom"), "custom");
+               spacingCO->addItem(qt_("Visible Space"), "visible");
        }
 
        connect(spacingCO, SIGNAL(highlighted(QString)),
@@ -80,13 +81,17 @@ GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
        connect(fillPatternCO, SIGNAL(activated(int)),
                this, SLOT(changedSlot()));
 
+       // Set up a signed (glue) length validator
+       LengthValidator * v = new LengthValidator(valueLE);
        if (math_mode_)
-               valueLE->setValidator(unsignedLengthValidator(valueLE));
+               v->setBottom(Length());
        else
-               valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
+               v->setBottom(GlueLength());
+       valueLE->setValidator(v);
 
        // initialize the length validator
        addCheckedWidget(valueLE, valueL);
+       enableWidgets();
 }
 
 
@@ -97,17 +102,23 @@ void GuiHSpace::changedSlot()
 }
 
 
-void GuiHSpace::enableWidgets()
+void GuiHSpace::enableWidgets() const
 {
        QString const selection = spacingCO->itemData(spacingCO->currentIndex()).toString();
        bool const custom = selection == "custom";
        valueLE->setEnabled(custom);
+       if (custom)
+               valueLE->setFocus();
+       valueL->setEnabled(custom);
        unitCO->setEnabled(custom);
        fillPatternCO->setEnabled(!math_mode_ && selection == "hfill");
+       fillPatternL->setEnabled(!math_mode_ && selection == "hfill");
        bool const no_pattern = fillPatternCO->currentIndex() == 0 || math_mode_;
        bool const enable_keep =
-               selection == "normal" || selection == "halfquad" || (selection == "hfill" && no_pattern) || custom;
+               selection == "normal" || selection == "halfquad"
+               || (selection == "hfill" && no_pattern) || custom;
        keepCB->setEnabled(enable_keep);
+       keepL->setEnabled(enable_keep);
 }
 
 
@@ -291,8 +302,19 @@ docstring GuiHSpace::dialogToParams() const
 }
 
 
-bool GuiHSpace::checkWidgets() const
+bool GuiHSpace::checkWidgets(bool readonly) const
 {
+       valueLE->setReadOnly(readonly);
+
+       if (readonly) {
+               spacingCO->setEnabled(false);
+               unitCO->setEnabled(false);
+               fillPatternCO->setEnabled(false);
+               keepCB->setEnabled(false);
+               valueLE->setEnabled(false);
+       } else
+               enableWidgets();
+
        if (!InsetParamsWidget::checkWidgets())
                return false;
        return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"