Marble

WaitEditWidget.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2013 Mihail Ivchenko <ematirov@gmail.com>
4// SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
5// SPDX-FileCopyrightText: 2014 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
6//
7
8#include "WaitEditWidget.h"
9
10#include <QDoubleSpinBox>
11#include <QHBoxLayout>
12#include <QLabel>
13#include <QToolButton>
14
15#include "GeoDataTourControl.h"
16#include "MarblePlacemarkModel.h"
17#include "geodata/data/GeoDataWait.h"
18
19namespace Marble
20{
21
22WaitEditWidget::WaitEditWidget(const QModelIndex &index, QWidget *parent)
23 : QWidget(parent)
24 , m_index(index)
25 , m_spinBox(new QDoubleSpinBox(this))
26 , m_button(new QToolButton(this))
27{
28 auto layout = new QHBoxLayout(this);
29 layout->setSpacing(5);
30
31 auto iconLabel = new QLabel(this);
32 iconLabel->setPixmap(QPixmap(QStringLiteral(":/marble/player-time.png")));
33 layout->addWidget(iconLabel);
34
35 auto waitLabel = new QLabel(this);
36 waitLabel->setText(tr("Wait duration:"));
37 layout->addWidget(waitLabel);
38
39 layout->addWidget(m_spinBox);
40 m_spinBox->setValue(waitElement()->duration());
41 m_spinBox->setSuffix(tr(" s", "seconds"));
42
43 m_button->setIcon(QIcon(QStringLiteral(":/marble/document-save.png")));
44 connect(m_button, &QAbstractButton::clicked, this, &WaitEditWidget::save);
45 layout->addWidget(m_button);
46}
47
48bool WaitEditWidget::editable() const
49{
50 return m_button->isEnabled();
51}
52
53void WaitEditWidget::setEditable(bool editable)
54{
55 m_button->setEnabled(editable);
56}
57
58void WaitEditWidget::save()
59{
60 waitElement()->setDuration(m_spinBox->value());
61 Q_EMIT editingDone(m_index);
62}
63
64GeoDataWait *WaitEditWidget::waitElement()
65{
66 auto object = qvariant_cast<GeoDataObject *>(m_index.data(MarblePlacemarkModel::ObjectPointerRole));
67 Q_ASSERT(object);
68 auto wait = geodata_cast<GeoDataWait>(object);
69 Q_ASSERT(wait);
70 return wait;
71}
72
73} // namespace Marble
74
75#include "moc_WaitEditWidget.cpp"
Binds a QML item to a specific geodetic location in screen coordinates.
void clicked(bool checked)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
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.