qwt_scale_widget.h 3.46 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12
/* -*- 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
13 14 15
#include "qwt_global.h"
#include "qwt_text.h"
#include "qwt_scale_draw.h"
pixhawk's avatar
pixhawk committed
16 17 18 19 20 21
#include <qwidget.h>
#include <qfont.h>
#include <qcolor.h>
#include <qstring.h>

class QPainter;
Bryant's avatar
Bryant committed
22
class QwtTransform;
pixhawk's avatar
pixhawk committed
23 24 25 26 27 28 29 30 31 32 33 34
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
{
35
    Q_OBJECT
pixhawk's avatar
pixhawk committed
36 37

public:
Bryant's avatar
Bryant committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    //! 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
53 54
    virtual ~QwtScaleWidget();

Bryant's avatar
Bryant committed
55 56
Q_SIGNALS:
    //! Signal emitted, whenever the scale division changes
pixhawk's avatar
pixhawk committed
57 58 59
    void scaleDivChanged();

public:
Bryant's avatar
Bryant committed
60 61
    void setTitle( const QString &title );
    void setTitle( const QwtText &title );
pixhawk's avatar
pixhawk committed
62 63
    QwtText title() const;

Bryant's avatar
Bryant committed
64 65 66 67
    void setLayoutFlag( LayoutFlag, bool on );
    bool testLayoutFlag( LayoutFlag ) const;

    void setBorderDist( int start, int end );
pixhawk's avatar
pixhawk committed
68 69 70
    int startBorderDist() const;
    int endBorderDist() const;

Bryant's avatar
Bryant committed
71
    void getBorderDistHint( int &start, int &end ) const;
pixhawk's avatar
pixhawk committed
72

Bryant's avatar
Bryant committed
73 74
    void getMinBorderDist( int &start, int &end ) const;
    void setMinBorderDist( int start, int end );
pixhawk's avatar
pixhawk committed
75

Bryant's avatar
Bryant committed
76
    void setMargin( int );
pixhawk's avatar
pixhawk committed
77 78
    int margin() const;

Bryant's avatar
Bryant committed
79
    void setSpacing( int td );
pixhawk's avatar
pixhawk committed
80 81
    int spacing() const;

Bryant's avatar
Bryant committed
82 83
    void setScaleDiv( const QwtScaleDiv &sd );
    void setTransformation( QwtTransform * );
pixhawk's avatar
pixhawk committed
84

Bryant's avatar
Bryant committed
85
    void setScaleDraw( QwtScaleDraw * );
pixhawk's avatar
pixhawk committed
86 87 88
    const QwtScaleDraw *scaleDraw() const;
    QwtScaleDraw *scaleDraw();

Bryant's avatar
Bryant committed
89 90
    void setLabelAlignment( Qt::Alignment );
    void setLabelRotation( double rotation );
pixhawk's avatar
pixhawk committed
91

Bryant's avatar
Bryant committed
92
    void setColorBarEnabled( bool );
pixhawk's avatar
pixhawk committed
93 94
    bool isColorBarEnabled() const;

Bryant's avatar
Bryant committed
95
    void setColorBarWidth( int );
pixhawk's avatar
pixhawk committed
96 97
    int colorBarWidth() const;

Bryant's avatar
Bryant committed
98
    void setColorMap( const QwtInterval &, QwtColorMap * );
pixhawk's avatar
pixhawk committed
99

Bryant's avatar
Bryant committed
100 101
    QwtInterval colorBarInterval() const;
    const QwtColorMap *colorMap() const;
pixhawk's avatar
pixhawk committed
102 103 104 105

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

Bryant's avatar
Bryant committed
106 107
    int titleHeightForWidth( int width ) const;
    int dimForLength( int length, const QFont &scaleFont ) const;
pixhawk's avatar
pixhawk committed
108

Bryant's avatar
Bryant committed
109 110 111
    void drawColorBar( QPainter *painter, const QRectF & ) const;
    void drawTitle( QPainter *painter, QwtScaleDraw::Alignment,
        const QRectF &rect ) const;
112

Bryant's avatar
Bryant committed
113
    void setAlignment( QwtScaleDraw::Alignment );
pixhawk's avatar
pixhawk committed
114 115
    QwtScaleDraw::Alignment alignment() const;

Bryant's avatar
Bryant committed
116
    QRectF colorBarRect( const QRectF& ) const;
pixhawk's avatar
pixhawk committed
117 118

protected:
Bryant's avatar
Bryant committed
119 120
    virtual void paintEvent( QPaintEvent * );
    virtual void resizeEvent( QResizeEvent * );
pixhawk's avatar
pixhawk committed
121

Bryant's avatar
Bryant committed
122
    void draw( QPainter *p ) const;
pixhawk's avatar
pixhawk committed
123 124 125 126 127

    void scaleChange();
    void layoutScale( bool update = true );

private:
Bryant's avatar
Bryant committed
128
    void initScale( QwtScaleDraw::Alignment );
pixhawk's avatar
pixhawk committed
129 130 131 132 133

    class PrivateData;
    PrivateData *d_data;
};

Bryant's avatar
Bryant committed
134 135
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtScaleWidget::LayoutFlags )

pixhawk's avatar
pixhawk committed
136
#endif