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;
311 return d_data->alignment;
324 d_data->alignment =
align;
339 switch ( d_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];
379 double minPos = scaleMap().transform( minTick );
380 double maxTick = minTick;
381 double maxPos = minPos;
383 for (
int i = 1; i < ticks.count(); i++ )
385 const double tickPos = scaleMap().transform( ticks[i] );
386 if ( tickPos < minPos )
391 if ( tickPos > scaleMap().transform( maxTick ) )
400 if ( orientation() == Qt::Vertical )
402 s = -labelRect( font, minTick ).top();
403 s -= qAbs( minPos - qRound( scaleMap().p2() ) );
405 e = labelRect( font, maxTick ).bottom();
406 e -= qAbs( maxPos - scaleMap().p1() );
410 s = -labelRect( font, minTick ).left();
411 s -= qAbs( minPos - scaleMap().p1() );
413 e = labelRect( font, maxTick ).right();
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++ )
461 bRect2 = labelRect( font, ticks[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 );
529 if ( orientation() == Qt::Vertical )
530 d = maxLabelWidth( font );
532 d = maxLabelHeight( font );
540 d += maxTickLength();
548 d =
qwtMaxF( d, minimumExtent() );
562 int startDist, endDist;
563 getBorderDistHint( font, startDist, endDist );
567 const uint minorCount =
570 const uint majorCount =
573 int lengthForLabels = 0;
575 lengthForLabels = minLabelDist( font ) * majorCount;
577 int lengthForTicks = 0;
581 lengthForTicks = qCeil( ( majorCount + minorCount ) * ( pw + 1.0 ) );
584 return startDist + endDist + qMax( lengthForLabels, lengthForTicks );
598 const double tval = scaleMap().transform( value );
599 double dist = spacing();
609 switch ( alignment() )
613 px = d_data->pos.x() + dist;
619 px = d_data->pos.x() - dist;
626 py = d_data->pos.y() + dist;
632 py = d_data->pos.y() - dist;
637 return QPointF( px, py );
654 const double tval = scaleMap().transform( value );
735 if ( length >= 0 && length < 10 )
739 if ( length < 0 && length > -10 )
742 length =
qwtMaxF( length, 10.0 );
745 d_data->len = length;
768 QwtText lbl = tickLabel( painter->font(), value );
772 QPointF pos = labelPosition( value );
774 QSizeF labelSize = lbl.
textSize( painter->font() );
776 const QTransform transform = labelTransformation( pos, labelSize );
779 painter->setWorldTransform( transform,
true );
781 lbl.
draw ( painter, QRect( QPoint( 0, 0 ), labelSize.toSize() ) );
800 QwtText lbl = tickLabel( font, value );
804 const QPointF pos = labelPosition( value );
805 QSizeF labelSize = lbl.
textSize( font );
807 const QTransform transform = labelTransformation( pos, labelSize );
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() );
826 transform.rotate( labelRotation() );
828 int flags = labelAlignment();
831 switch ( alignment() )
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 );
893 QwtText lbl = tickLabel( font, value );
895 return QRectF( 0.0, 0.0, 0.0, 0.0 );
897 const QPointF pos = labelPosition( value );
899 const QSizeF labelSize = lbl.
textSize( font );
900 const QTransform transform = labelTransformation( pos, labelSize );
902 QRectF br = transform.mapRect( QRectF( QPointF( 0, 0 ), labelSize ) );
903 br.translate( -pos.x(), -pos.y() );
918 return labelRect( font, value ).size();
936 d_data->labelRotation = rotation;
945 return d_data->labelRotation;
975 d_data->labelAlignment = alignment;
984 return d_data->labelAlignment;
993 double maxWidth = 0.0;
996 for (
int i = 0; i < ticks.count(); i++ )
998 const double v = ticks[i];
999 if ( scaleDiv().contains( v ) )
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];
1022 if ( scaleDiv().contains( v ) )
1024 const double h = labelSize( font, ticks[i] ).height();
1025 if ( h > maxHeight )
1030 return qCeil( maxHeight );
1035 const QPointF pos = d_data->pos;
1036 double len = d_data->len;
1039 if ( orientation() == Qt::Vertical )
A abstract base class for drawing scales.
void setAlignment(Alignment)
void setLength(double length)
virtual void drawTick(QPainter *, double value, double len) const QWT_OVERRIDE
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
static double qwtEffectivePenWidth(const QwtAbstractScaleDraw *scaleDraw)
QWT_CONSTEXPR float qwtMaxF(float a, float b)
void draw(QPainter *painter, const QRectF &rect) const
QPointF labelPosition(double value) const
A class representing a scale division.
void getBorderDistHint(const QFont &, int &start, int &end) const
Determine the minimum border distance.
QwtScaleDraw()
Constructor.
int minLength(const QFont &) const
void drawBackbone(QPainter *painter, const QwtScaleDraw *scaleDraw)
QRect boundingLabelRect(const QFont &, double value) const
Find the bounding rectangle for the label.
int minLabelDist(const QFont &) const
virtual ~QwtScaleDraw()
Destructor.
int maxLabelWidth(const QFont &) const
virtual void drawBackbone(QPainter *) const QWT_OVERRIDE
QTransform labelTransformation(const QPointF &, const QSizeF &) const
virtual void drawLabel(QPainter *, double value) const QWT_OVERRIDE
void * align(std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space, std::size_t &required_space)
Alignment alignment() const
double qwtRadians(double degrees)
Translate degrees into radians.
void drawBackbone(QPainter *painter, const QwtScaleDraw *scaleDraw)
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
A class representing a text.
void setLabelRotation(double rotation)
Backbone = the line where the ticks are located.
Qt::Orientation orientation() const
Qt::Alignment labelAlignment() const
QRectF labelRect(const QFont &, double value) const
void drawTick(QPainter *painter, const QwtScaleDraw *scaleDraw, qreal tickPos, qreal tickLength)
virtual double extent(const QFont &) const QWT_OVERRIDE
int maxLabelHeight(const QFont &) const
bool hasComponent(ScaleComponent) const
QSizeF labelSize(const QFont &, double value) const
A class for drawing scales.
qreal penWidth(const QPainter *painter, const QwtScaleDraw *scaleDraw)
Qt::Alignment labelAlignment
QList< double > ticks(int tickType) const
double labelRotation() const
void drawTick(QPainter *painter, const QwtScaleDraw *scaleDraw, qreal tickPos, qreal tickLength)
void setLabelAlignment(Qt::Alignment)
Change the label flags.
static bool roundingAlignment()
void move(double x, double y)