Warning, file /multimedia/amarok/src/playlist/PlaylistToolBar.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /**************************************************************************************** 0002 * Copyright (c) 2011 Teo Mrnjavac <teo@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) version 3 or * 0007 * any later version accepted by the membership of KDE e.V. (or its successor approved * 0008 * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * 0009 * version 3 of the license. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0013 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License along with * 0016 * this program. If not, see <http://www.gnu.org/licenses/>. * 0017 ****************************************************************************************/ 0018 0019 #include "PlaylistToolBar.h" 0020 #include "core/support/Debug.h" 0021 0022 #include <KLocalizedString> 0023 0024 #include <QToolButton> 0025 #include <QResizeEvent> 0026 0027 namespace Playlist { 0028 0029 ToolBar::ToolBar( QWidget *parent ) : 0030 QToolBar( parent ), 0031 m_collapsed( false ) 0032 { 0033 setObjectName( QStringLiteral("PlaylistToolBar") ); 0034 0035 m_collapsibleActions = new QActionGroup( parent ); //needs to exist before adding any 0036 //other action to the toolbar 0037 0038 m_playlistOperationsMenu = new KActionMenu( QIcon::fromTheme( QStringLiteral("amarok_playlist") ), 0039 i18n( "&Playlist" ), parent ); 0040 m_playlistOperationsMenu->setDelayed( false ); 0041 m_playlistOperationsMenu->setVisible( false ); 0042 0043 addAction( m_playlistOperationsMenu ); 0044 addSeparator(); 0045 0046 } 0047 0048 void ToolBar::addCollapsibleActions( const QActionGroup *actions ) 0049 { 0050 foreach( QAction *a, actions->actions() ) 0051 { 0052 m_collapsibleActions->addAction( a ); 0053 } 0054 onActionsAdded(); 0055 } 0056 0057 void ToolBar::setCollapsed( bool collapsed ) //SLOT 0058 { 0059 m_collapsed = collapsed; 0060 if( collapsed ) 0061 { 0062 foreach( QAction *a, m_collapsibleActions->actions() ) 0063 { 0064 removeAction( a ); 0065 m_playlistOperationsMenu->addAction( a ); 0066 } 0067 } 0068 else 0069 { 0070 insertActions( m_playlistOperationsMenu, m_collapsibleActions->actions() ); 0071 foreach( QAction *a, m_collapsibleActions->actions() ) 0072 { 0073 m_playlistOperationsMenu->removeAction( a ); 0074 } 0075 } 0076 m_playlistOperationsMenu->setVisible( collapsed ); 0077 } 0078 0079 void ToolBar::onActionsAdded() 0080 { 0081 int limit = limitWidth(); 0082 if( width() < limit ) 0083 setCollapsed( true ); 0084 else if( width() >= limit ) 0085 setCollapsed( false ); 0086 } 0087 0088 void ToolBar::resizeEvent( QResizeEvent *event ) 0089 { 0090 QToolBar::resizeEvent( event ); 0091 int limit = limitWidth(); 0092 0093 if( event->oldSize().width() >= limit && event->size().width() < limit ) 0094 setCollapsed( true ); 0095 else if( event->oldSize().width() < limit && event->size().width() >= limit ) 0096 setCollapsed( false ); 0097 } 0098 0099 void ToolBar::actionEvent( QActionEvent *event ) 0100 { 0101 QToolBar::actionEvent( event ); 0102 if( ( event->type() == QEvent::ActionAdded || event->type() == QEvent::ActionRemoved ) 0103 && !m_collapsibleActions->actions().contains( event->action() ) ) 0104 { 0105 onActionsAdded(); 0106 } 0107 } 0108 0109 } // namespace Playlist