# HG changeset patch # User Michiel Broek # Date 1656439936 -7200 # Node ID 04b93b656b60b3fc673959de7b7f91ed3bebf7ac # Parent 966b5de3182ede700a6f2bb46fffeabb20224641 Added LED plugin. diff -r 966b5de3182e -r 04b93b656b60 CMakeLists.txt --- a/CMakeLists.txt Tue Jun 28 15:33:52 2022 +0200 +++ b/CMakeLists.txt Tue Jun 28 20:12:16 2022 +0200 @@ -131,6 +131,13 @@ ${GEN_MOC_FILES2} ) + QT_WRAP_CPP( GEN_MOC_FILES3 ${SRCDIR}/LED.h designer/LEDPlugin.h) + add_library(bmsapp_LED SHARED + ${SRCDIR}/LED.cpp + designer/LEDPlugin.cpp + ${GEN_MOC_FILES3} + ) + ELSE() set( SRCS @@ -169,6 +176,7 @@ ${SRCDIR}/MonFermenters.cpp ${SRCDIR}/MonCO2meters.cpp ${SRCDIR}/MoniSpindels.cpp + ${SRCDIR}/DetailFermenter.cpp ${SRCDIR}/EditProduct.cpp ${SRCDIR}/ImportXML.cpp ${SRCDIR}/Setup.cpp @@ -180,6 +188,7 @@ ${SRCDIR}/database/db_recipe.cpp ${SRCDIR}/RangedSlider.cpp ${SRCDIR}/NullDateEdit.cpp + ${SRCDIR}/LED.cpp ${SRCDIR}/global.cpp ) @@ -218,6 +227,7 @@ ${SRCDIR}/MonFermenters.h ${SRCDIR}/MonCO2meters.h ${SRCDIR}/MoniSpindels.h + ${SRCDIR}/DetailFermenter.h ${SRCDIR}/EditProduct.h ${SRCDIR}/ImportXML.h ${SRCDIR}/Setup.h @@ -229,6 +239,7 @@ ${SRCDIR}/database/db_recipe.h ${SRCDIR}/RangedSlider.h ${SRCDIR}/NullDateEdit.h + ${SRCDIR}/LED.h ${SRCDIR}/global.h ) @@ -247,6 +258,7 @@ ${UIDIR}/EditProfileFerment.ui ${UIDIR}/EditRecipe.ui ${UIDIR}/EditProduct.ui + ${UIDIR}/DetailFermenter.ui ${UIDIR}/ImportXML.ui ${UIDIR}/MainWindow.ui ) @@ -298,7 +310,7 @@ IF( ${BUILD_DESIGNER_PLUGINS} ) - INSTALL(TARGETS bmsapp_rangeslider bmsapp_nulldate + INSTALL(TARGETS bmsapp_rangeslider bmsapp_nulldate bmsapp_LED DESTINATION "${LIBPATH}/plugins/designer" ) diff -r 966b5de3182e -r 04b93b656b60 designer/LEDPlugin.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/designer/LEDPlugin.cpp Tue Jun 28 20:12:16 2022 +0200 @@ -0,0 +1,78 @@ + +#include +#include +#include +#include +#include +#include + +#include "LEDPlugin.h" +#include "LED.h" + +LEDPlugin::LEDPlugin(QObject* parent) : + QObject(parent) +{ +} + +void LEDPlugin::initialize(QDesignerFormEditorInterface * /* core */) +{ + if(initialized) + return; + + initialized = true; + return; +} + +bool LEDPlugin::isInitialized() const +{ + return initialized; +} + +QString LEDPlugin::name() const +{ + return "LED"; +} + +QString LEDPlugin::group() const +{ + return "BMSapp Widgets"; +} + +QString LEDPlugin::toolTip() const +{ + return QString("An LED"); +} + +QString LEDPlugin::whatsThis() const +{ + return QString("An LED"); +} + +QString LEDPlugin::includeFile() const +{ + return "LED.h"; +} + +QString LEDPlugin::domXml() const +{ + return "\n" + " \n" + " \n" + "\n"; +} + +QIcon LEDPlugin::icon() const +{ + return QIcon(); +} + +bool LEDPlugin::isContainer() const +{ + return false; +} + +QWidget * LEDPlugin::createWidget(QWidget *parent) +{ + return new LED(parent); +} + diff -r 966b5de3182e -r 04b93b656b60 designer/LEDPlugin.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/designer/LEDPlugin.h Tue Jun 28 20:12:16 2022 +0200 @@ -0,0 +1,39 @@ +#ifndef _LED_PLUGIN_H_ +#define _LED_PLUGIN_H_ + +#include +#include +#include +#include +#include + +class LEDPlugin; + +class LEDPlugin : public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetCollectionInterface") + Q_INTERFACES(QDesignerCustomWidgetInterface) + +public: + LEDPlugin(QObject* parent=0); + + QString name() const; + QString group() const; + QString toolTip() const; + QString whatsThis() const; + QString includeFile() const; + QIcon icon() const; + QString domXml() const; + + bool isContainer() const; + bool isInitialized() const; + + QWidget *createWidget(QWidget *parent); + void initialize(QDesignerFormEditorInterface *core); + +private: + bool initialized = false; +}; + +#endif diff -r 966b5de3182e -r 04b93b656b60 src/LED.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/LED.cpp Tue Jun 28 20:12:16 2022 +0200 @@ -0,0 +1,207 @@ +#include + +#include +#include +#include +#include + +#include "LED.h" + +LED:: +LED(QWidget* parent) : + QWidget(parent), + diameter_(5), + color_(QColor("red")), + alignment_(Qt::AlignCenter), + initialState_(true), + state_(true), + flashRate_(200), + flashing_(false) +{ + timer_ = new QTimer(this); + connect(timer_, SIGNAL(timeout()), this, SLOT(toggleState())); + + setDiameter(diameter_); +} + +LED:: +~LED() +{ +} + + +double LED:: +diameter() const +{ + return diameter_; +} + +void LED:: +setDiameter(double diameter) +{ + diameter_ = diameter; + + pixX_ = round(double(height())/heightMM()); + pixY_ = round(double(width())/widthMM()); + + diamX_ = diameter_*pixX_; + diamY_ = diameter_*pixY_; + + update(); +} + + +QColor LED:: +color() const +{ + return color_; +} + +void LED:: +setColor(const QColor& color) +{ + color_ = color; + update(); +} + +Qt::Alignment LED:: +alignment() const +{ + return alignment_; +} + +void LED:: +setAlignment(Qt::Alignment alignment) +{ + alignment_ = alignment; + + update(); +} + +void LED:: +setFlashRate(int rate) +{ + flashRate_ = rate; + + update(); +} + +void LED:: +setFlashing(bool flashing) +{ + flashing_ = flashing; + + update(); +} + +void LED:: +startFlashing() +{ + setFlashing(true); +} + +void LED:: +stopFlashing() +{ + setFlashing(false); +} + + +void LED:: +setState(bool state) +{ + state_ = state; + update(); +} + +void LED:: +toggleState() +{ + state_ = !state_; + update(); +} + +int LED:: +heightForWidth(int width) const +{ + return width; +} + +QSize LED:: +sizeHint() const +{ + return QSize(diamX_, diamY_); +} + +QSize LED:: +minimumSizeHint() const +{ + return QSize(diamX_, diamY_); +} + +void LED:: +paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QPainter p(this); + + QRect geo = geometry(); + int width = geo.width(); + int height = geo.height(); + + int x=0, y=0; + if ( alignment_ & Qt::AlignLeft ) + x = 0; + else if ( alignment_ & Qt::AlignRight ) + x = width-diamX_; + else if ( alignment_ & Qt::AlignHCenter ) + x = (width-diamX_)/2; + else if ( alignment_ & Qt::AlignJustify ) + x = 0; + + if ( alignment_ & Qt::AlignTop ) + y = 0; + else if ( alignment_ & Qt::AlignBottom ) + y = height-diamY_; + else if ( alignment_ & Qt::AlignVCenter ) + y = (height-diamY_)/2; + + QRadialGradient g(x+diamX_/2, y+diamY_/2, diamX_*0.4, + diamX_*0.4, diamY_*0.4); + + g.setColorAt(0, Qt::white); + if ( state_ ) + g.setColorAt(1, color_); + else + g.setColorAt(1, Qt::black); + QBrush brush(g); + + p.setPen(color_); + p.setRenderHint(QPainter::Antialiasing, true); + p.setBrush(brush); + p.drawEllipse(x, y, diamX_-1, diamY_-1); + + if ( flashRate_ > 0 && flashing_ ) + timer_->start(flashRate_); + else + timer_->stop(); +} + +bool LED:: +state() const +{ + return state_; +} + +bool LED:: +isFlashing() const +{ + return flashing_; +} + +int LED:: +flashRate() const +{ + return flashRate_; +} diff -r 966b5de3182e -r 04b93b656b60 src/LED.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/LED.h Tue Jun 28 20:12:16 2022 +0200 @@ -0,0 +1,78 @@ +#ifndef _LED_H_ +#define _LED_H_ + +#include +#include + +class QTimer; + +class QDESIGNER_WIDGET_EXPORT LED : public QWidget +{ + Q_OBJECT + + Q_PROPERTY(double diameter READ diameter WRITE setDiameter) // mm + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) + Q_PROPERTY(bool state READ state WRITE setState) + Q_PROPERTY(bool flashing READ isFlashing WRITE setFlashing) + Q_PROPERTY(int flashRate READ flashRate WRITE setFlashRate) + +public: + explicit LED(QWidget* parent=0); + ~LED(); + + double diameter() const; + void setDiameter(double diameter); + + QColor color() const; + void setColor(const QColor& color); + + Qt::Alignment alignment() const; + void setAlignment(Qt::Alignment alignment); + + bool state() const; + + bool isFlashing() const; + + int flashRate() const; + +public slots: + void setState(bool state); + void toggleState(); + void setFlashing(bool flashing); + void setFlashRate(int rate); + void startFlashing(); + void stopFlashing(); + +public: + int heightForWidth(int width) const; + QSize sizeHint() const; + QSize minimumSizeHint() const; + +protected: + void paintEvent(QPaintEvent* event); + +private: + double diameter_; + QColor color_; + Qt::Alignment alignment_; + bool initialState_; + bool state_; + int flashRate_; + bool flashing_; + + // + // Pixels per mm for x and y... + // + int pixX_, pixY_; + + // + // Scaled values for x and y diameter. + // + int diamX_, diamY_; + + QRadialGradient gradient_; + QTimer* timer_; +}; + +#endif diff -r 966b5de3182e -r 04b93b656b60 ui/AboutDialog.ui --- a/ui/AboutDialog.ui Tue Jun 28 15:33:52 2022 +0200 +++ b/ui/AboutDialog.ui Tue Jun 28 20:12:16 2022 +0200 @@ -54,7 +54,13 @@ Icons: Silk Author: Mark James Source: http://www.famfamfam.com/lab/icons/silk/ -License: Creative Commons Attribution 2.5 License +License: Creative Commons Attribution 2.5 License + +Plugins: LED +Author: Mark Wilson +Source: https://www.ics.com/sites/default/files/code/led-designer-plugin.zip +License: Unknown +