From a167cda90c14a85feb22b815ff26f4de9c43f5b3 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Mon, 9 Jun 2014 12:56:07 +0200 Subject: [PATCH] DialogShoulderPoinr change --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogshoulderpoint.cpp | 61 ++++++++++++++-- src/app/dialogs/tools/dialogshoulderpoint.h | 21 +++++- src/app/dialogs/tools/dialogshoulderpoint.ui | 71 ++++++++++++++++--- src/app/mainwindow.cpp | 16 ++++- src/app/mainwindow.h | 1 + .../tools/drawTools/vtoolshoulderpoint.cpp | 14 +++- src/app/tools/drawTools/vtoolshoulderpoint.h | 4 +- 7 files changed, 162 insertions(+), 26 deletions(-) diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index 663424ff0..fe9af1bc7 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -40,11 +40,13 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent number = 0; InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; InitOkCancelApply(ui); + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + flagFormula = false; flagName = false; CheckState(); @@ -58,7 +60,38 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogShoulderPoint::PutVal); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogShoulderPoint::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogShoulderPoint::NamePointChanged); - connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogShoulderPoint::FormulaChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogShoulderPoint::FormulaTextChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogShoulderPoint::DeployFormulaTextEdit); + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogShoulderPoint::FormulaTextChanged() +{ + // TODO issue #79 : back to FormulaChanged when full update + // Also remove this function if only one function called here + this->FormulaChanged2(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogShoulderPoint::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGSHOULDERPOINT_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGSHOULDERPOINT_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"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -114,14 +147,27 @@ void DialogShoulderPoint::ChoosedObject(quint32 id, const Valentina::Scenes &typ //--------------------------------------------------------------------------------------------------------------------- void DialogShoulderPoint::DialogAccepted() +{ + this->SaveData(); + emit DialogClosed(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogShoulderPoint::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogShoulderPoint::SaveData() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - formula = ui->lineEditFormula->text(); + formula = ui->plainTextEditFormula->toPlainText(); + formula.replace("\n"," "); p1Line = getCurrentObjectId(ui->comboBoxP1Line); p2Line = getCurrentObjectId(ui->comboBoxP2Line); pShoulder = getCurrentObjectId(ui->comboBoxPShoulder); - emit DialogClosed(QDialog::Accepted); } //--------------------------------------------------------------------------------------------------------------------- @@ -146,7 +192,12 @@ void DialogShoulderPoint::setP1Line(const quint32 &value, const quint32 &id) void DialogShoulderPoint::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/dialogshoulderpoint.h b/src/app/dialogs/tools/dialogshoulderpoint.h index 933c4f96b..2b88ab209 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.h +++ b/src/app/dialogs/tools/dialogshoulderpoint.h @@ -31,6 +31,7 @@ #include "dialogtool.h" +#define DIALOGSHOULDERPOINT_MAX_FORMULA_HEIGHT 64 namespace Ui { class DialogShoulderPoint; @@ -124,12 +125,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(DialogShoulderPoint) + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ @@ -162,6 +175,10 @@ private: * @brief pShoulder id shoulder point */ quint32 pShoulder; + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline QString DialogShoulderPoint::getPointName() const diff --git a/src/app/dialogs/tools/dialogshoulderpoint.ui b/src/app/dialogs/tools/dialogshoulderpoint.ui index 27bd11328..a9ed3dc8b 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.ui +++ b/src/app/dialogs/tools/dialogshoulderpoint.ui @@ -74,17 +74,17 @@ - - - - 0 - 0 - + + + Qt::Horizontal - - Formula for calculation of length of line + + + 40 + 20 + - + @@ -150,6 +150,56 @@ + + + + + + + 16777215 + 24 + + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + @@ -462,14 +512,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditFormula lineEditNamePoint comboBoxP1Line comboBoxP2Line diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index dd4d4c4f7..48c45b976 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -451,8 +451,18 @@ void MainWindow::ClosedDialogAlongLine(int result) */ void MainWindow::ToolShoulderPoint(bool checked) { - SetToolButton(checked, Valentina::ShoulderPointTool, ":/cursor/shoulder_cursor.png", - tr("Select first point of line"), &MainWindow::ClosedDialogShoulderPoint); + SetToolButton2(checked, Valentina::ShoulderPointTool, ":/cursor/shoulder_cursor.png", + tr("Select first point of line"), &MainWindow::ClosedDialogShoulderPoint, + &MainWindow::ApplyDialogShoulderPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogShoulderPoint actions after apply in DialogEndLine. + */ +void MainWindow::ApplyDialogShoulderPoint() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -462,7 +472,7 @@ void MainWindow::ToolShoulderPoint(bool checked) */ void MainWindow::ClosedDialogShoulderPoint(int result) { - ClosedDialog(result); + ClosedDialog2(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 37e4be09d..a1eef0b61 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -108,6 +108,7 @@ public slots: void ClosedDialogAlongLine(int result); void ApplyDialogAlongLine(); void ClosedDialogShoulderPoint(int result); + void ApplyDialogShoulderPoint(); void ClosedDialogNormal(int result); void ApplyDialogNormal(); void ClosedDialogBisector(int result); diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index 1c8d1f932..b92d0e300 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -94,7 +94,7 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li } //--------------------------------------------------------------------------------------------------------------------- -void VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolShoulderPoint* VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); DialogShoulderPoint *dialogTool = qobject_cast(dialog); @@ -105,12 +105,18 @@ void VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphicsScene *scene, V const quint32 pShoulder = dialogTool->getPShoulder(); const QString typeLine = dialogTool->getTypeLine(); const QString pointName = dialogTool->getPointName(); - Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, scene, doc, data, + VToolShoulderPoint * point = nullptr; + point=Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolShoulderPoint::Create(const quint32 _id, QString &formula, const quint32 &p1Line, +VToolShoulderPoint* VToolShoulderPoint::Create(const quint32 _id, QString &formula, const quint32 &p1Line, const quint32 &p2Line, const quint32 &pShoulder, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, @@ -154,7 +160,9 @@ void VToolShoulderPoint::Create(const quint32 _id, QString &formula, const quint doc->IncrementReferens(p1Line); doc->IncrementReferens(p2Line); doc->IncrementReferens(pShoulder); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.h b/src/app/tools/drawTools/vtoolshoulderpoint.h index 9e9462d9d..e9eec3e8a 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.h +++ b/src/app/tools/drawTools/vtoolshoulderpoint.h @@ -76,7 +76,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolShoulderPoint* 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. @@ -94,7 +94,7 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const quint32 _id, QString &formula, const quint32 &p1Line, const quint32 &p2Line, + static VToolShoulderPoint* Create(const quint32 _id, QString &formula, const quint32 &p1Line, const quint32 &p2Line, const quint32 &pShoulder, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation);