From 8a10d43778b6419263c6b513f8ce8c284e322384 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 29 Oct 2014 20:00:38 +0200 Subject: [PATCH] Ignore Enter key in formula field. --HG-- branch : develop --- src/app/dialogs/tools/dialogalongline.cpp | 1 + src/app/dialogs/tools/dialogarc.cpp | 4 ++++ src/app/dialogs/tools/dialogbisector.cpp | 1 + .../tools/dialogcurveintersectaxis.cpp | 1 + src/app/dialogs/tools/dialogcutarc.cpp | 1 + src/app/dialogs/tools/dialogcutspline.cpp | 1 + src/app/dialogs/tools/dialogcutsplinepath.cpp | 1 + .../dialogs/tools/dialogeditwrongformula.cpp | 1 + src/app/dialogs/tools/dialogendline.cpp | 3 +++ .../dialogs/tools/dialoglineintersectaxis.cpp | 1 + src/app/dialogs/tools/dialognormal.cpp | 1 + .../dialogs/tools/dialogpointofcontact.cpp | 1 + src/app/dialogs/tools/dialogshoulderpoint.cpp | 1 + src/app/dialogs/tools/dialogtool.cpp | 21 +++++++++++++++++++ src/app/dialogs/tools/dialogtool.h | 1 + 15 files changed, 40 insertions(+) diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 0f5ca7f0e..9d37faa3b 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -52,6 +52,7 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId, labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancelApply(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 941863a18..b0ba3332b 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -57,6 +57,10 @@ DialogArc::DialogArc(const VContainer *data, const quint32 &toolId, QWidget *par this->formulaBaseHeightF1 = ui->plainTextEditF1->height(); this->formulaBaseHeightF2 = ui->plainTextEditF2->height(); + ui->plainTextEditFormula->installEventFilter(this); + ui->plainTextEditF1->installEventFilter(this); + ui->plainTextEditF2->installEventFilter(this); + timerRadius = new QTimer(this); connect(timerRadius, &QTimer::timeout, this, &DialogArc::EvalRadius); diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 0dc5a080c..7abbc3f2e 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -52,6 +52,7 @@ DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QW ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancelApply(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogcurveintersectaxis.cpp b/src/app/dialogs/tools/dialogcurveintersectaxis.cpp index 00e1ef42b..65f0c54d2 100644 --- a/src/app/dialogs/tools/dialogcurveintersectaxis.cpp +++ b/src/app/dialogs/tools/dialogcurveintersectaxis.cpp @@ -48,6 +48,7 @@ DialogCurveIntersectAxis::DialogCurveIntersectAxis(const VContainer *data, const ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeightAngle = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancelApply(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index 759b1ce7f..748ff0501 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -51,6 +51,7 @@ DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidge ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancelApply(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogcutspline.cpp b/src/app/dialogs/tools/dialogcutspline.cpp index becf3a736..ebfb4e5a9 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -50,6 +50,7 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancelApply(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index b0bb4d79d..a5abc37e1 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -50,6 +50,7 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 & ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancelApply(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogeditwrongformula.cpp b/src/app/dialogs/tools/dialogeditwrongformula.cpp index b66251c32..fa7170e39 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.cpp +++ b/src/app/dialogs/tools/dialogeditwrongformula.cpp @@ -38,6 +38,7 @@ DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const qui InitVariables(ui); InitFormulaUI(ui); this->formulaBaseHeight = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancel(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 73485c697..76ef75132 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -55,6 +55,9 @@ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWid this->formulaBaseHeight = ui->plainTextEditFormula->height(); this->formulaBaseHeightAngle = ui->plainTextEditAngle->height(); + ui->plainTextEditFormula->installEventFilter(this); + ui->plainTextEditAngle->installEventFilter(this); + InitOkCancelApply(ui); flagFormula = false; CheckState(); diff --git a/src/app/dialogs/tools/dialoglineintersectaxis.cpp b/src/app/dialogs/tools/dialoglineintersectaxis.cpp index 54ff4b1eb..768536d4b 100644 --- a/src/app/dialogs/tools/dialoglineintersectaxis.cpp +++ b/src/app/dialogs/tools/dialoglineintersectaxis.cpp @@ -48,6 +48,7 @@ DialogLineIntersectAxis::DialogLineIntersectAxis(const VContainer *data, const q ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeightAngle = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancelApply(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index e950b364f..77bf2cc3c 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -48,6 +48,7 @@ DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidge ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancelApply(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index 06c0d0c01..f07f18458 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -50,6 +50,7 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancelApply(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index a55968ad2..7048321af 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -52,6 +52,7 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 & ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); InitOkCancelApply(ui); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 718a9e346..3280a5897 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -401,6 +401,27 @@ void DialogTool::MoveCursorToEnd(QPlainTextEdit *plainTextEdit) plainTextEdit->setTextCursor(cursor); } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogTool::eventFilter(QObject *object, QEvent *event) +{ + QPlainTextEdit *plainTextEdit = qobject_cast(object); + if (plainTextEdit != nullptr) + { + QKeyEvent *keyEvent = static_cast(event); + if ((keyEvent->key() == Qt::Key_Enter) || (keyEvent->key() == Qt::Key_Return)) + { + // Ignore Enter key + return true; + } + } + else + { + // pass the event on to the parent class + return QDialog::eventFilter(object, event); + } + return false; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ValFormulaChanged handle change formula diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index d50a404af..0cf27043d 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -334,6 +334,7 @@ protected: */ virtual void SaveData(){} void MoveCursorToEnd(QPlainTextEdit *plainTextEdit); + bool eventFilter(QObject *object, QEvent *event); private: void FillList(QComboBox *box, const QMap &list)const; };