|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qsoundeffect.h" |
|
43 |
|
44 #if defined(QT_MULTIMEDIA_PULSEAUDIO) |
|
45 #include "qsoundeffect_pulse_p.h" |
|
46 #elif(QT_MULTIMEDIA_QMEDIAPLAYER) |
|
47 #include "qsoundeffect_qmedia_p.h" |
|
48 #else |
|
49 #include "qsoundeffect_qsound_p.h" |
|
50 #endif |
|
51 |
|
52 QT_BEGIN_NAMESPACE |
|
53 |
|
54 /*! |
|
55 \qmlclass SoundEffect QSoundEffect |
|
56 \brief The SoundEffect element provides a way to play sound effects in QML. |
|
57 |
|
58 This element is part of the \bold{Qt.multimedia 1.0} module. |
|
59 |
|
60 The following example plays a wav file on mouse click. |
|
61 |
|
62 \qml |
|
63 import Qt 4.7 |
|
64 import Qt.multimedia 1.0 |
|
65 |
|
66 Text { |
|
67 text: "Click Me!"; |
|
68 font.pointSize: 24; |
|
69 width: 150; height: 50; |
|
70 |
|
71 SoundEffect { |
|
72 id: playSound |
|
73 source: "soundeffect.wav" |
|
74 } |
|
75 MouseArea { |
|
76 id: playArea |
|
77 anchors.fill: parent |
|
78 onPressed: { playSound.play() } |
|
79 } |
|
80 } |
|
81 \endqml |
|
82 */ |
|
83 |
|
84 /*! |
|
85 \qmlproperty url SoundEffect::source |
|
86 |
|
87 This property provides a way to control the sound to play. |
|
88 */ |
|
89 |
|
90 /*! |
|
91 \qmlproperty int SoundEffect::loops |
|
92 |
|
93 This property provides a way to control the number of times to repeat the sound on each play(). |
|
94 */ |
|
95 |
|
96 /*! |
|
97 \qmlproperty int SoundEffect::volume |
|
98 |
|
99 This property provides a way to control the volume for playback. |
|
100 */ |
|
101 |
|
102 /*! |
|
103 \qmlproperty bool SoundEffect::muted |
|
104 |
|
105 This property provides a way to control muting. |
|
106 */ |
|
107 |
|
108 /*! |
|
109 \qmlsignal SoundEffect::sourceChanged() |
|
110 |
|
111 This handler is called when the source has changed. |
|
112 */ |
|
113 |
|
114 /*! |
|
115 \qmlsignal SoundEffect::loopsChanged() |
|
116 |
|
117 This handler is called when the number of loops has changes. |
|
118 */ |
|
119 |
|
120 /*! |
|
121 \qmlsignal SoundEffect::volumeChanged() |
|
122 |
|
123 This handler is called when the volume has changed. |
|
124 */ |
|
125 |
|
126 /*! |
|
127 \qmlsignal SoundEffect::mutedChanged() |
|
128 |
|
129 This handler is called when the mute state has changed. |
|
130 */ |
|
131 |
|
132 /*! |
|
133 \internal |
|
134 */ |
|
135 |
|
136 QSoundEffect::QSoundEffect(QObject *parent) : |
|
137 QObject(parent) |
|
138 { |
|
139 d = new QSoundEffectPrivate(this); |
|
140 connect(d, SIGNAL(volumeChanged()), SIGNAL(volumeChanged())); |
|
141 connect(d, SIGNAL(mutedChanged()), SIGNAL(mutedChanged())); |
|
142 } |
|
143 |
|
144 QSoundEffect::~QSoundEffect() |
|
145 { |
|
146 d->deleteLater(); |
|
147 } |
|
148 |
|
149 QUrl QSoundEffect::source() const |
|
150 { |
|
151 return d->source(); |
|
152 } |
|
153 |
|
154 void QSoundEffect::setSource(const QUrl &url) |
|
155 { |
|
156 if (d->source() == url) |
|
157 return; |
|
158 |
|
159 d->setSource(url); |
|
160 |
|
161 emit sourceChanged(); |
|
162 } |
|
163 |
|
164 int QSoundEffect::loops() const |
|
165 { |
|
166 return d->loopCount(); |
|
167 } |
|
168 |
|
169 void QSoundEffect::setLoops(int loopCount) |
|
170 { |
|
171 if (d->loopCount() == loopCount) |
|
172 return; |
|
173 |
|
174 d->setLoopCount(loopCount); |
|
175 emit loopsChanged(); |
|
176 } |
|
177 |
|
178 int QSoundEffect::volume() const |
|
179 { |
|
180 return d->volume(); |
|
181 } |
|
182 |
|
183 void QSoundEffect::setVolume(int volume) |
|
184 { |
|
185 if (d->volume() == volume) |
|
186 return; |
|
187 |
|
188 d->setVolume(volume); |
|
189 emit volumeChanged(); |
|
190 } |
|
191 |
|
192 bool QSoundEffect::isMuted() const |
|
193 { |
|
194 return d->isMuted(); |
|
195 } |
|
196 |
|
197 void QSoundEffect::setMuted(bool muted) |
|
198 { |
|
199 if (d->isMuted() == muted) |
|
200 return; |
|
201 |
|
202 d->setMuted(muted); |
|
203 emit mutedChanged(); |
|
204 } |
|
205 |
|
206 void QSoundEffect::play() |
|
207 { |
|
208 d->play(); |
|
209 } |
|
210 |
|
211 QT_END_NAMESPACE |