The Knob Widget. More...
#include <qwt_knob.h>
Classes | |
class | PrivateData |
Public Types | |
enum | Symbol { Line, Dot } |
Public Member Functions | |
QwtKnob (QWidget *parent=NULL) | |
QwtKnob (QWidget *parent, const char *name) | |
virtual | ~QwtKnob () |
Destructor. | |
void | setKnobWidth (int w) |
Change the knob's width. | |
int | knobWidth () const |
void | setTotalAngle (double angle) |
Set the total angle by which the knob can be turned. | |
double | totalAngle () const |
void | setBorderWidth (int bw) |
Set the knob's border width. | |
int | borderWidth () const |
void | setSymbol (Symbol) |
Set the symbol of the knob. | |
Symbol | symbol () const |
virtual QSize | sizeHint () const |
virtual QSize | minimumSizeHint () const |
Return a minimum size hint. | |
void | setScaleDraw (QwtRoundScaleDraw *) |
const QwtRoundScaleDraw * | scaleDraw () const |
QwtRoundScaleDraw * | scaleDraw () |
Protected Member Functions | |
virtual void | paintEvent (QPaintEvent *e) |
virtual void | resizeEvent (QResizeEvent *e) |
void | draw (QPainter *p, const QRect &ur) |
void | drawKnob (QPainter *p, const QRect &r) |
Draw the knob. | |
void | drawMarker (QPainter *p, double arc, const QColor &c) |
Draw the marker at the knob's front. | |
Properties | |
int | knobWidth |
Return the width of the knob. | |
int | borderWidth |
Return the border width. | |
double | totalAngle |
Return the total angle. | |
Symbol | symbol |
The Knob Widget.
The QwtKnob widget imitates look and behaviour of a volume knob on a radio. It contains a scale around the knob which is set up automatically or can be configured manually (see QwtAbstractScale). Automatic scrolling is enabled when the user presses a mouse button on the scale. For a description of signals, slots and other members, see QwtAbstractSlider.
Definition at line 34 of file qwt_knob.h.
enum QwtKnob::Symbol |
QwtKnob::QwtKnob | ( | QWidget * | parent = NULL ) |
[explicit] |
Constructor
parent | Parent widget |
Definition at line 56 of file qwt_knob.cpp.
: QwtAbstractSlider(Qt::Horizontal, parent) { initKnob(); }
QwtKnob::QwtKnob | ( | QWidget * | parent, |
const char * | name | ||
) | [explicit] |
Constructor
parent | Parent widget |
name | Object name |
Definition at line 68 of file qwt_knob.cpp.
: QwtAbstractSlider(Qt::Horizontal, parent) { setName(name); initKnob(); }
QwtKnob::~QwtKnob | ( | ) | [virtual] |
int QwtKnob::borderWidth | ( | ) | const |
void QwtKnob::draw | ( | QPainter * | painter, |
const QRect & | rect | ||
) | [protected] |
Repaint the knob
painter | Painter |
rect | Update rectangle |
Definition at line 387 of file qwt_knob.cpp.
References QwtAbstractScaleDraw::draw(), QwtPainter::drawFocusRect(), drawKnob(), QwtKnob::PrivateData::knobRect, and scaleDraw().
Referenced by paintEvent().
{ if ( !d_data->knobRect.contains( rect ) ) // event from valueChange() { #if QT_VERSION < 0x040000 scaleDraw()->draw( painter, colorGroup() ); #else scaleDraw()->draw( painter, palette() ); #endif } drawKnob( painter, d_data->knobRect ); if ( hasFocus() ) QwtPainter::drawFocusRect(painter, this); }
void QwtKnob::drawKnob | ( | QPainter * | painter, |
const QRect & | r | ||
) | [protected] |
Draw the knob.
painter | painter |
r | Bounding rectangle of the knob (without scale) |
Definition at line 187 of file qwt_knob.cpp.
References QwtKnob::PrivateData::angle, QwtKnob::PrivateData::borderWidth, drawMarker(), QwtAbstractSlider::isValid(), and qwtMin.
Referenced by draw().
{ #if QT_VERSION < 0x040000 const QBrush buttonBrush = colorGroup().brush(QColorGroup::Button); const QColor buttonTextColor = colorGroup().buttonText(); const QColor lightColor = colorGroup().light(); const QColor darkColor = colorGroup().dark(); #else const QBrush buttonBrush = palette().brush(QPalette::Button); const QColor buttonTextColor = palette().color(QPalette::ButtonText); const QColor lightColor = palette().color(QPalette::Light); const QColor darkColor = palette().color(QPalette::Dark); #endif const int bw2 = d_data->borderWidth / 2; const int radius = (qwtMin(r.width(), r.height()) - bw2) / 2; const QRect aRect( r.center().x() - radius, r.center().y() - radius, 2 * radius, 2 * radius); // // draw button face // painter->setBrush(buttonBrush); painter->drawEllipse(aRect); // // draw button shades // QPen pn; pn.setWidth(d_data->borderWidth); pn.setColor(lightColor); painter->setPen(pn); painter->drawArc(aRect, 45*16, 180*16); pn.setColor(darkColor); painter->setPen(pn); painter->drawArc(aRect, 225*16, 180*16); // // draw marker // if ( isValid() ) drawMarker(painter, d_data->angle, buttonTextColor); }
void QwtKnob::drawMarker | ( | QPainter * | p, |
double | arc, | ||
const QColor & | c | ||
) | [protected] |
Draw the marker at the knob's front.
p | Painter |
arc | Angle of the marker |
c | Marker color |
Definition at line 410 of file qwt_knob.cpp.
References QwtKnob::PrivateData::borderWidth, Dot, QwtKnob::PrivateData::dotWidth, QwtKnob::PrivateData::knobRect, Line, M_PI, qwtMax, and QwtKnob::PrivateData::symbol.
Referenced by drawKnob().
{ const double rarc = arc * M_PI / 180.0; const double ca = cos(rarc); const double sa = - sin(rarc); int radius = d_data->knobRect.width() / 2 - d_data->borderWidth; if (radius < 3) radius = 3; const int ym = d_data->knobRect.y() + radius + d_data->borderWidth; const int xm = d_data->knobRect.x() + radius + d_data->borderWidth; switch (d_data->symbol) { case Dot: { p->setBrush(c); p->setPen(Qt::NoPen); const double rb = double(qwtMax(radius - 4 - d_data->dotWidth / 2, 0)); p->drawEllipse(xm - qRound(sa * rb) - d_data->dotWidth / 2, ym - qRound(ca * rb) - d_data->dotWidth / 2, d_data->dotWidth, d_data->dotWidth); break; } case Line: { p->setPen(QPen(c, 2)); const double rb = qwtMax(double((radius - 4) / 3.0), 0.0); const double re = qwtMax(double(radius - 4), 0.0); p->drawLine ( xm - qRound(sa * rb), ym - qRound(ca * rb), xm - qRound(sa * re), ym - qRound(ca * re)); break; } } }
int QwtKnob::knobWidth | ( | ) | const |
QSize QwtKnob::minimumSizeHint | ( | ) | const [virtual] |
Return a minimum size hint.
Definition at line 541 of file qwt_knob.cpp.
References QwtRoundScaleDraw::extent(), QwtKnob::PrivateData::knobWidth, QwtKnob::PrivateData::scaleDist, and scaleDraw().
Referenced by sizeHint().
void QwtKnob::paintEvent | ( | QPaintEvent * | e ) | [protected, virtual] |
Repaint the knob
e | Paint event |
Definition at line 365 of file qwt_knob.cpp.
References draw(), and QwtPaintBuffer::painter().
{ const QRect &ur = e->rect(); if ( ur.isValid() ) { #if QT_VERSION < 0x040000 QwtPaintBuffer paintBuffer(this, ur); draw(paintBuffer.painter(), ur); #else QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); draw(&painter, ur); #endif } }
void QwtKnob::resizeEvent | ( | QResizeEvent * | e ) | [protected, virtual] |
const QwtRoundScaleDraw * QwtKnob::scaleDraw | ( | ) | const |
Definition at line 168 of file qwt_knob.cpp.
References QwtAbstractScale::abstractScaleDraw().
Referenced by draw(), minimumSizeHint(), and setTotalAngle().
{ return (QwtRoundScaleDraw *)abstractScaleDraw(); }
QwtRoundScaleDraw * QwtKnob::scaleDraw | ( | ) |
Definition at line 177 of file qwt_knob.cpp.
References QwtAbstractScale::abstractScaleDraw().
{ return (QwtRoundScaleDraw *)abstractScaleDraw(); }
void QwtKnob::setBorderWidth | ( | int | bw ) |
Set the knob's border width.
bw | new border width |
Definition at line 473 of file qwt_knob.cpp.
References QwtKnob::PrivateData::borderWidth, and qwtMax.
{ d_data->borderWidth = qwtMax(bw, 0); layoutKnob(); }
void QwtKnob::setKnobWidth | ( | int | w ) |
Change the knob's width.
The specified width must be >= 5, or it will be clipped.
w | New width |
Definition at line 457 of file qwt_knob.cpp.
References QwtKnob::PrivateData::knobWidth, and qwtMax.
void QwtKnob::setScaleDraw | ( | QwtRoundScaleDraw * | scaleDraw ) |
Change the scale draw of the knob
For changing the labels of the scales, it is necessary to derive from QwtRoundScaleDraw and overload QwtRoundScaleDraw::label().
Definition at line 158 of file qwt_knob.cpp.
References QwtAbstractScale::setAbstractScaleDraw(), setTotalAngle(), and QwtKnob::PrivateData::totalAngle.
{ setAbstractScaleDraw(scaleDraw); setTotalAngle(d_data->totalAngle); }
void QwtKnob::setSymbol | ( | QwtKnob::Symbol | s ) |
Set the symbol of the knob.
Definition at line 105 of file qwt_knob.cpp.
References QwtKnob::PrivateData::symbol.
void QwtKnob::setTotalAngle | ( | double | angle ) |
Set the total angle by which the knob can be turned.
angle | Angle in degrees. |
The default angle is 270 degrees. It is possible to specify an angle of more than 360 degrees so that the knob can be turned several times around its axis.
Definition at line 131 of file qwt_knob.cpp.
References scaleDraw(), QwtRoundScaleDraw::setAngleRange(), and QwtKnob::PrivateData::totalAngle.
Referenced by setScaleDraw().
{ if (angle < 10.0) d_data->totalAngle = 10.0; else d_data->totalAngle = angle; scaleDraw()->setAngleRange( -0.5 * d_data->totalAngle, 0.5 * d_data->totalAngle); layoutKnob(); }
QSize QwtKnob::sizeHint | ( | ) | const [virtual] |
Definition at line 531 of file qwt_knob.cpp.
References minimumSizeHint().
{ return minimumSizeHint(); }
Symbol QwtKnob::symbol | ( | ) | const |
double QwtKnob::totalAngle | ( | ) | const |
int QwtKnob::borderWidth [read, write] |
Return the border width.
Definition at line 39 of file qwt_knob.h.
int QwtKnob::knobWidth [read, write] |
Return the width of the knob.
Definition at line 38 of file qwt_knob.h.
QwtKnob::Symbol QwtKnob::symbol [read, write] |
double QwtKnob::totalAngle [read, write] |
Return the total angle.
Definition at line 40 of file qwt_knob.h.