/*! Change the alignment of the scale The alignment sets the orientation of the scale and the position of the ticks: - QwtScaleDraw::BottomScale: horizontal, ticks below - QwtScaleDraw::TopScale: horizontal, ticks above - QwtScaleDraw::LeftScale: vertical, ticks left - QwtScaleDraw::RightScale: vertical, ticks right For horizontal scales the position corresponds to QwtPlotItem::yAxis(), otherwise to QwtPlotItem::xAxis(). \sa scaleDraw(), QwtScaleDraw::alignment(), setPosition() */ void QwtPlotScaleItem::setAlignment( QwtScaleDraw::Alignment alignment ) { QwtScaleDraw *sd = d_data->scaleDraw; if ( sd->alignment() != alignment ) { sd->setAlignment( alignment ); itemChanged(); } }
/*! \brief Draw the scale */ void QwtPlotScaleItem::draw( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect ) const { QwtScaleDraw *sd = d_data->scaleDraw; if ( d_data->scaleDivFromAxis ) { const QwtInterval interval = d_data->scaleInterval( canvasRect, xMap, yMap ); if ( interval != sd->scaleDiv().interval() ) { QwtScaleDiv scaleDiv = sd->scaleDiv(); scaleDiv.setInterval( interval ); sd->setScaleDiv( scaleDiv ); } } QPen pen = painter->pen(); pen.setStyle( Qt::SolidLine ); painter->setPen( pen ); if ( sd->orientation() == Qt::Horizontal ) { double y; if ( d_data->borderDistance >= 0 ) { if ( sd->alignment() == QwtScaleDraw::BottomScale ) y = canvasRect.top() + d_data->borderDistance; else { y = canvasRect.bottom() - d_data->borderDistance; } } else { y = yMap.transform( d_data->position ); } if ( y < canvasRect.top() || y > canvasRect.bottom() ) return; sd->move( canvasRect.left(), y ); sd->setLength( canvasRect.width() - 1 ); QwtTransform *transform = NULL; if ( xMap.transformation() ) transform = xMap.transformation()->copy(); sd->setTransformation( transform ); } else // == Qt::Vertical { double x; if ( d_data->borderDistance >= 0 ) { if ( sd->alignment() == QwtScaleDraw::RightScale ) x = canvasRect.left() + d_data->borderDistance; else { x = canvasRect.right() - d_data->borderDistance; } } else { x = xMap.transform( d_data->position ); } if ( x < canvasRect.left() || x > canvasRect.right() ) return; sd->move( x, canvasRect.top() ); sd->setLength( canvasRect.height() - 1 ); QwtTransform *transform = NULL; if ( yMap.transformation() ) transform = yMap.transformation()->copy(); sd->setTransformation( transform ); } painter->setFont( d_data->font ); sd->draw( painter, d_data->palette ); }
/*! \brief Draw the scale */ void QwtPlotScaleItem::draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const { if ( canvasRect != d_data->canvasRectCache ) { QwtPlotScaleItem* that = (QwtPlotScaleItem*)this; that->updateBorders(); } QPen pen = painter->pen(); pen.setStyle(Qt::SolidLine); painter->setPen(pen); int pw = painter->pen().width(); if ( pw == 0 ) pw = 1; QwtScaleDraw *sd = d_data->scaleDraw; if ( sd->orientation() == Qt::Horizontal ) { int y; if ( d_data->borderDistance >= 0 ) { if ( sd->alignment() == QwtScaleDraw::BottomScale ) y = canvasRect.top() + d_data->borderDistance; else { y = canvasRect.bottom() - d_data->borderDistance - pw + 1; } } else { y = yMap.transform(d_data->position); } if ( y < canvasRect.top() || y > canvasRect.bottom() ) return; sd->move(canvasRect.left(), y); sd->setLength(canvasRect.width() - 1); sd->setTransformation(xMap.transformation()->copy()); } else // == Qt::Vertical { int x; if ( d_data->borderDistance >= 0 ) { if ( sd->alignment() == QwtScaleDraw::RightScale ) x = canvasRect.left() + d_data->borderDistance; else { x = canvasRect.right() - d_data->borderDistance - pw + 1; } } else { x = xMap.transform(d_data->position); } if ( x < canvasRect.left() || x > canvasRect.right() ) return; sd->move(x, canvasRect.top()); sd->setLength(canvasRect.height() - 1); sd->setTransformation(yMap.transformation()->copy()); } painter->setFont(d_data->font); #if QT_VERSION < 0x040000 sd->draw(painter, d_data->colorGroup); #else sd->draw(painter, d_data->palette); #endif }