File indexing completed on 2022-08-05 18:04:18
0001 /* 0002 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef GLOBALSHORTCUTCONTEXT_H 0008 #define GLOBALSHORTCUTCONTEXT_H 0009 0010 #include "kglobalshortcutinfo.h" 0011 0012 #include <QHash> 0013 #include <QString> 0014 0015 #include <kglobalaccel.h> 0016 0017 namespace KdeDGlobalAccel 0018 { 0019 class Component; 0020 } 0021 0022 class GlobalShortcut; 0023 0024 /** 0025 * @author Michael Jansen <kde@michael-jansen.biz> 0026 */ 0027 class GlobalShortcutContext 0028 { 0029 public: 0030 /** 0031 * Default constructor 0032 */ 0033 GlobalShortcutContext(const QString &uniqueName, const QString &friendlyName, KdeDGlobalAccel::Component *component); 0034 0035 /** 0036 * Destructor 0037 */ 0038 virtual ~GlobalShortcutContext(); 0039 0040 //! Adds @p shortcut to the context 0041 void addShortcut(GlobalShortcut *shortcut); 0042 0043 //! Return KGlobalShortcutInfos for all shortcuts 0044 QList<KGlobalShortcutInfo> allShortcutInfos() const; 0045 0046 /** 0047 * Get the name for the context 0048 */ 0049 QString uniqueName() const; 0050 QString friendlyName() const; 0051 0052 KdeDGlobalAccel::Component *component(); 0053 KdeDGlobalAccel::Component const *component() const; 0054 0055 //! Get shortcut for @p key or nullptr 0056 GlobalShortcut *getShortcutByKey(const QKeySequence &key, KGlobalAccel::MatchType type) const; 0057 0058 //! Remove @p shortcut from the context. The shortcut is not deleted. 0059 GlobalShortcut *takeShortcut(GlobalShortcut *shortcut); 0060 0061 // Returns true if key is not used by any global shortcuts in this context, 0062 // otherwise returns false 0063 bool isShortcutAvailable(const QKeySequence &key) const; 0064 0065 private: 0066 friend class KdeDGlobalAccel::Component; 0067 0068 //! The unique name for this context 0069 QString _uniqueName; 0070 0071 //! The unique name for this context 0072 QString _friendlyName; 0073 0074 //! The component the context belongs to 0075 KdeDGlobalAccel::Component *_component = nullptr; 0076 0077 //! The actions associated with this context 0078 QHash<QString, GlobalShortcut *> _actionsMap; 0079 }; 0080 0081 #endif /* #ifndef GLOBALSHORTCUTCONTEXT_H */