1 | /*************************************************************************** |
---|
2 | * Copyright (C) 2010 by Tn * |
---|
3 | * thenobody@poczta.fm * |
---|
4 | * * |
---|
5 | * This program is free software; you can redistribute it and/or modify * |
---|
6 | * it under the terms of the GNU Library General Public License as * |
---|
7 | * published by the Free Software Foundation; either version 3 of the * |
---|
8 | * License, or (at your option) any later version. * |
---|
9 | * * |
---|
10 | * This program is distributed in the hope that it will be useful, * |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
---|
13 | * GNU General Public License for more details. * |
---|
14 | * * |
---|
15 | * You should have received a copy of the GNU Library General Public * |
---|
16 | * License along with this program; if not, write to the * |
---|
17 | * Free Software Foundation, Inc., * |
---|
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
---|
19 | ***************************************************************************/ |
---|
20 | |
---|
21 | #include <QPainter> |
---|
22 | |
---|
23 | #include "qledindicator.h" |
---|
24 | |
---|
25 | const qreal QLedIndicator::scaledSize = 2500; /* Visual Studio static const mess */ |
---|
26 | |
---|
27 | QLedIndicator::QLedIndicator(QWidget *parent) : QAbstractButton(parent) |
---|
28 | { |
---|
29 | setMinimumSize(24,24); |
---|
30 | setCheckable(true); |
---|
31 | onColor1 = QColor(0,255,0); |
---|
32 | onColor2 = QColor(0,192,0); |
---|
33 | offColor1 = QColor(0,28,0); |
---|
34 | offColor2 = QColor(0,128,0); |
---|
35 | onColor1r = QColor(255,0,0); |
---|
36 | onColor2r = QColor(192,0,0); |
---|
37 | offColor1r = QColor(28,0,0); |
---|
38 | offColor2r = QColor(128,0,0); |
---|
39 | |
---|
40 | red= false; |
---|
41 | } |
---|
42 | |
---|
43 | void QLedIndicator::resizeEvent(QResizeEvent *event) { |
---|
44 | update(); |
---|
45 | } |
---|
46 | |
---|
47 | void QLedIndicator::paintEvent(QPaintEvent *event) { |
---|
48 | |
---|
49 | qreal realSize = qMin(width(), height()); |
---|
50 | |
---|
51 | QRadialGradient gradient; |
---|
52 | QPainter painter(this); |
---|
53 | QPen pen(Qt::black); |
---|
54 | pen.setWidth(1); |
---|
55 | |
---|
56 | painter.setRenderHint(QPainter::Antialiasing); |
---|
57 | painter.translate(width()/2, height()/2); |
---|
58 | painter.scale(realSize/scaledSize, realSize/scaledSize); |
---|
59 | |
---|
60 | gradient = QRadialGradient (QPointF(-500,-500), 1500, QPointF(-500,-500)); |
---|
61 | gradient.setColorAt(0, QColor(224,224,224)); |
---|
62 | gradient.setColorAt(1, QColor(28,28,28)); |
---|
63 | painter.setPen(pen); |
---|
64 | painter.setBrush(QBrush(gradient)); |
---|
65 | painter.drawEllipse(QPointF(0,0), 500, 500); |
---|
66 | |
---|
67 | gradient = QRadialGradient (QPointF(500,500), 1500, QPointF(500,500)); |
---|
68 | gradient.setColorAt(0, QColor(224,224,224)); |
---|
69 | gradient.setColorAt(1, QColor(28,28,28)); |
---|
70 | painter.setPen(pen); |
---|
71 | painter.setBrush(QBrush(gradient)); |
---|
72 | painter.drawEllipse(QPointF(0,0), 450, 450); |
---|
73 | |
---|
74 | painter.setPen(pen); |
---|
75 | if (red) |
---|
76 | { |
---|
77 | if( isChecked() ) { |
---|
78 | gradient = QRadialGradient (QPointF(-500,-500), 1500, QPointF(-500,-500)); |
---|
79 | gradient.setColorAt(0, onColor1r); |
---|
80 | gradient.setColorAt(1, onColor2r); |
---|
81 | } else { |
---|
82 | gradient = QRadialGradient (QPointF(500,500), 1500, QPointF(500,500)); |
---|
83 | gradient.setColorAt(0, offColor1r); |
---|
84 | gradient.setColorAt(1, offColor2r); |
---|
85 | } |
---|
86 | } |
---|
87 | else { |
---|
88 | if( isChecked() ) { |
---|
89 | gradient = QRadialGradient (QPointF(-500,-500), 1500, QPointF(-500,-500)); |
---|
90 | gradient.setColorAt(0, onColor1); |
---|
91 | gradient.setColorAt(1, onColor2); |
---|
92 | } else { |
---|
93 | gradient = QRadialGradient (QPointF(500,500), 1500, QPointF(500,500)); |
---|
94 | gradient.setColorAt(0, offColor1); |
---|
95 | gradient.setColorAt(1, offColor2); |
---|
96 | } |
---|
97 | } |
---|
98 | painter.setBrush(gradient); |
---|
99 | painter.drawEllipse(QPointF(0,0), 400, 400); |
---|
100 | } |
---|
101 | |
---|