QTfrontend/togglebutton.cpp
author nemo
Sun, 24 Jan 2010 16:46:06 +0000
changeset 2712 8f4527c9137c
parent 2377 f3fab2b09e0c
child 2948 3f21a9dc93d0
permissions -rw-r--r--
Minor tweak, try to make long flavour text last longer, move the hurt self messages to unused messages group, so they don't get wiped by crate an instant later.
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);
2377
f3fab2b09e0c And in frontend
nemo
parents: 1933
diff changeset
    28
1932
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
1933
7b8b0a9032d3 - perform lupdate-qt4
unc0rr
parents: 1932
diff changeset
    35
	pbMain->setMaximumWidth(pmChecked.width() + 6);
7b8b0a9032d3 - perform lupdate-qt4
unc0rr
parents: 1932
diff changeset
    36
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    37
	l->addWidget(pbMain);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    38
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    39
	painter->begin(&pmDisabled);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    40
	painter->drawPixmap(pmDisabled.rect(), pm);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    41
	painter->end();
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    42
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    43
	pbMain->setIconSize(pmDisabled.size());
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    44
	pbMain->setIcon(pmDisabled);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    45
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    46
	connect(pbMain, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool)));
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    47
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    48
	lbMain = new QLabel(this);
1933
7b8b0a9032d3 - perform lupdate-qt4
unc0rr
parents: 1932
diff changeset
    49
	lbMain->setWordWrap(true);
7b8b0a9032d3 - perform lupdate-qt4
unc0rr
parents: 1932
diff changeset
    50
//	lbMain->setFixedHeight(32);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    51
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    52
	l->addWidget(lbMain);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    53
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    54
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    55
ToggleButtonWidget::~ToggleButtonWidget()
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    56
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    57
	delete pbMain;
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    58
	delete lbMain;
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    59
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    60
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    61
bool ToggleButtonWidget::isChecked()
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    62
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    63
	return pbMain->isChecked();
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    64
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    65
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    66
void ToggleButtonWidget::setChecked(bool checked)
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    67
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    68
	pbMain->setChecked(checked);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    69
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    70
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    71
void ToggleButtonWidget::setText(QString s)
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    72
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    73
	lbMain->setText(s);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    74
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    75
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    76
void ToggleButtonWidget::eventToggled(bool checked)
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    77
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    78
	if (checked) pbMain->setIcon(pmChecked); else pbMain->setIcon(pmDisabled);
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    79
}