void QPaintWidget::drawCircle(QPainter *ppainter) { if (circle.radius !=0) { ppainter->save(); double posXCenter = scalePointX(circle.pos.x()); double posYCenter = scalePointY(circle.pos.y()); int sizeX = static_cast<int>(circle.radius/((maxX - minX) / canvasWidth())); int sizeY = static_cast<int>(circle.radius/((maxY - minY) / canvasHeight())); int size = kmin(sizeX, sizeY); ppainter->setPen(QPen(Qt::darkGreen, kDrawPenWidth)); ppainter->setBrush(QBrush(Qt::transparent)); ppainter->drawEllipse( posXCenter-size, posYCenter-size, 2*size+1, 2*size+1 ); ppainter->restore(); } }
/** * Initialize coordinate conversion. To be used before paint anything. */ void Plot2D::initPainterCoordinates() { const double dx = m_upperLeftCorner.x() - m_lowerRightCorner.x(); const double dy = m_lowerRightCorner.y() - m_upperLeftCorner.y(); m_padding.setSize(static_cast<double>(width()), static_cast<double>(height())); const Padding::Values paddingValues = m_padding.getPaddingValues(Padding::PIXELS); m_scaleX = (static_cast<double>(width()) * (1.0 - paddingValues.left - paddingValues.right)) / -dx; m_scaleY = (static_cast<double>(height()) * (1.0 - paddingValues.bottom - paddingValues.top)) / -dy; m_screenOriginX = scalePointX(0.0); m_screenOriginY = scalePointY(0.0); }
/** * Retrieve the scaled point from plot coordinates to widget coordinates. * * @param[in] x \f$X\f$ coordinate. * @param[in] y \f$Y\f$ coordinate. * * @return Point in widget coordinates. */ QPointF Plot2D::scalePoint(const double &x, const double &y) const { const double sx = scalePointX(x); const double sy = scalePointY(y); return QPointF(sx, sy); }
QPointF QPaintWidget::scalePoint(QPointF point) { return QPointF(scalePointX(point.x()) , scalePointY(point.y())); }