QTfrontend/drawmapscene.h
author sheepluva
Thu, 23 Jan 2014 13:56:53 +0100
changeset 10061 b7161f00a6ca
parent 9998 736015b847e3
child 10108 c68cf030eded
permissions -rw-r--r--
hide complete IP of other users, when non-admin requests player info. showing the first two parts of the IP was kinda pointless to begin with (what for?) and has recently lead to increased abuse and lobby flooding due to bots collecting/posting IP tracking information
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
     1
/*
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
     2
 * Hedgewars, a free turn based strategy game
9998
736015b847e3 update copyright to 2014
sheepluva
parents: 9555
diff changeset
     3
 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
     4
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
     8
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
    12
 * GNU General Public License for more details.
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
    13
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
    14
 * You should have received a copy of the GNU General Public License
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
    15
 * along with this program; if not, write to the Free Software
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
    17
 */
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
    18
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    19
#ifndef DRAWMAPSCENE_H
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    20
#define DRAWMAPSCENE_H
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    21
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    22
#include <QGraphicsScene>
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    23
#include <QPainterPath>
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    24
#include <QGraphicsEllipseItem>
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    25
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    26
class QGraphicsPathItem;
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    27
6873
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    28
struct PathParams
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    29
{
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    30
    quint8 width;
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    31
    bool erasing;
9551
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
    32
    QPoint initialPoint;
6873
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    33
    QList<QPoint> points;
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    34
};
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    35
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    36
typedef QList<PathParams> Paths;
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    37
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    38
class DrawMapScene : public QGraphicsScene
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    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
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
    42
        enum PathType {
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
    43
            Polyline  = 0,
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
    44
            Rectangle = 1,
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
    45
            Ellipse   = 2
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
    46
        };
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
    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
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    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
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
    52
        int pointsCount();
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    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
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    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();
6873
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    61
        void setErasing(bool erasing);
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    62
        void showCursor();
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    63
        void hideCursor();
9551
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
    64
        void setPathType(PathType pathType);
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    65
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    66
    private:
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    67
        QPen m_pen;
6873
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    68
        QBrush m_eraser;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    69
        QBrush m_brush;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    70
        QGraphicsPathItem  * m_currPath;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    71
        Paths paths;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    72
        Paths oldPaths;
6873
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    73
        bool m_isErasing;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    74
        QList<QGraphicsItem *> oldItems;
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    75
        QGraphicsEllipseItem * m_cursor;
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    76
        bool m_isCursorShown;
9472
265e5997580e Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents: 9080
diff changeset
    77
        QByteArray m_specialPoints;
9551
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
    78
        PathType m_pathType;
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    79
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    80
        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent);
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    81
        virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent);
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    82
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent);
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
    83
        virtual void wheelEvent(QGraphicsSceneWheelEvent *);
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    84
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    85
        QPainterPath pointsToPath(const QList<QPoint> points);
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
    86
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
    87
        quint8 serializePenWidth(int width);
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
    88
        int deserializePenWidth(quint8 width);
9551
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
    89
        QList<QPointF> makeEllipse(const QPointF & center, const QPointF & corner);
9555
485b424be769 uhm... a feature
unc0rr
parents: 9551
diff changeset
    90
        QPointF putSomeConstraints(const QPointF & initialPoint, const QPointF & point);
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    91
};
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    92
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    93
#endif // DRAWMAPSCENE_H