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 |
{
|
|
23 |
QVBoxLayout * l = new QVBoxLayout(this);
|
|
24 |
setLayout(l);
|
|
25 |
|
|
26 |
pbMain = new QPushButton(this);
|
|
27 |
pbMain->setCheckable(true);
|
|
28 |
|
|
29 |
QPixmap pm(":/res/btnDisabled.png");
|
|
30 |
QPainter * painter = new QPainter();
|
|
31 |
|
|
32 |
pmChecked.load(img);
|
|
33 |
pmDisabled.load(img);
|
|
34 |
|
|
35 |
l->addWidget(pbMain);
|
|
36 |
|
|
37 |
painter->begin(&pmDisabled);
|
|
38 |
painter->drawPixmap(pmDisabled.rect(), pm);
|
|
39 |
painter->end();
|
|
40 |
|
|
41 |
pbMain->setIconSize(pmDisabled.size());
|
|
42 |
pbMain->setIcon(pmDisabled);
|
|
43 |
|
|
44 |
connect(pbMain, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool)));
|
|
45 |
|
|
46 |
lbMain = new QLabel(this);
|
|
47 |
lbMain->setFixedHeight(32);
|
|
48 |
|
|
49 |
l->addWidget(lbMain);
|
|
50 |
}
|
|
51 |
|
|
52 |
ToggleButtonWidget::~ToggleButtonWidget()
|
|
53 |
{
|
|
54 |
delete pbMain;
|
|
55 |
delete lbMain;
|
|
56 |
}
|
|
57 |
|
|
58 |
bool ToggleButtonWidget::isChecked()
|
|
59 |
{
|
|
60 |
return pbMain->isChecked();
|
|
61 |
}
|
|
62 |
|
|
63 |
void ToggleButtonWidget::setChecked(bool checked)
|
|
64 |
{
|
|
65 |
pbMain->setChecked(checked);
|
|
66 |
}
|
|
67 |
|
|
68 |
void ToggleButtonWidget::setText(QString s)
|
|
69 |
{
|
|
70 |
lbMain->setText(s);
|
|
71 |
}
|
|
72 |
|
|
73 |
void ToggleButtonWidget::eventToggled(bool checked)
|
|
74 |
{
|
|
75 |
if (checked) pbMain->setIcon(pmChecked); else pbMain->setIcon(pmDisabled);
|
|
76 |
}
|