mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #335, trinary logic for LEDs improved.
The 3rd state usually means a transition state such as "connecting"
This commit is contained in:
committed by
Roland Winklmeier
parent
a94bceddab
commit
edea80319d
@@ -28,7 +28,8 @@ namespace BlackGui
|
|||||||
|
|
||||||
CLedWidget::CLedWidget(bool on, LedColor onColor, LedColor offColor, LedShape shape, const QString &onName, const QString &offName, QWidget *parent) :
|
CLedWidget::CLedWidget(bool on, LedColor onColor, LedColor offColor, LedShape shape, const QString &onName, const QString &offName, QWidget *parent) :
|
||||||
m_value(on ? On : Off), m_colorOn(onColor), m_colorOff(offColor),
|
m_value(on ? On : Off), m_colorOn(onColor), m_colorOff(offColor),
|
||||||
m_shape(shape), m_tooltipOn(onName), m_tooltipOff(offName), m_renderer(new QSvgRenderer(parent))
|
m_shape(shape), m_tooltipOn(onName), m_tooltipOff(offName),
|
||||||
|
m_renderer(new QSvgRenderer(parent))
|
||||||
{
|
{
|
||||||
this->setLed();
|
this->setLed();
|
||||||
}
|
}
|
||||||
@@ -45,21 +46,41 @@ namespace BlackGui
|
|||||||
ledShapeAndColor = shapes().at(static_cast<int>(this->m_shape));
|
ledShapeAndColor = shapes().at(static_cast<int>(this->m_shape));
|
||||||
if (ledColor == NoColor)
|
if (ledColor == NoColor)
|
||||||
{
|
{
|
||||||
if (m_value == On)
|
switch (m_value)
|
||||||
|
{
|
||||||
|
case On:
|
||||||
|
this->m_currentToolTip = this->m_tooltipOn;
|
||||||
|
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorOn));
|
||||||
|
break;
|
||||||
|
case TriState:
|
||||||
|
this->m_currentToolTip = this->m_tooltipTriState;
|
||||||
|
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorTriState));
|
||||||
|
break;
|
||||||
|
case Off:
|
||||||
|
default:
|
||||||
|
this->m_currentToolTip = this->m_tooltipOff;
|
||||||
|
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorOff));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ledColor == m_colorOn)
|
||||||
{
|
{
|
||||||
this->m_currentToolTip = this->m_tooltipOn;
|
this->m_currentToolTip = this->m_tooltipOn;
|
||||||
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorOn));
|
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorOn));
|
||||||
}
|
}
|
||||||
else
|
else if (ledColor == m_colorOff)
|
||||||
{
|
{
|
||||||
this->m_currentToolTip = this->m_tooltipOff;
|
this->m_currentToolTip = this->m_tooltipOff;
|
||||||
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorOff));
|
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorOff));
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
this->m_currentToolTip = this->m_tooltipTriState;
|
||||||
this->m_currentToolTip = "transition";
|
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorTriState));
|
||||||
ledShapeAndColor.append(CLedWidget::colorString(ledColor));
|
}
|
||||||
}
|
}
|
||||||
this->setToolTip(this->m_currentToolTip); // for widget
|
this->setToolTip(this->m_currentToolTip); // for widget
|
||||||
|
|
||||||
@@ -104,16 +125,30 @@ namespace BlackGui
|
|||||||
return colors().at(static_cast<int>(color));
|
return colors().at(static_cast<int>(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLedWidget::setToolTips(const QString &on, const QString &off)
|
void CLedWidget::setToolTips(const QString &on, const QString &off, const QString &triState)
|
||||||
{
|
{
|
||||||
this->m_tooltipOn = on;
|
this->m_tooltipOn = on;
|
||||||
this->m_tooltipOff = off;
|
this->m_tooltipOff = off;
|
||||||
|
this->m_tooltipTriState = triState;
|
||||||
this->setLed();
|
this->setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLedWidget::setOnToolTip(const QString &on)
|
void CLedWidget::setOnToolTip(const QString &on)
|
||||||
{
|
{
|
||||||
this->setToolTips(on, this->m_tooltipOff);
|
this->m_tooltipOn = on;
|
||||||
|
this->setLed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLedWidget::setOffToolTip(const QString &off)
|
||||||
|
{
|
||||||
|
this->m_tooltipOff = off;
|
||||||
|
this->setLed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLedWidget::setTriStateToolTip(const QString &triState)
|
||||||
|
{
|
||||||
|
this->m_tooltipTriState = triState;
|
||||||
|
this->setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLedWidget::setOnColor(LedColor color)
|
void CLedWidget::setOnColor(LedColor color)
|
||||||
@@ -130,10 +165,11 @@ namespace BlackGui
|
|||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLedWidget::setTemporaryColor(CLedWidget::LedColor color)
|
void CLedWidget::setTriStateColor(CLedWidget::LedColor color)
|
||||||
{
|
{
|
||||||
m_value = Temporary;
|
if (color == this->m_colorOff) return;
|
||||||
setLed(color);
|
m_colorTriState = color;
|
||||||
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLedWidget::setShape(LedShape newShape)
|
void CLedWidget::setShape(LedShape newShape)
|
||||||
@@ -154,6 +190,20 @@ namespace BlackGui
|
|||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CLedWidget::setValues(LedColor onColor, LedColor offColor, LedColor triStateColor, LedShape shape, const QString &toolTipOn, const QString &toolTipOff, const QString &toolTipTriState, int width)
|
||||||
|
{
|
||||||
|
m_colorOn = onColor;
|
||||||
|
m_colorOff = offColor;
|
||||||
|
m_colorTriState = triStateColor;
|
||||||
|
m_shape = shape;
|
||||||
|
m_tooltipOn = toolTipOn;
|
||||||
|
m_tooltipOff = toolTipOff;
|
||||||
|
m_tooltipTriState = toolTipTriState;
|
||||||
|
m_widthTarget = width;
|
||||||
|
setLed();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QPixmap CLedWidget::asPixmap() const
|
QPixmap CLedWidget::asPixmap() const
|
||||||
{
|
{
|
||||||
return this->renderToPixmap();
|
return this->renderToPixmap();
|
||||||
@@ -167,6 +217,13 @@ namespace BlackGui
|
|||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CLedWidget::setTriState()
|
||||||
|
{
|
||||||
|
if (m_value == TriState) return;
|
||||||
|
m_value = TriState;
|
||||||
|
setLed();
|
||||||
|
}
|
||||||
|
|
||||||
void CLedWidget::toggleValue()
|
void CLedWidget::toggleValue()
|
||||||
{
|
{
|
||||||
m_value = (m_value == Off) ? m_value = On : m_value = Off;
|
m_value = (m_value == Off) ? m_value = On : m_value = Off;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace BlackGui
|
|||||||
enum LedShape { Circle = 0, Square, Triangle, Rounded};
|
enum LedShape { Circle = 0, Square, Triangle, Rounded};
|
||||||
|
|
||||||
//! States
|
//! States
|
||||||
enum State { On, Off, Temporary };
|
enum State { On, Off, TriState };
|
||||||
|
|
||||||
//! Default constructor
|
//! Default constructor
|
||||||
CLedWidget(QWidget *parent = nullptr);
|
CLedWidget(QWidget *parent = nullptr);
|
||||||
@@ -53,9 +53,12 @@ namespace BlackGui
|
|||||||
//! Value
|
//! Value
|
||||||
bool value() const { return m_value; }
|
bool value() const { return m_value; }
|
||||||
|
|
||||||
//! Allows to set the led value {true,false}
|
//! Allows to set the led value {true, false}
|
||||||
void setOn(bool on);
|
void setOn(bool on);
|
||||||
|
|
||||||
|
//! Sets the 3rd state
|
||||||
|
void setTriState();
|
||||||
|
|
||||||
//! Toggle on / off
|
//! Toggle on / off
|
||||||
void toggleValue();
|
void toggleValue();
|
||||||
|
|
||||||
@@ -68,6 +71,9 @@ namespace BlackGui
|
|||||||
//! Off color
|
//! Off color
|
||||||
LedColor offColor() const { return m_colorOff; }
|
LedColor offColor() const { return m_colorOff; }
|
||||||
|
|
||||||
|
//! Tri-state color
|
||||||
|
LedColor triStateColor() const { return m_colorTriState; }
|
||||||
|
|
||||||
//! 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(LedColor color);
|
void setOnColor(LedColor color);
|
||||||
|
|
||||||
@@ -75,7 +81,7 @@ namespace BlackGui
|
|||||||
void setOffColor(LedColor color);
|
void setOffColor(LedColor color);
|
||||||
|
|
||||||
//! Temporary color until next value change
|
//! Temporary color until next value change
|
||||||
void setTemporaryColor(LedColor color);
|
void setTriStateColor(LedColor color);
|
||||||
|
|
||||||
//! Allows to change the led shape {Circle,Square,Triangle,Rounded rectangle}
|
//! Allows to change the led shape {Circle,Square,Triangle,Rounded rectangle}
|
||||||
void setShape(LedShape);
|
void setShape(LedShape);
|
||||||
@@ -89,30 +95,44 @@ namespace BlackGui
|
|||||||
//! Tool tip
|
//! Tool tip
|
||||||
QString getOffToolTip() const { return m_tooltipOff; }
|
QString getOffToolTip() const { return m_tooltipOff; }
|
||||||
|
|
||||||
|
//! Tool tip
|
||||||
|
QString getTriStateToolTip() const { return m_tooltipTriState; }
|
||||||
|
|
||||||
//! Tool tips
|
//! Tool tips
|
||||||
void setToolTips(const QString &on, const QString &off);
|
void setToolTips(const QString &on, const QString &off, const QString &triState = "tri-state");
|
||||||
|
|
||||||
//! On tool tip
|
//! On tool tip
|
||||||
void setOnToolTip(const QString &on);
|
void setOnToolTip(const QString &on);
|
||||||
|
|
||||||
//! New values
|
//! Off tool tip
|
||||||
|
void setOffToolTip(const QString &off);
|
||||||
|
|
||||||
|
//! Tri-state tool tip
|
||||||
|
void setTriStateToolTip(const QString &triState);
|
||||||
|
|
||||||
|
//! New values dual state
|
||||||
void setValues(LedColor onColor, LedColor offColor, LedShape 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);
|
||||||
|
|
||||||
|
//! New values tri-state
|
||||||
|
void setValues(LedColor onColor, LedColor offColor, LedColor triStateColor, LedShape shape, const QString &toolTipOn, const QString &toolTipOff, const QString &toolTipTriState, int width = -1);
|
||||||
|
|
||||||
//! Render as pixmap, so it can be used with TableViews
|
//! Render as pixmap, so it can be used with TableViews
|
||||||
QPixmap asPixmap() const;
|
QPixmap asPixmap() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
State m_value = Off; //!< current value
|
State m_value = Off; //!< current value
|
||||||
LedColor m_colorOn = Red; //!< On color
|
LedColor m_colorOn = Yellow; //!< On color
|
||||||
LedColor m_colorOff = Grey; //!< Off color
|
LedColor m_colorOff = Black; //!< Off color
|
||||||
|
LedColor m_colorTriState = Blue; //!< tri-state color
|
||||||
LedShape 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_widthTarget = -1; //!< desired width
|
int m_widthTarget = -1; //!< desired width
|
||||||
int m_heightCalculated = 1; //!< calculated height
|
int m_heightCalculated = 1; //!< calculated height
|
||||||
|
|
||||||
QString m_tooltipOn; //!< tooltip when on
|
QString m_tooltipOn = "on"; //!< tooltip when on
|
||||||
QString m_tooltipOff; //!< tooltip when off
|
QString m_tooltipOff = "off"; //!< tooltip when off
|
||||||
QString m_currentToolTip; //!< currently used tooltip
|
QString m_tooltipTriState = "tri-state"; //!< tooltip tri state
|
||||||
|
QString m_currentToolTip = "off"; //!< currently used tooltip
|
||||||
QScopedPointer<QSvgRenderer> m_renderer; //!< Renderer
|
QScopedPointer<QSvgRenderer> m_renderer; //!< Renderer
|
||||||
|
|
||||||
//! Paint event
|
//! Paint event
|
||||||
|
|||||||
Reference in New Issue
Block a user