mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 02:35:38 +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) :
|
CLedWidget::CLedWidget(bool on, LedColor onColor, LedColor offColor, LedShape shape, const QString &onName, const QString &offName, int targetWidth, QWidget *parent) :
|
||||||
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_shape(shape), m_widthTarget(targetWidth), m_tooltipOn(onName), m_tooltipOff(offName),
|
||||||
m_renderer(new QSvgRenderer(this))
|
m_renderer(new QSvgRenderer(this))
|
||||||
{
|
{
|
||||||
@@ -61,7 +61,7 @@ namespace BlackGui
|
|||||||
QString ledShapeAndColor(shapes().at(static_cast<int>(this->m_shape)));
|
QString ledShapeAndColor(shapes().at(static_cast<int>(this->m_shape)));
|
||||||
if (ledColor == NoColor)
|
if (ledColor == NoColor)
|
||||||
{
|
{
|
||||||
switch (m_value)
|
switch (m_state)
|
||||||
{
|
{
|
||||||
case On:
|
case On:
|
||||||
this->m_currentToolTip = this->m_tooltipOn;
|
this->m_currentToolTip = this->m_tooltipOn;
|
||||||
@@ -102,12 +102,12 @@ namespace BlackGui
|
|||||||
m_renderer->load(ledShapeAndColor); // load by filename
|
m_renderer->load(ledShapeAndColor); // load by filename
|
||||||
|
|
||||||
// original size
|
// original size
|
||||||
QSize s = m_renderer->defaultSize();
|
const QSize s = m_renderer->defaultSize();
|
||||||
this->m_whRatio = s.width() / s.height();
|
this->m_whRatio = s.width() / s.height();
|
||||||
|
|
||||||
// size
|
// size
|
||||||
if (this->m_widthTarget < 0) { this->m_widthTarget = widths().at(static_cast<int>(m_shape)); }
|
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->m_heightCalculated = qRound(h);
|
||||||
|
|
||||||
this->setFixedHeight(this->m_heightCalculated);
|
this->setFixedHeight(this->m_heightCalculated);
|
||||||
@@ -136,9 +136,11 @@ namespace BlackGui
|
|||||||
return colorFiles().at(static_cast<int>(color));
|
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)
|
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)
|
void CLedWidget::setOn(bool on, int resetTimeMs)
|
||||||
{
|
{
|
||||||
State s = on ? On : Off;
|
State s = on ? On : Off;
|
||||||
if (resetTimeMs < 0 && m_resetTimer.isActive()) { m_resetTimer.stop();}
|
|
||||||
if (resetTimeMs > 0)
|
if (resetTimeMs > 0)
|
||||||
{
|
{
|
||||||
m_resetTimer.singleShot(resetTimeMs, this, &CLedWidget::ps_resetState);
|
m_resetTimer.singleShot(resetTimeMs, this, &CLedWidget::resetState);
|
||||||
}
|
}
|
||||||
if (m_value == s) { return; }
|
else
|
||||||
m_value = s;
|
{
|
||||||
|
m_resetTimer.stop();
|
||||||
|
m_value = s;
|
||||||
|
}
|
||||||
|
if (m_state == s) { return; }
|
||||||
|
m_state = s;
|
||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLedWidget::blink(int resetTimeMs)
|
void CLedWidget::blink(int resetTimeMs)
|
||||||
{
|
{
|
||||||
|
m_value = Off;
|
||||||
this->setOn(true, resetTimeMs);
|
this->setOn(true, resetTimeMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLedWidget::setTriState(int resetTimeMs)
|
void CLedWidget::setTriState(int resetTimeMs)
|
||||||
{
|
{
|
||||||
if (resetTimeMs < 0 && m_resetTimer.isActive()) { m_resetTimer.stop();}
|
|
||||||
if (resetTimeMs > 0)
|
if (resetTimeMs > 0)
|
||||||
{
|
{
|
||||||
m_resetTimer.singleShot(resetTimeMs, this, &CLedWidget::ps_resetState);
|
m_resetTimer.singleShot(resetTimeMs, this, &CLedWidget::resetState);
|
||||||
}
|
}
|
||||||
if (m_value == TriState) { return; }
|
else
|
||||||
m_value = TriState;
|
{
|
||||||
|
m_resetTimer.stop();
|
||||||
|
m_value = TriState;
|
||||||
|
}
|
||||||
|
if (m_state == TriState) { return; }
|
||||||
|
m_state = TriState;
|
||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLedWidget::toggleValue()
|
void CLedWidget::toggleValue()
|
||||||
{
|
{
|
||||||
m_value = (m_value == Off) ? On : Off;
|
m_state = (m_state == Off) ? On : Off;
|
||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace BlackGui
|
|||||||
virtual ~CLedWidget();
|
virtual ~CLedWidget();
|
||||||
|
|
||||||
//! Value
|
//! Value
|
||||||
bool value() const { return m_value; }
|
bool value() const { return m_state; }
|
||||||
|
|
||||||
//! Allows to set the led value {true, false}
|
//! Allows to set the led value {true, false}
|
||||||
void setOn(bool on, int resetTimeMs = -1);
|
void setOn(bool on, int resetTimeMs = -1);
|
||||||
@@ -135,8 +135,9 @@ namespace BlackGui
|
|||||||
//! LED clicked
|
//! LED clicked
|
||||||
void clicked();
|
void clicked();
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
State m_value = Off; //!< current value
|
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_colorOn = Yellow; //!< On color
|
||||||
LedColor m_colorOff = Black; //!< Off color
|
LedColor m_colorOff = Black; //!< Off color
|
||||||
LedColor m_colorTriState = Blue; //!< tri-state color
|
LedColor m_colorTriState = Blue; //!< tri-state color
|
||||||
@@ -155,6 +156,9 @@ namespace BlackGui
|
|||||||
//! Init
|
//! Init
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
//! Reset the state
|
||||||
|
void resetState();
|
||||||
|
|
||||||
//! Paint event
|
//! Paint event
|
||||||
virtual void paintEvent(QPaintEvent *event) override;
|
virtual void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
@@ -178,10 +182,6 @@ namespace BlackGui
|
|||||||
|
|
||||||
//! Color string
|
//! Color string
|
||||||
static const QString &colorString(LedColor color); //!< Color string
|
static const QString &colorString(LedColor color); //!< Color string
|
||||||
|
|
||||||
private slots:
|
|
||||||
//! Reset state
|
|
||||||
void ps_resetState();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user