A class for drawing scales. More...
#include <qwt_scale_draw.h>


Classes | |
| class | PrivateData |
Public Types | |
| enum | Alignment { BottomScale, TopScale, LeftScale, RightScale } |
Public Member Functions | |
| QwtScaleDraw () | |
| Constructor. | |
| QwtScaleDraw (const QwtScaleDraw &) | |
| Copy constructor. | |
| virtual | ~QwtScaleDraw () |
| Destructor. | |
| QwtScaleDraw & | operator= (const QwtScaleDraw &other) |
| Assignment operator. | |
| void | getBorderDistHint (const QFont &, int &start, int &end) const |
| Determine the minimum border distance. | |
| int | minLabelDist (const QFont &) const |
| int | minLength (const QPen &, const QFont &) const |
| virtual int | extent (const QPen &, const QFont &) const |
| void | move (int x, int y) |
| void | move (const QPoint &) |
| Move the position of the scale. | |
| void | setLength (int length) |
| Alignment | alignment () const |
| void | setAlignment (Alignment) |
| Qt::Orientation | orientation () const |
| QPoint | pos () const |
| int | length () const |
| void | setLabelAlignment (int) |
| Change the label flags. | |
| int | labelAlignment () const |
| void | setLabelRotation (double rotation) |
| double | labelRotation () const |
| int | maxLabelHeight (const QFont &) const |
| int | maxLabelWidth (const QFont &) const |
| QPoint | labelPosition (double val) const |
| QRect | labelRect (const QFont &, double val) const |
| QSize | labelSize (const QFont &, double val) const |
| QRect | boundingLabelRect (const QFont &, double val) const |
Protected Member Functions | |
| QWMatrix | labelMatrix (const QPoint &, const QSize &) const |
| virtual void | drawTick (QPainter *p, double val, int len) const |
| virtual void | drawBackbone (QPainter *p) const |
| virtual void | drawLabel (QPainter *p, double val) const |
A class for drawing scales.
QwtScaleDraw can be used to draw linear or logarithmic scales. A scale has a position, an alignment and a length, which can be specified . The labels can be rotated and aligned to the ticks using setLabelRotation() and setLabelAlignment().
After a scale division has been specified as a QwtScaleDiv object using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s), the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
Definition at line 30 of file qwt_scale_draw.h.
Alignment of the scale draw
Definition at line 37 of file qwt_scale_draw.h.
{ BottomScale, TopScale, LeftScale, RightScale };
| QwtScaleDraw::QwtScaleDraw | ( | ) |
Constructor.
The range of the scale is initialized to [0, 100], The position is at (0, 0) with a length of 100. The orientation is QwtAbstractScaleDraw::Bottom.
Definition at line 60 of file qwt_scale_draw.cpp.
References setLength().
{
d_data = new QwtScaleDraw::PrivateData;
setLength(100);
}
| QwtScaleDraw::QwtScaleDraw | ( | const QwtScaleDraw & | other ) |
Copy constructor.
Definition at line 67 of file qwt_scale_draw.cpp.
:
QwtAbstractScaleDraw(other)
{
d_data = new QwtScaleDraw::PrivateData(*other.d_data);
}
| QwtScaleDraw::~QwtScaleDraw | ( | ) | [virtual] |
| QwtScaleDraw::Alignment QwtScaleDraw::alignment | ( | ) | const |
Return alignment of the scale
Definition at line 91 of file qwt_scale_draw.cpp.
References QwtScaleDraw::PrivateData::alignment.
Referenced by QwtScaleWidget::alignment(), QwtScaleWidget::colorBarRect(), QwtScaleWidget::draw(), QwtPlotScaleItem::draw(), drawBackbone(), drawTick(), labelMatrix(), labelPosition(), QwtScaleWidget::layoutScale(), QwtPlotScaleItem::setAlignment(), QwtSlider::setScaleDraw(), and QwtScaleWidget::setScaleDraw().
{
return d_data->alignment;
}
| QRect QwtScaleDraw::boundingLabelRect | ( | const QFont & | font, |
| double | value | ||
| ) | const |
Find the bounding rect for the label. The coordinates of the rect are absolute coordinates ( calculated from pos() ). in direction of the tick.
| font | Font used for painting |
| value | Value |
Definition at line 661 of file qwt_scale_draw.cpp.
References QwtText::isEmpty(), labelMatrix(), labelPosition(), labelSize(), pos(), QwtMatrix, QwtText::textSize(), and QwtAbstractScaleDraw::tickLabel().
{
QwtText lbl = tickLabel(font, value);
if ( lbl.isEmpty() )
return QRect();
const QPoint pos = labelPosition(value);
QSize labelSize = lbl.textSize(font);
if ( labelSize.height() % 2 )
labelSize.setHeight(labelSize.height() + 1);
const QwtMatrix m = labelMatrix( pos, labelSize);
return m.mapRect(QRect(QPoint(0, 0), labelSize));
}
| void QwtScaleDraw::drawBackbone | ( | QPainter * | painter ) | const [protected, virtual] |
Draws the baseline of the scale
| painter | Painter |
Implements QwtAbstractScaleDraw.
Definition at line 507 of file qwt_scale_draw.cpp.
References alignment(), BottomScale, QwtPainter::drawLine(), LeftScale, QwtScaleDraw::PrivateData::len, QwtScaleDraw::PrivateData::pos, pos(), RightScale, and TopScale.
{
const int bw2 = painter->pen().width() / 2;
const QPoint &pos = d_data->pos;
const int len = d_data->len - 1;
switch(alignment())
{
case LeftScale:
QwtPainter::drawLine(painter, pos.x() - bw2,
pos.y(), pos.x() - bw2, pos.y() + len );
break;
case RightScale:
QwtPainter::drawLine(painter, pos.x() + bw2,
pos.y(), pos.x() + bw2, pos.y() + len);
break;
case TopScale:
QwtPainter::drawLine(painter, pos.x(), pos.y() - bw2,
pos.x() + len, pos.y() - bw2);
break;
case BottomScale:
QwtPainter::drawLine(painter, pos.x(), pos.y() + bw2,
pos.x() + len, pos.y() + bw2);
break;
}
}
| void QwtScaleDraw::drawLabel | ( | QPainter * | painter, |
| double | value | ||
| ) | const [protected, virtual] |
Draws the label for a major scale tick
| painter | Painter |
| value | Value |
Implements QwtAbstractScaleDraw.
Definition at line 617 of file qwt_scale_draw.cpp.
References QwtText::draw(), QwtText::isEmpty(), labelMatrix(), labelPosition(), labelSize(), QwtMetricsMap::layoutToDevice(), QwtPainter::metricsMap(), pos(), QwtMatrix, QwtPainter::resetMetricsMap(), QwtPainter::setMetricsMap(), QwtText::textSize(), and QwtAbstractScaleDraw::tickLabel().
{
QwtText lbl = tickLabel(painter->font(), value);
if ( lbl.isEmpty() )
return;
QPoint pos = labelPosition(value);
QSize labelSize = lbl.textSize(painter->font());
if ( labelSize.height() % 2 )
labelSize.setHeight(labelSize.height() + 1);
const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
QwtPainter::resetMetricsMap();
labelSize = metricsMap.layoutToDevice(labelSize);
pos = metricsMap.layoutToDevice(pos);
const QwtMatrix m = labelMatrix( pos, labelSize);
painter->save();
#if QT_VERSION < 0x040000
painter->setWorldMatrix(m, true);
#else
painter->setMatrix(m, true);
#endif
lbl.draw (painter, QRect(QPoint(0, 0), labelSize) );
QwtPainter::setMetricsMap(metricsMap); // restore metrics map
painter->restore();
}
| void QwtScaleDraw::drawTick | ( | QPainter * | painter, |
| double | value, | ||
| int | len | ||
| ) | const [protected, virtual] |
Draw a tick
| painter | Painter |
| value | Value of the tick |
| len | Lenght of the tick |
Implements QwtAbstractScaleDraw.
Definition at line 406 of file qwt_scale_draw.cpp.
References alignment(), BottomScale, QwtPainter::drawLine(), QwtMetricsMap::isIdentity(), QwtMetricsMap::layoutToDevice(), QwtMetricsMap::layoutToDeviceX(), QwtMetricsMap::layoutToDeviceY(), LeftScale, QwtAbstractScaleDraw::map(), QwtPainter::metricsMap(), orientation(), QwtScaleDraw::PrivateData::pos, pos(), qwtMin, QwtPainter::resetMetricsMap(), RightScale, QwtAbstractScaleDraw::scaleMap(), QwtPainter::setMetricsMap(), and TopScale.
{
if ( len <= 0 )
return;
int pw2 = qwtMin((int)painter->pen().width(), len) / 2;
QwtScaleMap scaleMap = map();
const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
QPoint pos = d_data->pos;
if ( !metricsMap.isIdentity() )
{
/*
The perfect position of the ticks is important.
To avoid rounding errors we have to use
device coordinates.
*/
QwtPainter::resetMetricsMap();
pos = metricsMap.layoutToDevice(pos);
if ( orientation() == Qt::Vertical )
{
scaleMap.setPaintInterval(
metricsMap.layoutToDeviceY((int)scaleMap.p1()),
metricsMap.layoutToDeviceY((int)scaleMap.p2())
);
len = metricsMap.layoutToDeviceX(len);
}
else
{
scaleMap.setPaintInterval(
metricsMap.layoutToDeviceX((int)scaleMap.p1()),
metricsMap.layoutToDeviceX((int)scaleMap.p2())
);
len = metricsMap.layoutToDeviceY(len);
}
}
const int tval = scaleMap.transform(value);
switch(alignment())
{
case LeftScale:
{
#if QT_VERSION < 0x040000
QwtPainter::drawLine(painter, pos.x() + pw2, tval,
pos.x() - len - 2 * pw2, tval);
#else
QwtPainter::drawLine(painter, pos.x() - pw2, tval,
pos.x() - len, tval);
#endif
break;
}
case RightScale:
{
#if QT_VERSION < 0x040000
QwtPainter::drawLine(painter, pos.x(), tval,
pos.x() + len + pw2, tval);
#else
QwtPainter::drawLine(painter, pos.x() + pw2, tval,
pos.x() + len, tval);
#endif
break;
}
case BottomScale:
{
#if QT_VERSION < 0x040000
QwtPainter::drawLine(painter, tval, pos.y(),
tval, pos.y() + len + 2 * pw2);
#else
QwtPainter::drawLine(painter, tval, pos.y() + pw2,
tval, pos.y() + len);
#endif
break;
}
case TopScale:
{
#if QT_VERSION < 0x040000
QwtPainter::drawLine(painter, tval, pos.y() + pw2,
tval, pos.y() - len - 2 * pw2);
#else
QwtPainter::drawLine(painter, tval, pos.y() - pw2,
tval, pos.y() - len);
#endif
break;
}
}
QwtPainter::setMetricsMap(metricsMap); // restore metrics map
}
| int QwtScaleDraw::extent | ( | const QPen & | pen, |
| const QFont & | font | ||
| ) | const [virtual] |
Calculate the width/height that is needed for a vertical/horizontal scale.
The extent is calculated from the pen width of the backbone, the major tick length, the spacing and the maximum width/height of the labels.
| pen | Pen that is used for painting backbone and ticks |
| font | Font used for painting the labels |
Implements QwtAbstractScaleDraw.
Definition at line 280 of file qwt_scale_draw.cpp.
References QwtAbstractScaleDraw::Backbone, QwtAbstractScaleDraw::hasComponent(), QwtAbstractScaleDraw::Labels, QwtAbstractScaleDraw::majTickLength(), maxLabelHeight(), maxLabelWidth(), QwtAbstractScaleDraw::minimumExtent(), orientation(), qwtMax, QwtAbstractScaleDraw::spacing(), and QwtAbstractScaleDraw::Ticks.
Referenced by QwtScaleWidget::dimForLength(), QwtScaleWidget::layoutScale(), QwtThermo::minimumSizeHint(), and QwtSlider::minimumSizeHint().
{
int d = 0;
if ( hasComponent(QwtAbstractScaleDraw::Labels) )
{
if ( orientation() == Qt::Vertical )
d = maxLabelWidth(font);
else
d = maxLabelHeight(font);
if ( d > 0 )
d += spacing();
}
if ( hasComponent(QwtAbstractScaleDraw::Ticks) )
{
d += majTickLength();
}
if ( hasComponent(QwtAbstractScaleDraw::Backbone) )
{
const int pw = qwtMax( 1, pen.width() ); // penwidth can be zero
d += pw;
}
d = qwtMax(d, minimumExtent());
return d;
}
| void QwtScaleDraw::getBorderDistHint | ( | const QFont & | font, |
| int & | start, | ||
| int & | end | ||
| ) | const |
Determine the minimum border distance.
This member function returns the minimum space needed to draw the mark labels at the scale's endpoints.
| font | Font |
| start | Start border distance |
| end | End border distance |
Definition at line 139 of file qwt_scale_draw.cpp.
References QwtAbstractScaleDraw::hasComponent(), labelRect(), QwtAbstractScaleDraw::Labels, QwtScaleDiv::MajorTick, QwtAbstractScaleDraw::map(), orientation(), qwtAbs, QwtAbstractScaleDraw::scaleDiv(), and QwtScaleDiv::ticks().
Referenced by QwtScaleWidget::getBorderDistHint(), QwtSlider::layoutSlider(), QwtThermo::layoutThermo(), QwtSlider::minimumSizeHint(), and minLength().
{
start = 0;
end = 0;
if ( !hasComponent(QwtAbstractScaleDraw::Labels) )
return;
const QwtValueList &ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
if ( ticks.count() == 0 )
return;
QRect lr = labelRect(font, ticks[0]);
// find the distance between tick and border
int off = qwtAbs(map().transform(ticks[0]) - qRound(map().p1()));
if ( orientation() == Qt::Vertical )
end = lr.bottom() + 1 - off;
else
start = -lr.left() - off;
const int lastTick = ticks.count() - 1;
lr = labelRect(font, ticks[lastTick]);
// find the distance between tick and border
off = qwtAbs(map().transform(ticks[lastTick]) - qRound(map().p2()));
if ( orientation() == Qt::Vertical )
start = -lr.top() - off;
else
end = lr.right() + 1 - off;
// if the distance between tick and border is larger
// than half of the label width/height, we set to 0
if ( start < 0 )
start = 0;
if ( end < 0 )
end = 0;
}
| int QwtScaleDraw::labelAlignment | ( | ) | const |
Definition at line 871 of file qwt_scale_draw.cpp.
Referenced by labelMatrix().
{
return d_data->labelAlignment;
}
| QwtMatrix QwtScaleDraw::labelMatrix | ( | const QPoint & | pos, |
| const QSize & | size | ||
| ) | const [protected] |
Calculate the matrix that is needed to paint a label depending on its alignment and rotation.
| pos | Position where to paint the label |
| size | Size of the label |
Definition at line 685 of file qwt_scale_draw.cpp.
References alignment(), BottomScale, labelAlignment(), labelRotation(), LeftScale, QwtMatrix, RightScale, and TopScale.
Referenced by boundingLabelRect(), drawLabel(), and labelRect().
{
QwtMatrix m;
m.translate(pos.x(), pos.y());
m.rotate(labelRotation());
int flags = labelAlignment();
if ( flags == 0 )
{
switch(alignment())
{
case RightScale:
{
if ( flags == 0 )
flags = Qt::AlignRight | Qt::AlignVCenter;
break;
}
case LeftScale:
{
if ( flags == 0 )
flags = Qt::AlignLeft | Qt::AlignVCenter;
break;
}
case BottomScale:
{
if ( flags == 0 )
flags = Qt::AlignHCenter | Qt::AlignBottom;
break;
}
case TopScale:
{
if ( flags == 0 )
flags = Qt::AlignHCenter | Qt::AlignTop;
break;
}
}
}
const int w = size.width();
const int h = size.height();
int x, y;
if ( flags & Qt::AlignLeft )
x = -w;
else if ( flags & Qt::AlignRight )
x = -(w % 2);
else // Qt::AlignHCenter
x = -(w / 2);
if ( flags & Qt::AlignTop )
y = -h ;
else if ( flags & Qt::AlignBottom )
y = -(h % 2);
else // Qt::AlignVCenter
y = -(h/2);
m.translate(x, y);
return m;
}
| QPoint QwtScaleDraw::labelPosition | ( | double | value ) | const |
Find the position, where to paint a label
The position has a distance of majTickLength() + spacing() + 1 from the backbone. The direction depends on the alignment()
| value | Value |
Definition at line 356 of file qwt_scale_draw.cpp.
References alignment(), BottomScale, QuadProgPP::dist(), QwtAbstractScaleDraw::hasComponent(), LeftScale, QwtAbstractScaleDraw::majTickLength(), QwtAbstractScaleDraw::map(), QwtScaleDraw::PrivateData::pos, RightScale, QwtAbstractScaleDraw::spacing(), QwtAbstractScaleDraw::Ticks, TopScale, and QwtScaleMap::transform().
Referenced by boundingLabelRect(), drawLabel(), and labelRect().
{
const int tval = map().transform(value);
int dist = spacing() + 1;
if ( hasComponent(QwtAbstractScaleDraw::Ticks) )
dist += majTickLength();
int px = 0;
int py = 0;
switch(alignment())
{
case RightScale:
{
px = d_data->pos.x() + dist;
py = tval;
break;
}
case LeftScale:
{
px = d_data->pos.x() - dist;
py = tval;
break;
}
case BottomScale:
{
px = tval;
py = d_data->pos.y() + dist;
break;
}
case TopScale:
{
px = tval;
py = d_data->pos.y() - dist;
break;
}
}
return QPoint(px, py);
}
| QRect QwtScaleDraw::labelRect | ( | const QFont & | font, |
| double | value | ||
| ) | const |
Find the bounding rect for the label. The coordinates of the rect are relative to spacing + ticklength from the backbone in direction of the tick.
| font | Font used for painting |
| value | Value |
Definition at line 756 of file qwt_scale_draw.cpp.
References QwtText::isEmpty(), labelMatrix(), labelPosition(), labelSize(), pos(), QwtMatrix, QwtText::textSize(), QwtAbstractScaleDraw::tickLabel(), and QwtMetricsMap::translate().
Referenced by getBorderDistHint(), labelSize(), and minLabelDist().
{
QwtText lbl = tickLabel(font, value);
if ( lbl.isEmpty() )
return QRect(0, 0, 0, 0);
const QPoint pos = labelPosition(value);
QSize labelSize = lbl.textSize(font);
if ( labelSize.height() % 2 )
{
labelSize.setHeight(labelSize.height() + 1);
}
const QwtMatrix m = labelMatrix(pos, labelSize);
#if 0
QRect br = QwtMetricsMap::translate(m, QRect(QPoint(0, 0), labelSize));
#else
QwtPolygon pol(4);
pol.setPoint(0, 0, 0);
pol.setPoint(1, 0, labelSize.height() - 1 );
pol.setPoint(2, labelSize.width() - 1, 0);
pol.setPoint(3, labelSize.width() - 1, labelSize.height() - 1 );
pol = QwtMetricsMap::translate(m, pol);
QRect br = pol.boundingRect();
#endif
#if QT_VERSION < 0x040000
br.moveBy(-pos.x(), -pos.y());
#else
br.translate(-pos.x(), -pos.y());
#endif
return br;
}
| double QwtScaleDraw::labelRotation | ( | ) | const |
Definition at line 827 of file qwt_scale_draw.cpp.
References QwtScaleDraw::PrivateData::labelRotation.
Referenced by labelMatrix(), and minLabelDist().
{
return d_data->labelRotation;
}
| QSize QwtScaleDraw::labelSize | ( | const QFont & | font, |
| double | value | ||
| ) | const |
Calculate the size that is needed to draw a label
| font | Label font |
| value | Value |
Definition at line 800 of file qwt_scale_draw.cpp.
References labelRect().
Referenced by boundingLabelRect(), drawLabel(), labelRect(), maxLabelHeight(), and maxLabelWidth().
{
return labelRect(font, value).size();
}
| int QwtScaleDraw::length | ( | ) | const |
Definition at line 604 of file qwt_scale_draw.cpp.
References QwtScaleDraw::PrivateData::len.
Referenced by QwtPlot::printScale(), and setLength().
{
return d_data->len;
}
| int QwtScaleDraw::maxLabelHeight | ( | const QFont & | font ) | const |
| font | Font |
Definition at line 906 of file qwt_scale_draw.cpp.
References QwtScaleDiv::contains(), labelSize(), QwtScaleDiv::MajorTick, QwtAbstractScaleDraw::scaleDiv(), and QwtScaleDiv::ticks().
Referenced by extent().
{
int maxHeight = 0;
const QwtValueList &ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
for (uint i = 0; i < (uint)ticks.count(); i++)
{
const double v = ticks[i];
if ( scaleDiv().contains(v) )
{
const int h = labelSize(font, ticks[i]).height();
if ( h > maxHeight )
maxHeight = h;
}
}
return maxHeight;
}
| int QwtScaleDraw::maxLabelWidth | ( | const QFont & | font ) | const |
| font | Font |
Definition at line 883 of file qwt_scale_draw.cpp.
References QwtScaleDiv::contains(), labelSize(), QwtScaleDiv::MajorTick, QwtAbstractScaleDraw::scaleDiv(), and QwtScaleDiv::ticks().
Referenced by extent().
{
int maxWidth = 0;
const QwtValueList &ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
for (uint i = 0; i < (uint)ticks.count(); i++)
{
const double v = ticks[i];
if ( scaleDiv().contains(v) )
{
const int w = labelSize(font, ticks[i]).width();
if ( w > maxWidth )
maxWidth = w;
}
}
return maxWidth;
}
| int QwtScaleDraw::minLabelDist | ( | const QFont & | font ) | const |
Determine the minimum distance between two labels, that is necessary that the texts don't overlap.
| font | Font |
Definition at line 192 of file qwt_scale_draw.cpp.
References QuadProgPP::dist(), QwtAbstractScaleDraw::hasComponent(), int(), labelRect(), labelRotation(), QwtAbstractScaleDraw::Labels, M_PI, QwtScaleDiv::MajorTick, orientation(), QwtAbstractScaleDraw::scaleDiv(), and QwtScaleDiv::ticks().
Referenced by minLength().
{
if ( !hasComponent(QwtAbstractScaleDraw::Labels) )
return 0;
const QwtValueList &ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
if (ticks.count() == 0)
return 0;
const QFontMetrics fm(font);
const bool vertical = (orientation() == Qt::Vertical);
QRect bRect1;
QRect bRect2 = labelRect(font, ticks[0]);
if ( vertical )
{
bRect2.setRect(-bRect2.bottom(), 0, bRect2.height(), bRect2.width());
}
int maxDist = 0;
for (uint i = 1; i < (uint)ticks.count(); i++ )
{
bRect1 = bRect2;
bRect2 = labelRect(font, ticks[i]);
if ( vertical )
{
bRect2.setRect(-bRect2.bottom(), 0,
bRect2.height(), bRect2.width());
}
int dist = fm.leading(); // space between the labels
if ( bRect1.right() > 0 )
dist += bRect1.right();
if ( bRect2.left() < 0 )
dist += -bRect2.left();
if ( dist > maxDist )
maxDist = dist;
}
double angle = labelRotation() / 180.0 * M_PI;
if ( vertical )
angle += M_PI / 2;
if ( sin(angle) == 0.0 )
return maxDist;
const int fmHeight = fm.ascent() - 2;
// The distance we need until there is
// the height of the label font. This height is needed
// for the neighbour labal.
int labelDist = (int)(fmHeight / sin(angle) * cos(angle));
if ( labelDist < 0 )
labelDist = -labelDist;
// The cast above floored labelDist. We want to ceil.
labelDist++;
// For text orientations close to the scale orientation
if ( labelDist > maxDist )
labelDist = maxDist;
// For text orientations close to the opposite of the
// scale orientation
if ( labelDist < fmHeight )
labelDist = fmHeight;
return labelDist;
}
| int QwtScaleDraw::minLength | ( | const QPen & | pen, |
| const QFont & | font | ||
| ) | const |
Calculate the minimum length that is needed to draw the scale
| pen | Pen that is used for painting backbone and ticks |
| font | Font used for painting the labels |
Definition at line 318 of file qwt_scale_draw.cpp.
References getBorderDistHint(), QwtAbstractScaleDraw::hasComponent(), QwtAbstractScaleDraw::Labels, QwtScaleDiv::MajorTick, QwtScaleDiv::MediumTick, minLabelDist(), QwtScaleDiv::MinorTick, qwtMax, QwtAbstractScaleDraw::scaleDiv(), QwtAbstractScaleDraw::Ticks, and QwtScaleDiv::ticks().
Referenced by QwtThermo::minimumSizeHint(), QwtSlider::minimumSizeHint(), and QwtScaleWidget::minimumSizeHint().
{
int startDist, endDist;
getBorderDistHint(font, startDist, endDist);
const QwtScaleDiv &sd = scaleDiv();
const uint minorCount =
sd.ticks(QwtScaleDiv::MinorTick).count() +
sd.ticks(QwtScaleDiv::MediumTick).count();
const uint majorCount =
sd.ticks(QwtScaleDiv::MajorTick).count();
int lengthForLabels = 0;
if ( hasComponent(QwtAbstractScaleDraw::Labels) )
{
if ( majorCount >= 2 )
lengthForLabels = minLabelDist(font) * (majorCount - 1);
}
int lengthForTicks = 0;
if ( hasComponent(QwtAbstractScaleDraw::Ticks) )
{
const int pw = qwtMax( 1, pen.width() ); // penwidth can be zero
lengthForTicks = 2 * (majorCount + minorCount) * pw;
}
return startDist + endDist + qwtMax(lengthForLabels, lengthForTicks);
}
| void QwtScaleDraw::move | ( | int | x, |
| int | y | ||
| ) | [inline] |
Move the position of the scale
Definition at line 108 of file qwt_scale_draw.h.
Referenced by QwtPlotScaleItem::draw(), QwtScaleWidget::layoutScale(), QwtSlider::layoutSlider(), QwtThermo::layoutThermo(), and QwtPlot::printScale().
| void QwtScaleDraw::move | ( | const QPoint & | pos ) |
Move the position of the scale.
The meaning of the parameter pos depends on the alignment:
| pos | Origin of the scale |
Definition at line 566 of file qwt_scale_draw.cpp.
References pos(), and QwtScaleDraw::PrivateData::pos.
| QwtScaleDraw & QwtScaleDraw::operator= | ( | const QwtScaleDraw & | other ) |
Assignment operator.
Definition at line 80 of file qwt_scale_draw.cpp.
{
*(QwtAbstractScaleDraw*)this = (const QwtAbstractScaleDraw &)other;
*d_data = *other.d_data;
return *this;
}
| Qt::Orientation QwtScaleDraw::orientation | ( | ) | const |
Return the orientation
TopScale, BottomScale are horizontal (Qt::Horizontal) scales, LeftScale, RightScale are vertical (Qt::Vertical) scales.
Definition at line 115 of file qwt_scale_draw.cpp.
References QwtScaleDraw::PrivateData::alignment, BottomScale, LeftScale, RightScale, and TopScale.
Referenced by QwtScaleWidget::colorBarRect(), QwtScaleWidget::draw(), QwtPlotScaleItem::draw(), QwtScaleWidget::drawColorBar(), drawTick(), extent(), getBorderDistHint(), QwtScaleWidget::layoutScale(), QwtScaleWidget::minimumSizeHint(), minLabelDist(), QwtPlot::printScale(), QwtScaleWidget::setAlignment(), and QwtPlotScaleItem::updateScaleDiv().
{
switch(d_data->alignment)
{
case TopScale:
case BottomScale:
return Qt::Horizontal;
case LeftScale:
case RightScale:
default:
return Qt::Vertical;
}
}
| QPoint QwtScaleDraw::pos | ( | ) | const |
Definition at line 576 of file qwt_scale_draw.cpp.
References QwtScaleDraw::PrivateData::pos.
Referenced by boundingLabelRect(), drawBackbone(), drawLabel(), drawTick(), labelRect(), move(), and QwtPlot::printScale().
{
return d_data->pos;
}
| void QwtScaleDraw::setAlignment | ( | Alignment | align ) |
Set the alignment of the scale
The default alignment is QwtScaleDraw::BottomScale
Definition at line 102 of file qwt_scale_draw.cpp.
References QwtScaleDraw::PrivateData::alignment.
Referenced by QwtThermo::layoutThermo(), QwtPlotScaleItem::QwtPlotScaleItem(), QwtScaleWidget::setAlignment(), QwtPlotScaleItem::setAlignment(), QwtSlider::setScaleDraw(), QwtScaleWidget::setScaleDraw(), and QwtSlider::setScalePosition().
{
d_data->alignment = align;
}
| void QwtScaleDraw::setLabelAlignment | ( | int | alignment ) |
Change the label flags.
Labels are aligned to the point ticklength + spacing away from the backbone.
The alignment is relative to the orientation of the label text. In case of an flags of 0 the label will be aligned depending on the orientation of the scale:
QwtScaleDraw::TopScale: Qt::AlignHCenter | Qt::AlignTop
QwtScaleDraw::BottomScale: Qt::AlignHCenter | Qt::AlignBottom
QwtScaleDraw::LeftScale: Qt::AlignLeft | Qt::AlignVCenter
QwtScaleDraw::RightScale: Qt::AlignRight | Qt::AlignVCenter
Changing the alignment is often necessary for rotated labels.
| alignment | Or'd Qt::AlignmentFlags <see qnamespace.h> |
Definition at line 858 of file qwt_scale_draw.cpp.
{
d_data->labelAlignment = alignment;
}
| void QwtScaleDraw::setLabelRotation | ( | double | rotation ) |
Rotate all labels.
When changing the rotation, it might be necessary to adjust the label flags too. Finding a useful combination is often the result of try and error.
| rotation | Angle in degrees. When changing the label rotation, the label flags often needs to be adjusted too. |
Definition at line 818 of file qwt_scale_draw.cpp.
References QwtScaleDraw::PrivateData::labelRotation.
Referenced by QwtScaleWidget::setLabelRotation().
{
d_data->labelRotation = rotation;
}
| void QwtScaleDraw::setLength | ( | int | length ) |
Set the length of the backbone.
The length doesn't include the space needed for overlapping labels.
Definition at line 589 of file qwt_scale_draw.cpp.
References QwtScaleDraw::PrivateData::len, and length().
Referenced by QwtPlotScaleItem::draw(), QwtScaleWidget::layoutScale(), QwtSlider::layoutSlider(), QwtThermo::layoutThermo(), QwtPlot::printScale(), and QwtScaleDraw().
1.7.2