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