From b300bfb8f8a16e5c7d250dcff526046f0e975100 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Mon, 9 Jun 2014 22:38:10 +0200 Subject: [PATCH] DialogArc change... Seems the end at last !!! --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogarc.cpp | 61 ++++++++++++++++++++++++---- src/app/dialogs/tools/dialogarc.h | 15 ++++++- src/app/dialogs/tools/dialogarc.ui | 53 ++++++++++++++++++++---- src/app/dialogs/tools/dialogtool.cpp | 5 --- src/app/dialogs/tools/dialogtool.h | 15 ++++++- src/app/mainwindow.cpp | 16 ++++++-- src/app/mainwindow.h | 1 + src/app/tools/drawTools/vtoolarc.cpp | 14 +++++-- src/app/tools/drawTools/vtoolarc.h | 4 +- 9 files changed, 152 insertions(+), 32 deletions(-) diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 3fe156386..c1248034e 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -48,7 +48,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); @@ -64,9 +66,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"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -100,7 +125,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); } //--------------------------------------------------------------------------------------------------------------------- @@ -119,11 +149,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); } //--------------------------------------------------------------------------------------------------------------------- @@ -147,7 +190,7 @@ void DialogArc::ValChenged(int row) //--------------------------------------------------------------------------------------------------------------------- void DialogArc::PutRadius() { - PutValHere(ui->lineEditRadius, ui->listWidget); + PutValHere(ui->plainTextEditFormula, ui->listWidget); } //--------------------------------------------------------------------------------------------------------------------- @@ -173,7 +216,7 @@ void DialogArc::LineAngles() void DialogArc::RadiusChanged() { labelEditFormula = ui->labelEditRadius; - ValFormulaChanged(flagRadius, ui->lineEditRadius, timerRadius); + ValFormulaChanged(flagRadius, ui->plainTextEditFormula, timerRadius); } //--------------------------------------------------------------------------------------------------------------------- @@ -195,13 +238,15 @@ void DialogArc::CheckState() { SCASSERT(bOk != nullptr); bOk->setEnabled(flagRadius && flagF1 && flagF2); + SCASSERT(bApply != nullptr); + bApply->setEnabled(flagRadius && flagF1 && flagF2); } //--------------------------------------------------------------------------------------------------------------------- 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 dda31681b..554c0a2bd 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; @@ -104,7 +105,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(); /** * @brief ValChenged show description angles of lines * @param row number of row @@ -146,6 +151,10 @@ protected: virtual void CheckState(); private: Q_DISABLE_COPY(DialogArc) + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ @@ -206,6 +215,10 @@ private: * @brief ShowLineAngles show varibles angles of lines */ void ShowLineAngles(); + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline quint32 DialogArc::GetCenter() const 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 e075e63ed..5a90c094d 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 - //--------------------------------------------------------------------------------------------------------------------- DialogTool::DialogTool(const VContainer *data, QWidget *parent) :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(nullptr), diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index ccd8d99d4..9797c6f87 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -376,7 +376,21 @@ protected: * @param timer timer of formula */ void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer); + /** + * @brief ValFormulaChanged handle change formula + * @param flag flag state of formula + * @param edit PlainTextEdit + * @param timer timer of formula + */ void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer); + /** + * @brief Eval evaluate formula and show result + * @param edit PlainTextEdit of formula + * @param flag flag state of formula + * @param timer timer of formula + * @param label label for signal error + */ + void Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label); /** * @brief Eval evaluate formula and show result * @param edit lineEdit of formula @@ -384,7 +398,6 @@ protected: * @param timer timer of formula * @param label label for signal error */ - void Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label); void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); /** * @brief setCurrentPointId set current point id in combobox diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 175e16c0a..14c3cd1c7 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -602,8 +602,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(); } //--------------------------------------------------------------------------------------------------------------------- @@ -613,7 +623,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 268103c30..2c64f31d9 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;