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 "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
SoundCueEditWidget(const QModelIndex & index,QWidget * parent)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
editable() const51 bool SoundCueEditWidget::editable() const
52 {
53 return m_button->isEnabled();
54 }
55
setEditable(bool editable)56 void SoundCueEditWidget::setEditable( bool editable )
57 {
58 m_button->setEnabled( editable );
59 }
60
save()61 void SoundCueEditWidget::save()
62 {
63 soundCueElement()->setHref( m_lineEdit->text() );
64 emit editingDone(m_index);
65 }
open()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
soundCueElement()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"
85