File indexing completed on 2024-04-14 11:04:34

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 class Component;
0018 class GlobalShortcut;
0019 
0020 /**
0021  * @author Michael Jansen <kde@michael-jansen.biz>
0022  */
0023 class GlobalShortcutContext
0024 {
0025 public:
0026     /**
0027      * Default constructor
0028      */
0029     GlobalShortcutContext(const QString &uniqueName, const QString &friendlyName, Component *component);
0030 
0031     /**
0032      * Destructor
0033      */
0034     virtual ~GlobalShortcutContext();
0035 
0036     //! Adds @p shortcut to the context
0037     void addShortcut(GlobalShortcut *shortcut);
0038 
0039     //! Return KGlobalShortcutInfos for all shortcuts
0040     QList<KGlobalShortcutInfo> allShortcutInfos() const;
0041 
0042     /**
0043      * Get the name for the context
0044      */
0045     QString uniqueName() const;
0046     QString friendlyName() const;
0047 
0048     Component *component();
0049     Component const *component() const;
0050 
0051     //! Get shortcut for @p key or nullptr
0052     GlobalShortcut *getShortcutByKey(const QKeySequence &key, KGlobalAccel::MatchType type) const;
0053 
0054     //! Remove @p shortcut from the context. The shortcut is not deleted.
0055     GlobalShortcut *takeShortcut(GlobalShortcut *shortcut);
0056 
0057     // Returns true if key is not used by any global shortcuts in this context,
0058     // otherwise returns false
0059     bool isShortcutAvailable(const QKeySequence &key) const;
0060 
0061 private:
0062     friend class Component;
0063 
0064     //! The unique name for this context
0065     QString _uniqueName;
0066 
0067     //! The unique name for this context
0068     QString _friendlyName;
0069 
0070     //! The component the context belongs to
0071     Component *_component = nullptr;
0072 
0073     //! The actions associated with this context
0074     QHash<QString, GlobalShortcut *> _actionsMap;
0075 };
0076 
0077 #endif /* #ifndef GLOBALSHORTCUTCONTEXT_H */