Stellarium 0.13.0
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  {
44  };
45 
49  {
54  Unknown
55  };
56 
57  AngleSpinBox(QWidget* parent=0, DisplayFormat format=DMSSymbols, PrefixType prefix=Normal);
58  ~AngleSpinBox();
59 
60  // QAbstractSpinBox virtual members
61  virtual void stepBy(int steps);
62  virtual QValidator::State validate(QString& input, int& pos) const;
63 
66  double valueRadians();
69  double valueDegrees();
70 
73  void setDecimals(int places) { decimalPlaces = places; }
74 
77  int decimals() { return decimalPlaces; }
78 
81  void setDisplayFormat(DisplayFormat format) { angleSpinBoxFormat=format; formatText(); }
82 
85  DisplayFormat displayFormat() { return angleSpinBoxFormat; }
86 
89  void setPrefixType(PrefixType prefix) { currentPrefixType=prefix; formatText(); }
90 
93  PrefixType prefixType() { return currentPrefixType; }
94 
95 public slots:
97  virtual void clear();
98 
101  void setRadians(double radians);
102 
105  void setDegrees(double degrees);
106 
107 signals:
109  void valueChanged();
110 
111 protected:
112  virtual StepEnabled stepEnabled() const;
113 
114 private slots:
116  void updateValue(void);
117 
118 private:
126  double stringToDouble(QString input, QValidator::State* state, PrefixType prefix=Unknown) const;
127 
129  enum AngleSpinboxSection
130  {
131  SectionPrefix,
132  SectionDegreesHours,
133  SectionMinutes,
134  SectionSeconds,
135  SectionNone
136  };
137 
139  AngleSpinboxSection getCurrentSection() const;
140 
144  void formatText(void);
145 
146  static const QString positivePrefix(PrefixType prefix);
147  static const QString negativePrefix(PrefixType prefix);
148 
149  DisplayFormat angleSpinBoxFormat;
150  PrefixType currentPrefixType;
151  int decimalPlaces;
152  double radAngle;
153 
154 };
155 
156 #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.
void setRadians(double radians)
Set the value of the spin box in radians.
Degrees, minutes and seconds, e.g. 180° 4' 8".
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.
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.