Skip to content
Snippets Groups Projects
qwt_scale_widget.h 3.46 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
     *
     * 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_SCALE_WIDGET_H
    #define QWT_SCALE_WIDGET_H
    
    
    Bryant's avatar
    Bryant committed
    #include "qwt_global.h"
    #include "qwt_text.h"
    #include "qwt_scale_draw.h"
    
    pixhawk's avatar
    pixhawk committed
    #include <qwidget.h>
    #include <qfont.h>
    #include <qcolor.h>
    #include <qstring.h>
    
    class QPainter;
    
    Bryant's avatar
    Bryant committed
    class QwtTransform;
    
    pixhawk's avatar
    pixhawk committed
    class QwtScaleDiv;
    class QwtColorMap;
    
    /*!
      \brief A Widget which contains a scale
    
      This Widget can be used to decorate composite widgets with
      a scale.
    */
    
    class QWT_EXPORT QwtScaleWidget : public QWidget
    {
    
    pixhawk's avatar
    pixhawk committed
    
    public:
    
    Bryant's avatar
    Bryant committed
        //! Layout flags of the title
        enum LayoutFlag
        {
            /*!
              The title of vertical scales is painted from top to bottom. 
              Otherwise it is painted from bottom to top.
             */
            TitleInverted = 1
        };
    
        //! Layout flags of the title
        typedef QFlags<LayoutFlag> LayoutFlags;
    
        explicit QwtScaleWidget( QWidget *parent = NULL );
        explicit QwtScaleWidget( QwtScaleDraw::Alignment, QWidget *parent = NULL );
    
    pixhawk's avatar
    pixhawk committed
        virtual ~QwtScaleWidget();
    
    
    Bryant's avatar
    Bryant committed
    Q_SIGNALS:
        //! Signal emitted, whenever the scale division changes
    
    pixhawk's avatar
    pixhawk committed
        void scaleDivChanged();
    
    public:
    
    Bryant's avatar
    Bryant committed
        void setTitle( const QString &title );
        void setTitle( const QwtText &title );
    
    pixhawk's avatar
    pixhawk committed
        QwtText title() const;
    
    
    Bryant's avatar
    Bryant committed
        void setLayoutFlag( LayoutFlag, bool on );
        bool testLayoutFlag( LayoutFlag ) const;
    
        void setBorderDist( int start, int end );
    
    pixhawk's avatar
    pixhawk committed
        int startBorderDist() const;
        int endBorderDist() const;
    
    
    Bryant's avatar
    Bryant committed
        void getBorderDistHint( int &start, int &end ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void getMinBorderDist( int &start, int &end ) const;
        void setMinBorderDist( int start, int end );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void setMargin( int );
    
    pixhawk's avatar
    pixhawk committed
        int margin() const;
    
    
    Bryant's avatar
    Bryant committed
        void setSpacing( int td );
    
    pixhawk's avatar
    pixhawk committed
        int spacing() const;
    
    
    Bryant's avatar
    Bryant committed
        void setScaleDiv( const QwtScaleDiv &sd );
        void setTransformation( QwtTransform * );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void setScaleDraw( QwtScaleDraw * );
    
    pixhawk's avatar
    pixhawk committed
        const QwtScaleDraw *scaleDraw() const;
        QwtScaleDraw *scaleDraw();
    
    
    Bryant's avatar
    Bryant committed
        void setLabelAlignment( Qt::Alignment );
        void setLabelRotation( double rotation );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void setColorBarEnabled( bool );
    
    pixhawk's avatar
    pixhawk committed
        bool isColorBarEnabled() const;
    
    
    Bryant's avatar
    Bryant committed
        void setColorBarWidth( int );
    
    pixhawk's avatar
    pixhawk committed
        int colorBarWidth() const;
    
    
    Bryant's avatar
    Bryant committed
        void setColorMap( const QwtInterval &, QwtColorMap * );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        QwtInterval colorBarInterval() const;
        const QwtColorMap *colorMap() const;
    
    pixhawk's avatar
    pixhawk committed
    
        virtual QSize sizeHint() const;
        virtual QSize minimumSizeHint() const;
    
    
    Bryant's avatar
    Bryant committed
        int titleHeightForWidth( int width ) const;
        int dimForLength( int length, const QFont &scaleFont ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void drawColorBar( QPainter *painter, const QRectF & ) const;
        void drawTitle( QPainter *painter, QwtScaleDraw::Alignment,
            const QRectF &rect ) const;
    
    Bryant's avatar
    Bryant committed
        void setAlignment( QwtScaleDraw::Alignment );
    
    pixhawk's avatar
    pixhawk committed
        QwtScaleDraw::Alignment alignment() const;
    
    
    Bryant's avatar
    Bryant committed
        QRectF colorBarRect( const QRectF& ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    protected:
    
    Bryant's avatar
    Bryant committed
        virtual void paintEvent( QPaintEvent * );
        virtual void resizeEvent( QResizeEvent * );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void draw( QPainter *p ) const;
    
    pixhawk's avatar
    pixhawk committed
    
        void scaleChange();
        void layoutScale( bool update = true );
    
    private:
    
    Bryant's avatar
    Bryant committed
        void initScale( QwtScaleDraw::Alignment );
    
    pixhawk's avatar
    pixhawk committed
    
        class PrivateData;
        PrivateData *d_data;
    };
    
    
    Bryant's avatar
    Bryant committed
    Q_DECLARE_OPERATORS_FOR_FLAGS( QwtScaleWidget::LayoutFlags )
    
    
    pixhawk's avatar
    pixhawk committed
    #endif