|
1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2008-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation; version 2 of the License |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 */ |
|
18 |
|
19 #include <QPainter> |
|
20 #include <QPoint> |
|
21 #include <QStylePainter> |
|
22 #include <QStyleOptionGroupBox> |
|
23 |
|
24 #include "igbox.h" |
|
25 |
|
26 IconedGroupBox::IconedGroupBox(QWidget * parent) |
|
27 : QGroupBox(parent) |
|
28 { |
|
29 // Has issues with border-radius on children |
|
30 // setAttribute(Qt::WA_PaintOnScreen, true); |
|
31 titleLeftPadding = 49; |
|
32 contentTopPadding = 15; |
|
33 } |
|
34 |
|
35 void IconedGroupBox::setIcon(const QIcon & icon) |
|
36 { |
|
37 if (this->icon.isNull()) |
|
38 setStyleSheet(QString( |
|
39 "IconedGroupBox{" |
|
40 "margin-top: 46px;" |
|
41 "margin-left: 12px;" |
|
42 "padding: %1px 2px 5px 2px;" |
|
43 "}" |
|
44 "IconedGroupBox::title{" |
|
45 "subcontrol-origin: margin;" |
|
46 "subcontrol-position: top left;" |
|
47 "padding-left: %2px;" |
|
48 "padding-top: %1px;" |
|
49 "text-align: left;" |
|
50 "}" |
|
51 ).arg(contentTopPadding).arg(titleLeftPadding) |
|
52 ); |
|
53 |
|
54 this->icon = icon; |
|
55 repaint(); |
|
56 } |
|
57 |
|
58 void IconedGroupBox::paintEvent(QPaintEvent * event) |
|
59 { |
|
60 Q_UNUSED(event); |
|
61 |
|
62 QStylePainter painter(this); |
|
63 |
|
64 QStyleOptionGroupBox option; |
|
65 initStyleOption(&option); |
|
66 painter.drawComplexControl(QStyle::CC_GroupBox, option); |
|
67 |
|
68 icon.paint(&painter, QRect(QPoint(0, 0), icon.actualSize(size()))); |
|
69 } |
|
70 |
|
71 void IconedGroupBox::setTitleTextPadding(int px) |
|
72 { |
|
73 titleLeftPadding = px; |
|
74 } |
|
75 |
|
76 void IconedGroupBox::setContentTopPadding(int px) |
|
77 { |
|
78 contentTopPadding = px; |
|
79 } |