Marble

SoundCueEditWidget.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 "SoundCueEditWidget.h"
9 
10 #include <QToolButton>
11 #include <QLabel>
12 #include <QHBoxLayout>
13 #include <QLineEdit>
14 #include <QFileDialog>
15 
16 #include "MarbleWidget.h"
17 #include "geodata/data/GeoDataSoundCue.h"
18 #include "MarblePlacemarkModel.h"
19 
20 namespace Marble {
21 
22 SoundCueEditWidget::SoundCueEditWidget( const QModelIndex &index, QWidget *parent ) :
23  QWidget( parent ),
24  m_index( index ),
25  m_lineEdit( new QLineEdit ),
26  m_button( new QToolButton ),
27  m_button2( new QToolButton )
28 {
29  QHBoxLayout *layout = new QHBoxLayout;
30  layout->setSpacing( 5 );
31 
32  QLabel* iconLabel = new QLabel;
33  iconLabel->setPixmap(QPixmap(QStringLiteral(":/marble/playback-play.png")));
34  layout->addWidget( iconLabel );
35 
36  m_lineEdit->setPlaceholderText( "Audio location" );
37  m_lineEdit->setText( soundCueElement()->href() );
38  layout->addWidget( m_lineEdit );
39 
40  m_button2->setIcon(QIcon(QStringLiteral(":/marble/document-open.png")));
41  connect(m_button2, SIGNAL(clicked()), this, SLOT(open()));
42  layout->addWidget( m_button2 );
43 
44  m_button->setIcon(QIcon(QStringLiteral(":/marble/document-save.png")));
45  connect(m_button, SIGNAL(clicked()), this, SLOT(save()));
46  layout->addWidget( m_button );
47 
48  setLayout( layout );
49 }
50 
51 bool SoundCueEditWidget::editable() const
52 {
53  return m_button->isEnabled();
54 }
55 
56 void SoundCueEditWidget::setEditable( bool editable )
57 {
58  m_button->setEnabled( editable );
59 }
60 
61 void SoundCueEditWidget::save()
62 {
63  soundCueElement()->setHref( m_lineEdit->text() );
64  emit editingDone(m_index);
65 }
66 void SoundCueEditWidget::open()
67 {
68  QString fileName = QFileDialog::getOpenFileName(this, tr("Select sound files..."), QDir::homePath(), tr("Supported Sound Files (*.mp3 *.ogg *.wav)"));
69  m_lineEdit->setText(fileName);
70  soundCueElement()->setHref( m_lineEdit->text() );
71 }
72 
73 GeoDataSoundCue* SoundCueEditWidget::soundCueElement()
74 {
75  GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) );
76  Q_ASSERT( object );
77  auto soundCue = geodata_cast<GeoDataSoundCue>(object);
78  Q_ASSERT(soundCue);
79  return soundCue;
80 }
81 
82 } // namespace Marble
83 
84 #include "moc_SoundCueEditWidget.cpp"
QAction * open(const QObject *recvr, const char *slot, QObject *parent)
QString homePath()
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.
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
void setSpacing(int spacing)
void setPixmap(const QPixmap &)
QAction * save(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 26 2022 04:07:50 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.