DAWorkbench 0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
DAGraphicsView.h
1#ifndef DAGRAPHICSVIEW_H
2#define DAGRAPHICSVIEW_H
3#include <QGraphicsView>
4#include "DAGraphicsViewGlobal.h"
5#include "DAGraphicsItem.h"
6#include "DAGraphicsViewOverlayMouseMarker.h"
7class QWheelEvent;
8namespace DA
9{
10class DAAbstractGraphicsViewAction;
21class DAGRAPHICSVIEW_API DAGraphicsView : public QGraphicsView
22{
23 Q_OBJECT
24 DA_DECLARE_PRIVATE(DAGraphicsView)
25public:
30 {
31 ZoomNotUseWheel = 0x0001,
32 ZoomUseWheel = 0x0002,
33 ZoomUseWheelAndCtrl = 0x0004
34 };
35 Q_DECLARE_FLAGS(ZoomFlags, ZoomFlag)
36 Q_FLAG(ZoomFlag)
37
38
42 {
43 PadDiable = 0x0001,
44 PadByWheelMiddleButton = 0x0002,
45 PadBySpaceWithMouseLeftButton = 0x0004
46 };
47 Q_DECLARE_FLAGS(PadFlags, PadFlag)
48 Q_FLAG(PadFlag)
49
50public:
51 DAGraphicsView(QWidget* parent = 0);
52 DAGraphicsView(QGraphicsScene* scene, QWidget* parent = 0);
54 // 设置缩放的因子
55 void setScaleRange(qreal min, qreal max);
56 // 获取缩放因子
57 qreal getScaleMaxFactor() const;
58 qreal getScaleMinFactor() const;
59
60 // 设置是否可以滚轮缩放
61 bool isEnaleWheelZoom() const;
62 void setEnaleWheelZoom(bool enaleWheelZoom = true, ZoomFlags zf = ZoomUseWheelAndCtrl);
63
64 // 获取鼠标对应的scence的位置坐标
65 QPointF getMouseScenePos() const;
66
67 // 设置缩放flag
68 void setZoomFrags(ZoomFlags zf);
69 ZoomFlags getZoomFlags() const;
70
71 // 判断是否在拖动
72 bool isPadding() const;
73 // 设置拖动属性
74 void setPaddingFrags(PadFlags pf);
75 PadFlags getPaddingFrags() const;
76 // 选中的item
77 QList< DAGraphicsItem* > selectedDAItems() const;
78 // 是否空格被按下
79 bool isSpacebarPressed() const;
80 // 激活一个动作,DAAbstractGraphicsViewAction的内存归view管理,此函数发射viewActionActived
81 void setupViewAction(DAAbstractGraphicsViewAction* act);
82 // 清除视图action,此操作会把当前维护的视图action清除
83 void clearViewAction();
84 // 标记一个点,标记完成后
85 void markPoint(const QPointF& scenePoint, const QPen& pen = QPen(Qt::blue));
86 // 是否marker生效
87 bool isEnableMarker() const;
88 // 获取当前的markerstyle,如果没生效,返回DAGraphicsViewOverlayMouseMarker::NoMarkerStyle
89 DAGraphicsViewOverlayMouseMarker::MarkerStyle getCurrentMarkerStyle() const;
90 // 获取marker指针
91 DAGraphicsViewOverlayMouseMarker* getMarker() const;
92public slots:
93 // 放大
94 void zoomIn();
95 // 缩小
96 void zoomOut();
97 // 设置最适合视图尺寸
98 void zoomFit();
99 // 选中所有可选的item
100 void selectAll();
101 // 取消所有选中
102 void clearSelection();
103 // 设置标记,此操作基于DAGraphicsViewOverlayMouseMarker
104 void setViewMarkerStyle(DAGraphicsViewOverlayMouseMarker::MarkerStyle style);
105 // 设置标记是否生效
106 void setViewMarkerEnable(bool on);
107
108protected:
109 virtual void wheelEvent(QWheelEvent* event) override;
110 virtual void mouseMoveEvent(QMouseEvent* event) override;
111 virtual void mousePressEvent(QMouseEvent* event) override;
112 virtual void mouseReleaseEvent(QMouseEvent* event) override;
113 virtual void keyPressEvent(QKeyEvent* event) override;
114 virtual void keyReleaseEvent(QKeyEvent* event) override;
115 virtual void resizeEvent(QResizeEvent* event) override;
116
117protected:
118 void wheelZoom(QWheelEvent* event);
119 // 开始拖动
120 void startPad(QMouseEvent* event);
121 // 结束拖动
122 void endPad();
123 // 创建鼠标标记,如果重载了DAGraphicsViewOverlayMouseMarker,需要重载此函数返回自己的MouseMarker
124 virtual DAGraphicsViewOverlayMouseMarker* createMarker();
125
126private:
127 void init();
128 //
129 void tryInitViewMarker();
130Q_SIGNALS:
136
142
143private:
144};
145}
146#endif // GGRAPHICSVIEW_H
针对DAGraphicsView的action.
Definition DAAbstractGraphicsViewAction.h:17
用于显示十字线的遮罩窗口
Definition DAGraphicsViewOverlayMouseMarker.h:19
MarkerStyle
标记样式
Definition DAGraphicsViewOverlayMouseMarker.h:25
支持缩放和拖动的GraphicsView
Definition DAGraphicsView.h:22
PadFlag
表征拖动状态
Definition DAGraphicsView.h:42
void viewActionActived(DA::DAAbstractGraphicsViewAction *act)
一个视图动作被激活的信号
ZoomFlag
缩放设置
Definition DAGraphicsView.h:30
void viewActionDeactived(DA::DAAbstractGraphicsViewAction *act)
一个视图动作已经解除激活的信号
序列化类都是带异常的,使用中需要处理异常
Definition AppMainWindow.cpp:44