#include #include "nmObjBase.h" #include ZX_DEFINE_DYNAMIC(nObjBase, nmObjBase) nmObjBase::nmObjBase() { } nmObjBase::nmObjBase(const QString& sName, \ ZxSubAxisX* pAxisX, \ ZxSubAxisY* pAxisY) { } nmObjBase::~nmObjBase() { } void nmObjBase::paintBack(QPainter* painter, const ZxPaintParam& param) { ZxObjBase::paintBack(painter, param); } void nmObjBase::afterCreated() { } void nmObjBase::removeData() { } void nmObjBase::paintNodeHandle(QPainter* painter, const QPointF& pt, int nPixelSize, const QColor& borderColor, const QColor& fillColor) { if (painter == nullptr || nPixelSize < 2) { return; } // 先转换节点中心,再临时取消地图变换;框的大小和线宽不随缩放变化。 // combinedTransform 不包含设备像素比,Qt 继续负责高 DPI 下的逻辑像素映射。 const QPointF screenPos = painter->combinedTransform().map(pt); if (!qIsFinite(screenPos.x()) || !qIsFinite(screenPos.y())) { return; } painter->save(); painter->resetTransform(); painter->setRenderHint(QPainter::Antialiasing, false); QPen pen(borderColor); pen.setWidthF(1.0); painter->setPen(pen); painter->setBrush(fillColor.isValid() ? QBrush(fillColor) : QBrush(Qt::NoBrush)); // 关闭抗锯齿时,Qt 已将 1 像素边线落到像素格内,只需对左上角取整。 // 不再额外加半像素,避免栅格化后节点框向右下偏离折线交点。 // 路径宽高扣除边线,使可见外框仍为 nPixelSize 像素。 const qreal left = qRound(screenPos.x() - nPixelSize * 0.5); const qreal top = qRound(screenPos.y() - nPixelSize * 0.5); painter->drawRect(QRectF(left, top, nPixelSize - 1, nPixelSize - 1)); painter->restore(); } void nmObjBase::paintSelectedNodeHandles(QPainter* painter, const QVector& points) const { if (!isSelected()) { return; } for (int i = 0; i < points.count(); ++i) { const bool active = m_oHitOption == OHO_Point && m_nHitIndex == i; const QColor nodeColor = active ? QColor(Qt::red) : QColor(0, 0, 128); paintNodeHandle(painter, points[i], 5, nodeColor, active ? nodeColor : QColor()); } }