Warning, file /education/kstars/kstars/dialogs/timedialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2001 Jason Harris <jharris@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "timedialog.h"
0008 
0009 #include "geolocation.h"
0010 #include "kstarsdata.h"
0011 #include "kstarsdatetime.h"
0012 #include "simclock.h"
0013 
0014 #include <KLocalizedString>
0015 #include <KDatePicker>
0016 
0017 #include <QFrame>
0018 #include <QHBoxLayout>
0019 #include <QKeyEvent>
0020 #include <QPushButton>
0021 #include <QTimeEdit>
0022 #include <QVBoxLayout>
0023 
0024 TimeDialog::TimeDialog(const KStarsDateTime &now, GeoLocation *_geo, QWidget *parent, bool UTCFrame)
0025     : QDialog(parent), geo(_geo)
0026 {
0027 #ifdef Q_OS_OSX
0028     setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
0029 #endif
0030     UTCNow = UTCFrame;
0031 
0032     QFrame *page = new QFrame(this);
0033 
0034     QVBoxLayout *mainLayout = new QVBoxLayout;
0035     mainLayout->addWidget(page);
0036     setLayout(mainLayout);
0037 
0038     if (UTCNow)
0039         setWindowTitle(i18nc("@title:window set clock to a new time", "Set UTC Time"));
0040     else
0041         setWindowTitle(i18nc("@title:window set clock to a new time", "Set Time"));
0042 
0043     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0044     mainLayout->addWidget(buttonBox);
0045     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
0046     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
0047 
0048     vlay = new QVBoxLayout(page);
0049     vlay->setContentsMargins(2, 2, 2, 2);
0050     vlay->setSpacing(2);
0051     hlay = new QHBoxLayout(); //this layout will be added to the VLayout
0052     hlay->setSpacing(2);
0053 
0054     dPicker   = new KDatePicker(now.date(), page);
0055     tEdit     = new QTimeEdit(now.time(), page);
0056     NowButton = new QPushButton(page);
0057     NowButton->setObjectName("NowButton");
0058     NowButton->setText(UTCNow ? i18n("UTC Now") : i18n("Now"));
0059 
0060     vlay->addWidget(dPicker, 0);
0061     vlay->addLayout(hlay, 0);
0062 
0063     hlay->addWidget(tEdit);
0064     hlay->addWidget(NowButton);
0065 
0066     vlay->activate();
0067 
0068     QObject::connect(NowButton, SIGNAL(clicked()), this, SLOT(setNow()));
0069 }
0070 
0071 //Add handler for Escape key to close window
0072 //Use keyReleaseEvent because keyPressEvents are already consumed
0073 //by the KDatePicker.
0074 void TimeDialog::keyReleaseEvent(QKeyEvent *kev)
0075 {
0076     switch (kev->key())
0077     {
0078         case Qt::Key_Escape:
0079         {
0080             close();
0081             break;
0082         }
0083 
0084         default:
0085         {
0086             kev->ignore();
0087             break;
0088         }
0089     }
0090 }
0091 
0092 void TimeDialog::setNow(void)
0093 {
0094     KStarsDateTime dt(KStarsDateTime::currentDateTimeUtc());
0095     if (!UTCNow)
0096         dt = geo->UTtoLT(dt);
0097 
0098     dPicker->setDate(dt.date());
0099     tEdit->setTime(dt.time());
0100 }
0101 
0102 QTime TimeDialog::selectedTime(void)
0103 {
0104     return tEdit->time();
0105 }
0106 
0107 QDate TimeDialog::selectedDate(void)
0108 {
0109     return dPicker->date();
0110 }
0111 
0112 KStarsDateTime TimeDialog::selectedDateTime(void)
0113 {
0114     return KStarsDateTime(selectedDate(), selectedTime());
0115 }