10 #include "qwt_scale_draw.h" 
   11 #include "qwt_scale_div.h" 
   12 #include "qwt_scale_map.h" 
   14 #include "qwt_painter.h" 
   18 #include <qpaintengine.h> 
   23     return qwtMaxF( scaleDraw->
penWidthF(), 1.0 );
 
   26 namespace QwtScaleRendererReal
 
   28     inline qreal penWidth( 
const QPainter* painter, 
const QwtScaleDraw* scaleDraw )
 
   36         if ( painter->pen().isCosmetic() )
 
   38             const QTransform& transform = painter->transform();
 
   45                     width /= transform.m11();
 
   51                     width /= transform.m22();
 
   60     inline void drawBackbone( QPainter* painter, 
const QwtScaleDraw* scaleDraw )
 
   62         const qreal pw2 = 0.5 * penWidth( painter, scaleDraw );
 
   64         const QPointF pos = scaleDraw->
pos();
 
   65         const qreal length = scaleDraw->
length();
 
   71                 const qreal x = pos.x() + 1.0 - pw2;
 
   78                 const qreal x = pos.x() - 1.0 + pw2;
 
   85                 const qreal y = pos.y() + 1.0 - pw2;
 
   92                 const qreal y = pos.y() - 1.0 + pw2;
 
  100     inline void drawTick( QPainter* painter,
 
  101         const QwtScaleDraw* scaleDraw, qreal tickPos, qreal tickLength )
 
  103         const QPointF pos = scaleDraw->
pos();
 
  108             pw = penWidth( painter, scaleDraw );
 
  110         const qreal length = tickLength + pw;
 
  117         const qreal off1 = 1.0;
 
  118         const qreal off2 = ( scaleDraw->
penWidthF() <= 0.0 ) ? 0.5 : 0.0;
 
  124                 const qreal x = pos.x() + off1 - off2;
 
  131                 const qreal x = pos.x() - off1 + off2;
 
  137                 const qreal y = pos.y() + off1 - 2 * off2;
 
  144                 const qreal y = pos.y() - off1 + off2;
 
  153 namespace QwtScaleRendererInt
 
  155     inline void drawBackbone( QPainter* painter, 
const QwtScaleDraw* scaleDraw )
 
  157         const int pw = qMax( qRound( scaleDraw->
penWidthF() ), 1 );
 
  159         const qreal length = scaleDraw->
length();
 
  160         const QPointF pos = scaleDraw->
pos();
 
  166                 const qreal x = qRound( pos.x() - ( pw - 1 ) / 2 );
 
  173                 const qreal x = qRound( pos.x() + pw / 2 );
 
  180                 const qreal y = qRound( pos.y() - ( pw - 1 ) / 2 );
 
  187                 const qreal y = qRound( pos.y() + pw / 2 );
 
  195     inline void drawTick( QPainter* painter,
 
  196         const QwtScaleDraw* scaleDraw, qreal tickPos, qreal tickLength )
 
  198         const QPointF pos = scaleDraw->
pos();
 
  199         tickPos = qRound( tickPos );
 
  203             pw = qMax( qRound( scaleDraw->
penWidthF() ), 1 );
 
  205         int len = qMax( qRound( tickLength ), 1 );
 
  210         if ( painter->pen().capStyle() == Qt::FlatCap )
 
  215         if ( painter->paintEngine()->type() == QPaintEngine::X11 )
 
  228                 const qreal x1 = qRound( pos.x() ) + 1;
 
  229                 const qreal x2 = x1 - len + 1;
 
  237                 const qreal x1 = qRound( pos.x() );
 
  238                 const qreal x2 = x1 + len - 1;
 
  246                 const qreal y1 = qRound( pos.y() );
 
  247                 const qreal y2 = y1 + len - 1;
 
  255                 const qreal y1 = qRound( pos.y() );
 
  256                 const qreal y2 = y1 - len + 1;
 
  266 class QwtScaleDraw::PrivateData
 
  294     m_data = 
new QwtScaleDraw::PrivateData;
 
  311     return m_data->alignment;
 
  324     m_data->alignment = align;
 
  339     switch ( m_data->alignment )
 
  343             return Qt::Horizontal;
 
  362     const QFont& font, 
int& start, 
int& end )
 const 
  371     if ( ticks.count() == 0 )
 
  378     double minTick = ticks[0];
 
  380     double maxTick = minTick;
 
  381     double maxPos = minPos;
 
  383     for ( 
int i = 1; i < ticks.count(); i++ )
 
  386         if ( tickPos < minPos )
 
  391         if ( tickPos > 
scaleMap().transform( maxTick ) )
 
  403         s -= qAbs( minPos - qRound( 
scaleMap().p2() ) );
 
  406         e -= qAbs( maxPos - 
scaleMap().p1() );
 
  411         s -= qAbs( minPos - 
scaleMap().p1() );
 
  414         e -= qAbs( maxPos - 
scaleMap().p2() );
 
  422     start = qwtCeil( s );
 
  442     if ( ticks.isEmpty() )
 
  445     const QFontMetrics fm( font );
 
  447     const bool vertical = ( 
orientation() == Qt::Vertical );
 
  450     QRectF bRect2 = 
labelRect( font, ticks[0] );
 
  453         bRect2.setRect( -bRect2.bottom(), 0.0, bRect2.height(), bRect2.width() );
 
  456     double maxDist = 0.0;
 
  458     for ( 
int i = 1; i < ticks.count(); i++ )
 
  464             bRect2.setRect( -bRect2.bottom(), 0.0,
 
  465                 bRect2.height(), bRect2.width() );
 
  468         double dist = fm.leading(); 
 
  469         if ( bRect1.right() > 0 )
 
  470             dist += bRect1.right();
 
  471         if ( bRect2.left() < 0 )
 
  472             dist += -bRect2.left();
 
  474         if ( dist > maxDist )
 
  482     const double sinA = qFastSin( angle ); 
 
  483     if ( qFuzzyCompare( sinA + 1.0, 1.0 ) )
 
  484         return qCeil( maxDist );
 
  486     const int fmHeight = fm.ascent() - 2;
 
  492     double labelDist = fmHeight / qFastSin( angle ) * qFastCos( angle );
 
  494         labelDist = -labelDist;
 
  498     if ( labelDist > maxDist )
 
  504     if ( labelDist < fmHeight )
 
  505         labelDist = fmHeight;
 
  507     return qCeil( labelDist );
 
  545         d += qwtEffectivePenWidth( 
this );
 
  562     int startDist, endDist;
 
  567     const uint minorCount =
 
  570     const uint majorCount =
 
  573     int lengthForLabels = 0;
 
  577     int lengthForTicks = 0;
 
  580         const double pw = qwtEffectivePenWidth( 
this );
 
  581         lengthForTicks = qCeil( ( majorCount + minorCount ) * ( pw + 1.0 ) );
 
  584     return startDist + endDist + qMax( lengthForLabels, lengthForTicks );
 
  601         dist += qwtEffectivePenWidth( 
this );
 
  613             px = m_data->pos.x() + dist;
 
  619             px = m_data->pos.x() - dist;
 
  626             py = m_data->pos.y() + dist;
 
  632             py = m_data->pos.y() - dist;
 
  637     return QPointF( px, py );
 
  657         QwtScaleRendererInt::drawTick( painter, 
this, tval, len );
 
  659         QwtScaleRendererReal::drawTick( painter, 
this, tval, len );
 
  671         QwtScaleRendererInt::drawBackbone( painter, 
this );
 
  673         QwtScaleRendererReal::drawBackbone( painter, 
this );
 
  739     if ( length < 0 && length > -10 )
 
  779     painter->setWorldTransform( transform, 
true );
 
  781     lbl.
draw ( painter, QRect( QPoint( 0, 0 ), 
labelSize.toSize() ) );
 
  808     return transform.mapRect( QRect( QPoint( 0, 0 ), 
labelSize.toSize() ) );
 
  822     const QPointF& pos, 
const QSizeF& size )
 const 
  824     QTransform transform;
 
  825     transform.translate( 
pos.x(), 
pos.y() );
 
  836                     flags = Qt::AlignRight | Qt::AlignVCenter;
 
  842                     flags = Qt::AlignLeft | Qt::AlignVCenter;
 
  848                     flags = Qt::AlignHCenter | Qt::AlignBottom;
 
  854                     flags = Qt::AlignHCenter | Qt::AlignTop;
 
  862     if ( flags & Qt::AlignLeft )
 
  864     else if ( flags & Qt::AlignRight )
 
  867         x = -( 0.5 * size.width() );
 
  869     if ( flags & Qt::AlignTop )
 
  871     else if ( flags & Qt::AlignBottom )
 
  874         y = -( 0.5 * size.height() );
 
  876     transform.translate( x, y );
 
  895         return QRectF( 0.0, 0.0, 0.0, 0.0 );
 
  902     QRectF br = transform.mapRect( QRectF( QPointF( 0, 0 ), 
labelSize ) );
 
  903     br.translate( -
pos.x(), -
pos.y() );
 
  936     m_data->labelRotation = rotation;
 
  945     return m_data->labelRotation;
 
  984     return m_data->labelAlignment;
 
  993     double maxWidth = 0.0;
 
  996     for ( 
int i = 0; i < ticks.count(); i++ )
 
  998         const double v = ticks[i];
 
 1001             const double w = 
labelSize( font, ticks[i] ).width();
 
 1007     return qCeil( maxWidth );
 
 1016     double maxHeight = 0.0;
 
 1019     for ( 
int i = 0; i < ticks.count(); i++ )
 
 1021         const double v = ticks[i];
 
 1024             const double h = 
labelSize( font, ticks[i] ).height();
 
 1025             if ( h > maxHeight )
 
 1030     return qCeil( maxHeight );
 
 1033 void QwtScaleDraw::updateMap()
 
 1035     const QPointF 
pos = m_data->pos;
 
 1036     double len = m_data->len;
 
A abstract base class for drawing scales.
const QwtScaleMap & scaleMap() const
@ Backbone
Backbone = the line where the ticks are located.
double tickLength(QwtScaleDiv::TickType) const
bool hasComponent(ScaleComponent) const
const QwtText & tickLabel(const QFont &, double value) const
Convert a value into its representing label and cache it.
double maxTickLength() const
double minimumExtent() const
const QwtScaleDiv & scaleDiv() const
double spacing() const
Get the spacing.
static bool roundingAlignment()
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
A class representing a scale division.
QList< double > ticks(int tickType) const
@ MediumTick
Medium ticks.
A class for drawing scales.
void setLength(double length)
QRect boundingLabelRect(const QFont &, double value) const
Find the bounding rectangle for the label.
QTransform labelTransformation(const QPointF &, const QSizeF &) const
Qt::Alignment labelAlignment() const
void move(double x, double y)
double labelRotation() const
virtual void drawLabel(QPainter *, double value) const override
virtual double extent(const QFont &) const override
void getBorderDistHint(const QFont &, int &start, int &end) const
Determine the minimum border distance.
void setLabelAlignment(Qt::Alignment)
Change the label flags.
int minLength(const QFont &) const
virtual void drawTick(QPainter *, double value, double len) const override
QPointF labelPosition(double value) const
void setAlignment(Alignment)
virtual void drawBackbone(QPainter *) const override
Alignment alignment() const
virtual ~QwtScaleDraw()
Destructor.
int maxLabelHeight(const QFont &) const
Qt::Orientation orientation() const
void setLabelRotation(double rotation)
int maxLabelWidth(const QFont &) const
@ BottomScale
The scale is below.
@ TopScale
The scale is above.
@ RightScale
The scale is right.
@ LeftScale
The scale is left.
int minLabelDist(const QFont &) const
QwtScaleDraw()
Constructor.
QRectF labelRect(const QFont &, double value) const
QSizeF labelSize(const QFont &, double value) const
double transform(double s) const
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
A class representing a text.
void draw(QPainter *painter, const QRectF &rect) const