From d9a2a4026800865b15da186620ffab4c6b409765 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Mon, 17 Apr 2017 20:32:31 +0200 Subject: [PATCH] BufferParams: get rid of the HSpace class for mathindent as requested by JMarc --- src/Buffer.cpp | 2 +- src/BufferParams.cpp | 25 +++----------- src/BufferParams.h | 5 --- src/frontends/qt4/GuiDocument.cpp | 56 +++++++++++++++++-------------- src/frontends/qt4/GuiDocument.h | 1 + 5 files changed, 38 insertions(+), 51 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 479589217c..36fb8d21d8 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -916,7 +916,7 @@ int Buffer::readHeader(Lexer & lex) params().headheight.erase(); params().headsep.erase(); params().footskip.erase(); - params().math_indentation.erase(); + params().math_indentation = "default"; params().columnsep.erase(); params().fonts_cjk.erase(); params().listings_params.clear(); diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 73b47436b8..09ec43467b 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -342,7 +342,6 @@ public: * and for detached paragraphs in "indented" documents. */ VSpace defskip; - HSpace math_indentation; PDFOptions pdfoptions; LayoutFileIndex baseClass_; FormatList exportableFormatList; @@ -629,18 +628,6 @@ PDFOptions const & BufferParams::pdfoptions() const } -HSpace const & BufferParams::getMathIndentation() const -{ - return pimpl_->math_indentation; -} - - -void BufferParams::setMathIndentation(HSpace const & indent) -{ - pimpl_->math_indentation = indent; -} - - Length const & BufferParams::getParIndent() const { return pimpl_->parindent; @@ -846,9 +833,7 @@ string BufferParams::readToken(Lexer & lex, string const & token, } else if (token == "\\is_math_indent") { lex >> is_math_indent; } else if (token == "\\math_indentation") { - lex.next(); - string math_indentation = lex.getString(); - pimpl_->math_indentation = HSpace(math_indentation); + lex >> math_indentation; } else if (token == "\\quotes_style") { string qstyle; lex >> qstyle; @@ -1346,8 +1331,8 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const else os << "\n\\defskip " << getDefSkip().asLyXCommand(); os << "\n\\is_math_indent " << is_math_indent; - if (is_math_indent && getMathIndentation().asLyXCommand() != "default") - os << "\n\\math_indentation " << getMathIndentation().asLyXCommand(); + if (is_math_indent && math_indentation != "default") + os << "\n\\math_indentation " << math_indentation; os << "\n\\quotes_style " << string_quotes_style[quotes_style] << "\n\\dynamic_quotes " << dynamic_quotes @@ -1959,9 +1944,9 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, if (is_math_indent) { // when formula indentation // only output something when it is not the default - if (getMathIndentation().asLyXCommand() != "default") { + if (math_indentation != "default") { os << "\\setlength{\\mathindent}{" - << from_utf8(getMathIndentation().asLatexCommand()) + << from_utf8(math_indentation) << "}\n"; } } diff --git a/src/BufferParams.h b/src/BufferParams.h index 14935a9370..437d00b700 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -102,11 +102,6 @@ public: /// void setDefSkip(VSpace const & vs); - /// - HSpace const & getMathIndentation() const; - /// - void setMathIndentation(HSpace const & indent); - /// Whether formulas are indented bool is_math_indent; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 52515dd85c..d3ccb8f5b0 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -727,6 +727,8 @@ GuiDocument::GuiDocument(GuiView & lv) connect(textLayoutModule->MathIndentCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor())); + connect(textLayoutModule->MathIndentCB, SIGNAL(toggled(bool)), + this, SLOT(allowMathIndent())); connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)), @@ -1610,6 +1612,22 @@ void GuiDocument::enableSkip(bool skip) setSkip(textLayoutModule->skipCO->currentIndex()); } +void GuiDocument::allowMathIndent() +{ + // only disable when not checked, checked does not always allow enabling + if (!textLayoutModule->MathIndentCB->isChecked()) { + textLayoutModule->MathIndentLE->setEnabled(false); + textLayoutModule->MathIndentLengthCO->setEnabled(false); + } + if (textLayoutModule->MathIndentCB->isChecked() + && textLayoutModule->MathIndentCO->currentIndex() == 1) { + textLayoutModule->MathIndentLE->setEnabled(true); + textLayoutModule->MathIndentLengthCO->setEnabled(true); + + } + isValid(); +} + void GuiDocument::setMathIndent(int item) { bool const enable = (item == 1); @@ -2900,16 +2918,7 @@ void GuiDocument::applyView() if (rb->isChecked()) bp_.use_package(it->first, BufferParams::package_off); } - bp_.is_math_indent = textLayoutModule->MathIndentCB->isChecked(); - // if math is indented - if (bp_.is_math_indent) { - HSpace MathIndentation = HSpace( - widgetsToLength(textLayoutModule->MathIndentLE, - textLayoutModule->MathIndentLengthCO) - ); - bp_.setMathIndentation(MathIndentation); - } - + // Page Layout if (pageLayoutModule->pagestyleCO->currentIndex() == 0) bp_.pagestyle = "default"; @@ -2997,26 +3006,24 @@ void GuiDocument::applyView() } } - if (textLayoutModule->MathIndentCB->isChecked()) { - // if formulas are indented + bp_.is_math_indent = textLayoutModule->MathIndentCB->isChecked(); + if (bp_.is_math_indent) { + // if math is indented switch (textLayoutModule->MathIndentCO->currentIndex()) { case 0: - bp_.setMathIndentation(HSpace(HSpace::DEFAULT)); + bp_.math_indentation = "default"; break; - case 1: { - HSpace MathIndent = HSpace( - widgetsToLength(textLayoutModule->MathIndentLE, - textLayoutModule->MathIndentLengthCO) - ); - bp_.setMathIndentation(MathIndent); + case 1: + bp_.math_indentation = widgetsToLength(textLayoutModule->MathIndentLE, + textLayoutModule->MathIndentLengthCO); break; - } default: // this should never happen - bp_.setMathIndentation(HSpace(HSpace::DEFAULT)); + bp_.math_indentation = "default"; break; } - } + } else + bp_.math_indentation = "default"; bp_.options = fromqstr(latexModule->optionsLE->text()); @@ -3384,12 +3391,11 @@ void GuiDocument::paramsToDialog() // math if (bp_.is_math_indent) { textLayoutModule->MathIndentCB->setChecked(bp_.is_math_indent); - string MathIndentation = bp_.getMathIndentation().asLyXCommand(); int MathIndent = 0; - if (MathIndentation != "default") { + if (bp_.math_indentation != "default") { lengthToWidgets(textLayoutModule->MathIndentLE, textLayoutModule->MathIndentLengthCO, - MathIndentation, default_unit); + bp_.math_indentation, default_unit); MathIndent = 1; } textLayoutModule->MathIndentCO->setCurrentIndex(MathIndent); diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index b33fca95f8..7527a59edc 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -109,6 +109,7 @@ private Q_SLOTS: void enableIndent(bool); void setSkip(int); void enableSkip(bool); + void allowMathIndent(); void setMathIndent(int); void browseLayout(); void browseMaster(); -- 2.39.2