File indexing completed on 2024-05-05 04:48:44

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 #ifndef AMAROK_PLAYLISTTOOLBAR_H
0020 #define AMAROK_PLAYLISTTOOLBAR_H
0021 
0022 #include <KActionMenu>
0023 
0024 #include <QToolBar>
0025 
0026 namespace Playlist {
0027 
0028 /**
0029   * The Playlist::ToolBar class provides a toolbar with collapsible actions, which end up
0030   * in a menu if the toolbar is too narrow to fit all the icons in a row.
0031   * @author Teo Mrnjavac <teo@kde.org
0032   */
0033 class ToolBar : public QToolBar
0034 {
0035     Q_OBJECT
0036 public:
0037     /**
0038       * Constructor.
0039       * @param parent a pointer to the parent widget.
0040       */
0041     explicit ToolBar( QWidget *parent );
0042 
0043     /**
0044       * Adds a list of actions which are either placed at the beginning of the toolbar, or
0045       * collapsed into a menu at the beginning of the toolbar.
0046       * @param actions the collapsible actions.
0047       */
0048     void addCollapsibleActions( const QActionGroup *actions );
0049 
0050 private Q_SLOTS:
0051     /**
0052       * Sets the collapsed state of the toolbar.
0053       * @param collapsed true if the actions are to be collapsed, otherwise false.
0054       */
0055     void setCollapsed( bool collapsed );
0056 
0057     /**
0058       * Handles the collapsing state after an action is added.
0059       */
0060     void onActionsAdded();
0061 
0062 protected:
0063     void resizeEvent( QResizeEvent *event ) override;
0064     void actionEvent( QActionEvent *event ) override;
0065 
0066 private:
0067     /**
0068       * Computes the limit width, if the toolbar is smaller then the collapsible actions
0069       * should be collapsed.
0070       */
0071     inline int limitWidth()
0072     {
0073         int limitWidth;
0074         if( m_collapsed )
0075             limitWidth = (actions().count() + m_collapsibleActions->actions().count() -1)*27;
0076         else
0077             limitWidth = (actions().count() -1)*27;
0078         return limitWidth;
0079     }
0080 
0081     KActionMenu *m_playlistOperationsMenu;
0082     QActionGroup *m_collapsibleActions;
0083     QActionGroup *m_visibleActions;
0084 
0085     bool m_collapsed;
0086 };
0087 
0088 } // namespace Playlist
0089 
0090 #endif // AMAROK_PLAYLISTTOOLBAR_H