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