1 /****************************************************************************************
2  * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org>                                *
3  * Copyright (c) 2009 Mark Kretschmann <kretschmann@kde.org>                            *
4  *                                                                                      *
5  * This program is free software; you can redistribute it and/or modify it under        *
6  * the terms of the GNU General Public License as published by the Free Software        *
7  * Foundation; either version 2 of the License, or (at your option) any later           *
8  * version.                                                                             *
9  *                                                                                      *
10  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
12  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
13  *                                                                                      *
14  * You should have received a copy of the GNU General Public License along with         *
15  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
16  ****************************************************************************************/
17 
18 #include "SlimToolbar.h"
19 
20 #include "ActionClasses.h"
21 #include "core/support/Amarok.h"
22 #include "EngineController.h"
23 #include "VolumePopupButton.h"
24 
25 #include "widgets/ProgressWidget.h"
26 
27 #include <QApplication>
28 #include <QIcon>
29 #include <KLocalizedString>
30 #include <QVBoxLayout>
31 
32 #include <QEvent>
33 #include <QLayout>
34 
SlimToolbar(QWidget * parent)35 SlimToolbar::SlimToolbar( QWidget * parent )
36     : QToolBar( i18n( "Slim Toolbar" ), parent )
37     , m_currentTrackToolbar( 0 )
38     , m_volumePopupButton( 0 )
39 {
40     setObjectName( "Slim Toolbar" );
41 
42     setIconSize( QSize( 28, 28 ) );
43     layout()->setSpacing( 0 );
44     setContentsMargins( 0, 0, 0, 0 );
45 
46     addAction( Amarok::actionCollection()->action( "prev" ) );
47     addAction( Amarok::actionCollection()->action( "play_pause" ) );
48     addAction( Amarok::actionCollection()->action( "stop" ) );
49     addAction( Amarok::actionCollection()->action( "next" ) );
50 
51     m_currentTrackToolbar = new CurrentTrackToolbar( 0 );
52 
53     addWidget( m_currentTrackToolbar );
54 
55     ProgressWidget *progressWidget = new ProgressWidget( 0 );
56     addWidget( progressWidget );
57 
58 
59     QToolBar *volumeToolBar = new QToolBar( this );
60     volumeToolBar->setIconSize( QSize( 22, 22 ) );
61     volumeToolBar->setContentsMargins( 0, 0, 0, 0 );
62     m_volumePopupButton = new VolumePopupButton( this );
63     volumeToolBar->addWidget( m_volumePopupButton );
64     addWidget( volumeToolBar );
65 
66     installEventFilter( this );
67 }
68 
~SlimToolbar()69 SlimToolbar::~SlimToolbar()
70 {}
71 
72 bool
eventFilter(QObject * object,QEvent * event)73 SlimToolbar::eventFilter( QObject* object, QEvent* event )
74 {
75     // This makes it possible to change volume by using the mouse wheel anywhere on the toolbar
76     if( event->type() == QEvent::Wheel && object == this )
77     {
78         qApp->sendEvent( m_volumePopupButton, event );
79         return true;
80     }
81 
82     return QToolBar::eventFilter( object, event );
83 }
84 
85 
86