#include #include "nmObjLine.h" #include "nmObjLineTool.h" nmObjLineTool::nmObjLineTool() { setText(tr("nObjLineTool")); m_oNot = NOT_Line; } bool nmObjLineTool::onLeftDown(const QPointF& pt) { if (NULL == m_pObj) { m_ptStart = pt; m_bTracking = true; return true; } return nmObjPointTool::onLeftDown(pt); } bool nmObjLineTool::onMouseMove(const QPointF& pt) { if (NULL == m_pObj) { m_ptMove = pt; // Qt::CursorShape o = getCursorBy(0, 0); // changeCursor(o); if (m_bTracking) { m_rtTracker = getView()->adjustRectFitViewAspect(getTrackRect()); updateLastMoveArea(true); } return true; } return nmObjPointTool::onMouseMove(pt); } bool nmObjLineTool::onLeftUp(const QPointF& pt) { if (NULL == m_pObj) { getView()->setSnapshotMode(false); if (m_bTracking) { m_bTracking = false; } QVector vec; vec << m_ptStart << pt; emit sigPtsFinished(vec); return true; } return nmObjPointTool::onLeftUp(pt); } bool nmObjLineTool::onMouseWheel(const QPointF& pt, int delta) { return nmObjPointTool::onMouseWheel(pt, delta); } bool nmObjLineTool::onLeftDoubleClick(const QPointF& pt) { return nmObjPointTool::onLeftDoubleClick(pt); } void nmObjLineTool::onPaint(QPainter* painter, const ZxPaintParam& param) { nmObjLine* pObj = dynamic_cast(m_pObj); if (pObj == NULL) { Qt::CursorShape o = Qt::CrossCursor; if (m_bTracking) { painter->save(); QPen focus(Qt::DashLine); painter->setPen(focus); painter->drawLine(m_ptStart, getCurrentPos()); changeCursor(o); painter->restore(); } else { changeCursor(o); } } else { if (m_bTracking) { painter->save(); Qt::CursorShape o = getCursorBy((int)m_oHitOption, pObj->m_nHitIndex); QVector vec = pObj->getAllPos(); if (m_oHitOption == OHO_Point && pObj->m_nHitIndex == 0) { QPen focus(Qt::DashLine); QPointF endPoint = vec[1]; painter->drawPoint(endPoint); painter->drawPoint(getCurrentPos()); painter->setPen(focus); painter->drawLine(endPoint, getCurrentPos()); } else if (m_oHitOption == OHO_Point && pObj->m_nHitIndex == 1) { QPen focus(Qt::DashLine); QPointF startPoint = vec[0]; painter->drawPoint(startPoint); painter->drawPoint(getCurrentPos()); painter->setPen(focus); painter->drawLine(startPoint, getCurrentPos()); } else if (m_oHitOption == OHO_Bound) { QPen focus(Qt::DashLine); QPointF pt1 = vec[0]; QPointF pt2 = vec[1]; QPointF ptOld = m_ptStart; QPointF ptNew = getCurrentPos(); pt1 = pObj->offsetPoint(pt1, ptOld, ptNew); pt2 = pObj->offsetPoint(pt2, ptOld, ptNew); painter->drawPoint(pt1); painter->drawPoint(pt2); painter->setPen(focus); painter->drawLine(pt1, pt2); } changeCursor(o); painter->restore(); } } } Qt::CursorShape nmObjLineTool::getCursorBy(const int& nOption, const int& nSubIndex) { if (nOption < 0) { return Qt::ArrowCursor; } ObjHitOption oHitOption = (ObjHitOption)nOption; if (oHitOption == OHO_Point) { return (Qt::CrossCursor); } else if (oHitOption == OHO_Bound) { return (Qt::SizeAllCursor); } return Qt::ArrowCursor; }