19 #if QT_VERSION < 0x040601 20 #define qFastSin(x) qSin(x) 21 #define qFastCos(x) qCos(x) 102 return Qt::Horizontal;
121 const QFont &font,
int &start,
int &end )
const 130 if ( ticks.count() == 0 )
137 double minTick = ticks[0];
139 double maxTick = minTick;
140 double maxPos = minPos;
142 for (
int i = 1;
i < ticks.count();
i++ )
145 if ( tickPos < minPos )
150 if ( tickPos >
scaleMap().transform( maxTick ) )
162 s -= qAbs( minPos - qRound(
scaleMap().p2() ) );
165 e -= qAbs( maxPos -
scaleMap().p1() );
170 s -= qAbs( minPos -
scaleMap().p1() );
173 e -= qAbs( maxPos -
scaleMap().p2() );
201 if ( ticks.isEmpty() )
204 const QFontMetrics fm( font );
206 const bool vertical = (
orientation() == Qt::Vertical );
209 QRectF bRect2 =
labelRect( font, ticks[0] );
212 bRect2.setRect( -bRect2.bottom(), 0.0, bRect2.height(), bRect2.width() );
215 double maxDist = 0.0;
217 for (
int i = 1;
i < ticks.count();
i++ )
223 bRect2.setRect( -bRect2.bottom(), 0.0,
224 bRect2.height(), bRect2.width() );
227 double dist = fm.leading();
228 if ( bRect1.right() > 0 )
229 dist += bRect1.right();
230 if ( bRect2.left() < 0 )
231 dist += -bRect2.left();
233 if ( dist > maxDist )
241 const double sinA =
qFastSin( angle );
242 if ( qFuzzyCompare( sinA + 1.0, 1.0 ) )
243 return qCeil( maxDist );
245 const int fmHeight = fm.ascent() - 2;
253 labelDist = -labelDist;
257 if ( labelDist > maxDist )
263 if ( labelDist < fmHeight )
264 labelDist = fmHeight;
266 return qCeil( labelDist );
304 const double pw = qMax( 1,
penWidth() );
322 int startDist, endDist;
327 const uint minorCount =
330 const uint majorCount =
333 int lengthForLabels = 0;
337 int lengthForTicks = 0;
340 const double pw = qMax( 1,
penWidth() );
341 lengthForTicks = qCeil( ( majorCount + minorCount ) * ( pw + 1.0 ) );
344 return startDist + endDist + qMax( lengthForLabels, lengthForTicks );
397 return QPointF( px, py );
419 if ( roundingAlignment )
420 tval = qRound( tval );
424 if ( pw > 1 && roundingAlignment )
431 double x1 = pos.x() + a;
432 double x2 = pos.x() + a - pw -
len;
433 if ( roundingAlignment )
446 double x2 = pos.x() + pw +
len;
447 if ( roundingAlignment )
460 double y2 = pos.y() + pw +
len;
461 if ( roundingAlignment )
473 double y1 = pos.y() + a;
474 double y2 = pos.y() - pw - len + a;
475 if ( roundingAlignment )
499 const int pw = qMax(
penWidth(), 1 );
509 off = ( pw - 1 ) / 2;
522 double x = pos.x() - off;
531 double x = pos.x() + off;
540 double y = pos.y() - off;
549 double y = pos.y() + off;
618 if ( length >= 0 && length < 10 )
622 if ( length < 0 && length > -10 )
625 length = qMax( length, 10.0 );
662 painter->setWorldTransform( transform,
true );
664 lbl.
draw ( painter, QRect( QPoint( 0, 0 ), labelSize.toSize() ) );
691 return transform.mapRect( QRect( QPoint( 0, 0 ), labelSize.toSize() ) );
705 const QPointF &
pos,
const QSizeF &size )
const 707 QTransform transform;
708 transform.translate( pos.x(), pos.y() );
719 flags = Qt::AlignRight | Qt::AlignVCenter;
725 flags = Qt::AlignLeft | Qt::AlignVCenter;
731 flags = Qt::AlignHCenter | Qt::AlignBottom;
737 flags = Qt::AlignHCenter | Qt::AlignTop;
745 if ( flags & Qt::AlignLeft )
747 else if ( flags & Qt::AlignRight )
750 x = -( 0.5 * size.width() );
752 if ( flags & Qt::AlignTop )
754 else if ( flags & Qt::AlignBottom )
757 y = -( 0.5 * size.height() );
759 transform.translate( x, y );
778 return QRectF( 0.0, 0.0, 0.0, 0.0 );
785 QRectF br = transform.mapRect( QRectF( QPointF( 0, 0 ), labelSize ) );
786 br.translate( -pos.x(), -pos.y() );
876 double maxWidth = 0.0;
879 for (
int i = 0;
i < ticks.count();
i++ )
881 const double v = ticks[
i];
884 const double w =
labelSize( font, ticks[
i] ).width();
890 return qCeil( maxWidth );
899 double maxHeight = 0.0;
902 for (
int i = 0;
i < ticks.count();
i++ )
904 const double v = ticks[
i];
907 const double h =
labelSize( font, ticks[
i] ).height();
913 return qCeil( maxHeight );
static void drawLine(QPainter *, double x1, double y1, double x2, double y2)
Wrapper for QPainter::drawLine()
virtual void drawTick(QPainter *, double val, double len) const
void setAlignment(Alignment)
void setLength(double length)
virtual double extent(const QFont &) const
QPointF labelPosition(double val) const
void draw(QPainter *painter, const QRectF &rect) const
A class representing a scale division.
const QwtScaleMap & scaleMap() const
void getBorderDistHint(const QFont &, int &start, int &end) const
Determine the minimum border distance.
TFSIMD_FORCE_INLINE const tfScalar & y() const
QwtScaleDraw()
Constructor.
double minimumExtent() const
int minLength(const QFont &) const
int minLabelDist(const QFont &) const
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
virtual ~QwtScaleDraw()
Destructor.
int maxLabelWidth(const QFont &) const
QTransform labelTransformation(const QPointF &, const QSizeF &) const
QSizeF textSize(const QFont &=QFont()) const
QSizeF labelSize(const QFont &, double val) const
bool contains(double value) const
Alignment alignment() const
double qwtRadians(double degrees)
Translate degrees into radians.
const QwtScaleDiv & scaleDiv() const
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
A class representing a text.
double maxTickLength() const
TFSIMD_FORCE_INLINE const tfScalar & x() const
void setLabelRotation(double rotation)
Backbone = the line where the ticks are located.
Qt::Orientation orientation() const
virtual void drawBackbone(QPainter *) const
Qt::Alignment labelAlignment() const
virtual void drawLabel(QPainter *, double val) const
const QwtText & tickLabel(const QFont &, double value) const
Convert a value into its representing label and cache it.
TFSIMD_FORCE_INLINE const tfScalar & w() const
QRectF labelRect(const QFont &, double val) const
int maxLabelHeight(const QFont &) const
bool hasComponent(ScaleComponent) const
A class for drawing scales.
double transform(double s) const
QRect boundingLabelRect(const QFont &, double val) const
Find the bounding rectangle for the label.
Qt::Alignment labelAlignment
QList< double > ticks(int tickType) const
double tickLength(QwtScaleDiv::TickType) const
double labelRotation() const
void setLabelAlignment(Qt::Alignment)
Change the label flags.
double spacing() const
Get the spacing.
static bool roundingAlignment()
void move(double x, double y)