QtPdWidgets  2.3.1
Scale.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2009 Florian Pose <fp@igh-essen.com>
4  *
5  * This file is part of the QtPdWidgets library.
6  *
7  * The QtPdWidgets library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation, either version 3 of the License,
10  * or (at your option) any later version.
11  *
12  * The QtPdWidgets library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with the QtPdWidgets Library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  ****************************************************************************/
22 
23 #ifndef PD_SCALE_H
24 #define PD_SCALE_H
25 
26 #include <QRect>
27 #include <QWidget>
28 
29 namespace Pd {
30 
31 /****************************************************************************/
32 
35 class Scale
36 {
37  public:
40  enum Orientation {
43  };
44 
45  Scale(QWidget *, Orientation = Vertical);
46 
49  double getMin() const;
50  void setMin(double);
51  double getMax() const;
52  void setMax(double);
53  int getLength() const;
54  void setLength(int);
55  const QString &getSuffix() const;
56  void setSuffix(const QString&);
57  void resetSuffix();
58 
59  void update();
60 
61  double range() const;
62  int getOuterLength() const;
63 
64  void draw(QPainter &, const QRect &, const QColor &, int = 0) const;
65 
66  private:
67  const QWidget * const parent;
69  double min;
70  double max;
71  int length;
72  QString suffix;
75  double majorStep;
76  unsigned int minorDiv;
77  int decade;
79  Scale();
80  QString formatValue(double) const;
81 };
82 
83 /****************************************************************************/
84 
89 {
90  return orientation;
91 }
92 
93 /****************************************************************************/
94 
98 inline double Scale::getMin() const
99 {
100  return min;
101 }
102 
103 /****************************************************************************/
104 
108 inline double Scale::getMax() const
109 {
110  return max;
111 }
112 
113 /****************************************************************************/
114 
118 inline int Scale::getLength() const
119 {
120  return length;
121 }
122 
123 /****************************************************************************/
124 
128 inline const QString &Scale::getSuffix() const
129 {
130  return suffix;
131 }
132 
133 /****************************************************************************/
134 
138 inline double Scale::range() const
139 {
140  return max - min;
141 }
142 
143 /****************************************************************************/
144 
148 inline int Scale::getOuterLength() const
149 {
150  return outerLength;
151 }
152 
153 /****************************************************************************/
154 
155 } // namespace Pd
156 
157 #endif
double getMin() const
Definition: Scale.h:98
double min
Minimum value.
Definition: Scale.h:69
Scale is oriented horizontally.
Definition: Scale.h:42
Definition: Bar.h:36
void setMin(double)
Sets the scale value minimum (min).
Definition: Scale.cpp:77
double max
Maximum value.
Definition: Scale.h:70
const QWidget *const parent
Parent widget.
Definition: Scale.h:67
Scale.
Definition: Scale.h:35
QString suffix
Suffix to display after each value step.
Definition: Scale.h:72
Scale is oriented vertically.
Definition: Scale.h:41
void update()
Calculates the scale&#39;s layout.
Definition: Scale.cpp:140
double majorStep
The major division (long ticks).
Definition: Scale.h:75
Orientation getOrientation() const
Definition: Scale.h:88
unsigned int minorDiv
The minor division (short ticks).
Definition: Scale.h:76
int getOuterLength() const
Definition: Scale.h:148
double getMax() const
Definition: Scale.h:108
QString formatValue(double) const
Formats a numeric value.
Definition: Scale.cpp:336
void setMax(double)
Sets the scale value maximum (max).
Definition: Scale.cpp:91
void resetSuffix()
Resets the suffix to display after each value step.
Definition: Scale.cpp:131
int outerLength
Space for the numbering in pixel.
Definition: Scale.h:74
void setLength(int)
Sets the scale length in pixel.
Definition: Scale.cpp:105
int decade
Decimal power.
Definition: Scale.h:77
int getLength() const
Definition: Scale.h:118
Orientation orientation
Orientation.
Definition: Scale.h:68
int length
Scale length in pixel.
Definition: Scale.h:71
const QString & getSuffix() const
Definition: Scale.h:128
void draw(QPainter &, const QRect &, const QColor &, int=0) const
Draws the scale into the given QRect with the given QPainter.
Definition: Scale.cpp:209
double range() const
Definition: Scale.h:138
Orientation
Scale orientation.
Definition: Scale.h:40
void setSuffix(const QString &)
Sets the suffix to display after each value step.
Definition: Scale.cpp:118
void setOrientation(Orientation)
Sets the orientation.
Definition: Scale.cpp:63