QTfrontend/togglebutton.cpp
author unc0rr
Thu, 02 Apr 2009 20:37:03 +0000
changeset 1932 f586d75c8b6a
child 1933 7b8b0a9032d3
permissions -rw-r--r--
New schemes page look by TheXception
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     1
/*
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2009 Kristian Lehmann <email@thexception.net>
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     4
 *
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     8
 *
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    13
 *
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    17
 */
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    18
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    19
#include "togglebutton.h"
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    20
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    21
ToggleButtonWidget::ToggleButtonWidget(QWidget * parent, QString img)
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    22
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    23
	QVBoxLayout * l = new QVBoxLayout(this);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    24
	setLayout(l);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    25
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    26
	pbMain = new QPushButton(this);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    27
	pbMain->setCheckable(true);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    28
	
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    29
	QPixmap pm(":/res/btnDisabled.png");
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    30
	QPainter * painter = new QPainter();
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    31
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    32
	pmChecked.load(img);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    33
	pmDisabled.load(img);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    34
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    35
	l->addWidget(pbMain);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    36
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    37
	painter->begin(&pmDisabled);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    38
	painter->drawPixmap(pmDisabled.rect(), pm);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    39
	painter->end();
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    40
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    41
	pbMain->setIconSize(pmDisabled.size());
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    42
	pbMain->setIcon(pmDisabled);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    43
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    44
	connect(pbMain, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool)));
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    45
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    46
	lbMain = new QLabel(this);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    47
	lbMain->setFixedHeight(32);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    48
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    49
	l->addWidget(lbMain);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    50
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    51
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    52
ToggleButtonWidget::~ToggleButtonWidget()
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    53
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    54
	delete pbMain;
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    55
	delete lbMain;
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    56
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    57
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    58
bool ToggleButtonWidget::isChecked()
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    59
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    60
	return pbMain->isChecked();
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    61
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    62
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    63
void ToggleButtonWidget::setChecked(bool checked)
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    64
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    65
	pbMain->setChecked(checked);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    66
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    67
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    68
void ToggleButtonWidget::setText(QString s)
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    69
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    70
	lbMain->setText(s);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    71
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    72
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    73
void ToggleButtonWidget::eventToggled(bool checked)
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    74
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    75
	if (checked) pbMain->setIcon(pmChecked); else pbMain->setIcon(pmDisabled);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    76
}