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 <QFileDialog>
11#include <QHBoxLayout>
12#include <QLabel>
13#include <QLineEdit>
14#include <QToolButton>
15
16#include "MarblePlacemarkModel.h"
17#include "MarbleWidget.h"
18#include "geodata/data/GeoDataSoundCue.h"
19
20namespace Marble
21{
22
23SoundCueEditWidget::SoundCueEditWidget(const QModelIndex &index, QWidget *parent)
24 : QWidget(parent)
25 , m_index(index)
26 , m_lineEdit(new QLineEdit(this))
27 , m_button(new QToolButton(this))
28 , m_button2(new QToolButton(this))
29{
30 auto layout = new QHBoxLayout(this);
31 layout->setSpacing(5);
32
33 auto iconLabel = new QLabel(this);
34 iconLabel->setPixmap(QPixmap(QStringLiteral(":/marble/playback-play.png")));
35 layout->addWidget(iconLabel);
36
37 m_lineEdit->setPlaceholderText(tr("Audio location"));
38 m_lineEdit->setText(soundCueElement()->href());
39 layout->addWidget(m_lineEdit);
40
41 m_button2->setIcon(QIcon(QStringLiteral(":/marble/document-open.png")));
42 connect(m_button2, &QAbstractButton::clicked, this, &SoundCueEditWidget::open);
43 layout->addWidget(m_button2);
44
45 m_button->setIcon(QIcon(QStringLiteral(":/marble/document-save.png")));
46 connect(m_button, &QAbstractButton::clicked, this, &SoundCueEditWidget::save);
47 layout->addWidget(m_button);
48}
49
50bool SoundCueEditWidget::editable() const
51{
52 return m_button->isEnabled();
53}
54
55void SoundCueEditWidget::setEditable(bool editable)
56{
57 m_button->setEnabled(editable);
58}
59
60void SoundCueEditWidget::save()
61{
62 soundCueElement()->setHref(m_lineEdit->text());
63 Q_EMIT editingDone(m_index);
64}
65void SoundCueEditWidget::open()
66{
67 QString fileName = QFileDialog::getOpenFileName(this, tr("Select sound files..."), QDir::homePath(), tr("Supported Sound Files (*.mp3 *.ogg *.wav)"));
68 m_lineEdit->setText(fileName);
69 soundCueElement()->setHref(m_lineEdit->text());
70}
71
72GeoDataSoundCue *SoundCueEditWidget::soundCueElement()
73{
74 auto object = qvariant_cast<GeoDataObject *>(m_index.data(MarblePlacemarkModel::ObjectPointerRole));
75 Q_ASSERT(object);
76 auto soundCue = geodata_cast<GeoDataSoundCue>(object);
77 Q_ASSERT(soundCue);
78 return soundCue;
79}
80
81} // namespace Marble
82
83#include "moc_SoundCueEditWidget.cpp"
This file contains the headers for MarbleWidget.
Binds a QML item to a specific geodetic location in screen coordinates.
void clicked(bool checked)
QString homePath()
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
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 Mon Nov 4 2024 16:37:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.