qwt_abstract_scale_draw.h 3.53 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * 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_ABSTRACT_SCALE_DRAW_H
#define QWT_ABSTRACT_SCALE_DRAW_H

#include "qwt_global.h"
#include "qwt_scale_div.h"
#include "qwt_text.h"

class QPalette;
class QPainter;
class QFont;
Bryant's avatar
Bryant committed
20
class QwtTransform;
pixhawk's avatar
pixhawk committed
21 22 23 24 25 26 27 28
class QwtScaleMap;

/*!
  \brief A abstract base class for drawing scales

  QwtAbstractScaleDraw can be used to draw linear or logarithmic scales.

  After a scale division has been specified as a QwtScaleDiv object
Bryant's avatar
Bryant committed
29
  using setScaleDiv(), the scale can be drawn with the draw() member.
pixhawk's avatar
pixhawk committed
30 31 32 33 34
*/
class QWT_EXPORT QwtAbstractScaleDraw
{
public:

35 36
    /*!
       Components of a scale
Bryant's avatar
Bryant committed
37 38 39 40 41 42
       \sa enableComponent(), hasComponent
    */
    enum ScaleComponent
    {
        //! Backbone = the line where the ticks are located
        Backbone = 0x01,
pixhawk's avatar
pixhawk committed
43

Bryant's avatar
Bryant committed
44 45
        //! Ticks
        Ticks = 0x02,
pixhawk's avatar
pixhawk committed
46

Bryant's avatar
Bryant committed
47 48
        //! Labels
        Labels = 0x04
pixhawk's avatar
pixhawk committed
49
    };
50

Bryant's avatar
Bryant committed
51 52 53
    //! Scale components
    typedef QFlags<ScaleComponent> ScaleComponents;

pixhawk's avatar
pixhawk committed
54 55 56
    QwtAbstractScaleDraw();
    virtual ~QwtAbstractScaleDraw();

Bryant's avatar
Bryant committed
57
    void setScaleDiv( const QwtScaleDiv &s );
pixhawk's avatar
pixhawk committed
58 59
    const QwtScaleDiv& scaleDiv() const;

Bryant's avatar
Bryant committed
60 61 62
    void setTransformation( QwtTransform * );
    const QwtScaleMap &scaleMap() const;
    QwtScaleMap &scaleMap();
pixhawk's avatar
pixhawk committed
63

Bryant's avatar
Bryant committed
64 65
    void enableComponent( ScaleComponent, bool enable = true );
    bool hasComponent( ScaleComponent ) const;
pixhawk's avatar
pixhawk committed
66

Bryant's avatar
Bryant committed
67 68 69
    void setTickLength( QwtScaleDiv::TickType, double length );
    double tickLength( QwtScaleDiv::TickType ) const;
    double maxTickLength() const;
pixhawk's avatar
pixhawk committed
70

Bryant's avatar
Bryant committed
71 72
    void setSpacing( double margin );
    double spacing() const;
73

Bryant's avatar
Bryant committed
74 75 76 77
    void setPenWidth( int width );
    int penWidth() const;

    virtual void draw( QPainter *, const QPalette & ) const;
pixhawk's avatar
pixhawk committed
78

Bryant's avatar
Bryant committed
79
    virtual QwtText label( double ) const;
pixhawk's avatar
pixhawk committed
80

81 82
    /*!
      Calculate the extent
pixhawk's avatar
pixhawk committed
83

Bryant's avatar
Bryant committed
84
      The extent is the distance from the baseline to the outermost
pixhawk's avatar
pixhawk committed
85 86
      pixel of the scale draw in opposite to its orientation.
      It is at least minimumExtent() pixels.
87

Bryant's avatar
Bryant committed
88 89 90
      \param font Font used for drawing the tick labels
      \return Number of pixels

pixhawk's avatar
pixhawk committed
91 92
      \sa setMinimumExtent(), minimumExtent()
    */
Bryant's avatar
Bryant committed
93
    virtual double extent( const QFont &font ) const = 0;
pixhawk's avatar
pixhawk committed
94

Bryant's avatar
Bryant committed
95 96
    void setMinimumExtent( double );
    double minimumExtent() const;
pixhawk's avatar
pixhawk committed
97 98 99 100

protected:
    /*!
       Draw a tick
101

pixhawk's avatar
pixhawk committed
102 103
       \param painter Painter
       \param value Value of the tick
Bryant's avatar
Bryant committed
104
       \param len Length of the tick
pixhawk's avatar
pixhawk committed
105 106

       \sa drawBackbone(), drawLabel()
107
    */
Bryant's avatar
Bryant committed
108
    virtual void drawTick( QPainter *painter, double value, double len ) const = 0;
pixhawk's avatar
pixhawk committed
109 110 111 112 113 114 115

    /*!
      Draws the baseline of the scale
      \param painter Painter

      \sa drawTick(), drawLabel()
    */
Bryant's avatar
Bryant committed
116
    virtual void drawBackbone( QPainter *painter ) const = 0;
pixhawk's avatar
pixhawk committed
117

118
    /*!
pixhawk's avatar
pixhawk committed
119
        Draws the label for a major scale tick
120

pixhawk's avatar
pixhawk committed
121 122 123
        \param painter Painter
        \param value Value

Bryant's avatar
Bryant committed
124
        \sa drawTick(), drawBackbone()
125
    */
Bryant's avatar
Bryant committed
126
    virtual void drawLabel( QPainter *painter, double value ) const = 0;
pixhawk's avatar
pixhawk committed
127 128

    void invalidateCache();
Bryant's avatar
Bryant committed
129
    const QwtText &tickLabel( const QFont &, double value ) const;
pixhawk's avatar
pixhawk committed
130 131

private:
Bryant's avatar
Bryant committed
132 133
    QwtAbstractScaleDraw( const QwtAbstractScaleDraw & );
    QwtAbstractScaleDraw &operator=( const QwtAbstractScaleDraw & );
pixhawk's avatar
pixhawk committed
134 135 136 137 138

    class PrivateData;
    PrivateData *d_data;
};

Bryant's avatar
Bryant committed
139 140
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtAbstractScaleDraw::ScaleComponents )

pixhawk's avatar
pixhawk committed
141
#endif