File indexing completed on 2024-04-28 15:23:53
0001 /* 0002 * Copyright (C) 2009 Michael Howell <mhowell123@gmail.com>. 0003 * Copyright (C) 2009 Germain Garand <germain@ebooksfrance.org> 0004 * Parts copyright (C) 2007, 2008 Apple Inc. All rights reserved. 0005 * 0006 * Redistribution and use in source and binary forms, with or without 0007 * modification, are permitted provided that the following conditions 0008 * are met: 0009 * 1. Redistributions of source code must retain the above copyright 0010 * notice, this list of conditions and the following disclaimer. 0011 * 2. Redistributions in binary form must reproduce the above copyright 0012 * notice, this list of conditions and the following disclaimer in the 0013 * documentation and/or other materials provided with the distribution. 0014 * 0015 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 0016 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0017 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 0018 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 0019 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 0020 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 0021 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 0022 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 0023 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0024 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0025 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0026 */ 0027 0028 #include "media_controls.h" 0029 #include <QHBoxLayout> 0030 #include <phonon/seekslider.h> 0031 #include <rendering/render_media.h> 0032 #include <phonon/videowidget.h> 0033 #include <ktogglefullscreenaction.h> 0034 #include <klocalizedstring.h> 0035 0036 #include "config-khtml.h" 0037 0038 #if HAVE_KGLOBALACCEL 0039 #include <kglobalaccel.h> 0040 #endif 0041 0042 namespace khtml 0043 { 0044 0045 MediaControls::MediaControls(MediaPlayer *mediaPlayer, QWidget *parent) : QWidget(parent) 0046 { 0047 m_mediaPlayer = mediaPlayer; 0048 Phonon::MediaObject *mediaObject = m_mediaPlayer->mediaObject(); 0049 setLayout(new QHBoxLayout(this)); 0050 m_play = new QPushButton(QIcon::fromTheme("media-playback-start"), i18n("Play"), this); 0051 connect(m_play, SIGNAL(clicked()), mediaObject, SLOT(play())); 0052 layout()->addWidget(m_play); 0053 m_pause = new QPushButton(QIcon::fromTheme("media-playback-pause"), i18n("Pause"), this); 0054 connect(m_pause, SIGNAL(clicked()), mediaObject, SLOT(pause())); 0055 layout()->addWidget(m_pause); 0056 layout()->addWidget(new Phonon::SeekSlider(mediaObject, this)); 0057 QAction *fsac = new KToggleFullScreenAction(this); 0058 fsac->setObjectName("KHTMLMediaPlayerFullScreenAction"); // needed for global shortcut activation. 0059 m_fullscreen = new QToolButton(this); 0060 m_fullscreen->setDefaultAction(fsac); 0061 m_fullscreen->setCheckable(true); 0062 connect(fsac, SIGNAL(toggled(bool)), this, SLOT(slotToggled(bool))); 0063 layout()->addWidget(m_fullscreen); 0064 0065 slotStateChanged(mediaObject->state()); 0066 connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), SLOT(slotStateChanged(Phonon::State))); 0067 } 0068 0069 void MediaControls::slotToggled(bool t) 0070 { 0071 if (t) { 0072 m_mediaPlayer->videoWidget()->enterFullScreen(); 0073 #if HAVE_KGLOBALACCEL 0074 KGlobalAccel::self()->setShortcut(m_fullscreen->defaultAction(), QList<QKeySequence>() << Qt::Key_Escape); 0075 #endif 0076 } else { 0077 m_mediaPlayer->videoWidget()->exitFullScreen(); 0078 #if HAVE_KGLOBALACCEL 0079 KGlobalAccel::self()->removeAllShortcuts(m_fullscreen->defaultAction()); 0080 #endif 0081 } 0082 } 0083 0084 void MediaControls::slotStateChanged(Phonon::State state) 0085 { 0086 if (state == Phonon::PlayingState) { 0087 m_play->hide(); 0088 m_pause->show(); 0089 } else { 0090 m_pause->hide(); 0091 m_play->show(); 0092 } 0093 } 0094 0095 } 0096 0097 #include "moc_media_controls.cpp"