QTfrontend/drawmapscene.h
changeset 7006 6af78154dc62
parent 6952 7f70f37bbf08
child 9080 9b42757d7e71
equal deleted inserted replaced
6852:9e724f4863a3 7006:6af78154dc62
     1 /*
     1 /*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2012 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     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
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    19 #ifndef DRAWMAPSCENE_H
    19 #ifndef DRAWMAPSCENE_H
    20 #define DRAWMAPSCENE_H
    20 #define DRAWMAPSCENE_H
    21 
    21 
    22 #include <QGraphicsScene>
    22 #include <QGraphicsScene>
    23 #include <QPainterPath>
    23 #include <QPainterPath>
       
    24 #include <QGraphicsEllipseItem>
    24 
    25 
    25 class QGraphicsPathItem;
    26 class QGraphicsPathItem;
    26 
    27 
    27 typedef QList<QPair<quint8, QList<QPoint> > > Paths;
    28 struct PathParams
       
    29 {
       
    30     quint8 width;
       
    31     bool erasing;
       
    32     QList<QPoint> points;
       
    33 };
       
    34 
       
    35 typedef QList<PathParams> Paths;
    28 
    36 
    29 class DrawMapScene : public QGraphicsScene
    37 class DrawMapScene : public QGraphicsScene
    30 {
    38 {
    31         Q_OBJECT
    39         Q_OBJECT
    32     public:
    40     public:
    33         explicit DrawMapScene(QObject *parent = 0);
    41         explicit DrawMapScene(QObject *parent = 0);
    34 
    42 
    35         QByteArray encode();
    43         QByteArray encode();
    36         void decode(QByteArray data);
    44         void decode(QByteArray data);
       
    45         int pointsCount();
    37 
    46 
    38     signals:
    47     signals:
    39         void pathChanged();
    48         void pathChanged();
    40 
    49 
    41     public slots:
    50     public slots:
    42         void undo();
    51         void undo();
    43         void clearMap();
    52         void clearMap();
    44         void simplifyLast();
    53         void simplifyLast();
       
    54         void setErasing(bool erasing);
       
    55         void showCursor();
       
    56         void hideCursor();
    45 
    57 
    46     private:
    58     private:
    47         QPen m_pen;
    59         QPen m_pen;
       
    60         QBrush m_eraser;
    48         QBrush m_brush;
    61         QBrush m_brush;
    49         QGraphicsPathItem  * m_currPath;
    62         QGraphicsPathItem  * m_currPath;
    50         Paths paths;
    63         Paths paths;
    51         Paths oldPaths;
    64         Paths oldPaths;
       
    65         bool m_isErasing;
    52         QList<QGraphicsItem *> oldItems;
    66         QList<QGraphicsItem *> oldItems;
       
    67         QGraphicsEllipseItem * m_cursor;
       
    68         bool m_isCursorShown;
    53 
    69 
    54         virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent);
    70         virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent);
    55         virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent);
    71         virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent);
    56         virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent);
    72         virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent);
    57         virtual void wheelEvent(QGraphicsSceneWheelEvent *);
    73         virtual void wheelEvent(QGraphicsSceneWheelEvent *);