]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiParagraph.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiParagraph.cpp
index 6a0248ad2c2cb3ca56b5f496e4fb50d65599bc7c..ab6c9aef8b671cee8386a098c0244fb547c88b0b 100644 (file)
@@ -32,6 +32,7 @@
 #include "support/gettext.h"
 
 #include <QCheckBox>
+#include <QDialogButtonBox>
 #include <QLineEdit>
 #include <QPushButton>
 #include <QSettings>
@@ -49,6 +50,9 @@ GuiParagraph::GuiParagraph(GuiView & lv)
 {
        setupUi(this);
 
+       // fix height to minimum
+       setFixedHeight(sizeHint().height());
+
        connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
        connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
        connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
@@ -66,13 +70,14 @@ GuiParagraph::GuiParagraph(GuiView & lv)
        // foreground and are hidden when the main window is not focused.
        setWindowFlags(Qt::Tool);
        synchronizedViewCB->setChecked(true);
-       closePB->setText(qt_("&Cancel"));
 #else
        synchronizedViewCB->setChecked(false);
 #endif
 
        on_synchronizedViewCB_toggled();
-       linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
+       QDoubleValidator * val = new QDoubleValidator(linespacingValue);
+       val->setNotation(QDoubleValidator::StandardNotation);
+       linespacingValue->setValidator(val);
 
        labelWidth->setWhatsThis(qt_(
                "As described in the User Guide, the width of"
@@ -152,45 +157,49 @@ LyXAlignment GuiParagraph::getAlignmentFromDialog() const
 void GuiParagraph::on_synchronizedViewCB_toggled()
 {
        bool in_sync = synchronizedViewCB->isChecked();
-       restorePB->setEnabled(!in_sync);
-       applyPB->setEnabled(!in_sync);
-       okPB->setEnabled(!in_sync);
+       buttonBox->button(QDialogButtonBox::Reset)->setEnabled(!in_sync);
+       buttonBox->button(QDialogButtonBox::Apply)->setEnabled(!in_sync);
+       buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!in_sync);
        if (!in_sync)
-               closePB->setText(qt_("&Cancel"));
+               buttonBox->button(QDialogButtonBox::Cancel)->setText(qt_("&Cancel"));
        else
-               closePB->setText(qt_("&Close"));
+               buttonBox->button(QDialogButtonBox::Cancel)->setText(qt_("&Close"));
 }
 
 
 void GuiParagraph::changed()
 {
-       if (synchronizedViewCB->isChecked())
-               on_applyPB_clicked();
-}
-
-
-void GuiParagraph::on_applyPB_clicked()
-{
-       applyView();
-}
-
-
-void GuiParagraph::on_okPB_clicked()
-{
-       applyView();
-       hide();
+       QLocale loc;
+       // We apply immediately, except if we have custom line spacing
+       // with an intermediate result (trailing decimal separator) or
+       // an invalid value (which might as well be intermediate)
+       if (synchronizedViewCB->isChecked()
+           && (linespacing->currentIndex() != 4
+               || (!linespacingValue->text().endsWith(loc.decimalPoint())
+                   && linespacingValue->hasAcceptableInput())))
+               applyView();
 }
 
 
-void GuiParagraph::on_closePB_clicked()
+void GuiParagraph::on_buttonBox_clicked(QAbstractButton * button)
 {
-       hide();
-}
-
-
-void GuiParagraph::on_restorePB_clicked()
-{
-       updateView();
+       switch (buttonBox->standardButton(button)) {
+       case QDialogButtonBox::Ok:
+               applyView();
+               hide();
+               break;
+       case QDialogButtonBox::Apply:
+               applyView();
+               break;
+       case QDialogButtonBox::Cancel:
+               hide();
+               break;
+       case QDialogButtonBox::Reset:
+               updateView();
+               break;
+       default:
+               break;
+       }
 }
 
 
@@ -261,32 +270,45 @@ void GuiParagraph::updateView()
 
        // linespacing
        int ls;
+       bool pending_input = false;
        Spacing const & space = pp.spacing();
-       switch (space.getSpace()) {
-       case Spacing::Single:
-               ls = 1;
-               break;
-       case Spacing::Onehalf:
-               ls = 2;
-               break;
-       case Spacing::Double:
-               ls = 3;
-               break;
-       case Spacing::Other:
+       if (synchronizedViewCB->isChecked() && linespacingValue->hasFocus()) {
+               // The user is about to enter custom spacing.
+               // We thus stay in Custom mode.
+               // This prevents the combo from e.g. immediately
+               // switching to single if a user enters "1" in the
+               // linespacingValue widget while aiming at e.g. "1.3"
                ls = 4;
-               break;
-       default:
-               ls = 0;
-               break;
+               pending_input = true;
+       } else {
+               switch (space.getSpace()) {
+               case Spacing::Single:
+                       ls = 1;
+                       break;
+               case Spacing::Onehalf:
+                       ls = 2;
+                       break;
+               case Spacing::Double:
+                       ls = 3;
+                       break;
+               case Spacing::Other:
+                       ls = 4;
+                       break;
+               default:
+                       ls = 0;
+                       break;
+               }
        }
        linespacing->setCurrentIndex(ls);
-       if (space.getSpace() == Spacing::Other) {
+       if (space.getSpace() == Spacing::Other || pending_input) {
                doubleToWidget(linespacingValue, space.getValue());
                linespacingValue->setEnabled(true);
        } else {
                linespacingValue->setText(QString());
                linespacingValue->setEnabled(false);
        }
+       // Somewhere in the chain this can lose default status (#11417)
+       buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
 }
 
 
@@ -296,8 +318,8 @@ void GuiParagraph::enableView(bool enable)
        linespacing->setEnabled(enable);
        labelWidth->setEnabled(enable);
        synchronizedViewCB->setEnabled(enable);
-       applyPB->setEnabled(enable);
-       restorePB->setEnabled(enable);
+       buttonBox->button(QDialogButtonBox::Apply)->setEnabled(enable);
+       buttonBox->button(QDialogButtonBox::Reset)->setEnabled(enable);
        if (!enable)
                synchronizedViewCB->setChecked(true);
        RadioMap::const_iterator it = radioMap_.begin();
@@ -320,9 +342,9 @@ ParagraphParameters const & GuiParagraph::params() const
 
 void GuiParagraph::dispatchParams()
 {
-       ostringstream data;
-       params_.write(data);
-       FuncRequest const fr(getLfun(), data.str());
+       ostringstream os;
+       params_.write(os);
+       FuncRequest const fr(getLfun(), os.str());
        dispatch(fr);
 }
 
@@ -333,7 +355,7 @@ bool GuiParagraph::haveMultiParSelection() const
        return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
 }
 
-       
+
 bool GuiParagraph::canIndent() const
 {
        Layout const lay = bufferview()->cursor().innerParagraph().layout();
@@ -364,10 +386,9 @@ bool GuiParagraph::hasLabelwidth() const
 }
 
 
-void GuiParagraph::saveSession() const
+void GuiParagraph::saveSession(QSettings & settings) const
 {
-       Dialog::saveSession();
-       QSettings settings;
+       Dialog::saveSession(settings);
        settings.setValue(sessionKey() + "/autoapply", synchronizedViewCB->isChecked());
 }