QTfrontend/togglebutton.cpp
author koda
Sat, 06 Mar 2010 13:52:56 +0000
changeset 2956 f3db27564808
parent 2948 3f21a9dc93d0
child 3061 e129e4c3f30e
permissions -rw-r--r--
ifrontend: add the missing panels
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
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    23
    QVBoxLayout * l = new QVBoxLayout(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    24
    setLayout(l);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    25
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    26
    pbMain = new QPushButton(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    27
    pbMain->setCheckable(true);
2377
f3fab2b09e0c And in frontend
nemo
parents: 1933
diff changeset
    28
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    29
    QPixmap pm(":/res/btnDisabled.png");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    30
    QPainter * painter = new QPainter();
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    31
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    32
    pmChecked.load(img);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    33
    pmDisabled.load(img);
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
    pbMain->setMaximumWidth(pmChecked.width() + 6);
1933
7b8b0a9032d3 - perform lupdate-qt4
unc0rr
parents: 1932
diff changeset
    36
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    37
    l->addWidget(pbMain);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    38
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    39
    painter->begin(&pmDisabled);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    40
    painter->drawPixmap(pmDisabled.rect(), pm);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    41
    painter->end();
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    42
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    43
    pbMain->setIconSize(pmDisabled.size());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    44
    pbMain->setIcon(pmDisabled);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    45
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    46
    connect(pbMain, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool)));
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    47
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    48
    lbMain = new QLabel(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    49
    lbMain->setWordWrap(true);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    50
//  lbMain->setFixedHeight(32);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    51
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    52
    l->addWidget(lbMain);
1932
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
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    57
    delete pbMain;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    58
    delete lbMain;
1932
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
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    63
    return pbMain->isChecked();
1932
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
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    68
    pbMain->setChecked(checked);
1932
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
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    73
    lbMain->setText(s);
1932
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
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    78
    if (checked) pbMain->setIcon(pmChecked); else pbMain->setIcon(pmDisabled);
1932
f586d75c8b6a New schemes page look by TheXception
unc0rr
parents:
diff changeset
    79
}