annotate widgets/SubdividingMenu.h @ 151:8f51db2434dc

* Pull alphabetical categorisation code out into a SubdividingMenu class
author Chris Cannam
date Mon, 25 Sep 2006 11:21:12 +0000
parents
children 6a3f3c13173f
rev   line source
Chris@151 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@151 2
Chris@151 3 /*
Chris@151 4 Sonic Visualiser
Chris@151 5 An audio file viewer and annotation editor.
Chris@151 6 Centre for Digital Music, Queen Mary, University of London.
Chris@151 7
Chris@151 8 This program is free software; you can redistribute it and/or
Chris@151 9 modify it under the terms of the GNU General Public License as
Chris@151 10 published by the Free Software Foundation; either version 2 of the
Chris@151 11 License, or (at your option) any later version. See the file
Chris@151 12 COPYING included with this distribution for more information.
Chris@151 13 */
Chris@151 14
Chris@151 15 #ifndef _SUBDIVIDING_MENU_H_
Chris@151 16 #define _SUBDIVIDING_MENU_H_
Chris@151 17
Chris@151 18 #include <QMenu>
Chris@151 19
Chris@151 20 #include <QString>
Chris@151 21 #include <set>
Chris@151 22 #include <map>
Chris@151 23
Chris@151 24 /**
Chris@151 25 * A menu that divides its entries into submenus, alphabetically. For
Chris@151 26 * menus that may contain a very large or small number of named items
Chris@151 27 * (e.g. plugins).
Chris@151 28 *
Chris@151 29 * The menu needs to be told, before any of the actions are added,
Chris@151 30 * what the set of entry strings will be, so it can determine a
Chris@151 31 * reasonable categorisation. Do this by calling the setEntries()
Chris@151 32 * method.
Chris@151 33 */
Chris@151 34
Chris@151 35 class SubdividingMenu : public QMenu
Chris@151 36 {
Chris@151 37 public:
Chris@151 38 SubdividingMenu(QWidget *parent = 0);
Chris@151 39 SubdividingMenu(const QString &title, QWidget *parent = 0);
Chris@151 40 virtual ~SubdividingMenu();
Chris@151 41
Chris@151 42 void setEntries(const std::set<QString> &entries);
Chris@151 43
Chris@151 44 // Action names and strings passed to addAction and addMenu must
Chris@151 45 // appear in the set previously given to setEntries. If you want
Chris@151 46 // to use a different string, use the two-argument method and pass
Chris@151 47 // the entry string (used to determine which submenu the action
Chris@151 48 // ends up on) as the first argument.
Chris@151 49
Chris@151 50 virtual void addAction(QAction *);
Chris@151 51 virtual QAction *addAction(const QString &);
Chris@151 52 virtual void addAction(const QString &entry, QAction *);
Chris@151 53
Chris@151 54 virtual void addMenu(QMenu *);
Chris@151 55 virtual QMenu *addMenu(const QString &);
Chris@151 56 virtual void addMenu(const QString &entry, QMenu *);
Chris@151 57
Chris@151 58 protected:
Chris@151 59 std::map<QString, QMenu *> m_nameToChunkMenuMap;
Chris@151 60 };
Chris@151 61
Chris@151 62 #endif
Chris@151 63