src/analog/led.cpp

changeset 316
dcd472be9ae8
child 319
d1861707054c
equal deleted inserted replaced
315:cf4e83cecdb5 316:dcd472be9ae8
1 /***************************************************************************
2 * Copyright (C) 2006-2008 by Tomasz Ziobrowski *
3 * http://www.3electrons.com *
4 * e-mail: t.ziobrowski@3electrons.com *
5 * *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
22
23 #include <QtGui>
24 #include "led.h"
25
26
27 Led::Led(QWidget * parent):WidgetWithBackground(parent)
28 {
29 m_checked = true;
30 m_color = Qt::red;
31 resize(330,330);
32 }
33
34
35 bool Led::isChecked () const
36 {
37 return m_checked;
38 }
39
40
41 void Led::setChecked(bool i)
42 {
43 m_checked = i;
44 updateWithBackground();
45 checkChanged( m_checked );
46 }
47
48
49 QColor Led::color() const
50 {
51 return m_color;
52 }
53
54
55 void Led::setColor(QColor i)
56 {
57 m_color = i;
58 updateWithBackground();
59 }
60
61 // Maluje całą diodę - koło o kolorze bazowym a na to nakłada odblask.
62 void Led::paintEvent(QPaintEvent * /* event*/ )
63 {
64 QPainter painter(this);
65 initCoordinateSystem(painter);
66 // *** Draw circle */
67 int h,s,v,a;
68 QColor c,back = color();
69 c=back;
70
71 // Kolor diody
72 if (!m_checked || !isEnabled())
73 {
74 back.getHsv(&h,&s,&v,&a);
75 s*=0.20;
76 back.setHsv(h,s,v,a);
77 }
78 painter.setBrush(back);
79
80 // obwudka diody
81 QPen pen;
82 // przyciemnienie obwudki
83 c.getHsv(&h,&s,&v,&a);
84 s*=0.5;
85 c.setHsv(h,s,v,a);
86
87 pen.setColor(c);
88 pen.setWidthF(3.0);
89
90 painter.drawEllipse(-149,-149,299,299);
91 painter.end();
92
93 // odblask światła diody
94 drawBackground(); // to maluje na tym co dotychczas to co jest w bitmapce
95 }
96
97
98 // Rysuje odblask swiatła na diodzie
99 void Led::paintBackground(QPainter & painter)
100 {
101 initCoordinateSystem(painter);
102 painter.setPen(Qt::NoPen);
103 QRadialGradient shine(QPointF(-40.0,-40.0),120.0,QPointF(-40,-40));
104 QColor white1(255,255,255,200);
105 QColor white0(255,255,255,0);
106
107 shine.setColorAt(0.0,white1);
108 shine.setColorAt(1.0,white0);
109
110 painter.setBrush(shine);
111 painter.drawEllipse(-147,-147,297,297);
112
113 }
114
115 void Led::initCoordinateSystem(QPainter & painter)
116 {
117 int side = qMin(width(), height());
118 // inicjalizacja paintera
119 painter.setRenderHint(QPainter::Antialiasing);
120 painter.translate(width() / 2, height() / 2);
121 painter.scale(side / 330.0, side / 330.0);
122 }
123

mercurial