delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / phonon / tests / mediacontrols.cpp
blob84616205c727144c2d7cf24f9564d96d358aa5ab
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>
23 #include <kglobal.h>
24 #include <kiconloader.h>
25 #include <klocale.h>
26 #include <QtGui/QBoxLayout>
27 #include <QtGui/QToolButton>
28 #include <Phonon/SeekSlider>
29 #include <Phonon/VolumeSlider>
30 #include <kicon.h>
31 #include "mediacontrols_p.h"
33 namespace Phonon
36 MediaControls::MediaControls(QWidget *parent)
37 : QWidget(parent),
38 d_ptr(new MediaControlsPrivate(this))
40 setMaximumHeight(32);
43 MediaControls::~MediaControls()
45 delete d_ptr;
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)
68 Q_D(MediaControls);
69 if (d->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()));
78 d->media = media;
79 if (media) {
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)
94 Q_D(MediaControls);
95 d->volumeSlider.setAudioOutput(audioOutput);
96 d->volumeSlider.setVisible(audioOutput != 0);
99 void MediaControls::setSeekSliderVisible(bool vis)
101 Q_D(MediaControls);
102 d->seekSlider.setVisible(vis);
105 void MediaControls::setVolumeControlVisible(bool vis)
107 Q_D(MediaControls);
108 d->volumeSlider.setVisible(vis);
111 void MediaControls::setLoopControlVisible(bool vis)
113 Q_D(MediaControls);
114 d->loopButton.setVisible(vis);
117 void MediaControlsPrivate::_k_stateChanged(State newstate, State)
119 switch(newstate)
121 case Phonon::LoadingState:
122 case Phonon::PausedState:
123 case Phonon::StoppedState:
124 playButton.show();
125 pauseButton.hide();
126 break;
127 case Phonon::BufferingState:
128 case Phonon::PlayingState:
129 playButton.hide();
130 pauseButton.show();
131 break;
132 case Phonon::ErrorState:
133 return;
137 void MediaControlsPrivate::_k_mediaDestroyed()
139 media = 0;
142 void MediaControlsPrivate::_k_finished()
144 if (loopButton.isChecked()) {
145 Q_ASSERT(media->state() == Phonon::StoppedState);
146 media->play();
150 } // namespace Phonon
152 // vim: sw=4 ts=4