|
|
|
|
@ -10,6 +10,9 @@
|
|
|
|
|
nmObjToolBase::nmObjToolBase() : ZxObjToolBase()
|
|
|
|
|
{
|
|
|
|
|
m_oNot = NMOT_UNKNWON;
|
|
|
|
|
m_bCreationCancelled = false;
|
|
|
|
|
m_bEscapeCancellationEnabled = false;
|
|
|
|
|
m_bConsumeCancelledRelease = false;
|
|
|
|
|
m_bInteractionCursorEnabled = false;
|
|
|
|
|
m_bCreationCursorActive = false;
|
|
|
|
|
m_bPointSnappingEnabled = false;
|
|
|
|
|
@ -19,10 +22,15 @@ nmObjToolBase::nmObjToolBase() : ZxObjToolBase()
|
|
|
|
|
|
|
|
|
|
bool nmObjToolBase::onLeftDown(const QPointF& pt)
|
|
|
|
|
{
|
|
|
|
|
// 新按下表示新一轮操作,失焦丢失的松手不能影响后续编辑。
|
|
|
|
|
m_bConsumeCancelledRelease = false;
|
|
|
|
|
// 上一次双击若因窗口失焦未收到松手,不影响下一次正常按下。
|
|
|
|
|
m_bConsumeInsertPointRelease = false;
|
|
|
|
|
clearPointSnap();
|
|
|
|
|
const bool handled = ZxObjToolBase::onLeftDown(pt);
|
|
|
|
|
if (handled) {
|
|
|
|
|
registerCancellableInteraction();
|
|
|
|
|
}
|
|
|
|
|
if (handled && m_bInteractionCursorEnabled && m_pObj != nullptr) {
|
|
|
|
|
// 按下时还未开始拖动,保持悬停样式;实际移动后再切为握手。
|
|
|
|
|
changeCursor(interactionCursor(m_oHitOption, false));
|
|
|
|
|
@ -32,6 +40,13 @@ bool nmObjToolBase::onLeftDown(const QPointF& pt)
|
|
|
|
|
|
|
|
|
|
bool nmObjToolBase::onMouseMove(const QPointF& pt)
|
|
|
|
|
{
|
|
|
|
|
if (m_bConsumeCancelledRelease) {
|
|
|
|
|
if (QApplication::mouseButtons().testFlag(Qt::LeftButton)) {
|
|
|
|
|
return true; // Esc 后仍按住左键移动时,不让框架重新进入拖动。
|
|
|
|
|
}
|
|
|
|
|
// 松手发生在窗口外时也可恢复悬停;取消时已清空命中,不会提交旧移动。
|
|
|
|
|
m_bConsumeCancelledRelease = false;
|
|
|
|
|
}
|
|
|
|
|
if (m_bConsumeInsertPointRelease) {
|
|
|
|
|
if (QApplication::mouseButtons().testFlag(Qt::LeftButton)) {
|
|
|
|
|
return true;
|
|
|
|
|
@ -57,6 +72,14 @@ bool nmObjToolBase::onMouseMove(const QPointF& pt)
|
|
|
|
|
|
|
|
|
|
bool nmObjToolBase::onLeftUp(const QPointF& pt)
|
|
|
|
|
{
|
|
|
|
|
if (m_bConsumeCancelledRelease) {
|
|
|
|
|
m_bConsumeCancelledRelease = false;
|
|
|
|
|
m_bTracking = false;
|
|
|
|
|
m_oHitOption = OHO_None;
|
|
|
|
|
// 保留框架的松手收尾,但不进入移动提交和吸附分支,也不恢复旧命中光标。
|
|
|
|
|
ZxObjToolBase::onLeftUp(pt);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (m_bInteractionCursorEnabled && m_pObj != nullptr &&
|
|
|
|
|
(m_oHitOption != OHO_None || m_bConsumeInsertPointRelease)) {
|
|
|
|
|
// 单击未必被框架记为“最后活动工具”,由实际处理松手的工具请求刷新。
|
|
|
|
|
@ -84,6 +107,71 @@ bool nmObjToolBase::onLeftUp(const QPointF& pt)
|
|
|
|
|
return handled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::enableEscapeCancellation()
|
|
|
|
|
{
|
|
|
|
|
m_bEscapeCancellationEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::registerCancellableInteraction()
|
|
|
|
|
{
|
|
|
|
|
if (m_bEscapeCancellationEnabled) {
|
|
|
|
|
if (nmPlotView* view = dynamic_cast<nmPlotView*>(getView())) {
|
|
|
|
|
view->setCancellableTool(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::clearCreationPoints()
|
|
|
|
|
{
|
|
|
|
|
// 其他工具默认没有需要清理的点集,三个绘制工具分别实现。
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmObjToolBase::cancelInteraction()
|
|
|
|
|
{
|
|
|
|
|
ZxRenderView* view = getView();
|
|
|
|
|
if (!m_bEscapeCancellationEnabled || view == nullptr || !isEnabled() ||
|
|
|
|
|
getCompoundTool() == nullptr || m_bCreationCancelled) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const bool creating = m_pObj == nullptr;
|
|
|
|
|
if (creating) {
|
|
|
|
|
if (!m_bCreationCursorActive) {
|
|
|
|
|
return false; // 已完成的临时工具不能再次取消。
|
|
|
|
|
}
|
|
|
|
|
} else if (!isLeftDown() || m_bConsumeInsertPointRelease ||
|
|
|
|
|
(m_oHitOption != OHO_Point && m_oHitOption != OHO_Bound)) {
|
|
|
|
|
return false; // 空闲选择和已经提交的双击加点不属于待取消的移动。
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_bConsumeCancelledRelease = isLeftDown();
|
|
|
|
|
m_bTracking = false;
|
|
|
|
|
m_oHitOption = OHO_None;
|
|
|
|
|
m_bHitTestMoving = false;
|
|
|
|
|
m_bConsumeInsertPointRelease = false;
|
|
|
|
|
if (creating) {
|
|
|
|
|
m_bCreationCancelled = true;
|
|
|
|
|
clearCreationPoints();
|
|
|
|
|
} else {
|
|
|
|
|
// 移动尚未提交,清理预览状态即可;不写回点集,也不产生撤销记录。
|
|
|
|
|
m_pObj->m_oHitOption = OHO_None;
|
|
|
|
|
m_pObj->m_nHitIndex = -1;
|
|
|
|
|
m_pObj->resetBrotherOffset();
|
|
|
|
|
m_pObj->update();
|
|
|
|
|
}
|
|
|
|
|
clearPointSnap();
|
|
|
|
|
resetInteractionCursor();
|
|
|
|
|
view->setSnapshotMode(false);
|
|
|
|
|
view->restoreCursor();
|
|
|
|
|
updateScene();
|
|
|
|
|
|
|
|
|
|
if (creating) {
|
|
|
|
|
// removeTools 可能仍留有按下工具缓存,保留取消标记以消费随后的鼠标回调。
|
|
|
|
|
setEnabled(false);
|
|
|
|
|
emit sigCreationCancelled();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::enableInteractionCursor()
|
|
|
|
|
{
|
|
|
|
|
m_bInteractionCursorEnabled = true;
|
|
|
|
|
@ -118,6 +206,7 @@ void nmObjToolBase::beginCreationCursor()
|
|
|
|
|
if (!m_bInteractionCursorEnabled || m_pObj != nullptr || getView() == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
registerCancellableInteraction();
|
|
|
|
|
m_bCreationCursorActive = true;
|
|
|
|
|
getView()->setCursorKeeping(true);
|
|
|
|
|
changeCursor(Qt::CrossCursor);
|
|
|
|
|
@ -246,6 +335,9 @@ void nmObjToolBase::onDeactivated()
|
|
|
|
|
|
|
|
|
|
bool nmObjToolBase::insertPointOnDoubleClick(const QPointF& pt, bool bClosed)
|
|
|
|
|
{
|
|
|
|
|
if (m_bConsumeCancelledRelease) {
|
|
|
|
|
return true; // 取消后的同一次按压不能转成双击加点。
|
|
|
|
|
}
|
|
|
|
|
if (m_pObj == nullptr || getView() == nullptr || !m_pObj->isSelected() ||
|
|
|
|
|
!m_pObj->isVisible() || m_pObj->isReadOnly() ||
|
|
|
|
|
m_pObj->isLockPos() || m_pObj->isLockSize()) {
|
|
|
|
|
|