diff --git a/src/TomahawkWindow.cpp b/src/TomahawkWindow.cpp index dbd0179f7..4ee3f6450 100644 --- a/src/TomahawkWindow.cpp +++ b/src/TomahawkWindow.cpp @@ -3,6 +3,7 @@ * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2012, Leo Franchi * Copyright 2010-2012, Jeff Mitchell + * Copyright 2012, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -114,7 +115,7 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) ui->centralWidget->setContentsMargins( 0, 0, 0, 0 ); TomahawkUtils::unmarginLayout( ui->centralWidget->layout() ); - setMenuBar( ActionCollection::instance()->createMenuBar( this ) ); + setupMenuBar(); setupAccountsMenu(); setupToolBar(); setupSideBar(); @@ -186,6 +187,14 @@ TomahawkWindow::loadSettings() setWindowOpacity( 1 ); } #endif + +#ifndef Q_OS_MAC + bool mbVisible = s->menuBarVisible(); + menuBar()->setVisible( mbVisible ); + m_compactMenuAction->setVisible( !mbVisible ); + ActionCollection::instance()->getAction( "toggleMenuBar" ) + ->setText( mbVisible ? tr( "Hide Menu Bar" ) : tr( "Show Menu Bar" ) ); +#endif } @@ -196,6 +205,7 @@ TomahawkWindow::saveSettings() s->setMainWindowGeometry( saveGeometry() ); s->setMainWindowState( saveState() ); s->setMainWindowSplitterState( ui->splitter->saveState() ); + s->setMenuBarVisible( menuBar()->isVisible() ); } @@ -218,7 +228,7 @@ TomahawkWindow::applyPlatformTweaks() void TomahawkWindow::setupToolBar() { - QToolBar* toolbar = addToolBar( "TomahawkToolbar" ); + QToolBar *toolbar = addToolBar( "TomahawkToolbar" ); toolbar->setObjectName( "TomahawkToolbar" ); toolbar->setMovable( false ); toolbar->setFloatable( false ); @@ -260,6 +270,16 @@ TomahawkWindow::setupToolBar() accountsMenuButton->setToolButtonStyle( Qt::ToolButtonIconOnly ); accountsMenuButton->setPopupMode( QToolButton::InstantPopup ); toolbar->addWidget( accountsMenuButton ); + +#ifndef Q_OS_MAC + QToolButton *compactMenuButton = new QToolButton( toolbar ); + compactMenuButton->setIcon( QIcon( RESPATH "images/advanced-settings.png" ) ); + compactMenuButton->setText( tr( "&Main Menu" ) ); + compactMenuButton->setMenu( m_compactMainMenu ); + compactMenuButton->setToolButtonStyle( Qt::ToolButtonIconOnly ); + compactMenuButton->setPopupMode( QToolButton::InstantPopup ); + m_compactMenuAction = toolbar->addWidget( compactMenuButton ); +#endif } @@ -439,6 +459,8 @@ TomahawkWindow::setupSignals() #if defined( Q_OS_MAC ) connect( ac->getAction( "minimize" ), SIGNAL( triggered() ), SLOT( minimize() ) ); connect( ac->getAction( "zoom" ), SIGNAL( triggered() ), SLOT( maximize() ) ); +#else + connect( ac->getAction( "toggleMenuBar" ), SIGNAL( triggered() ), SLOT( toggleMenuBar() ) ); #endif // @@ -471,6 +493,16 @@ TomahawkWindow::setupAccountsMenu() m_menuAccounts->addSeparator(); } +void +TomahawkWindow::setupMenuBar() +{ + // Always create a menubar, but only create a compactMenu on Windows and X11 + m_menuBar = ActionCollection::instance()->createMenuBar( this ); + setMenuBar( m_menuBar ); +#ifndef Q_OS_MAC + m_compactMainMenu = ActionCollection::instance()->createCompactMenu( this ); +#endif +} void TomahawkWindow::changeEvent( QEvent* e ) @@ -1250,3 +1282,23 @@ TomahawkWindow::crashNow() { TomahawkUtils::crash(); } + +void +TomahawkWindow::toggleMenuBar() //SLOT +{ +#ifndef Q_OS_MAC + if( menuBar()->isVisible() ) + { + menuBar()->setVisible( false ); + ActionCollection::instance()->getAction( "toggleMenuBar" )->setText( tr( "Show Menu Bar" ) ); + m_compactMenuAction->setVisible( true ); + } + else + { + m_compactMenuAction->setVisible( false ); + ActionCollection::instance()->getAction( "toggleMenuBar" )->setText( tr( "Hide Menu Bar" ) ); + menuBar()->setVisible( true ); + } + saveSettings(); +#endif +} diff --git a/src/TomahawkWindow.h b/src/TomahawkWindow.h index 33155e311..b44fdba65 100644 --- a/src/TomahawkWindow.h +++ b/src/TomahawkWindow.h @@ -3,6 +3,7 @@ * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2012, Leo Franchi * Copyright 2010-2011, Jeff Mitchell + * Copyright 2012, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +27,7 @@ #include #include #include +#include #include "Result.h" #include "audio/AudioEngine.h" @@ -143,6 +145,8 @@ private slots: void crashNow(); + void toggleMenuBar(); + #ifdef Q_OS_WIN void audioStateChanged( AudioState newState, AudioState oldState ); void updateWindowsLoveButton(); @@ -155,6 +159,7 @@ private: void applyPlatformTweaks(); void setupSignals(); void setupAccountsMenu(); //must be called before setupToolBar + void setupMenuBar(); void setupToolBar(); void setupSideBar(); void setupUpdateCheck(); @@ -179,8 +184,13 @@ private: JobStatusSortModel* m_jobsModel; // Menus and menu actions: Accounts menu - QMenu *m_menuAccounts; - QAction *m_actionToggleConnect; + QMenu *m_menuAccounts; + QAction *m_actionToggleConnect; + QMenuBar *m_menuBar; +#ifndef Q_OS_MAC + QAction *m_compactMenuAction; + QMenu *m_compactMainMenu; +#endif QAction* m_backAction; QAction* m_forwardAction; diff --git a/src/libtomahawk/ActionCollection.cpp b/src/libtomahawk/ActionCollection.cpp index 7bb74bb5b..73e295867 100644 --- a/src/libtomahawk/ActionCollection.cpp +++ b/src/libtomahawk/ActionCollection.cpp @@ -71,10 +71,10 @@ ActionCollection::initActions() connect( m_actionCollection[ "togglePrivacy" ], SIGNAL( triggered() ), SLOT( togglePrivateListeningMode() ), Qt::UniqueConnection ); m_actionCollection[ "loadPlaylist" ] = new QAction( tr( "&Load Playlist" ), this ); - m_actionCollection[ "loadPlaylist" ]->setShortcut( Qt::Key_Space ); m_actionCollection[ "renamePlaylist" ] = new QAction( tr( "&Rename Playlist" ), this ); m_actionCollection[ "copyPlaylist" ] = new QAction( tr( "&Copy Playlist Link" ), this ); m_actionCollection[ "playPause" ] = new QAction( tr( "&Play" ), this ); + m_actionCollection[ "playPause" ]->setShortcut( Qt::Key_Space ); m_actionCollection[ "stop" ] = new QAction( tr( "&Stop" ), this ); m_actionCollection[ "previousTrack" ] = new QAction( tr( "&Previous Track" ), this ); m_actionCollection[ "nextTrack" ] = new QAction( tr( "&Next Track" ), this ); @@ -97,10 +97,15 @@ ActionCollection::initActions() m_actionCollection[ "showOfflineSources" ]->setCheckable( true ); m_actionCollection[ "preferences" ] = new QAction( tr( "&Configure Tomahawk..." ), this ); m_actionCollection[ "preferences" ]->setMenuRole( QAction::PreferencesRole ); +#ifdef Q_OS_MAC m_actionCollection[ "minimize" ] = new QAction( tr( "Minimize" ), this ); m_actionCollection[ "minimize" ]->setShortcut( QKeySequence( "Ctrl+M" ) ); m_actionCollection[ "zoom" ] = new QAction( tr( "Zoom" ), this ); m_actionCollection[ "zoom" ]->setShortcut( QKeySequence( "Meta+Ctrl+Z" ) ); +#else + m_actionCollection[ "toggleMenuBar" ] = new QAction( tr( "Hide Menu Bar" ), this ); + m_actionCollection[ "toggleMenuBar" ]->setShortcut( QKeySequence( "Ctrl+M" ) ); +#endif m_actionCollection[ "diagnostics" ] = new QAction( tr( "Diagnostics..." ), this ); m_actionCollection[ "aboutTomahawk" ] = new QAction( tr( "About &Tomahawk..." ), this ); m_actionCollection[ "aboutTomahawk" ]->setMenuRole( QAction::AboutRole ); @@ -132,12 +137,11 @@ ActionCollection::createMenuBar( QWidget *parent ) controlsMenu->addAction( m_actionCollection[ "quit" ] ); QMenu *settingsMenu = new QMenu( tr( "&Settings" ), menuBar ); +#ifndef Q_OS_MAC + settingsMenu->addAction( m_actionCollection[ "toggleMenuBar" ] ); +#endif settingsMenu->addAction( m_actionCollection[ "preferences" ] ); - QMenu *windowMenu = new QMenu( tr( "&Window" ), menuBar ); - windowMenu->addAction( m_actionCollection[ "minimize" ] ); - windowMenu->addAction( m_actionCollection[ "zoom" ] ); - QMenu *helpMenu = new QMenu( tr( "&Help" ), menuBar ); helpMenu->addAction( m_actionCollection[ "diagnostics" ] ); helpMenu->addAction( m_actionCollection[ "aboutTomahawk" ] ); @@ -163,6 +167,10 @@ ActionCollection::createMenuBar( QWidget *parent ) menuBar->addMenu( controlsMenu ); menuBar->addMenu( settingsMenu ); #if defined( Q_OS_MAC ) + QMenu *windowMenu = new QMenu( tr( "&Window" ), menuBar ); + windowMenu->addAction( m_actionCollection[ "minimize" ] ); + windowMenu->addAction( m_actionCollection[ "zoom" ] ); + menuBar->addMenu( windowMenu ); #endif menuBar->addMenu( helpMenu ); @@ -170,9 +178,55 @@ ActionCollection::createMenuBar( QWidget *parent ) } QMenu * -ActionCollection::createCompressedMenu( QWidget *parent ) +ActionCollection::createCompactMenu( QWidget *parent ) { + QMenu *compactMenu = new QMenu( tr( "Main Menu" ), parent ); + compactMenu->addAction( m_actionCollection[ "playPause" ] ); + compactMenu->addAction( m_actionCollection[ "previousTrack" ] ); + compactMenu->addAction( m_actionCollection[ "nextTrack" ] ); + compactMenu->addSeparator(); + compactMenu->addAction( m_actionCollection[ "togglePrivacy" ] ); + compactMenu->addAction( m_actionCollection[ "showOfflineSources" ] ); + compactMenu->addSeparator(); + compactMenu->addAction( m_actionCollection[ "loadXSPF" ] ); + compactMenu->addAction( m_actionCollection[ "updateCollection" ] ); + compactMenu->addAction( m_actionCollection[ "rescanCollection" ] ); + compactMenu->addSeparator(); + +#ifdef Q_OS_MAC // This should never happen anyway + compactMenu->addAction( m_actionCollection[ "minimize" ] ); + compactMenu->addAction( m_actionCollection[ "zoom" ] ); +#else + compactMenu->addAction( m_actionCollection[ "toggleMenuBar" ] ); +#endif + compactMenu->addAction( m_actionCollection[ "preferences" ] ); + compactMenu->addSeparator(); + + compactMenu->addAction( m_actionCollection[ "diagnostics" ] ); + compactMenu->addAction( m_actionCollection[ "aboutTomahawk" ] ); + compactMenu->addAction( m_actionCollection[ "legalInfo" ] ); + + // Setup update check +#ifndef Q_OS_MAC + compactMenu->insertSeparator( m_actionCollection[ "aboutTomahawk" ] ); +#endif + +#if defined( Q_OS_MAC ) && defined( HAVE_SPARKLE ) + compactMenu->addAction( m_actionCollection[ "checkForUpdates" ] ); +#elif defined( Q_WS_WIN ) + compactMenu->addSeparator(); + compactMenu->addAction( m_actionCollection[ "checkForUpdates" ] ); +#endif + if ( qApp->arguments().contains( "--debug" ) ) + { + compactMenu->addSeparator(); + compactMenu->addAction( m_actionCollection[ "crashNow" ] ); + } + compactMenu->addSeparator(); + compactMenu->addAction( m_actionCollection[ "quit" ] ); + + return compactMenu; } diff --git a/src/libtomahawk/ActionCollection.h b/src/libtomahawk/ActionCollection.h index aa24ba58f..0de8f25cd 100644 --- a/src/libtomahawk/ActionCollection.h +++ b/src/libtomahawk/ActionCollection.h @@ -44,8 +44,18 @@ public: void initActions(); + /** + * This method returns a main menu bar, suitable for Windows, Mac and X11. + */ QMenuBar *createMenuBar( QWidget *parent ); - QMenu *createCompressedMenu( QWidget *parent ); + + /** + * Returns a QMenu with all the entries that would normally be in the main menu, + * arranged in a sensible way. The compressed menu makes absolutely no sense on Mac, + * and fairly little sense on Unity and other X11 desktop configurations which pull + * out the menu bar from the window. + */ + QMenu *createCompactMenu( QWidget *parent ); QAction* getAction( const QString& name ); QList< QAction* > getAction( ActionDestination category ); diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index e73105a54..d8bd1063c 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -901,6 +901,24 @@ TomahawkSettings::setVerboseNotifications( bool notifications ) setValue( "ui/notifications/verbose", notifications ); } +bool +TomahawkSettings::menuBarVisible() const +{ +#ifndef Q_OS_MAC + return value( "ui/mainwindow/menuBarVisible", true ).toBool(); +#else + return true; +#endif +} + +void +TomahawkSettings::setMenuBarVisible( bool visible ) +{ +#ifndef Q_OS_MAC + setValue( "ui/mainwindow/menuBarVisible", visible ); +#endif +} + bool TomahawkSettings::showOfflineSources() const diff --git a/src/libtomahawk/TomahawkSettings.h b/src/libtomahawk/TomahawkSettings.h index 42fdac340..cfd43baeb 100644 --- a/src/libtomahawk/TomahawkSettings.h +++ b/src/libtomahawk/TomahawkSettings.h @@ -76,6 +76,9 @@ public: bool verboseNotifications() const; void setVerboseNotifications( bool notifications ); + bool menuBarVisible() const; + void setMenuBarVisible( bool visible ); + // Collection Stuff bool showOfflineSources() const; void setShowOfflineSources( bool show );