1/* 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 3 * 4 * 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 "config.h" 29#include "FullScreenVideoWidget.h" 30 31#include <QApplication> 32#include <QCloseEvent> 33#include <QDesktopWidget> 34#include <QKeyEvent> 35#include <QMediaPlayer> 36 37static const int gHideMouseCursorDelay = 3000; 38 39namespace WebKit { 40 41FullScreenVideoWidget::FullScreenVideoWidget() 42 : QVideoWidget() 43 , m_mediaPlayer(0) 44{ 45 QPalette palette(this->palette()); 46 palette.setColor(QPalette::Base, Qt::black); 47 palette.setColor(QPalette::Background, Qt::black); 48 setPalette(palette); 49 50 setWindowModality(Qt::ApplicationModal); 51 setWindowFlags(windowFlags() | Qt::FramelessWindowHint); 52 53 setGeometry(QApplication::desktop()->screenGeometry()); 54 55 m_cursorTimer.setSingleShot(true); 56 connect(&m_cursorTimer, SIGNAL(timeout()), this, SLOT(hideCursor())); 57} 58 59FullScreenVideoWidget::~FullScreenVideoWidget() 60{ 61} 62 63void FullScreenVideoWidget::show(QMediaPlayer* player) 64{ 65 m_mediaPlayer = player; 66 showFullScreen(); 67 setMouseTracking(true); 68 raise(); 69 m_mediaPlayer->setVideoOutput(this); 70 setFocus(); 71 grabMouse(); 72 hideCursor(); 73} 74 75void FullScreenVideoWidget::closeEvent(QCloseEvent* event) 76{ 77 m_mediaPlayer = 0; 78 m_cursorTimer.stop(); 79 setMouseTracking(false); 80 releaseMouse(); 81 QApplication::restoreOverrideCursor(); 82 event->ignore(); 83 hide(); 84 emit didExitFullScreen(); 85} 86 87bool FullScreenVideoWidget::event(QEvent* ev) 88{ 89 switch (ev->type()) { 90 case QEvent::MouseMove: 91 showCursor(); 92 ev->accept(); 93 return true; 94 case QEvent::MouseButtonDblClick: 95 close(); 96 ev->accept(); 97 return true; 98 default: 99 return QVideoWidget::event(ev); 100 } 101} 102 103void FullScreenVideoWidget::keyPressEvent(QKeyEvent* ev) 104{ 105 if (m_mediaPlayer && ev->key() == Qt::Key_Space) { 106 if (m_mediaPlayer->state() == QMediaPlayer::PlayingState) 107 m_mediaPlayer->pause(); 108 else 109 m_mediaPlayer->play(); 110 } else if (ev->key() == Qt::Key_Escape) 111 close(); 112} 113 114void FullScreenVideoWidget::hideCursor() 115{ 116 QApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); 117} 118 119void FullScreenVideoWidget::showCursor() 120{ 121 QApplication::restoreOverrideCursor(); 122 m_cursorTimer.start(gHideMouseCursorDelay); 123} 124 125} 126