author | unc0rr |
Thu, 05 Oct 2006 16:33:18 +0000 | |
changeset 183 | 57c2ef19f719 |
parent 182 | 0ca777e942d6 |
child 184 | f97a7a3dc8f6 |
permissions | -rw-r--r-- |
182
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
1 |
/* |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
2 |
* Hedgewars, a worms-like game |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
3 |
* Copyright (c) 2006 Igor Ulyanov <iulyanov@gmail.com> |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
4 |
* |
183 | 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 |
|
182
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
8 |
* |
183 | 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. |
|
182
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
13 |
* |
183 | 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 |
|
182
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
17 |
*/ |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
18 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
19 |
#include "mapContainer.h" |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
20 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
21 |
#include <QPushButton> |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
22 |
#include <QBuffer> |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
23 |
#include <QUuid> |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
24 |
#include <QBitmap> |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
25 |
#include <QPainter> |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
26 |
#include <QLinearGradient> |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
27 |
#include <QColor> |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
28 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
29 |
HWMapContainer::HWMapContainer(QWidget * parent) : |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
30 |
QWidget(parent), mainLayout(this) |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
31 |
{ |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
32 |
imageButt=new QPushButton(this); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
33 |
imageButt->setMaximumSize(256, 128); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
34 |
imageButt->setFlat(true); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
35 |
imageButt->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
36 |
mainLayout.addWidget(imageButt); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
37 |
connect(imageButt, SIGNAL(clicked()), this, SLOT(changeImage())); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
38 |
changeImage(); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
39 |
} |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
40 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
41 |
void HWMapContainer::setImage(const QImage newImage) |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
42 |
{ |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
43 |
QPixmap px(256, 128); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
44 |
QPixmap pxres(256, 128); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
45 |
QPainter p(&pxres); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
46 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
47 |
px.fill(Qt::yellow); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
48 |
QBitmap bm = QBitmap::fromImage(newImage); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
49 |
px.setMask(bm); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
50 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
51 |
QLinearGradient linearGrad(QPoint(128, 0), QPoint(128, 128)); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
52 |
linearGrad.setColorAt(0, QColor(0, 0, 192)); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
53 |
linearGrad.setColorAt(1, QColor(0, 0, 64)); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
54 |
p.fillRect(QRect(0, 0, 256, 128), linearGrad); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
55 |
p.drawPixmap(QPoint(0, 0), px); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
56 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
57 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
58 |
imageButt->setIcon(pxres); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
59 |
imageButt->setIconSize(QSize(256, 128)); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
60 |
} |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
61 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
62 |
void HWMapContainer::changeImage() |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
63 |
{ |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
64 |
pMap=new HWMap(); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
65 |
connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage))); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
66 |
m_seed = QUuid::createUuid().toString(); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
67 |
pMap->getImage(m_seed.toStdString()); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
68 |
} |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
69 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
70 |
QString HWMapContainer::getCurrentSeed() const |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
71 |
{ |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
72 |
return m_seed; |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
73 |
} |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
74 |
|
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
75 |
void HWMapContainer::resizeEvent ( QResizeEvent * event ) |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
76 |
{ |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
77 |
//imageButt->setIconSize(imageButt->size()); |
0ca777e942d6
Preview with gradient, get rid of workaround with memory buffer
unc0rr
parents:
172
diff
changeset
|
78 |
} |