Kstars

dmsbox.cpp
1 /*
2  SPDX-FileCopyrightText: 2001-2002 Pablo de Vicente <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "dmsbox.h"
8 
9 #include <QApplication>
10 #include <QFocusEvent>
11 #include <QRegExp>
12 
13 #include <KLocalizedString>
14 
15 #include <QDebug>
16 
17 #include <cstdlib>
18 
19 dmsBox::dmsBox(QWidget *parent, Unit unit) : QLineEdit(parent), m_unit(unit)
20 {
21  setMaxLength(14);
22  setMaximumWidth(160);
23  setUnits(unit);
24 }
25 
26 void dmsBox::setPlaceholderText()
27 {
28  if (m_unit == DEGREES)
29  QLineEdit::setPlaceholderText("dd mm ss.s");
30  else
31  QLineEdit::setPlaceholderText("hh mm ss.s");
32 }
33 
34 void dmsBox::setUnits(Unit unit)
35 {
36  m_unit = unit;
37  const bool t = (m_unit == Unit::DEGREES);
38 
39  QString sTip = (t ? i18n("Angle value in degrees.") : i18n("Angle value in hours."));
40  QString sWhatsThis;
41 
42  if (isReadOnly())
43  {
44  if (t)
45  {
46  sWhatsThis = i18n("This box displays an angle in degrees. "
47  "The three numbers displayed are the angle's "
48  "degrees, arcminutes, and arcseconds.");
49  }
50  else
51  {
52  sWhatsThis = i18n("This box displays an angle in hours. "
53  "The three numbers displayed are the angle's "
54  "hours, minutes, and seconds.");
55  }
56  }
57  else
58  {
59  if (t)
60  {
61  sTip += i18n(" You may enter a simple integer, or a floating-point value, "
62  "or space- or colon-delimited values specifying "
63  "degrees, arcminutes and arcseconds");
64 
65  sWhatsThis = i18n("Enter an angle value in degrees. The angle can be expressed "
66  "as a simple integer (\"12\"), a floating-point value "
67  "(\"12.33\"), or as space- or colon-delimited "
68  "values specifying degrees, arcminutes and arcseconds (\"12:20\", \"12:20:00\", "
69  "\"12 20\", \"12 20 00.0\", etc.).");
70  }
71  else
72  {
73  sTip += i18n(" You may enter a simple integer, or a floating-point value, "
74  "or space- or colon-delimited values specifying "
75  "hours, minutes and seconds");
76 
77  sWhatsThis = i18n("Enter an angle value in hours. The angle can be expressed "
78  "as a simple integer (\"12\"), a floating-point value "
79  "(\"12.33\"), or as space- or colon-delimited "
80  "values specifying hours, minutes and seconds (\"12:20\", \"12:20:00\", "
81  "\"12 20\", \"12 20 00.0\", etc.).");
82  }
83  }
84 
85  setToolTip(sTip);
86  setWhatsThis(sWhatsThis);
87  setPlaceholderText();
88 
89  clear();
90 }
91 
92 void dmsBox::show(const dms &d)
93 {
94  if (m_unit == Unit::DEGREES)
95  {
96  double seconds = d.arcsec() + d.marcsec() / 1000.;
97  setText(QString::asprintf("%02d %02d %05.2f", d.degree(), d.arcmin(), seconds));
98  }
99  else if (m_unit == Unit::HOURS)
100  {
101  double seconds = d.second() + d.msecond() / 1000.;
102  setText(QString::asprintf("%02d %02d %05.2f", d.hour(), d.minute(), seconds));
103  }
104  else
105  {
106  Q_ASSERT(false); // Unhandled unit type
107  }
108 }
109 
111 {
112  dms dmsAngle;
113  bool check;
114  check = dmsAngle.setFromString(text(), (m_unit == Unit::DEGREES));
115  if (ok)
116  *ok = check; //ok might be a null pointer!
117 
118  return dmsAngle;
119 }
void setPlaceholderText(const QString &)
void setWhatsThis(const QString &)
void setMaxLength(int)
void setUnits(Unit unit)
set the dmsBox to Degrees or Hours
Definition: dmsbox.cpp:34
void setMaximumWidth(int maxw)
void clear()
QString i18n(const char *text, const TYPE &arg...)
void setText(const QString &)
bool isReadOnly() const const
virtual bool setFromString(const QString &s, bool isDeg=true)
Attempt to parse the string argument as a dms value, and set the dms object accordingly.
Definition: dms.cpp:48
void show()
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
dms createDms(bool *ok=nullptr)
Parse the text in the dmsBox as an angle.
Definition: dmsbox.cpp:110
void setToolTip(const QString &)
dmsBox(QWidget *parent, Unit unit)
Constructor for the dmsBox object.
Definition: dmsbox.cpp:19
QString asprintf(const char *cformat,...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.