Marble

SoundCueEditWidget.cpp
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
20namespace Marble {
21
22SoundCueEditWidget::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
51bool SoundCueEditWidget::editable() const
52{
53 return m_button->isEnabled();
54}
55
56void SoundCueEditWidget::setEditable( bool editable )
57{
58 m_button->setEnabled( editable );
59}
60
61void SoundCueEditWidget::save()
62{
63 soundCueElement()->setHref( m_lineEdit->text() );
64 emit editingDone(m_index);
65}
66void 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
73GeoDataSoundCue* 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"
This file contains the headers for MarbleWidget.
KGuiItem open()
KGuiItem save()
Binds a QML item to a specific geodetic location in screen coordinates.
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void setSpacing(int spacing) override
QString homePath()
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
void setPixmap(const QPixmap &)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.