author | alfadur |
Wed, 16 May 2018 19:36:49 -0400 | |
changeset 13392 | ff1fb8757026 |
parent 13243 | 480dcc29391c |
permissions | -rw-r--r-- |
1932 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2009 Kristian Lehmann <email@thexception.net> |
|
11046 | 4 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
1932 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; version 2 of the License |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
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 | 18 |
*/ |
19 |
||
20 |
#include "togglebutton.h" |
|
21 |
||
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 | 24 |
{ |
3061 | 25 |
setCheckable(true); |
2377 | 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 | 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 | 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 | 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 | 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 | 53 |
|
3061 | 54 |
connect(this, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool))); |
1932 | 55 |
} |
56 |
||
57 |
ToggleButtonWidget::~ToggleButtonWidget() |
|
58 |
{ |
|
59 |
} |
|
60 |
||
61 |
void ToggleButtonWidget::eventToggled(bool checked) |
|
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 | 64 |
} |