myGraphicsScene.h 1.97 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef MYGRAPHICSSCENE_H
#define MYGRAPHICSSCENE_H

#include <vector>

#include <QGraphicsScene>

#include "crazyFlyZone.h"
#include "tablePiece.h"

class QGraphicsSceneMouseEvent;
class QPointF;
class QColor;


class myGraphicsScene : public QGraphicsScene
{
    Q_OBJECT

public:

    explicit myGraphicsScene(QObject *parent = 0);
    std::vector<crazyFlyZone*> crazyfly_zones;
    std::vector<tablePiece*> table_pieces;
    int getMode();

    void setMode(int new_mode);
    void setGrid(bool enable);

    void hideTable();
    void showTable();

    void hideCrazyFlyZones();
    void showCrazyFlyZones();

    QRectF getRectFCrazyFlyZone(int index);

    enum {mode_table, mode_crazyfly_zones, mode_locked};

    void removeTable();

public slots:
    void removeCrazyFlyZone(int index);
    void setSelectedCrazyFlyZone(int index);
    void changeModeTo(int next_mode);

signals:
    void numCrazyFlyZonesChanged(int newNum);
    void crazyFlyZoneSelected(int index);
    void modeChanged(int mode);
    void numTablePiecesChanged(int newNum);

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override;

    void keyPressEvent(QKeyEvent * keyEvent) override;
    void drawBackground(QPainter *painter, const QRectF &rect);

private:
    void lockTablePieces(void);
    void unlockTablePieces(void);
    void lockCrazyFlyZones(void);
    void unlockCrazyFlyZones(void);

    void addCrazyFlyZoneToVector(crazyFlyZone* rect);
    void addTablePieceToVector(tablePiece* rect);
    int checkSelectedCrazyFlyZone();
    void updateIndexesAndLabelsCrazyFlyZones();
    void removeTablePiece(int index);

    QPen* pen;
    QBrush* brush;
    QRectF* tmp_rect;
    crazyFlyZone* tmp_crazyfly_zone_item;
    tablePiece* tmp_table_piece_item;
    QPointF* p1;
    QPointF* p2;

    bool startedRect;
    int mode;
    bool grid_enable;
};

#endif