18 #include <qpaintengine.h>
36 if ( painter->pen().isCosmetic() )
38 const QTransform& transform = painter->transform();
45 width /= transform.m11();
51 width /= transform.m22();
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;
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;
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 );
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;
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() );
414 e -= qAbs( maxPos -
scaleMap().p2() );
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 );
562 int startDist, endDist;
567 const uint minorCount =
570 const uint majorCount =
573 int lengthForLabels = 0;
577 int lengthForTicks = 0;
581 lengthForTicks = qCeil( ( majorCount + minorCount ) * ( pw + 1.0 ) );
584 return startDist + endDist + qMax( lengthForLabels, lengthForTicks );
637 return QPointF( px, py );
738 if ( length < 0 && length > -10 )
775 painter->setWorldTransform( transform,
true );
777 lbl.
draw ( painter, QRect( QPoint( 0, 0 ),
labelSize.toSize() ) );
804 return transform.mapRect( QRect( QPoint( 0, 0 ),
labelSize.toSize() ) );
818 const QPointF& pos,
const QSizeF&
size )
const
820 QTransform transform;
821 transform.translate(
pos.x(),
pos.y() );
832 flags = Qt::AlignRight | Qt::AlignVCenter;
838 flags = Qt::AlignLeft | Qt::AlignVCenter;
844 flags = Qt::AlignHCenter | Qt::AlignBottom;
850 flags = Qt::AlignHCenter | Qt::AlignTop;
858 if ( flags & Qt::AlignLeft )
860 else if ( flags & Qt::AlignRight )
863 x = -( 0.5 *
size.width() );
865 if ( flags & Qt::AlignTop )
867 else if ( flags & Qt::AlignBottom )
870 y = -( 0.5 *
size.height() );
872 transform.translate(
x,
y );
891 return QRectF( 0.0, 0.0, 0.0, 0.0 );
898 QRectF br = transform.mapRect( QRectF( QPointF( 0, 0 ),
labelSize ) );
899 br.translate( -
pos.x(), -
pos.y() );
989 double maxWidth = 0.0;
992 for (
int i = 0; i < ticks.count(); i++ )
994 const double v = ticks[i];
997 const double w =
labelSize( font, ticks[i] ).width();
1003 return qCeil( maxWidth );
1012 double maxHeight = 0.0;
1015 for (
int i = 0; i < ticks.count(); i++ )
1017 const double v = ticks[i];
1020 const double h =
labelSize( font, ticks[i] ).height();
1021 if ( h > maxHeight )
1026 return qCeil( maxHeight );