X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fmain_interface.cpp;h=1a86e3478091d3204731fec25fc1ebaf7b40ab73;hb=eeb1cf539937c797bcfe87807bc0e5b3a7a034b3;hp=d70e6f8f3d6a9c014cb7c09449b145a1adc2aa98;hpb=08737f85e0e34e8b75da567054389cc0521327e6;p=vlc diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp index d70e6f8f3d..1a86e34780 100644 --- a/modules/gui/qt4/main_interface.cpp +++ b/modules/gui/qt4/main_interface.cpp @@ -110,7 +110,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) b_autoresize = var_InheritBool( p_intf, "qt-video-autoresize" ); /* Are we in the enhanced always-video mode or not ? */ - i_visualmode = var_InheritInteger( p_intf, "qt-minimal-view" ); + b_minimalView = var_InheritBool( p_intf, "qt-minimal-view" ); /* Do we want anoying popups or not */ b_notificationEnabled = var_InheritBool( p_intf, "qt-notification" ); @@ -198,26 +198,27 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) /* END CONNECTS ON IM */ /* VideoWidget connects for asynchronous calls */ + b_videoFullScreen = false; + b_videoOnTop = false; connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)), this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)), Qt::BlockingQueuedConnection ); connect( this, SIGNAL(askReleaseVideo( void )), this, SLOT(releaseVideoSlot( void )), Qt::BlockingQueuedConnection ); + CONNECT( this, askVideoOnTop(bool), this, setVideoOnTop(bool)); if( videoWidget ) { if( b_autoresize ) { CONNECT( this, askVideoToResize( unsigned int, unsigned int ), - videoWidget, SetSizing( unsigned int, unsigned int ) ); + this, setVideoSize( unsigned int, unsigned int ) ); CONNECT( videoWidget, sizeChanged( int, int ), this, resizeStack( int, int ) ); } CONNECT( this, askVideoSetFullScreen( bool ), - videoWidget, SetFullScreen( bool ) ); - CONNECT( videoWidget, keyPressed( QKeyEvent * ), - this, handleKeyPress( QKeyEvent * ) ); + this, setVideoFullScreen( bool ) ); } CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() ); @@ -243,6 +244,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) QVLCTools::restoreWidgetPosition( settings, this, QSize(400, 100) ); settings->endGroup(); + b_interfaceFullScreen = isFullScreen(); + /* Final sizing and showing */ setVisible( !b_hideAfterCreation ); @@ -250,7 +253,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) menuBar()->sizeHint().width() ) + 30 ); /* Switch to minimal view if needed, must be called after the show() */ - if( i_visualmode ) + if( b_minimalView ) toggleMinimalView( true ); } @@ -531,21 +534,6 @@ void MainInterface::toggleFSC() * Video Handling ****************************************************************************/ -/* This event is used to deal with the fullscreen and always on top - issue conflict (bug in wx) */ -class SetVideoOnTopQtEvent : public QEvent -{ -public: - SetVideoOnTopQtEvent( bool _onTop ) : - QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop) - {} - - bool OnTop() const { return onTop; } - -private: - bool onTop; -}; - /** * NOTE: * You must not change the state of this object or other Qt4 UI objects, @@ -594,6 +582,8 @@ void MainInterface::releaseVideo( void ) void MainInterface::releaseVideoSlot( void ) { videoWidget->release(); + setVideoOnTop( false ); + setVideoFullScreen( false ); if( stackCentralW->currentWidget() == videoWidget ) restoreStackOldWidget(); @@ -602,6 +592,66 @@ void MainInterface::releaseVideoSlot( void ) stackCentralOldWidget = bgWidget; } +void MainInterface::setVideoSize( unsigned int w, unsigned int h ) +{ + if( !isFullScreen() && !isMaximized() ) + videoWidget->SetSizing( w, h ); +} + +void MainInterface::setVideoFullScreen( bool fs ) +{ + b_videoFullScreen = fs; + if( fs ) + { + int numscreen = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" ); + /* if user hasn't defined screennumber, or screennumber that is bigger + * than current number of screens, take screennumber where current interface + * is + */ + if( numscreen == -1 || numscreen > QApplication::desktop()->numScreens() ) + numscreen = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi ); + + QRect screenres = QApplication::desktop()->screenGeometry( numscreen ); + + /* To be sure window is on proper-screen in xinerama */ + if( !screenres.contains( pos() ) ) + { + msg_Dbg( p_intf, "Moving video to correct screen"); + move( QPoint( screenres.x(), screenres.y() ) ); + } + setMinimalView( true ); + setInterfaceFullScreen( true ); + } + else + { + /* TODO do we want to restore screen and position ? (when + * qt-fullscreen-screennumber is forced) */ + setMinimalView( b_minimalView ); + setInterfaceFullScreen( b_interfaceFullScreen ); + } + videoWidget->sync(); +} + +/* Slot to change the video always-on-top flag. + * Emit askVideoOnTop() to invoke this from other thread. */ +void MainInterface::setVideoOnTop( bool on_top ) +{ + b_videoOnTop = on_top; + + Qt::WindowFlags oldflags = windowFlags(), newflags; + + if( b_videoOnTop ) + newflags = oldflags | Qt::WindowStaysOnTopHint; + else + newflags = oldflags & ~Qt::WindowStaysOnTopHint; + + if( newflags != oldflags ) + { + setWindowFlags( newflags ); + show(); /* necessary to apply window flags */ + } +} + /* Asynchronous call from WindowControl function */ int MainInterface::controlVideo( int i_query, va_list args ) { @@ -611,8 +661,7 @@ int MainInterface::controlVideo( int i_query, va_list args ) { unsigned int i_width = va_arg( args, unsigned int ); unsigned int i_height = va_arg( args, unsigned int ); - if( isFullScreen() || isMaximized() ) - showNormal(); + emit askVideoToResize( i_width, i_height ); return VLC_SUCCESS; } @@ -620,12 +669,14 @@ int MainInterface::controlVideo( int i_query, va_list args ) { unsigned i_arg = va_arg( args, unsigned ); unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE; - QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) ); + + emit askVideoOnTop( on_top != 0 ); return VLC_SUCCESS; } case VOUT_WINDOW_SET_FULLSCREEN: { bool b_fs = va_arg( args, int ); + emit askVideoSetFullScreen( b_fs ); return VLC_SUCCESS; } @@ -725,12 +776,20 @@ void MainInterface::dockPlaylist( bool p_docked ) playlistVisible = true; } +void MainInterface::setMinimalView( bool b_minimal ) +{ + menuBar()->setVisible( !b_minimal ); + controls->setVisible( !b_minimal ); + statusBar()->setVisible( !b_minimal ); + inputC->setVisible( !b_minimal ); +} + /* - If b_switch is false, then we are normalView + If b_minimal is false, then we are normalView */ -void MainInterface::toggleMinimalView( bool b_switch ) +void MainInterface::toggleMinimalView( bool b_minimal ) { - if( i_visualmode == 0 && b_autoresize ) /* Normal mode */ + if( !b_minimalView && b_autoresize ) /* Normal mode */ { if( stackCentralW->currentWidget() == bgWidget ) { @@ -740,13 +799,11 @@ void MainInterface::toggleMinimalView( bool b_switch ) } } } + b_minimalView = b_minimal; + if( !b_videoFullScreen ) + setMinimalView( b_minimalView ); - menuBar()->setVisible( !b_switch ); - controls->setVisible( !b_switch ); - statusBar()->setVisible( !b_switch ); - inputC->setVisible( !b_switch ); - - emit minimalViewToggled( b_switch ); + emit minimalViewToggled( b_minimalView ); } /* toggling advanced controls buttons */ @@ -983,8 +1040,9 @@ void MainInterface::dropEvent(QDropEvent *event) void MainInterface::dropEventPlay( QDropEvent *event, bool b_play ) { - event->setDropAction( Qt::CopyAction ); - if( !event->possibleActions() & Qt::CopyAction ) + if( event->possibleActions() & Qt::CopyAction ) + event->setDropAction( Qt::CopyAction ); + else return; const QMimeData *mimeData = event->mimeData(); @@ -1004,18 +1062,30 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play ) bool first = b_play; foreach( const QUrl &url, mimeData->urls() ) { - QString s = toNativeSeparators( url.toLocalFile() ); - - if( s.length() > 0 ) { - char* psz_uri = make_URI( qtu(s) ); + if( url.isValid() ) + { + char* psz_uri = make_URI( qtu( url.toString() ) ); playlist_Add( THEPL, psz_uri, NULL, PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE), PLAYLIST_END, true, pl_Unlocked ); free( psz_uri ); first = false; - RecentsMRL::getInstance( p_intf )->addRecent( s ); + RecentsMRL::getInstance( p_intf )->addRecent( url.toString() ); } } + + /* Browsers give content as text if you dnd the addressbar, + so check if mimedata has valid url in text and use it + if we didn't get any normal Urls()*/ + if( !mimeData->hasUrls() && mimeData->hasText() && + QUrl(mimeData->text()).isValid() ) + { + char *psz_uri = make_URI( qtu( mimeData->text() ) ); + playlist_Add( THEPL, psz_uri, NULL, + PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE), + PLAYLIST_END, true, pl_Unlocked ); + free( psz_uri ); + } event->accept(); } void MainInterface::dragEnterEvent(QDragEnterEvent *event) @@ -1034,19 +1104,6 @@ void MainInterface::dragLeaveEvent(QDragLeaveEvent *event) /************************************************************************ * Events stuff ************************************************************************/ -void MainInterface::customEvent( QEvent *event ) -{ - if ( event->type() == (int)SetVideoOnTopEvent_Type ) - { - SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event; - if( p_event->OnTop() ) - setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint ); - else - setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint ); - show(); /* necessary to apply window flags */ - } -} - void MainInterface::keyPressEvent( QKeyEvent *e ) { handleKeyPress( e ); @@ -1054,10 +1111,9 @@ void MainInterface::keyPressEvent( QKeyEvent *e ) void MainInterface::handleKeyPress( QKeyEvent *e ) { - if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H ) - && !menuBar()->isVisible() ) + if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H ) ) { - toggleMinimalView( false ); + toggleMinimalView( !b_minimalView ); e->accept(); } @@ -1085,18 +1141,19 @@ void MainInterface::closeEvent( QCloseEvent *e ) THEDP->quit(); } -void MainInterface::toggleFullScreen() +void MainInterface::setInterfaceFullScreen( bool fs ) { - if( isFullScreen() ) - { - showNormal(); - emit fullscreenInterfaceToggled( false ); - } - else - { + if( fs ) showFullScreen(); - emit fullscreenInterfaceToggled( true ); - } + else + showNormal(); +} +void MainInterface::toggleInterfaceFullScreen() +{ + b_interfaceFullScreen = !b_interfaceFullScreen; + if( !b_videoFullScreen ) + setInterfaceFullScreen( b_interfaceFullScreen ); + emit fullscreenInterfaceToggled( b_interfaceFullScreen ); } /*****************************************************************************