-
Notifications
You must be signed in to change notification settings - Fork 0
/
myscene.h
71 lines (64 loc) · 1.65 KB
/
myscene.h
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
#ifndef MYSCENE_H
#define MYSCENE_H
#include "Items/baseitem.h"
#include "Items/circlept.h"
#include "Items/crosspt.h"
#include "Items/ring.h"
#include "Items/myline.h"
#include <QDataStream>
#include <myview.h>
class MyView; //需要前置声明
class MyScene : public QGraphicsScene
{
Q_OBJECT
public:
enum SIZE{
width = 1200,
height = 800
};
enum GridMode
{
POINT,
GRID,
NONE
};
GridMode mode;
public:
explicit MyScene(QObject *parent = Q_NULLPTR);
virtual ~MyScene();
void InitText();
void InitData();
void InitShape();
void InitScene();
void UnloadScene();
// QSet<QList<QGraphicsItem*> > set; //不要写成>>,否则报错
void Save(QDataStream& s);
void Export(QDataStream& s,QList<QGraphicsItem*> items);
bool Load(QDataStream& s);
void Import(QDataStream& s,int count);
void setMode(GridMode m);
void setDraftMode(bool on);
void selectPen(QPen p);
QRectF itemsBoundingRect() const;
MyView* getCurrentView();
private:
enum{
min_space = 20,
space = min_space * 5
};
QPen pen;
QGraphicsLineItem *AxisX, *AxisY;
QGraphicsPolygonItem *ArrowX, *ArrowY;
QGraphicsEllipseItem *Origin;
QGraphicsSimpleTextItem *X, *Y;
bool m_draft,m_pressed;
qreal x,y;
QGraphicsItem* tempItem;
MyView* view;
protected:
void drawBackground(QPainter * painter, const QRectF & rect);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
};
#endif // MYSCENE_H