|
|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QLineF>
|
|
|
|
|
#include "ZxObjBase.h"
|
|
|
|
|
#include "nmObjBase.h"
|
|
|
|
|
#include "nmObjToolBase.h"
|
|
|
|
|
|
|
|
|
|
nmObjToolBase::nmObjToolBase() : ZxObjToolBase()
|
|
|
|
|
@ -120,33 +121,15 @@ QPointF nmObjToolBase::pointSnapPosition(const QPointF& pt) const
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::paintPointSnapTargets(QPainter* painter) const
|
|
|
|
|
{
|
|
|
|
|
if (getView() == nullptr || m_vecSnapCandidates.isEmpty() ||
|
|
|
|
|
if (getView() == nullptr || m_nSnapTargetIndex < 0 ||
|
|
|
|
|
m_nSnapTargetIndex >= m_vecSnapCandidates.count() ||
|
|
|
|
|
(m_pObj != nullptr && !m_pObj->isSelected())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
|
QPen pen(Qt::black);
|
|
|
|
|
pen.setWidth(0); // 使用像素宽度,标记边线不随地图缩放变粗。
|
|
|
|
|
painter->setPen(pen);
|
|
|
|
|
painter->setBrush(Qt::NoBrush);
|
|
|
|
|
const qreal halfSize = 4.0;
|
|
|
|
|
for (int i = 0; i < m_vecSnapCandidates.count(); ++i) {
|
|
|
|
|
const QPointF pos = getView()->mapFromScene(m_vecSnapCandidates[i]);
|
|
|
|
|
if (i == m_nSnapTargetIndex || !qIsFinite(pos.x()) || !qIsFinite(pos.y())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const QRectF rect(pos - QPointF(halfSize, halfSize), QSizeF(halfSize * 2, halfSize * 2));
|
|
|
|
|
painter->drawRect(getView()->mapToScene(rect));
|
|
|
|
|
}
|
|
|
|
|
// 最后绘制当前目标,避免同坐标候选的空心标记盖住高亮。
|
|
|
|
|
if (m_nSnapTargetIndex >= 0 && m_nSnapTargetIndex < m_vecSnapCandidates.count()) {
|
|
|
|
|
const QPointF pos = getView()->mapFromScene(m_vecSnapCandidates[m_nSnapTargetIndex]);
|
|
|
|
|
const QRectF rect(pos - QPointF(halfSize, halfSize), QSizeF(halfSize * 2, halfSize * 2));
|
|
|
|
|
painter->setBrush(Qt::green);
|
|
|
|
|
painter->drawRect(getView()->mapToScene(rect));
|
|
|
|
|
}
|
|
|
|
|
painter->restore();
|
|
|
|
|
// 吸附目标比普通节点大一圈,绿色填充配深色细边,便于在不同背景上辨认。
|
|
|
|
|
nmObjBase::paintNodeHandle(painter, m_vecSnapCandidates[m_nSnapTargetIndex],
|
|
|
|
|
8, QColor(40, 40, 40), QColor(0, 200, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjToolBase::clearPointSnap()
|
|
|
|
|
|