/*! Draws the label for a major scale tick \param painter Painter \param value Value \sa drawTick(), drawBackbone() */ void QwtRoundScaleDraw::drawLabel( QPainter *painter, double value ) const { const QwtText label = tickLabel( painter->font(), value ); if ( label.isEmpty() ) return; const double tval = scaleMap().transform( value ); if ( ( tval > d_data->startAngle + 359 * 16 ) || ( tval < d_data->startAngle - 359 * 16 ) ) { return; } double radius = d_data->radius; if ( hasComponent( QwtAbstractScaleDraw::Ticks ) || hasComponent( QwtAbstractScaleDraw::Backbone ) ) { radius += spacing(); } if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ) radius += tickLength( QwtScaleDiv::MajorTick ); const QSizeF sz = label.textSize( painter->font() ); const double arc = tval / 16.0 / 360.0 * 2 * M_PI; const double x = d_data->center.x() + ( radius + sz.width() / 2.0 ) * qSin( arc ); const double y = d_data->center.y() - ( radius + sz.height() / 2.0 ) * cos( arc ); const QRectF r( x - sz.width() / 2, y - sz.height() / 2, sz.width(), sz.height() ); label.draw( painter, r ); }
/*! Find the position, where to paint a label The position has a distance that depends on the length of the ticks in direction of the alignment(). \param value Value \return Position, where to paint a label */ QPointF QwtScaleDraw::labelPosition( double value ) const { const double tval = scaleMap().transform( value ); double dist = spacing(); if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) dist += qMax( 1, penWidth() ); if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ) dist += tickLength( QwtScaleDiv::MajorTick ); double px = 0; double py = 0; switch ( alignment() ) { case RightScale: { px = d_data->pos.x() + dist; py = tval; break; } case LeftScale: { px = d_data->pos.x() - dist; py = tval; break; } case BottomScale: { px = tval; py = d_data->pos.y() + dist; break; } case TopScale: { px = tval; py = d_data->pos.y() - dist; break; } } return QPointF( px, py ); }
void ScaleDraw::drawInwardTick(QPainter *painter, double value, int len) const { ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis()); if (sc_engine->hasBreak() && (sc_engine->axisBreakLeft() <= value && sc_engine->axisBreakRight() >= value)) return; int pw2 = qwtMin((int)painter->pen().width(), len) / 2; QwtScaleMap scaleMap = map(); const QwtMetricsMap metricsMap = QwtPainter::metricsMap(); QPoint pos = this->pos(); int majLen = tickLength(QwtScaleDiv::MajorTick); if ( !metricsMap.isIdentity() ){ /* The perfect position of the ticks is important. To avoid rounding errors we have to use device coordinates. */ QwtPainter::resetMetricsMap(); pos = metricsMap.layoutToDevice(pos); if ( orientation() == Qt::Vertical ){ scaleMap.setPaintInterval( metricsMap.layoutToDeviceY((int)scaleMap.p1()), metricsMap.layoutToDeviceY((int)scaleMap.p2()) ); len = metricsMap.layoutToDeviceX(len); majLen = metricsMap.layoutToDeviceX(majLen); } else { scaleMap.setPaintInterval( metricsMap.layoutToDeviceX((int)scaleMap.p1()), metricsMap.layoutToDeviceX((int)scaleMap.p2()) ); len = metricsMap.layoutToDeviceY(len); majLen = metricsMap.layoutToDeviceY(majLen); } } const int clw = d_plot->canvasLineWidth(); const int tval = scaleMap.transform(value); bool draw = false; if ( orientation() == Qt::Vertical ){ int low = (int)scaleMap.p2() + majLen; int high = (int)scaleMap.p1() - majLen; if ((tval > low && tval < high) || (tval > high && !d_plot->axisEnabled (QwtPlot::xBottom) && !clw) || (tval < low && !d_plot->axisEnabled(QwtPlot::xTop) && !clw)) draw = true; } else { int low = (int)scaleMap.p1() + majLen; int high = (int)scaleMap.p2() - majLen; if ((tval > low && tval < high) || (tval > high && !d_plot->axisEnabled(QwtPlot::yRight) && !clw) || (tval < low && !d_plot->axisEnabled(QwtPlot::yLeft) && !clw)) draw = true; } if (draw){ switch(alignment()){ case LeftScale: { QwtPainter::drawLine(painter, pos.x() + pw2, tval, pos.x() + len, tval); break; } case RightScale: { QwtPainter::drawLine(painter, pos.x() - pw2, tval, pos.x() - len, tval); break; } case BottomScale: { QwtPainter::drawLine(painter, tval, pos.y() - pw2, tval, pos.y() - len); break; } case TopScale: { QwtPainter::drawLine(painter, tval, pos.y() + pw2, tval, pos.y() + len); break; } } } QwtPainter::setMetricsMap(metricsMap); // restore metrics map }