2009-05-01 12:55:51 +02:00
|
|
|
/******************************************************************************\
|
|
|
|
* Copyright (c) 2004-2009
|
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Implements a multi color LED bar
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
|
|
|
#include "multicolorledbar.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Implementation *************************************************************/
|
|
|
|
CMultiColorLEDBar::CMultiColorLEDBar ( QWidget* parent, Qt::WindowFlags f )
|
|
|
|
: QLabel ( parent, f ),
|
2009-05-01 16:00:53 +02:00
|
|
|
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" ) )
|
2009-05-01 12:55:51 +02:00
|
|
|
{
|
2009-05-01 16:00:53 +02:00
|
|
|
// set total number of LEDs
|
|
|
|
iNumLEDs = NUM_STEPS_INP_LEV_METER;
|
2009-05-01 12:55:51 +02:00
|
|
|
|
2009-05-01 16:00:53 +02:00
|
|
|
// create layout and set spacing to zero
|
|
|
|
pMainLayout = new QHBoxLayout ( this );
|
|
|
|
pMainLayout->setSpacing ( 0 );
|
|
|
|
|
|
|
|
// create LEDs
|
|
|
|
vecpLEDs.Init ( iNumLEDs );
|
|
|
|
for ( int i = 0; i < iNumLEDs; i++ )
|
|
|
|
{
|
|
|
|
// create LED label
|
|
|
|
vecpLEDs[i] = new QLabel ( "", parent );
|
|
|
|
|
|
|
|
// add LED to layout
|
|
|
|
pMainLayout->addWidget ( vecpLEDs[i] );
|
|
|
|
|
|
|
|
// set initial bitmap
|
|
|
|
vecpLEDs[i]->setPixmap ( BitmCubeRoundGrey );
|
|
|
|
|
|
|
|
// bitmap defines minimum size of the label
|
|
|
|
vecpLEDs[i]->setMinimumSize (
|
|
|
|
BitmCubeRoundGrey.width(), BitmCubeRoundGrey.height() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMultiColorLEDBar::setValue ( const int value )
|
|
|
|
{
|
|
|
|
|
|
|
|
// TODO speed optimiation: only change bitmaps of LEDs which
|
|
|
|
// actually have to be changed
|
|
|
|
|
|
|
|
// use green LEDs for the range from 0 to the YELLOW_BOUND_INP_LEV_METER,
|
|
|
|
// yellow in the range YELLOW_BOUND_INP_LEV_METER to
|
|
|
|
// RED_BOUND_INP_LEV_METER and red for up to value and grey for the rest
|
|
|
|
for ( int i = 0; i < iNumLEDs; i++ )
|
|
|
|
{
|
|
|
|
if ( i < value )
|
|
|
|
{
|
|
|
|
// we are below current input level, check which color
|
|
|
|
// we should use (green, yellow or red)
|
|
|
|
if ( i < YELLOW_BOUND_INP_LEV_METER )
|
|
|
|
{
|
|
|
|
// green region
|
|
|
|
vecpLEDs[i]->setPixmap ( BitmCubeRoundGreen );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( i < RED_BOUND_INP_LEV_METER )
|
|
|
|
{
|
|
|
|
// yellow region
|
|
|
|
vecpLEDs[i]->setPixmap ( BitmCubeRoundYellow );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// red region
|
|
|
|
vecpLEDs[i]->setPixmap ( BitmCubeRoundRed );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we are above current input level -> use grey LED
|
|
|
|
vecpLEDs[i]->setPixmap ( BitmCubeRoundGrey );
|
|
|
|
}
|
|
|
|
}
|
2009-05-01 12:55:51 +02:00
|
|
|
}
|