|
|
|
|
@ -15,6 +15,8 @@
|
|
|
|
|
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
|
|
#include "ZxRenderView.h"
|
|
|
|
|
#include <QtCore/qnumeric.h>
|
|
|
|
|
|
|
|
|
|
#include "nmPlotGraphicBinder.h"
|
|
|
|
|
|
|
|
|
|
@ -253,65 +255,70 @@ bool nmObjRegionMark::hitTest(const QPointF& pt)
|
|
|
|
|
|
|
|
|
|
bool nmObjRegionMark::_runHitTest(const QPointF& pt, int& nOption, int& nSubIndex)
|
|
|
|
|
{
|
|
|
|
|
if(!nmObjBase::_runHitTest(pt, nOption, nSubIndex)) {
|
|
|
|
|
if (!nmObjBase::_runHitTest(pt, nOption, nSubIndex)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nOption = -1;
|
|
|
|
|
nSubIndex = 0;
|
|
|
|
|
|
|
|
|
|
if(NULL == m_pAxisX || NULL == m_pAxisY) {
|
|
|
|
|
nOption = OHO_None;
|
|
|
|
|
nSubIndex = -1;
|
|
|
|
|
ZxRenderView* view = getView();
|
|
|
|
|
if (view == nullptr || m_pAxisX == nullptr || m_pAxisY == nullptr || m_vecPoints.isEmpty()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<QPointF> pts = getPosOf(m_vecPoints);
|
|
|
|
|
|
|
|
|
|
// 点
|
|
|
|
|
double r = 3.f;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < pts.count(); i++) {
|
|
|
|
|
QPointF ptTopLeft = QPointF(pts[i].x() - r,
|
|
|
|
|
pts[i].y() - r);
|
|
|
|
|
QSizeF sz = QSizeF(r * 2.f, r * 2.f);
|
|
|
|
|
|
|
|
|
|
QRectF rt = QRectF(ptTopLeft, sz);
|
|
|
|
|
bool b = rt.contains(pt);
|
|
|
|
|
|
|
|
|
|
if(b) {
|
|
|
|
|
nOption = (int)OHO_Point;
|
|
|
|
|
nSubIndex = i;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
const QPointF mousePos = view->mapFromScene(pt);
|
|
|
|
|
const QPointF anchor = getPosOf(m_vecPoints.first());
|
|
|
|
|
const QRectF iconRect = view->mapFromScene(regionMarkIconRect(anchor)).normalized();
|
|
|
|
|
if (!qIsFinite(mousePos.x()) || !qIsFinite(mousePos.y()) ||
|
|
|
|
|
!qIsFinite(iconRect.left()) || !qIsFinite(iconRect.right()) ||
|
|
|
|
|
!qIsFinite(iconRect.top()) || !qIsFinite(iconRect.bottom())) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nOption = (int)OHO_None;
|
|
|
|
|
nSubIndex = -1;
|
|
|
|
|
// 命中区覆盖完整图标并留出像素余量,缩小时也保留最小点击范围。
|
|
|
|
|
const qreal paddingPixels = 2.0;
|
|
|
|
|
const qreal paddingX = qMax(paddingPixels, NodeHitRadiusPixels - iconRect.width() / 2);
|
|
|
|
|
const qreal paddingY = qMax(paddingPixels, NodeHitRadiusPixels - iconRect.height() / 2);
|
|
|
|
|
if (!iconRect.adjusted(-paddingX, -paddingY, paddingX, paddingY).contains(mousePos)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
nOption = OHO_Point;
|
|
|
|
|
nSubIndex = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmObjRegionMark::runMove(const QPointF& pt1,
|
|
|
|
|
const QPointF& pt2)
|
|
|
|
|
bool nmObjRegionMark::calculateMoveAnchor(const QPointF& start, const QPointF& end,
|
|
|
|
|
QPointF& anchor) const
|
|
|
|
|
{
|
|
|
|
|
if(isLockPos()) {
|
|
|
|
|
if (isReadOnly() || isLockPos() || m_vecPoints.isEmpty() ||
|
|
|
|
|
m_pAxisX == nullptr || m_pAxisY == nullptr ||
|
|
|
|
|
m_pAxisX->getRangeMin() == m_pAxisX->getRangeMax() ||
|
|
|
|
|
m_pAxisY->getRangeMin() == m_pAxisY->getRangeMax()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(NULL == m_pAxisX || NULL == m_pAxisY) {
|
|
|
|
|
anchor = getPosOf(m_vecPoints.first()) + (end - start);
|
|
|
|
|
return qIsFinite(anchor.x()) && qIsFinite(anchor.y());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmObjRegionMark::runMove(const QPointF& pt1, const QPointF& pt2)
|
|
|
|
|
{
|
|
|
|
|
QPointF anchor;
|
|
|
|
|
if (m_oHitOption != OHO_Point || m_nHitIndex != 0 ||
|
|
|
|
|
!calculateMoveAnchor(pt1, pt2, anchor)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nCount = m_vecPoints.count();
|
|
|
|
|
QVector<QPointF> vecPts = getPosOf(m_vecPoints);
|
|
|
|
|
|
|
|
|
|
if(m_oHitOption == OHO_Point && m_nHitIndex >= 0) {
|
|
|
|
|
// 如果是点,不用计算偏移量,直接将该点移动到鼠标抬起的位置即可
|
|
|
|
|
vecPts[m_nHitIndex] = pt2;
|
|
|
|
|
return moveToPos(vecPts);
|
|
|
|
|
} else {
|
|
|
|
|
QVector<QPointF> positions = getAllPos();
|
|
|
|
|
positions[0] = anchor;
|
|
|
|
|
resetBrotherOffset();
|
|
|
|
|
if (!moveToPos(positions)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_pGraphicBinder != nullptr) {
|
|
|
|
|
m_pGraphicBinder->syncRegionMarkMove(this);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -350,12 +357,10 @@ void nmObjRegionMark::paintBack(QPainter* painter, const ZxPaintParam& param)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPointF ptPos = getPosOf(m_vecPoints[0]);
|
|
|
|
|
painter->save();
|
|
|
|
|
const QPointF ptPos = getPosOf(m_vecPoints[0]);
|
|
|
|
|
|
|
|
|
|
ZxPlot* m_pCurPlot = dynamic_cast<ZxPlot*>(this->getParent());
|
|
|
|
|
if (m_pCurPlot == nullptr) {
|
|
|
|
|
painter->restore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -404,22 +409,27 @@ void nmObjRegionMark::paintBack(QPainter* painter, const ZxPaintParam& param)
|
|
|
|
|
m_pGraphicBinder->syncRegionMarkData(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paintMarker(painter, ptPos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjRegionMark::paintMarker(QPainter* painter, const QPointF& anchor) const
|
|
|
|
|
{
|
|
|
|
|
painter->save();
|
|
|
|
|
|
|
|
|
|
// 设置字体
|
|
|
|
|
QFont ft = qApp->font();
|
|
|
|
|
ft.setPointSize(8);
|
|
|
|
|
painter->setFont(ft);
|
|
|
|
|
painter->setPen(Qt::black);
|
|
|
|
|
|
|
|
|
|
// 计算图标的矩形区域,居中于ptPos
|
|
|
|
|
const QRectF iconRect = regionMarkIconRect(ptPos);
|
|
|
|
|
const QRectF iconRect = regionMarkIconRect(anchor);
|
|
|
|
|
painter->drawPixmap(iconRect, m_icon, m_icon.rect());
|
|
|
|
|
|
|
|
|
|
// 计算文本的矩形区域,位于图标上方
|
|
|
|
|
const QRectF textRect = regionMarkTextRect(ptPos);
|
|
|
|
|
ZxDrawHelper::drawText(painter, textRect, Qt::AlignCenter, m_sName); // 使用居中对齐
|
|
|
|
|
const QRectF textRect = regionMarkTextRect(anchor);
|
|
|
|
|
ZxDrawHelper::drawText(painter, textRect, Qt::AlignCenter, m_sName);
|
|
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjRegionMark::setColorIndex(int newIndex)
|
|
|
|
|
|