KHtml

media_controls.cpp
1 /*
2  * Copyright (C) 2009 Michael Howell <[email protected]>.
3  * Copyright (C) 2009 Germain Garand <[email protected]>
4  * Parts copyright (C) 2007, 2008 Apple Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "media_controls.h"
29 #include <QHBoxLayout>
30 #include <phonon/seekslider.h>
31 #include <rendering/render_media.h>
32 #include <phonon/videowidget.h>
33 #include <ktogglefullscreenaction.h>
34 #include <kglobalaccel.h>
35 #include <klocalizedstring.h>
36 
37 namespace khtml
38 {
39 
40 MediaControls::MediaControls(MediaPlayer *mediaPlayer, QWidget *parent) : QWidget(parent)
41 {
42  m_mediaPlayer = mediaPlayer;
43  Phonon::MediaObject *mediaObject = m_mediaPlayer->mediaObject();
44  setLayout(new QHBoxLayout(this));
45  m_play = new QPushButton(QIcon::fromTheme("media-playback-start"), i18n("Play"), this);
46  connect(m_play, SIGNAL(clicked()), mediaObject, SLOT(play()));
47  layout()->addWidget(m_play);
48  m_pause = new QPushButton(QIcon::fromTheme("media-playback-pause"), i18n("Pause"), this);
49  connect(m_pause, SIGNAL(clicked()), mediaObject, SLOT(pause()));
50  layout()->addWidget(m_pause);
51  layout()->addWidget(new Phonon::SeekSlider(mediaObject, this));
52  QAction *fsac = new KToggleFullScreenAction(this);
53  fsac->setObjectName("KHTMLMediaPlayerFullScreenAction"); // needed for global shortcut activation.
54  m_fullscreen = new QToolButton(this);
55  m_fullscreen->setDefaultAction(fsac);
56  m_fullscreen->setCheckable(true);
57  connect(fsac, SIGNAL(toggled(bool)), this, SLOT(slotToggled(bool)));
58  layout()->addWidget(m_fullscreen);
59 
60  slotStateChanged(mediaObject->state());
61  connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), SLOT(slotStateChanged(Phonon::State)));
62 }
63 
64 void MediaControls::slotToggled(bool t)
65 {
66  if (t) {
67  m_mediaPlayer->videoWidget()->enterFullScreen();
68  KGlobalAccel::self()->setShortcut(m_fullscreen->defaultAction(), QList<QKeySequence>() << Qt::Key_Escape);
69  } else {
70  m_mediaPlayer->videoWidget()->exitFullScreen();
71  KGlobalAccel::self()->removeAllShortcuts(m_fullscreen->defaultAction());
72  }
73 }
74 
75 void MediaControls::slotStateChanged(Phonon::State state)
76 {
77  if (state == Phonon::PlayingState) {
78  m_play->hide();
79  m_pause->show();
80  } else {
81  m_pause->hide();
82  m_play->show();
83  }
84 }
85 
86 }
87 
void removeAllShortcuts(QAction *action)
This file is part of the HTML rendering engine for KDE.
KToggleAction * pause(const QObject *recvr, const char *slot, QObject *parent)
void setObjectName(const QString &name)
State state() const
QString i18n(const char *text, const TYPE &arg...)
static KGlobalAccel * self()
QIcon fromTheme(const QString &name)
bool setShortcut(QAction *action, const QList< QKeySequence > &shortcut, GlobalShortcutLoading loadFlag=Autoloading)
Key_Escape
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:06 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.