5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _BUTTONSWIDGET_H_
22 #define _BUTTONSWIDGET_H_
24 #include "radiouiaction.h"
25 #include "radiokeywidget.h"
29 #include <QStyleOption>
31 class ButtonsWidget
: public QWidget
37 explicit ButtonsWidget(QWidget
* parent
):
42 virtual void setStyleSheet(const QString
& sheet
)
44 defaultStyleSheet
= sheet
;
45 QWidget::setStyleSheet(sheet
);
48 RadioKeyWidget
* addArea(const QRect
& rect
, const char * image
, RadioUiAction
* action
= NULL
)
50 return addArea(QPolygon(rect
), image
, action
);
53 RadioKeyWidget
* addArea(const QPolygon
& polygon
, const char * image
, RadioUiAction
* action
= NULL
)
55 RadioKeyWidget
* btn
= new RadioKeyWidget(polygon
, image
, action
, this);
56 m_buttons
.append(btn
);
57 connect(btn
, &RadioKeyWidget::imageChanged
, this, &ButtonsWidget::setBitmap
);
63 void setBitmap(QString bitmap
)
65 QString css
= defaultStyleSheet
;
66 if (!bitmap
.isEmpty())
67 css
= QString("background:url(:/images/simulator/%1);").arg(bitmap
);
69 QWidget::setStyleSheet(css
);
73 void onMouseButtonEvent(bool press
, QMouseEvent
* event
)
75 if (!(event
->button() & (Qt::LeftButton
| Qt::MidButton
))) {
80 foreach(RadioKeyWidget
* key
, m_buttons
) {
81 if (key
->contains(event
->pos())) {
86 else if (key
->getValue()) {
93 virtual void mousePressEvent(QMouseEvent
* event
)
95 onMouseButtonEvent(true, event
);
97 virtual void mouseReleaseEvent(QMouseEvent
* event
)
99 onMouseButtonEvent(false, event
);
102 void paintEvent(QPaintEvent
*)
107 style()->drawPrimitive(QStyle::PE_Widget
, &opt
, &p
, this);
110 QList
<RadioKeyWidget
*> m_buttons
;
111 QString defaultStyleSheet
;
114 #endif // _BUTTONSWIDGET_H_