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_PLOT_RESCALER_H
|
---|
11 | #define QWT_PLOT_RESCALER_H 1
|
---|
12 |
|
---|
13 | #include "qwt_global.h"
|
---|
14 | #include "qwt_double_rect.h"
|
---|
15 | #include "qwt_double_interval.h"
|
---|
16 | #include "qwt_plot.h"
|
---|
17 | #include <qobject.h>
|
---|
18 |
|
---|
19 | class QwtPlotCanvas;
|
---|
20 | class QResizeEvent;
|
---|
21 |
|
---|
22 | /*!
|
---|
23 | \brief QwtPlotRescaler takes care of fixed aspect ratios for plot scales
|
---|
24 |
|
---|
25 | QwtPlotRescaler autoadjusts the axes of a QwtPlot according
|
---|
26 | to fixed aspect ratios.
|
---|
27 | */
|
---|
28 |
|
---|
29 | class QWT_EXPORT QwtPlotRescaler: public QObject
|
---|
30 | {
|
---|
31 | public:
|
---|
32 | /*!
|
---|
33 | \brief Rescale Policy
|
---|
34 |
|
---|
35 | The rescale policy defines how to rescale the reference axis and
|
---|
36 | their depending axes.
|
---|
37 |
|
---|
38 | - Fixed
|
---|
39 |
|
---|
40 | The interval of the reference axis remains unchanged, when the
|
---|
41 | geometry of the canvas changes. All other axes
|
---|
42 | will be adjusted according to their aspect ratio.
|
---|
43 |
|
---|
44 | - Expanding
|
---|
45 |
|
---|
46 | The interval of the reference axis will be shrinked/expanded,
|
---|
47 | when the geometry of the canvas changes. All other axes
|
---|
48 | will be adjusted according to their aspect ratio.
|
---|
49 |
|
---|
50 | The interval, that is represented by one pixel is fixed.
|
---|
51 |
|
---|
52 | - Fitting
|
---|
53 |
|
---|
54 | The intervals of the axes are calculated, so that all axes include
|
---|
55 | their minimal interval.
|
---|
56 | */
|
---|
57 |
|
---|
58 | enum RescalePolicy
|
---|
59 | {
|
---|
60 | Fixed,
|
---|
61 | Expanding,
|
---|
62 | Fitting
|
---|
63 | };
|
---|
64 |
|
---|
65 | enum ExpandingDirection
|
---|
66 | {
|
---|
67 | ExpandUp,
|
---|
68 | ExpandDown,
|
---|
69 | ExpandBoth
|
---|
70 | };
|
---|
71 |
|
---|
72 | explicit QwtPlotRescaler(QwtPlotCanvas *,
|
---|
73 | int referenceAxis = QwtPlot::xBottom,
|
---|
74 | RescalePolicy = Expanding );
|
---|
75 |
|
---|
76 | virtual ~QwtPlotRescaler();
|
---|
77 |
|
---|
78 | void setEnabled(bool);
|
---|
79 | bool isEnabled() const;
|
---|
80 |
|
---|
81 | void setRescalePolicy(RescalePolicy);
|
---|
82 | RescalePolicy rescalePolicy() const;
|
---|
83 |
|
---|
84 | void setExpandingDirection(ExpandingDirection);
|
---|
85 | void setExpandingDirection(int axis, ExpandingDirection);
|
---|
86 | ExpandingDirection expandingDirection(int axis) const;
|
---|
87 |
|
---|
88 | void setReferenceAxis(int axis);
|
---|
89 | int referenceAxis() const;
|
---|
90 |
|
---|
91 | void setAspectRatio(double ratio);
|
---|
92 | void setAspectRatio(int axis, double ratio);
|
---|
93 | double aspectRatio(int axis) const;
|
---|
94 |
|
---|
95 | void setIntervalHint(int axis, const QwtDoubleInterval&);
|
---|
96 | QwtDoubleInterval intervalHint(int axis) const;
|
---|
97 |
|
---|
98 | QwtPlotCanvas *canvas();
|
---|
99 | const QwtPlotCanvas *canvas() const;
|
---|
100 |
|
---|
101 | QwtPlot *plot();
|
---|
102 | const QwtPlot *plot() const;
|
---|
103 |
|
---|
104 | virtual bool eventFilter(QObject *, QEvent *);
|
---|
105 |
|
---|
106 | void rescale() const;
|
---|
107 |
|
---|
108 | protected:
|
---|
109 | virtual void canvasResizeEvent(QResizeEvent *);
|
---|
110 |
|
---|
111 | virtual void rescale(const QSize &oldSize, const QSize &newSize) const;
|
---|
112 | virtual QwtDoubleInterval expandScale( int axis,
|
---|
113 | const QSize &oldSize, const QSize &newSize) const;
|
---|
114 |
|
---|
115 | virtual QwtDoubleInterval syncScale(
|
---|
116 | int axis, const QwtDoubleInterval& reference,
|
---|
117 | const QSize &size) const;
|
---|
118 |
|
---|
119 | virtual void updateScales(
|
---|
120 | QwtDoubleInterval intervals[QwtPlot::axisCnt]) const;
|
---|
121 |
|
---|
122 | Qt::Orientation orientation(int axis) const;
|
---|
123 | QwtDoubleInterval interval(int axis) const;
|
---|
124 | QwtDoubleInterval expandInterval(const QwtDoubleInterval &,
|
---|
125 | double width, ExpandingDirection) const;
|
---|
126 |
|
---|
127 | private:
|
---|
128 | double pixelDist(int axis, const QSize &) const;
|
---|
129 |
|
---|
130 | class AxisData;
|
---|
131 | class PrivateData;
|
---|
132 | PrivateData *d_data;
|
---|
133 | };
|
---|
134 |
|
---|
135 | #endif
|
---|