QTfrontend/ui/widget/togglebutton.cpp
author Wuzzy <Wuzzy2@mail.ru>
Mon, 01 Apr 2019 23:15:18 +0200
changeset 14758 123aaa2bf4b5
parent 13243 480dcc29391c
permissions -rw-r--r--
Make dark clan colors visible in stats screen
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
13243
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    27
    QPixmap pixOffOverlay(":/res/btnDisabled.png");
2948
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
13243
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    30
    QPixmap pixOn = QPixmap(img);
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    31
    QPixmap pixOff = QPixmap(img);
13159
6f189da00c25 Fix disabled button rendering
unc0rr
parents: 11046
diff changeset
    32
13243
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    33
    // Use the same image for disabled (i.e. non-clickable) button.
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    34
    // The default would be gray which is a little bit hard on the eye.
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    35
    // The disabled state is communicated to the user by the button
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    36
    // border, which turns gray.
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    37
    icoChecked.addPixmap(pixOn, QIcon::Normal);
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    38
    icoChecked.addPixmap(pixOn, QIcon::Disabled);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    39
13243
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    40
    pixOff.setDevicePixelRatio(pixOffOverlay.devicePixelRatio());
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    41
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    42
    setMaximumWidth(pixOn.width() + 6);
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    43
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    44
    painter->begin(&pixOff);
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    45
    painter->drawPixmap(pixOff.rect(), pixOffOverlay);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    46
    painter->end();
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    47
13243
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    48
    icoUnchecked.addPixmap(pixOff, QIcon::Normal);
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    49
    icoUnchecked.addPixmap(pixOff, QIcon::Disabled);
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    50
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    51
    setIconSize(pixOff.size());
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    52
    setIcon(icoUnchecked);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    53
3061
e129e4c3f30e Frontend:
smxx
parents: 2948
diff changeset
    54
    connect(this, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool)));
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    55
}
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    56
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    57
ToggleButtonWidget::~ToggleButtonWidget()
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    58
{
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
void ToggleButtonWidget::eventToggled(bool checked)
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    62
{
13243
480dcc29391c Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
Wuzzy <Wuzzy2@mail.ru>
parents: 13159
diff changeset
    63
    setIcon(checked ? icoChecked : icoUnchecked);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    64
}