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, SIGNAL(valueChanged(int)), this, SLOT(updateSpeedLabel(int)) );
30 connect( m_uiWidget->nowToolButton, SIGNAL(clicked()), this, SLOT(nowClicked()) );
31 connect( m_uiWidget->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()) );
32 connect( m_uiWidget->buttonBox, SIGNAL(rejected()), this, SLOT(reject()) );
33 connect( m_uiWidget->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(apply()) );
34 connect( m_uiWidget->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept()) );
35 connect( m_clock, SIGNAL(timeChanged()), this, SLOT(updateDateTime()) );
36 connect( m_clock, SIGNAL(updateIntervalChanged(int)), this, SLOT(updateRefreshRate(int)) );
37
38 setModal( false );
39
40}
41
42TimeControlWidget::~TimeControlWidget()
43{
44 delete m_uiWidget;
45}
46
47void TimeControlWidget::updateSpeedLabel( int speed )
48{
49 m_uiWidget->speedLabel->setText( QString( "%1x" ).arg( speed ) );
50}
51
52void TimeControlWidget::updateRefreshRate( int seconds )
53{
54 m_uiWidget->refreshIntervalSpinBox->setValue( seconds );
55}
56
57void TimeControlWidget::updateDateTime()
58{
59 m_uiWidget->currentDateTimeEdit->setDateTime( m_clock->dateTime().addSecs( m_clock->timezone() ) );
60}
61
62void TimeControlWidget::nowClicked()
63{
64 m_uiWidget->newDateTimeEdit->setDateTime( QDateTime::currentDateTime().toUTC().addSecs( m_clock->timezone() ) );
65}
66
67void TimeControlWidget::apply()
68{
69 if( m_lastDateTime != m_uiWidget->newDateTimeEdit->dateTime() )
70 {
71 m_lastDateTime = m_uiWidget->newDateTimeEdit->dateTime();
72 m_clock->setDateTime( m_lastDateTime.toUTC() );
73 }
74 m_clock->setUpdateInterval( m_uiWidget->refreshIntervalSpinBox->value() );
75 m_clock->setSpeed( m_uiWidget->speedSlider->value() );
76}
77
78void TimeControlWidget::showEvent(QShowEvent* event)
79{
80 if( !event->spontaneous() )
81 {
82 // Loading all options
83 m_uiWidget->refreshIntervalSpinBox->setValue( m_clock->updateInterval() );
84 m_uiWidget->speedSlider->setValue( m_clock->speed() );
85 m_uiWidget->speedLabel->setText( QString( "%1x" ).arg( m_clock->speed() ) );
86 updateDateTime();
87 m_lastDateTime = m_clock->dateTime();
88 m_uiWidget->newDateTimeEdit->setDateTime( m_lastDateTime.addSecs( m_clock->timezone() ) );
89 }
90}
91
92#include "moc_TimeControlWidget.cpp"
KGuiItem apply()
Binds a QML item to a specific geodetic location in screen coordinates.
QDateTime addSecs(qint64 s) const const
QDateTime currentDateTime()
QDateTime toUTC() const const
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 Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.