/*! Calculate the width/height that is needed for a vertical/horizontal scale. The extent is calculated from the pen width of the backbone, the major tick length, the spacing and the maximum width/height of the labels. \param pen Pen that is used for painting backbone and ticks \param font Font used for painting the labels \sa minLength() */ int QwtScaleDraw::extent(const QPen &pen, const QFont &font) const { int d = 0; if ( hasComponent(QwtAbstractScaleDraw::Labels) ) { if ( orientation() == Qt::Vertical ) d = maxLabelWidth(font); else d = maxLabelHeight(font); if ( d > 0 ) d += spacing(); } if ( hasComponent(QwtAbstractScaleDraw::Ticks) ) { d += majTickLength(); } if ( hasComponent(QwtAbstractScaleDraw::Backbone) ) { const int pw = qwtMax( 1, pen.width() ); // penwidth can be zero d += pw; } d = qwtMax(d, minimumExtent()); return d; }
void ScaleDraw::drawBreak(QPainter *painter) const { ScaleEngine *sc_engine = static_cast<ScaleEngine *>(d_plot->axisScaleEngine(axis())); /*const QwtScaleEngine * qwtsc_engine=d_plot->axisScaleEngine(axis()); const ScaleEngine *sc_engine =dynamic_cast<const ScaleEngine*>(qwtsc_engine); if(sc_engine!=NULL) {*/ if (!sc_engine->hasBreak() || !sc_engine->hasBreakDecoration()) return; painter->save(); painter->setRenderHint(QPainter::Antialiasing); int len = majTickLength(); QwtScaleMap scaleMap = map(); const QwtMetricsMap metricsMap = QwtPainter::metricsMap(); QPoint pos = this->pos(); if (!metricsMap.isIdentity()) { 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); } else { scaleMap.setPaintInterval(metricsMap.layoutToDeviceX((int)scaleMap.p1()), metricsMap.layoutToDeviceX((int)scaleMap.p2())); len = metricsMap.layoutToDeviceY(len); } } int lval = scaleMap.transform(sc_engine->axisBreakLeft()); int rval = scaleMap.transform(sc_engine->axisBreakRight()); switch (alignment()) { case LeftScale: QwtPainter::drawLine(painter, pos.x(), lval, pos.x() - len, lval + len); QwtPainter::drawLine(painter, pos.x(), rval, pos.x() - len, rval + len); break; case RightScale: QwtPainter::drawLine(painter, pos.x(), lval, pos.x() + len, lval - len); QwtPainter::drawLine(painter, pos.x(), rval, pos.x() + len, rval - len); break; case BottomScale: QwtPainter::drawLine(painter, lval, pos.y(), lval - len, pos.y() + len); QwtPainter::drawLine(painter, rval, pos.y(), rval - len, pos.y() + len); break; case TopScale: QwtPainter::drawLine(painter, lval, pos.y(), lval + len, pos.y() - len); QwtPainter::drawLine(painter, rval, pos.y(), rval + len, pos.y() - len); break; } QwtPainter::setMetricsMap(metricsMap); // restore metrics map painter->restore(); //} }
/*! Find the position, where to paint a label The position has a distance of majTickLength() + spacing() + 1 from the backbone. The direction depends on the alignment() \param value Value */ QPointF QwtScaleDraw::labelPosition( double value ) const { const double tval = map().transform( value ); double dist = spacing(); if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) dist += qMax( 1, penWidth() ); if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ) dist += majTickLength(); 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 ); }