1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************
20 * This is a subset of the API of KDE's KActionCollection. *
21 ***************************************************************************/
25 #include "uisupport-export.h"
31 # include <KXmlGui/KActionCollection>
46 using ActionCollectionParent = KActionCollection;
48 using ActionCollectionParent = QObject;
51 class UISUPPORT_EXPORT ActionCollection : public ActionCollectionParent
56 using ActionCollectionParent::ActionCollectionParent;
58 // Convenience function that takes a list of Actions
59 void addActions(const std::vector<std::pair<QString, Action *>> &actions);
61 // Everything else is defined in KActionCollection
63 /// Clears the entire action collection, deleting all actions.
66 /// Associate all action in this collection to the given \a widget.
67 /** Not that this only adds all current actions in the collection to that widget;
68 * subsequently added actions won't be added automatically.
70 void associateWidget(QWidget *widget) const;
72 /// Associate all actions in this collection to the given \a widget.
73 /** Subsequently added actions will be automagically associated with this widget as well.
75 void addAssociatedWidget(QWidget *widget);
77 void removeAssociatedWidget(QWidget *widget);
78 QList<QWidget *> associatedWidgets() const;
79 void clearAssociatedWidgets();
82 void writeSettings() const;
87 QAction *action(int index) const;
88 QAction *action(const QString &name) const;
89 QList<QAction *> actions() const;
91 QAction *addAction(const QString &name, QAction *action);
92 void removeAction(QAction *action);
93 QAction *takeAction(QAction *action);
96 void inserted(QAction *action);
97 void actionHovered(QAction *action);
98 void actionTriggered(QAction *action);
101 void connectNotify(const QMetaMethod &signal) override;
102 virtual void slotActionTriggered();
105 void slotActionHovered();
106 void actionDestroyed(QObject *);
107 void associatedWidgetDestroyed(QObject *);
110 bool unlistAction(QAction *);
112 QMap<QString, QAction *> _actionByName;
113 QList<QAction *> _actions;
114 QList<QWidget *> _associatedWidgets;
116 bool _connectHovered{false};
117 bool _connectTriggered{false};
119 #endif /* HAVE_KDE */