author | nemo |
Wed, 24 Mar 2010 18:01:49 +0000 | |
changeset 3060 | 0c5f5f13eef4 |
parent 2948 | 3f21a9dc93d0 |
child 3061 | e129e4c3f30e |
permissions | -rw-r--r-- |
1932 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2009 Kristian Lehmann <email@thexception.net> |
|
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 "togglebutton.h" |
|
20 |
||
21 |
ToggleButtonWidget::ToggleButtonWidget(QWidget * parent, QString img) |
|
22 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
23 |
QVBoxLayout * l = new QVBoxLayout(this); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
24 |
setLayout(l); |
1932 | 25 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
26 |
pbMain = new QPushButton(this); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
27 |
pbMain->setCheckable(true); |
2377 | 28 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
29 |
QPixmap pm(":/res/btnDisabled.png"); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
30 |
QPainter * painter = new QPainter(); |
1932 | 31 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
32 |
pmChecked.load(img); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
33 |
pmDisabled.load(img); |
1932 | 34 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
35 |
pbMain->setMaximumWidth(pmChecked.width() + 6); |
1933 | 36 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
37 |
l->addWidget(pbMain); |
1932 | 38 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
39 |
painter->begin(&pmDisabled); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
40 |
painter->drawPixmap(pmDisabled.rect(), pm); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
41 |
painter->end(); |
1932 | 42 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
43 |
pbMain->setIconSize(pmDisabled.size()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
44 |
pbMain->setIcon(pmDisabled); |
1932 | 45 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
46 |
connect(pbMain, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool))); |
1932 | 47 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
48 |
lbMain = new QLabel(this); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
49 |
lbMain->setWordWrap(true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
50 |
// lbMain->setFixedHeight(32); |
1932 | 51 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
52 |
l->addWidget(lbMain); |
1932 | 53 |
} |
54 |
||
55 |
ToggleButtonWidget::~ToggleButtonWidget() |
|
56 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
57 |
delete pbMain; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
58 |
delete lbMain; |
1932 | 59 |
} |
60 |
||
61 |
bool ToggleButtonWidget::isChecked() |
|
62 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
63 |
return pbMain->isChecked(); |
1932 | 64 |
} |
65 |
||
66 |
void ToggleButtonWidget::setChecked(bool checked) |
|
67 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
68 |
pbMain->setChecked(checked); |
1932 | 69 |
} |
70 |
||
71 |
void ToggleButtonWidget::setText(QString s) |
|
72 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
73 |
lbMain->setText(s); |
1932 | 74 |
} |
75 |
||
76 |
void ToggleButtonWidget::eventToggled(bool checked) |
|
77 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
78 |
if (checked) pbMain->setIcon(pmChecked); else pbMain->setIcon(pmDisabled); |
1932 | 79 |
} |