File indexing completed on 2024-04-28 07:38:12
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2013 Mihail Ivchenko <ematirov@gmail.com> 0004 // SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com> 0005 // SPDX-FileCopyrightText: 2014 Illya Kovalevskyy <illya.kovalevskyy@gmail.com> 0006 // 0007 0008 #include "SoundCueEditWidget.h" 0009 0010 #include <QToolButton> 0011 #include <QLabel> 0012 #include <QHBoxLayout> 0013 #include <QLineEdit> 0014 #include <QFileDialog> 0015 0016 #include "MarbleWidget.h" 0017 #include "geodata/data/GeoDataSoundCue.h" 0018 #include "MarblePlacemarkModel.h" 0019 0020 namespace Marble { 0021 0022 SoundCueEditWidget::SoundCueEditWidget( const QModelIndex &index, QWidget *parent ) : 0023 QWidget( parent ), 0024 m_index( index ), 0025 m_lineEdit( new QLineEdit ), 0026 m_button( new QToolButton ), 0027 m_button2( new QToolButton ) 0028 { 0029 QHBoxLayout *layout = new QHBoxLayout; 0030 layout->setSpacing( 5 ); 0031 0032 QLabel* iconLabel = new QLabel; 0033 iconLabel->setPixmap(QPixmap(QStringLiteral(":/marble/playback-play.png"))); 0034 layout->addWidget( iconLabel ); 0035 0036 m_lineEdit->setPlaceholderText( "Audio location" ); 0037 m_lineEdit->setText( soundCueElement()->href() ); 0038 layout->addWidget( m_lineEdit ); 0039 0040 m_button2->setIcon(QIcon(QStringLiteral(":/marble/document-open.png"))); 0041 connect(m_button2, SIGNAL(clicked()), this, SLOT(open())); 0042 layout->addWidget( m_button2 ); 0043 0044 m_button->setIcon(QIcon(QStringLiteral(":/marble/document-save.png"))); 0045 connect(m_button, SIGNAL(clicked()), this, SLOT(save())); 0046 layout->addWidget( m_button ); 0047 0048 setLayout( layout ); 0049 } 0050 0051 bool SoundCueEditWidget::editable() const 0052 { 0053 return m_button->isEnabled(); 0054 } 0055 0056 void SoundCueEditWidget::setEditable( bool editable ) 0057 { 0058 m_button->setEnabled( editable ); 0059 } 0060 0061 void SoundCueEditWidget::save() 0062 { 0063 soundCueElement()->setHref( m_lineEdit->text() ); 0064 emit editingDone(m_index); 0065 } 0066 void SoundCueEditWidget::open() 0067 { 0068 QString fileName = QFileDialog::getOpenFileName(this, tr("Select sound files..."), QDir::homePath(), tr("Supported Sound Files (*.mp3 *.ogg *.wav)")); 0069 m_lineEdit->setText(fileName); 0070 soundCueElement()->setHref( m_lineEdit->text() ); 0071 } 0072 0073 GeoDataSoundCue* SoundCueEditWidget::soundCueElement() 0074 { 0075 GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) ); 0076 Q_ASSERT( object ); 0077 auto soundCue = geodata_cast<GeoDataSoundCue>(object); 0078 Q_ASSERT(soundCue); 0079 return soundCue; 0080 } 0081 0082 } // namespace Marble 0083 0084 #include "moc_SoundCueEditWidget.cpp"