]>
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/Global>
24 #include <Phonon/MediaObject>
25 #include <Phonon/SeekSlider>
26 #include <Phonon/VideoPlayer>
27 #include <QtGui/QVBoxLayout>
28 #include <QtGui/QHBoxLayout>
29 #include <QtGui/QShowEvent>
30 #include <QtGui/QToolButton>
35 PhononWidget::PhononWidget(QWidget
*parent
)
47 void PhononWidget::setUrl(const KUrl
&url
)
50 stop(); // emits playingStopped() signal
52 m_videoPlayer
->hide();
56 KUrl
PhononWidget::url() const
61 void PhononWidget::setMode(Mode mode
)
64 stop(); // emits playingStopped() signal
67 if (m_mode
== Audio
) {
68 m_videoPlayer
->hide();
74 PhononWidget::Mode
PhononWidget::mode() const
79 void PhononWidget::showEvent(QShowEvent
*event
)
81 if (event
->spontaneous()) {
82 QWidget::showEvent(event
);
86 if (m_playButton
== 0) {
87 QVBoxLayout
*topLayout
= new QVBoxLayout(this);
88 topLayout
->setMargin(0);
89 topLayout
->setSpacing(0);
90 QHBoxLayout
*controlsLayout
= new QHBoxLayout(this);
91 controlsLayout
->setMargin(0);
92 controlsLayout
->setSpacing(0);
94 m_playButton
= new QToolButton(this);
95 m_stopButton
= new QToolButton(this);
96 m_seekSlider
= new Phonon::SeekSlider(this);
97 m_videoPlayer
= new Phonon::VideoPlayer(Phonon::VideoCategory
, this);
98 m_videoPlayer
->hide();
100 controlsLayout
->addWidget(m_playButton
);
101 controlsLayout
->addWidget(m_stopButton
);
102 controlsLayout
->addWidget(m_seekSlider
);
104 topLayout
->addWidget(m_videoPlayer
);
105 topLayout
->addLayout(controlsLayout
);
107 m_playButton
->setToolTip(i18n("play"));
108 m_playButton
->setIconSize(QSize(16, 16));
109 m_playButton
->setIcon(KIcon("media-playback-start"));
110 connect(m_playButton
, SIGNAL(clicked()), this, SLOT(play()));
112 m_stopButton
->setToolTip(i18n("stop"));
113 m_stopButton
->setIconSize(QSize(16, 16));
114 m_stopButton
->setIcon(KIcon("media-playback-stop"));
115 m_stopButton
->hide();
116 connect(m_stopButton
, SIGNAL(clicked()), this, SLOT(stop()));
118 m_seekSlider
->setIconVisible(false);
122 void PhononWidget::hideEvent(QHideEvent
*event
)
124 QWidget::hideEvent(event
);
125 if (!event
->spontaneous()) {
127 if (m_videoPlayer
!= 0) {
128 m_videoPlayer
->hide();
133 void PhononWidget::stateChanged(Phonon::State newstate
)
135 setUpdatesEnabled(false);
137 case Phonon::PlayingState
:
138 case Phonon::BufferingState
:
139 m_stopButton
->show();
140 m_playButton
->hide();
143 m_stopButton
->hide();
144 m_playButton
->show();
147 setUpdatesEnabled(true);
150 void PhononWidget::play()
155 m_media
= Phonon::createPlayer(Phonon::MusicCategory
, m_url
);
156 m_media
->setParent(this);
158 m_media
->setCurrentSource(m_url
);
162 m_videoPlayer
->show();
163 m_videoPlayer
->play(m_url
);
164 m_media
= m_videoPlayer
->mediaObject();
171 Q_ASSERT(m_media
!= 0);
172 connect(m_media
, SIGNAL(stateChanged(Phonon::State
, Phonon::State
)),
173 this, SLOT(stateChanged(Phonon::State
)));
174 m_seekSlider
->setMediaObject(m_media
);
176 emit
playingStarted();
179 void PhononWidget::stop()
183 disconnect(m_media
, SIGNAL(stateChanged(Phonon::State
, Phonon::State
)),
184 this, SLOT(stateChanged(Phonon::State
)));
185 emit
playingStopped();
187 m_stopButton
->hide();
188 m_playButton
->show();