From 2089ab89a13db6184a33dff005c1c1e3dd598ed3 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 21 Aug 2014 11:19:46 +0200 Subject: [PATCH] Fixed qLed state, wrong if temporary icon is used * Using state instead of just bool --- .../components/infobarstatuscomponent.cpp | 20 ++++---- src/blackgui/led.cpp | 46 ++++++++++------- src/blackgui/led.h | 51 ++++++++++--------- 3 files changed, 64 insertions(+), 53 deletions(-) diff --git a/src/blackgui/components/infobarstatuscomponent.cpp b/src/blackgui/components/infobarstatuscomponent.cpp index a29d02a5c..5f0a2c117 100644 --- a/src/blackgui/components/infobarstatuscomponent.cpp +++ b/src/blackgui/components/infobarstatuscomponent.cpp @@ -40,7 +40,7 @@ namespace BlackGui void CInfoBarStatusComponent::initLeds() { - CLed::LedShapes shape = CLed::Circle; + CLed::LedShape shape = CLed::Circle; this->ui->led_DBus->setValues(CLed::Yellow, CLed::Black, shape, "DBus connected", "DBus disconnected", 14); this->ui->led_Network->setValues(CLed::Yellow, CLed::Black, shape, "Network connected", "Network disconnected", 14); this->ui->led_Simulator->setValues(CLed::Yellow, CLed::Black, shape, "Simulator connected", "Simulator disconnected", 14); @@ -52,7 +52,7 @@ namespace BlackGui void CInfoBarStatusComponent::setDBusStatus(bool dbus) { - this->ui->led_DBus->setValue(dbus); + this->ui->led_DBus->setOn(dbus); } void CInfoBarStatusComponent::setDBusTooltip(const QString &tooltip) @@ -64,11 +64,11 @@ namespace BlackGui { if (volume < 1) { - this->ui->led_Audio->setValue(false); + this->ui->led_Audio->setOn(false); } else { - this->ui->led_Audio->setValue(true); + this->ui->led_Audio->setOn(true); } } @@ -92,18 +92,18 @@ namespace BlackGui { if (this->getIContextApplication()->usingLocalObjects()) { - this->ui->led_DBus->setValue(false); + this->ui->led_DBus->setOn(false); } else { - this->ui->led_DBus->setValue(true); + this->ui->led_DBus->setOn(true); } } } void CInfoBarStatusComponent::ps_simulatorConnectionChanged(bool connected) { - this->ui->led_Simulator->setValue(connected); + this->ui->led_Simulator->setOn(connected); } void CInfoBarStatusComponent::ps_networkConnectionChanged(uint from, uint to, const QString &message) @@ -119,16 +119,16 @@ namespace BlackGui case INetwork::DisconnectedError: case INetwork::DisconnectedFailed: case INetwork::DisconnectedLost: - this->ui->led_Network->setValue(false); + this->ui->led_Network->setOn(false); break; case INetwork::Connected: - this->ui->led_Network->setValue(true); + this->ui->led_Network->setOn(true); break; case INetwork::Connecting: this->ui->led_Network->setTemporaryColor(CLed::Yellow); break; default: - this->ui->led_Network->setValue(false); + this->ui->led_Network->setOn(false); break; } } diff --git a/src/blackgui/led.cpp b/src/blackgui/led.cpp index 1b21f2e54..d6a43069e 100644 --- a/src/blackgui/led.cpp +++ b/src/blackgui/led.cpp @@ -23,7 +23,6 @@ #include #include - namespace BlackGui { CLed::CLed(QWidget *parent) : QWidget(parent) @@ -31,20 +30,20 @@ namespace BlackGui this->setLed(); } - CLed::CLed(bool on, CLed::LedColors onColor, CLed::LedColors offColor, CLed::LedShapes shape, QWidget *parent) : - QWidget(parent), m_value(on), m_onColor(onColor), m_offColor(offColor), m_shape(shape) + CLed::CLed(bool on, CLed::LedColor onColor, CLed::LedColor offColor, CLed::LedShape shape, QWidget *parent) : + QWidget(parent), m_value(on ? On : Off), m_onColor(onColor), m_offColor(offColor), m_shape(shape) { this->setLed(); } - void CLed::setLed(LedColors tempColor) + void CLed::setLed(LedColor ledColor) { // load image, init renderer QString ledShapeAndColor; ledShapeAndColor = shapes().at(static_cast(this->m_shape)); - if (tempColor == NoColor) + if (ledColor == NoColor) { - if (m_value) + if (m_value == On) { this->setToolTip(this->m_tooltipOn); ledShapeAndColor.append(CLed::colorString(this->m_onColor)); @@ -58,7 +57,7 @@ namespace BlackGui else { this->setToolTip("transition"); - ledShapeAndColor.append(CLed::colorString(tempColor)); + ledShapeAndColor.append(CLed::colorString(ledColor)); } // init renderer, allow re-init @@ -87,12 +86,12 @@ namespace BlackGui if (!firstTime) { - // re-init + // re-init widget (adjust size etc.) this->update(); } } - const QString &CLed::colorString(CLed::LedColors color) + const QString &CLed::colorString(CLed::LedColor color) { static const QString empty; if (color == NoColor) return empty; @@ -136,33 +135,34 @@ namespace BlackGui m_renderer->render(&painter); } - void CLed::setOnColor(LedColors color) + void CLed::setOnColor(LedColor color) { if (color == this->m_onColor) return; m_onColor = color; setLed(); } - void CLed::setOffColor(LedColors color) + void CLed::setOffColor(LedColor color) { if (color == this->m_offColor) return; m_offColor = color; setLed(); } - void CLed::setTemporaryColor(CLed::LedColors color) + void CLed::setTemporaryColor(CLed::LedColor color) { + m_value = Temporary; setLed(color); } - void CLed::setShape(LedShapes newShape) + void CLed::setShape(LedShape newShape) { if (newShape == this->m_shape) return; m_shape = newShape; setLed(); } - void CLed::setValues(CLed::LedColors onColor, CLed::LedColors offColor, CLed::LedShapes shape, const QString &toolTipOn, const QString &toolTipOff, int width) + void CLed::setValues(CLed::LedColor onColor, CLed::LedColor offColor, CLed::LedShape shape, const QString &toolTipOn, const QString &toolTipOff, int width) { m_onColor = onColor; m_offColor = offColor; @@ -173,16 +173,24 @@ namespace BlackGui setLed(); } - void CLed::setValue(bool value) + void CLed::setOn(bool on) { - if (value == m_value) return; - m_value = value; + State s = on ? On : Off; + if (m_value == s) return; + m_value = s; setLed(); } void CLed::toggleValue() { - m_value = !m_value; + if (m_value == Temporary || m_value == On) + { + m_value = Off; + } + else + { + m_value = Off; + } setLed(); } @@ -200,7 +208,7 @@ namespace BlackGui const QList &CLed::widths() { - static const QList widths({ 16 , 16, 16, 16}); + static const QList widths({ 16, 16, 16, 16}); return widths; } } diff --git a/src/blackgui/led.h b/src/blackgui/led.h index d4845e719..0be43d191 100644 --- a/src/blackgui/led.h +++ b/src/blackgui/led.h @@ -32,32 +32,35 @@ namespace BlackGui class CLed : public QWidget { Q_OBJECT - Q_ENUMS(LedColors) - Q_ENUMS(LedShapes) + Q_ENUMS(LedColor) + Q_ENUMS(LedShape) //! Value on/off - Q_PROPERTY(bool value READ value WRITE setValue) + Q_PROPERTY(bool value READ value WRITE setOn) //! Color when on - Q_PROPERTY(LedColors onColor READ onColor WRITE setOnColor) + Q_PROPERTY(LedColor onColor READ onColor WRITE setOnColor) //! Color when off - Q_PROPERTY(LedColors offColor READ offColor WRITE setOffColor) + Q_PROPERTY(LedColor offColor READ offColor WRITE setOffColor) //! Shape - Q_PROPERTY(LedShapes shape READ shape WRITE setShape) + Q_PROPERTY(LedShape shape READ shape WRITE setShape) public: //! Colors //! \remarks None has to be last entry - enum LedColors { Red = 0, Green, Yellow, Grey, Orange, Purple, Blue, Black, NoColor}; + enum LedColor { Red = 0, Green, Yellow, Grey, Orange, Purple, Blue, Black, NoColor}; //! Shapes - enum LedShapes { Circle = 0, Square, Triangle, Rounded}; + enum LedShape { Circle = 0, Square, Triangle, Rounded}; + + //! States + enum State { On, Off, Temporary }; //! Constructor CLed(QWidget *parent = nullptr); //! Constructor - CLed(bool on, LedColors onColor, LedColors offColor, LedShapes shape, QWidget *parent = nullptr); + CLed(bool on, LedColor onColor, LedColor offColor, LedShape shape, QWidget *parent = nullptr); //! Destructor virtual ~CLed(); @@ -66,25 +69,25 @@ namespace BlackGui bool value() const { return m_value; } //! On color - LedColors onColor() const { return m_onColor; } + LedColor onColor() const { return m_onColor; } //! Off color - LedColors offColor() const { return m_offColor; } + LedColor offColor() const { return m_offColor; } //! Shape - LedShapes shape() const { return m_shape; } + LedShape shape() const { return m_shape; } //! Allows to set the led value {true,false} - void setValue(bool); + void setOn(bool on); //! Allows to change the On color {Red,Green,Yellow,Grey,Orange,Purple,blue} - void setOnColor(LedColors color); + void setOnColor(LedColor color); //! Allows to change the Off color {Red,Green,Yellow,Grey,Orange,Purple,blue} - void setOffColor(LedColors color); + void setOffColor(LedColor color); //! Temporary color until next value change - void setTemporaryColor(LedColors color); + void setTemporaryColor(LedColor color); //! Tool tips void setToolTips(const QString &on, const QString &off); @@ -93,22 +96,22 @@ namespace BlackGui void setOnToolTip(const QString &on); //! Allows to change the led shape {Circle,Square,Triangle,Rounded rectangle} - void setShape(LedShapes); + void setShape(LedShape); //! Target width void setTargetWidth(int width) { this->m_targetWidth = width; } //! New values - void setValues(LedColors onColor, LedColors offColor, LedShapes shape, const QString &toolTipOn, const QString &toolTipOff, int width = -1); + void setValues(LedColor onColor, LedColor offColor, LedShape shape, const QString &toolTipOn, const QString &toolTipOff, int width = -1); //! Toggle on / off void toggleValue(); protected: - bool m_value = false; //!< current value - LedColors m_onColor = Red; //!< On color - LedColors m_offColor = Grey; //!< Off color - LedShapes m_shape = Circle; //!< shape + State m_value = Off; //!< current value + LedColor m_onColor = Red; //!< On color + LedColor m_offColor = Grey; //!< Off color + LedShape m_shape = Circle; //!< shape double m_whRatio = 1.0; //!< width/height ratio int m_targetWidth = -1; //!< TargetWidth @@ -128,8 +131,8 @@ namespace BlackGui QSvgRenderer *m_renderer = nullptr; //!< Renderer QString m_tooltipOn; QString m_tooltipOff; - void setLed(LedColors tempColor = NoColor); //!< Init LED - static const QString &colorString(LedColors color); //!