qwt_thermo.h 4.59 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* -*- 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_THERMO_H
#define QWT_THERMO_H

#include "qwt_global.h"
#include "qwt_abstract_scale.h"
Bryant's avatar
Bryant committed
15
#include "qwt_interval.h"
pixhawk's avatar
pixhawk committed
16 17

class QwtScaleDraw;
Bryant's avatar
Bryant committed
18
class QwtColorMap;
pixhawk's avatar
pixhawk committed
19 20 21 22 23 24 25 26 27 28 29 30

/*!
  \brief The Thermometer Widget

  QwtThermo is a widget which displays a value in an interval. It supports:
  - a horizontal or vertical layout;
  - a range;
  - a scale;
  - an alarm level.

  \image html sysinfo.png

Bryant's avatar
Bryant committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44
  The fill colors might be calculated from an optional color map
  If no color map has been assigned QwtThermo uses the 
  following colors/brushes from the widget palette:

  - QPalette::Base
    Background of the pipe
  - QPalette::ButtonText
    Fill brush below the alarm level
  - QPalette::Highlight
    Fill brush for the values above the alarm level
  - QPalette::WindowText
    For the axis of the scale
  - QPalette::Text
    For the labels of the scale
pixhawk's avatar
pixhawk committed
45
*/
Bryant's avatar
Bryant committed
46
class QWT_EXPORT QwtThermo: public QwtAbstractScale
pixhawk's avatar
pixhawk committed
47 48 49
{
    Q_OBJECT

Bryant's avatar
Bryant committed
50 51 52 53 54 55 56 57
    Q_ENUMS( ScalePosition )
    Q_ENUMS( OriginMode )

    Q_PROPERTY( Qt::Orientation orientation
        READ orientation WRITE setOrientation )
    Q_PROPERTY( ScalePosition scalePosition 
        READ scalePosition WRITE setScalePosition )
    Q_PROPERTY( OriginMode originMode READ originMode WRITE setOriginMode )
pixhawk's avatar
pixhawk committed
58 59 60

    Q_PROPERTY( bool alarmEnabled READ alarmEnabled WRITE setAlarmEnabled )
    Q_PROPERTY( double alarmLevel READ alarmLevel WRITE setAlarmLevel )
Bryant's avatar
Bryant committed
61 62
    Q_PROPERTY( double origin READ origin WRITE setOrigin )
    Q_PROPERTY( int spacing READ spacing WRITE setSpacing )
pixhawk's avatar
pixhawk committed
63 64 65 66 67
    Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
    Q_PROPERTY( int pipeWidth READ pipeWidth WRITE setPipeWidth )
    Q_PROPERTY( double value READ value WRITE setValue )

public:
68

Bryant's avatar
Bryant committed
69 70 71 72 73 74 75
    /*!
      Position of the scale
      \sa setScalePosition(), setOrientation()
     */
    enum ScalePosition
    {
        //! The slider has no scale
76
        NoScale,
Bryant's avatar
Bryant committed
77 78 79 80 81 82

        //! The scale is right of a vertical or below of a horizontal slider
        LeadingScale,

        //! The scale is left of a vertical or above of a horizontal slider
        TrailingScale
pixhawk's avatar
pixhawk committed
83 84
    };

Bryant's avatar
Bryant committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    /*!
      Origin mode. This property specifies where the beginning of the liquid
      is placed.

      \sa setOriginMode(), setOrigin()
    */
    enum OriginMode
    {
        //! The origin is the minimum of the scale
        OriginMinimum,

        //! The origin is the maximum of the scale
        OriginMaximum,

        //! The origin is specified using the origin() property
        OriginCustom
    };

    explicit QwtThermo( QWidget *parent = NULL );
pixhawk's avatar
pixhawk committed
104 105
    virtual ~QwtThermo();

Bryant's avatar
Bryant committed
106 107
    void setOrientation( Qt::Orientation );
    Qt::Orientation orientation() const;
pixhawk's avatar
pixhawk committed
108

Bryant's avatar
Bryant committed
109 110
    void setScalePosition( ScalePosition );
    ScalePosition scalePosition() const;
pixhawk's avatar
pixhawk committed
111

Bryant's avatar
Bryant committed
112 113 114 115
    void setSpacing( int );
    int spacing() const;

    void setBorderWidth( int w );
pixhawk's avatar
pixhawk committed
116 117
    int borderWidth() const;

Bryant's avatar
Bryant committed
118 119
    void setOriginMode( OriginMode );
    OriginMode originMode() const;
pixhawk's avatar
pixhawk committed
120

Bryant's avatar
Bryant committed
121 122
    void setOrigin( double );
    double origin() const;
123

Bryant's avatar
Bryant committed
124 125
    void setFillBrush( const QBrush &b );
    QBrush fillBrush() const;
pixhawk's avatar
pixhawk committed
126

Bryant's avatar
Bryant committed
127 128
    void setAlarmBrush( const QBrush &b );
    QBrush alarmBrush() const;
pixhawk's avatar
pixhawk committed
129

Bryant's avatar
Bryant committed
130
    void setAlarmLevel( double v );
pixhawk's avatar
pixhawk committed
131 132
    double alarmLevel() const;

Bryant's avatar
Bryant committed
133
    void setAlarmEnabled( bool tf );
pixhawk's avatar
pixhawk committed
134 135
    bool alarmEnabled() const;

Bryant's avatar
Bryant committed
136 137 138
    void setColorMap( QwtColorMap * );
    QwtColorMap *colorMap();
    const QwtColorMap *colorMap() const;
pixhawk's avatar
pixhawk committed
139

Bryant's avatar
Bryant committed
140 141
    void setPipeWidth( int w );
    int pipeWidth() const;
pixhawk's avatar
pixhawk committed
142

Bryant's avatar
Bryant committed
143 144
    void setRangeFlags( QwtInterval::BorderFlags );
    QwtInterval::BorderFlags rangeFlags() const;
pixhawk's avatar
pixhawk committed
145 146 147 148 149 150

    double value() const;

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

Bryant's avatar
Bryant committed
151
    void setScaleDraw( QwtScaleDraw * );
pixhawk's avatar
pixhawk committed
152 153
    const QwtScaleDraw *scaleDraw() const;

Bryant's avatar
Bryant committed
154 155
public Q_SLOTS:
    virtual void setValue( double val );
156

pixhawk's avatar
pixhawk committed
157
protected:
Bryant's avatar
Bryant committed
158
    virtual void drawLiquid( QPainter *, const QRect & ) const;
pixhawk's avatar
pixhawk committed
159 160
    virtual void scaleChange();

Bryant's avatar
Bryant committed
161 162 163
    virtual void paintEvent( QPaintEvent * );
    virtual void resizeEvent( QResizeEvent * );
    virtual void changeEvent( QEvent * );
pixhawk's avatar
pixhawk committed
164 165 166

    QwtScaleDraw *scaleDraw();

Bryant's avatar
Bryant committed
167 168 169 170
    QRect pipeRect() const;
    QRect fillRect( const QRect & ) const;
    QRect alarmRect( const QRect & ) const;

pixhawk's avatar
pixhawk committed
171
private:
Bryant's avatar
Bryant committed
172
    void layoutThermo( bool );
173

pixhawk's avatar
pixhawk committed
174 175 176 177 178
    class PrivateData;
    PrivateData *d_data;
};

#endif