Marble

WaitEditWidget.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2013 Mihail Ivchenko <[email protected]>
4 // SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <[email protected]>
5 // SPDX-FileCopyrightText: 2014 Illya Kovalevskyy <[email protected]>
6 //
7 
8 #include "WaitEditWidget.h"
9 
10 #include <QHBoxLayout>
11 #include <QLabel>
12 #include <QToolButton>
13 #include <QDoubleSpinBox>
14 
15 #include "MarblePlacemarkModel.h"
16 #include "GeoDataTourControl.h"
17 #include "geodata/data/GeoDataWait.h"
18 
19 namespace Marble
20 {
21 
22 WaitEditWidget::WaitEditWidget( const QModelIndex &index, QWidget *parent ) :
23  QWidget( parent ),
24  m_index( index ),
25  m_spinBox( new QDoubleSpinBox ),
26  m_button( new QToolButton )
27 {
28  QHBoxLayout *layout = new QHBoxLayout;
29  layout->setSpacing( 5 );
30 
31  QLabel* iconLabel = new QLabel;
32  iconLabel->setPixmap(QPixmap(QStringLiteral(":/marble/player-time.png")));
33  layout->addWidget( iconLabel );
34 
35  QLabel *waitLabel = new QLabel;
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, SIGNAL(clicked()), this, SLOT(save()));
45  layout->addWidget( m_button );
46 
47  setLayout( layout );
48 }
49 
50 bool WaitEditWidget::editable() const
51 {
52  return m_button->isEnabled();
53 }
54 
55 void WaitEditWidget::setEditable( bool editable )
56 {
57  m_button->setEnabled( editable );
58 }
59 
60 void WaitEditWidget::save()
61 {
62  waitElement()->setDuration( m_spinBox->value() );
63  emit editingDone(m_index);
64 }
65 
66 GeoDataWait* WaitEditWidget::waitElement()
67 {
68  GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) );
69  Q_ASSERT( object );
70  auto wait = geodata_cast<GeoDataWait>(object);
71  Q_ASSERT(wait);
72  return wait;
73 }
74 
75 } // namespace Marble
76 
77 #include "moc_WaitEditWidget.cpp"
void setText(const QString &)
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)
@ ObjectPointerRole
The pointer to a specific object.
Binds a QML item to a specific geodetic location in screen coordinates.
void setSpacing(int spacing)
void setPixmap(const QPixmap &)
QString tr(const char *sourceText, const char *disambiguation, int n)
QAction * save(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Oct 4 2023 04:09:43 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.