|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QIcon>
|
|
|
|
|
#include "IxInterface.h"
|
|
|
|
|
#include "ZxRenderView.h"
|
|
|
|
|
|
|
|
|
|
class QPointF;
|
|
|
|
|
class ZxRenderView;
|
|
|
|
|
class ZxToolPrivate;
|
|
|
|
|
class ZxCompoundTool;
|
|
|
|
|
|
|
|
|
|
/// 图形工具
|
|
|
|
|
class I_PLOTBASE_EXPORT ZxTool : public QObject
|
|
|
|
|
, virtual public IxInterface
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
ZxTool();
|
|
|
|
|
~ZxTool();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
ZxTool* getRootTool() const;
|
|
|
|
|
ZxRenderView* getView() const;
|
|
|
|
|
ZxSceneItem* getScene() const;
|
|
|
|
|
ZxToolState* getState() const;
|
|
|
|
|
|
|
|
|
|
ZxSelection getSelection() const;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
// 最后活动的工具
|
|
|
|
|
virtual ZxTool* getLastActivateTool();
|
|
|
|
|
|
|
|
|
|
// 键是否按下
|
|
|
|
|
bool isLeftDown();
|
|
|
|
|
bool isRightDown();
|
|
|
|
|
|
|
|
|
|
// 鼠标左键或右键按下时的控制键状态
|
|
|
|
|
Qt::KeyboardModifiers getDownModifiers() const;
|
|
|
|
|
|
|
|
|
|
// 鼠标当前控制键状态
|
|
|
|
|
Qt::KeyboardModifiers getCurrentModifiers() const;
|
|
|
|
|
|
|
|
|
|
// 鼠标左键或右键按下的位置
|
|
|
|
|
const QPointF& getDownPos();
|
|
|
|
|
|
|
|
|
|
// 鼠标当前位置
|
|
|
|
|
const QPointF& getCurrentPos();
|
|
|
|
|
|
|
|
|
|
// 鼠标前一个位置
|
|
|
|
|
const QPointF& getPreviousPos();
|
|
|
|
|
|
|
|
|
|
// 鼠标左键或右键按下后到最后一次移动之间拖出来的矩形区域
|
|
|
|
|
QRectF getTrackRect();
|
|
|
|
|
|
|
|
|
|
// 在鼠标按下和抬起之间没有移动, 是一个点击操作.
|
|
|
|
|
bool isClick();
|
|
|
|
|
|
|
|
|
|
// 激活项
|
|
|
|
|
ZxRenderItem* getActiveItem();
|
|
|
|
|
void setActiveItem(ZxRenderItem* p);
|
|
|
|
|
|
|
|
|
|
// 引用次数
|
|
|
|
|
int addRef();
|
|
|
|
|
int release();
|
|
|
|
|
|
|
|
|
|
// 刷新视图(视图坐标系)
|
|
|
|
|
virtual void updateViewport();
|
|
|
|
|
virtual void updateViewport(const QRectF& rect);
|
|
|
|
|
virtual void updateViewport(float x, float y, float width, float height);
|
|
|
|
|
|
|
|
|
|
// 刷新场景(场景坐标系)
|
|
|
|
|
virtual void updateScene();
|
|
|
|
|
virtual void updateScene(const QRectF& rect);
|
|
|
|
|
virtual void updateScene(float x, float y, float width, float height);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
// 鼠标左键按下前后处理(通常是一些状态处理)
|
|
|
|
|
virtual void beforeLeftDown(const QPointF& pt);
|
|
|
|
|
virtual void afterLeftUp(const QPointF& pt);
|
|
|
|
|
|
|
|
|
|
/// 左键按下
|
|
|
|
|
/// @param pt 位置
|
|
|
|
|
/// @return 已处理返回true, 未处理返回false
|
|
|
|
|
virtual bool onLeftDown(const QPointF& pt) = 0;
|
|
|
|
|
|
|
|
|
|
/// 左键抬起
|
|
|
|
|
/// @param pt 位置
|
|
|
|
|
/// @return 已处理返回true, 未处理返回false
|
|
|
|
|
virtual bool onLeftUp(const QPointF& pt) = 0;
|
|
|
|
|
|
|
|
|
|
/// 右键按下
|
|
|
|
|
/// @param pt 位置
|
|
|
|
|
/// @return 已处理返回true, 未处理返回false
|
|
|
|
|
virtual bool onRightDown(const QPointF& pt) = 0;
|
|
|
|
|
|
|
|
|
|
/// 右键抬起
|
|
|
|
|
/// @param pt 位置
|
|
|
|
|
/// @return 已处理返回true, 未处理返回false
|
|
|
|
|
virtual bool onRightUp(const QPointF& pt) = 0;
|
|
|
|
|
|
|
|
|
|
/// 滚轮滚动
|
|
|
|
|
/// @param pt 位置
|
|
|
|
|
/// @param delta 滚动行数
|
|
|
|
|
/// @return 已处理返回true, 未处理返回false
|
|
|
|
|
virtual bool onMouseWheel(const QPointF& pt, int delta) = 0;
|
|
|
|
|
|
|
|
|
|
/// 鼠标移动
|
|
|
|
|
/// @param pt 位置
|
|
|
|
|
/// @return 已处理返回true, 未处理返回false
|
|
|
|
|
virtual bool onMouseMove(const QPointF& pt) = 0;
|
|
|
|
|
|
|
|
|
|
/// 左键双击
|
|
|
|
|
/// @param pt 位置
|
|
|
|
|
/// @return 已处理返回true, 未处理返回false
|
|
|
|
|
virtual bool onLeftDoubleClick(const QPointF& pt) = 0;
|
|
|
|
|
|
|
|
|
|
/// 键按下
|
|
|
|
|
virtual void onKeyPress(QKeyEvent* event);
|
|
|
|
|
|
|
|
|
|
/// 键抬起
|
|
|
|
|
virtual void onKeyRelease(QKeyEvent* event);
|
|
|
|
|
|
|
|
|
|
/// 绘制工具的拖曳线/拖曳框等临时的辅助元素
|
|
|
|
|
virtual void onPaint(QPainter* painter, const ZxPaintParam& param);
|
|
|
|
|
|
|
|
|
|
/// 使最后移动的区域无效
|
|
|
|
|
virtual void updateLastMoveArea(bool trackOnly);
|
|
|
|
|
|
|
|
|
|
/// 工具名称
|
|
|
|
|
virtual QString getText() const;
|
|
|
|
|
virtual void setText(const QString& s);
|
|
|
|
|
|
|
|
|
|
/// 工具图标
|
|
|
|
|
virtual void setIcon(const QIcon& icon);
|
|
|
|
|
virtual void setIcon(const QString& iconName);
|
|
|
|
|
virtual QIcon getIcon() const;
|
|
|
|
|
|
|
|
|
|
/// 工具提示
|
|
|
|
|
virtual QString getToolTip() const;
|
|
|
|
|
virtual void setToolTip(const QString& s);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/// enabled.
|
|
|
|
|
virtual void setEnabled(bool b);
|
|
|
|
|
virtual bool isEnabled() const;
|
|
|
|
|
|
|
|
|
|
/// active.
|
|
|
|
|
virtual bool isActive() const;
|
|
|
|
|
|
|
|
|
|
/// tracking
|
|
|
|
|
virtual void setMouseTracking(bool b);
|
|
|
|
|
virtual bool isMouseTracking() const;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
virtual QPointF calcSnapPos(const QPointF& pt) const;
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
|
|
/// 激活
|
|
|
|
|
virtual void activate();
|
|
|
|
|
virtual void deactivate();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
/// 工具激活
|
|
|
|
|
virtual void onActivated();
|
|
|
|
|
virtual void onDeactivated();
|
|
|
|
|
|
|
|
|
|
/// 选择状态改变
|
|
|
|
|
virtual void onSelectionChanged(ZxSelection& selection);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
void _setCurrentView(ZxRenderView* p);
|
|
|
|
|
void _attachView(ZxRenderView* p);
|
|
|
|
|
void _detachView(ZxRenderView* p);
|
|
|
|
|
virtual void _callOnActivated() = 0;
|
|
|
|
|
virtual void _callOnDeactivated() = 0;
|
|
|
|
|
|
|
|
|
|
// 右键模拟
|
|
|
|
|
void _simRightDown(const QPointF& pt);
|
|
|
|
|
|
|
|
|
|
ZxToolPrivate* _getPrivate() const;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
ZxToolPrivate* _private;
|
|
|
|
|
ZxCompoundTool* m_pParent;
|
|
|
|
|
ZxRenderView* m_pView; // 一定有效
|
|
|
|
|
static ZxRenderView* _currentView; // 可能为空
|
|
|
|
|
|
|
|
|
|
QString m_sText;
|
|
|
|
|
QString m_sTooltip;
|
|
|
|
|
|
|
|
|
|
mutable QIcon m_icon;
|
|
|
|
|
int m_nRefCount;
|
|
|
|
|
bool m_bEnabled : 1;
|
|
|
|
|
bool m_bMouseTracking : 1;
|
|
|
|
|
bool m_bProperRelease : 1;
|
|
|
|
|
|
|
|
|
|
friend class ZxRenderView;
|
|
|
|
|
friend class ZxCompoundTool;
|
|
|
|
|
friend class ZxSimpleTool;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|