diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 2d69e0f79..d5e87e17e 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -38,9 +38,11 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) { ui->setupUi(this); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + flagFormula = false; flagName = false; InitOkCancelApply(ui); @@ -55,11 +57,37 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogAlongLine::PutHere); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula); - connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogAlongLine::FormulaChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogAlongLine::FormulaTextChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogAlongLine::DeployFormulaTextEdit); InitVariables(ui); connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogTool::PutVal); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::FormulaTextChanged() +{ + // TODO issue #79 : back to FormulaChanged when full update + // Also remove this function if only one function called here + this->FormulaChanged2(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGALONLINE_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGALONLINE_MAX_FORMULA_HEIGHT); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next")); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down")); + } +} + //--------------------------------------------------------------------------------------------------------------------- DialogAlongLine::~DialogAlongLine() { @@ -93,15 +121,27 @@ void DialogAlongLine::ChoosedObject(quint32 id, const Valentina::Scenes &type) } } -//--------------------------------------------------------------------------------------------------------------------- void DialogAlongLine::DialogAccepted() +{ + this->SaveData(); + emit DialogClosed(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::SaveData() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - formula = ui->lineEditFormula->text(); + formula = ui->plainTextEditFormula->toPlainText(); + formula.replace("\n"," "); firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); - emit DialogClosed(QDialog::Accepted); } //--------------------------------------------------------------------------------------------------------------------- @@ -120,7 +160,12 @@ void DialogAlongLine::setFirstPointId(const quint32 &value, const quint32 &id) void DialogAlongLine::setFormula(const QString &value) { formula = qApp->FormulaToUser(value); - ui->lineEditFormula->setText(formula); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployFormulaTextEdit(); + } + ui->plainTextEditFormula->setPlainText(formula); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogalongline.h b/src/app/dialogs/tools/dialogalongline.h index 69ef285f8..f485a5c9a 100644 --- a/src/app/dialogs/tools/dialogalongline.h +++ b/src/app/dialogs/tools/dialogalongline.h @@ -31,6 +31,7 @@ #include "dialogtool.h" +#define DIALOGALONLINE_MAX_FORMULA_HEIGHT 64 namespace Ui { class DialogAlongLine; @@ -113,12 +114,24 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); - /** TODO ISSUE 79 : create real function + /** * @brief DialogApply apply data and emit signal about applied dialog. */ - virtual void DialogApply(){} + virtual void DialogApply(); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployFormulaTextEdit(); + /** + * @brief FormulaTextChanged when formula text changes for validation and calc + */ + void FormulaTextChanged(); private: Q_DISABLE_COPY(DialogAlongLine) + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ @@ -147,6 +160,10 @@ private: * @brief secondPointId id second point of line */ quint32 secondPointId; + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline QString DialogAlongLine::getPointName() const diff --git a/src/app/dialogs/tools/dialogalongline.ui b/src/app/dialogs/tools/dialogalongline.ui index 9113f9e04..c935b0f11 100644 --- a/src/app/dialogs/tools/dialogalongline.ui +++ b/src/app/dialogs/tools/dialogalongline.ui @@ -74,11 +74,17 @@ - - - Formula for the calculation of length of line + + + Qt::Horizontal - + + + 40 + 20 + + + @@ -150,6 +156,50 @@ + + + + + + + 16777215 + 24 + + + + + + + + + 16 + 16 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + @@ -390,14 +440,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditFormula toolButtonEqual lineEditNamePoint comboBoxFirstPoint diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 5a287426e..12be8bf7a 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -169,6 +169,9 @@ 0 + + QPlainTextEdit::NoWrap + @@ -186,7 +189,8 @@ - + + :/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png:/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png @@ -673,6 +677,7 @@ + diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 4215af96e..86f0b0e4d 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -421,8 +421,17 @@ void MainWindow::ClosedDialogLine(int result) */ void MainWindow::ToolAlongLine(bool checked) { - SetToolButton(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png", - tr("Select point"), &MainWindow::ClosedDialogAlongLine); + SetToolButton2(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png", + tr("Select point"), &MainWindow::ClosedDialogAlongLine, &MainWindow::ApplyDialogAlongLine); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogAlongLine actions after apply in DialogAlongLine. + */ +void MainWindow::ApplyDialogAlongLine() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -432,7 +441,7 @@ void MainWindow::ToolAlongLine(bool checked) */ void MainWindow::ClosedDialogAlongLine(int result) { - ClosedDialog(result); + ClosedDialog2(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index eac2e1886..c5bd288b3 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -106,6 +106,7 @@ public slots: void ApplyDialogEndLine(); void ClosedDialogLine(int result); void ClosedDialogAlongLine(int result); + void ApplyDialogAlongLine(); void ClosedDialogShoulderPoint(int result); void ClosedDialogNormal(int result); void ClosedDialogBisector(int result); diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index a0c8da771..19f1f703e 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -158,7 +158,7 @@ void VToolAlongLine::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolAlongLine* VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); DialogAlongLine *dialogTool = qobject_cast(dialog); @@ -168,12 +168,18 @@ void VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatt const quint32 secondPointId = dialogTool->getSecondPointId(); const QString typeLine = dialogTool->getTypeLine(); const QString pointName = dialogTool->getPointName(); - Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, scene, doc, data, + VToolAlongLine *point=nullptr; + point = Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolAlongLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, +VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) @@ -212,5 +218,7 @@ void VToolAlongLine::Create(const quint32 _id, const QString &pointName, const Q doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); + return point; } + return nullptr; } diff --git a/src/app/tools/drawTools/vtoolalongline.h b/src/app/tools/drawTools/vtoolalongline.h index 8276c3954..a5f9795bb 100644 --- a/src/app/tools/drawTools/vtoolalongline.h +++ b/src/app/tools/drawTools/vtoolalongline.h @@ -64,7 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolAlongLine* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -81,7 +81,7 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, + static VToolAlongLine* Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation);