18 #include <qstyleoption.h> 21 #include <qapplication.h> 23 #if QT_VERSION < 0x040601 24 #define qAtan2(y, x) ::atan2(y, x) 25 #define qFabs(x) ::fabs(x) 26 #define qFastCos(x) qCos(x) 27 #define qFastSin(x) qSin(x) 34 knobWidth = qMax( 3 * knob->
markerSize(), min );
38 const int d = 2 * ( extent + 4 ) + knobWidth;
40 int left, right, top, bottom;
41 knob->getContentsMargins( &left, &top, &right, &bottom );
43 return QSize( d + left + right, d + top + bottom );
51 double a = 90.0 - angle;
54 else if ( a >= 180.0 )
122 setSizePolicy( QSizePolicy::MinimumExpanding,
123 QSizePolicy::MinimumExpanding );
194 angle = qBound( 10.0, angle, 360.0 );
228 numTurns = qMax( numTurns, 1 );
233 const double angle = numTurns * 360.0;
301 const QRect cr = contentsRect();
303 const int extent = qCeil(
scaleDraw()->extent( font() ) );
309 const int dim = qMin( cr.width(), cr.height() );
315 QRect r( 0, 0, w, w );
319 r.moveLeft( cr.left() + d );
323 r.moveRight( cr.right() - d );
327 r.moveCenter( QPoint( cr.center().x(), r.center().y() ) );
332 r.moveTop( cr.top() + d );
336 r.moveBottom( cr.bottom() - d );
340 r.moveCenter( QPoint( r.center().x(), cr.center().y() ) );
358 const QRegion region( kr, QRegion::Ellipse );
359 if ( region.contains( pos ) && ( pos != kr.center() ) )
361 const double angle = QLineF( kr.center(), pos ).angle();
382 double angle = QLineF( rect().center(), pos ).angle();
394 if ( qAbs( valueAngle - angle ) > 180.0 )
396 numTurns += ( angle > valueAngle ) ? -1 : 1;
403 const double boundedAngle =
407 angle = boundedAngle;
420 if ( ( currentAngle > 90.0 ) && ( boundedAngle < -90.0 ) )
422 else if ( ( currentAngle < -90.0 ) && ( boundedAngle > 90.0 ) )
428 angle = boundedAngle;
440 switch( event->type() )
442 case QEvent::StyleChange:
443 case QEvent::FontChange:
462 QPainter painter(
this );
463 painter.setClipRegion( event->region() );
467 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter,
this);
469 painter.setRenderHint( QPainter::Antialiasing,
true );
471 if ( !knobRect.contains( event->region().boundingRect() ) )
484 painter.setRenderHint( QPainter::Antialiasing,
false );
498 double dim = qMin( knobRect.width(), knobRect.height() );
501 QRectF aRect( 0, 0, dim, dim );
502 aRect.moveCenter( knobRect.center() );
504 QPen pen( Qt::NoPen );
507 QColor c1 = palette().color( QPalette::Light );
508 QColor c2 = palette().color( QPalette::Dark );
510 QLinearGradient gradient( aRect.topLeft(), aRect.bottomRight() );
511 gradient.setColorAt( 0.0, c1 );
512 gradient.setColorAt( 0.3, c1 );
513 gradient.setColorAt( 0.7, c2 );
514 gradient.setColorAt( 1.0, c2 );
524 double off = 0.3 * knobRect.width();
525 QRadialGradient gradient( knobRect.center(),
526 knobRect.width(), knobRect.topLeft() + QPointF( off, off ) );
528 gradient.setColorAt( 0.0, palette().color( QPalette::Midlight ) );
529 gradient.setColorAt( 1.0, palette().color( QPalette::Button ) );
531 brush = QBrush( gradient );
537 QRadialGradient gradient(knobRect.center().x() - knobRect.width() / 3,
538 knobRect.center().y() - knobRect.height() / 2,
539 knobRect.width() * 1.3,
540 knobRect.center().x(),
541 knobRect.center().y() - knobRect.height() / 2);
543 const QColor c = palette().color( QPalette::Button );
544 gradient.setColorAt(0, c.lighter(110));
545 gradient.setColorAt(qreal(0.5), c);
546 gradient.setColorAt(qreal(0.501), c.darker(102));
547 gradient.setColorAt(1, c.darker(115));
549 brush = QBrush( gradient );
555 QLinearGradient gradient(
556 knobRect.topLeft(), knobRect.bottomRight() );
557 gradient.setColorAt( 0.0, palette().color( QPalette::Mid ) );
558 gradient.setColorAt( 0.5, palette().color( QPalette::Button ) );
559 gradient.setColorAt( 1.0, palette().color( QPalette::Midlight ) );
560 brush = QBrush( gradient );
566 brush = palette().brush( QPalette::Button );
569 painter->setPen( pen );
570 painter->setBrush( brush );
571 painter->drawEllipse( aRect );
584 const QRectF &rect,
double angle )
const 590 const double sinA = -
qFastSin( radians );
591 const double cosA =
qFastCos( radians );
593 const double xm = rect.center().x();
594 const double ym = rect.center().y();
595 const double margin = 4.0;
602 if ( markerSize <= 0 )
603 markerSize = qRound( 0.4 * radius );
610 const double dotWidth =
611 qMin(
double( markerSize ), radius);
613 const double dotCenterDist = radius - 0.5 * dotWidth;
614 if ( dotCenterDist > 0.0 )
616 const QPointF center( xm - sinA * dotCenterDist,
617 ym - cosA * dotCenterDist );
619 QRectF ellipse( 0.0, 0.0, dotWidth, dotWidth );
620 ellipse.moveCenter( center );
622 QColor c1 = palette().color( QPalette::Light );
623 QColor c2 = palette().color( QPalette::Mid );
628 QLinearGradient gradient(
629 ellipse.topLeft(), ellipse.bottomRight() );
630 gradient.setColorAt( 0.0, c1 );
631 gradient.setColorAt( 1.0, c2 );
633 painter->setPen( Qt::NoPen );
634 painter->setBrush( gradient );
636 painter->drawEllipse( ellipse );
642 const double dotWidth =
643 qMin(
double( markerSize ), radius);
645 const double dotCenterDist = radius - 0.5 * dotWidth;
646 if ( dotCenterDist > 0.0 )
648 const QPointF center( xm - sinA * dotCenterDist,
649 ym - cosA * dotCenterDist );
651 QRectF ellipse( 0.0, 0.0, dotWidth, dotWidth );
652 ellipse.moveCenter( center );
654 painter->setPen( Qt::NoPen );
655 painter->setBrush( palette().color( QPalette::ButtonText ) );
656 painter->drawEllipse( ellipse );
663 const double rb = qMax( radius - markerSize, 1.0 );
664 const double re = radius;
666 const QLineF line( xm - sinA * rb, ym - cosA * rb,
667 xm - sinA * re, ym - cosA * re );
669 QPen pen( palette().color( QPalette::ButtonText ), 0 );
670 pen.setCapStyle( Qt::FlatCap );
671 painter->setPen( pen );
672 painter->drawLine ( line );
678 const double rb = qMax( radius - markerSize, 1.0 );
679 const double re = radius;
681 painter->translate( rect.center() );
682 painter->rotate( angle - 90.0 );
685 polygon += QPointF( re, 0.0 );
686 polygon += QPointF( rb, 0.5 * ( re - rb ) );
687 polygon += QPointF( rb, -0.5 * ( re - rb ) );
689 painter->setPen( Qt::NoPen );
690 painter->setBrush( palette().color( QPalette::ButtonText ) );
691 painter->drawPolygon( polygon );
693 painter->resetTransform();
708 const QRect cr = contentsRect();
713 w = qMin( cr.width(), cr.height() );
717 const int extent = qCeil(
scaleDraw()->extent( font() ) );
721 QRect focusRect( 0, 0, w, w );
722 focusRect.moveCenter( cr.center() );
770 width = qMax( width, 0 );
774 QSizePolicy::Policy policy;
776 policy = QSizePolicy::Minimum;
778 policy = QSizePolicy::MinimumExpanding;
780 setSizePolicy( policy, policy );
845 return hint.expandedTo( QApplication::globalStrut() );
virtual void drawMarker(QPainter *, const QRectF &, double arc) const
Draw the marker at the knob's front.
void setKnobStyle(KnobStyle)
Set the knob type.
void setScale(double lowerBound, double upperBound)
Specify a scale.
Paint a circle in QPalette::ButtonText color.
void setKnobWidth(int)
Change the knob's width.
void setBorderWidth(int bw)
Set the knob's border width.
static void drawFocusRect(QPainter *, const QWidget *)
Draw a focus rectangle on a widget using its style.
Paint a triangle in QPalette::ButtonText color.
void setAbstractScaleDraw(QwtAbstractScaleDraw *)
Set a scale draw.
int transform(double) const
void setValue(double val)
virtual void drawKnob(QPainter *, const QRectF &) const
Draw the knob.
static QSize qwtKnobSizeHint(const QwtKnob *knob, int min)
void setScaleDraw(QwtRoundScaleDraw *)
virtual QSize sizeHint() const
Qt::Alignment alignment() const
const QwtScaleMap & scaleMap() const
virtual bool isScrollPosition(const QPoint &) const
Determine what to do when the user presses a mouse button.
QwtKnob(QWidget *parent=NULL)
Constructor.
static double qwtToDegrees(double value)
virtual double extent(const QFont &) const
void setAlignment(Qt::Alignment)
Set the alignment of the knob.
Don't paint any marker.
virtual void drawFocusIndicator(QPainter *) const
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
void moveCenter(double x, double y)
Move the center of the scale draw, leaving the radius unchanged.
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
An abstract base class for slider widgets with a scale.
const QwtRoundScaleDraw * scaleDraw() const
double qwtRadians(double degrees)
Translate degrees into radians.
void setMarkerSize(int)
Set the size of the marker.
virtual double scrolledTo(const QPoint &) const
Determine the value for a new position of the mouse.
virtual void changeEvent(QEvent *)
KnobStyle
Style of the knob surface.
KnobStyle knobStyle() const
Paint a single tick in QPalette::ButtonText color.
double totalAngle() const
const QwtAbstractScaleDraw * abstractScaleDraw() const
virtual QSize minimumSizeHint() const
double invTransform(double p) const
QwtKnob::KnobStyle knobStyle
void setAngleRange(double angle1, double angle2)
Adjust the baseline circle segment for round scales.
A class for drawing round scales.
TFSIMD_FORCE_INLINE const tfScalar & w() const
void setTotalAngle(double angle)
Set the total angle by which the knob can be turned.
virtual void draw(QPainter *, const QPalette &) const
Draw the scale.
virtual ~QwtKnob()
Destructor.
Build a gradient from QPalette::Midlight and QPalette::Button.
static double qwtToScaleAngle(double angle)
MarkerStyle markerStyle() const
int knobWidth
Return the width of the knob.
void setRadius(double radius)
double transform(double s) const
void setNumTurns(int)
Set the number of turns.
double qwtNormalizeDegrees(double degrees)
Normalize an angle to be int the range [0.0, 360.0[.
virtual void paintEvent(QPaintEvent *)
QwtKnob::MarkerStyle markerStyle
Fill the knob with a brush from QPalette::Button.
void setMarkerStyle(MarkerStyle)
Set the marker type of the knob.