]>
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>
36 #include <KIconLoader>
40 class EmbeddedVideoPlayer
: public Phonon::VideoWidget
43 EmbeddedVideoPlayer(QWidget
*parent
= 0) :
44 Phonon::VideoWidget(parent
)
48 void setSizeHint(const QSize
& size
)
54 virtual QSize
sizeHint() const
56 return m_sizeHint
.isValid() ? m_sizeHint
: Phonon::VideoWidget::sizeHint();
63 PhononWidget::PhononWidget(QWidget
*parent
)
76 void PhononWidget::setUrl(const KUrl
&url
)
79 stop(); // emits playingStopped() signal
84 KUrl
PhononWidget::url() const
89 void PhononWidget::setVideoSize(const QSize
& size
)
91 if (m_videoSize
!= size
) {
97 QSize
PhononWidget::videoSize() const
102 void PhononWidget::showEvent(QShowEvent
*event
)
104 if (event
->spontaneous()) {
105 QWidget::showEvent(event
);
110 m_topLayout
= new QVBoxLayout(this);
111 m_topLayout
->setMargin(0);
112 m_topLayout
->setSpacing(KDialog::spacingHint());
113 QHBoxLayout
*controlsLayout
= new QHBoxLayout(this);
114 controlsLayout
->setMargin(0);
115 controlsLayout
->setSpacing(0);
117 m_playButton
= new QToolButton(this);
118 m_stopButton
= new QToolButton(this);
119 m_seekSlider
= new Phonon::SeekSlider(this);
121 controlsLayout
->addWidget(m_playButton
);
122 controlsLayout
->addWidget(m_stopButton
);
123 controlsLayout
->addWidget(m_seekSlider
);
125 m_topLayout
->addLayout(controlsLayout
);
127 const int smallIconSize
= IconSize(KIconLoader::Small
);
128 const QSize
buttonSize(smallIconSize
, smallIconSize
);
130 m_playButton
->setToolTip(i18n("play"));
131 m_playButton
->setIconSize(buttonSize
);
132 m_playButton
->setIcon(KIcon("media-playback-start"));
133 m_playButton
->setAutoRaise(true);
134 connect(m_playButton
, &QToolButton::clicked
, this, &PhononWidget::play
);
136 m_stopButton
->setToolTip(i18n("stop"));
137 m_stopButton
->setIconSize(buttonSize
);
138 m_stopButton
->setIcon(KIcon("media-playback-stop"));
139 m_stopButton
->setAutoRaise(true);
140 m_stopButton
->hide();
141 connect(m_stopButton
, &QToolButton::clicked
, this, &PhononWidget::stop
);
143 m_seekSlider
->setIconVisible(false);
145 // Creating an audio player or video player instance might take up to
146 // 2 seconds when doing it the first time. To prevent that the user
147 // interface gets noticeable blocked, the creation is delayed until
148 // the play button has been pressed (see PhononWidget::play()).
152 void PhononWidget::hideEvent(QHideEvent
*event
)
154 QWidget::hideEvent(event
);
155 if (!event
->spontaneous()) {
160 void PhononWidget::stateChanged(Phonon::State newstate
)
162 setUpdatesEnabled(false);
164 case Phonon::PlayingState
:
165 case Phonon::BufferingState
:
166 m_stopButton
->show();
167 m_playButton
->hide();
170 m_stopButton
->hide();
171 m_playButton
->show();
174 setUpdatesEnabled(true);
177 void PhononWidget::play()
180 m_media
= new Phonon::MediaObject(this);
181 connect(m_media
, &Phonon::MediaObject::stateChanged
,
182 this, &PhononWidget::stateChanged
);
183 connect(m_media
, &Phonon::MediaObject::hasVideoChanged
,
184 this, &PhononWidget::slotHasVideoChanged
);
185 m_seekSlider
->setMediaObject(m_media
);
188 if (!m_audioOutput
) {
189 m_audioOutput
= new Phonon::AudioOutput(Phonon::MusicCategory
, this);
190 Phonon::createPath(m_media
, m_audioOutput
);
193 emit
hasVideoChanged(false);
195 m_media
->setCurrentSource(m_url
);
200 void PhononWidget::stop()
205 m_stopButton
->hide();
206 m_playButton
->show();
210 m_videoPlayer
->hide();
213 emit
hasVideoChanged(false);
216 void PhononWidget::slotHasVideoChanged(bool hasVideo
)
218 emit
hasVideoChanged(hasVideo
);
221 if (!m_videoPlayer
) {
222 // Replay the media to apply path changes
224 m_videoPlayer
= new EmbeddedVideoPlayer(this);
225 m_topLayout
->insertWidget(0, m_videoPlayer
);
226 Phonon::createPath(m_media
, m_videoPlayer
);
230 m_videoPlayer
->show();
234 void PhononWidget::applyVideoSize()
236 if ((m_videoPlayer
) && m_videoSize
.isValid()) {
237 m_videoPlayer
->setSizeHint(m_videoSize
);