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.
335 lines
7.6 KiB
C++
335 lines
7.6 KiB
C++
#include <QPainter>
|
|
|
|
#include "ZxSerializer.h"
|
|
#include "IxPtyPano.h"
|
|
|
|
#include "ZxSubAxisX.h"
|
|
#include "ZxSubAxisY.h"
|
|
|
|
#include "nmObjLimitTool.h"
|
|
#include "nmObjLimit.h"
|
|
|
|
ZX_DEFINE_DYNAMIC(nObjLimit, nmObjLimit)
|
|
|
|
nmObjLimit::nmObjLimit()
|
|
{
|
|
m_sObjTag = "nObjLimit";
|
|
nmObjLimit::init("", nullptr, nullptr);
|
|
}
|
|
|
|
nmObjLimit::nmObjLimit(const QString& sName, \
|
|
ZxSubAxisX* pAxisX, \
|
|
ZxSubAxisY* pAxisY)
|
|
{
|
|
m_sObjTag = "nObjLimit";
|
|
nmObjLimit::init(sName, pAxisX, pAxisY);
|
|
}
|
|
|
|
nmObjLimit::~nmObjLimit()
|
|
{
|
|
}
|
|
|
|
void nmObjLimit::init(const QString& sName, \
|
|
ZxSubAxisX* pAxisX, \
|
|
ZxSubAxisY* pAxisY)
|
|
{
|
|
nmObjBase::init(sName, pAxisX, pAxisY);
|
|
|
|
nmObjLimit::initFlags();
|
|
|
|
m_oPen = QPen(QBrush(QColor(128, 128, 128)), \
|
|
0.3, Qt::SolidLine);
|
|
m_clrBackgrd = QColor(170, 170, 0, 30);
|
|
|
|
loadTempl();
|
|
}
|
|
|
|
void nmObjLimit::initTools()
|
|
{
|
|
m_pTool = new nmObjLimitTool();
|
|
|
|
nmObjBase::initTools();
|
|
}
|
|
|
|
void nmObjLimit::initFlags()
|
|
{
|
|
setLockPos(false);
|
|
setLockSize(false);
|
|
setReadOnly(false);
|
|
}
|
|
|
|
bool nmObjLimit::hitTest(const QPointF& pt)
|
|
{
|
|
return nmObjBase::hitTest(pt);
|
|
}
|
|
|
|
bool nmObjLimit::_runHitTest(const QPointF& pt, int& nOption, int& nSubIndex)
|
|
{
|
|
if (!nmObjBase::_runHitTest(pt, nOption, nSubIndex))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
nOption = -1;
|
|
nSubIndex = 0;
|
|
|
|
if (nullptr == m_pAxisX || nullptr == m_pAxisY)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
QVector<QPointF> pts = getPosOf(m_vecPoints);
|
|
|
|
// 点
|
|
double r = 1.0;
|
|
for (int i = 0; i < pts.count(); i++)
|
|
{
|
|
QPointF ptTopLeft = QPointF(pts[i].x() - r,
|
|
pts[i].y() - r);
|
|
QSizeF sz = QSizeF(r * 2.0, r * 2.0);
|
|
|
|
QRectF rt = QRectF(ptTopLeft, sz);
|
|
bool b = rt.contains(pt);
|
|
if (b)
|
|
{
|
|
nOption = (int)OHO_Point;
|
|
nSubIndex = i;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// 线
|
|
for (int i = 0; i < pts.count()/* - 1*/; i++)
|
|
{
|
|
int n1 = i;
|
|
int n2 = (i == pts.count() - 1 ? 0 : i + 1);
|
|
if (_isNearLine(pt, pts[n1], pts[n2], 1.0 * 2))
|
|
{
|
|
nOption = (int)OHO_Bound;
|
|
nSubIndex = i;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// 内部
|
|
QPainterPath oPath;
|
|
oPath.moveTo(pts[0]);
|
|
for (int i = 1; i < pts.count(); i++)
|
|
{
|
|
oPath.lineTo(pts[i]);
|
|
}
|
|
oPath.closeSubpath();
|
|
if (oPath.contains(pt))
|
|
{
|
|
nOption = (int)OHO_Inner;
|
|
nSubIndex = 0;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool nmObjLimit::runMove(const QPointF& pt1,
|
|
const QPointF& pt2)
|
|
{
|
|
if (isLockPos())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (nullptr == m_pAxisX || nullptr == m_pAxisY)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//emit sigRunMoveTo(pt1, pt2);
|
|
|
|
int nCount = m_vecPoints.count();
|
|
QVector<QPointF> vecPts = getPosOf(m_vecPoints); //屏幕值
|
|
if (m_oHitOption == OHO_Point && m_nHitIndex >= 0)
|
|
{
|
|
vecPts[m_nHitIndex] = offsetPoint(vecPts[m_nHitIndex],
|
|
pt1, pt2);
|
|
return moveToPos(vecPts);
|
|
}
|
|
else if (m_oHitOption == OHO_Bound && m_nHitIndex >= 0)
|
|
{
|
|
vecPts[m_nHitIndex] = offsetPoint(vecPts[m_nHitIndex],
|
|
pt1, pt2);
|
|
vecPts[m_nHitIndex + 1] = offsetPoint(vecPts[m_nHitIndex + 1],
|
|
pt1, pt2);
|
|
return moveToPos(vecPts);
|
|
}
|
|
else if (m_oHitOption == OHO_Inner)
|
|
{
|
|
for (int i = 0; i < nCount; i++)
|
|
{
|
|
vecPts[i] = offsetPoint(vecPts[i], pt1, pt2);
|
|
}
|
|
m_dOffsetX = pt2.x() - pt1.x();
|
|
m_dOffsetY = pt2.y() - pt1.y();
|
|
return moveToPos(vecPts);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void nmObjLimit::fillPtyPano(IxPtyPano* sheet)
|
|
{
|
|
nmObjBase::fillPtyPano(sheet);
|
|
|
|
ZX_PROP("ObjLimit.Pen", getPen, setPen);
|
|
ZX_PROP("ObjLimit.BackgrdColor", getBackgrdColor, setBackgrdColor);
|
|
ZX_PROP("ObjLimit.BackgrdColorAlpha", getBackgrdAlpha, setBackgrdAlpha);
|
|
}
|
|
|
|
void nmObjLimit::onSerialize(ZxSerializer* ser)
|
|
{
|
|
nmObjBase::onSerialize(ser);
|
|
|
|
ser->write("BackgrdColor", m_clrBackgrd);
|
|
|
|
// for ()
|
|
// {
|
|
// ser->write("BackgrdColor", m_clrBackgrd);
|
|
// }
|
|
}
|
|
|
|
void nmObjLimit::onDeserialize(ZxSerializer* ser)
|
|
{
|
|
nmObjBase::onDeserialize(ser);
|
|
|
|
ser->read("BackgrdColor", m_clrBackgrd);
|
|
}
|
|
|
|
void nmObjLimit::onSaveTempl(ZxSerializer* ser)
|
|
{
|
|
nmObjBase::onSaveTempl(ser);
|
|
|
|
ser->write("BackgrdColor", m_clrBackgrd);
|
|
}
|
|
|
|
void nmObjLimit::onLoadTempl(ZxSerializer* ser)
|
|
{
|
|
nmObjBase::onLoadTempl(ser);
|
|
|
|
ser->read("BackgrdColor", m_clrBackgrd);
|
|
}
|
|
|
|
//QColor nmObjLimit::getBackgrdColor() const
|
|
//{
|
|
// //if (m_nLineIndex)
|
|
// //return m_vecPresType[m_nLineIndex]
|
|
// return m_clrBackgrd;
|
|
//}
|
|
//void nmObjLimit::setBackgrdColor(QColor color)
|
|
//{
|
|
// if (m_clrBackgrd != color)
|
|
// {
|
|
// //m_vecPresType[m_nLineIndex] =
|
|
// m_clrBackgrd = color;
|
|
// update();
|
|
// }
|
|
//}
|
|
|
|
QColor nmObjLimit::getBackgrdColor() const
|
|
{
|
|
return m_clrBackgrd;
|
|
}
|
|
void nmObjLimit::setBackgrdColor(QColor clr)
|
|
{
|
|
m_clrBackgrd.setRed(clr.red());
|
|
m_clrBackgrd.setGreen(clr.green());
|
|
m_clrBackgrd.setBlue(clr.blue());
|
|
update();
|
|
}
|
|
|
|
int nmObjLimit::getBackgrdAlpha() const
|
|
{
|
|
return m_clrBackgrd.alpha();
|
|
}
|
|
void nmObjLimit::setBackgrdAlpha(int nAlpha)
|
|
{
|
|
m_clrBackgrd.setAlpha(nAlpha);
|
|
update();
|
|
}
|
|
|
|
void nmObjLimit::paintBack(QPainter* painter, const ZxPaintParam& param)
|
|
{
|
|
if (nullptr == m_pAxisX || nullptr == m_pAxisY || \
|
|
m_pAxisX->getRangeMin() == m_pAxisX->getRangeMax() || \
|
|
m_pAxisY->getRangeMin() == m_pAxisY->getRangeMax())
|
|
{
|
|
return;
|
|
}
|
|
|
|
painter->save();
|
|
|
|
QVector<QPointF> pts = getPosOf(m_vecPoints);
|
|
QRectF bound = getBounds();
|
|
|
|
if (!pts.empty())
|
|
{
|
|
// 填充
|
|
QPainterPath oPath;
|
|
oPath.moveTo(pts[0]);
|
|
for (int i = 1; i < pts.count(); i++)
|
|
{
|
|
oPath.lineTo(pts[i]);
|
|
}
|
|
oPath.closeSubpath();
|
|
// m_clrBackgrd.setAlpha(100);
|
|
painter->fillPath(oPath, QBrush(m_clrBackgrd));
|
|
|
|
// 边界
|
|
QPen pen = m_oPen;
|
|
painter->setPen(pen);
|
|
painter->drawPolygon(&pts[0], pts.count());
|
|
|
|
// 绘制名称文字
|
|
QFont ft = qApp->font();
|
|
ft.setPointSize(8);
|
|
painter->setFont(ft);
|
|
painter->setPen(Qt::black);
|
|
ZxDrawHelper::drawText(painter,
|
|
bound,
|
|
Qt::AlignCenter|Qt::AlignVCenter,
|
|
m_sName);
|
|
}
|
|
|
|
if (isSelected()) //选中状态下
|
|
{
|
|
QPen pen(QBrush(Qt::black), 0.0f, Qt::DotLine);
|
|
painter->setPen(pen);
|
|
painter->drawPolygon(&pts[0], pts.count());
|
|
for (int i = 0; i < pts.count(); i++)
|
|
{
|
|
double w = 2.2;
|
|
QPointF pt = pts[i];
|
|
QRectF rect(pt.x() - w * 0.5, pt.y() - w * 0.5, w, w);
|
|
if (m_nHitIndex == i && m_oHitOption == OHO_Point)
|
|
{
|
|
QBrush br(Qt::red);
|
|
painter->fillRect(rect, br);
|
|
}
|
|
// else if (m_nHitIndex == i && m_oHitOption == OHO_Bound)
|
|
// {
|
|
// //QBrush br(Qt::red);
|
|
// painter->setPen(QColor(0, 0, 255));
|
|
// painter->drawLine(pts[i], pts[i + 1]);
|
|
// }
|
|
else
|
|
{
|
|
painter->setPen(QColor(0, 0, 128));
|
|
painter->drawRect(rect);
|
|
}
|
|
}
|
|
}
|
|
|
|
painter->restore();
|
|
}
|