1 /***************************************************************************
4 begin : Wed Dec 19 2002
5 copyright : (C) 2001-2002 by Pablo de Vicente
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
21 #include <klineedit.h>
26 *A KLineEdit which is capable of displaying and parsing angle values
27 *flexibly and robustly. Angle values can be displayed and parsed as
28 *Degrees or Hours. When displaying a value, it uses a space-delimited
29 *triplet of integers representing the degrees, arcminutes, and arcseconds
30 *of the angle (or hours, minutes, seconds). For example, "-34 45 57".
31 *When parsing a value input by the user, it can also understand
32 *a number of other formats:
33 *@li colon-delimited fields ("-34:45:57")
34 *@li one or two fields ("-35"; "-34 46")
35 *@li fields with unit-labels ("-34d 45m 57s")
36 *@li floating-point numbers ("-34.76583")
38 *@note Inherits KLineEdit.
39 *@author Pablo de Vicente
43 class dmsBox
: public KLineEdit
{
45 Q_PROPERTY (bool degType READ degType WRITE setDegType
)
48 /**Constructor for the dmsBox object.
49 *@p parent pointer to the parent QWidget
50 *@p ni the name of the object
51 *@p deg if TRUE use deg/arcmin/arcsec; otherwise
54 dmsBox(QWidget
*parent
, const char *ni
=0, bool deg
=TRUE
);
56 /**Destructor (empty)*/
59 /**Display an angle using Hours/Min/Sec.
60 *@p t the dms object which is to be displayed
62 void showInHours(dms t
);
63 /**Display an angle using Hours/Min/Sec. This behaves just
64 *like the above function. It differs only in the data type of
66 *@p t pointer to the dms object which is to be displayed
68 void showInHours(const dms
*t
);
70 /**Display an angle using Deg/Arcmin/Arcsec.
71 *@p t the dms object which is to be displayed
73 void showInDegrees(dms t
);
74 /**Display an angle using Deg/Arcmin/Arcsec. This behaves just
75 *like the above function. It differs only in the data type of
77 *@p t pointer to the dms object which is to be displayed
79 void showInDegrees(const dms
*t
);
81 /**Display an angle. Simply calls showInDegrees(t) or
82 *showInHours(t) depending on the value of deg.
83 *@param t the dms object which is to be displayed.
84 *@param deg if TRUE, display Deg/Arcmin/Arcsec; otherwise
85 *display Hours/Min/Sec.
87 void show(dms t
, bool deg
=TRUE
);
88 /**Display an angle. Simply calls showInDegrees(t) or
89 *showInHours(t) depending on the value of deg.
90 *This behaves essentially like the above function. It
91 *differs only in the data type of its argument.
92 *@param t the dms object which is to be displayed.
93 *@param deg if TRUE, display Deg/Arcmin/Arcsec; otherwise
94 *display Hours/Min/Sec.
96 void show(const dms
*t
,bool deg
=TRUE
);
98 /**Simply display a string.
99 *@note JH: Why don't we just use KLineEdit::setText() instead?
100 *@param s the string to display (it need not be a valid angle value).
102 void setDMS(QString s
) { setText(s
); }
104 /**Parse the text in the dmsBox as an angle. The text may be an integer
105 *or double value, or it may be a triplet of integer values (separated by spaces
106 *or colons) representing deg/hrs, min, sec. It is also possible to have two
107 *fields. In this case, if the second field is a double, it is converted
108 *to decimal min and double sec.
109 *@param ok set to true if a dms object was succedssfully created.
110 *@return a dms object constructed from the fields of the dmsbox
112 dms
createDms(bool deg
=TRUE
, bool *ok
=0);
114 /**@return a boolean indicating if object contains degrees or hours
116 bool degType(void) const {return deg
;}
118 /**@short set the dmsBox to Degrees or Hours
119 *@param t if true, the box expects angle values in degrees; otherwise
120 *it expects values in hours
122 void setDegType( bool t
);
124 /**Clears the KLineEdit
126 void clearFields (void) { setDMS(""); }
129 void focusInEvent( QFocusEvent
*e
);
130 void focusOutEvent( QFocusEvent
*e
);
133 void slotTextChanged( const QString
&t
);
138 int degree
, minute
, hour
;
140 int second_int
, msecond
;