-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjsrglobalhotkey.cpp
57 lines (44 loc) · 1.36 KB
/
jsrglobalhotkey.cpp
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
#include "jsrglobalhotkey.h"
#include "jscallback.h"
JSRGlobalHotkey::JSRGlobalHotkey(QJSEngine* pengine, QJSValue callback, const QString& shortcut)
: JSCallback(pengine, callback), m_shortcut_string(shortcut), m_pshortcut(NULL)
{
//do nothing
}
JSRGlobalHotkey::~JSRGlobalHotkey()
{
delete m_pshortcut;
}
bool JSRGlobalHotkey::exec()
{
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();
}
QxtGlobalShortcut *JSRGlobalHotkey::shortcut() const
{
return m_pshortcut;
}
QString JSRGlobalHotkey::shortcutString() const
{
return m_shortcut_string;
}
void JSRGlobalHotkey::setShortcutString(const QString &shortcut_string)
{
m_shortcut_string = shortcut_string;
}
void JSRGlobalHotkey::setShortcut(QxtGlobalShortcut *shortcut)
{
m_pshortcut = shortcut;
}
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);
}