qwt_scale_draw.h 3.09 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
 * 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_DRAW_H
#define QWT_SCALE_DRAW_H

#include "qwt_global.h"
#include "qwt_abstract_scale_draw.h"
Bryant's avatar
Bryant committed
15
16
17
#include <qpoint.h>
#include <qrect.h>
#include <qtransform.h>
pixhawk's avatar
pixhawk committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

/*!
  \brief A class for drawing scales

  QwtScaleDraw can be used to draw linear or logarithmic scales.
  A scale has a position, an alignment and a length, which can be specified .
  The labels can be rotated and aligned
  to the ticks using setLabelRotation() and setLabelAlignment().

  After a scale division has been specified as a QwtScaleDiv object
  using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s),
  the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
*/
class QWT_EXPORT QwtScaleDraw: public QwtAbstractScaleDraw
{
public:
34
    /*!
pixhawk's avatar
pixhawk committed
35
36
37
        Alignment of the scale draw
        \sa setAlignment(), alignment()
     */
Bryant's avatar
Bryant committed
38
39
40
41
    enum Alignment 
    { 
        //! The scale is below
        BottomScale, 
pixhawk's avatar
pixhawk committed
42

Bryant's avatar
Bryant committed
43
44
        //! The scale is above
        TopScale, 
pixhawk's avatar
pixhawk committed
45

Bryant's avatar
Bryant committed
46
47
48
49
50
51
        //! The scale is left
        LeftScale, 

        //! The scale is right
        RightScale 
    };
pixhawk's avatar
pixhawk committed
52

Bryant's avatar
Bryant committed
53
54
    QwtScaleDraw();
    virtual ~QwtScaleDraw();
pixhawk's avatar
pixhawk committed
55

Bryant's avatar
Bryant committed
56
57
    void getBorderDistHint( const QFont &, int &start, int &end ) const;
    int minLabelDist( const QFont & ) const;
pixhawk's avatar
pixhawk committed
58

Bryant's avatar
Bryant committed
59
60
    int minLength( const QFont & ) const;
    virtual double extent( const QFont & ) const;
pixhawk's avatar
pixhawk committed
61

Bryant's avatar
Bryant committed
62
63
64
    void move( double x, double y );
    void move( const QPointF & );
    void setLength( double length );
pixhawk's avatar
pixhawk committed
65
66

    Alignment alignment() const;
Bryant's avatar
Bryant committed
67
    void setAlignment( Alignment );
pixhawk's avatar
pixhawk committed
68
69
70

    Qt::Orientation orientation() const;

Bryant's avatar
Bryant committed
71
72
    QPointF pos() const;
    double length() const;
pixhawk's avatar
pixhawk committed
73

Bryant's avatar
Bryant committed
74
    void setLabelAlignment( Qt::Alignment );
pixhawk's avatar
pixhawk committed
75
76
    Qt::Alignment labelAlignment() const;

Bryant's avatar
Bryant committed
77
    void setLabelRotation( double rotation );
pixhawk's avatar
pixhawk committed
78
79
    double labelRotation() const;

Bryant's avatar
Bryant committed
80
81
    int maxLabelHeight( const QFont & ) const;
    int maxLabelWidth( const QFont & ) const;
pixhawk's avatar
pixhawk committed
82

Bryant's avatar
Bryant committed
83
    QPointF labelPosition( double val ) const;
pixhawk's avatar
pixhawk committed
84

Bryant's avatar
Bryant committed
85
86
    QRectF labelRect( const QFont &, double val ) const;
    QSizeF labelSize( const QFont &, double val ) const;
pixhawk's avatar
pixhawk committed
87

Bryant's avatar
Bryant committed
88
    QRect boundingLabelRect( const QFont &, double val ) const;
pixhawk's avatar
pixhawk committed
89
90

protected:
Bryant's avatar
Bryant committed
91
    QTransform labelTransformation( const QPointF &, const QSizeF & ) const;
pixhawk's avatar
pixhawk committed
92

Bryant's avatar
Bryant committed
93
94
95
    virtual void drawTick( QPainter *, double val, double len ) const;
    virtual void drawBackbone( QPainter * ) const;
    virtual void drawLabel( QPainter *, double val ) const;
pixhawk's avatar
pixhawk committed
96
97

private:
Bryant's avatar
Bryant committed
98
99
100
    QwtScaleDraw( const QwtScaleDraw & );
    QwtScaleDraw &operator=( const QwtScaleDraw &other );

pixhawk's avatar
pixhawk committed
101
102
103
104
105
106
    void updateMap();

    class PrivateData;
    PrivateData *d_data;
};

Bryant's avatar
Bryant committed
107
108
109
110
111
112
113
114
115
/*!
   Move the position of the scale

   \param x X coordinate
   \param y Y coordinate

   \sa move(const QPointF &)
*/
inline void QwtScaleDraw::move( double x, double y )
pixhawk's avatar
pixhawk committed
116
{
Bryant's avatar
Bryant committed
117
    move( QPointF( x, y ) );
pixhawk's avatar
pixhawk committed
118
119
120
}

#endif