Compare commits

...

3 Commits

Author SHA1 Message Date
44839c740d CircleIndicator icon 2024-05-02 12:10:09 +03:00
144d24711c add CircleIndicator 2024-04-30 15:23:48 +03:00
9966f2d5e4 version 2.28.0
piqt conversion PI2QMathMatrixT(), Q2PIMathMatrixT() and many Q2PIMathVectorT()
2024-04-26 15:37:57 +03:00
9 changed files with 441 additions and 19 deletions

View File

@@ -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 27)
set(QAD_MINOR 28)
set(QAD_REVISION 0)
set(QAD_SUFFIX )
set(QAD_COMPANY SHS)

BIN
icons/circle-indicator.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@@ -27,8 +27,11 @@
#include <QColor>
#include <QDateTime>
#include <QGenericMatrix>
#include <QImage>
#include <QMatrix4x4>
#include <QPolygonF>
#include <QVector2D>
#include <QVector3D>
#if QT_VERSION_MAJOR == 5
# if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
@@ -105,6 +108,60 @@ inline PIMathVectorT3d Q2PIVector3(const QVector3D & v) {
return PIMathVectorT3d({double(v.x()), double(v.y()), double(v.z())});
}
template<uint Rows, uint Cols = Rows, typename Type = double>
inline QGenericMatrix<Cols, Rows, Type> PI2QMathMatrixT(const PIMathMatrixT<Rows, Cols, Type> & v) {
QGenericMatrix<Cols, Rows, Type> ret;
for (int r = 0; r < Rows; ++r)
for (int c = 0; c < Cols; ++c)
ret(r, c) = v[r][c];
return ret;
}
template<int Rows, int Cols = Rows, typename Type = double>
inline PIMathMatrixT<Rows, Cols, Type> Q2PIMathMatrixT(const QGenericMatrix<Cols, Rows, Type> & v) {
PIMathMatrixT<Rows, Cols, Type> ret;
for (int r = 0; r < Rows; ++r)
for (int c = 0; c < Cols; ++c)
ret[r][c] = v(r, c);
return ret;
}
inline PIMathMatrixT<4, 4, float> Q2PIMathMatrixT(const QMatrix4x4 & v) {
PIMathMatrixT<4, 4, float> ret;
for (int r = 0; r < 4; ++r)
for (int c = 0; c < 4; ++c)
ret[r][c] = v(r, c);
return ret;
}
inline PIMathVectorT2d Q2PIMathVectorT(const QVector2D & v) {
return PIMathVectorT2d({v[0], v[1]});
}
inline PIMathVectorT2d Q2PIMathVectorT(const QPointF & v) {
return PIMathVectorT2d({v.x(), v.y()});
}
inline PIMathVectorT3d Q2PIMathVectorT(const QVector3D & v) {
return PIMathVectorT3d({v[0], v[1], v[2]});
}
inline PIMathVectorT4d Q2PIMathVectorT(const QVector4D & v) {
return PIMathVectorT4d({v[0], v[1], v[2], v[3]});
}
template<int Size, typename Type = double>
inline PIMathVectorT<Size, double> Q2PIMathVectorT(const QGenericMatrix<1, Size, Type> & v) {
PIMathVectorT<Size, double> ret;
for (int i = 0; i < Size; ++i)
ret[i] = v(i, 0);
return ret;
}
template<int Size, typename Type = double>
inline PIMathVectorT<Size, double> Q2PIMathVectorT(const QGenericMatrix<Size, 1, Type> & v) {
PIMathVectorT<Size, double> ret;
for (int i = 0; i < Size; ++i)
ret[i] = v(0, i);
return ret;
}
inline QPointF PI2QPoint(const PIPointd & v) {
return QPointF(v.x, v.y);
}

View File

@@ -0,0 +1,174 @@
#include "circleindicator.h"
#include "qad_types.h"
#include <QApplication>
#include <QBoxLayout>
#include <QLayout>
#include <QPainter>
#include <QPainterPath>
#include <QStyleOption>
#include <qmath.h>
template<typename T>
inline T qClamp(T v, T min, T max) {
return qMin<T>(max, qMax<T>(min, v));
}
CircleIndicator::CircleIndicator(QWidget * parent): QWidget(parent) {
init();
}
CircleIndicator::~CircleIndicator() {}
int CircleIndicator::heightForWidth(int) const {
return width();
}
bool CircleIndicator::hasHeightForWidth() const {
return false;
}
void CircleIndicator::init() {
connect(&anim, &QVariantAnimation::valueChanged, this, [this](QVariant v) {
m_value_visual = v.toDouble();
update();
});
anim.setDuration(200);
anim.setEasingCurve(QEasingCurve::OutQuad);
fill_color = QColor(255, 245, 60);
back_color = QColor(216, 216, 216);
border_color = Qt::darkGray;
}
QSize CircleIndicator::minimumSizeHint() const {
return QSize(40, 40) * appScale();
}
QSize CircleIndicator::sizeHint() const {
return QSize(120, 120) * appScale();
}
void CircleIndicator::paintEvent(QPaintEvent *) {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setRenderHint(QPainter::SmoothPixmapTransform);
float w = width(), h = height(), r = qMin<float>(w, h) / 2.f, thick = qMax<double>(1., r / 80.);
r -= thick;
float thin = qMax<double>(1., thick / 3.), lr = r * bar_ / 100.;
p.translate(w / 2.f, h / 2.f);
p.save();
p.rotate(m_angle_offset + 90.);
QRectF rct(-r, -r, r + r, r + r);
double range = maximum() - minimum();
double nv = qClamp<double>((m_value_visual - minimum()) / qMax(range, 1.E-3), 0., 1.) * 100.;
QPainterPath path, path2;
QPointF tp;
path.arcMoveTo(rct, angle_gap);
tp = path.currentPosition();
path.arcTo(rct, angle_gap, 360 - angle_gap - angle_gap);
rct.adjust(lr, lr, -lr, -lr);
path2.arcMoveTo(rct, -angle_gap);
path2.arcTo(rct, -angle_gap, -360 + angle_gap + angle_gap);
path2.lineTo(tp);
path.connectPath(path2);
p.setPen(QPen(border_color, thick));
QConicalGradient grad;
double v = qClamp((1. - nv / (100. - thin / 3.6)) * ((360. - angle_gap - angle_gap) / 360.) + (angle_gap / 360.), 0., 1.);
grad.setColorAt(1., fill_color);
grad.setColorAt(qClamp(v + thin / 360., 0., 1.), fill_color);
grad.setColorAt(v, back_color);
grad.setColorAt(0., back_color);
p.setBrush(grad);
p.drawPath(path);
float hs = (r - lr) / 1.2;
QRect ir(-hs, -hs, hs + hs, hs + hs);
p.restore();
if (m_text.isEmpty()) return;
p.setPen(palette().text().color());
auto tbr = p.boundingRect({}, m_text);
if (tbr.isEmpty()) return;
double tscl = qMin(ir.width() / tbr.width(), ir.height() / tbr.height());
p.scale(tscl, tscl);
p.drawText(ir, Qt::AlignCenter, m_text);
}
void CircleIndicator::animate() {
anim.stop();
anim.setStartValue(m_value_visual);
anim.setEndValue(m_value);
anim.start();
}
void CircleIndicator::setValue(double v) {
if (m_value == v) return;
m_value = qClamp(v, minimum(), maximum());
animate();
}
void CircleIndicator::setMinimum(double ll) {
m_minimum = ll;
setValue(qClamp(value(), minimum(), maximum()));
update();
}
void CircleIndicator::setMaximum(double hl) {
m_maximum = hl;
setValue(qClamp(value(), minimum(), maximum()));
update();
}
void CircleIndicator::setFillColor(const QColor & c) {
fill_color = c;
update();
}
void CircleIndicator::setBorderColor(const QColor & c) {
border_color = c;
update();
}
void CircleIndicator::setText(const QString & t) {
m_text = t;
update();
}
void CircleIndicator::setBackColor(const QColor & c) {
back_color = c;
update();
}
void CircleIndicator::setAngleGap(double a) {
angle_gap = qClamp<double>(a, 0., 180.);
update();
}
void CircleIndicator::setBarSize(double a) {
bar_ = qClamp<double>(a, 0., 100.);
update();
}
void CircleIndicator::setAngleStartOffset(double a) {
m_angle_offset = a;
update();
}

View File

@@ -0,0 +1,80 @@
#ifndef circleindicator_H
#define circleindicator_H
#include "qad_widgets_export.h"
#include <QDebug>
#include <QTime>
#include <QVariantAnimation>
#include <QWidget>
class QAD_WIDGETS_EXPORT CircleIndicator: public QWidget {
Q_OBJECT
Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor)
Q_PROPERTY(QColor backColor READ backColor WRITE setBackColor)
Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(double angleStartOffset READ angleStartOffset WRITE setAngleStartOffset)
Q_PROPERTY(double angleGap READ angleGap WRITE setAngleGap)
Q_PROPERTY(double barSize READ barSize WRITE setBarSize)
Q_PROPERTY(double value READ value WRITE setValue)
Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
public:
explicit CircleIndicator(QWidget * parent = 0);
~CircleIndicator();
double value() const { return m_value; }
double minimum() const { return m_minimum; }
double maximum() const { return m_maximum; }
QColor backColor() const { return back_color; }
void setBackColor(const QColor & c);
QColor fillColor() const { return fill_color; }
void setFillColor(const QColor & c);
QColor borderColor() const { return border_color; }
void setBorderColor(const QColor & c);
QString text() const { return m_text; }
void setText(const QString & t);
double angleStartOffset() const { return m_angle_offset; }
void setAngleStartOffset(double a);
double angleGap() const { return angle_gap; }
void setAngleGap(double a);
double barSize() const { return bar_; }
void setBarSize(double a);
int heightForWidth(int) const;
bool hasHeightForWidth() const;
private:
void init();
QSize minimumSizeHint() const;
QSize sizeHint() const;
void paintEvent(QPaintEvent *);
void animate();
QColor fill_color, back_color, border_color;
QString m_text;
QVariantAnimation anim;
double m_value = 0., m_value_visual = 0., m_minimum = 0., m_maximum = 100.;
double m_angle_offset = 0., angle_gap = 20., bar_ = 30.;
public slots:
void enable() { setEnabled(true); }
void disable() { setEnabled(false); }
void setValue(double v);
void setMinimum(double m);
void setMaximum(double m);
};
#endif

View File

@@ -0,0 +1,69 @@
#include "circleindicatorplugin.h"
#include "circleindicator.h"
#include <QtCore/QtPlugin>
CircleIndicatorPlugin::CircleIndicatorPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void CircleIndicatorPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized) return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool CircleIndicatorPlugin::isInitialized() const {
return m_initialized;
}
QWidget * CircleIndicatorPlugin::createWidget(QWidget * parent) {
return new CircleIndicator(parent);
}
QString CircleIndicatorPlugin::name() const {
return QLatin1String("CircleIndicator");
}
QString CircleIndicatorPlugin::group() const {
return QLatin1String("Display Widgets");
}
QIcon CircleIndicatorPlugin::icon() const {
return QIcon(/*":/icons/circle-indicator.png"*/);
}
QString CircleIndicatorPlugin::toolTip() const {
return QLatin1String("Circle indicator with text");
}
QString CircleIndicatorPlugin::whatsThis() const {
return QLatin1String("Circle indicator with text");
}
bool CircleIndicatorPlugin::isContainer() const {
return false;
}
QString CircleIndicatorPlugin::domXml() const {
return QLatin1String("<widget class=\"CircleIndicator\" name=\"circleIndicator\">\n</widget>\n");
}
QString CircleIndicatorPlugin::includeFile() const {
return QLatin1String("circleindicator.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef circleindicatorplugin_H
#define circleindicatorplugin_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class CircleIndicatorPlugin
: public QObject
, public QDesignerCustomWidgetInterface {
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
CircleIndicatorPlugin(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

View File

@@ -1,5 +1,6 @@
#include "qad_widgets.h"
#include "circleindicatorplugin.h"
#include "clineeditplugin.h"
#include "colorbuttonplugin.h"
#include "ecomboboxplugin.h"
@@ -21,24 +22,28 @@
QADWidgets::QADWidgets(QObject * parent): QObject(parent) {
m_widgets.append(new SpinSliderPlugin(this));
m_widgets.append(new ColorButtonPlugin(this));
m_widgets.append(new ShortcutsPlugin(this));
m_widgets.append(new CLineEditPlugin(this));
m_widgets.append(new QIPEditPlugin(this));
m_widgets.append(new QPointEditPlugin(this));
m_widgets.append(new QRectEditPlugin(this));
m_widgets.append(new EComboBoxPlugin(this));
m_widgets.append(new QPIConsolePlugin(this));
m_widgets.append(new IconedLabelPlugin(this));
m_widgets.append(new QCodeEditPlugin(this));
m_widgets.append(new QVariantEditPlugin(this));
m_widgets.append(new QPIConfigPlugin(this));
m_widgets.append(new EvalSpinBoxPlugin(this));
m_widgets.append(new ImageViewPlugin(this));
m_widgets.append(new ScrollSpinBoxPlugin(this));
m_widgets.append(new RangeSliderPlugin(this));
m_widgets.append(new StateIconPlugin(this));
// clang-format off
m_widgets
<< new SpinSliderPlugin(this)
<< new ColorButtonPlugin(this)
<< new ShortcutsPlugin(this)
<< new CLineEditPlugin(this)
<< new QIPEditPlugin(this)
<< new QPointEditPlugin(this)
<< new QRectEditPlugin(this)
<< new EComboBoxPlugin(this)
<< new QPIConsolePlugin(this)
<< new IconedLabelPlugin(this)
<< new QCodeEditPlugin(this)
<< new QVariantEditPlugin(this)
<< new QPIConfigPlugin(this)
<< new EvalSpinBoxPlugin(this)
<< new ImageViewPlugin(this)
<< new ScrollSpinBoxPlugin(this)
<< new RangeSliderPlugin(this)
<< new StateIconPlugin(this)
<< new CircleIndicatorPlugin(this);
// clang-format on
}

View File

@@ -41,5 +41,6 @@
<file>../../icons/f1.png</file>
<file>../../icons/scroll_spin.png</file>
<file>../../icons/led_on.png</file>
<file>../../icons/circle-indicator.png</file>
</qresource>
</RCC>