|
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 "slideshow.h" |
|
43 |
|
44 #include <qmediaservice.h> |
|
45 #include <qmediaplaylist.h> |
|
46 #include <qvideowidget.h> |
|
47 |
|
48 #include <QtGui> |
|
49 |
|
50 SlideShow::SlideShow(QWidget *parent) |
|
51 : QWidget(parent) |
|
52 , imageViewer(0) |
|
53 , playlist(0) |
|
54 , imageLabel(0) |
|
55 , playButton(0) |
|
56 , stopButton(0) |
|
57 { |
|
58 imageViewer = new QMediaImageViewer(this); |
|
59 |
|
60 connect(imageViewer, SIGNAL(stateChanged(QMediaImageViewer::State)), |
|
61 this, SLOT(stateChanged(QMediaImageViewer::State))); |
|
62 |
|
63 playlist = new QMediaPlaylist; |
|
64 playlist->setMediaObject(imageViewer); |
|
65 |
|
66 QVideoWidget *videoWidget = new QVideoWidget; |
|
67 videoWidget->setMediaObject(imageViewer); |
|
68 |
|
69 QMenu *openMenu = new QMenu(this); |
|
70 openMenu->addAction(tr("Directory..."), this, SLOT(openDirectory())); |
|
71 openMenu->addAction(tr("Playlist..."), this, SLOT(openPlaylist())); |
|
72 openMenu->addAction(tr("Location..."), this, SLOT(openLocation())); |
|
73 |
|
74 QToolButton *openButton = new QToolButton; |
|
75 openButton->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton)); |
|
76 openButton->setMenu(openMenu); |
|
77 openButton->setPopupMode(QToolButton::InstantPopup); |
|
78 |
|
79 playButton = new QToolButton; |
|
80 playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); |
|
81 |
|
82 connect(playButton, SIGNAL(clicked()), this, SLOT(play())); |
|
83 |
|
84 stopButton = new QToolButton; |
|
85 stopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop)); |
|
86 stopButton->setEnabled(false); |
|
87 |
|
88 connect(stopButton, SIGNAL(clicked()), imageViewer, SLOT(stop())); |
|
89 |
|
90 QAbstractButton *nextButton = new QToolButton; |
|
91 nextButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipForward)); |
|
92 |
|
93 connect(nextButton, SIGNAL(clicked()), playlist, SLOT(next())); |
|
94 |
|
95 QAbstractButton *previousButton = new QToolButton; |
|
96 previousButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipBackward)); |
|
97 |
|
98 connect(previousButton, SIGNAL(clicked()), playlist, SLOT(previous())); |
|
99 |
|
100 QBoxLayout *controlLayout = new QHBoxLayout; |
|
101 controlLayout->setMargin(0); |
|
102 controlLayout->addWidget(openButton); |
|
103 controlLayout->addStretch(1); |
|
104 controlLayout->addWidget(previousButton); |
|
105 controlLayout->addWidget(stopButton); |
|
106 controlLayout->addWidget(playButton); |
|
107 controlLayout->addWidget(nextButton); |
|
108 controlLayout->addStretch(1); |
|
109 |
|
110 QBoxLayout *layout = new QVBoxLayout; |
|
111 layout->addWidget(videoWidget, Qt::AlignCenter); |
|
112 layout->addLayout(controlLayout); |
|
113 |
|
114 setLayout(layout); |
|
115 |
|
116 } |
|
117 |
|
118 void SlideShow::openPlaylist() |
|
119 { |
|
120 QString path = QFileDialog::getOpenFileName(this); |
|
121 |
|
122 if (!path.isEmpty()) { |
|
123 #ifndef Q_OS_WIN |
|
124 playlist->load(QUrl(QLatin1String("file://") + path)); |
|
125 #else |
|
126 playlist->load(QUrl(QLatin1String("file:///") + path)); |
|
127 #endif |
|
128 } |
|
129 } |
|
130 |
|
131 void SlideShow::openDirectory() |
|
132 { |
|
133 QString path = QFileDialog::getExistingDirectory(this); |
|
134 |
|
135 if (!path.isEmpty()) { |
|
136 playlist->clear(); |
|
137 |
|
138 QDir dir(path); |
|
139 |
|
140 foreach (const QString &fileName, dir.entryList(QDir::Files)) { |
|
141 QString absolutePath = dir.absoluteFilePath(fileName); |
|
142 #ifndef Q_OS_WIN |
|
143 playlist->addMedia(QUrl(QLatin1String("file://") + absolutePath)); |
|
144 #else |
|
145 playlist->addMedia(QUrl(QLatin1String("file:///") + absolutePath)); |
|
146 #endif |
|
147 } |
|
148 } |
|
149 } |
|
150 |
|
151 void SlideShow::openLocation() |
|
152 { |
|
153 QLineEdit *urlEdit = new QLineEdit; |
|
154 |
|
155 QDialogButtonBox *buttons = new QDialogButtonBox( |
|
156 QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
|
157 |
|
158 QFormLayout *layout = new QFormLayout; |
|
159 layout->addRow(tr("Location"), urlEdit); |
|
160 layout->addWidget(buttons); |
|
161 |
|
162 QDialog dialog(this); |
|
163 dialog.setLayout(layout); |
|
164 |
|
165 connect(urlEdit, SIGNAL(returnPressed()), &dialog, SLOT(accept())); |
|
166 connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept())); |
|
167 connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject())); |
|
168 |
|
169 if (dialog.exec() == QDialog::Accepted) { |
|
170 QUrl url(urlEdit->text()); |
|
171 |
|
172 if (url.isValid()) |
|
173 playlist->load(url); |
|
174 } |
|
175 } |
|
176 |
|
177 void SlideShow::play() |
|
178 { |
|
179 switch (imageViewer->state()) { |
|
180 case QMediaImageViewer::StoppedState: |
|
181 case QMediaImageViewer::PausedState: |
|
182 imageViewer->play(); |
|
183 break; |
|
184 case QMediaImageViewer::PlayingState: |
|
185 imageViewer->pause(); |
|
186 break; |
|
187 } |
|
188 } |
|
189 |
|
190 void SlideShow::stateChanged(QMediaImageViewer::State state) |
|
191 { |
|
192 switch (state) { |
|
193 case QMediaImageViewer::StoppedState: |
|
194 stopButton->setEnabled(false); |
|
195 playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); |
|
196 break; |
|
197 case QMediaImageViewer::PlayingState: |
|
198 stopButton->setEnabled(true); |
|
199 playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); |
|
200 break; |
|
201 case QMediaImageViewer::PausedState: |
|
202 stopButton->setEnabled(true); |
|
203 playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); |
|
204 break; |
|
205 } |
|
206 } |