Fixed qLed state, wrong if temporary icon is used

* Using state instead of just bool
This commit is contained in:
Klaus Basan
2014-08-21 11:19:46 +02:00
parent 5df96c576b
commit 2089ab89a1
3 changed files with 64 additions and 53 deletions

View File

@@ -40,7 +40,7 @@ namespace BlackGui
void CInfoBarStatusComponent::initLeds() 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_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_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); 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) void CInfoBarStatusComponent::setDBusStatus(bool dbus)
{ {
this->ui->led_DBus->setValue(dbus); this->ui->led_DBus->setOn(dbus);
} }
void CInfoBarStatusComponent::setDBusTooltip(const QString &tooltip) void CInfoBarStatusComponent::setDBusTooltip(const QString &tooltip)
@@ -64,11 +64,11 @@ namespace BlackGui
{ {
if (volume < 1) if (volume < 1)
{ {
this->ui->led_Audio->setValue(false); this->ui->led_Audio->setOn(false);
} }
else else
{ {
this->ui->led_Audio->setValue(true); this->ui->led_Audio->setOn(true);
} }
} }
@@ -92,18 +92,18 @@ namespace BlackGui
{ {
if (this->getIContextApplication()->usingLocalObjects()) if (this->getIContextApplication()->usingLocalObjects())
{ {
this->ui->led_DBus->setValue(false); this->ui->led_DBus->setOn(false);
} }
else else
{ {
this->ui->led_DBus->setValue(true); this->ui->led_DBus->setOn(true);
} }
} }
} }
void CInfoBarStatusComponent::ps_simulatorConnectionChanged(bool connected) 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) void CInfoBarStatusComponent::ps_networkConnectionChanged(uint from, uint to, const QString &message)
@@ -119,16 +119,16 @@ namespace BlackGui
case INetwork::DisconnectedError: case INetwork::DisconnectedError:
case INetwork::DisconnectedFailed: case INetwork::DisconnectedFailed:
case INetwork::DisconnectedLost: case INetwork::DisconnectedLost:
this->ui->led_Network->setValue(false); this->ui->led_Network->setOn(false);
break; break;
case INetwork::Connected: case INetwork::Connected:
this->ui->led_Network->setValue(true); this->ui->led_Network->setOn(true);
break; break;
case INetwork::Connecting: case INetwork::Connecting:
this->ui->led_Network->setTemporaryColor(CLed::Yellow); this->ui->led_Network->setTemporaryColor(CLed::Yellow);
break; break;
default: default:
this->ui->led_Network->setValue(false); this->ui->led_Network->setOn(false);
break; break;
} }
} }

View File

@@ -23,7 +23,6 @@
#include <QtSvg> #include <QtSvg>
#include <QSvgRenderer> #include <QSvgRenderer>
namespace BlackGui namespace BlackGui
{ {
CLed::CLed(QWidget *parent) : QWidget(parent) CLed::CLed(QWidget *parent) : QWidget(parent)
@@ -31,20 +30,20 @@ namespace BlackGui
this->setLed(); this->setLed();
} }
CLed::CLed(bool on, CLed::LedColors onColor, CLed::LedColors offColor, CLed::LedShapes shape, QWidget *parent) : CLed::CLed(bool on, CLed::LedColor onColor, CLed::LedColor offColor, CLed::LedShape shape, QWidget *parent) :
QWidget(parent), m_value(on), m_onColor(onColor), m_offColor(offColor), m_shape(shape) QWidget(parent), m_value(on ? On : Off), m_onColor(onColor), m_offColor(offColor), m_shape(shape)
{ {
this->setLed(); this->setLed();
} }
void CLed::setLed(LedColors tempColor) void CLed::setLed(LedColor ledColor)
{ {
// load image, init renderer // load image, init renderer
QString ledShapeAndColor; QString ledShapeAndColor;
ledShapeAndColor = shapes().at(static_cast<int>(this->m_shape)); ledShapeAndColor = shapes().at(static_cast<int>(this->m_shape));
if (tempColor == NoColor) if (ledColor == NoColor)
{ {
if (m_value) if (m_value == On)
{ {
this->setToolTip(this->m_tooltipOn); this->setToolTip(this->m_tooltipOn);
ledShapeAndColor.append(CLed::colorString(this->m_onColor)); ledShapeAndColor.append(CLed::colorString(this->m_onColor));
@@ -58,7 +57,7 @@ namespace BlackGui
else else
{ {
this->setToolTip("transition"); this->setToolTip("transition");
ledShapeAndColor.append(CLed::colorString(tempColor)); ledShapeAndColor.append(CLed::colorString(ledColor));
} }
// init renderer, allow re-init // init renderer, allow re-init
@@ -87,12 +86,12 @@ namespace BlackGui
if (!firstTime) if (!firstTime)
{ {
// re-init // re-init widget (adjust size etc.)
this->update(); this->update();
} }
} }
const QString &CLed::colorString(CLed::LedColors color) const QString &CLed::colorString(CLed::LedColor color)
{ {
static const QString empty; static const QString empty;
if (color == NoColor) return empty; if (color == NoColor) return empty;
@@ -136,33 +135,34 @@ namespace BlackGui
m_renderer->render(&painter); m_renderer->render(&painter);
} }
void CLed::setOnColor(LedColors color) void CLed::setOnColor(LedColor color)
{ {
if (color == this->m_onColor) return; if (color == this->m_onColor) return;
m_onColor = color; m_onColor = color;
setLed(); setLed();
} }
void CLed::setOffColor(LedColors color) void CLed::setOffColor(LedColor color)
{ {
if (color == this->m_offColor) return; if (color == this->m_offColor) return;
m_offColor = color; m_offColor = color;
setLed(); setLed();
} }
void CLed::setTemporaryColor(CLed::LedColors color) void CLed::setTemporaryColor(CLed::LedColor color)
{ {
m_value = Temporary;
setLed(color); setLed(color);
} }
void CLed::setShape(LedShapes newShape) void CLed::setShape(LedShape newShape)
{ {
if (newShape == this->m_shape) return; if (newShape == this->m_shape) return;
m_shape = newShape; m_shape = newShape;
setLed(); 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_onColor = onColor;
m_offColor = offColor; m_offColor = offColor;
@@ -173,16 +173,24 @@ namespace BlackGui
setLed(); setLed();
} }
void CLed::setValue(bool value) void CLed::setOn(bool on)
{ {
if (value == m_value) return; State s = on ? On : Off;
m_value = value; if (m_value == s) return;
m_value = s;
setLed(); setLed();
} }
void CLed::toggleValue() void CLed::toggleValue()
{ {
m_value = !m_value; if (m_value == Temporary || m_value == On)
{
m_value = Off;
}
else
{
m_value = Off;
}
setLed(); setLed();
} }

View File

@@ -32,32 +32,35 @@ namespace BlackGui
class CLed : public QWidget class CLed : public QWidget
{ {
Q_OBJECT Q_OBJECT
Q_ENUMS(LedColors) Q_ENUMS(LedColor)
Q_ENUMS(LedShapes) Q_ENUMS(LedShape)
//! Value on/off //! Value on/off
Q_PROPERTY(bool value READ value WRITE setValue) Q_PROPERTY(bool value READ value WRITE setOn)
//! Color when on //! Color when on
Q_PROPERTY(LedColors onColor READ onColor WRITE setOnColor) Q_PROPERTY(LedColor onColor READ onColor WRITE setOnColor)
//! Color when off //! Color when off
Q_PROPERTY(LedColors offColor READ offColor WRITE setOffColor) Q_PROPERTY(LedColor offColor READ offColor WRITE setOffColor)
//! Shape //! Shape
Q_PROPERTY(LedShapes shape READ shape WRITE setShape) Q_PROPERTY(LedShape shape READ shape WRITE setShape)
public: public:
//! Colors //! Colors
//! \remarks None has to be last entry //! \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 //! Shapes
enum LedShapes { Circle = 0, Square, Triangle, Rounded}; enum LedShape { Circle = 0, Square, Triangle, Rounded};
//! States
enum State { On, Off, Temporary };
//! Constructor //! Constructor
CLed(QWidget *parent = nullptr); CLed(QWidget *parent = nullptr);
//! Constructor //! 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 //! Destructor
virtual ~CLed(); virtual ~CLed();
@@ -66,25 +69,25 @@ namespace BlackGui
bool value() const { return m_value; } bool value() const { return m_value; }
//! On color //! On color
LedColors onColor() const { return m_onColor; } LedColor onColor() const { return m_onColor; }
//! Off color //! Off color
LedColors offColor() const { return m_offColor; } LedColor offColor() const { return m_offColor; }
//! Shape //! Shape
LedShapes shape() const { return m_shape; } LedShape shape() const { return m_shape; }
//! Allows to set the led value {true,false} //! 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} //! 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} //! 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 //! Temporary color until next value change
void setTemporaryColor(LedColors color); void setTemporaryColor(LedColor color);
//! Tool tips //! Tool tips
void setToolTips(const QString &on, const QString &off); void setToolTips(const QString &on, const QString &off);
@@ -93,22 +96,22 @@ namespace BlackGui
void setOnToolTip(const QString &on); void setOnToolTip(const QString &on);
//! Allows to change the led shape {Circle,Square,Triangle,Rounded rectangle} //! Allows to change the led shape {Circle,Square,Triangle,Rounded rectangle}
void setShape(LedShapes); void setShape(LedShape);
//! Target width //! Target width
void setTargetWidth(int width) { this->m_targetWidth = width; } void setTargetWidth(int width) { this->m_targetWidth = width; }
//! New values //! 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 //! Toggle on / off
void toggleValue(); void toggleValue();
protected: protected:
bool m_value = false; //!< current value State m_value = Off; //!< current value
LedColors m_onColor = Red; //!< On color LedColor m_onColor = Red; //!< On color
LedColors m_offColor = Grey; //!< Off color LedColor m_offColor = Grey; //!< Off color
LedShapes m_shape = Circle; //!< shape LedShape m_shape = Circle; //!< shape
double m_whRatio = 1.0; //!< width/height ratio double m_whRatio = 1.0; //!< width/height ratio
int m_targetWidth = -1; //!< TargetWidth int m_targetWidth = -1; //!< TargetWidth
@@ -128,8 +131,8 @@ namespace BlackGui
QSvgRenderer *m_renderer = nullptr; //!< Renderer QSvgRenderer *m_renderer = nullptr; //!< Renderer
QString m_tooltipOn; QString m_tooltipOn;
QString m_tooltipOff; QString m_tooltipOff;
void setLed(LedColors tempColor = NoColor); //!< Init LED void setLed(LedColor ledColor = NoColor); //!< Init LED
static const QString &colorString(LedColors color); //!<Color string static const QString &colorString(LedColor color); //!<Color string
}; };
} }
#endif #endif