Marble

TimeControlWidget.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Harshit Jain <hjain.itbhu@gmail.com>
4//
5
6// Own
7#include "TimeControlWidget.h"
8#include "ui_TimeControlWidget.h"
9
10// Qt
11#include <QPushButton>
12#include <QShowEvent>
13
14// Marble
15#include "MarbleClock.h"
16#include "MarbleDebug.h"
17
18using namespace Marble;
19/* TRANSLATOR Marble::TimeControlWidget */
20
21TimeControlWidget::TimeControlWidget(MarbleClock *clock, QWidget *parent)
22 : QDialog(parent)
23 , m_uiWidget(new Ui::TimeControlWidget)
24 , m_clock(clock)
25 , m_lastDateTime()
26{
27 m_uiWidget->setupUi(this);
28
29 connect(m_uiWidget->speedSlider, &QAbstractSlider::valueChanged, this, &TimeControlWidget::updateSpeedLabel);
30 connect(m_uiWidget->nowToolButton, &QAbstractButton::clicked, this, &TimeControlWidget::nowClicked);
31 connect(m_uiWidget->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
32 connect(m_uiWidget->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
33 connect(m_uiWidget->buttonBox->button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &TimeControlWidget::apply);
34 connect(m_uiWidget->buttonBox->button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &QDialog::accept);
35 connect(m_clock, &MarbleClock::timeChanged, this, &TimeControlWidget::updateDateTime);
36 connect(m_clock, &MarbleClock::updateIntervalChanged, this, &TimeControlWidget::updateRefreshRate);
37
38 setModal(false);
39}
40
41TimeControlWidget::~TimeControlWidget()
42{
43 delete m_uiWidget;
44}
45
46void TimeControlWidget::updateSpeedLabel(int speed)
47{
48 m_uiWidget->speedLabel->setText(QStringLiteral("%1x").arg(speed));
49}
50
51void TimeControlWidget::updateRefreshRate(int seconds)
52{
53 m_uiWidget->refreshIntervalSpinBox->setValue(seconds);
54}
55
56void TimeControlWidget::updateDateTime()
57{
58 m_uiWidget->currentDateTimeEdit->setDateTime(m_clock->dateTime().addSecs(m_clock->timezone()));
59}
60
61void TimeControlWidget::nowClicked()
62{
63 m_uiWidget->newDateTimeEdit->setDateTime(QDateTime::currentDateTime().toUTC().addSecs(m_clock->timezone()));
64}
65
66void TimeControlWidget::apply()
67{
68 if (m_lastDateTime != m_uiWidget->newDateTimeEdit->dateTime()) {
69 m_lastDateTime = m_uiWidget->newDateTimeEdit->dateTime();
70 m_clock->setDateTime(m_lastDateTime.toUTC());
71 }
72 m_clock->setUpdateInterval(m_uiWidget->refreshIntervalSpinBox->value());
73 m_clock->setSpeed(m_uiWidget->speedSlider->value());
74}
75
76void TimeControlWidget::showEvent(QShowEvent *event)
77{
78 if (!event->spontaneous()) {
79 // Loading all options
80 m_uiWidget->refreshIntervalSpinBox->setValue(m_clock->updateInterval());
81 m_uiWidget->speedSlider->setValue(m_clock->speed());
82 m_uiWidget->speedLabel->setText(QStringLiteral("%1x").arg(m_clock->speed()));
83 updateDateTime();
84 m_lastDateTime = m_clock->dateTime();
85 m_uiWidget->newDateTimeEdit->setDateTime(m_lastDateTime.addSecs(m_clock->timezone()));
86 }
87}
88
89#include "moc_TimeControlWidget.cpp"
KGuiItem apply()
Binds a QML item to a specific geodetic location in screen coordinates.
void clicked(bool checked)
void valueChanged(int value)
QDateTime addSecs(qint64 s) const const
QDateTime currentDateTime()
QDateTime toUTC() const const
virtual void accept()
virtual void reject()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
virtual bool event(QEvent *event) override
void setupUi(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.