Kirigami-addons

SoundsPicker.qml
1/*
2 * SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
3 * SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8import QtQuick
9import QtQuick.Controls as Controls2
10import org.kde.kirigami as Kirigami
11import QtQuick.Layouts
12import QtMultimedia
13import org.kde.kirigamiaddons.sounds
14import org.kde.kirigamiaddons.delegates as Delegates
15
16/**
17 * A sound picker component for picking ringtones and notifications.
18 * \inherits QtQuick.ListView
19 */
20ListView {
21 id: listView
22
23 /**
24 * This property holds the selected audio url.
25 */
26 property string selectedUrl: soundsModel.initialSourceUrl(listView.currentIndex)
27
28 /**
29 * This property controls the sound type (ringtone or notification).
30 * \property bool notification
31 */
32 property bool notification: true
34 /**
35 * This property lets you choose sound theme, default to "plasma-mobile"
36 * \property string theme
37 */
38 property alias theme: soundsModel.theme
39
40 /**
41 * This property is the internal Audio qml type used for play sound
42 * \property QtMultimedia.Audio playMusic
43 */
44 property alias audioPlayer: playMusic
45
46 model: SoundsModel {
47 id: soundsModel
48 notification: listView.notification
49 theme: 'freedesktop'
50 }
51
52 delegate: Delegates.RoundedItemDelegate {
53 required property string ringtoneName
54 required property url sourceUrl
55 required property int index
56
57 text: ringtoneName
58
59 icon.name: ListView.isCurrentItem ? "object-select-symbolic" : ""
60 onClicked: {
61 selectedUrl = sourceUrl;
62 if (playMusic.playbackState === MediaPlayer.PlayingState) {
63 playMusic.pause();
64 } else {
65 playMusic.play();
66 }
67 }
68 }
69
70 MediaPlayer {
71 id: playMusic
72 source: selectedUrl
73 audioOutput: AudioOutput {}
74 }
75}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.