1 /* This file is part of the KDE project
2 Copyright (C) 2006 Matthias Kretz <kretz@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
20 #include "mediacontrols.h"
21 #include <Phonon/MediaObject>
22 #include <Phonon/AudioOutput>
24 #include <kiconloader.h>
26 #include <QtGui/QBoxLayout>
27 #include <QtGui/QToolButton>
28 #include <Phonon/SeekSlider>
29 #include <Phonon/VolumeSlider>
31 #include "mediacontrols_p.h"
36 MediaControls::MediaControls(QWidget
*parent
)
38 d_ptr(new MediaControlsPrivate(this))
43 MediaControls::~MediaControls()
48 bool MediaControls::isSeekSliderVisible() const
50 Q_D(const MediaControls
);
51 return d
->seekSlider
.isVisible();
54 bool MediaControls::isVolumeControlVisible() const
56 Q_D(const MediaControls
);
57 return d
->volumeSlider
.isVisible();
60 bool MediaControls::isLoopControlVisible() const
62 Q_D(const MediaControls
);
63 return d
->loopButton
.isVisible();
66 void MediaControls::setMediaObject(MediaObject
*media
)
70 disconnect(d
->media
, SIGNAL(destroyed()), this, SLOT(_k_mediaDestroyed()));
71 disconnect(d
->media
, SIGNAL(stateChanged(Phonon::State
, Phonon::State
)), this,
72 SLOT(_k_stateChanged(Phonon::State
, Phonon::State
)));
73 disconnect(d
->media
, SIGNAL(finished()), this, SLOT(_k_finished()));
74 disconnect(&d
->playButton
, SIGNAL(clicked()), d
->media
, SLOT(play()));
75 disconnect(&d
->pauseButton
, SIGNAL(clicked()), d
->media
, SLOT(pause()));
76 disconnect(&d
->stopButton
, SIGNAL(clicked()), d
->media
, SLOT(stop()));
80 connect(media
, SIGNAL(destroyed()), SLOT(_k_mediaDestroyed()));
81 connect(media
, SIGNAL(stateChanged(Phonon::State
, Phonon::State
)),
82 SLOT(_k_stateChanged(Phonon::State
, Phonon::State
)));
83 connect(d
->media
, SIGNAL(finished()), this, SLOT(_k_finished()));
84 connect(&d
->playButton
, SIGNAL(clicked()), media
, SLOT(play()));
85 connect(&d
->pauseButton
, SIGNAL(clicked()), media
, SLOT(pause()));
86 connect(&d
->stopButton
, SIGNAL(clicked()), media
, SLOT(stop()));
89 d
->seekSlider
.setMediaObject(media
);
92 void MediaControls::setAudioOutput(AudioOutput
*audioOutput
)
95 d
->volumeSlider
.setAudioOutput(audioOutput
);
96 d
->volumeSlider
.setVisible(audioOutput
!= 0);
99 void MediaControls::setSeekSliderVisible(bool vis
)
102 d
->seekSlider
.setVisible(vis
);
105 void MediaControls::setVolumeControlVisible(bool vis
)
108 d
->volumeSlider
.setVisible(vis
);
111 void MediaControls::setLoopControlVisible(bool vis
)
114 d
->loopButton
.setVisible(vis
);
117 void MediaControlsPrivate::_k_stateChanged(State newstate
, State
)
121 case Phonon::LoadingState
:
122 case Phonon::PausedState
:
123 case Phonon::StoppedState
:
127 case Phonon::BufferingState
:
128 case Phonon::PlayingState
:
132 case Phonon::ErrorState
:
137 void MediaControlsPrivate::_k_mediaDestroyed()
142 void MediaControlsPrivate::_k_finished()
144 if (loopButton
.isChecked()) {
145 Q_ASSERT(media
->state() == Phonon::StoppedState
);
150 } // namespace Phonon