git-svn-id: svn://db.shs.com.ru/libs@646 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2019-12-03 22:33:11 +00:00
parent 2d2552ff63
commit f510e8e957
10 changed files with 364 additions and 8 deletions

BIN
qad/icons/scroll_spin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -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_();

View File

@@ -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();

View File

@@ -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));
}

View File

@@ -0,0 +1,69 @@
#include "scroll_spin_box.h"
#include "scroll_spin_boxplugin.h"
#include <QtCore/QtPlugin>
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("<widget class=\"ScrollSpinBox\" name=\"spin\">\n</widget>\n");
}
QString ScrollSpinBoxPlugin::includeFile() const {
return QLatin1String("scroll_spin_box.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef SCROLLSPINBOXPLUGIN_H
#define SCROLLSPINBOXPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#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

View File

@@ -42,5 +42,6 @@
<file>../icons/dialog-warning.png</file>
<file>../icons/tools-wizard.png</file>
<file>../icons/evalspinbox.png</file>
<file>../icons/scroll_spin.png</file>
</qresource>
</RCC>

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "scroll_spin_box.h"
#include "ui_scroll_spin_box.h"
#include <evalspinbox.h>
#include <qad_types.h>
#include <QStyleOptionSpinBox>
#include <QApplication>
#include <QMouseEvent>
#include <QStyle>
#include <QDebug>
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<int>(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);
}
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef SCROLL_SPIN_BOX_H
#define SCROLL_SPIN_BOX_H
#include <QWidget>
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

View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScrollSpinBox</class>
<widget class="QWidget" name="ScrollSpinBox">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>292</width>
<height>40</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="EvalSpinBox" name="spin">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="handle" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="cursor">
<cursorShape>SplitVCursor</cursorShape>
</property>
<property name="toolTip">
<string>Grab and scroll</string>
</property>
<property name="styleSheet">
<string notr="true">image: url(:/icons/scroll_spin.png);</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>EvalSpinBox</class>
<extends>QWidget</extends>
<header>evalspinbox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
<slots>
<slot>mapChanged()</slot>
</slots>
</ui>