|
|
|
|
@ -5,10 +5,13 @@
|
|
|
|
|
#include "ZxObjBase.h"
|
|
|
|
|
#include "nmObjBase.h"
|
|
|
|
|
#include "nmObjToolBase.h"
|
|
|
|
|
#include "nmPlotView.h"
|
|
|
|
|
|
|
|
|
|
nmObjToolBase::nmObjToolBase() : ZxObjToolBase()
|
|
|
|
|
{
|
|
|
|
|
m_oNot = NMOT_UNKNWON;
|
|
|
|
|
m_bInteractionCursorEnabled = false;
|
|
|
|
|
m_bCreationCursorActive = false;
|
|
|
|
|
m_bPointSnappingEnabled = false;
|
|
|
|
|
m_nSnapTargetIndex = -1;
|
|
|
|
|
m_bConsumeInsertPointRelease = false;
|
|
|
|
|
@ -19,7 +22,12 @@ bool nmObjToolBase::onLeftDown(const QPointF& pt)
|
|
|
|
|
// 上一次双击若因窗口失焦未收到松手,不影响下一次正常按下。
|
|
|
|
|
m_bConsumeInsertPointRelease = false;
|
|
|
|
|
clearPointSnap();
|
|
|
|
|
return ZxObjToolBase::onLeftDown(pt);
|
|
|
|
|
const bool handled = ZxObjToolBase::onLeftDown(pt);
|
|
|
|
|
if (handled && m_bInteractionCursorEnabled && m_pObj != nullptr) {
|
|
|
|
|
// 按下时还未开始拖动,保持悬停样式;实际移动后再切为握手。
|
|
|
|
|
changeCursor(interactionCursor(m_oHitOption, false));
|
|
|
|
|
}
|
|
|
|
|
return handled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmObjToolBase::onMouseMove(const QPointF& pt)
|
|
|
|
|
@ -32,6 +40,11 @@ bool nmObjToolBase::onMouseMove(const QPointF& pt)
|
|
|
|
|
m_bConsumeInsertPointRelease = false;
|
|
|
|
|
}
|
|
|
|
|
const bool handled = ZxObjToolBase::onMouseMove(pt);
|
|
|
|
|
if (handled && m_bInteractionCursorEnabled && m_pObj != nullptr &&
|
|
|
|
|
m_bTracking && isLeftDown() && !isClick()) {
|
|
|
|
|
// 框架只在悬停分支调用 getCursorBy,拖动分支需显式更新光标。
|
|
|
|
|
changeCursor(interactionCursor(m_oHitOption, true));
|
|
|
|
|
}
|
|
|
|
|
if (m_bPointSnappingEnabled) {
|
|
|
|
|
if (isPointSnapDrag()) {
|
|
|
|
|
updatePointSnap(pt);
|
|
|
|
|
@ -44,6 +57,14 @@ bool nmObjToolBase::onMouseMove(const QPointF& pt)
|
|
|
|
|
|
|
|
|
|
bool nmObjToolBase::onLeftUp(const QPointF& pt)
|
|
|
|
|
{
|
|
|
|
|
if (m_bInteractionCursorEnabled && m_pObj != nullptr &&
|
|
|
|
|
(m_oHitOption != OHO_None || m_bConsumeInsertPointRelease)) {
|
|
|
|
|
// 单击未必被框架记为“最后活动工具”,由实际处理松手的工具请求刷新。
|
|
|
|
|
// 视图会等框架全部收尾后再回调,避免刚设置的悬停光标被重置。
|
|
|
|
|
if (nmPlotView* view = dynamic_cast<nmPlotView*>(getView())) {
|
|
|
|
|
view->requestHoverCursorRefresh(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (m_bConsumeInsertPointRelease) {
|
|
|
|
|
m_bConsumeInsertPointRelease = false;
|
|
|
|
|
m_bTracking = false;
|
|
|
|
|
@ -63,6 +84,80 @@ bool nmObjToolBase::onLeftUp(const QPointF& pt)
|
|
|
|
|
return handled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::enableInteractionCursor()
|
|
|
|
|
{
|
|
|
|
|
m_bInteractionCursorEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::CursorShape nmObjToolBase::interactionCursor(int nOption, bool dragging) const
|
|
|
|
|
{
|
|
|
|
|
if (m_pObj == nullptr || !m_pObj->isSelected() || !m_pObj->isVisible() ||
|
|
|
|
|
m_pObj->isReadOnly() || m_pObj->isLockPos()) {
|
|
|
|
|
return Qt::ArrowCursor;
|
|
|
|
|
}
|
|
|
|
|
if (nOption == OHO_Point) {
|
|
|
|
|
return m_pObj->isLockSize() ? Qt::ArrowCursor : Qt::CrossCursor;
|
|
|
|
|
}
|
|
|
|
|
if (nOption == OHO_Bound) {
|
|
|
|
|
// 锁定尺寸不妨碍整体平移;是否允许移动由位置锁定决定。
|
|
|
|
|
return dragging ? Qt::ClosedHandCursor : Qt::OpenHandCursor;
|
|
|
|
|
}
|
|
|
|
|
return Qt::ArrowCursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::CursorShape nmObjToolBase::getCursorBy(const int& nOption, const int& nSubIndex)
|
|
|
|
|
{
|
|
|
|
|
if (!m_bInteractionCursorEnabled) {
|
|
|
|
|
return ZxObjToolBase::getCursorBy(nOption, nSubIndex);
|
|
|
|
|
}
|
|
|
|
|
return interactionCursor(nOption, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::beginCreationCursor()
|
|
|
|
|
{
|
|
|
|
|
if (!m_bInteractionCursorEnabled || m_pObj != nullptr || getView() == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_bCreationCursorActive = true;
|
|
|
|
|
getView()->setCursorKeeping(true);
|
|
|
|
|
changeCursor(Qt::CrossCursor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::resetInteractionCursor()
|
|
|
|
|
{
|
|
|
|
|
if (!m_bInteractionCursorEnabled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZxRenderView* view = getView();
|
|
|
|
|
const bool hadCreationCursor = m_bCreationCursorActive;
|
|
|
|
|
m_bCreationCursorActive = false;
|
|
|
|
|
if (view != nullptr) {
|
|
|
|
|
// 只释放本工具开启的保持状态,避免影响其他创建工具。
|
|
|
|
|
if (hadCreationCursor) {
|
|
|
|
|
view->setCursorKeeping(false);
|
|
|
|
|
}
|
|
|
|
|
if (hadCreationCursor || getLastActivateTool() == this) {
|
|
|
|
|
view->restoreCursor();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::refreshHoverCursor(const QPointF& pt)
|
|
|
|
|
{
|
|
|
|
|
if (!m_bInteractionCursorEnabled || m_pObj == nullptr || getView() == nullptr ||
|
|
|
|
|
!isEnabled() || getCompoundTool() == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int option = -1;
|
|
|
|
|
int index = -1;
|
|
|
|
|
// 重新查询提交后的几何位置,不复用拖动前的命中,也不再次分发鼠标事件。
|
|
|
|
|
if (m_pObj->isVisible() && m_pObj->_runHitTest(pt, option, index)) {
|
|
|
|
|
changeCursor(interactionCursor(option, false));
|
|
|
|
|
} else {
|
|
|
|
|
getView()->restoreCursor();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::enablePointSnapping()
|
|
|
|
|
{
|
|
|
|
|
m_bPointSnappingEnabled = true;
|
|
|
|
|
@ -144,6 +239,7 @@ void nmObjToolBase::clearPointSnap()
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::onDeactivated()
|
|
|
|
|
{
|
|
|
|
|
resetInteractionCursor();
|
|
|
|
|
clearPointSnap();
|
|
|
|
|
ZxObjToolBase::onDeactivated();
|
|
|
|
|
}
|
|
|
|
|
|