author | unc0rr |
Fri, 16 Oct 2009 13:22:32 +0000 | |
changeset 2483 | a725063e8e05 |
parent 2098 | c977d7f2aa09 |
child 2948 | 3f21a9dc93d0 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
184 | 3 |
* Copyright (c) 2006 Andrey Korotaev <unC0Rr@gmail.com> |
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QPaintEvent> |
|
20 |
#include <QPainter> |
|
21 |
#include "SquareLabel.h" |
|
2098
c977d7f2aa09
Toggle for stars ("frontend effects") - also turns off optimisations for stars that were causing problems onone machine
nemo
parents:
2072
diff
changeset
|
22 |
#include "hwform.h" |
184 | 23 |
|
24 |
SquareLabel::SquareLabel(QWidget * parent) : |
|
310 | 25 |
QWidget(parent) |
184 | 26 |
{ |
2098
c977d7f2aa09
Toggle for stars ("frontend effects") - also turns off optimisations for stars that were causing problems onone machine
nemo
parents:
2072
diff
changeset
|
27 |
if(frontendEffects) setAttribute(Qt::WA_PaintOnScreen, true); |
184 | 28 |
} |
29 |
||
30 |
void SquareLabel::paintEvent(QPaintEvent * event) |
|
31 |
{ |
|
32 |
QPainter painter(this); |
|
33 |
int pixsize; |
|
34 |
if (width() > height()) { |
|
35 |
pixsize = height(); |
|
36 |
painter.translate((width() - pixsize) / 2, 0); |
|
37 |
} else { |
|
38 |
pixsize = width(); |
|
39 |
painter.translate(0, (height() - pixsize) / 2); |
|
40 |
} |
|
310 | 41 |
painter.drawPixmap(0, 0, pixsize, pixsize, pixmap.scaled(pixsize, pixsize, Qt::KeepAspectRatio)); |
184 | 42 |
} |
310 | 43 |
|
44 |
void SquareLabel::setPixmap(const QPixmap & pixmap) |
|
45 |
{ |
|
46 |
this->pixmap = pixmap; |
|
47 |
repaint(); |
|
48 |
} |