From 2f630435bb0c39e5fbf779b957db1542f3690fe2 Mon Sep 17 00:00:00 2001 From: peri4 Date: Tue, 18 Apr 2023 14:06:21 +0300 Subject: [PATCH] EvalSpinBox::singleStep property --- CMakeLists.txt | 2 +- libs/widgets/evalspinbox.cpp | 26 ++++++++++++-------------- libs/widgets/evalspinbox.h | 8 ++++++-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33d91b9..882f67c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default project(QAD) set(QAD_MAJOR 2) -set(QAD_MINOR 15) +set(QAD_MINOR 16) set(QAD_REVISION 0) set(QAD_SUFFIX ) set(QAD_COMPANY SHS) diff --git a/libs/widgets/evalspinbox.cpp b/libs/widgets/evalspinbox.cpp index ae55e17..fca62cc 100644 --- a/libs/widgets/evalspinbox.cpp +++ b/libs/widgets/evalspinbox.cpp @@ -19,11 +19,10 @@ EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) { - status = new QWidget(lineEdit()); - cw = new QWidget(lineEdit()); - label = new QLabel(lineEdit()); - eval = new QPIEvaluator(); - precision_ = -1; + status = new QWidget(lineEdit()); + cw = new QWidget(lineEdit()); + label = new QLabel(lineEdit()); + eval = new QPIEvaluator(); clear_im.load(":/icons/edit-clear-locationbar-rtl.png"); icon_ok.load(":/icons/dialog-ok-apply.png"); icon_fail.load(":/icons/dialog-warning.png"); @@ -35,8 +34,6 @@ EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) { cw->setCursor(Qt::ArrowCursor); cw->setToolTip(tr("Clear")); cw->hide(); - cw_visible = false; - calc_visible = true; cw->installEventFilter(this); status->installEventFilter(this); connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString))); @@ -212,7 +209,7 @@ void EvalSpinBox::setValue(double val) { void EvalSpinBox::stepBy(int steps) { - stepByDouble(steps); + stepByDouble(steps * m_singleStep); } @@ -291,15 +288,16 @@ void EvalSpinBox::focusOutEvent(QFocusEvent * event) { void EvalSpinBox::wheelEvent(QWheelEvent * event) { if (event->modifiers().testFlag(Qt::ShiftModifier)) { - stepByDouble( + stepByDouble(( #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - event->delta() + event->delta() #else - event->angleDelta().y() + event->angleDelta().y() #endif - > 0 - ? 0.1 - : -0.1); + > 0 + ? 0.1 + : -0.1) * + m_singleStep); } else { QAbstractSpinBox::wheelEvent(event); } diff --git a/libs/widgets/evalspinbox.h b/libs/widgets/evalspinbox.h index 776d1d2..04cc5ff 100644 --- a/libs/widgets/evalspinbox.h +++ b/libs/widgets/evalspinbox.h @@ -37,6 +37,7 @@ class QAD_WIDGETS_EXPORT EvalSpinBox: public QAbstractSpinBox { Q_PROPERTY(bool clearButtonVisible READ isClearButtonVisible WRITE setClearButtonVisible) Q_PROPERTY(bool calculationVisible READ isCalculationVisible WRITE setCalculationVisible) Q_PROPERTY(int precision READ precision WRITE setPrecision) + Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep) public: explicit EvalSpinBox(QWidget * parent = nullptr); @@ -49,6 +50,7 @@ public: bool isCalculationVisible() const { return calc_visible; } bool isCleared() const; int precision() const { return precision_; } + double singleStep() const { return m_singleStep; } void stepBy(int steps) override; void clear() override; @@ -61,6 +63,7 @@ public slots: void setClearButtonVisible(bool visible); void setCalculationVisible(bool visible); void setPrecision(int precision) { precision_ = precision; } + void setSingleStep(double step) { m_singleStep = step; } protected: QString text() const { return QAbstractSpinBox::text(); } @@ -99,8 +102,9 @@ private: QImage icon; QImage clear_im; QString dt; - bool cw_visible, calc_visible; - int precision_; + bool cw_visible = false, calc_visible = true; + int precision_ = -1; + double m_singleStep = 1.; }; #endif // EVALSPINBOX_H