Kstars

timedialog.cpp
1/*
2 SPDX-FileCopyrightText: 2001 Jason Harris <jharris@30doradus.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "timedialog.h"
8
9#include "geolocation.h"
10#include "kstarsdata.h"
11#include "kstarsdatetime.h"
12#include "simclock.h"
13
14#include <KLocalizedString>
15#include <KDatePicker>
16
17#include <QFrame>
18#include <QHBoxLayout>
19#include <QKeyEvent>
20#include <QPushButton>
21#include <QTimeEdit>
22#include <QVBoxLayout>
23
25 : QDialog(parent), geo(_geo)
26{
27#ifdef Q_OS_OSX
29#endif
30 UTCNow = UTCFrame;
31
32 QFrame *page = new QFrame(this);
33
34 QVBoxLayout *mainLayout = new QVBoxLayout;
35 mainLayout->addWidget(page);
36 setLayout(mainLayout);
37
38 if (UTCNow)
39 setWindowTitle(i18nc("@title:window set clock to a new time", "Set UTC Time"));
40 else
41 setWindowTitle(i18nc("@title:window set clock to a new time", "Set Time"));
42
44 mainLayout->addWidget(buttonBox);
45 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
46 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
47
48 vlay = new QVBoxLayout(page);
49 vlay->setContentsMargins(2, 2, 2, 2);
50 vlay->setSpacing(2);
51 hlay = new QHBoxLayout(); //this layout will be added to the VLayout
52 hlay->setSpacing(2);
53
54 dPicker = new KDatePicker(now.date(), page);
55 tEdit = new QTimeEdit(now.time(), page);
56 NowButton = new QPushButton(page);
57 NowButton->setObjectName("NowButton");
58 NowButton->setText(UTCNow ? i18n("UTC Now") : i18n("Now"));
59
60 vlay->addWidget(dPicker, 0);
61 vlay->addLayout(hlay, 0);
62
63 hlay->addWidget(tEdit);
64 hlay->addWidget(NowButton);
65
66 vlay->activate();
67
68 QObject::connect(NowButton, SIGNAL(clicked()), this, SLOT(setNow()));
69}
70
71//Add handler for Escape key to close window
72//Use keyReleaseEvent because keyPressEvents are already consumed
73//by the KDatePicker.
74void TimeDialog::keyReleaseEvent(QKeyEvent *kev)
75{
76 switch (kev->key())
77 {
78 case Qt::Key_Escape:
79 {
80 close();
81 break;
82 }
83
84 default:
85 {
86 kev->ignore();
87 break;
88 }
89 }
90}
91
93{
95 if (!UTCNow)
96 dt = geo->UTtoLT(dt);
97
98 dPicker->setDate(dt.date());
99 tEdit->setTime(dt.time());
100}
101
103{
104 return tEdit->time();
105}
106
108{
109 return dPicker->date();
110}
111
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
Definition geolocation.h:28
bool setDate(const QDate &date)
const QDate & date() const
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
static KStarsDateTime currentDateTimeUtc()
TimeDialog(const KStarsDateTime &now, GeoLocation *_geo, QWidget *parent, bool UTCFrame=false)
Constructor.
QDate selectedDate(void)
void setNow(void)
When the "Now" button is pressed, read the time and date from the system clock.
QTime selectedTime(void)
KStarsDateTime selectedDateTime(void)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void setText(const QString &text)
void addLayout(QLayout *layout, int stretch)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void setSpacing(int spacing) override
QDate date() const const
QTime time() const const
void setTime(QTime time)
virtual void accept()
void accepted()
virtual void reject()
void rejected()
bool activate()
void setContentsMargins(const QMargins &margins)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setObjectName(QAnyStringView name)
Key_Escape
bool close()
void setLayout(QLayout *layout)
void setWindowFlags(Qt::WindowFlags type)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:02 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.