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
):
27 fPixmapRect(0, 0, 0, 0)
34 // matching fLastColor
35 fPixmap
.load(":/scalable/led_off.svg");
38 void LEDButton::setColor(Color color
)
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);
56 if (fLastColor
!= fColor
)
61 fPixmap
.load(":/scalable/led_off.svg");
64 fPixmap
.load(":/scalable/led_blue.svg");
67 fPixmap
.load(":/scalable/led_green.svg");
70 fPixmap
.load(":/scalable/led_red.svg");
73 fPixmap
.load(":/scalable/led_yellow.svg");
82 else if (fLastColor
!= OFF
)
84 fPixmap
.load(":/scalable/led_off.svg");
88 painter
.drawPixmap(fPixmapRect
, fPixmap
, fPixmapRect
);