QtCreator Widget Plugin custom class
Unsolved
General and Desktop
-
#ifndef _WLED_H_ #define _WLED_H_ #include <QtDesigner/QtDesigner> #include <QWidget> class QTimer; class QDESIGNER_WIDGET_EXPORT WLED : 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(bool mirror READ isMirror WRITE setMirror) Q_PROPERTY(int flashRate READ flashRate WRITE setFlashRate) public: explicit WLED(QWidget* parent=0); ~WLED(); 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; bool isMirror() const; int flashRate() const; public slots: void setState(bool state); void toggleState(); void setFlashing(bool flashing); void setMirror(bool mirror); void setFlashRate(int rate); void startFlashing(); void stopFlashing(); public: int heightForWidth(int width) const; QSize sizeHint() const; QSize minimumSizeHint() const; public: signals: void setStateSig(bool state); void setNOTStateSig(bool state); protected: void paintEvent(QPaintEvent* event); private: double diameter_; QColor color_; Qt::Alignment alignment_; bool initialState_; bool state_; int flashRate_; bool flashing_; bool mirror_; // // 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
then cpp file .....
#include <math.h> #include <QPainter> #include <QGradient> #include <QPaintDevice> #include <QTimer> #include "WLED.h" WLED:: WLED(QWidget* parent) : QWidget(parent), diameter_(5), color_(QColor("red")), alignment_(Qt::AlignCenter), initialState_(true), state_(true), flashRate_(200), flashing_(false), mirror_(false) { timer_ = new QTimer(this); connect(timer_, SIGNAL(timeout()), this, SLOT(toggleState())); setDiameter(diameter_); } WLED:: ~WLED() { } double WLED:: diameter() const { return diameter_; } void WLED:: setDiameter(double diameter) { diameter_ = diameter; pixX_ = round(double(height())/heightMM()); pixY_ = round(double(width())/widthMM()); diamX_ = diameter_*pixX_; diamY_ = diameter_*pixY_; update(); } QColor WLED:: color() const { return color_; } void WLED:: setColor(const QColor& color) { color_ = color; update(); } Qt::Alignment WLED:: alignment() const { return alignment_; } void WLED:: setAlignment(Qt::Alignment alignment) { alignment_ = alignment; update(); } void WLED:: setFlashRate(int rate) { flashRate_ = rate; //emit setFlashRateSig(rate); update(); } void WLED:: setMirror(bool mirror) { mirror_ = mirror; update(); } void WLED:: setFlashing(bool flashing) { flashing_ = flashing; update(); } void WLED:: startFlashing() { setFlashing(true); } void WLED:: stopFlashing() { setFlashing(false); } void WLED:: setState(bool state) { state_ = state; emit setStateSig(state_); emit setNOTStateSig(!state_); if(mirror_){setFlashing(state_);} update(); } void WLED:: toggleState() { state_ = !state_; update(); } int WLED:: heightForWidth(int width) const { return width; } QSize WLED:: sizeHint() const { return QSize(diamX_, diamY_); } QSize WLED:: minimumSizeHint() const { return QSize(diamX_, diamY_); } void WLED:: 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 WLED:: state() const { return state_; } bool WLED:: isMirror() const { return mirror_; } bool WLED:: isFlashing() const { return flashing_; } int WLED:: flashRate() const { return flashRate_; }
I would like the "mirror" led to sometimes flash instead of "fixed" like the led from which it derives. The "parent" leds are in fact always on / off and never fixed ..... I would like to make everything stay on this plugin, but QtCretor keeps returning the error: the wled class has no setMirror members ...... that instead there are ..... it is the first plugin I handle so that I could have made trivial mistakes ..... someone suggest me something?
thank you