]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/phononwidget.cpp
1 /* This file is part of the KDE project
2 Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "phononwidget.h"
23 #include <Phonon/AudioOutput>
24 #include <Phonon/Global>
25 #include <Phonon/MediaObject>
26 #include <Phonon/SeekSlider>
27 #include <Phonon/VideoWidget>
29 #include <QVBoxLayout>
30 #include <QHBoxLayout>
32 #include <QToolButton>
35 #include <KIconLoader>
37 #include <KLocalizedString>
39 class EmbeddedVideoPlayer
: public Phonon::VideoWidget
42 EmbeddedVideoPlayer(QWidget
*parent
= 0) :
43 Phonon::VideoWidget(parent
)
47 void setSizeHint(const QSize
& size
)
53 virtual QSize
sizeHint() const
55 return m_sizeHint
.isValid() ? m_sizeHint
: Phonon::VideoWidget::sizeHint();
62 PhononWidget::PhononWidget(QWidget
*parent
)
75 void PhononWidget::setUrl(const QUrl
&url
)
78 stop(); // emits playingStopped() signal
83 QUrl
PhononWidget::url() const
88 void PhononWidget::setVideoSize(const QSize
& size
)
90 if (m_videoSize
!= size
) {
96 QSize
PhononWidget::videoSize() const
101 void PhononWidget::showEvent(QShowEvent
*event
)
103 if (event
->spontaneous()) {
104 QWidget::showEvent(event
);
109 m_topLayout
= new QVBoxLayout(this);
110 m_topLayout
->setMargin(0);
112 QHBoxLayout
*controlsLayout
= new QHBoxLayout(this);
113 controlsLayout
->setMargin(0);
114 controlsLayout
->setSpacing(0);
116 m_playButton
= new QToolButton(this);
117 m_stopButton
= new QToolButton(this);
118 m_seekSlider
= new Phonon::SeekSlider(this);
120 controlsLayout
->addWidget(m_playButton
);
121 controlsLayout
->addWidget(m_stopButton
);
122 controlsLayout
->addWidget(m_seekSlider
);
124 m_topLayout
->addLayout(controlsLayout
);
126 const int smallIconSize
= IconSize(KIconLoader::Small
);
127 const QSize
buttonSize(smallIconSize
, smallIconSize
);
129 m_playButton
->setToolTip(i18n("play"));
130 m_playButton
->setIconSize(buttonSize
);
131 m_playButton
->setIcon(QIcon::fromTheme("media-playback-start"));
132 m_playButton
->setAutoRaise(true);
133 connect(m_playButton
, &QToolButton::clicked
, this, &PhononWidget::play
);
135 m_stopButton
->setToolTip(i18n("stop"));
136 m_stopButton
->setIconSize(buttonSize
);
137 m_stopButton
->setIcon(QIcon::fromTheme("media-playback-stop"));
138 m_stopButton
->setAutoRaise(true);
139 m_stopButton
->hide();
140 connect(m_stopButton
, &QToolButton::clicked
, this, &PhononWidget::stop
);
142 m_seekSlider
->setIconVisible(false);
144 // Creating an audio player or video player instance might take up to
145 // 2 seconds when doing it the first time. To prevent that the user
146 // interface gets noticeable blocked, the creation is delayed until
147 // the play button has been pressed (see PhononWidget::play()).
151 void PhononWidget::hideEvent(QHideEvent
*event
)
153 QWidget::hideEvent(event
);
154 if (!event
->spontaneous()) {
159 void PhononWidget::stateChanged(Phonon::State newstate
)
161 setUpdatesEnabled(false);
163 case Phonon::PlayingState
:
164 case Phonon::BufferingState
:
165 m_stopButton
->show();
166 m_playButton
->hide();
168 case Phonon::StoppedState
:
170 m_videoPlayer
->hide();
172 emit
hasVideoChanged(false);
175 m_stopButton
->hide();
176 m_playButton
->show();
179 setUpdatesEnabled(true);
182 void PhononWidget::play()
185 m_media
= new Phonon::MediaObject(this);
186 connect(m_media
, &Phonon::MediaObject::stateChanged
,
187 this, &PhononWidget::stateChanged
);
188 connect(m_media
, &Phonon::MediaObject::hasVideoChanged
,
189 this, &PhononWidget::slotHasVideoChanged
);
190 m_seekSlider
->setMediaObject(m_media
);
193 if (!m_videoPlayer
) {
194 m_videoPlayer
= new EmbeddedVideoPlayer(this);
195 m_topLayout
->insertWidget(0, m_videoPlayer
);
196 Phonon::createPath(m_media
, m_videoPlayer
);
200 if (!m_audioOutput
) {
201 m_audioOutput
= new Phonon::AudioOutput(Phonon::MusicCategory
, this);
202 Phonon::createPath(m_media
, m_audioOutput
);
205 emit
hasVideoChanged(false);
207 m_media
->setCurrentSource(m_url
);
212 void PhononWidget::stop()
219 void PhononWidget::slotHasVideoChanged(bool hasVideo
)
221 emit
hasVideoChanged(hasVideo
);
224 m_videoPlayer
->show();
228 void PhononWidget::applyVideoSize()
230 if ((m_videoPlayer
) && m_videoSize
.isValid()) {
231 m_videoPlayer
->setSizeHint(m_videoSize
);