From f8634df8c77782d446984ebbd082610cf92242bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Wed, 4 Dec 2019 10:40:06 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@648 a8b55f48-bf90-11e4-a774-851b48703e85 --- qad/widgets/scroll_spin_box.cpp | 16 ++++++++++++++-- qad/widgets/scroll_spin_box.h | 6 ++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/qad/widgets/scroll_spin_box.cpp b/qad/widgets/scroll_spin_box.cpp index ca5e87f..e1ff155 100644 --- a/qad/widgets/scroll_spin_box.cpp +++ b/qad/widgets/scroll_spin_box.cpp @@ -32,6 +32,7 @@ ScrollSpinBox::ScrollSpinBox(QWidget * parent): QWidget(parent) { ui->setupUi(this); ui->spin->setPrecision(3); ui->handle->installEventFilter(this); + connect(ui->spin, SIGNAL(valueChanged(double)), this, SIGNAL(valueChanged(double))); last_value = 0.; sensivity_ = 0.2; scroll_scale = sensivity_ / 10; @@ -44,6 +45,11 @@ EvalSpinBox * ScrollSpinBox::spin() { } +double ScrollSpinBox::value() const { + return ui->spin->value(); +} + + void ScrollSpinBox::changeEvent(QEvent * e) { QWidget::changeEvent(e); switch (e->type()) { @@ -91,7 +97,8 @@ void ScrollSpinBox::mousePress(QMouseEvent * e) { if (e->button() == Qt::LeftButton) { down_pos = e->pos(); last_text = ui->spin->expression(); - last_value = ui->spin->value(); + last_value = qAbs(ui->spin->value()); + if (last_value == 0.) last_value = 1.; } } @@ -107,7 +114,12 @@ void ScrollSpinBox::mouseMove(QMouseEvent * e) { double dv = (down_pos.y() - e->pos().y()) * scroll_scale; if (dv != 0.) { QCursor::setPos(ui->handle->mapToGlobal(down_pos)); - ui->spin->setValue(ui->spin->value() + qAbs(last_value) * dv); + ui->spin->setValue(ui->spin->value() + last_value * dv); } } } + + +void ScrollSpinBox::setValue(double v) { + ui->spin->setValue(v); +} diff --git a/qad/widgets/scroll_spin_box.h b/qad/widgets/scroll_spin_box.h index b87fa89..16f010c 100644 --- a/qad/widgets/scroll_spin_box.h +++ b/qad/widgets/scroll_spin_box.h @@ -30,10 +30,12 @@ class ScrollSpinBox: public QWidget { Q_OBJECT Q_PROPERTY(double sensivity READ sensivity WRITE setSensivity) + Q_PROPERTY(double value READ value WRITE setValue) public: explicit ScrollSpinBox(QWidget * parent = 0); EvalSpinBox * spin(); + double value() const; double sensivity() const {return sensivity_;} protected: @@ -52,6 +54,10 @@ protected: public slots: void setSensivity(double s) {sensivity_ = s;} + void setValue(double v); + +signals: + void valueChanged(double); };