Commit 9f0375cd authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt, menus: various changes, speedups and addition to approach mac menus.

parent 8d5ee287
......@@ -121,9 +121,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
/* 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" );
......@@ -141,7 +138,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
/************
* Menu Bar *
************/
QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
QVLCMenu::createMenuBar( this, p_intf );
#if 0
/* Create a Dock to get the playlist */
......
......@@ -141,7 +141,9 @@ void EnableStaticEntries( QMenu *menu, bool enable = true )
QList< QAction* > actions = menu->actions();
for( int i = 0; i < actions.size(); ++i )
{
actions[i]->setEnabled( enable && actions[i]->data().toBool() );
actions[i]->setEnabled( enable &&
/* Be careful here, because data("string").toBool is true */
(actions[i]->data().toString() == "true" ) );
}
}
......@@ -150,9 +152,10 @@ void EnableStaticEntries( QMenu *menu, bool enable = true )
*/
int DeleteNonStaticEntries( QMenu *menu )
{
if( !menu ) return VLC_EGENERIC;
int i_ret = 0;
if( !menu )
return VLC_EGENERIC;
QList< QAction* > actions = menu->actions();
for( int i = 0; i < actions.size(); ++i )
{
......@@ -200,7 +203,6 @@ static int InputAutoMenuBuilder( input_thread_t *p_object,
PUSH_VAR( "chapter" );
PUSH_VAR( "navigation" );
PUSH_VAR( "program" );
PUSH_VAR( "dvd_menus" );
return VLC_SUCCESS;
}
......@@ -269,9 +271,7 @@ static int AudioAutoMenuBuilder( aout_instance_t *p_object,
* Main Menu Bar Creation
**/
void QVLCMenu::createMenuBar( MainInterface *mi,
intf_thread_t *p_intf,
bool visual_selector_enabled )
/* FIXME remove this visual dependency */
intf_thread_t *p_intf )
{
/* QMainWindows->menuBar()
gives the QProcess::destroyed timeout issue on Cleanlooks style with
......@@ -286,8 +286,7 @@ void QVLCMenu::createMenuBar( MainInterface *mi,
BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
qtr( "V&iew" ) );
BAR_ADD( ViewMenu( p_intf, mi ), qtr( "V&iew" ) );
BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
}
#undef BAR_ADD
......@@ -386,29 +385,21 @@ QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
* Interface Modification
**/
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
QMenu *current,
MainInterface *mi,
bool visual_selector_enabled,
bool with_intf )
{
QMenu *menu;
if( current )
menu = new QMenu( current );
else
menu = new QMenu( mi );
QAction *act;
if( mi )
{
act = menu->addAction( QIcon( ":/playlist_menu" ),
qtr( "Play&list" ), mi,
SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
act->setData( true );
}
assert( mi );
QMenu *menu = new QMenu( qtr( "V&iew" ), mi );
QAction *act = menu->addAction( QIcon( ":/playlist_menu" ),
qtr( "Play&list" ), mi,
SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
/*menu->addSeparator();
menu->addAction( qtr( "Undock from Interface" ), mi,
SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
menu->addSeparator();
if( with_intf )
......@@ -419,38 +410,35 @@ QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
THEDP->menusUpdateMapper->setMapping( intfmenu, f );
menu->addSeparator();
}
if( mi )
{
/* Minimal View */
QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
action->setCheckable( true );
action->setData( true );
if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
action->setChecked( true );
minimalViewAction = action; /* HACK for minimalView */
/* FullScreen View */
action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
SLOT( toggleFullScreen() ), QString( "F11" ) );
fullscreenViewAction = action;
action->setCheckable( true );
action->setData( true );
/* Advanced Controls */
action = menu->addAction( qtr( "&Advanced Controls" ), mi,
SLOT( toggleAdvanced() ) );
action->setCheckable( true );
action->setData( true );
if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
action->setChecked( true );
/* Minimal View */
QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
action->setCheckable( true );
if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
action->setChecked( true );
minimalViewAction = action; /* HACK for minimalView */
/* FullScreen View */
action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
SLOT( toggleFullScreen() ), QString( "F11" ) );
fullscreenViewAction = action;
action->setCheckable( true );
/* Advanced Controls */
action = menu->addAction( qtr( "&Advanced Controls" ), mi,
SLOT( toggleAdvanced() ) );
action->setCheckable( true );
if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
action->setChecked( true );
#if 0 /* For Visualisations. Not yet working */
adv = menu->addAction( qtr( "Visualizations selector" ),
mi, SLOT( visual() ) );
adv->setCheckable( true );
if( visual_selector_enabled ) adv->setChecked( true );
adv = menu->addAction( qtr( "Visualizations selector" ),
mi, SLOT( visual() ) );
adv->setCheckable( true );
if( visual_selector_enabled ) adv->setChecked( true );
#endif
}
menu->addSeparator();
addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
......@@ -594,46 +582,49 @@ QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
**/
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
{
if( menu->isEmpty() )
{
QAction *action;
QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
SLOT( bookmarksDialog() ) );
submenu->addSeparator();
action = menu->addMenu( submenu );
action->setData( "bookmark" );
ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
QAction *action;
menu->addSeparator();
addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
SLOT( gotoTimeDialog() ), "Ctrl+T" );
QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
SLOT( bookmarksDialog() ) );
submenu->addSeparator();
action = menu->addMenu( submenu );
action->setData( "bookmark" );
}
ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
menu->addSeparator();
PopupMenuControlEntries( menu, p_intf );//, THEMIM->getInput() );
PopupMenuPlaylistControlEntries( menu, p_intf );
return menu;
}
QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
{
/* */
input_thread_t *p_object;
vector<vlc_object_t *> objects;
vector<const char *> varnames;
/* Get the input and hold it */
p_object = THEMIM->getInput();
if( p_object )
vlc_object_hold( p_object );
InputAutoMenuBuilder( p_object, objects, varnames );
menu->addSeparator();
/* Title and so on */
PUSH_VAR( "prev-title" );
PUSH_VAR( "next-title" );
PUSH_VAR( "prev-chapter" );
PUSH_VAR( "next-chapter" );
menu->addSeparator();
EnableStaticEntries( menu, ( p_object != NULL ) );
if( p_object )
vlc_object_release( p_object );
......@@ -717,7 +708,7 @@ QMenu *QVLCMenu::HelpMenu( QWidget *parent )
p_intf->p_sys->p_popup_menu = NULL; \
i_last_separator = 0;
void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
void QVLCMenu::PopupPlayEntries( QMenu *menu,
intf_thread_t *p_intf,
input_thread_t *p_input )
{
......@@ -736,9 +727,13 @@ void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
":/pause", SLOT( togglePlayPause() ) );
}
}
void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
{
QAction *action;
/* Stop */
addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
":/stop", SLOT( stop() ) );
addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), ":/stop", SLOT( stop() ) );
/* Faster/Slower */
action = menu->addAction( qtr( "Faster" ), THEMIM->getIM(), SLOT( faster() ) );
......@@ -746,13 +741,24 @@ void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
menu->addAction( qtr( "Normal Speed" ), THEMIM->getIM(), SLOT( normalRate() ) );
action = menu->addAction( qtr( "Slower" ), THEMIM->getIM(), SLOT( slower() ) );
action->setIcon( QIcon( ":/slower") );
menu->addSeparator();
action = menu->addAction( qtr( "Jump Forward" ), THEMIM->getIM(),
SLOT( jumpFwd() ) );
action->setIcon( QIcon( ":/skip_fw") );
action = menu->addAction( qtr( "Jump Backward" ), THEMIM->getIM(),
SLOT( jumpBwd() ) );
action->setIcon( QIcon( ":/skip_back") );
}
void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
intf_thread_t *p_intf,
input_thread_t *p_input )
intf_thread_t *p_intf )
{
addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
SLOT( gotoTimeDialog() ), "Ctrl+T" );
menu->addSeparator();
/* Next / Previous */
addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
":/previous", SLOT( prev() ) );
......@@ -822,7 +828,7 @@ void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
CREATE_POPUP;
}
/* Navigation stuff, and general menus ( open ) */
/* Navigation stuff, and general menus ( open ), used only for skins */
void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
{
POPUP_BOILERPLATE;
......@@ -839,10 +845,10 @@ void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
Populate( p_intf, menu, varnames, objects );
menu->addSeparator();
PopupMenuControlEntries( menu, p_intf, p_input );
PopupMenuControlEntries( menu, p_intf ); //, p_input );
menu->addSeparator();
PopupMenuPlaylistControlEntries( menu, p_intf, p_input );
PopupMenuPlaylistControlEntries( menu, p_intf); //, p_input );
menu->addSeparator();
PopupMenuStaticEntries( menu );
......@@ -855,129 +861,113 @@ void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
/* Main Menu that sticks everything together */
void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
{
MainInterface *mi = p_intf->p_sys->p_mi;
if( show )
/* Destroy popup menu if there is one */
if( !show )
{
/* Delete and recreate a popup if there is one */
if( p_intf->p_sys->p_popup_menu )
delete p_intf->p_sys->p_popup_menu;
delete p_intf->p_sys->p_popup_menu;
p_intf->p_sys->p_popup_menu = NULL;
return;
}
QMenu *menu = new QMenu();
QMenu *submenu;
QAction *action;
bool b_isFullscreen = false;
/* Delete and recreate a popup if there is one */
if( p_intf->p_sys->p_popup_menu )
delete p_intf->p_sys->p_popup_menu;
POPUP_BOILERPLATE;
/* */
QMenu *menu = new QMenu();
QMenu *submenu;
QAction *action;
bool b_isFullscreen = false;
MainInterface *mi = p_intf->p_sys->p_mi;
PopupMenuControlEntries( menu, p_intf, p_input );
menu->addSeparator();
POPUP_BOILERPLATE;
PopupMenuPlaylistControlEntries( menu, p_intf, p_input );
menu->addSeparator();
PopupMenuControlEntries( menu, p_intf ); //, p_input );
menu->addSeparator();
if( p_input )
if( p_input )
{
vout_thread_t *p_vout = THEMIM->getVout();
/* Add a fullscreen switch button, since it is the most used function */
if( p_vout )
{
vout_thread_t *p_vout = THEMIM->getVout();
vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
/* Add a fullscreen switch button */
if( p_vout )
{
vlc_value_t val;
var_Get( p_vout, "fullscreen", &val );
b_isFullscreen = !( !val.b_bool );
if( b_isFullscreen )
CreateAndConnect( menu, "fullscreen",
qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
b_isFullscreen );
vlc_object_release( p_vout );
}
b_isFullscreen = !( !val.b_bool );
if( b_isFullscreen )
CreateAndConnect( menu, "fullscreen",
qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
vlc_object_release( p_vout );
menu->addSeparator();
}
/* Input menu */
vlc_object_hold( p_input );
InputAutoMenuBuilder( p_input, objects, varnames );
vlc_object_release( p_input );
/* Input menu */
vlc_object_hold( p_input );
InputAutoMenuBuilder( p_input, objects, varnames );
vlc_object_release( p_input );
/* Audio menu */
submenu = new QMenu( menu );
action = menu->addMenu( AudioMenu( p_intf, submenu ) );
action->setText( qtr( "&Audio" ) );
if( action->menu()->isEmpty() )
action->setEnabled( false );
/* Audio menu */
submenu = new QMenu( menu );
action = menu->addMenu( AudioMenu( p_intf, submenu ) );
action->setText( qtr( "&Audio" ) );
if( action->menu()->isEmpty() )
action->setEnabled( false );
/* Video menu */
submenu = new QMenu( menu );
action = menu->addMenu( VideoMenu( p_intf, submenu ) );
action->setText( qtr( "&Video" ) );
if( action->menu()->isEmpty() )
action->setEnabled( false );
/* Video menu */
submenu = new QMenu( menu );
action = menu->addMenu( VideoMenu( p_intf, submenu ) );
action->setText( qtr( "&Video" ) );
if( action->menu()->isEmpty() )
action->setEnabled( false );
/* Playback menu for chapters */
submenu = new QMenu( menu );
action = menu->addMenu( NavigMenu( p_intf, submenu ) );
action->setText( qtr( "&Playback" ) );
if( action->menu()->isEmpty() )
action->setEnabled( false );
}
/* Playback menu for chapters */
submenu = new QMenu( menu );
action = menu->addMenu( NavigMenu( p_intf, submenu ) );
action->setText( qtr( "&Playback" ) );
if( action->menu()->isEmpty() )
action->setEnabled( false );
}
menu->addSeparator();
menu->addSeparator();
/* Add some special entries for windowed mode: Interface Menu */
if( !b_isFullscreen )
/* Add some special entries for windowed mode: Interface Menu */
if( !b_isFullscreen )
{
submenu = new QMenu( qtr( "Interface" ), menu );
QMenu *tools = ToolsMenu( submenu );
submenu->addSeparator();
/* In skins interface, append some items */
if( !mi )
{
submenu = new QMenu( qtr( "Interface" ), menu );
if( mi )
{
submenu->addAction( QIcon( ":/playlist" ),
qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
action = submenu->addAction( QIcon( "" ),
qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
action->setCheckable( true );
action->setChecked( !( mi->getControlsVisibilityStatus() &
CONTROLS_VISIBLE ) );
action = submenu->addAction( QIcon( "" ),
qtr( "Fullscreen Interface" ),
mi, SLOT( toggleFullScreen() ) );
action->setCheckable( true );
action->setChecked( mi->isFullScreen() );
}
else /* We are using the skins interface.
If not, this entry will not show. */
{
objects.clear(); varnames.clear();
QMenu *tools = ToolsMenu( submenu );
submenu->addSeparator();
objects.clear();
varnames.clear();
vlc_object_t *p_object = ( vlc_object_t* )
vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
if( p_object )
{
objects.push_back( p_object );
varnames.push_back( "intf-skins" );
Populate( p_intf, submenu, varnames, objects );
vlc_object_release( p_object );
}
else
msg_Dbg( p_intf, "could not find parent interface" );
vlc_object_t *p_object = ( vlc_object_t* )
vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
if( p_object )
{
objects.push_back( p_object );
varnames.push_back( "intf-skins" );
Populate( p_intf, submenu, varnames, objects );
vlc_object_release( p_object );
}
menu->addMenu( submenu );
else
msg_Warn( p_intf, "could not find parent interface" );
}
else
menu->addMenu( ViewMenu( p_intf, mi, false ));
/* Static entries for ending, like open */
PopupMenuStaticEntries( menu );
p_intf->p_sys->p_popup_menu = menu;
p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
}
else
{
// destroy popup if there is one
delete p_intf->p_sys->p_popup_menu;
p_intf->p_sys->p_popup_menu = NULL;
menu->addMenu( submenu );
}
/* Static entries for ending, like open */
PopupMenuStaticEntries( menu );
p_intf->p_sys->p_popup_menu = menu;
p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
}
#undef ACT_ADD
......@@ -1013,8 +1003,8 @@ void QVLCMenu::updateSystrayMenu( MainInterface *mi,
}
sysMenu->addSeparator();
PopupMenuControlEntries( sysMenu, p_intf, p_input );
PopupMenuPlaylistControlEntries( sysMenu, p_intf, p_input );
PopupMenuControlEntries( sysMenu, p_intf);//, p_input );
PopupMenuPlaylistControlEntries( sysMenu, p_intf);//, p_input );
sysMenu->addSeparator();
addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
......@@ -1038,11 +1028,7 @@ QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
vector<vlc_object_t *> & objects )
{
QMenu *menu = current;
if( !menu )
{
msg_Warn( p_intf, "%s leaking a menu", __func__ );
menu = new QMenu();
}
assert( menu );
currentGroup = NULL;
......
......@@ -79,7 +79,7 @@ class QVLCMenu : public QObject
public:
/* Main bar creation */
static void createMenuBar( MainInterface *mi, intf_thread_t *, bool );
static void createMenuBar( MainInterface *mi, intf_thread_t * );
/* Popups Menus */
static void PopupMenu( intf_thread_t *, bool );
......@@ -102,31 +102,40 @@ private:
/* All main Menus */
static QMenu *FileMenu( intf_thread_t *, QWidget * );
static QMenu *SDMenu( intf_thread_t *, QWidget * );
static QMenu *ToolsMenu( QMenu * );
static QMenu *ToolsMenu( QWidget * );
static QMenu *ViewMenu( intf_thread_t *, QMenu *, MainInterface *,
bool, bool with = true );
static QMenu *ViewMenu( intf_thread_t *, MainInterface *,
bool with = true );
static QMenu *InterfacesMenu( intf_thread_t *p_intf, QMenu * );
static QMenu *NavigMenu( intf_thread_t *, QMenu * );
static QMenu *NavigMenu( intf_thread_t *, QWidget * );
static QMenu *RebuildNavigMenu( intf_thread_t *, QMenu *);
static QMenu *VideoMenu( intf_thread_t *, QMenu * );
static QMenu *VideoMenu( intf_thread_t *, QWidget * );
static QMenu *AudioMenu( intf_thread_t *, QMenu * );
static QMenu *AudioMenu( intf_thread_t *, QWidget * );
static QMenu *InterfacesMenu( intf_thread_t *p_intf, QMenu * );
static QMenu *HelpMenu( QWidget * );
/* Popups Menus */
static void PopupMenuStaticEntries( QMenu *menu );
static void PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf,
input_thread_t *p_input );
static void PopupMenuPlaylistControlEntries( QMenu *menu, intf_thread_t *p_intf,
static void PopupPlayEntries( QMenu *menu, intf_thread_t *p_intf,
input_thread_t *p_input );
static void PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf );
static void PopupMenuPlaylistControlEntries( QMenu *menu, intf_thread_t *p_intf );
/* Generic automenu methods */
static QMenu * Populate( intf_thread_t *, QMenu *current,
vector<const char*>&, vector<vlc_object_t *>& );
static void CreateAndConnect( QMenu *, const char *, QString, QString,
int, vlc_object_t *, vlc_value_t, int, bool c = false );
int, vlc_object_t *, vlc_value_t, int,
bool c = false );
static void UpdateItem( intf_thread_t *, QMenu *, const char *,
vlc_object_t *, bool );
static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t *, bool );
......@@ -152,7 +161,7 @@ public:
{
case 1: QVLCMenu::AudioMenu( p_intf, menu ); break;
case 2: QVLCMenu::VideoMenu( p_intf, menu ); break;
case 3: QVLCMenu::NavigMenu( p_intf, menu ); break;
case 3: QVLCMenu::RebuildNavigMenu( p_intf, menu ); break;
case 4: QVLCMenu::InterfacesMenu( p_intf, menu ); break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment