The Wheel Widget. More...
#include <qwt_wheel.h>


Classes | |
| class | PrivateData |
Public Member Functions | |
| QwtWheel (QWidget *parent=NULL) | |
| Constructor. | |
| QwtWheel (QWidget *parent, const char *name) | |
| virtual | ~QwtWheel () |
| Destructor. | |
| virtual void | setOrientation (Qt::Orientation) |
| Set the wheel's orientation. | |
| double | totalAngle () const |
| double | viewAngle () const |
| int | tickCnt () const |
| int | internalBorder () const |
| double | mass () const |
| void | setTotalAngle (double angle) |
| Set the total angle which the wheel can be turned. | |
| void | setTickCnt (int cnt) |
| Adjust the number of grooves in the wheel's surface. | |
| void | setViewAngle (double angle) |
| Specify the visible portion of the wheel. | |
| void | setInternalBorder (int width) |
| Set the internal border width of the wheel. | |
| void | setMass (double val) |
| Set the mass of the wheel. | |
| void | setWheelWidth (int w) |
| Set the width of the wheel. | |
| virtual QSize | sizeHint () const |
| virtual QSize | minimumSizeHint () const |
| Return a minimum size hint. | |
Protected Member Functions | |
| virtual void | resizeEvent (QResizeEvent *e) |
| Qt Resize Event. | |
| virtual void | paintEvent (QPaintEvent *e) |
| Qt Paint Event. | |
| void | layoutWheel (bool update=true) |
| Recalculate the slider's geometry and layout based on. | |
| void | draw (QPainter *p, const QRect &update_rect) |
| void | drawWheel (QPainter *p, const QRect &r) |
| Redraw the wheel. | |
| void | drawWheelBackground (QPainter *p, const QRect &r) |
| void | setColorArray () |
| Set up the color array for the background pixmap. | |
| virtual void | valueChange () |
| Notify value change. | |
| virtual void | paletteChange (const QPalette &) |
| Call update() when the palette changes. | |
| virtual double | getValue (const QPoint &p) |
| Determine the value corresponding to a specified point. | |
| virtual void | getScrollMode (const QPoint &p, int &scrollMode, int &direction) |
| Determine the scrolling mode and direction corresponding to a specified point. | |
Properties | |
| double | totalAngle |
| double | viewAngle |
| int | tickCnt |
| int | internalBorder |
| double | mass |
The Wheel Widget.
The wheel widget can be used to change values over a very large range in very small steps. Using the setMass member, it can be configured as a flywheel.
Definition at line 25 of file qwt_wheel.h.
| QwtWheel::QwtWheel | ( | QWidget * | parent = NULL ) |
[explicit] |
Constructor.
Definition at line 51 of file qwt_wheel.cpp.
:
QwtAbstractSlider(Qt::Horizontal, parent)
{
initWheel();
}
| QwtWheel::QwtWheel | ( | QWidget * | parent, |
| const char * | name | ||
| ) | [explicit] |
Definition at line 58 of file qwt_wheel.cpp.
:
QwtAbstractSlider(Qt::Horizontal, parent)
{
setName(name);
initWheel();
}
| QwtWheel::~QwtWheel | ( | ) | [virtual] |
Destructor.
Definition at line 86 of file qwt_wheel.cpp.
References QwtWheel::PrivateData::allocContext.
{
#if QT_VERSION < 0x040000
if ( d_data->allocContext )
QColor::destroyAllocContext( d_data->allocContext );
#endif
delete d_data;
}
| void QwtWheel::draw | ( | QPainter * | painter, |
| const QRect & | update_rect | ||
| ) | [protected] |
Redraw panel and wheel
| painter | Painter |
Definition at line 600 of file qwt_wheel.cpp.
References QwtWheel::PrivateData::borderWidth, QwtPainter::drawFocusRect(), drawWheel(), and QwtWheel::PrivateData::sliderRect.
Referenced by paintEvent().
{
qDrawShadePanel( painter, rect().x(), rect().y(),
rect().width(), rect().height(),
#if QT_VERSION < 0x040000
colorGroup(),
#else
palette(),
#endif
true, d_data->borderWidth );
drawWheel( painter, d_data->sliderRect );
if ( hasFocus() )
QwtPainter::drawFocusRect(painter, this);
}
| void QwtWheel::drawWheel | ( | QPainter * | painter, |
| const QRect & | r | ||
| ) | [protected] |
Redraw the wheel.
| painter | painter |
| r | contents rectangle |
Definition at line 408 of file qwt_wheel.cpp.
References drawWheelBackground(), int(), QwtWheel::PrivateData::intBorder, M_PI, QwtDoubleRange::maxValue(), QwtDoubleRange::minValue(), QwtAbstractSlider::orientation(), qwtAbs, sign(), QwtWheel::PrivateData::tickCnt, QwtWheel::PrivateData::totalAngle, QwtDoubleRange::value(), and QwtWheel::PrivateData::viewAngle.
Referenced by draw().
{
//
// draw background gradient
//
drawWheelBackground( painter, r );
if ( maxValue() == minValue() || d_data->totalAngle == 0.0 )
return;
#if QT_VERSION < 0x040000
const QColor light = colorGroup().light();
const QColor dark = colorGroup().dark();
#else
const QColor light = palette().color(QPalette::Light);
const QColor dark = palette().color(QPalette::Dark);
#endif
const double sign = (minValue() < maxValue()) ? 1.0 : -1.0;
double cnvFactor = qwtAbs(d_data->totalAngle / (maxValue() - minValue()));
const double halfIntv = 0.5 * d_data->viewAngle / cnvFactor;
const double loValue = value() - halfIntv;
const double hiValue = value() + halfIntv;
const double tickWidth = 360.0 / double(d_data->tickCnt) / cnvFactor;
const double sinArc = sin(d_data->viewAngle * M_PI / 360.0);
cnvFactor *= M_PI / 180.0;
//
// draw grooves
//
if ( orientation() == Qt::Horizontal )
{
const double halfSize = double(r.width()) * 0.5;
int l1 = r.y() + d_data->intBorder;
int l2 = r.y() + r.height() - d_data->intBorder - 1;
// draw one point over the border if border > 1
if ( d_data->intBorder > 1 )
{
l1 --;
l2 ++;
}
const int maxpos = r.x() + r.width() - 2;
const int minpos = r.x() + 2;
//
// draw tick marks
//
for ( double tickValue = ceil(loValue / tickWidth) * tickWidth;
tickValue < hiValue; tickValue += tickWidth )
{
//
// calculate position
//
const int tickPos = r.x() + r.width()
- int( halfSize
* (sinArc + sign * sin((tickValue - value()) * cnvFactor))
/ sinArc);
//
// draw vertical line
//
if ( (tickPos <= maxpos) && (tickPos > minpos) )
{
painter->setPen(dark);
painter->drawLine(tickPos -1 , l1, tickPos - 1, l2 );
painter->setPen(light);
painter->drawLine(tickPos, l1, tickPos, l2);
}
}
}
else if ( orientation() == Qt::Vertical )
{
const double halfSize = double(r.height()) * 0.5;
int l1 = r.x() + d_data->intBorder;
int l2 = r.x() + r.width() - d_data->intBorder - 1;
if ( d_data->intBorder > 1 )
{
l1--;
l2++;
}
const int maxpos = r.y() + r.height() - 2;
const int minpos = r.y() + 2;
//
// draw tick marks
//
for ( double tickValue = ceil(loValue / tickWidth) * tickWidth;
tickValue < hiValue; tickValue += tickWidth )
{
//
// calculate position
//
const int tickPos = r.y() + int( halfSize *
(sinArc + sign * sin((tickValue - value()) * cnvFactor))
/ sinArc);
//
// draw horizontal line
//
if ( (tickPos <= maxpos) && (tickPos > minpos) )
{
painter->setPen(dark);
painter->drawLine(l1, tickPos - 1 ,l2, tickPos - 1);
painter->setPen(light);
painter->drawLine(l1, tickPos, l2, tickPos);
}
}
}
}
| void QwtWheel::drawWheelBackground | ( | QPainter * | painter, |
| const QRect & | r | ||
| ) | [protected] |
Draw the Wheel's background gradient
| painter | Painter |
| r | Bounding rectangle |
Definition at line 214 of file qwt_wheel.cpp.
References QwtWheel::PrivateData::colors, QwtWheel::PrivateData::intBorder, NUM_COLORS, QwtAbstractSlider::orientation(), qwtAbs, and setColorArray().
Referenced by drawWheel().
{
painter->save();
//
// initialize pens
//
#if QT_VERSION < 0x040000
const QColor light = colorGroup().light();
const QColor dark = colorGroup().dark();
#else
const QColor light = palette().color(QPalette::Light);
const QColor dark = palette().color(QPalette::Dark);
#endif
QPen lightPen;
lightPen.setColor(light);
lightPen.setWidth(d_data->intBorder);
QPen darkPen;
darkPen.setColor(dark);
darkPen.setWidth(d_data->intBorder);
setColorArray();
//
// initialize auxiliary variables
//
const int nFields = NUM_COLORS * 13 / 10;
const int hiPos = nFields - NUM_COLORS + 1;
if ( orientation() == Qt::Horizontal )
{
const int rx = r.x();
int ry = r.y() + d_data->intBorder;
const int rh = r.height() - 2* d_data->intBorder;
const int rw = r.width();
//
// draw shaded background
//
int x1 = rx;
for (int i = 1; i < nFields; i++ )
{
const int x2 = rx + (rw * i) / nFields;
painter->fillRect(x1, ry, x2-x1 + 1 ,rh,
d_data->colors[qwtAbs(i-hiPos)]);
x1 = x2 + 1;
}
painter->fillRect(x1, ry, rw - (x1 - rx), rh,
d_data->colors[NUM_COLORS - 1]);
//
// draw internal border
//
painter->setPen(lightPen);
ry = r.y() + d_data->intBorder / 2;
painter->drawLine(r.x(), ry, r.x() + r.width() , ry);
painter->setPen(darkPen);
ry = r.y() + r.height() - (d_data->intBorder - d_data->intBorder / 2);
painter->drawLine(r.x(), ry , r.x() + r.width(), ry);
}
else // Qt::Vertical
{
int rx = r.x() + d_data->intBorder;
const int ry = r.y();
const int rh = r.height();
const int rw = r.width() - 2 * d_data->intBorder;
//
// draw shaded background
//
int y1 = ry;
for ( int i = 1; i < nFields; i++ )
{
const int y2 = ry + (rh * i) / nFields;
painter->fillRect(rx, y1, rw, y2-y1 + 1,
d_data->colors[qwtAbs(i-hiPos)]);
y1 = y2 + 1;
}
painter->fillRect(rx, y1, rw, rh - (y1 - ry),
d_data->colors[NUM_COLORS - 1]);
//
// draw internal borders
//
painter->setPen(lightPen);
rx = r.x() + d_data->intBorder / 2;
painter->drawLine(rx, r.y(), rx, r.y() + r.height());
painter->setPen(darkPen);
rx = r.x() + r.width() - (d_data->intBorder - d_data->intBorder / 2);
painter->drawLine(rx, r.y(), rx , r.y() + r.height());
}
painter->restore();
}
| void QwtWheel::getScrollMode | ( | const QPoint & | p, |
| int & | scrollMode, | ||
| int & | direction | ||
| ) | [protected, virtual] |
Determine the scrolling mode and direction corresponding to a specified point.
| p | point |
| scrollMode | scrolling mode |
| direction | direction |
Implements QwtAbstractSlider.
Definition at line 632 of file qwt_wheel.cpp.
References QwtAbstractSlider::ScrMouse, QwtAbstractSlider::ScrNone, and QwtWheel::PrivateData::sliderRect.
{
if ( d_data->sliderRect.contains(p) )
scrollMode = ScrMouse;
else
scrollMode = ScrNone;
direction = 0;
}
| double QwtWheel::getValue | ( | const QPoint & | p ) | [protected, virtual] |
Determine the value corresponding to a specified point.
Implements QwtAbstractSlider.
Definition at line 527 of file qwt_wheel.cpp.
References QwtDoubleRange::maxValue(), QwtDoubleRange::minValue(), QwtAbstractSlider::orientation(), QwtWheel::PrivateData::sliderRect, QwtWheel::PrivateData::totalAngle, and QwtWheel::PrivateData::viewAngle.
{
// The reference position is arbitrary, but the
// sign of the offset is important
int w, dx;
if ( orientation() == Qt::Vertical )
{
w = d_data->sliderRect.height();
dx = d_data->sliderRect.y() - p.y();
}
else
{
w = d_data->sliderRect.width();
dx = p.x() - d_data->sliderRect.x();
}
// w pixels is an arc of viewAngle degrees,
// so we convert change in pixels to change in angle
const double ang = dx * d_data->viewAngle / w;
// value range maps to totalAngle degrees,
// so convert the change in angle to a change in value
const double val = ang * ( maxValue() - minValue() ) / d_data->totalAngle;
// Note, range clamping and rasterizing to step is automatically
// handled by QwtAbstractSlider, so we simply return the change in value
return val;
}
| int QwtWheel::internalBorder | ( | ) | const |
| void QwtWheel::layoutWheel | ( | bool | update = true ) |
[protected] |
Recalculate the slider's geometry and layout based on.
Definition at line 566 of file qwt_wheel.cpp.
References QwtWheel::PrivateData::borderWidth, and QwtWheel::PrivateData::sliderRect.
Referenced by resizeEvent(), setInternalBorder(), setOrientation(), and setWheelWidth().
{
const QRect r = this->rect();
d_data->sliderRect.setRect(r.x() + d_data->borderWidth, r.y() + d_data->borderWidth,
r.width() - 2*d_data->borderWidth, r.height() - 2*d_data->borderWidth);
if ( update_geometry )
{
updateGeometry();
update();
}
}
| double QwtWheel::mass | ( | ) | const [virtual] |
Reimplemented from QwtAbstractSlider.
| QSize QwtWheel::minimumSizeHint | ( | ) | const [virtual] |
Return a minimum size hint.
Definition at line 678 of file qwt_wheel.cpp.
References QwtWheel::PrivateData::borderWidth, QwtAbstractSlider::orientation(), and QwtWheel::PrivateData::wheelWidth.
Referenced by sizeHint().
{
QSize sz( 3*d_data->wheelWidth + 2*d_data->borderWidth,
d_data->wheelWidth + 2*d_data->borderWidth );
if ( orientation() != Qt::Horizontal )
sz.transpose();
return sz;
}
| void QwtWheel::paintEvent | ( | QPaintEvent * | e ) | [protected, virtual] |
Qt Paint Event.
Definition at line 580 of file qwt_wheel.cpp.
References draw(), and QwtPaintBuffer::painter().
{
// Use double-buffering
const QRect &ur = e->rect();
if ( ur.isValid() )
{
#if QT_VERSION < 0x040000
QwtPaintBuffer paintBuffer(this, ur);
draw(paintBuffer.painter(), ur);
#else
QPainter painter(this);
draw(&painter, ur);
#endif
}
}
| void QwtWheel::paletteChange | ( | const QPalette & | ) | [protected, virtual] |
| void QwtWheel::resizeEvent | ( | QResizeEvent * | e ) | [protected, virtual] |
Qt Resize Event.
Definition at line 557 of file qwt_wheel.cpp.
References layoutWheel().
{
layoutWheel( false );
}
| void QwtWheel::setColorArray | ( | ) | [protected] |
Set up the color array for the background pixmap.
Definition at line 96 of file qwt_wheel.cpp.
References QwtWheel::PrivateData::allocContext, QwtWheel::PrivateData::colors, and NUM_COLORS.
Referenced by drawWheelBackground().
{
if ( !d_data->colors )
return;
#if QT_VERSION < 0x040000
const QColor light = colorGroup().light();
const QColor dark = colorGroup().dark();
#else
const QColor light = palette().color(QPalette::Light);
const QColor dark = palette().color(QPalette::Dark);
#endif
if ( !d_data->colors[0].isValid() ||
d_data->colors[0] != light ||
d_data->colors[NUM_COLORS - 1] != dark )
{
#if QT_VERSION < 0x040000
if ( d_data->allocContext )
QColor::destroyAllocContext( d_data->allocContext );
d_data->allocContext = QColor::enterAllocContext();
#endif
d_data->colors[0] = light;
d_data->colors[NUM_COLORS - 1] = dark;
int dh, ds, dv, lh, ls, lv;
#if QT_VERSION < 0x040000
d_data->colors[0].rgb(&lh, &ls, &lv);
d_data->colors[NUM_COLORS - 1].rgb(&dh, &ds, &dv);
#else
d_data->colors[0].getRgb(&lh, &ls, &lv);
d_data->colors[NUM_COLORS - 1].getRgb(&dh, &ds, &dv);
#endif
for ( int i = 1; i < NUM_COLORS - 1; ++i )
{
const double factor = double(i) / double(NUM_COLORS);
d_data->colors[i].setRgb( lh + int( double(dh - lh) * factor ),
ls + int( double(ds - ls) * factor ),
lv + int( double(dv - lv) * factor ));
}
#if QT_VERSION < 0x040000
QColor::leaveAllocContext();
#endif
}
}
| void QwtWheel::setInternalBorder | ( | int | w ) |
Set the internal border width of the wheel.
The internal border must not be smaller than 1 and is limited in dependence on the wheel's size. Values outside the allowed range will be clipped.
The internal border defaults to 2.
| w | border width |
Definition at line 191 of file qwt_wheel.cpp.
References QwtWheel::PrivateData::intBorder, layoutWheel(), qwtMax, and qwtMin.
| void QwtWheel::setMass | ( | double | val ) | [virtual] |
Set the mass of the wheel.
Assigning a mass turns the wheel into a flywheel.
| val | the wheel's mass |
Reimplemented from QwtAbstractSlider.
Definition at line 648 of file qwt_wheel.cpp.
{
QwtAbstractSlider::setMass(val);
}
| void QwtWheel::setOrientation | ( | Qt::Orientation | o ) | [virtual] |
Set the wheel's orientation.
| o | Orientation. Allowed values are Qt::Horizontal and Qt::Vertical. Defaults to Qt::Horizontal. |
Definition at line 352 of file qwt_wheel.cpp.
References layoutWheel(), and QwtAbstractSlider::orientation().
{
if ( orientation() == o )
return;
#if QT_VERSION >= 0x040000
if ( !testAttribute(Qt::WA_WState_OwnSizePolicy) )
#else
if ( !testWState( WState_OwnSizePolicy ) )
#endif
{
QSizePolicy sp = sizePolicy();
sp.transpose();
setSizePolicy(sp);
#if QT_VERSION >= 0x040000
setAttribute(Qt::WA_WState_OwnSizePolicy, false);
#else
clearWState( WState_OwnSizePolicy );
#endif
}
QwtAbstractSlider::setOrientation(o);
layoutWheel();
}
| void QwtWheel::setTickCnt | ( | int | cnt ) |
Adjust the number of grooves in the wheel's surface.
The number of grooves is limited to 6 <= cnt <= 50. Values outside this range will be clipped. The default value is 10.
| cnt | Number of grooves per 360 degrees |
Definition at line 156 of file qwt_wheel.cpp.
References qwtLim(), and QwtWheel::PrivateData::tickCnt.
| void QwtWheel::setTotalAngle | ( | double | angle ) |
Set the total angle which the wheel can be turned.
One full turn of the wheel corresponds to an angle of 360 degrees. A total angle of n*360 degrees means that the wheel has to be turned n times around its axis to get from the minimum value to the maximum value.
The default setting of the total angle is 360 degrees.
| angle | total angle in degrees |
Definition at line 327 of file qwt_wheel.cpp.
References QwtWheel::PrivateData::totalAngle.
{
if ( angle < 0.0 )
angle = 0.0;
d_data->totalAngle = angle;
update();
}
| void QwtWheel::setViewAngle | ( | double | angle ) |
Specify the visible portion of the wheel.
You may use this function for fine-tuning the appearance of the wheel. The default value is 175 degrees. The value is limited from 10 to 175 degrees.
| angle | Visible angle in degrees |
Definition at line 388 of file qwt_wheel.cpp.
References qwtLim(), and QwtWheel::PrivateData::viewAngle.
| void QwtWheel::setWheelWidth | ( | int | w ) |
Set the width of the wheel.
Corresponds to the wheel height for horizontal orientation, and the wheel width for vertical orientation.
| w | the wheel's width |
Definition at line 660 of file qwt_wheel.cpp.
References layoutWheel(), and QwtWheel::PrivateData::wheelWidth.
{
d_data->wheelWidth = w;
layoutWheel();
}
| QSize QwtWheel::sizeHint | ( | ) | const [virtual] |
Definition at line 669 of file qwt_wheel.cpp.
References minimumSizeHint().
{
return minimumSizeHint();
}
| int QwtWheel::tickCnt | ( | ) | const |
| double QwtWheel::totalAngle | ( | ) | const |
| void QwtWheel::valueChange | ( | ) | [protected, virtual] |
Notify value change.
Reimplemented from QwtAbstractSlider.
Definition at line 618 of file qwt_wheel.cpp.
{
QwtAbstractSlider::valueChange();
update();
}
| double QwtWheel::viewAngle | ( | ) | const |
int QwtWheel::internalBorder [read, write] |
Definition at line 31 of file qwt_wheel.h.
double QwtWheel::mass [read, write] |
int QwtWheel::tickCnt [read, write] |
Definition at line 30 of file qwt_wheel.h.
double QwtWheel::totalAngle [read, write] |
Definition at line 28 of file qwt_wheel.h.
double QwtWheel::viewAngle [read, write] |
Definition at line 29 of file qwt_wheel.h.
1.7.2