-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobalshortcutmanager.cpp
More file actions
89 lines (77 loc) · 2.72 KB
/
globalshortcutmanager.cpp
File metadata and controls
89 lines (77 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* globalshortcutmanager.cpp - Class managing global shortcuts
* Copyright (C) 2006 Maciej Niedzielski
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "globalshortcutmanager.h"
#include <QCoreApplication>
#include "globalshortcuttrigger.h"
/**
* \brief Constructs new GlobalShortcutManager.
*/
GlobalShortcutManager::GlobalShortcutManager()
: QObject(QCoreApplication::instance())
{
}
GlobalShortcutManager* GlobalShortcutManager::instance_ = 0;
/**
* \brief Returns the instance of GlobalShortcutManager.
*/
GlobalShortcutManager* GlobalShortcutManager::instance()
{
if (!instance_)
instance_ = new GlobalShortcutManager();
return instance_;
}
/**
* \brief Connects a key sequence with a slot.
* \param key, global shortcut to be connected
* \param receiver, object which should receive the notification
* \param slot, the SLOT() of the \a receiver which should be triggerd if the \a key is activated
*/
void GlobalShortcutManager::connect(const QKeySequence& key, QObject* receiver, const char* slot, int value)
{
KeyTrigger* t = instance()->triggers_[key];
if (!t) {
t = new KeyTrigger(key, value);
instance()->triggers_.insert(key, t);
}
QObject::connect(t, SIGNAL(activated(int)), receiver, slot);
}
/**
* \brief Disonnects a key sequence from a slot.
* \param key, global shortcut to be disconnected
* \param receiver, object which \a slot is about to be disconnected
* \param slot, the SLOT() of the \a receiver which should no longer be triggerd if the \a key is activated
*/
void GlobalShortcutManager::disconnect(const QKeySequence& key, QObject* receiver, const char* slot)
{
KeyTrigger* t = instance()->triggers_[key];
if (!t) {
return;
}
QObject::disconnect(t, SIGNAL(activated()), receiver, slot);
if (!t->isUsed()) {
delete instance()->triggers_.take(key);
}
}
void GlobalShortcutManager::clear()
{
foreach (KeyTrigger* t, instance()->triggers_)
delete t;
instance()->triggers_.clear();
}