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.
nmWTAI-Platform/Src/nmNum/nmPlot/nmObjBase.cpp

76 lines
2.1 KiB
C++

#include <QPainter>
#include "nmObjBase.h"
#include <QtCore/qnumeric.h>
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));
// 将一像素边线对齐到像素中心,并把边线本身计入节点框的总尺寸。
const qreal left = qRound(screenPos.x() - nPixelSize * 0.5) + 0.5;
const qreal top = qRound(screenPos.y() - nPixelSize * 0.5) + 0.5;
painter->drawRect(QRectF(left, top, nPixelSize - 1, nPixelSize - 1));
painter->restore();
}
void nmObjBase::paintSelectedNodeHandles(QPainter* painter, const QVector<QPointF>& 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());
}
}