Kstars

dmsbox.cpp
1/*
2 SPDX-FileCopyrightText: 2001-2002 Pablo de Vicente <vicente@oan.es>
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 <QRegularExpression>
12
13#include <KLocalizedString>
14
15#include <QDebug>
16
17#include <cstdlib>
18
19dmsBox::dmsBox(QWidget *parent, Unit unit) : QLineEdit(parent), m_unit(unit)
20{
21 setMaxLength(14);
22 setMaximumWidth(160);
23 setUnits(unit);
24}
25
26void dmsBox::setPlaceholderText()
27{
28 if (m_unit == DEGREES)
30 else
32}
33
34void 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
92void 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}
dmsBox(QWidget *parent, Unit unit)
Constructor for the dmsBox object.
Definition dmsbox.cpp:19
void setUnits(Unit unit)
set the dmsBox to Degrees or Hours
Definition dmsbox.cpp:34
dms createDms(bool *ok=nullptr)
Parse the text in the dmsBox as an angle.
Definition dmsbox.cpp:110
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
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
QString i18n(const char *text, const TYPE &arg...)
void clear()
void setMaxLength(int)
void setPlaceholderText(const QString &)
bool isReadOnly() const const
void setText(const QString &)
QString asprintf(const char *cformat,...)
void setMaximumWidth(int maxw)
void show()
void setToolTip(const QString &)
void setWhatsThis(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.