Kstars

timedialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2001 Jason Harris <[email protected]>
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 
24 TimeDialog::TimeDialog(const KStarsDateTime &now, GeoLocation *_geo, QWidget *parent, bool UTCFrame)
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.
74 void 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 
113 {
115 }
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
void setNow(void)
When the "Now" button is pressed, read the time and date from the system clock.
Definition: timedialog.cpp:92
virtual void reject()
QTime time() const const
static KStarsDateTime currentDateTimeUtc()
KStarsDateTime selectedDateTime(void)
Definition: timedialog.cpp:112
bool setDate(const QDate &date)
bool close()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void rejected()
QString i18n(const char *text, const TYPE &arg...)
void setWindowFlags(Qt::WindowFlags type)
void setWindowTitle(const QString &)
QDate selectedDate(void)
Definition: timedialog.cpp:107
void setTime(const QTime &time)
virtual void accept()
Key_Escape
TimeDialog(const KStarsDateTime &now, GeoLocation *_geo, QWidget *parent, bool UTCFrame=false)
Constructor.
Definition: timedialog.cpp:24
int key() const const
void setSpacing(int spacing)
QTime selectedTime(void)
Definition: timedialog.cpp:102
void setObjectName(const QString &name)
void ignore()
QDate date() const const
void setContentsMargins(int left, int top, int right, int bottom)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void addLayout(QLayout *layout, int stretch)
bool activate()
const QDate & date() const
void setLayout(QLayout *layout)
void setText(const QString &text)
Relevant data about an observing location on Earth.
Definition: geolocation.h:27
void accepted()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.