Cleanup
[carla.git] / source / frontend / widgets / ledbutton.cpp
blobc575594a9f0cfe60f21e1a3ce6119c9604afd7c1
1 /*
2 * LED Button, a custom Qt4 widget
3 * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "ledbutton.hpp"
20 #include <QtGui/QPainter>
21 #include <QtGui/QPaintEvent>
23 LEDButton::LEDButton(QWidget* parent):
24 QPushButton(parent),
25 fColor(OFF),
26 fLastColor(OFF),
27 fPixmapRect(0, 0, 0, 0)
29 setCheckable(true);
30 setText("");
32 setColor(BLUE);
34 // matching fLastColor
35 fPixmap.load(":/scalable/led_off.svg");
38 void LEDButton::setColor(Color color)
40 fColor = color;
41 int size = 14;
43 fPixmapRect = QRectF(0, 0, size, size);
45 setMinimumSize(size, size);
46 setMaximumSize(size, size);
49 void LEDButton::paintEvent(QPaintEvent* event)
51 QPainter painter(this);
52 event->accept();
54 if (isChecked())
56 if (fLastColor != fColor)
58 switch (fColor)
60 case OFF:
61 fPixmap.load(":/scalable/led_off.svg");
62 break;
63 case BLUE:
64 fPixmap.load(":/scalable/led_blue.svg");
65 break;
66 case GREEN:
67 fPixmap.load(":/scalable/led_green.svg");
68 break;
69 case RED:
70 fPixmap.load(":/scalable/led_red.svg");
71 break;
72 case YELLOW:
73 fPixmap.load(":/scalable/led_yellow.svg");
74 break;
75 default:
76 return;
79 fLastColor = fColor;
82 else if (fLastColor != OFF)
84 fPixmap.load(":/scalable/led_off.svg");
85 fLastColor = OFF;
88 painter.drawPixmap(fPixmapRect, fPixmap, fPixmapRect);