Skip to content
qwt_dial.h 4.85 KiB
Newer Older
pixhawk's avatar
pixhawk committed
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_DIAL_H
#define QWT_DIAL_H 1

#include "qwt_global.h"
#include "qwt_abstract_slider.h"
Bryant's avatar
Bryant committed
#include "qwt_abstract_scale_draw.h"
#include <qframe.h>
#include <qpalette.h>
pixhawk's avatar
pixhawk committed

class QwtDialNeedle;
Bryant's avatar
Bryant committed
class QwtRoundScaleDraw;
pixhawk's avatar
pixhawk committed

/*!
  \brief QwtDial class provides a rounded range control.
pixhawk's avatar
pixhawk committed

  QwtDial is intended as base class for dial widgets like
  speedometers, compass widgets, clocks ...
pixhawk's avatar
pixhawk committed

  \image html dials2.png

  A dial contains a scale and a needle indicating the current value
  of the dial. Depending on Mode one of them is fixed and the
pixhawk's avatar
pixhawk committed
  other is rotating. If not isReadOnly() the
  dial can be rotated by dragging the mouse or using keyboard inputs
Bryant's avatar
Bryant committed
  (see QwtAbstractSlider::keyPressEvent()). A dial might be wrapping, what means
pixhawk's avatar
pixhawk committed
  a rotation below/above one limit continues on the other limit (f.e compass).
  The scale might cover any arc of the dial, its values are related to
  the origin() of the dial.
Bryant's avatar
Bryant committed
  Often dials have to be updated very often according to values from external
  devices. For these high refresh rates QwtDial caches as much as possible.
  For derived classes it might be necessary to clear these caches manually
  according to attribute changes using invalidateCache().
pixhawk's avatar
pixhawk committed
  \sa QwtCompass, QwtAnalogClock, QwtDialNeedle
Bryant's avatar
Bryant committed
  \note The controls and dials examples shows different types of dials.
  \note QDial is more similar to QwtKnob than to QwtDial
pixhawk's avatar
pixhawk committed
*/

class QWT_EXPORT QwtDial: public QwtAbstractSlider
{
    Q_OBJECT

Bryant's avatar
Bryant committed
    Q_ENUMS( Shadow Mode Direction )
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    Q_PROPERTY( int lineWidth READ lineWidth WRITE setLineWidth )
    Q_PROPERTY( Shadow frameShadow READ frameShadow WRITE setFrameShadow )
    Q_PROPERTY( Mode mode READ mode WRITE setMode )
    Q_PROPERTY( double origin READ origin WRITE setOrigin )
    Q_PROPERTY( double minScaleArc READ minScaleArc WRITE setMinScaleArc )
    Q_PROPERTY( double maxScaleArc READ maxScaleArc WRITE setMaxScaleArc )
pixhawk's avatar
pixhawk committed

public:

    /*!
        \brief Frame shadow

         Unfortunately it is not possible to use QFrame::Shadow
         as a property of a widget that is not derived from QFrame.
         The following enum is made for the designer only. It is safe
         to use QFrame::Shadow instead.
     */
Bryant's avatar
Bryant committed
    enum Shadow
    {
        //! QFrame::Plain
pixhawk's avatar
pixhawk committed
        Plain = QFrame::Plain,
Bryant's avatar
Bryant committed

        //! QFrame::Raised
pixhawk's avatar
pixhawk committed
        Raised = QFrame::Raised,

Bryant's avatar
Bryant committed
        //! QFrame::Sunken
        Sunken = QFrame::Sunken
pixhawk's avatar
pixhawk committed
    };

Bryant's avatar
Bryant committed
    //! Mode controlling whether the needle or the scale is rotating
    enum Mode
    {
        //! The needle is rotating
pixhawk's avatar
pixhawk committed
        RotateNeedle,
Bryant's avatar
Bryant committed

        //! The needle is fixed, the scales are rotating
pixhawk's avatar
pixhawk committed
        RotateScale
    };

Bryant's avatar
Bryant committed
    explicit QwtDial( QWidget *parent = NULL );
pixhawk's avatar
pixhawk committed
    virtual ~QwtDial();

Bryant's avatar
Bryant committed
    void setFrameShadow( Shadow );
pixhawk's avatar
pixhawk committed
    Shadow frameShadow() const;

Bryant's avatar
Bryant committed
    void setLineWidth( int );
pixhawk's avatar
pixhawk committed
    int lineWidth() const;

Bryant's avatar
Bryant committed
    void setMode( Mode );
pixhawk's avatar
pixhawk committed
    Mode mode() const;

Bryant's avatar
Bryant committed
    void setScaleArc( double min, double max );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setMinScaleArc( double min );
pixhawk's avatar
pixhawk committed
    double minScaleArc() const;
Bryant's avatar
Bryant committed

    void setMaxScaleArc( double min );
pixhawk's avatar
pixhawk committed
    double maxScaleArc() const;

Bryant's avatar
Bryant committed
    virtual void setOrigin( double );
pixhawk's avatar
pixhawk committed
    double origin() const;

Bryant's avatar
Bryant committed
    void setNeedle( QwtDialNeedle * );
pixhawk's avatar
pixhawk committed
    const QwtDialNeedle *needle() const;
    QwtDialNeedle *needle();

    QRect boundingRect() const;
Bryant's avatar
Bryant committed
    QRect innerRect() const;

    virtual QRect scaleInnerRect() const;
pixhawk's avatar
pixhawk committed

    virtual QSize sizeHint() const;
    virtual QSize minimumSizeHint() const;

Bryant's avatar
Bryant committed
    void setScaleDraw( QwtRoundScaleDraw * );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    QwtRoundScaleDraw *scaleDraw();
    const QwtRoundScaleDraw *scaleDraw() const;
pixhawk's avatar
pixhawk committed

protected:
Bryant's avatar
Bryant committed
    virtual void wheelEvent( QWheelEvent * );
    virtual void paintEvent( QPaintEvent * );
    virtual void changeEvent( QEvent * );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    virtual void drawFrame( QPainter *p );
    virtual void drawContents( QPainter * ) const;
    virtual void drawFocusIndicator( QPainter * ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void invalidateCache();
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    virtual void drawScale( QPainter *, 
        const QPointF &center, double radius ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    virtual void drawScaleContents( QPainter *painter, 
        const QPointF &center, double radius ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    virtual void drawNeedle( QPainter *, const QPointF &,
        double radius, double direction, QPalette::ColorGroup ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    virtual double scrolledTo( const QPoint & ) const;
    virtual bool isScrollPosition( const QPoint & ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    virtual void sliderChange();
    virtual void scaleChange();
pixhawk's avatar
pixhawk committed

private:
Bryant's avatar
Bryant committed
    void setAngleRange( double angle, double span );
    void drawNeedle( QPainter * ) const;
pixhawk's avatar
pixhawk committed

    class PrivateData;
    PrivateData *d_data;
};

#endif