speed optimization
This commit is contained in:
parent
b375e3a9c8
commit
0597f63815
3 changed files with 100 additions and 53 deletions
|
@ -60,7 +60,7 @@ public:
|
||||||
void SetLight ( const int iNewStatus );
|
void SetLight ( const int iNewStatus );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum ELightColor { RL_GREY, RL_RED, RL_GREEN, RL_YELLOW };
|
enum ELightColor { RL_GREY, RL_GREEN, RL_YELLOW, RL_RED };
|
||||||
ELightColor eColorFlag;
|
ELightColor eColorFlag;
|
||||||
|
|
||||||
void UpdateColor();
|
void UpdateColor();
|
||||||
|
|
|
@ -30,11 +30,7 @@
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
CMultiColorLEDBar::CMultiColorLEDBar ( QWidget* parent, Qt::WindowFlags f )
|
CMultiColorLEDBar::CMultiColorLEDBar ( QWidget* parent, Qt::WindowFlags f )
|
||||||
: QFrame ( parent, f ),
|
: QFrame ( parent, f )
|
||||||
BitmCubeRoundGrey ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDGreySmall.png" ) ),
|
|
||||||
BitmCubeRoundGreen ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDGreenSmall.png" ) ),
|
|
||||||
BitmCubeRoundYellow ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDYellowSmall.png" ) ),
|
|
||||||
BitmCubeRoundRed ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDRedSmall.png" ) )
|
|
||||||
{
|
{
|
||||||
// set total number of LEDs
|
// set total number of LEDs
|
||||||
iNumLEDs = NUM_STEPS_INP_LEV_METER;
|
iNumLEDs = NUM_STEPS_INP_LEV_METER;
|
||||||
|
@ -47,65 +43,103 @@ CMultiColorLEDBar::CMultiColorLEDBar ( QWidget* parent, Qt::WindowFlags f )
|
||||||
|
|
||||||
// create LEDs
|
// create LEDs
|
||||||
vecpLEDs.Init ( iNumLEDs );
|
vecpLEDs.Init ( iNumLEDs );
|
||||||
for ( int i = 0; i < iNumLEDs; i++ )
|
for ( int iLEDIdx = 0; iLEDIdx < iNumLEDs; iLEDIdx++ )
|
||||||
{
|
{
|
||||||
// create LED label
|
// create LED object
|
||||||
vecpLEDs[i] = new QLabel ( "", parent );
|
vecpLEDs[iLEDIdx] = new cLED ( parent );
|
||||||
|
|
||||||
// add LED to layout with spacer
|
// add LED to layout with spacer
|
||||||
pMainLayout->addStretch();
|
pMainLayout->addStretch();
|
||||||
pMainLayout->addWidget ( vecpLEDs[i] );
|
pMainLayout->addWidget ( vecpLEDs[iLEDIdx]->getLabelPointer() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set initial bitmap
|
CMultiColorLEDBar::~CMultiColorLEDBar()
|
||||||
vecpLEDs[i]->setPixmap ( BitmCubeRoundGrey );
|
{
|
||||||
|
// clean up the LED objects
|
||||||
// bitmap defines minimum size of the label
|
for ( int iLEDIdx = 0; iLEDIdx < iNumLEDs; iLEDIdx++ )
|
||||||
vecpLEDs[i]->setMinimumSize (
|
{
|
||||||
BitmCubeRoundGrey.width(), BitmCubeRoundGrey.height() );
|
delete vecpLEDs[iLEDIdx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMultiColorLEDBar::setValue ( const int value )
|
void CMultiColorLEDBar::setValue ( const int value )
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO speed optimiation: only change bitmaps of LEDs which
|
|
||||||
// actually have to be changed
|
|
||||||
|
|
||||||
// update state of all LEDs for current level value
|
// update state of all LEDs for current level value
|
||||||
for ( int i = 0; i < iNumLEDs; i++ )
|
for ( int iLEDIdx = 0; iLEDIdx < iNumLEDs; iLEDIdx++ )
|
||||||
{
|
{
|
||||||
// set active if value is above current LED index
|
// set active LED color if value is above current LED index
|
||||||
SetLED ( i, i < value );
|
if ( iLEDIdx < value )
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMultiColorLEDBar::SetLED ( const int iLEDIdx, const bool bActive )
|
|
||||||
{
|
|
||||||
if ( bActive )
|
|
||||||
{
|
{
|
||||||
// check which color we should use (green, yellow or red)
|
// check which color we should use (green, yellow or red)
|
||||||
if ( iLEDIdx < YELLOW_BOUND_INP_LEV_METER )
|
if ( iLEDIdx < YELLOW_BOUND_INP_LEV_METER )
|
||||||
{
|
{
|
||||||
// green region
|
// green region
|
||||||
vecpLEDs[iLEDIdx]->setPixmap ( BitmCubeRoundGreen );
|
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_GREEN );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( iLEDIdx < RED_BOUND_INP_LEV_METER )
|
if ( iLEDIdx < RED_BOUND_INP_LEV_METER )
|
||||||
{
|
{
|
||||||
// yellow region
|
// yellow region
|
||||||
vecpLEDs[iLEDIdx]->setPixmap ( BitmCubeRoundYellow );
|
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_YELLOW );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// red region
|
// red region
|
||||||
vecpLEDs[iLEDIdx]->setPixmap ( BitmCubeRoundRed );
|
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_RED );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we use grey LED for inactive state
|
// we use grey LED for inactive state
|
||||||
vecpLEDs[iLEDIdx]->setPixmap ( BitmCubeRoundGrey );
|
vecpLEDs[iLEDIdx]->setColor ( cLED::RL_GREY );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CMultiColorLEDBar::cLED::cLED ( QWidget* parent ) :
|
||||||
|
BitmCubeRoundGrey ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDGreySmall.png" ) ),
|
||||||
|
BitmCubeRoundGreen ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDGreenSmall.png" ) ),
|
||||||
|
BitmCubeRoundYellow ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDYellowSmall.png" ) ),
|
||||||
|
BitmCubeRoundRed ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDRedSmall.png" ) )
|
||||||
|
{
|
||||||
|
// create LED label
|
||||||
|
pLEDLabel = new QLabel ( "", parent );
|
||||||
|
|
||||||
|
// bitmap defines minimum size of the label
|
||||||
|
pLEDLabel->setMinimumSize (
|
||||||
|
BitmCubeRoundGrey.width(), BitmCubeRoundGrey.height() );
|
||||||
|
|
||||||
|
// set initial bitmap
|
||||||
|
pLEDLabel->setPixmap ( BitmCubeRoundGrey );
|
||||||
|
eCurLightColor = RL_GREY;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMultiColorLEDBar::cLED::setColor ( const ELightColor eNewColor )
|
||||||
|
{
|
||||||
|
// only update LED if color has changed
|
||||||
|
if ( eNewColor != eCurLightColor )
|
||||||
|
{
|
||||||
|
switch ( eNewColor )
|
||||||
|
{
|
||||||
|
case RL_GREY:
|
||||||
|
pLEDLabel->setPixmap ( BitmCubeRoundGrey );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RL_GREEN:
|
||||||
|
pLEDLabel->setPixmap ( BitmCubeRoundGreen );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RL_YELLOW:
|
||||||
|
pLEDLabel->setPixmap ( BitmCubeRoundYellow );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RL_RED:
|
||||||
|
pLEDLabel->setPixmap ( BitmCubeRoundRed );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
eCurLightColor = eNewColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,21 +40,34 @@ class CMultiColorLEDBar : public QFrame
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CMultiColorLEDBar ( QWidget* parent = 0, Qt::WindowFlags f = 0 );
|
CMultiColorLEDBar ( QWidget* parent = 0, Qt::WindowFlags f = 0 );
|
||||||
|
virtual ~CMultiColorLEDBar();
|
||||||
|
|
||||||
void setValue ( const int value );
|
void setValue ( const int value );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetLED ( const int iLEDIdx, const bool bActive = true );
|
class cLED
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum ELightColor { RL_GREY, RL_GREEN, RL_YELLOW, RL_RED };
|
||||||
|
|
||||||
|
cLED ( QWidget* parent );
|
||||||
|
void setColor ( const ELightColor eNewColor );
|
||||||
|
QLabel* getLabelPointer() { return pLEDLabel; }
|
||||||
|
|
||||||
|
protected:
|
||||||
QPixmap BitmCubeRoundGrey;
|
QPixmap BitmCubeRoundGrey;
|
||||||
QPixmap BitmCubeRoundGreen;
|
QPixmap BitmCubeRoundGreen;
|
||||||
QPixmap BitmCubeRoundYellow;
|
QPixmap BitmCubeRoundYellow;
|
||||||
QPixmap BitmCubeRoundRed;
|
QPixmap BitmCubeRoundRed;
|
||||||
|
|
||||||
|
ELightColor eCurLightColor;
|
||||||
|
QLabel* pLEDLabel;
|
||||||
|
};
|
||||||
|
|
||||||
QHBoxLayout* pMainLayout;
|
QHBoxLayout* pMainLayout;
|
||||||
|
|
||||||
int iNumLEDs;
|
int iNumLEDs;
|
||||||
CVector<QLabel*> vecpLEDs;
|
CVector<cLED*> vecpLEDs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _MULTCOLORLEDBAR_H__FD6B49B5_87DF_48DD_E1606C2AC__INCLUDED_
|
#endif // _MULTCOLORLEDBAR_H__FD6B49B5_87DF_48DD_E1606C2AC__INCLUDED_
|
||||||
|
|
Loading…
Add table
Reference in a new issue