/** * Calls virtual drawShape() method to draw the actial shape. * Draws bounding rect and control points if the shape is selected. * * @param painter :: QPainter used for drawing. */ void Shape2D::draw(QPainter& painter) const { if (!m_visible) return; painter.setPen(m_color); this->drawShape(painter); if (m_editing || m_selected) { QColor c(255, 255, 255, 100); painter.setPen(c); painter.drawRect(m_boundingRect.toQRectF()); size_t np = NCommonCP; double rsize = 2; int alpha = 100; if (m_editing) { // if editing show all CP, make them bigger and opaque np = getNControlPoints(); rsize = sizeCP; alpha = 255; } for (size_t i = 0; i < np; ++i) { QPointF p = painter.transform().map(getControlPoint(i)); QRectF r(p - QPointF(rsize, rsize), p + QPointF(rsize, rsize)); painter.save(); painter.resetTransform(); QColor c(255, 255, 255, alpha); painter.fillRect(r, c); r.adjust(-1, -1, 0, 0); painter.setPen(QColor(0, 0, 0, alpha)); painter.drawRect(r); painter.restore(); } } }
QPointF Shape2D::getControlPoint(size_t i) const { if ( i >= getNControlPoints()) { throw std::range_error("Control point index is out of range"); } if ( i < 4 ) return m_boundingRect.vertex( i ); return getShapeControlPoint(i - NCommonCP); }
void Shape2D::setControlPoint(size_t i, const QPointF& pos) { if (i >= getNControlPoints()) { throw std::range_error("Control point index is out of range"); } if (i < 4) { m_boundingRect.setVertex(i, pos); refit(); } // else ? else setShapeControlPoint(i - NCommonCP, pos); resetBoundingRect(); }
void Shape2D::draw(QPainter& painter) const { painter.setPen(m_color); this->drawShape(painter); if (m_editing) { QColor c(255,255,255,100); painter.setPen(c); painter.setCompositionMode(QPainter::CompositionMode_Plus); painter.drawRect(m_boundingRect.toQRectF()); for(size_t i = 0; i < getNControlPoints(); ++i) { QPointF p = painter.transform().map(getControlPoint(i)); QRectF r(p - QPointF(sizeCP,sizeCP),p + QPointF(sizeCP,sizeCP)); painter.save(); painter.resetTransform(); painter.fillRect(r,c); painter.restore(); } } }