QTfrontend/ui/widget/togglebutton.cpp
author sheepluva
Mon, 11 Jan 2016 22:23:14 +0100
changeset 11497 66f1cff4284b
parent 11046 47a8c19ecb60
child 13159 6f189da00c25
permissions -rw-r--r--
stop screenshot-flash-effects from showing up on consecutive screenshots
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>
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     4
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     5
 *
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     8
 * the Free Software Foundation; version 2 of the License
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
     9
 *
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    13
 * GNU General Public License for more details.
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    14
 *
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    18
 */
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    19
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    20
#include "togglebutton.h"
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    21
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    22
ToggleButtonWidget::ToggleButtonWidget(QWidget * parent, QString img)
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 3061
diff changeset
    23
    : QPushButton(parent)
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    24
{
3061
e129e4c3f30e Frontend:
smxx
parents: 2948
diff changeset
    25
    setCheckable(true);
2377
f3fab2b09e0c And in frontend
nemo
parents: 1933
diff changeset
    26
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    27
    QPixmap pm(":/res/btnDisabled.png");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    28
    QPainter * painter = new QPainter();
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    29
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    30
    pmChecked.load(img);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    31
    pmDisabled.load(img);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    32
3061
e129e4c3f30e Frontend:
smxx
parents: 2948
diff changeset
    33
    setMaximumWidth(pmChecked.width() + 6);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    34
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    35
    painter->begin(&pmDisabled);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    36
    painter->drawPixmap(pmDisabled.rect(), pm);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    37
    painter->end();
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    38
3061
e129e4c3f30e Frontend:
smxx
parents: 2948
diff changeset
    39
    setIconSize(pmDisabled.size());
e129e4c3f30e Frontend:
smxx
parents: 2948
diff changeset
    40
    setIcon(pmDisabled);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    41
3061
e129e4c3f30e Frontend:
smxx
parents: 2948
diff changeset
    42
    connect(this, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool)));
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    43
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    44
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    45
ToggleButtonWidget::~ToggleButtonWidget()
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    46
{
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    47
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    48
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    49
void ToggleButtonWidget::eventToggled(bool checked)
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    50
{
3061
e129e4c3f30e Frontend:
smxx
parents: 2948
diff changeset
    51
    setIcon(checked ? pmChecked : pmDisabled);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    52
}