Stellarium 0.15.2
AngleSpinBox.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2008 Matthew Gates
4  * Copyright (C) 2015 Georg Zotti (min/max limits)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
19  */
20 
21 #ifndef _ANGLESPINBOX_HPP_
22 #define _ANGLESPINBOX_HPP_
23 
24 #include <QAbstractSpinBox>
25 #include <QString>
26 #include <cmath>
27 
34 class AngleSpinBox : public QAbstractSpinBox
35 {
36  Q_OBJECT
37 
38 public:
42  {
50  };
51 
55  {
60  Unknown
61  };
62 
63  AngleSpinBox(QWidget* parent=0, DisplayFormat format=DMSSymbols, PrefixType prefix=Normal);
64  ~AngleSpinBox();
65 
66  // QAbstractSpinBox virtual members
67  virtual void stepBy(int steps);
68  virtual QValidator::State validate(QString& input, int& pos) const;
69 
72  double valueRadians();
75  double valueDegrees();
76 
79  void setDecimals(int places) { decimalPlaces = places; }
80 
83  int decimals() { return decimalPlaces; }
84 
87  void setDisplayFormat(DisplayFormat format) { angleSpinBoxFormat=format; formatText(); }
88 
91  DisplayFormat displayFormat() { return angleSpinBoxFormat; }
92 
95  void setPrefixType(PrefixType prefix) { currentPrefixType=prefix; formatText(); }
96 
99  PrefixType prefixType() { return currentPrefixType; }
100 
104  void setMinimum(const double min, const bool isDegrees=false) {minRad = min * (isDegrees? M_PI/180.0 : 1.); }
108  double getMinimum(const bool isDegrees) { return minRad * (isDegrees ? 180.0/M_PI : 1.0); }
109 
113  void setMaximum(const double max, const bool isDegrees=false) {maxRad = max * (isDegrees? M_PI/180.0 : 1.); }
117  double getMaximum(const bool isDegrees) { return maxRad * (isDegrees ? 180.0/M_PI : 1.0); }
118 
119 
120 public slots:
122  virtual void clear();
123 
126  void setRadians(double radians);
127 
130  void setDegrees(double degrees);
131 
132 signals:
134  void valueChanged();
135 
136 protected:
137  virtual StepEnabled stepEnabled() const;
138 
139 private slots:
141  void updateValue(void);
142 
143 private:
151  double stringToDouble(QString input, QValidator::State* state, PrefixType prefix=Unknown) const;
152 
154  enum AngleSpinboxSection
155  {
156  SectionPrefix,
157  SectionDegreesHours,
158  SectionMinutes,
159  SectionSeconds,
160  SectionNone
161  };
162 
164  AngleSpinboxSection getCurrentSection() const;
165 
169  void formatText(void);
170 
171  static const QString positivePrefix(PrefixType prefix);
172  static const QString negativePrefix(PrefixType prefix);
173 
174  DisplayFormat angleSpinBoxFormat;
175  PrefixType currentPrefixType;
176  int decimalPlaces;
177  double radAngle;
178  // min/max angles (radians), users should not be able to enter more/less.
179  // Use together with the wrapping() property!
180  double minRad;
181  double maxRad;
182 };
183 
184 #endif // _ANGLESPINBOX_HPP_
void valueChanged()
Emitted when the value changes.
Hours, minutes and seconds, e.g. 12h 4m 6s.
negative values have &#39;-&#39; prefix
void setDisplayFormat(DisplayFormat format)
Set the display format.
double valueRadians()
Get the angle held in the AngleSpinBox.
DisplayFormat
Used to decide how to display the angle.
Hours, minutes and seconds, e.g. 12h 4&#39; 6s".
double getMaximum(const bool isDegrees)
Get the maximum value.
double valueDegrees()
Get the angle held in the AngleSpinBox.
positive values have &#39;E&#39; prefix, negative values have &#39;W&#39; prefix.
virtual void clear()
Set the value to default 0 angle.
Degrees, minutes and seconds, e.g. 180d 4m 8s, with negative values, [-360..360d].
void setMinimum(const double min, const bool isDegrees=false)
Set the minimum value.
Degrees, minutes and seconds, e.g. 180° 4&#39; 8", [0..360°].
void setRadians(double radians)
Set the value of the spin box in radians.
Degrees, minutes and seconds, e.g. 180° 4&#39; 8", with negative values, [-360..360°].
A spin box for displaying/entering angular values.
void setDegrees(double degrees)
Set the value of the spin box in decimal degrees.
void setDecimals(int places)
Set the number of decimal places to express float values to (e.g.
positive values have &#39;+&#39; prefix, negative values have &#39;-&#39; prefix.
Degrees, minutes and seconds, e.g. 180d 4m 8s, [0..360d].
positive values have &#39;N&#39; prefix, negative values have &#39;S&#39; prefix.
void setMaximum(const double max, const bool isDegrees=false)
Set the maximum value.
PrefixType prefixType()
Get the current display format.
void setPrefixType(PrefixType prefix)
Set the prefix type.
double getMinimum(const bool isDegrees)
Get the minimum value.
DisplayFormat displayFormat()
Get the current display format.
Decimal degrees, e.g. 180.06888.
int decimals()
Get the number of decimal places to express float values to (e.g.
PrefixType
Determines how positive and negative values are indicated.