#include #include #include "IxPtyPano.h" #include "ZxSubAxisX.h" #include "ZxSubAxisY.h" #include "ZxPlot.h" #include "ZxObjText.h" #include "nmObjPointTool.h" #include "nmObjPoint.h" ZX_DEFINE_DYNAMIC(nObjPoint, nmObjPoint) nmObjPoint::nmObjPoint() { m_sObjTag = "nObjPoint"; init("", NULL, NULL); } nmObjPoint::nmObjPoint(const QString& sName, \ ZxSubAxisX* pAxisX, \ ZxSubAxisY* pAxisY) : nmObjBase(sName, pAxisX, pAxisY) { m_sObjTag = "nObjPoint"; init(sName, pAxisX, pAxisY); } void nmObjPoint::init(const QString& sName, \ ZxSubAxisX* pAxisX, \ ZxSubAxisY* pAxisY) { nmObjBase::init(sName, pAxisX, pAxisY); initFlags(); m_oDot = ZxDot(DTS_DownTriangle, QColor(255,0,0,125), 1.f, true); m_sDesc = ""; m_bShowSubObjs = true; m_oDot = ZxDot(DTS_Circle, QColor(0, 255, 0), 1.5f, true); m_clrFillUnvalid = QColor(0, 255, 255); m_clrOuter = QColor(255, 0, 0); m_vecPoints << QPointF(0.f, 0.f); loadTempl(); } nmObjPoint::~nmObjPoint() { } void nmObjPoint::initTools() { m_pTool = new nmObjPointTool(); nmObjBase::initTools(); } void nmObjPoint::initFlags() { setLockPos(false); setLockSize(false); setReadOnly(false); } void nmObjPoint::initSubObjs() { ZxPlot* pPlot = dynamic_cast(this->getParent()); if (NULL != pPlot) { QString sName = ""; ZxObjBase* p = pPlot->addOneObj(POT_Text, sName, false, \ m_pAxisX, m_pAxisY); appendSubObjs(p); ZxObjText* pBoundText = dynamic_cast(p); Q_ASSERT (NULL != pBoundText); pBoundText->setFrameVisible(false); QColor clr = QColor(255, 255, 255, 64); pBoundText->setBackgroundColor(clr); pBoundText->setReadOnly(true); int n = Qt::AlignHCenter | Qt::AlignVCenter; pBoundText->setAlignFlag(n); pBoundText->setFont(QFont("Times",8)); pBoundText->deselect(true); pBoundText->deselectOthers(); pBoundText->setText(tr("Point")); } } bool nmObjPoint::hitTest(const QPointF& pt) { return nmObjBase::hitTest(pt); } bool nmObjPoint::_runHitTest(const QPointF& pt, int& nOption, int& nSubIndex) { if (!nmObjBase::_runHitTest(pt, nOption, nSubIndex)) { return false; } nOption = -1; nSubIndex = 0; Q_ASSERT (NULL != m_pAxisX); Q_ASSERT (NULL != m_pAxisY); QPointF ptPos = getCenterPos(); QPointF ptTopLeft = QPointF(ptPos.x() - m_oDot.radius(), ptPos.y() - m_oDot.radius()); QSizeF sz = QSizeF(m_oDot.radius() * 2.f, m_oDot.radius() * 2.f); QRectF rt = QRectF(ptTopLeft, sz); bool b = rt.contains(pt); if (b) { nOption = (int)OHO_Point; nSubIndex = 0; } else { nOption = (int)OHO_None; nSubIndex = -1; } return b; } bool nmObjPoint::runMove(const QPointF& pt1, const QPointF& pt2) { if (isLockPos()) { return false; } if (m_oHitOption == OHO_Point) { QVector vec = getAllPos(); vec[0] = pt2; //setPtPosOf(0, pt2); return moveToPos(vec); } return nmObjBase::runMove(pt1, pt2); } void nmObjPoint::fillPtyPano(IxPtyPano* sheet) { nmObjBase::fillPtyPano(sheet); ZX_PROP("Point.Dot", getDot, setDot); } void nmObjPoint::onSerialize(ZxSerializer* ser) { nmObjBase::onSerialize(ser); ser->write("PDesc", m_sDesc); ser->write("ClrFillUnvalid", m_clrFillUnvalid); ser->write("ClrOuter", m_clrOuter); } void nmObjPoint::onDeserialize(ZxSerializer* ser) { nmObjBase::onDeserialize(ser); ser->read("PDesc", m_sDesc); ser->read("ClrFillUnvalid", m_clrFillUnvalid); ser->read("ClrOuter", m_clrOuter); } void nmObjPoint::onSaveTempl(ZxSerializer* ser) { nmObjBase::onSaveTempl(ser); ser->write("PDesc", m_sDesc); ser->write("ClrFillUnvalid", m_clrFillUnvalid); ser->write("ClrOuter", m_clrOuter); } void nmObjPoint::onLoadTempl(ZxSerializer* ser) { nmObjBase::onLoadTempl(ser); ser->read("PDesc", m_sDesc); ser->read("ClrFillUnvalid", m_clrFillUnvalid); ser->read("ClrOuter", m_clrOuter); } //QColor nmObjPolygon::getBackgrdColor() const //{ // return m_clrBackgrd; //} //void nmObjPolygon::setBackgrdColor(QColor color) //{ // if (m_clrBackgrd != color) // { // m_clrBackgrd = color; // update(); // } //} void nmObjPoint::paintBack(QPainter* painter, const ZxPaintParam& param) { QPointF ptPos = getPosOf(m_vecPoints[0]); drawWellPos(painter, ptPos); } bool nmObjPoint::drawWellPos(QPainter* painter, QPointF ptPos) { Q_ASSERT (NULL != m_pAxisX); Q_ASSERT (NULL != m_pAxisY); if (m_pAxisX->getRangeMin() == m_pAxisX->getRangeMax() || \ m_pAxisY->getRangeMin() == m_pAxisY->getRangeMax()) { return false; } painter->save(); // 绘制填充 float r = m_oDot.radius(); // if (bCenter) // { // r *= 1.2f; // } QColor clrInner = m_oDot.color(); ZxDrawHelper::drawPoint(painter, ptPos, (int)m_oDot.style(), r, m_oDot.isFilling(), clrInner); //if (bCenter) { ZxDrawHelper::drawPoint(painter, ptPos, (int)m_oDot.style(), m_oDot.radius() * 0.5f, m_oDot.isFilling(), QColor(255, 0, 0)); } painter->setPen(m_clrOuter); painter->drawEllipse(ptPos, r, r); painter->restore(); /*{ QPointF ptPos = getCenterPos(); ///绘制填充色 paintDotPt(painter, ptPos, m_oDot); painter->restore(); }//*/ return true; } void nmObjPoint::setValueX(float x) { m_vecPoints[0].setX(x); update(); } float nmObjPoint::getValueX() { return m_vecPoints[0].x(); } void nmObjPoint::setValueY(float y) { m_vecPoints[0].setY(y); update(); } float nmObjPoint::getValueY() { return m_vecPoints[0].y(); } void nmObjPoint::setDesc(QString sDesc) { m_sDesc = sDesc; } QString nmObjPoint::getDesc() { return m_sDesc; } void nmObjPoint::resetOthers() { if (getChildren().count() <= 0) { return; } ZxObjText* pBoundText = dynamic_cast(at(0)); if (NULL == pBoundText) { return; } QString sText = pBoundText->getText(); pBoundText->setText(sText); QPointF pt = getCenterPos(); pBoundText->resetBoundsEx(sText, QPointF(pt.rx() - 2,pt.ry() -2)); pBoundText->deselect(true); pBoundText->deselectOthers(); } QPointF nmObjPoint::getCenterPos() { return getPosOf(m_vecPoints[0]); } void nmObjPoint::setPointTag(QString s) { if (getChildren().count() <= 0) { return; } ZxObjText* pBoundText = dynamic_cast(at(0)); if (NULL == pBoundText) { return; } pBoundText->setText(s); } void nmObjPoint::resetBounds() { QPointF pt1 = getPosOf(m_vecPoints[0]); QRectF rcClient(pt1.x()-(2+m_oDot.radius()/2),pt1.y()-(2+m_oDot.radius()/2),4+m_oDot.radius(),4+m_oDot.radius()); setBounds(rcClient); m_rtBoundVs = calValueBounds(); resetOthers(); } QRectF nmObjPoint::getBounds4Update() { if (m_vecPoints.count() != 1) { return nmObjBase::getBounds4Update(); } else { QPointF pt = getPosOf(m_vecPoints[0]); return QRectF(pt.x() - (2 + m_oDot.radius()), pt.y() - (2 + m_oDot.radius()), 4 + m_oDot.radius() * 2, 4 + m_oDot.radius() * 2); } }