mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-12 15:25:34 +08:00
Ref T171, fixed wrong reset state in LED (always off)
- distinguish between value and state - protected -> private (no need for protected)
This commit is contained in:
@@ -33,7 +33,7 @@ namespace BlackGui
|
||||
|
||||
CLedWidget::CLedWidget(bool on, LedColor onColor, LedColor offColor, LedShape shape, const QString &onName, const QString &offName, int targetWidth, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_value(on ? On : Off), m_colorOn(onColor), m_colorOff(offColor),
|
||||
m_state(on ? On : Off), m_colorOn(onColor), m_colorOff(offColor),
|
||||
m_shape(shape), m_widthTarget(targetWidth), m_tooltipOn(onName), m_tooltipOff(offName),
|
||||
m_renderer(new QSvgRenderer(this))
|
||||
{
|
||||
@@ -61,7 +61,7 @@ namespace BlackGui
|
||||
QString ledShapeAndColor(shapes().at(static_cast<int>(this->m_shape)));
|
||||
if (ledColor == NoColor)
|
||||
{
|
||||
switch (m_value)
|
||||
switch (m_state)
|
||||
{
|
||||
case On:
|
||||
this->m_currentToolTip = this->m_tooltipOn;
|
||||
@@ -102,12 +102,12 @@ namespace BlackGui
|
||||
m_renderer->load(ledShapeAndColor); // load by filename
|
||||
|
||||
// original size
|
||||
QSize s = m_renderer->defaultSize();
|
||||
const QSize s = m_renderer->defaultSize();
|
||||
this->m_whRatio = s.width() / s.height();
|
||||
|
||||
// size
|
||||
if (this->m_widthTarget < 0) { this->m_widthTarget = widths().at(static_cast<int>(m_shape)); }
|
||||
double h = this->m_widthTarget / this->m_whRatio;
|
||||
const double h = this->m_widthTarget / this->m_whRatio;
|
||||
this->m_heightCalculated = qRound(h);
|
||||
|
||||
this->setFixedHeight(this->m_heightCalculated);
|
||||
@@ -136,9 +136,11 @@ namespace BlackGui
|
||||
return colorFiles().at(static_cast<int>(color));
|
||||
}
|
||||
|
||||
void CLedWidget::ps_resetState()
|
||||
void CLedWidget::resetState()
|
||||
{
|
||||
this->setOn(false);
|
||||
if (m_value == m_state) { return; }
|
||||
m_state = m_value;
|
||||
this->setLed();
|
||||
}
|
||||
|
||||
void CLedWidget::setToolTips(const QString &on, const QString &off, const QString &triState)
|
||||
@@ -227,36 +229,45 @@ namespace BlackGui
|
||||
void CLedWidget::setOn(bool on, int resetTimeMs)
|
||||
{
|
||||
State s = on ? On : Off;
|
||||
if (resetTimeMs < 0 && m_resetTimer.isActive()) { m_resetTimer.stop();}
|
||||
if (resetTimeMs > 0)
|
||||
{
|
||||
m_resetTimer.singleShot(resetTimeMs, this, &CLedWidget::ps_resetState);
|
||||
m_resetTimer.singleShot(resetTimeMs, this, &CLedWidget::resetState);
|
||||
}
|
||||
if (m_value == s) { return; }
|
||||
m_value = s;
|
||||
else
|
||||
{
|
||||
m_resetTimer.stop();
|
||||
m_value = s;
|
||||
}
|
||||
if (m_state == s) { return; }
|
||||
m_state = s;
|
||||
setLed();
|
||||
}
|
||||
|
||||
void CLedWidget::blink(int resetTimeMs)
|
||||
{
|
||||
m_value = Off;
|
||||
this->setOn(true, resetTimeMs);
|
||||
}
|
||||
|
||||
void CLedWidget::setTriState(int resetTimeMs)
|
||||
{
|
||||
if (resetTimeMs < 0 && m_resetTimer.isActive()) { m_resetTimer.stop();}
|
||||
if (resetTimeMs > 0)
|
||||
{
|
||||
m_resetTimer.singleShot(resetTimeMs, this, &CLedWidget::ps_resetState);
|
||||
m_resetTimer.singleShot(resetTimeMs, this, &CLedWidget::resetState);
|
||||
}
|
||||
if (m_value == TriState) { return; }
|
||||
m_value = TriState;
|
||||
else
|
||||
{
|
||||
m_resetTimer.stop();
|
||||
m_value = TriState;
|
||||
}
|
||||
if (m_state == TriState) { return; }
|
||||
m_state = TriState;
|
||||
setLed();
|
||||
}
|
||||
|
||||
void CLedWidget::toggleValue()
|
||||
{
|
||||
m_value = (m_value == Off) ? On : Off;
|
||||
m_state = (m_state == Off) ? On : Off;
|
||||
setLed();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace BlackGui
|
||||
virtual ~CLedWidget();
|
||||
|
||||
//! Value
|
||||
bool value() const { return m_value; }
|
||||
bool value() const { return m_state; }
|
||||
|
||||
//! Allows to set the led value {true, false}
|
||||
void setOn(bool on, int resetTimeMs = -1);
|
||||
@@ -135,8 +135,9 @@ namespace BlackGui
|
||||
//! LED clicked
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
State m_value = Off; //!< current value
|
||||
private:
|
||||
State m_state = Off; //!< current state, can be different from value when blinking
|
||||
State m_value = Off; //!< explicit value
|
||||
LedColor m_colorOn = Yellow; //!< On color
|
||||
LedColor m_colorOff = Black; //!< Off color
|
||||
LedColor m_colorTriState = Blue; //!< tri-state color
|
||||
@@ -155,6 +156,9 @@ namespace BlackGui
|
||||
//! Init
|
||||
void init();
|
||||
|
||||
//! Reset the state
|
||||
void resetState();
|
||||
|
||||
//! Paint event
|
||||
virtual void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
@@ -178,10 +182,6 @@ namespace BlackGui
|
||||
|
||||
//! Color string
|
||||
static const QString &colorString(LedColor color); //!< Color string
|
||||
|
||||
private slots:
|
||||
//! Reset state
|
||||
void ps_resetState();
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user