📄 videowidget.cpp
字号:
/************************************************************************ Copyright (C) 2000-2002 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include <qtopia/resource.h>#include <qtopia/mediaplayerplugininterface.h>#include <qwidget.h>#include <qpainter.h>#include <qpixmap.h>#include <qslider.h>#include <qdrawutil.h>#include "imageutil.h"#include "videowidget.h"#include "mediaplayerstate.h"#include "maindocumentwidgetstack.h"#ifdef Q_WS_QWS# define HAVE_PIXMAP_BITS# define USE_DIRECT_PAINTER# include <qdirectpainter_qws.h># include <qgfxraster_qws.h>#endif// Layout information for the videoButtons (and if it is a toggle button or not)MediaButton videoButtons[] = { { FALSE, FALSE, FALSE, FALSE, "previous", PreviousButton }, // No tr { FALSE, FALSE, FALSE, FALSE, "backward", BackwardButton }, // No tr { TRUE, FALSE, FALSE, FALSE, "play", PlayButton }, // No tr { FALSE, FALSE, FALSE, FALSE, "forward", ForwardButton }, // No tr { FALSE, FALSE, FALSE, FALSE, "next", NextButton }, // No tr { TRUE, FALSE, FALSE, FALSE, "loop", LoopButton }, // No tr // { TRUE, FALSE, FALSE, FALSE, "fullscreen", FullscreenButton },};/* XPM */static const char * turnup_xpm[] = {"24 24 3 1"," c None",". c #000000","+ c #DBD081"," "," ......................."," .++++++++++++++++++++. "," .+++++++++++++++++++. "," .++++++++++++++++++. "," .+++++++++++++++++. "," .++++++++++++++++. "," .+++++++++++++++. "," .++++++++++++++. "," .+++++++++++++. "," .++++++++++++. "," .+++++++++++. "," .++++++++++. "," .+++++++++. "," .++++++++. "," .+++++++. "," .++++++. "," .+++++. "," .++++. "," .+++. "," .++. "," .+. "," .. "," . "};VideoOutput::VideoOutput( VideoWidget* parent ) : QWidget( parent), parentWidget( parent ), targetRect( 0, 0, 0, 0 ){ // Create a QImage which is large enough to hold a video frame no matter what the // orientation of the screen or the movie is or regardless of any rotations in effect int size = QMAX( qApp->desktop()->width(), qApp->desktop()->height() ); currentFrame = new QImage( size, size, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); rotatedFrame = new QImage( size, size, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); setBackgroundColor( Qt::black );}VideoOutput::~VideoOutput(){ if ( currentFrame ) delete currentFrame; delete rotatedFrame;}void VideoOutput::paintEvent( QPaintEvent * ){ // Draw the current frame playVideo();}void VideoOutput::mouseReleaseEvent( QMouseEvent * ){ // Effectively blank the view next time we show it// targetRect = QRect( 0, 0, 0, 0 ); parentWidget->setNextMode();}void VideoWidget::setNextMode(){ if ( screenMode == Fullscreen ) { setMode( Normal ); } else if ( screenMode == Large || !showCornerButton() ) setMode( Fullscreen ); else setMode( Large );}VideoWidget::VideoWidget(QWidget* parent, const QString& skin, const char* name ) : ControlWidgetBase( parent, skin, "video", name ), // No tr cornerButton( this ), cornerMenu( 0 ), screenMode( InvalidMode ), videoOutput( this ){ setButtonData( videoButtons, sizeof(videoButtons)/sizeof(MediaButton) ); connect( mediaPlayerState, SIGNAL( viewChanged(View) ), this, SLOT( setView(View) ) ); setMode( mediaPlayerState->fullscreen() ? Fullscreen : Normal ); qDebug("vw 1"); // slider.setEnabled( mediaPlayerState->decoderIsSeekable() ); qDebug("vw 2"); cornerButton.setPixmap( QPixmap( turnup_xpm ) ); cornerButton.setFlat( TRUE ); cornerButton.setFocusPolicy( QWidget::NoFocus ); connect( &cornerButton, SIGNAL( clicked() ), this, SLOT( doModeMenu() ) ); cornerMenu.insertItem( tr("Fullscreen"), Fullscreen, Fullscreen ); cornerMenu.insertItem( tr("Large"), Large, Large ); cornerMenu.insertItem( tr("Normal"), Normal, Normal ); connect( &cornerMenu, SIGNAL( activated( int ) ), this, SLOT( setMode( int ) ) );}VideoWidget::~VideoWidget(){}void VideoWidget::virtualResize(){ // Resize or dynamic rotation from size which supports // Large mode to size which does not if ( screenMode == Large && !showCornerButton() ) screenMode = Normal; updateVideoOutputGeometry(); if ( screenMode == Fullscreen ) return; int w = width(); int h = height(); int scaleW = w; int scaleH = h; if ( showCornerButton() ) { cornerButton.setGeometry( w - 24, h - 24, 24, 24 ); cornerButton.show(); } else { cornerButton.hide(); } // scale width and height to be both less than 400 if ( scaleW > 400 ) { scaleW = 400; scaleH = h * 400 / w; } if ( scaleH > 400 ) { scaleW = w * 400 / h; scaleH = 400; } if ( screenMode != Large ) buttonHeight = resizeObjects( w, h, scaleW, scaleH, ( showCornerButton() ) ? 24 : 0 );}void VideoWidget::updateVideoOutputGeometry(){ if ( screenMode == Fullscreen ) return; int bH = ( screenMode == Large ) ? 0 : buttonHeight; int h = height(); int w = width(); int border = w / 40; const int timeHeight = 20; movieBorder = w / 50; w -= 2 * (border + movieBorder); h -= 4 * border + timeHeight + bH + 2 * movieBorder; if ( screenMode == Normal && w > 352 ) w = 352; if ( screenMode == Large && w > 576 ) w = 576; innerMovieArea = QRect( (width() - w) / 2, border + movieBorder, w, h ); outerMovieArea = QRect( innerMovieArea.left() - movieBorder, innerMovieArea.top() - movieBorder, innerMovieArea.width() + 2 * movieBorder, innerMovieArea.height() + 2 * movieBorder ); videoOutput.setGeometry( innerMovieArea );}void VideoWidget::setView( View view ){ if ( view == VideoView ) { if ( mediaPlayerState->fullscreen() ) screenMode = Fullscreen; else if ( screenMode == Fullscreen ) screenMode = Normal; makeVisible(); } else { videoOutput.hide(); if ( screenMode == Fullscreen ) { videoOutput.reparent( this, innerMovieArea.topLeft() ); videoOutput.resize( innerMovieArea.size() ); videoOutput.unsetCursor(); } canPaint = FALSE; } resetButtons();}void VideoWidget::makeVisible(){ videoOutput.hide(); if ( screenMode == Fullscreen ) { videoOutput.reparent( 0, QPoint( 0, 0 ) ); videoOutput.resize( qApp->desktop()->size() ); videoOutput.setCursor( QCursor( blankCursor ) ); videoOutput.showFullScreen(); } else { mainDocumentWindow->raiseWidget( this ); updateVideoOutputGeometry(); videoOutput.reparent( this, innerMovieArea.topLeft() ); videoOutput.resize( innerMovieArea.size() ); videoOutput.unsetCursor(); videoOutput.show(); } qApp->processEvents();}void VideoWidget::setMode( int mode ){ if ( screenMode == (Mode)mode ) return; screenMode = (Mode)mode; if ( mediaPlayerState->fullscreen() != ( mode == Fullscreen ) ) { // toggle from/to Fullscreen from/to Normal or Large mode mediaPlayerState->setFullscreen( ( mode == Fullscreen ) ); makeVisible(); } else { // toggle from/to Large to/from Nomal mode updateVideoOutputGeometry(); repaint(); }}void VideoWidget::doModeMenu(){ cornerMenu.popup( QCursor::pos() );}void VideoWidget::virtualUpdateSlider(){ if ( screenMode == Fullscreen ) return; updateSlider();}void VideoWidget::paintButton( QPainter& p, int i ){ if ( screenMode == Normal ) ControlWidgetBase::paintButton( p, i );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -