[89] | 1 | /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
---|
| 2 | * Qwt Widget Library
|
---|
| 3 | * Copyright (C) 1997 Josef Wilgen
|
---|
| 4 | * Copyright (C) 2002 Uwe Rathmann
|
---|
| 5 | *
|
---|
| 6 | * This library is free software; you can redistribute it and/or
|
---|
| 7 | * modify it under the terms of the Qwt License, Version 1.0
|
---|
| 8 | *****************************************************************************/
|
---|
| 9 |
|
---|
| 10 | #ifndef QWT_ABSTRACT_SCALE_DRAW_H
|
---|
| 11 | #define QWT_ABSTRACT_SCALE_DRAW_H
|
---|
| 12 |
|
---|
| 13 | #include "qwt_global.h"
|
---|
| 14 | #include "qwt_scale_div.h"
|
---|
| 15 | #include "qwt_text.h"
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | #if QT_VERSION < 0x040000
|
---|
| 19 | class QColorGroup;
|
---|
| 20 | #else
|
---|
| 21 | class QPalette;
|
---|
| 22 | #endif
|
---|
| 23 | class QPainter;
|
---|
| 24 | class QFont;
|
---|
| 25 | class QwtScaleTransformation;
|
---|
| 26 | class QwtScaleMap;
|
---|
| 27 |
|
---|
| 28 | /*!
|
---|
| 29 | \brief A abstract base class for drawing scales
|
---|
| 30 |
|
---|
| 31 | QwtAbstractScaleDraw can be used to draw linear or logarithmic scales.
|
---|
| 32 |
|
---|
| 33 | After a scale division has been specified as a QwtScaleDiv object
|
---|
| 34 | using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s),
|
---|
| 35 | the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
|
---|
| 36 | */
|
---|
| 37 | class QWT_EXPORT QwtAbstractScaleDraw
|
---|
| 38 | {
|
---|
| 39 | public:
|
---|
| 40 |
|
---|
| 41 | /*!
|
---|
| 42 | Components of a scale
|
---|
| 43 |
|
---|
| 44 | - Backbone
|
---|
| 45 | - Ticks
|
---|
| 46 | - Labels
|
---|
| 47 |
|
---|
| 48 | \sa enableComponent(), hasComponent
|
---|
| 49 | */
|
---|
| 50 |
|
---|
| 51 | enum ScaleComponent
|
---|
| 52 | {
|
---|
| 53 | Backbone = 1,
|
---|
| 54 | Ticks = 2,
|
---|
| 55 | Labels = 4
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | QwtAbstractScaleDraw();
|
---|
| 59 | QwtAbstractScaleDraw( const QwtAbstractScaleDraw & );
|
---|
| 60 | virtual ~QwtAbstractScaleDraw();
|
---|
| 61 |
|
---|
| 62 | QwtAbstractScaleDraw &operator=(const QwtAbstractScaleDraw &);
|
---|
| 63 |
|
---|
| 64 | void setScaleDiv(const QwtScaleDiv &s);
|
---|
| 65 | const QwtScaleDiv& scaleDiv() const;
|
---|
| 66 |
|
---|
| 67 | void setTransformation(QwtScaleTransformation *);
|
---|
| 68 | const QwtScaleMap &map() const;
|
---|
| 69 |
|
---|
| 70 | void enableComponent(ScaleComponent, bool enable = true);
|
---|
| 71 | bool hasComponent(ScaleComponent) const;
|
---|
| 72 |
|
---|
| 73 | void setTickLength(QwtScaleDiv::TickType, int length);
|
---|
| 74 | int tickLength(QwtScaleDiv::TickType) const;
|
---|
| 75 | int majTickLength() const;
|
---|
| 76 |
|
---|
| 77 | void setSpacing(int margin);
|
---|
| 78 | int spacing() const;
|
---|
| 79 |
|
---|
| 80 | #if QT_VERSION < 0x040000
|
---|
| 81 | virtual void draw(QPainter *, const QColorGroup &) const;
|
---|
| 82 | #else
|
---|
| 83 | virtual void draw(QPainter *, const QPalette &) const;
|
---|
| 84 | #endif
|
---|
| 85 |
|
---|
| 86 | virtual QwtText label(double) const;
|
---|
| 87 |
|
---|
| 88 | /*!
|
---|
| 89 | Calculate the extent
|
---|
| 90 |
|
---|
| 91 | The extent is the distcance from the baseline to the outermost
|
---|
| 92 | pixel of the scale draw in opposite to its orientation.
|
---|
| 93 | It is at least minimumExtent() pixels.
|
---|
| 94 |
|
---|
| 95 | \sa setMinimumExtent(), minimumExtent()
|
---|
| 96 | */
|
---|
| 97 | virtual int extent(const QPen &, const QFont &) const = 0;
|
---|
| 98 |
|
---|
| 99 | void setMinimumExtent(int);
|
---|
| 100 | int minimumExtent() const;
|
---|
| 101 |
|
---|
| 102 | QwtScaleMap &scaleMap();
|
---|
| 103 |
|
---|
| 104 | protected:
|
---|
| 105 | /*!
|
---|
| 106 | Draw a tick
|
---|
| 107 |
|
---|
| 108 | \param painter Painter
|
---|
| 109 | \param value Value of the tick
|
---|
| 110 | \param len Lenght of the tick
|
---|
| 111 |
|
---|
| 112 | \sa drawBackbone(), drawLabel()
|
---|
| 113 | */
|
---|
| 114 | virtual void drawTick(QPainter *painter, double value, int len) const = 0;
|
---|
| 115 |
|
---|
| 116 | /*!
|
---|
| 117 | Draws the baseline of the scale
|
---|
| 118 | \param painter Painter
|
---|
| 119 |
|
---|
| 120 | \sa drawTick(), drawLabel()
|
---|
| 121 | */
|
---|
| 122 | virtual void drawBackbone(QPainter *painter) const = 0;
|
---|
| 123 |
|
---|
| 124 | /*!
|
---|
| 125 | Draws the label for a major scale tick
|
---|
| 126 |
|
---|
| 127 | \param painter Painter
|
---|
| 128 | \param value Value
|
---|
| 129 |
|
---|
| 130 | \sa drawTick, drawBackbone
|
---|
| 131 | */
|
---|
| 132 | virtual void drawLabel(QPainter *painter, double value) const = 0;
|
---|
| 133 |
|
---|
| 134 | void invalidateCache();
|
---|
| 135 | const QwtText &tickLabel(const QFont &, double value) const;
|
---|
| 136 |
|
---|
| 137 | private:
|
---|
| 138 | int operator==(const QwtAbstractScaleDraw &) const;
|
---|
| 139 | int operator!=(const QwtAbstractScaleDraw &) const;
|
---|
| 140 |
|
---|
| 141 | class PrivateData;
|
---|
| 142 | PrivateData *d_data;
|
---|
| 143 | };
|
---|
| 144 |
|
---|
| 145 | #endif
|
---|