📄 main_interface.cpp
字号:
/***************************************************************************** * main_interface.cpp : Main interface **************************************************************************** * Copyright (C) 2006-2008 the VideoLAN team * $Id: 77823a7204617ec9f5102cbc9ac1605731906d9f $ * * Authors: Clément Stenac <zorglub@videolan.org> * Jean-Baptiste Kempf <jb@videolan.org> * Ilkka Ollakka <ileoo@videolan.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include "qt4.hpp"#include "main_interface.hpp"#include "input_manager.hpp"#include "util/qvlcframe.hpp"#include "util/customwidgets.hpp"#include "dialogs_provider.hpp"#include "components/interface_widgets.hpp"#include "components/playlist/playlist.hpp"#include "dialogs/extended.hpp"#include "dialogs/playlist.hpp"#include "menus.hpp"#include <QMenuBar>#include <QCloseEvent>#include <QPushButton>#include <QStatusBar>#include <QKeyEvent>#include <QUrl>#include <QSystemTrayIcon>#include <QSize>#include <QMenu>#include <QLabel>#include <QSlider>#include <QWidgetAction>#include <QToolBar>#include <QGroupBox>#include <QDate>#include <assert.h>#include <vlc_keys.h>#include <vlc_vout.h>/* Callback prototypes */static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable, vlc_value_t old_val, vlc_value_t new_val, void *param );static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable, vlc_value_t old_val, vlc_value_t new_val, void *param );static int InteractCallback( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void *);MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ){ /* Variables initialisation */ // need_components_update = false; bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL; sysTray = NULL; videoIsActive = false; playlistVisible = false; input_name = ""; fullscreenControls = NULL; /* Ask for privacy */ askForPrivacy(); /** * Configuration and settings * Pre-building of interface **/ /* Main settings */ setFocusPolicy( Qt::StrongFocus ); setAcceptDrops( true ); setWindowIcon( QApplication::windowIcon() ); setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) ); /* Set The Video In emebedded Mode or not */ videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" ); /* Are we in the enhanced always-video mode or not ? */ i_visualmode = config_GetInt( p_intf, "qt-display-mode" ); /* Set the other interface settings */ settings = getSettings(); settings->beginGroup( "MainWindow" ); /* Visualisation, not really used yet */ visualSelectorEnabled = settings->value( "visual-selector", false).toBool(); /* Do we want anoying popups or not */ notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" ); /************************** * UI and Widgets design **************************/ setVLCWindowsTitle(); handleMainUi( settings );#if 0 /* Create a Dock to get the playlist */ dockPL = new QDockWidget( qtr( "Playlist" ), this ); dockPL->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding ); dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures ); dockPL->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea ); dockPL->hide();#endif /************************** * Menu Bar and Status Bar **************************/ QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled ); /* StatusBar Creation */ createStatusBar(); /******************** * Input Manager * ********************/ MainInputManager::getInstance( p_intf ); /************************** * Various CONNECTs on IM * **************************/ /* Connect the input manager to the GUI elements it manages */ /* It is also connected to the control->slider, see the ControlsWidget */ CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ), this, setDisplayPosition( float, int, int ) ); /* Change the SpeedRate in the Status */ CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) ); /** * Connects on nameChanged() * Those connects are not merged because different options can trigger * them down. */ /* Naming in the controller statusbar */ CONNECT( THEMIM->getIM(), nameChanged( QString ), this, setName( QString ) ); /* and in the systray */ if( sysTray ) { CONNECT( THEMIM->getIM(), nameChanged( QString ), this, updateSystrayTooltipName( QString ) ); } /* and in the title of the controller */ if( config_GetInt( p_intf, "qt-name-in-title" ) ) { CONNECT( THEMIM->getIM(), nameChanged( QString ), this, setVLCWindowsTitle( QString ) ); } /** * CONNECTS on PLAY_STATUS **/ /* Status on the main controller */ CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) ); /* and in the systray */ if( sysTray ) { CONNECT( THEMIM->getIM(), statusChanged( int ), this, updateSystrayTooltipStatus( int ) ); } /* END CONNECTS ON IM */ /** OnTimeOut **/ /* TODO Remove this function, but so far, there is no choice because there is no intf-should-die variable #1365 */ ON_TIMEOUT( updateOnTimer() ); /************ * Callbacks ************/ var_Create( p_intf, "interaction", VLC_VAR_ADDRESS ); var_AddCallback( p_intf, "interaction", InteractCallback, this ); p_intf->b_interaction = true; var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf ); /* Register callback for the intf-popupmenu variable */ var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf ); /* VideoWidget connects to avoid different threads speaking to each other */ CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) ); if( videoWidget ) CONNECT( this, askVideoToResize( unsigned int, unsigned int ), videoWidget, SetSizing( unsigned int, unsigned int ) ); CONNECT( this, askUpdate(), this, doComponentsUpdate() ); /* Size and placement of interface */ QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) ); bool b_visible = settings->value( "playlist-visible", 0 ).toInt(); settings->endGroup(); /* Playlist */ if( b_visible ) togglePlaylist(); /* Final sizing and showing */ setMinimumWidth( __MAX( controls->sizeHint().width(), menuBar()->sizeHint().width() ) ); show(); /* And switch to minimal view if needed Must be called after the show() */ if( i_visualmode == QT_MINIMAL_MODE ) toggleMinimalView(); /* Update the geometry : It is useful if you switch between qt-display-modes ?*/ updateGeometry(); resize( sizeHint() ); /***************************************************** * End everything by creating the Systray Management * *****************************************************/ initSystray();}MainInterface::~MainInterface(){ msg_Dbg( p_intf, "Destroying the main interface" ); /* Saving volume */ if( config_GetInt( p_intf, "qt-autosave-volume" ) ) { audio_volume_t i_volume; aout_VolumeGet( p_intf, &i_volume ); config_PutInt( p_intf, "volume", i_volume ); config_SaveConfigFile( p_intf, NULL ); } if( playlistWidget ) { if( !isDocked() ) QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget ); } settings->beginGroup( "MainWindow" ); settings->setValue( "pl-dock-status", (int)i_pl_dock ); settings->setValue( "playlist-visible", (int)playlistVisible ); settings->setValue( "adv-controls", getControlsVisibilityStatus() & CONTROLS_ADVANCED ); if( !videoIsActive ) { QVLCTools::saveWidgetPosition(settings, this); } else { msg_Dbg( p_intf, "Not saving because video is in use." ); } if( bgWidget ) settings->setValue( "backgroundSize", bgWidget->size() ); settings->endGroup(); var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf ); /* Unregister callback for the intf-popupmenu variable */ var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf ); p_intf->b_interaction = false; var_DelCallback( p_intf, "interaction", InteractCallback, this ); p_intf->p_sys->p_mi = NULL;}/***************************** * Main UI handling * *****************************/inline void MainInterface::createStatusBar(){ /**************** * Status Bar * ****************/ /* Widgets Creation*/ b_remainingTime = false; timeLabel = new TimeLabel; timeLabel->setText( " --:--/--:-- " ); timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); timeLabel->setToolTip( qtr( "Toggle between elapsed and remaining time" ) ); nameLabel = new QLabel; nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard ); speedLabel = new SpeedLabel( p_intf, "1.00x" ); speedLabel->setToolTip( qtr( "Current playback speed.\nRight click to adjust" ) ); speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu ); /* Styling those labels */ timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel ); speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel ); nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel); /* and adding those */ statusBar()->addWidget( nameLabel, 8 ); statusBar()->addPermanentWidget( speedLabel, 0 ); statusBar()->addPermanentWidget( timeLabel, 0 ); /* timeLabel behaviour: - double clicking opens the goto time dialog - right-clicking and clicking just toggle between remaining and elapsed time.*/ CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() ); CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() ); CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() ); /* Speed Label behaviour: - right click gives the vertical speed slider */ CONNECT( speedLabel, customContextMenuRequested( QPoint ), this, showSpeedMenu( QPoint ) );}inline void MainInterface::initSystray(){ bool b_createSystray = false; bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable(); if( config_GetInt( p_intf, "qt-start-minimized") ) { if( b_systrayAvailable ) { b_createSystray = true; hide(); } else msg_Err( p_intf, "You can't minimize if you haven't a system " "tray bar" ); } if( config_GetInt( p_intf, "qt-system-tray") ) b_createSystray = true; if( b_systrayAvailable && b_createSystray ) createSystray();}/** * Give the decorations of the Main Window a correct Name. * If nothing is given, set it to VLC... **/void MainInterface::setVLCWindowsTitle( QString aTitle ){ if( aTitle.isEmpty() ) { setWindowTitle( qtr( "VLC media player" ) ); } else { setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) ); }}void MainInterface::handleMainUi( QSettings *settings ){ /* Create the main Widget and the mainLayout */ QWidget *main = new QWidget; setCentralWidget( main ); mainLayout = new QVBoxLayout( main ); /* Margins, spacing */ main->setContentsMargins( 0, 0, 0, 0 ); main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 ); /* Create the CONTROLS Widget */ bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); controls = new ControlsWidget( p_intf, this, settings->value( "adv-controls", false ).toBool(), b_shiny ); CONNECT( controls, advancedControlsToggled( bool ), this, doComponentsUpdate() );#ifdef WIN32 if ( depth() > 8 )#endif /* Create the FULLSCREEN CONTROLS Widget */ if( config_GetInt( p_intf, "qt-fs-controller" ) ) { fullscreenControls = new FullscreenControllerWidget( p_intf, this, settings->value( "adv-controls", false ).toBool(), b_shiny ); CONNECT( fullscreenControls, advancedControlsToggled( bool ), this, doComponentsUpdate() ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -