Chris@151: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@151: Chris@151: /* Chris@151: Sonic Visualiser Chris@151: An audio file viewer and annotation editor. Chris@151: Centre for Digital Music, Queen Mary, University of London. Chris@182: This file copyright 2006 QMUL. Chris@151: Chris@151: This program is free software; you can redistribute it and/or Chris@151: modify it under the terms of the GNU General Public License as Chris@151: published by the Free Software Foundation; either version 2 of the Chris@151: License, or (at your option) any later version. See the file Chris@151: COPYING included with this distribution for more information. Chris@151: */ Chris@151: Chris@1347: #ifndef SV_SUBDIVIDING_MENU_H Chris@1347: #define SV_SUBDIVIDING_MENU_H Chris@151: Chris@151: #include Chris@151: Chris@151: #include Chris@151: #include Chris@151: #include Chris@151: Chris@151: /** Chris@151: * A menu that divides its entries into submenus, alphabetically. For Chris@151: * menus that may contain a very large or small number of named items Chris@151: * (e.g. plugins). Chris@151: * Chris@151: * The menu needs to be told, before any of the actions are added, Chris@151: * what the set of entry strings will be, so it can determine a Chris@151: * reasonable categorisation. Do this by calling the setEntries() Chris@152: * method. If it isn't practical to do this in advance, then add the Chris@152: * entries and call entriesAdded() afterwards instead. Chris@151: */ Chris@151: Chris@151: class SubdividingMenu : public QMenu Chris@151: { Chris@222: Q_OBJECT Chris@222: Chris@151: public: Chris@807: SubdividingMenu(int lowerLimit = 0, int upperLimit = 0, Chris@152: QWidget *parent = 0); Chris@807: SubdividingMenu(const QString &title, int lowerLimit = 0, Chris@807: int upperLimit = 0, QWidget *parent = 0); Chris@151: virtual ~SubdividingMenu(); Chris@151: Chris@151: void setEntries(const std::set &entries); Chris@152: void entriesAdded(); Chris@151: Chris@151: // Action names and strings passed to addAction and addMenu must Chris@151: // appear in the set previously given to setEntries. If you want Chris@151: // to use a different string, use the two-argument method and pass Chris@151: // the entry string (used to determine which submenu the action Chris@151: // ends up on) as the first argument. Chris@151: Chris@151: virtual void addAction(QAction *); Chris@151: virtual QAction *addAction(const QString &); Chris@151: virtual void addAction(const QString &entry, QAction *); Chris@151: Chris@151: virtual void addMenu(QMenu *); Chris@151: virtual QMenu *addMenu(const QString &); Chris@151: virtual void addMenu(const QString &entry, QMenu *); Chris@151: Chris@151: protected: Chris@151: std::map m_nameToChunkMenuMap; Chris@152: Chris@807: int m_lowerLimit; Chris@807: int m_upperLimit; Chris@152: Chris@152: bool m_entriesSet; Chris@152: std::map m_pendingEntries; Chris@151: }; Chris@151: Chris@151: #endif Chris@151: