author | unc0rr |
Fri, 22 Aug 2014 00:37:26 +0400 | |
changeset 10391 | ce3ccc45d790 |
parent 10235 | bafca1686867 |
child 11046 | 47a8c19ecb60 |
permissions | -rw-r--r-- |
4976 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
9998 | 3 |
* Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 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 |
|
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
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4976 | 17 |
*/ |
18 |
||
4423 | 19 |
#ifndef DRAWMAPSCENE_H |
20 |
#define DRAWMAPSCENE_H |
|
21 |
||
22 |
#include <QGraphicsScene> |
|
4442 | 23 |
#include <QPainterPath> |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
24 |
#include <QGraphicsEllipseItem> |
4423 | 25 |
|
4426 | 26 |
class QGraphicsPathItem; |
27 |
||
6873 | 28 |
struct PathParams |
29 |
{ |
|
30 |
quint8 width; |
|
31 |
bool erasing; |
|
9551 | 32 |
QPoint initialPoint; |
6873 | 33 |
QList<QPoint> points; |
34 |
}; |
|
35 |
||
36 |
typedef QList<PathParams> Paths; |
|
4427 | 37 |
|
4423 | 38 |
class DrawMapScene : public QGraphicsScene |
39 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
40 |
Q_OBJECT |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
41 |
public: |
9551 | 42 |
enum PathType { |
43 |
Polyline = 0, |
|
44 |
Rectangle = 1, |
|
45 |
Ellipse = 2 |
|
46 |
}; |
|
47 |
||
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
48 |
explicit DrawMapScene(QObject *parent = 0); |
4423 | 49 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
50 |
QByteArray encode(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
51 |
void decode(QByteArray data); |
6935 | 52 |
int pointsCount(); |
4427 | 53 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
54 |
signals: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
55 |
void pathChanged(); |
4423 | 56 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
57 |
public slots: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
58 |
void undo(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
59 |
void clearMap(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
60 |
void simplifyLast(); |
10235 | 61 |
void optimize(); |
6873 | 62 |
void setErasing(bool erasing); |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
63 |
void showCursor(); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
64 |
void hideCursor(); |
9551 | 65 |
void setPathType(PathType pathType); |
4423 | 66 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
67 |
private: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
68 |
QPen m_pen; |
6873 | 69 |
QBrush m_eraser; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
70 |
QBrush m_brush; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
71 |
QGraphicsPathItem * m_currPath; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
72 |
Paths paths; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
73 |
Paths oldPaths; |
6873 | 74 |
bool m_isErasing; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
75 |
QList<QGraphicsItem *> oldItems; |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
76 |
QGraphicsEllipseItem * m_cursor; |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
77 |
bool m_isCursorShown; |
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
78 |
QByteArray m_specialPoints; |
9551 | 79 |
PathType m_pathType; |
4424 | 80 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
81 |
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
82 |
virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
83 |
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent); |
6781 | 84 |
virtual void wheelEvent(QGraphicsSceneWheelEvent *); |
4442 | 85 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
86 |
QPainterPath pointsToPath(const QList<QPoint> points); |
6781 | 87 |
|
88 |
quint8 serializePenWidth(int width); |
|
89 |
int deserializePenWidth(quint8 width); |
|
9551 | 90 |
QList<QPointF> makeEllipse(const QPointF & center, const QPointF & corner); |
9555 | 91 |
QPointF putSomeConstraints(const QPointF & initialPoint, const QPointF & point); |
4423 | 92 |
}; |
93 |
||
94 |
#endif // DRAWMAPSCENE_H |