20 #include <qstyleoption.h> 29 knobWidth = qMax( 3 * knob->
markerSize(), min );
33 const int d = 2 * ( extent + 4 ) + knobWidth;
35 const QMargins m = knob->contentsMargins();
36 return QSize( d + m.left() + m.right(), d + m.top() + m.bottom() );
44 double a = 90.0 - angle;
47 else if ( a >= 180.0 )
115 setSizePolicy( QSizePolicy::MinimumExpanding,
116 QSizePolicy::MinimumExpanding );
187 angle = qBound( 10.0, angle, 360.0 );
221 numTurns = qMax( numTurns, 1 );
226 const double angle = numTurns * 360.0;
294 const QRect cr = contentsRect();
302 const int dim = qMin( cr.width(), cr.height() );
308 QRect r( 0, 0, w, w );
312 r.moveLeft( cr.left() + d );
316 r.moveRight( cr.right() - d );
320 r.moveCenter( QPoint( cr.center().x(), r.center().y() ) );
325 r.moveTop( cr.top() + d );
329 r.moveBottom( cr.bottom() - d );
333 r.moveCenter( QPoint( r.center().x(), cr.center().y() ) );
351 const QRegion region( kr, QRegion::Ellipse );
352 if ( region.contains( pos ) && ( pos != kr.center() ) )
354 const double angle = QLineF( kr.center(), pos ).angle();
375 double angle = QLineF( rect().
center(), pos ).angle();
387 if ( qAbs( valueAngle - angle ) > 180.0 )
389 numTurns += ( angle > valueAngle ) ? -1 : 1;
396 const double boundedAngle =
400 angle = boundedAngle;
413 if ( ( currentAngle > 90.0 ) && ( boundedAngle < -90.0 ) )
415 else if ( ( currentAngle < -90.0 ) && ( boundedAngle > 90.0 ) )
421 angle = boundedAngle;
433 switch( event->type() )
435 case QEvent::StyleChange:
436 case QEvent::FontChange:
455 QPainter painter(
this );
456 painter.setClipRegion( event->region() );
460 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter,
this);
462 painter.setRenderHint( QPainter::Antialiasing,
true );
464 if ( !knobRect.contains( event->region().boundingRect() ) )
477 painter.setRenderHint( QPainter::Antialiasing,
false );
491 double dim = qMin( knobRect.width(), knobRect.height() );
494 QRectF aRect( 0, 0, dim, dim );
495 aRect.moveCenter( knobRect.center() );
497 QPen pen( Qt::NoPen );
500 QColor c1 = palette().color( QPalette::Light );
501 QColor c2 = palette().color( QPalette::Dark );
503 QLinearGradient gradient( aRect.topLeft(), aRect.bottomRight() );
504 gradient.setColorAt( 0.0, c1 );
505 gradient.setColorAt( 0.3, c1 );
506 gradient.setColorAt( 0.7, c2 );
507 gradient.setColorAt( 1.0, c2 );
517 double off = 0.3 * knobRect.width();
518 QRadialGradient gradient( knobRect.center(),
519 knobRect.width(), knobRect.topLeft() + QPointF( off, off ) );
521 gradient.setColorAt( 0.0, palette().
color( QPalette::Midlight ) );
522 gradient.setColorAt( 1.0, palette().
color( QPalette::Button ) );
524 brush = QBrush( gradient );
530 QRadialGradient gradient(knobRect.center().x() - knobRect.width() / 3,
531 knobRect.center().y() - knobRect.height() / 2,
532 knobRect.width() * 1.3,
533 knobRect.center().x(),
534 knobRect.center().y() - knobRect.height() / 2);
536 const QColor c = palette().color( QPalette::Button );
537 gradient.setColorAt(0, c.lighter(110) );
538 gradient.setColorAt( 0.5, c);
539 gradient.setColorAt( 0.501, c.darker(102) );
540 gradient.setColorAt(1, c.darker(115) );
542 brush = QBrush( gradient );
548 QLinearGradient gradient(
549 knobRect.topLeft(), knobRect.bottomRight() );
550 gradient.setColorAt( 0.0, palette().
color( QPalette::Mid ) );
551 gradient.setColorAt( 0.5, palette().
color( QPalette::Button ) );
552 gradient.setColorAt( 1.0, palette().
color( QPalette::Midlight ) );
553 brush = QBrush( gradient );
559 brush = palette().brush( QPalette::Button );
562 painter->setPen( pen );
563 painter->setBrush( brush );
564 painter->drawEllipse( aRect );
577 const QRectF& rect,
double angle )
const 583 const double sinA = -qFastSin( radians );
584 const double cosA = qFastCos( radians );
586 const double xm = rect.center().x();
587 const double ym = rect.center().y();
588 const double margin = 4.0;
595 if ( markerSize <= 0 )
596 markerSize = qRound( 0.4 * radius );
603 const double dotWidth =
qwtMinF( markerSize, radius );
605 const double dotCenterDist = radius - 0.5 * dotWidth;
606 if ( dotCenterDist > 0.0 )
608 const QPointF
center( xm - sinA * dotCenterDist,
609 ym - cosA * dotCenterDist );
611 QRectF ellipse( 0.0, 0.0, dotWidth, dotWidth );
612 ellipse.moveCenter( center );
614 QColor c1 = palette().color( QPalette::Light );
615 QColor c2 = palette().color( QPalette::Mid );
620 QLinearGradient gradient(
621 ellipse.topLeft(), ellipse.bottomRight() );
622 gradient.setColorAt( 0.0, c1 );
623 gradient.setColorAt( 1.0, c2 );
625 painter->setPen( Qt::NoPen );
626 painter->setBrush( gradient );
628 painter->drawEllipse( ellipse );
634 const double dotWidth =
qwtMinF( markerSize, radius);
636 const double dotCenterDist = radius - 0.5 * dotWidth;
637 if ( dotCenterDist > 0.0 )
639 const QPointF
center( xm - sinA * dotCenterDist,
640 ym - cosA * dotCenterDist );
642 QRectF ellipse( 0.0, 0.0, dotWidth, dotWidth );
643 ellipse.moveCenter( center );
645 painter->setPen( Qt::NoPen );
646 painter->setBrush( palette().
color( QPalette::ButtonText ) );
647 painter->drawEllipse( ellipse );
654 const double rb =
qwtMaxF( radius - markerSize, 1.0 );
655 const double re = radius;
657 const QLineF line( xm - sinA * rb, ym - cosA * rb,
658 xm - sinA * re, ym - cosA * re );
660 QPen pen( palette().
color( QPalette::ButtonText ), 0 );
661 pen.setCapStyle( Qt::FlatCap );
662 painter->setPen( pen );
663 painter->drawLine ( line );
669 const double rb =
qwtMaxF( radius - markerSize, 1.0 );
670 const double re = radius;
672 painter->translate( rect.center() );
673 painter->rotate( angle - 90.0 );
676 polygon += QPointF( re, 0.0 );
677 polygon += QPointF( rb, 0.5 * ( re - rb ) );
678 polygon += QPointF( rb, -0.5 * ( re - rb ) );
680 painter->setPen( Qt::NoPen );
681 painter->setBrush( palette().
color( QPalette::ButtonText ) );
682 painter->drawPolygon( polygon );
684 painter->resetTransform();
699 const QRect cr = contentsRect();
704 w = qMin( cr.width(), cr.height() );
708 const int extent = qCeil(
scaleDraw()->extent( font() ) );
712 QRect focusRect( 0, 0, w, w );
713 focusRect.moveCenter( cr.center() );
761 width = qMax( width, 0 );
765 QSizePolicy::Policy policy;
767 policy = QSizePolicy::Minimum;
769 policy = QSizePolicy::MinimumExpanding;
771 setSizePolicy( policy, policy );
849 #include "moc_qwt_knob.cpp" double invTransform(double p) const
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.
virtual void draw(QPainter *, const QPalette &) const
Draw the scale.
static void drawFocusRect(QPainter *, const QWidget *)
Draw a focus rectangle on a widget using its style.
Paint a triangle in QPalette::ButtonText color.
Qt::Alignment alignment() const
void setAbstractScaleDraw(QwtAbstractScaleDraw *)
Set a scale draw.
double totalAngle() const
QSize qwtExpandedToGlobalStrut(const QSize &size)
QWT_CONSTEXPR float qwtMaxF(float a, float b)
virtual bool isScrollPosition(const QPoint &) const QWT_OVERRIDE
Determine what to do when the user presses a mouse button.
void setValue(double value)
static QSize qwtKnobSizeHint(const QwtKnob *knob, int min)
void setScaleDraw(QwtRoundScaleDraw *)
QwtKnob(QWidget *parent=NULL)
Constructor.
virtual void drawMarker(QPainter *, const QRectF &, double angle) const
Draw the marker at the knob's front.
static double qwtToDegrees(double value)
void setAlignment(Qt::Alignment)
Set the alignment of the knob.
double transform(double s) const
Don't paint any marker.
QWT_CONSTEXPR float qwtMinF(float a, float b)
const QwtScaleMap & scaleMap() const
virtual void drawKnob(QPainter *, const QRectF &) const
Draw the knob.
int qwtFloor(qreal value)
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.
double qwtRadians(double degrees)
Translate degrees into radians.
void setMarkerSize(int)
Set the size of the marker.
KnobStyle
Style of the knob surface.
KnobStyle knobStyle() const
Paint a single tick in QPalette::ButtonText color.
virtual void changeEvent(QEvent *) QWT_OVERRIDE
MarkerStyle markerStyle() const
virtual double extent(const QFont &) const QWT_OVERRIDE
QwtKnob::KnobStyle knobStyle
void setAngleRange(double angle1, double angle2)
Adjust the baseline circle segment for round scales.
int transform(double) const
const QwtAbstractScaleDraw * abstractScaleDraw() const
virtual QSize minimumSizeHint() const QWT_OVERRIDE
virtual QSize sizeHint() const QWT_OVERRIDE
A class for drawing round scales.
void setTotalAngle(double angle)
Set the total angle by which the knob can be turned.
const QwtRoundScaleDraw * scaleDraw() const
virtual ~QwtKnob()
Destructor.
Build a gradient from QPalette::Midlight and QPalette::Button.
static double qwtToScaleAngle(double angle)
virtual double scrolledTo(const QPoint &) const QWT_OVERRIDE
Determine the value for a new position of the mouse.
void setBorderWidth(int)
Set the knob's border width.
span_constexpr std::size_t size(span< T, Extent > const &spn)
virtual void drawFocusIndicator(QPainter *) const
int knobWidth
Return the width of the knob.
void setRadius(double radius)
void setNumTurns(int)
Set the number of turns.
double qwtNormalizeDegrees(double degrees)
Normalize an angle to be int the range [0.0, 360.0[.
QwtKnob::MarkerStyle markerStyle
Fill the knob with a brush from QPalette::Button.
virtual void paintEvent(QPaintEvent *) QWT_OVERRIDE
void setMarkerStyle(MarkerStyle)
Set the marker type of the knob.