1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************
20 * This is a subset of the API of KDE's KActionCollection. *
21 ***************************************************************************/
23 #ifndef ACTIONCOLLECTION_H_
24 #define ACTIONCOLLECTION_H_
37 class ActionCollection : public QObject {
41 explicit ActionCollection(QObject *parent);
42 virtual ~ActionCollection();
44 /// Clears the entire action collection, deleting all actions.
47 /// Associate all action in this collection to the given \a widget.
48 /** Not that this only adds all current actions in the collection to that widget;
49 * subsequently added actions won't be added automatically.
51 void associateWidget(QWidget *widget) const;
53 /// Associate all actions in this collection to the given \a widget.
54 /** Subsequently added actions will be automagically associated with this widget as well.
56 void addAssociatedWidget(QWidget *widget);
58 void removeAssociatedWidget(QWidget *widget);
59 QList<QWidget *> associatedWidgets() const;
60 void clearAssociatedWidgets();
63 void writeSettings() const;
65 inline int count() const;
66 inline bool isEmpty() const;
68 QAction *action(int index) const;
69 QAction *action(const QString &name) const;
70 QList<QAction *> actions() const;
72 QAction *addAction(const QString &name, QAction *action);
73 Action *addAction(const QString &name, Action *action);
74 Action *addAction(const QString &name, const QObject *receiver = 0, const char *member = 0);
75 void removeAction(QAction *action);
76 QAction *takeAction(QAction *action);
78 /// Create new action under the given name, add it to the collection and connect its triggered(bool) signal to the specified receiver.
79 template<class ActionType>
80 ActionType *add(const QString &name, const QObject *receiver = 0, const char *member = 0) {
81 ActionType *a = new ActionType(this);
82 if(receiver && member)
83 connect(a, SIGNAL(triggered(bool)), receiver, member);
89 void inserted(QAction *action);
90 void actionHovered(QAction *action);
91 void actionTriggered(QAction *action);
94 virtual void connectNotify(const char *signal);
95 virtual void slotActionTriggered();
98 void slotActionHovered();
99 void actionDestroyed(QObject *);
100 void associatedWidgetDestroyed(QObject *);
103 bool unlistAction(QAction *);
105 QMap<QString, QAction *> _actionByName;
106 QList<QAction *> _actions;
107 QList<QWidget *> _associatedWidgets;
109 bool _connectHovered;
110 bool _connectTriggered;
113 int ActionCollection::count() const { return actions().count(); }
114 bool ActionCollection::isEmpty() const { return actions().count(); }