diff --git a/qad/icons/scroll_spin.png b/qad/icons/scroll_spin.png new file mode 100644 index 0000000..d732fbf Binary files /dev/null and b/qad/icons/scroll_spin.png differ diff --git a/qad/widgets/evalspinbox.cpp b/qad/widgets/evalspinbox.cpp index 6bf2c8d..1c0d76a 100644 --- a/qad/widgets/evalspinbox.cpp +++ b/qad/widgets/evalspinbox.cpp @@ -14,6 +14,7 @@ EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) { status = new QWidget(lineEdit()); cw = new QWidget(lineEdit()); label = new QLabel(lineEdit()); + precision_ = -1; // label->hide(); clear_im.load(":/icons/edit-clear-locationbar-rtl.png"); icon_ok.load(":/icons/dialog-ok-apply.png"); @@ -155,7 +156,7 @@ void EvalSpinBox::setExpression_() { /*if (eval.expression() == "0") lineEdit()->clear(); else*/ lineEdit()->setText(eval.expression()); eval.evaluate(); - if (td) lineEdit()->setText(QString::number(value(), 'G', 10)); + if (td) lineEdit()->setText(QString::number(value(), 'G', precision_ > 0 ? precision_ : 16)); status->setToolTip("OK -> " + QString::number(value(), 'G', 10)); icon = icon_ok; } else { @@ -199,7 +200,7 @@ void EvalSpinBox::setExpression(const QString & expr) { void EvalSpinBox::setValue(double val) { - lineEdit()->setText(QString::number(val, 'G', 16)); + lineEdit()->setText(QString::number(val, 'G', precision_ > 0 ? precision_ : 16)); //if (val == 0) lineEdit()->clear(); cw->setVisible(text() != dt && cw_visible); setExpression_(); diff --git a/qad/widgets/evalspinbox.h b/qad/widgets/evalspinbox.h index 43ad094..eedc03b 100644 --- a/qad/widgets/evalspinbox.h +++ b/qad/widgets/evalspinbox.h @@ -14,6 +14,7 @@ class EvalSpinBox: public QAbstractSpinBox Q_PROPERTY(QString expression READ expression WRITE setExpression USER true) Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText) Q_PROPERTY(bool clearButtonVisible READ isClearButtonVisible WRITE setClearButtonVisible) + Q_PROPERTY(int precision READ precision WRITE setPrecision) public: explicit EvalSpinBox(QWidget * parent = 0); @@ -24,17 +25,12 @@ public: const QString & defaultText() const {return dt;} bool isClearButtonVisible() const {return cw_visible;} bool isCleared() const; + int precision() const {return precision_;} virtual void stepBy(int steps); virtual void clear(); virtual QSize sizeHint() const; -public slots: - void setExpression(const QString & expr); - void setValue(double val); - void setDefaultText(const QString & t); - void setClearButtonVisible(bool visible); - protected: QString text() const {return QAbstractSpinBox::text();} @@ -56,6 +52,7 @@ protected: QImage clear_im; QString dt; bool cw_visible; + int precision_; private: bool eventFilter(QObject * o, QEvent * e); @@ -70,6 +67,13 @@ private slots: void setExpression_(); void resizeIcons(); +public slots: + void setExpression(const QString & expr); + void setValue(double val); + void setDefaultText(const QString & t); + void setClearButtonVisible(bool visible); + void setPrecision(int precision) {precision_ = precision;} + signals: void valueChanged(double val); void cleared(); diff --git a/qad/widgets/plugin/qad_widgets.cpp b/qad/widgets/plugin/qad_widgets.cpp index 257bd37..23a0812 100644 --- a/qad/widgets/plugin/qad_widgets.cpp +++ b/qad/widgets/plugin/qad_widgets.cpp @@ -15,6 +15,7 @@ #include "qpiconfigplugin.h" #include "evalspinboxplugin.h" #include "imageviewplugin.h" +#include "scroll_spin_boxplugin.h" QADWidgets::QADWidgets(QObject * parent): QObject(parent) { @@ -34,6 +35,7 @@ QADWidgets::QADWidgets(QObject * parent): QObject(parent) { m_widgets.append(new QPIConfigPlugin(this)); m_widgets.append(new EvalSpinBoxPlugin(this)); m_widgets.append(new ImageViewPlugin(this)); + m_widgets.append(new ScrollSpinBoxPlugin(this)); } diff --git a/qad/widgets/plugin/scroll_spin_boxplugin.cpp b/qad/widgets/plugin/scroll_spin_boxplugin.cpp new file mode 100644 index 0000000..e7c0cd8 --- /dev/null +++ b/qad/widgets/plugin/scroll_spin_boxplugin.cpp @@ -0,0 +1,69 @@ +#include "scroll_spin_box.h" +#include "scroll_spin_boxplugin.h" +#include + + +ScrollSpinBoxPlugin::ScrollSpinBoxPlugin(QObject * parent): QObject(parent) { + m_initialized = false; +} + + +void ScrollSpinBoxPlugin::initialize(QDesignerFormEditorInterface * /* core */) { + if (m_initialized) + return; + + // Add extension registrations, etc. here + + m_initialized = true; +} + + +bool ScrollSpinBoxPlugin::isInitialized() const { + return m_initialized; +} + + +QWidget * ScrollSpinBoxPlugin::createWidget(QWidget * parent) { + return new ScrollSpinBox(parent); +} + + +QString ScrollSpinBoxPlugin::name() const { + return QLatin1String("ScrollSpinBox"); +} + + +QString ScrollSpinBoxPlugin::group() const { + return QLatin1String("Input Widgets"); +} + + +QIcon ScrollSpinBoxPlugin::icon() const { + return QIcon(); +} + + +QString ScrollSpinBoxPlugin::toolTip() const { + return QLatin1String("SpinBox with scroll"); +} + + +QString ScrollSpinBoxPlugin::whatsThis() const { + return QLatin1String("SpinBox with scroll"); +} + + +bool ScrollSpinBoxPlugin::isContainer() const { + return false; +} + + +QString ScrollSpinBoxPlugin::domXml() const { + return QLatin1String("\n\n"); +} + + +QString ScrollSpinBoxPlugin::includeFile() const { + return QLatin1String("scroll_spin_box.h"); +} + diff --git a/qad/widgets/plugin/scroll_spin_boxplugin.h b/qad/widgets/plugin/scroll_spin_boxplugin.h new file mode 100644 index 0000000..3c92283 --- /dev/null +++ b/qad/widgets/plugin/scroll_spin_boxplugin.h @@ -0,0 +1,36 @@ +#ifndef SCROLLSPINBOXPLUGIN_H +#define SCROLLSPINBOXPLUGIN_H + +#include +#if QT_VERSION >= 0x050000 +# include +#else +# include +#endif + +class ScrollSpinBoxPlugin: public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES(QDesignerCustomWidgetInterface) + +public: + ScrollSpinBoxPlugin(QObject * parent = 0); + + bool isContainer() const; + bool isInitialized() const; + QIcon icon() const; + QString domXml() const; + QString group() const; + QString includeFile() const; + QString name() const; + QString toolTip() const; + QString whatsThis() const; + QWidget * createWidget(QWidget * parent); + void initialize(QDesignerFormEditorInterface * core); + +private: + bool m_initialized; + +}; + +#endif // SCROLLSPINBOXPLUGIN_H diff --git a/qad/widgets/qad_widgets.qrc b/qad/widgets/qad_widgets.qrc index bc585b9..5b064ed 100644 --- a/qad/widgets/qad_widgets.qrc +++ b/qad/widgets/qad_widgets.qrc @@ -42,5 +42,6 @@ ../icons/dialog-warning.png ../icons/tools-wizard.png ../icons/evalspinbox.png + ../icons/scroll_spin.png diff --git a/qad/widgets/scroll_spin_box.cpp b/qad/widgets/scroll_spin_box.cpp new file mode 100644 index 0000000..ca5e87f --- /dev/null +++ b/qad/widgets/scroll_spin_box.cpp @@ -0,0 +1,113 @@ +/* + QGLView + Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this programap-> If not, see . +*/ + +#include "scroll_spin_box.h" +#include "ui_scroll_spin_box.h" +#include +#include +#include +#include +#include +#include +#include + + +ScrollSpinBox::ScrollSpinBox(QWidget * parent): QWidget(parent) { + ui = new Ui::ScrollSpinBox(); + ui->setupUi(this); + ui->spin->setPrecision(3); + ui->handle->installEventFilter(this); + last_value = 0.; + sensivity_ = 0.2; + scroll_scale = sensivity_ / 10; + canceled = false; +} + + +EvalSpinBox * ScrollSpinBox::spin() { + return ui->spin; +} + + +void ScrollSpinBox::changeEvent(QEvent * e) { + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + + +void ScrollSpinBox::resizeEvent(QResizeEvent * e) { + QStyleOptionSpinBox so; + so.initFrom(ui->spin); + QRect r = qApp->style()->subControlRect(QStyle::CC_SpinBox, &so, QStyle::SC_SpinBoxUp); + ui->handle->setFixedWidth(qMax(ui->handle->height() / 3, r.width())); + scroll_scale = sensivity_ / appScale(this) / 10; +} + + +bool ScrollSpinBox::eventFilter(QObject * o, QEvent * e) { + switch (e->type()) { + case QEvent::MouseButtonPress: + mousePress((QMouseEvent*)e); + return true; + case QEvent::MouseButtonRelease: + mouseRelease((QMouseEvent*)e); + return true; + case QEvent::MouseMove: + mouseMove((QMouseEvent*)e); + return true; + default: break; + } + return QWidget::eventFilter(o, e); +} + + +void ScrollSpinBox::mousePress(QMouseEvent * e) { + if (canceled) return; + if (e->button() == Qt::RightButton) { + canceled = true; + ui->spin->setExpression(last_text); + } + if (e->button() == Qt::LeftButton) { + down_pos = e->pos(); + last_text = ui->spin->expression(); + last_value = ui->spin->value(); + } +} + + +void ScrollSpinBox::mouseRelease(QMouseEvent * e) { + if (e->buttons() == Qt::NoButton) canceled = false; +} + + +void ScrollSpinBox::mouseMove(QMouseEvent * e) { + if (canceled) return; + if (e->buttons().testFlag(Qt::LeftButton)) { + 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); + } + } +} diff --git a/qad/widgets/scroll_spin_box.h b/qad/widgets/scroll_spin_box.h new file mode 100644 index 0000000..b87fa89 --- /dev/null +++ b/qad/widgets/scroll_spin_box.h @@ -0,0 +1,58 @@ +/* + QGLView + Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef SCROLL_SPIN_BOX_H +#define SCROLL_SPIN_BOX_H + +#include + +namespace Ui { + class ScrollSpinBox; +} +class EvalSpinBox; + +class ScrollSpinBox: public QWidget +{ + Q_OBJECT + Q_PROPERTY(double sensivity READ sensivity WRITE setSensivity) +public: + explicit ScrollSpinBox(QWidget * parent = 0); + + EvalSpinBox * spin(); + double sensivity() const {return sensivity_;} + +protected: + void changeEvent(QEvent * e); + void resizeEvent(QResizeEvent * e); + bool eventFilter(QObject * o, QEvent * e); + void mousePress(QMouseEvent * e); + void mouseRelease(QMouseEvent * e); + void mouseMove(QMouseEvent * e); + + Ui::ScrollSpinBox * ui; + QPoint down_pos; + QString last_text; + double last_value, scroll_scale, sensivity_; + bool canceled; + +public slots: + void setSensivity(double s) {sensivity_ = s;} + +}; + +#endif // SCROLL_SPIN_BOX_H diff --git a/qad/widgets/scroll_spin_box.ui b/qad/widgets/scroll_spin_box.ui new file mode 100644 index 0000000..c398780 --- /dev/null +++ b/qad/widgets/scroll_spin_box.ui @@ -0,0 +1,72 @@ + + + ScrollSpinBox + + + + 0 + 0 + 292 + 40 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + SplitVCursor + + + Grab and scroll + + + image: url(:/icons/scroll_spin.png); + + + + + + + + EvalSpinBox + QWidget +
evalspinbox.h
+
+
+ + + + mapChanged() + +