1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 20:45:34 +00:00
openmw/apps/opencs/model/prefs/shortcuteventhandler.hpp

66 lines
1.6 KiB
C++
Raw Normal View History

#ifndef CSM_PREFS_SHORTCUT_EVENT_HANDLER_H
#define CSM_PREFS_SHORTCUT_EVENT_HANDLER_H
#include <map>
#include <vector>
#include <QObject>
class QEvent;
class QWidget;
namespace CSMPrefs
{
class Shortcut;
/// Users of this class should install it as an event handler
class ShortcutEventHandler : public QObject
{
2022-09-22 18:26:05 +00:00
Q_OBJECT
2022-09-22 18:26:05 +00:00
public:
ShortcutEventHandler(QObject* parent);
2022-09-22 18:26:05 +00:00
void addShortcut(Shortcut* shortcut);
void removeShortcut(Shortcut* shortcut);
2022-09-22 18:26:05 +00:00
protected:
bool eventFilter(QObject* watched, QEvent* event) override;
2022-09-22 18:26:05 +00:00
private:
typedef std::vector<Shortcut*> ShortcutList;
// Child, Parent
typedef std::map<QWidget*, QWidget*> WidgetMap;
typedef std::map<QWidget*, ShortcutList> ShortcutMap;
2022-09-22 18:26:05 +00:00
enum MatchResult
{
Matches_WithMod,
Matches_NoMod,
Matches_Not
};
2022-09-22 18:26:05 +00:00
void updateParent(QWidget* widget);
2022-09-22 18:26:05 +00:00
bool activate(QWidget* widget, unsigned int mod, unsigned int button);
2022-09-22 18:26:05 +00:00
bool deactivate(QWidget* widget, unsigned int mod, unsigned int button);
2022-09-22 18:26:05 +00:00
bool checkModifier(unsigned int mod, unsigned int button, Shortcut* shortcut, bool activate);
2022-09-22 18:26:05 +00:00
MatchResult match(unsigned int mod, unsigned int button, unsigned int value);
2022-09-22 18:26:05 +00:00
// Prefers Matches_WithMod and a larger number of buttons
static bool sort(const std::pair<MatchResult, Shortcut*>& left, const std::pair<MatchResult, Shortcut*>& right);
2022-09-22 18:26:05 +00:00
WidgetMap mChildParentRelations;
ShortcutMap mWidgetShortcuts;
2022-09-22 18:26:05 +00:00
private slots:
2022-09-22 18:26:05 +00:00
void widgetDestroyed();
};
}
#endif