1 /******************************************************************************\
2 * Copyright (c) 2004-2020
3 *
4 * Author(s):
5 * Volker Fischer
6 *
7 * Description:
8 * Implements a multi color LED
9 *
10 ******************************************************************************
11 *
12 * This program is free software; you can redistribute it and/or modify it under
13 * the terms of the GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the License, or (at your option) any later
15 * version.
16 *
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 *
26 \******************************************************************************/
27
28 #include "multicolorled.h"
29
30 /* Implementation *************************************************************/
CMultiColorLED(QWidget * parent)31 CMultiColorLED::CMultiColorLED ( QWidget* parent ) :
32 QLabel ( parent ),
33 BitmCubeDisabled ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDDisabledSmall.png" ) ),
34 BitmCubeGrey ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDGreySmall.png" ) ),
35 BitmCubeGreen ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDGreenSmall.png" ) ),
36 BitmCubeYellow ( QString::fromUtf8 ( ":/png/LEDs/res/IndicatorYellowFancy.png" ) ),
37 BitmCubeRed ( QString::fromUtf8 ( ":/png/LEDs/res/IndicatorRedFancy.png" ) ),
38 BitmIndicatorGreen ( QString::fromUtf8 ( ":/png/LEDs/res/IndicatorGreen.png" ) ),
39 BitmIndicatorYellow ( QString::fromUtf8 ( ":/png/LEDs/res/IndicatorYellow.png" ) ),
40 BitmIndicatorRed ( QString::fromUtf8 ( ":/png/LEDs/res/IndicatorRed.png" ) )
41 {
42 // set init bitmap
43 setPixmap ( BitmCubeGrey );
44 eColorFlag = RL_GREY;
45
46 // set default type and reset
47 eType = MT_LED;
48 Reset();
49 }
50
SetType(const EType eNType)51 void CMultiColorLED::SetType ( const EType eNType )
52 {
53 eType = eNType;
54 Reset();
55 }
56
changeEvent(QEvent * curEvent)57 void CMultiColorLED::changeEvent ( QEvent* curEvent )
58 {
59 // act on enabled changed state
60 if ( curEvent->type() == QEvent::EnabledChange )
61 {
62 if ( isEnabled() )
63 {
64 setPixmap ( BitmCubeGrey );
65 eColorFlag = RL_GREY;
66 }
67 else
68 {
69 setPixmap ( BitmCubeDisabled );
70 eColorFlag = RL_DISABLED;
71 }
72 }
73 }
74
SetColor(const ELightColor eNewColorFlag)75 void CMultiColorLED::SetColor ( const ELightColor eNewColorFlag )
76 {
77 switch ( eNewColorFlag )
78 {
79 case RL_RED:
80 // red
81 if ( eColorFlag != RL_RED )
82 {
83 if ( eType == MT_LED )
84 {
85 setPixmap ( BitmCubeRed );
86 }
87 else
88 {
89 setPixmap ( BitmIndicatorRed );
90 }
91 setAccessibleDescription ( tr ( "Red" ) );
92 eColorFlag = RL_RED;
93 }
94 break;
95
96 case RL_YELLOW:
97 // yellow
98 if ( eColorFlag != RL_YELLOW )
99 {
100 if ( eType == MT_LED )
101 {
102 setPixmap ( BitmCubeYellow );
103 }
104 else
105 {
106 setPixmap ( BitmIndicatorYellow );
107 }
108 setAccessibleDescription ( tr ( "Yellow" ) );
109 eColorFlag = RL_YELLOW;
110 }
111 break;
112
113 case RL_GREEN:
114 // green
115 if ( eColorFlag != RL_GREEN )
116 {
117 if ( eType == MT_LED )
118 {
119 setPixmap ( BitmCubeGreen );
120 }
121 else
122 {
123 setPixmap ( BitmIndicatorGreen );
124 }
125 setAccessibleDescription ( tr ( "Green" ) );
126 eColorFlag = RL_GREEN;
127 }
128 break;
129
130 default:
131 // if no color is active, set control to grey light
132 if ( eColorFlag != RL_GREY )
133 {
134 if ( eType == MT_LED )
135 {
136 setPixmap ( BitmCubeGrey );
137 }
138 else
139 {
140 // make it invisible if in indicator mode
141 setPixmap ( QPixmap() );
142 }
143 eColorFlag = RL_GREY;
144 }
145 break;
146 }
147 }
148
Reset()149 void CMultiColorLED::Reset()
150 {
151 if ( isEnabled() )
152 {
153 // set color flag to disable to make sure the pixmap gets updated
154 eColorFlag = RL_DISABLED;
155 SetColor ( RL_GREY );
156 }
157 }
158
SetLight(const ELightColor eNewStatus)159 void CMultiColorLED::SetLight ( const ELightColor eNewStatus )
160 {
161 if ( isEnabled() )
162 {
163 SetColor ( eNewStatus );
164 }
165 }
166