You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWATI/Include/iPlot/iPlotBase/Commands/ZxPolicy.h

122 lines
2.5 KiB
C++

#pragma once
#include <QPointF>
#include <QCursor>
#include "ZxPaintParam.h"
#include "ZxEdit.h"
#include "IxInterface.h"
#include "iPlotBase_global.h"
class QPainter;
class ZxRenderItem;
class ZxRenderView;
class ZxSimpleTool;
class ZxSceneItem;
class ZxTool;
class QUndoCommand;
class ZxSelection;
/// 策略基类
class I_PLOTBASE_EXPORT ZxPolicy
: public QObject
, virtual public IxInterface
{
Q_OBJECT
public:
ZxPolicy();
/// 获取所属的图件
virtual ZxRenderItem* getItem() const;
template<typename T> T getItem() const
{
T p = dynamic_cast<T>(getItem());
Q_ASSERT(p);
return p;
}
/// 获取所属的Edit
virtual ZxEdit* getEdit() const;
/// 获取所属的Scene
virtual ZxSceneItem* getScene() const;
/// 获取当前工具
virtual ZxTool* getCurrentTool() const;
/// 获取当前视图
virtual ZxRenderView* getCurrentToolView() const;
/// 刷新
/// @note 相当于 getItem()->update()
virtual void update();
/// 尝试把工具压到当前工具栈中
/// @note 弹栈用 pTool->detach()
/// @param pTool 要压栈的工具
/// @return 成功放回true, 失败返回false.
bool pushTool(ZxSimpleTool* pTool);
/// 工具弹栈
void popTool(ZxSimpleTool* pTool);
/// 键按下
virtual void onKeyPress(QKeyEvent* event);
/// 键抬起
virtual void onKeyRelease(QKeyEvent* event);
/// 运行一个命令. 相当于getScene()->pushCommand()
virtual bool pushCommand(QUndoCommand* cmd);
/// 相当于getScene()->getSelection()
virtual ZxSelection getSelection();
/// 设置静态模式.
/// @note 静态模式是指在图元被取消选择时不自动删除policy.
void setStatic(bool bStatic);
/// 是否静态模式
bool isStatic() const;
protected:
/// 激活
virtual void onActivate();
virtual void onDeactivate();
/// Edit关联
virtual void onAddToEdit();
virtual void onRemoveFromEdit();
/// 准备菜单
virtual void onPrepareContextMenu(QMenu* pMenu, const QPointF& pos);
/// Move+Resize
virtual void onItemMove(const QPointF& ptOld, const QPointF& ptNew);
virtual void onItemResize(const QSizeF& szOld, const QSizeF& szNew);
virtual void onPaint(QPainter* painter, const ZxPaintParam& param);
private:
void setEdit(ZxEdit* p);
private:
ZxRenderItem* m_pItem;
bool m_bStatic : 1;
friend class ZxEdit;
};