Stellarium 0.11.4
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

gui/AngleSpinBox.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2008 Matthew Gates
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00018  */
00019 
00020 #ifndef _ANGLESPINBOX_HPP_
00021 #define _ANGLESPINBOX_HPP_
00022 
00023 #include <QAbstractSpinBox>
00024 #include <QString>
00025 
00030 class AngleSpinBox : public QAbstractSpinBox
00031 {
00032     Q_OBJECT
00033 
00034 public:
00037     enum DisplayFormat
00038     {
00039         DMSLetters,     
00040         DMSSymbols,     
00041         HMSLetters,     
00042         HMSSymbols,     
00043         DecimalDeg      
00044     };
00045 
00048     enum PrefixType
00049     {
00050         Normal,     
00051         NormalPlus, 
00052         Longitude,  
00053         Latitude,   
00054         Unknown
00055     };
00056     
00057     AngleSpinBox(QWidget* parent=0, DisplayFormat format=DMSSymbols, PrefixType prefix=Normal);
00058     ~AngleSpinBox();
00059 
00060     // QAbstractSpinBox virtual members
00061     virtual void stepBy(int steps);
00062     virtual QValidator::State validate(QString& input, int& pos) const;
00063 
00066     double valueRadians();
00069     double valueDegrees();
00070 
00073     void setDecimals(int places) { decimalPlaces = places; }
00074 
00077     int decimals() { return decimalPlaces; }
00078 
00081     void setDisplayFormat(DisplayFormat format) { angleSpinBoxFormat=format; formatText(); }
00082 
00085     DisplayFormat displayFormat() { return angleSpinBoxFormat; }
00086 
00089     void setPrefixType(PrefixType prefix) { currentPrefixType=prefix; formatText(); }
00090 
00093     PrefixType prefixType() { return currentPrefixType; }
00094     
00095 public slots:
00097     virtual void clear();
00098     
00101     void setRadians(double radians);
00102     
00105     void setDegrees(double degrees);
00106 
00107 signals:
00109     void valueChanged();
00110 
00111 protected:
00112     virtual StepEnabled stepEnabled() const;
00113 
00114 private slots:
00116     void updateValue(void);
00117 
00118 private:
00126     double stringToDouble(QString input, QValidator::State* state, PrefixType prefix=Unknown) const;
00127     
00129     enum AngleSpinboxSection
00130     {
00131         SectionPrefix,          
00132         SectionDegreesHours,    
00133         SectionMinutes,         
00134         SectionSeconds,         
00135         SectionNone             
00136     };
00137     
00139     AngleSpinboxSection getCurrentSection() const;
00140     
00144     void formatText(void);
00145         
00146     static const QString positivePrefix(PrefixType prefix);
00147     static const QString negativePrefix(PrefixType prefix);
00148 
00149     DisplayFormat angleSpinBoxFormat;
00150     PrefixType currentPrefixType;
00151     int decimalPlaces;
00152     double radAngle;
00153 
00154 };
00155 
00156 #endif // _ANGLESPINBOX_HPP_
Generated on Sat Aug 25 22:13:30 2012 for Stellarium by  doxygen 1.6.3