Home · All Namespaces · All Classes · Functions · Coding Style · 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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     void stepBy (int steps);
00062     QValidator::State validate (QString& input, int& pos) const;
00063 
00066     double valueRadians();
00069     double valueDegrees();
00070 
00073     QString text();
00074 
00082     double stringToDouble(QString input, QValidator::State* state, PrefixType prefix=Unknown) const;
00083 
00086     void setDecimals(int places) { decimalPlaces = places; }
00087 
00090     int decimals() { return decimalPlaces; }
00091 
00094     void setDisplayFormat(DisplayFormat format) { angleSpinBoxFormat=format; formatText(); }
00095 
00098     DisplayFormat displayFormat() { return angleSpinBoxFormat; }
00099 
00102     void setPrefixType(PrefixType prefix) { currentPrefixType=prefix; formatText(); }
00103 
00106     PrefixType prefixType() { return currentPrefixType; }
00107     
00108 public slots:
00109     void clear();
00110 
00113     void setRadians(double radians);
00116     void setDegrees(double degrees);
00117 
00118 signals:
00120     void valueChanged();
00121 
00122 protected:
00123     StepEnabled stepEnabled () const;
00124 
00125 private slots:
00127     void updateValue(void);
00128 
00129 private:
00130     
00132     enum AngleSpinboxSection
00133     {
00134         SectionPrefix,          
00135         SectionDegreesHours,    
00136         SectionMinutes,         
00137         SectionSeconds,         
00138         SectionNone             
00139     };
00140     
00142     AngleSpinboxSection getCurrentSection() const;
00143     
00147     void formatText(void);
00148         
00149     static const QString positivePrefix(PrefixType prefix);
00150     static const QString negativePrefix(PrefixType prefix);
00151 
00152     DisplayFormat angleSpinBoxFormat;
00153     PrefixType currentPrefixType;
00154     int decimalPlaces;
00155     double radAngle;
00156 
00157 };
00158 
00159 #endif // _ANGLESPINBOX_HPP_

Generated on Mon Feb 2 17:23:47 2009 for Stellarium by  doxygen 1.5.5