11 #include "qwt_dial_needle.h" 
   13 #include "qwt_scale_map.h" 
   14 #include "qwt_round_scale_draw.h" 
   15 #include "qwt_painter.h" 
   23 #include <qstyleoption.h> 
   25 static inline double qwtAngleDist( 
double a1, 
double a2 )
 
   27     double dist = qAbs( a2 - a1 );
 
   34 static inline bool qwtIsOnArc( 
double angle, 
double min, 
double max )
 
   38         return ( angle >= min ) && ( angle <= max );
 
   42         return ( angle >= min ) || ( angle <= max );
 
   46 static inline double qwtBoundedAngle( 
double min, 
double angle, 
double max )
 
   48     double from = qwtNormalizeDegrees( min );
 
   49     double to = qwtNormalizeDegrees( max );
 
   53     if ( qwtIsOnArc( angle, from, to ) )
 
   61         if ( qwtAngleDist( angle, from ) <
 
   62             qwtAngleDist( angle, to ) )
 
   75 class QwtDial::PrivateData
 
  127     m_data = 
new PrivateData;
 
  129     setFocusPolicy( Qt::TabFocus );
 
  131     QPalette p = palette();
 
  132     for ( 
int i = 0; i < QPalette::NColorGroups; i++ )
 
  134         const QPalette::ColorGroup colorGroup =
 
  135             static_cast< QPalette::ColorGroup 
>( i );
 
  140         p.setColor( colorGroup, QPalette::WindowText,
 
  141             p.color( colorGroup, QPalette::Base ) );
 
  172     if ( shadow != m_data->frameShadow )
 
  176         m_data->frameShadow = shadow;
 
  188     return m_data->frameShadow;
 
  217     return m_data->lineWidth;
 
  236     const QRect cr = contentsRect();
 
  238     const int dim = qMin( cr.width(), cr.height() );
 
  240     QRect inner( 0, 0, dim, dim );
 
  241     inner.moveCenter( cr.center() );
 
  257         int scaleDist = qwtCeil( sd->
extent( font() ) );
 
  260         rect.adjust( scaleDist, scaleDist, -scaleDist, -scaleDist );
 
  280     if ( 
mode != m_data->mode )
 
  303     m_data->pixmapCache = QPixmap();
 
  312     QPainter painter( 
this );
 
  313     painter.setClipRegion( event->region() );
 
  317     style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, 
this);
 
  322         painter.setRenderHint( QPainter::Antialiasing, 
true );
 
  329     const QRect r = contentsRect();
 
  330     if ( r.size() != m_data->pixmapCache.size() )
 
  333         m_data->pixmapCache.fill( Qt::transparent );
 
  335         QPainter p( &m_data->pixmapCache );
 
  336         p.setRenderHint( QPainter::Antialiasing, 
true );
 
  337         p.translate( -r.topLeft() );
 
  349     painter.drawPixmap( r.topLeft(), m_data->pixmapCache );
 
  376         palette(), 
lineWidth(), m_data->frameShadow );
 
  393     if ( testAttribute( Qt::WA_NoSystemBackground ) ||
 
  394         palette().brush( QPalette::Base ) !=
 
  395         palette().brush( QPalette::Window ) )
 
  400         painter->setPen( Qt::NoPen );
 
  401         painter->setBrush( palette().brush( QPalette::Base ) );
 
  402         painter->drawEllipse( br );
 
  407     if ( palette().brush( QPalette::WindowText ) !=
 
  408         palette().brush( QPalette::Base ) )
 
  411         painter->setPen( Qt::NoPen );
 
  412         painter->setBrush( palette().brush( QPalette::WindowText ) );
 
  413         painter->drawEllipse( insideScaleRect );
 
  417     const QPointF center = insideScaleRect.center();
 
  418     const double radius = 0.5 * insideScaleRect.width();
 
  439     double radius, 
double direction, QPalette::ColorGroup colorGroup )
 const 
  441     if ( m_data->needle )
 
  443         direction = 360.0 - direction; 
 
  444         m_data->needle->draw( painter, center, radius, direction, colorGroup );
 
  453     QPalette::ColorGroup colorGroup;
 
  455         colorGroup = hasFocus() ? QPalette::Active : QPalette::Inactive;
 
  457         colorGroup = QPalette::Disabled;
 
  462     painter->setRenderHint( QPainter::Antialiasing, 
true );
 
  463     drawNeedle( painter, sr.center(), 0.5 * sr.width(),
 
  476     const QPointF& center, 
double radius )
 const 
  485     QPalette pal = palette();
 
  487     const QColor textColor = pal.color( QPalette::Text );
 
  488     pal.setColor( QPalette::WindowText, textColor ); 
 
  490     painter->setFont( font() );
 
  491     painter->setPen( QPen( textColor, sd->
penWidthF() ) );
 
  493     painter->setBrush( Qt::red );
 
  494     sd->
draw( painter, pal );
 
  507     const QPointF& center, 
double radius )
 const 
  524     if ( 
needle != m_data->needle )
 
  526         if ( m_data->needle )
 
  527             delete m_data->needle;
 
  540     return m_data->needle;
 
  549     return m_data->needle;
 
  590     if ( minArc != 360.0 && minArc != -360.0 )
 
  591         minArc = std::fmod( minArc, 360.0 );
 
  592     if ( maxArc != 360.0 && maxArc != -360.0 )
 
  593         maxArc = std::fmod( maxArc, 360.0 );
 
  629     return m_data->minScaleArc;
 
  649     return m_data->maxScaleArc;
 
  676     return m_data->origin;
 
  687         sh = qwtCeil( 
scaleDraw()->extent( font() ) );
 
  693         hint = qwtExpandedToGlobalStrut( hint );
 
  706         sh = qwtCeil( 
scaleDraw()->extent( font() ) );
 
  710     return QSize( d, d );
 
  723     const QRegion region( 
innerRect(), QRegion::Ellipse );
 
  724     if ( region.contains( pos ) && ( pos != 
innerRect().center() ) )
 
  726         double angle = QLineF( rect().center(), pos ).angle();
 
  728             angle = 360.0 - angle;
 
  733         m_data->mouseOffset = qwtNormalizeDegrees( angle - valueAngle );
 
  753     double angle = QLineF( rect().center(), pos ).angle();
 
  757         angle = 360.0 - angle;
 
  760     angle = qwtNormalizeDegrees( angle - m_data->mouseOffset );
 
  761     angle = qwtNormalizeDegrees( 90.0 - angle );
 
  770             double boundedAngle = angle;
 
  773             if ( qAbs( arc ) > 180.0 )
 
  775                 boundedAngle = ( arc > 0 )
 
  779             m_data->mouseOffset += ( boundedAngle - angle );
 
  781             angle = boundedAngle;
 
  786         const double boundedAngle =
 
  790             m_data->mouseOffset += ( boundedAngle - angle );
 
  792         angle = boundedAngle;
 
  806     switch( event->type() )
 
  808         case QEvent::EnabledChange:
 
  809         case QEvent::FontChange:
 
  810         case QEvent::StyleChange:
 
  811         case QEvent::PaletteChange:
 
  812         case QEvent::LanguageChange:
 
  813         case QEvent::LocaleChange:
 
  831 #if QT_VERSION < 0x050e00 
  832     const QPoint wheelPos = 
event->pos();
 
  834     const QPoint wheelPos = 
event->position().toPoint();
 
  837     const QRegion region( 
innerRect(), QRegion::Ellipse );
 
  838     if ( region.contains( wheelPos ) )
 
  842 void QwtDial::setAngleRange( 
double angle, 
double span )
 
  846         angle = qwtNormalizeDegrees( angle - 270.0 );
 
  847         sd->setAngleRange( angle, angle + span );
 
  863     setAngleRange( m_data->origin + m_data->minScaleArc,
 
  864         m_data->maxScaleArc - m_data->minScaleArc );
 
  869         setAngleRange( m_data->origin - arc,
 
  870             m_data->maxScaleArc - m_data->minScaleArc );
 
  877 #include "moc_qwt_dial.cpp" 
A abstract base class for drawing scales.
virtual double extent(const QFont &font) const =0
virtual void draw(QPainter *, const QPalette &) const
Draw the scale.
const QwtScaleMap & scaleMap() const
void setScaleMaxMajor(int ticks)
Set the maximum number of major tick intervals.
const QwtAbstractScaleDraw * abstractScaleDraw() const
void setScaleMaxMinor(int ticks)
Set the maximum number of minor tick intervals.
int transform(double) const
void setAbstractScaleDraw(QwtAbstractScaleDraw *)
Set a scale draw.
virtual void changeEvent(QEvent *) override
An abstract base class for slider widgets with a scale.
virtual void scaleChange() override
virtual void sliderChange()
Calling update()
void setValue(double value)
virtual void wheelEvent(QWheelEvent *) override
double value() const
Returns the current value.
void setMinScaleArc(double)
virtual void drawFrame(QPainter *)
double minScaleArc() const
virtual ~QwtDial()
Destructor.
double maxScaleArc() const
void setFrameShadow(Shadow)
virtual void wheelEvent(QWheelEvent *) override
virtual QSize sizeHint() const override
void setScaleDraw(QwtRoundScaleDraw *)
virtual QRect scaleInnerRect() const
virtual void setOrigin(double)
Change the origin.
virtual void changeEvent(QEvent *) override
virtual void scaleChange() override
QRect boundingRect() const
virtual void drawScale(QPainter *, const QPointF ¢er, double radius) const
const QwtDialNeedle * needle() const
void setMode(Mode)
Change the mode of the dial.
Mode
Mode controlling whether the needle or the scale is rotating.
@ RotateScale
The needle is fixed, the scales are rotating.
@ RotateNeedle
The needle is rotating.
virtual bool isScrollPosition(const QPoint &) const override
Determine what to do when the user presses a mouse button.
virtual double scrolledTo(const QPoint &) const override
Determine the value for a new position of the slider handle.
QwtDial(QWidget *parent=NULL)
Constructor.
virtual void drawFocusIndicator(QPainter *) const
virtual void sliderChange() override
Calling update()
virtual QSize minimumSizeHint() const override
Shadow frameShadow() const
virtual void paintEvent(QPaintEvent *) override
void setNeedle(QwtDialNeedle *)
virtual void drawNeedle(QPainter *, const QPointF &, double radius, double direction, QPalette::ColorGroup) const
void setScaleArc(double minArc, double maxArc)
QwtRoundScaleDraw * scaleDraw()
virtual void drawScaleContents(QPainter *painter, const QPointF ¢er, double radius) const
virtual void drawContents(QPainter *) const
Draw the contents inside the frame.
void setMaxScaleArc(double)
Base class for needles that can be used in a QwtDial.
static void drawRoundFrame(QPainter *, const QRectF &, const QPalette &, int lineWidth, int frameStyle)
static void drawFocusRect(QPainter *, const QWidget *)
Draw a focus rectangle on a widget using its style.
static QPixmap backingStore(QWidget *, const QSize &)
A class for drawing round scales.
void setRadius(double radius)
void moveCenter(double x, double y)
Move the center of the scale draw, leaving the radius unchanged.
double transform(double s) const
double invTransform(double p) const