Marble

TourControlEditWidget.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 "TourControlEditWidget.h"
9 
10 #include <QHBoxLayout>
11 #include <QLabel>
12 #include <QToolButton>
13 #include <QRadioButton>
14 
15 #include "MarblePlacemarkModel.h"
16 #include "GeoDataTourControl.h"
17 
18 namespace Marble
19 {
20 
21 TourControlEditWidget::TourControlEditWidget( const QModelIndex &index, QWidget *parent ) :
22  QWidget( parent ),
23  m_index( index ),
24  m_radio_play( new QRadioButton ),
25  m_radio_pause( new QRadioButton ),
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/media-playback-pause.png")));
33  layout->addWidget( iconLabel );
34 
35  layout->addWidget( m_radio_play );
36  m_radio_play->setText( tr( "Play" ) );
37 
38  layout->addWidget( m_radio_pause );
39  m_radio_pause->setText( tr( "Pause" ) );
40 
41  if( tourControlElement()->playMode() == GeoDataTourControl::Play ){
42  m_radio_play->setChecked( true );
43  }else{
44  m_radio_pause->setChecked( true );
45  }
46 
47  m_button->setIcon(QIcon(QStringLiteral(":/marble/document-save.png")));
48  connect(m_button, SIGNAL(clicked()), this, SLOT(save()));
49  layout->addWidget( m_button );
50 
51  setLayout( layout );
52 }
53 
54 bool TourControlEditWidget::editable() const
55 {
56  return m_button->isEnabled();
57 }
58 
59 void TourControlEditWidget::setEditable( bool editable )
60 {
61  m_button->setEnabled( editable );
62 }
63 
64 void TourControlEditWidget::save()
65 {
66  if ( m_radio_play->isChecked() ) {
67  tourControlElement()->setPlayMode( GeoDataTourControl::Play );
68  } else {
69  tourControlElement()->setPlayMode( GeoDataTourControl::Pause );
70  }
71  emit editingDone(m_index);
72 }
73 
74 GeoDataTourControl* TourControlEditWidget::tourControlElement()
75 {
76  GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) );
77  Q_ASSERT( object );
78  auto tourControl = geodata_cast<GeoDataTourControl>(object);
79  Q_ASSERT(tourControl);
80  return tourControl;
81 }
82 
83 } // namespace Marble
84 
85 #include "moc_TourControlEditWidget.cpp"
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)
const QList< QKeySequence > & save()
void setPixmap(const QPixmap &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Oct 2 2023 03:52:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.