-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjsrglobalhotkey.cpp
More file actions
70 lines (57 loc) · 1.64 KB
/
Copy pathjsrglobalhotkey.cpp
File metadata and controls
70 lines (57 loc) · 1.64 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
#include "jsrglobalhotkey.h"
#include "jscallback.h"
JSRGlobalHotkey::JSRGlobalHotkey(QJSEngine* pengine, QJSValue callback, const QString& shortcut)
: JSCallback(pengine, callback), m_shortcut_string(shortcut)
#ifdef Q_OS_WIN
, m_pshortcut(NULL)
#endif
{
//do nothing
}
JSRGlobalHotkey::~JSRGlobalHotkey()
{
#ifdef Q_OS_WIN
delete m_pshortcut;
#endif
}
bool JSRGlobalHotkey::exec()
{
#ifdef Q_OS_WIN
m_pshortcut = new QxtGlobalShortcut();
m_pshortcut->setShortcut(QKeySequence(m_shortcut_string));
connect(m_pshortcut, SIGNAL(activated()), this, SLOT(shortcutExecuted()));
m_pshortcut->setEnabled(true);
return m_pshortcut->isEnabled();
#else
//TODO: global hotkeys are not yet implemented outside of Windows
qWarning() << "addGlobalHotkey is not supported on this platform yet:" << m_shortcut_string;
return false;
#endif
}
#ifdef Q_OS_WIN
QxtGlobalShortcut *JSRGlobalHotkey::shortcut() const
{
return m_pshortcut;
}
void JSRGlobalHotkey::setShortcut(QxtGlobalShortcut *shortcut)
{
m_pshortcut = shortcut;
}
#endif
QString JSRGlobalHotkey::shortcutString() const
{
return m_shortcut_string;
}
void JSRGlobalHotkey::setShortcutString(const QString &shortcut_string)
{
m_shortcut_string = shortcut_string;
}
void JSRGlobalHotkey::shortcutExecuted()
{
QJSValueList args;
//TODO: what data do we send back? the global shortcut was pressed
call(args);
//emit a signal that our callback was completed,
//in this case, we should not allow our shortcut to be deleted because it is global shortcut that can be pressed multiple times
emit callbackCompleted(this, m_callbackResult);
}