Skip to content
Snippets Groups Projects
qwt_dial_needle.h 3.99 KiB
Newer Older
  • Learn to ignore specific revisions
  • pixhawk's avatar
    pixhawk committed
    /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     * Qwt Widget Library
     * Copyright (C) 1997   Josef Wilgen
     * Copyright (C) 2002   Uwe Rathmann
    
    pixhawk's avatar
    pixhawk committed
     * 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_NEEDLE_H
    #define QWT_DIAL_NEEDLE_H 1
    
    #include "qwt_global.h"
    
    Bryant's avatar
    Bryant committed
    #include <qpalette.h>
    
    pixhawk's avatar
    pixhawk committed
    
    class QPainter;
    class QPoint;
    
    /*!
      \brief Base class for needles that can be used in a QwtDial.
    
    
      QwtDialNeedle is a pointer that indicates a value by pointing
      to a specific direction.
    
    
    pixhawk's avatar
    pixhawk committed
      \sa QwtDial, QwtCompass
    */
    
    class QWT_EXPORT QwtDialNeedle
    {
    public:
        QwtDialNeedle();
        virtual ~QwtDialNeedle();
    
    
    Bryant's avatar
    Bryant committed
        virtual void setPalette( const QPalette & );
        const QPalette &palette() const;
    
        virtual void draw( QPainter *painter, const QPointF &center,
            double length, double direction, 
            QPalette::ColorGroup = QPalette::Active ) const;
    
    protected:
    
    pixhawk's avatar
    pixhawk committed
        /*!
    
    Bryant's avatar
    Bryant committed
          \brief Draw the needle
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
          The origin of the needle is at position (0.0, 0.0 )
          pointing in direction 0.0 ( = east ). 
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
          The painter is already initialized with translation and 
          rotation.
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
          \param painter Painter
          \param length Length of the needle
          \param colorGroup Color group, used for painting
    
          \sa setPalette(), palette()
        */
        virtual void drawNeedle( QPainter *painter, 
            double length, QPalette::ColorGroup colorGroup ) const = 0;
    
        virtual void drawKnob( QPainter *, double width, 
            const QBrush &, bool sunken ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    private:
        QPalette d_palette;
    };
    
    /*!
      \brief A needle for dial widgets
    
      The following colors are used:
    
    Bryant's avatar
    Bryant committed
    
      - QPalette::Mid\n
    
    pixhawk's avatar
    pixhawk committed
        Pointer
    
    Bryant's avatar
    Bryant committed
      - QPalette::Base\n
    
    pixhawk's avatar
    pixhawk committed
        Knob
    
      \sa QwtDial, QwtCompass
    */
    
    class QWT_EXPORT QwtDialSimpleNeedle: public QwtDialNeedle
    {
    public:
        //! Style of the needle
    
    Bryant's avatar
    Bryant committed
        enum Style
        {
            //! Arrow
    
    pixhawk's avatar
    pixhawk committed
            Arrow,
    
    Bryant's avatar
    Bryant committed
    
            //! A straight line from the center
    
    pixhawk's avatar
    pixhawk committed
            Ray
        };
    
    
    Bryant's avatar
    Bryant committed
        QwtDialSimpleNeedle( Style, bool hasKnob = true,
            const QColor &mid = Qt::gray, const QColor &base = Qt::darkGray );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void setWidth( double width );
        double width() const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
    protected:
        virtual void drawNeedle( QPainter *, double length,
            QPalette::ColorGroup ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    private:
        Style d_style;
        bool d_hasKnob;
    
    Bryant's avatar
    Bryant committed
        double d_width;
    
    pixhawk's avatar
    pixhawk committed
    };
    
    /*!
      \brief A magnet needle for compass widgets
    
      A magnet needle points to two opposite directions indicating
      north and south.
    
      The following colors are used:
    
    Bryant's avatar
    Bryant committed
      - QPalette::Light\n
    
    pixhawk's avatar
    pixhawk committed
        Used for pointing south
    
    Bryant's avatar
    Bryant committed
      - QPalette::Dark\n
    
    pixhawk's avatar
    pixhawk committed
        Used for pointing north
    
    Bryant's avatar
    Bryant committed
      - QPalette::Base\n
    
    pixhawk's avatar
    pixhawk committed
        Knob (ThinStyle only)
    
      \sa QwtDial, QwtCompass
    */
    
    class QWT_EXPORT QwtCompassMagnetNeedle: public QwtDialNeedle
    {
    public:
        //! Style of the needle
    
    Bryant's avatar
    Bryant committed
        enum Style
        {
            //! A needle with a triangular shape
    
    pixhawk's avatar
    pixhawk committed
            TriangleStyle,
    
    Bryant's avatar
    Bryant committed
    
            //! A thin needle 
    
    pixhawk's avatar
    pixhawk committed
            ThinStyle
        };
    
    
    Bryant's avatar
    Bryant committed
        QwtCompassMagnetNeedle( Style = TriangleStyle,
            const QColor &light = Qt::white, const QColor &dark = Qt::red );
    
    pixhawk's avatar
    pixhawk committed
    
    protected:
    
    Bryant's avatar
    Bryant committed
        virtual void drawNeedle( QPainter *, 
            double length, QPalette::ColorGroup ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    private:
        Style d_style;
    };
    
    /*!
      \brief An indicator for the wind direction
    
      QwtCompassWindArrow shows the direction where the wind comes from.
    
    
    Bryant's avatar
    Bryant committed
      - QPalette::Light\n
    
    pixhawk's avatar
    pixhawk committed
        Used for Style1, or the light half of Style2
    
    Bryant's avatar
    Bryant committed
      - QPalette::Dark\n
    
    pixhawk's avatar
    pixhawk committed
        Used for the dark half of Style2
    
      \sa QwtDial, QwtCompass
    */
    
    class QWT_EXPORT QwtCompassWindArrow: public QwtDialNeedle
    {
    public:
        //! Style of the arrow
    
    Bryant's avatar
    Bryant committed
        enum Style
        {
            //! A needle pointing to the center
    
    pixhawk's avatar
    pixhawk committed
            Style1,
    
    Bryant's avatar
    Bryant committed
    
            //! A needle pointing to the center
    
    pixhawk's avatar
    pixhawk committed
            Style2
        };
    
    
    Bryant's avatar
    Bryant committed
        QwtCompassWindArrow( Style, const QColor &light = Qt::white,
            const QColor &dark = Qt::gray );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
    protected:
        virtual void drawNeedle( QPainter *, 
            double length, QPalette::ColorGroup ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    private:
        Style d_style;
    };
    
    
    Bryant's avatar
    Bryant committed
    #endif