Stellarium 0.13.3
AngleSpinBox.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2008 Matthew Gates
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _ANGLESPINBOX_HPP_
21 #define _ANGLESPINBOX_HPP_
22 
23 #include <QAbstractSpinBox>
24 #include <QString>
25 
30 class AngleSpinBox : public QAbstractSpinBox
31 {
32  Q_OBJECT
33 
34 public:
38  {
46  };
47 
51  {
56  Unknown
57  };
58 
59  AngleSpinBox(QWidget* parent=0, DisplayFormat format=DMSSymbols, PrefixType prefix=Normal);
60  ~AngleSpinBox();
61 
62  // QAbstractSpinBox virtual members
63  virtual void stepBy(int steps);
64  virtual QValidator::State validate(QString& input, int& pos) const;
65 
68  double valueRadians();
71  double valueDegrees();
72 
75  void setDecimals(int places) { decimalPlaces = places; }
76 
79  int decimals() { return decimalPlaces; }
80 
83  void setDisplayFormat(DisplayFormat format) { angleSpinBoxFormat=format; formatText(); }
84 
87  DisplayFormat displayFormat() { return angleSpinBoxFormat; }
88 
91  void setPrefixType(PrefixType prefix) { currentPrefixType=prefix; formatText(); }
92 
95  PrefixType prefixType() { return currentPrefixType; }
96 
97 public slots:
99  virtual void clear();
100 
103  void setRadians(double radians);
104 
107  void setDegrees(double degrees);
108 
109 signals:
111  void valueChanged();
112 
113 protected:
114  virtual StepEnabled stepEnabled() const;
115 
116 private slots:
118  void updateValue(void);
119 
120 private:
128  double stringToDouble(QString input, QValidator::State* state, PrefixType prefix=Unknown) const;
129 
131  enum AngleSpinboxSection
132  {
133  SectionPrefix,
134  SectionDegreesHours,
135  SectionMinutes,
136  SectionSeconds,
137  SectionNone
138  };
139 
141  AngleSpinboxSection getCurrentSection() const;
142 
146  void formatText(void);
147 
148  static const QString positivePrefix(PrefixType prefix);
149  static const QString negativePrefix(PrefixType prefix);
150 
151  DisplayFormat angleSpinBoxFormat;
152  PrefixType currentPrefixType;
153  int decimalPlaces;
154  double radAngle;
155 
156 };
157 
158 #endif // _ANGLESPINBOX_HPP_
void valueChanged()
Emitted when the value changes.
Hours, minutes and seconds, e.g. 12h 4m 6s.
negative values have '-' 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' 6s".
double valueDegrees()
Get the angle held in the AngleSpinBox.
positive values have 'E' prefix, negative values have 'W' 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].
Degrees, minutes and seconds, e.g. 180° 4' 8", [0..360°].
void setRadians(double radians)
Set the value of the spin box in radians.
Degrees, minutes and seconds, e.g. 180° 4' 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 '+' prefix, negative values have '-' prefix.
Degrees, minutes and seconds, e.g. 180d 4m 8s, [0..360d].
positive values have 'N' prefix, negative values have 'S' prefix.
PrefixType prefixType()
Get the current display format.
void setPrefixType(PrefixType prefix)
Set the prefix type.
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.