1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-14 13:01:53 +02:00

Made the compact and accounts menus pop up inside the window.

This commit is contained in:
Teo Mrnjavac 2012-08-04 17:15:39 +02:00
parent fee87151d3
commit fd87c5f352
4 changed files with 103 additions and 6 deletions

View File

@ -73,6 +73,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
TomahawkWindow.cpp
LoadXSPFDialog.cpp
SocialWidget.cpp
ContainedMenuButton.cpp
)
IF( WITH_BREAKPAD )

View File

@ -0,0 +1,52 @@
/* === This file is part of Tomahawk Player - <http://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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ContainedMenuButton.h"
#include <QtGui/QMouseEvent>
ContainedMenuButton::ContainedMenuButton( QWidget *parent )
: QToolButton( parent )
{
}
void
ContainedMenuButton::setMenu( QMenu *menu )
{
m_menu = menu;
connect( m_menu, SIGNAL( aboutToHide() ), SLOT( menuHidden() ) );
}
void
ContainedMenuButton::mousePressEvent( QMouseEvent *event )
{
if( m_menu )
{
QPoint myPos = mapToGlobal( rect().bottomRight() );
myPos.rx() -= m_menu->sizeHint().width();
m_menu->popup( myPos );
event->accept();
}
QToolButton::mousePressEvent( event );
}
void
ContainedMenuButton::menuHidden()
{
setDown( false );
}

47
src/ContainedMenuButton.h Normal file
View File

@ -0,0 +1,47 @@
/* === This file is part of Tomahawk Player - <http://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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONTAINEDMENUBUTTON_H
#define CONTAINEDMENUBUTTON_H
#include <QtGui/QMenu>
#include <QtGui/QToolButton>
/**
* @brief The ContainedMenuButton class defines a modified QToolButton that pops
* up a QMenu under itself, stretching left instead of right and witout
* drawing an arrow primitive.
*/
class ContainedMenuButton : public QToolButton
{
Q_OBJECT
public:
explicit ContainedMenuButton( QWidget *parent = 0 );
void setMenu( QMenu *menu );
QMenu *menu() const { return m_menu; }
protected:
void mousePressEvent( QMouseEvent *event );
private slots:
void menuHidden();
private:
QMenu *m_menu;
};
#endif // CONTAINEDMENUBUTTON_H

View File

@ -72,6 +72,7 @@
#include "libtomahawk/filemetadata/ScanManager.h"
#include "TomahawkApp.h"
#include "LoadXSPFDialog.h"
#include "ContainedMenuButton.h"
#ifdef Q_OS_WIN
#include <qtsparkle/Updater>
@ -261,23 +262,19 @@ TomahawkWindow::setupToolBar()
rightSpacer->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
toolbar->addWidget( rightSpacer );
QToolButton *accountsMenuButton = new QToolButton( toolbar );
ContainedMenuButton *accountsMenuButton = new ContainedMenuButton( toolbar );
accountsMenuButton->setIcon( QIcon( RESPATH "images/account-settings.png" ) );
accountsMenuButton->setText( tr( "&Network" ) );
accountsMenuButton->setMenu( m_menuAccounts );
//TODO: when we decide if compressed menus go left or right, if they go right, make
// them pop up *inside* the main window.
accountsMenuButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
accountsMenuButton->setPopupMode( QToolButton::InstantPopup );
toolbar->addWidget( accountsMenuButton );
#ifndef Q_OS_MAC
QToolButton *compactMenuButton = new QToolButton( toolbar );
ContainedMenuButton *compactMenuButton = new ContainedMenuButton( toolbar );
compactMenuButton->setIcon( QIcon( RESPATH "images/configure.png" ) );
compactMenuButton->setText( tr( "&Main Menu" ) );
compactMenuButton->setMenu( m_compactMainMenu );
compactMenuButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
compactMenuButton->setPopupMode( QToolButton::InstantPopup );
m_compactMenuAction = toolbar->addWidget( compactMenuButton );
#endif
}