diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 00e8e1de7..c03425285 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -53,7 +53,9 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent) timerF2 = new QTimer(this); connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF2); - InitOkCancel(ui); + InitOkCancelApply(ui); + + this->formulaBaseHeight=ui->plainTextEditFormula->height(); FillComboBoxPoints(ui->comboBoxBasePoint); @@ -69,9 +71,32 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent) connect(ui->toolButtonEqualF1, &QPushButton::clicked, this, &DialogArc::EvalF1); connect(ui->toolButtonEqualF2, &QPushButton::clicked, this, &DialogArc::EvalF2); - connect(ui->lineEditRadius, &QLineEdit::textChanged, this, &DialogArc::RadiusChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogArc::RadiusChanged); connect(ui->lineEditF1, &QLineEdit::textChanged, this, &DialogArc::F1Changed); connect(ui->lineEditF2, &QLineEdit::textChanged, this, &DialogArc::F2Changed); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogArc::DeployFormulaTextEdit); + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArc::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGARC_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGARC_MAX_FORMULA_HEIGHT); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-next.png"))); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -121,7 +146,12 @@ void DialogArc::SetF1(const QString &value) void DialogArc::SetRadius(const QString &value) { radius = value; - ui->lineEditRadius->setText(radius); + // increase height if needed. + if (radius.length() > 80) + { + this->DeployFormulaTextEdit(); + } + ui->plainTextEditFormula->setPlainText(radius); } //--------------------------------------------------------------------------------------------------------------------- @@ -148,11 +178,24 @@ void DialogArc::ChoosedObject(quint32 id, const Valentina::Scenes &type) */ void DialogArc::DialogAccepted() { - radius = ui->lineEditRadius->text(); + this->SaveData(); + emit DialogClosed(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArc::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogArc::SaveData() +{ + radius = ui->plainTextEditFormula->toPlainText(); + radius.replace("\n"," "); f1 = ui->lineEditF1->text(); f2 = ui->lineEditF2->text(); center = getCurrentObjectId(ui->comboBoxBasePoint); - emit DialogClosed(QDialog::Accepted); } //--------------------------------------------------------------------------------------------------------------------- @@ -183,7 +226,7 @@ void DialogArc::ValChenged(int row) */ void DialogArc::PutRadius() { - PutValHere(ui->lineEditRadius, ui->listWidget); + PutValHere(ui->plainTextEditFormula, ui->listWidget); } //--------------------------------------------------------------------------------------------------------------------- @@ -221,7 +264,7 @@ void DialogArc::LineAngles() void DialogArc::RadiusChanged() { labelEditFormula = ui->labelEditRadius; - ValFormulaChanged(flagRadius, ui->lineEditRadius, timerRadius); + ValFormulaChanged(flagRadius, ui->plainTextEditFormula, timerRadius); } //--------------------------------------------------------------------------------------------------------------------- @@ -252,6 +295,8 @@ void DialogArc::CheckState() { SCASSERT(bOk != nullptr); bOk->setEnabled(flagRadius && flagF1 && flagF2); + SCASSERT(bApply != nullptr); + bApply->setEnabled(flagRadius && flagF1 && flagF2); } //--------------------------------------------------------------------------------------------------------------------- @@ -261,7 +306,7 @@ void DialogArc::CheckState() void DialogArc::EvalRadius() { labelEditFormula = ui->labelEditRadius; - Eval(ui->lineEditRadius, flagRadius, timerRadius, ui->labelResultRadius); + Eval(ui->plainTextEditFormula, flagRadius, timerRadius, ui->labelResultRadius); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogarc.h b/src/app/dialogs/tools/dialogarc.h index 2a0f9781a..361c8d695 100644 --- a/src/app/dialogs/tools/dialogarc.h +++ b/src/app/dialogs/tools/dialogarc.h @@ -31,6 +31,7 @@ #include "dialogtool.h" +#define DIALOGARC_MAX_FORMULA_HEIGHT 64 namespace Ui { class DialogArc; @@ -63,7 +64,11 @@ public slots: /** 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(); virtual void ValChenged(int row); void PutRadius(); void PutF1(); @@ -111,10 +116,17 @@ private: /** @brief f2 formula of second angle */ QString f2; + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeight; + void EvalRadius(); void EvalF1(); void EvalF2(); void ShowLineAngles(); + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogarc.ui b/src/app/dialogs/tools/dialogarc.ui index f5705908f..606cf83c4 100644 --- a/src/app/dialogs/tools/dialogarc.ui +++ b/src/app/dialogs/tools/dialogarc.ui @@ -23,6 +23,9 @@ + + QLayout::SetDefaultConstraint + @@ -74,15 +77,48 @@ - - - - 0 - 0 - + + + + 16777215 + 24 + + + + + + + + + 18 + 18 + + + + + 0 + 0 + - Formula for the calculation of radius of arc + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true @@ -580,14 +616,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditRadius lineEditF1 lineEditF2 comboBoxBasePoint diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index cf6d12ac9..3f7772386 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -34,11 +34,6 @@ #include #include "../../../libs/qmuparser/qmuparsererror.h" -// TODO : for issue #79 -// replace lineEditFormula -> plainTextEditFormula -// delete lineEditFormala everywhrer -// delete PutValHere and eval overloaded functions - //--------------------------------------------------------------------------------------------------------------------- /** * @brief DialogTool create dialog diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 9b421fc0c..fcbe0a5f3 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -205,11 +205,11 @@ protected: void ChangeCurrentText(QComboBox *box, const QString &value); void ChangeCurrentData(QComboBox *box, const quint32 &value) const; void PutValHere(QLineEdit *lineEdit, QListWidget *listWidget); -void PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidget); + void PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidget); void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer); void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer); - void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); void Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label); + void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); void setCurrentPointId(QComboBox *box, quint32 &pointId, const quint32 &value, const quint32 &id) const; void setCurrentSplineId(QComboBox *box, quint32 &splineId, const quint32 &value, const quint32 &id, ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline) const; diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 725e77ef6..88442fed0 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -604,8 +604,18 @@ void MainWindow::ClosedDialogCutSpline(int result) */ void MainWindow::ToolArc(bool checked) { - SetToolButton(checked, Valentina::ArcTool, ":/cursor/arc_cursor.png", - tr("Select point of center of arc"), &MainWindow::ClosedDialogArc); + SetToolButtonWithApply(checked, Valentina::ArcTool, ":/cursor/arc_cursor.png", + tr("Select point of center of arc"), &MainWindow::ClosedDialogArc, + &MainWindow::ApplyDialogArc); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogArc actions after apply in DialogArc. + */ +void MainWindow::ApplyDialogArc() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -615,7 +625,7 @@ void MainWindow::ToolArc(bool checked) */ void MainWindow::ClosedDialogArc(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 7976860d0..d9904ffae 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -116,6 +116,7 @@ public slots: void ClosedDialogLineIntersect(int result); void ClosedDialogSpline(int result); void ClosedDialogArc(int result); + void ApplyDialogArc(); void ClosedDialogSplinePath(int result); void ClosedDialogCutSplinePath(int result); void ClosedDialogPointOfContact(int result); diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index fadf1a9ed..b486e6660 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -73,7 +73,7 @@ void VToolArc::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolArc* VToolArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); DialogArc *dialogTool = qobject_cast(dialog); @@ -82,11 +82,17 @@ void VToolArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *d QString radius = dialogTool->GetRadius(); QString f1 = dialogTool->GetF1(); QString f2 = dialogTool->GetF2(); - Create(0, center, radius, f1, f2, scene, doc, data, Document::FullParse, Valentina::FromGui); + VToolArc* point = nullptr; + point=Create(0, center, radius, f1, f2, scene, doc, data, Document::FullParse, Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, +VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) { @@ -121,7 +127,9 @@ void VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &radius, connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); doc->AddTool(id, toolArc); doc->IncrementReferens(center); + return toolArc; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index b601a230a..88e3ef809 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -61,7 +61,7 @@ public: * @param doc dom document container * @param data container with variables */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolArc* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool form GUI. * @param _id tool id, 0 if tool doesn't exist yet. @@ -75,7 +75,7 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, + static VToolArc* Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString TagName;