added disabled state for LED bar
This commit is contained in:
parent
04da12c959
commit
bcf39db392
4 changed files with 76 additions and 30 deletions
|
@ -67,47 +67,78 @@ CMultiColorLEDBar::~CMultiColorLEDBar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMultiColorLEDBar::setValue ( const int value )
|
void CMultiColorLEDBar::changeEvent ( QEvent* curEvent )
|
||||||
{
|
{
|
||||||
// update state of all LEDs for current level value
|
// act on enabled changed state
|
||||||
|
if ( (*curEvent).type() == QEvent::EnabledChange )
|
||||||
|
{
|
||||||
|
// reset all LEDs
|
||||||
|
Reset ( this->isEnabled() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMultiColorLEDBar::Reset ( const bool bEnabled )
|
||||||
|
{
|
||||||
|
// update state of all LEDs
|
||||||
for ( int iLEDIdx = 0; iLEDIdx < iNumLEDs; iLEDIdx++ )
|
for ( int iLEDIdx = 0; iLEDIdx < iNumLEDs; iLEDIdx++ )
|
||||||
{
|
{
|
||||||
// set active LED color if value is above current LED index
|
// different reset behavoiur for enabled and disabled control
|
||||||
if ( iLEDIdx < value )
|
if ( bEnabled )
|
||||||
{
|
{
|
||||||
// check which color we should use (green, yellow or red)
|
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_GREY );
|
||||||
if ( iLEDIdx < YELLOW_BOUND_INP_LEV_METER )
|
|
||||||
{
|
|
||||||
// green region
|
|
||||||
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_GREEN );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( iLEDIdx < RED_BOUND_INP_LEV_METER )
|
|
||||||
{
|
|
||||||
// yellow region
|
|
||||||
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_YELLOW );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// red region
|
|
||||||
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_RED );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we use grey LED for inactive state
|
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_DISABLED );
|
||||||
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_GREY );
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMultiColorLEDBar::setValue ( const int value )
|
||||||
|
{
|
||||||
|
if ( this->isEnabled() )
|
||||||
|
{
|
||||||
|
// update state of all LEDs for current level value
|
||||||
|
for ( int iLEDIdx = 0; iLEDIdx < iNumLEDs; iLEDIdx++ )
|
||||||
|
{
|
||||||
|
// set active LED color if value is above current LED index
|
||||||
|
if ( iLEDIdx < value )
|
||||||
|
{
|
||||||
|
// check which color we should use (green, yellow or red)
|
||||||
|
if ( iLEDIdx < YELLOW_BOUND_INP_LEV_METER )
|
||||||
|
{
|
||||||
|
// green region
|
||||||
|
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_GREEN );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( iLEDIdx < RED_BOUND_INP_LEV_METER )
|
||||||
|
{
|
||||||
|
// yellow region
|
||||||
|
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_YELLOW );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// red region
|
||||||
|
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_RED );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we use grey LED for inactive state
|
||||||
|
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_GREY );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CMultiColorLEDBar::cLED::cLED ( QWidget* parent ) :
|
CMultiColorLEDBar::cLED::cLED ( QWidget* parent ) :
|
||||||
BitmCubeRoundGrey ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDGreySmall.png" ) ),
|
BitmCubeRoundDisabled ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDDisabledSmall.png" ) ),
|
||||||
BitmCubeRoundGreen ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDGreenSmall.png" ) ),
|
BitmCubeRoundGrey ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDGreySmall.png" ) ),
|
||||||
BitmCubeRoundYellow ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDYellowSmall.png" ) ),
|
BitmCubeRoundGreen ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDGreenSmall.png" ) ),
|
||||||
BitmCubeRoundRed ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDRedSmall.png" ) )
|
BitmCubeRoundYellow ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDYellowSmall.png" ) ),
|
||||||
|
BitmCubeRoundRed ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDRedSmall.png" ) )
|
||||||
{
|
{
|
||||||
// create LED label
|
// create LED label
|
||||||
pLEDLabel = new QLabel ( "", parent );
|
pLEDLabel = new QLabel ( "", parent );
|
||||||
|
@ -128,6 +159,10 @@ void CMultiColorLEDBar::cLED::setColor ( const ELightColor eNewColor )
|
||||||
{
|
{
|
||||||
switch ( eNewColor )
|
switch ( eNewColor )
|
||||||
{
|
{
|
||||||
|
case RL_DISABLED:
|
||||||
|
pLEDLabel->setPixmap ( BitmCubeRoundDisabled );
|
||||||
|
break;
|
||||||
|
|
||||||
case RL_GREY:
|
case RL_GREY:
|
||||||
pLEDLabel->setPixmap ( BitmCubeRoundGrey );
|
pLEDLabel->setPixmap ( BitmCubeRoundGrey );
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -48,13 +48,21 @@ protected:
|
||||||
class cLED
|
class cLED
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ELightColor { RL_GREY, RL_GREEN, RL_YELLOW, RL_RED };
|
enum ELightColor
|
||||||
|
{
|
||||||
|
RL_DISABLED,
|
||||||
|
RL_GREY,
|
||||||
|
RL_GREEN,
|
||||||
|
RL_YELLOW,
|
||||||
|
RL_RED
|
||||||
|
};
|
||||||
|
|
||||||
cLED ( QWidget* parent );
|
cLED ( QWidget* parent );
|
||||||
void setColor ( const ELightColor eNewColor );
|
void setColor ( const ELightColor eNewColor );
|
||||||
QLabel* getLabelPointer() { return pLEDLabel; }
|
QLabel* getLabelPointer() { return pLEDLabel; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QPixmap BitmCubeRoundDisabled;
|
||||||
QPixmap BitmCubeRoundGrey;
|
QPixmap BitmCubeRoundGrey;
|
||||||
QPixmap BitmCubeRoundGreen;
|
QPixmap BitmCubeRoundGreen;
|
||||||
QPixmap BitmCubeRoundYellow;
|
QPixmap BitmCubeRoundYellow;
|
||||||
|
@ -64,6 +72,9 @@ protected:
|
||||||
QLabel* pLEDLabel;
|
QLabel* pLEDLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void Reset ( const bool bEnabled );
|
||||||
|
virtual void changeEvent ( QEvent* curEvent );
|
||||||
|
|
||||||
QHBoxLayout* pMainLayout;
|
QHBoxLayout* pMainLayout;
|
||||||
|
|
||||||
int iNumLEDs;
|
int iNumLEDs;
|
||||||
|
|
BIN
src/res/CLEDDisabledSmall.png
Executable file
BIN
src/res/CLEDDisabledSmall.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
src/res/VLEDDisabledSmall.png
Executable file
BIN
src/res/VLEDDisabledSmall.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 798 B |
Loading…
Reference in a new issue