]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiParagraph.cpp
GuiBibtex: Use appropriate title when using Biblatex
[lyx.git] / src / frontends / qt4 / GuiParagraph.cpp
index 835bd520ebc4b57eaada06c7e1221d1e963ffc71..0c8e01aaa434d66d258b13a5a32dd459fa9e1cf4 100644 (file)
@@ -61,7 +61,7 @@ GuiParagraph::GuiParagraph(GuiView & lv)
        connect(labelWidth, SIGNAL(textChanged(QString)),
                this, SLOT(changed()));
 
-#ifdef Q_WS_MACX
+#ifdef Q_OS_MAC
        // On Mac it's common to have tool windows which are always in the
        // foreground and are hidden when the main window is not focused.
        setWindowFlags(Qt::Tool);
@@ -72,7 +72,9 @@ GuiParagraph::GuiParagraph(GuiView & lv)
 #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"
@@ -135,7 +137,7 @@ void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
 }
 
 
-LyXAlignment GuiParagraph::getAlignmentFromDialog()
+LyXAlignment GuiParagraph::getAlignmentFromDialog() const
 {
        LyXAlignment alignment = LYX_ALIGN_NONE;
        RadioMap::const_iterator it = radioMap_.begin();
@@ -164,7 +166,14 @@ void GuiParagraph::on_synchronizedViewCB_toggled()
 
 void GuiParagraph::changed()
 {
-       if (synchronizedViewCB->isChecked())
+       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())))
                on_applyPB_clicked();
 }
 
@@ -196,9 +205,9 @@ void GuiParagraph::on_restorePB_clicked()
 
 void GuiParagraph::applyView()
 {
-       ParagraphParameters & pp = params();
+       params_ = params();
 
-       pp.align(getAlignmentFromDialog());
+       params_.align(getAlignmentFromDialog());
 
        // get spacing
        Spacing::Space ls = Spacing::Default;
@@ -218,17 +227,17 @@ void GuiParagraph::applyView()
                break;
        case 4:
                ls = Spacing::Other;
-               other = fromqstr(linespacingValue->text());
+               other = widgetToDoubleStr(linespacingValue);
                break;
        }
 
        Spacing const spacing(ls, other);
-       pp.spacing(spacing);
+       params_.spacing(spacing);
 
        // label width
-       pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
-       // indendation
-       pp.noindent(!indentCB->isChecked());
+       params_.labelWidthString(qstring_to_ucs4(labelWidth->text()));
+       // indentation
+       params_.noindent(!indentCB->isChecked());
 
        dispatchParams();
 }
@@ -242,8 +251,7 @@ void GuiParagraph::updateView()
 
        // label width
        docstring const & labelwidth = pp.labelWidthString();
-       // FIXME We should not compare translated strings
-       if (labelwidth != _("Senseless with this layout!")) {
+       if (hasLabelwidth()) {
                labelwidthGB->setEnabled(true);
                labelWidth->setText(toqstr(labelwidth));
        } else {
@@ -262,27 +270,38 @@ 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) {
-               linespacingValue->setText(toqstr(space.getValueAsString()));
+       if (space.getSpace() == Spacing::Other || pending_input) {
+               doubleToWidget(linespacingValue, space.getValue());
                linespacingValue->setEnabled(true);
        } else {
                linespacingValue->setText(QString());
@@ -307,52 +326,41 @@ void GuiParagraph::enableView(bool enable)
 }
 
 
-ParagraphParameters & GuiParagraph::params()
+ParagraphParameters const & GuiParagraph::params() const
 {
        if (haveMultiParSelection()) {
-               multiparsel_ = ParagraphParameters();
-               // FIXME: It would be nice to initialise the parameters that
-               // are common to all paragraphs.
-               return multiparsel_;
+               // FIXME: in case of multi-paragraph selection, it would be nice to
+               // initialise the parameters that are common to all paragraphs.
+               static ParagraphParameters const empty;
+               return empty;
        }
-
-       return bufferview()->cursor().innerParagraph().params();
-}
-
-
-ParagraphParameters const & GuiParagraph::params() const
-{
        return bufferview()->cursor().innerParagraph().params();
 }
 
 
 void GuiParagraph::dispatchParams()
 {
-       if (haveMultiParSelection()) {
-               ostringstream data;
-               multiparsel_.write(data);
-               FuncRequest const fr(getLfun(), data.str());
-               dispatch(fr);
-               return;
-       }
-
-       bufferview()->updateMetrics();
-       bufferview()->buffer().changed();
-       bufferview()->buffer().markDirty();
+       ostringstream data;
+       params_.write(data);
+       FuncRequest const fr(getLfun(), data.str());
+       dispatch(fr);
 }
 
 
-bool GuiParagraph::haveMultiParSelection()
+bool GuiParagraph::haveMultiParSelection() const
 {
        Cursor const & cur = bufferview()->cursor();
        return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
 }
 
-       
+
 bool GuiParagraph::canIndent() const
 {
-       return buffer().params().paragraph_separation
-               == BufferParams::ParagraphIndentSeparation;
+       Layout const lay = bufferview()->cursor().innerParagraph().layout();
+       if (buffer().params().paragraph_separation
+               == BufferParams::ParagraphIndentSeparation)
+               return (lay.toggle_indent != ITOGGLE_NEVER);
+       return (lay.toggle_indent == ITOGGLE_ALWAYS);
 }
 
 
@@ -368,6 +376,14 @@ LyXAlignment GuiParagraph::alignDefault() const
 }
 
 
+bool GuiParagraph::hasLabelwidth() const
+{
+       Layout layout = bufferview()->cursor().innerParagraph().layout();
+       return (layout.margintype == MARGIN_MANUAL
+               || layout.latextype == LATEX_BIB_ENVIRONMENT);
+}
+
+
 void GuiParagraph::saveSession() const
 {
        Dialog::saveSession();
@@ -394,4 +410,4 @@ Dialog * createGuiParagraph(GuiView & lv)
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiParagraph_moc.cpp"
+#include "moc_GuiParagraph.cpp"