1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-22 00:42:04 +02:00

Added support for hiding the menu bar and showing the compact menu.

Except on Mac, where things should behave exactly as before.
This commit is contained in:
Teo Mrnjavac 2012-08-04 14:50:19 +02:00
parent 9d913a49aa
commit 8ffe9019e3
6 changed files with 158 additions and 11 deletions

@ -3,6 +3,7 @@
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2012, Teo Mrnjavac <teo@kde.org>
*
* 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
// <AccountHandler>
@ -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
}

@ -3,6 +3,7 @@
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2012, Teo Mrnjavac <teo@kde.org>
*
* 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 <QPushButton>
#include <QString>
#include <QStackedWidget>
#include <QToolButton>
#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;

@ -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;
}

@ -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 );

@ -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

@ -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 );