File indexing completed on 2024-03-24 03:47:43
0001 /* 0002 SPDX-FileCopyrightText: 2001-2002 Pablo de Vicente <vicente@oan.es> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "dms.h" 0010 0011 #include <QFocusEvent> 0012 #include <QLineEdit> 0013 0014 /** 0015 * @class dmsBox 0016 * 0017 * A QLineEdit which is capable of displaying and parsing angle values 0018 * flexibly and robustly. Angle values can be displayed and parsed as 0019 * Degrees or Hours. When displaying a value, it uses a space-delimited 0020 * triplet of integers representing the degrees, arcminutes, and arcseconds 0021 * of the angle (or hours, minutes, seconds). For example, "-34 45 57". 0022 * When parsing a value input by the user, it can also understand 0023 * a number of other formats: 0024 * @li colon-delimited fields ("-34:45:57") 0025 * @li one or two fields ("-35"; "-34 46") 0026 * @li fields with unit-labels ("-34d 45m 57s") 0027 * @li floating-point numbers ("-34.76583") 0028 * 0029 * @note Inherits QLineEdit. 0030 * @author Pablo de Vicente 0031 * @version 1.0 0032 */ 0033 class dmsBox : public QLineEdit 0034 { 0035 Q_OBJECT 0036 Q_PROPERTY(Unit units READ getUnits WRITE setUnits) 0037 0038 public: 0039 0040 typedef enum 0041 { 0042 HOURS, 0043 DEGREES 0044 } Unit; 0045 /** 0046 * Constructor for the dmsBox object. 0047 * 0048 * @param parent Pointer to the parent QWidget 0049 * @param unit Units to use (Degree/Arcmin/Arcsec or Hour/Min/Sec) 0050 */ 0051 explicit dmsBox(QWidget *parent, Unit unit); 0052 0053 /** 0054 * Deprecated delegating constructor for backwards compatibility 0055 * 0056 * @param parent Pointer to the parent QWidget 0057 * @param isDegree If true, use Unit::DEGREES; if false, use Unit::HOURS 0058 */ 0059 explicit dmsBox(QWidget *parent, bool isDegree = true) 0060 : dmsBox(parent, isDegree ? Unit::DEGREES : Unit::HOURS) {} 0061 0062 virtual ~dmsBox() override = default; 0063 0064 /** 0065 * Display an angle. 0066 * 0067 * @param d the dms object which is to be displayed. 0068 */ 0069 void show(const dms &d); 0070 0071 /** 0072 * Display an angle.This behaves essentially like the above 0073 * function. It differs only in the data type of its argument. 0074 * 0075 * @param t the dms object which is to be displayed. 0076 */ 0077 inline void show(const dms *t) 0078 { 0079 show(*t); 0080 } 0081 0082 /** 0083 * Parse the text in the dmsBox as an angle. The text may be an integer 0084 * or double value, or it may be a triplet of integer values (separated by spaces 0085 * or colons) representing deg/hrs, min, sec. It is also possible to have two 0086 * fields. In this case, if the second field is a double, it is converted 0087 * to decimal min and double sec. 0088 * 0089 * @param ok set to true if a dms object was successfully created. 0090 * @return a dms object constructed from the fields of the dmsbox 0091 */ 0092 dms createDms(bool *ok = nullptr); 0093 0094 /** 0095 * @return the unit being used (DEGREES or HOURS) 0096 */ 0097 inline Unit getUnits() const 0098 { 0099 return m_unit; 0100 } 0101 0102 /** 0103 * @short set the dmsBox to Degrees or Hours 0104 * 0105 * @param unit If Unit::DEGREES, then the display and 0106 * interpretation of text is in degrees, if Unit::HOURS then in 0107 * hours. 0108 */ 0109 void setUnits(Unit unit); 0110 0111 /** Clears the QLineEdit */ 0112 inline void clearFields(void) 0113 { 0114 setText(QString()); 0115 } 0116 0117 inline bool isEmpty() const 0118 { 0119 return text().isEmpty(); 0120 } 0121 0122 private: 0123 0124 void setPlaceholderText(); 0125 0126 Unit m_unit; 0127 };