|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 "playercontrols.h" |
|
43 |
|
44 #include <QtGui/qboxlayout.h> |
|
45 #include <QtGui/qslider.h> |
|
46 #include <QtGui/qstyle.h> |
|
47 #include <QtGui/qtoolbutton.h> |
|
48 #include <QtGui/qcombobox.h> |
|
49 |
|
50 PlayerControls::PlayerControls(QWidget *parent) |
|
51 : QWidget(parent) |
|
52 , playerState(QMediaPlayer::StoppedState) |
|
53 , playerMuted(false) |
|
54 , playButton(0) |
|
55 , stopButton(0) |
|
56 , nextButton(0) |
|
57 , previousButton(0) |
|
58 , muteButton(0) |
|
59 #ifdef Q_OS_SYMBIAN |
|
60 , openButton(0) |
|
61 , fullScreenButton(0) |
|
62 , playListButton(0) |
|
63 #else |
|
64 , volumeSlider(0) |
|
65 , rateBox(0) |
|
66 #endif |
|
67 { |
|
68 playButton = new QToolButton; |
|
69 playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); |
|
70 |
|
71 connect(playButton, SIGNAL(clicked()), this, SLOT(playClicked())); |
|
72 |
|
73 stopButton = new QToolButton; |
|
74 stopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop)); |
|
75 stopButton->setEnabled(false); |
|
76 |
|
77 connect(stopButton, SIGNAL(clicked()), this, SIGNAL(stop())); |
|
78 |
|
79 nextButton = new QToolButton; |
|
80 nextButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipForward)); |
|
81 |
|
82 connect(nextButton, SIGNAL(clicked()), this, SIGNAL(next())); |
|
83 |
|
84 previousButton = new QToolButton; |
|
85 previousButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipBackward)); |
|
86 |
|
87 connect(previousButton, SIGNAL(clicked()), this, SIGNAL(previous())); |
|
88 |
|
89 muteButton = new QToolButton; |
|
90 muteButton->setIcon(style()->standardIcon(QStyle::SP_MediaVolume)); |
|
91 |
|
92 connect(muteButton, SIGNAL(clicked()), this, SLOT(muteClicked())); |
|
93 |
|
94 #ifdef Q_OS_SYMBIAN |
|
95 #else |
|
96 volumeSlider = new QSlider(Qt::Horizontal); |
|
97 volumeSlider->setRange(0, 100); |
|
98 |
|
99 connect(volumeSlider, SIGNAL(sliderMoved(int)), this, SIGNAL(changeVolume(int))); |
|
100 |
|
101 rateBox = new QComboBox; |
|
102 rateBox->addItem("0.5x", QVariant(0.5)); |
|
103 rateBox->addItem("1.0x", QVariant(1.0)); |
|
104 rateBox->addItem("2.0x", QVariant(2.0)); |
|
105 rateBox->setCurrentIndex(1); |
|
106 |
|
107 connect(rateBox, SIGNAL(activated(int)), SLOT(updateRate())); |
|
108 |
|
109 #endif |
|
110 #ifdef Q_OS_SYMBIAN |
|
111 playButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); |
|
112 playButton->setMinimumSize(1, 1); |
|
113 stopButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); |
|
114 stopButton->setMinimumSize(1, 1); |
|
115 nextButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); |
|
116 nextButton->setMinimumSize(1, 1); |
|
117 previousButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); |
|
118 previousButton->setMinimumSize(1, 1); |
|
119 muteButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); |
|
120 muteButton->setMinimumSize(1, 1); |
|
121 |
|
122 openButton = new QToolButton(this); |
|
123 openButton->setIcon(style()->standardIcon(QStyle::SP_DirOpenIcon)); |
|
124 openButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); |
|
125 openButton->setMinimumSize(1, 1); |
|
126 connect(openButton, SIGNAL(clicked()), this, SIGNAL(open())); |
|
127 |
|
128 fullScreenButton = new QToolButton(this); |
|
129 fullScreenButton->setIcon(style()->standardIcon(QStyle::SP_DesktopIcon)); |
|
130 fullScreenButton->setCheckable(true); |
|
131 fullScreenButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); |
|
132 fullScreenButton->setMinimumSize(1, 1); |
|
133 connect(fullScreenButton, SIGNAL(clicked(bool)), this, SIGNAL(fullScreen(bool))); |
|
134 |
|
135 playListButton = new QToolButton(this); |
|
136 playListButton->setIcon(style()->standardIcon(QStyle::SP_FileDialogDetailedView)); |
|
137 playListButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); |
|
138 playListButton->setMinimumSize(1, 1); |
|
139 connect(playListButton, SIGNAL(clicked(bool)), this, SIGNAL(openPlayList())); |
|
140 |
|
141 #endif |
|
142 |
|
143 QBoxLayout *layout = new QHBoxLayout; |
|
144 layout->setMargin(0); |
|
145 layout->addWidget(stopButton); |
|
146 layout->addWidget(previousButton); |
|
147 layout->addWidget(playButton); |
|
148 layout->addWidget(nextButton); |
|
149 layout->addWidget(muteButton); |
|
150 #ifdef Q_OS_SYMBIAN |
|
151 layout->addWidget(openButton); |
|
152 layout->addWidget(playListButton); |
|
153 layout->addWidget(fullScreenButton); |
|
154 #else |
|
155 layout->addWidget(volumeSlider); |
|
156 layout->addWidget(rateBox); |
|
157 #endif |
|
158 setLayout(layout); |
|
159 } |
|
160 |
|
161 QMediaPlayer::State PlayerControls::state() const |
|
162 { |
|
163 return playerState; |
|
164 } |
|
165 |
|
166 void PlayerControls::setState(QMediaPlayer::State state) |
|
167 { |
|
168 if (state != playerState) { |
|
169 playerState = state; |
|
170 |
|
171 switch (state) { |
|
172 case QMediaPlayer::StoppedState: |
|
173 stopButton->setEnabled(false); |
|
174 playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); |
|
175 break; |
|
176 case QMediaPlayer::PlayingState: |
|
177 stopButton->setEnabled(true); |
|
178 playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); |
|
179 break; |
|
180 case QMediaPlayer::PausedState: |
|
181 stopButton->setEnabled(true); |
|
182 playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); |
|
183 break; |
|
184 } |
|
185 } |
|
186 } |
|
187 |
|
188 int PlayerControls::volume() const |
|
189 { |
|
190 #ifdef Q_OS_SYMBIAN |
|
191 return 0; |
|
192 #else |
|
193 return volumeSlider->value(); |
|
194 #endif |
|
195 } |
|
196 |
|
197 void PlayerControls::setVolume(int volume) |
|
198 { |
|
199 #ifdef Q_OS_SYMBIAN |
|
200 #else |
|
201 volumeSlider->setValue(volume); |
|
202 #endif |
|
203 } |
|
204 |
|
205 bool PlayerControls::isMuted() const |
|
206 { |
|
207 return playerMuted; |
|
208 } |
|
209 |
|
210 void PlayerControls::setMuted(bool muted) |
|
211 { |
|
212 if (muted != playerMuted) { |
|
213 playerMuted = muted; |
|
214 |
|
215 muteButton->setIcon(style()->standardIcon(muted |
|
216 ? QStyle::SP_MediaVolumeMuted |
|
217 : QStyle::SP_MediaVolume)); |
|
218 } |
|
219 } |
|
220 |
|
221 void PlayerControls::playClicked() |
|
222 { |
|
223 switch (playerState) { |
|
224 case QMediaPlayer::StoppedState: |
|
225 case QMediaPlayer::PausedState: |
|
226 emit play(); |
|
227 break; |
|
228 case QMediaPlayer::PlayingState: |
|
229 emit pause(); |
|
230 break; |
|
231 } |
|
232 } |
|
233 |
|
234 void PlayerControls::muteClicked() |
|
235 { |
|
236 emit changeMuting(!playerMuted); |
|
237 } |
|
238 |
|
239 qreal PlayerControls::playbackRate() const |
|
240 { |
|
241 #ifdef Q_OS_SYMBIAN |
|
242 return 0; |
|
243 #else |
|
244 return rateBox->itemData(rateBox->currentIndex()).toDouble(); |
|
245 #endif |
|
246 } |
|
247 |
|
248 void PlayerControls::setPlaybackRate(float rate) |
|
249 { |
|
250 #ifdef Q_OS_SYMBIAN |
|
251 #else |
|
252 for (int i=0; i<rateBox->count(); i++) { |
|
253 if (qFuzzyCompare(rate, float(rateBox->itemData(i).toDouble()))) { |
|
254 rateBox->setCurrentIndex(i); |
|
255 return; |
|
256 } |
|
257 } |
|
258 |
|
259 rateBox->addItem( QString("%1x").arg(rate), QVariant(rate)); |
|
260 rateBox->setCurrentIndex(rateBox->count()-1); |
|
261 #endif |
|
262 } |
|
263 |
|
264 void PlayerControls::updateRate() |
|
265 { |
|
266 #ifdef Q_OS_SYMBIAN |
|
267 #else |
|
268 emit changeRate(playbackRate()); |
|
269 #endif |
|
270 } |