-
Notifications
You must be signed in to change notification settings - Fork 0
/
myview.h
150 lines (127 loc) · 3.16 KB
/
myview.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef MYVIEW_H
#define MYVIEW_H
#include <QGraphicsView>
#include <QMimeData>
#include <QGraphicsSimpleTextItem>
#include "Dialogs/posdialog.h"
#include <myscene.h>
#include "mainwindow.h"
#include "command.h"
class Command;
class MainWindow;
class MyView : public QGraphicsView
{
Q_OBJECT
public:
explicit MyView(QWidget *parent = 0);
~MyView();
MyScene* getScene();
MainWindow* getMainWindow();
void updateCenterRect();
void setSaved(bool flag);
bool IsSaved();
void setNew(bool flag);
bool IsNew();
void setDraftFile(bool flag);
bool isDraftFile();
void SetMoveFlag(bool flag);
void showStatus(QString msg);
void catchPt(QPointF pt);
bool goCatch();
QPointF getP3();
QBrush getBrush();
QPen getPen();
QPointF getScenePos();
void changeCursor(const QString& shape);
void changeCursor(Qt::CursorShape shape);
private:
MyScene* m_scene;
PosDialog* dlg;
Command* Cmd;
MainWindow* m_main;
enum DrawFlag{
drawNone = 0x0,
drawCirPt = 0x1,
drawCross = 0x2,
drawPtXY = 0x4,
drawLine = 0x8,
drawLineXY = 0x10,
drawLineAH = 0x20,
drawRect = 0x40,
drawRectXY = 0x80,
drawElli = 0x100,
drawElliXY = 0x200,
drawRing = 0x400,
drawText = 0x800,
drawDividePt = 0x1000,
dragZoom = 0x1001,
drawDraft = 0x1002
};
DrawFlag flag;
bool m_drawMulti;
QVector<QGraphicsLineItem*> LineVec;
QVector<QGraphicsRectItem*> RectVec;
QVector<QGraphicsEllipseItem*> ElliVec;
int LineCount,RectCount,ElliCount;
QGraphicsSimpleTextItem* Text;
QPointF StartPt;
enum MouseMode
{
NORMAL,
DRAG,
EDIT,
ZOOM
};
MouseMode mode;
QPointF dragBegin;
QGraphicsItem *viewCenter;
QPointF pastePos;
bool m_copied, m_movable, m_catch, m_full;
bool m_saved, m_new, m_draft;
QTransform m_translate;
// 画笔样式
Qt::PenStyle PenStyle;
int PenWidth;
QColor PenColor;
QBrush PenBrush;
QPen pen;
QFont TextFont;
QPointF p2;
private:
void InitView();
void InitParameters();
void InitViewRect();
int getPenWidth();
Qt::PenStyle getPenStyle();
QColor getColor();
bool pressCtrlKey(QKeyEvent *event, int key);
QString inputMultiText(bool multi);
public slots:
void DrawPt();
void DrawLine();
void DrawRect();
void DrawEllipse();
void DrawTexts();
void setCatch(bool on);
void setFullView(bool full);
QFont getFont();
void ShowContextMenu(); //加右键菜单
void setZoomMode(bool on);
void setDraftMode(bool on);
void setNormalMode();
void Locate(); //重置原点
void Reset(); //重置放缩倍数
void Copy();
void Paste();
void Delete();
void Empty();
void Translate(int direction);
void showItemInfo();
protected:
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event);
void keyPressEvent(QKeyEvent *event);
};
#endif // MYVIEW_H