summaryrefslogtreecommitdiff
path: root/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp
Unidiff
Diffstat (limited to 'noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp
new file mode 100644
index 0000000..84a8a89
--- a/dev/null
+++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp
@@ -0,0 +1,140 @@
1#include "KeyRepeater.h"
2
3KeyRepeater::KeyRepeater()
4{
5 qDebug("KeyRepeater::KeyRepeater()");
6 m_pTimer = new QTimer(this);
7 connect(m_pTimer, SIGNAL(timeout()), this, SLOT(autoRepeat()));
8 init();
9}
10
11KeyRepeater::~KeyRepeater()
12{
13 qDebug("KeyRepeater::~KeyRepeater()");
14 delete m_pTimer;
15}
16
17void KeyRepeater::start(int unicode, int keycode, int modifiers)
18{
19 m_unicode = unicode;
20 m_keycode = keycode;
21 m_modifiers = modifiers;
22 if(m_mode == ENABLE){
23 m_pTimer->stop();
24 if(isRepeatable(keycode)){
25 /* repeater start */
26 m_pTimer->start(m_repeatdelay, TRUE);
27 }
28 }
29}
30
31void KeyRepeater::stop(int keycode)
32{
33 if(keycode == 0
34 || keycode == m_keycode
35 || isRepeatable(keycode) == false){
36 m_pTimer->stop();
37 }
38}
39
40void KeyRepeater::init()
41{
42 m_mode = ENABLE;
43 m_repeatdelay = 400;
44 m_repeatperiod = 60;
45 m_disablekeys.append(0);
46 m_disablekeys.append(Qt::Key_Escape);
47 m_disablekeys.append(Qt::Key_Shift);
48 m_disablekeys.append(Qt::Key_Control);
49 m_disablekeys.append(Qt::Key_Alt);
50 m_disablekeys.append(Qt::Key_Meta);
51 for(int i=Qt::Key_F1; i<=Qt::Key_F35; i++){
52 m_disablekeys.append(i);
53 }
54}
55
56void KeyRepeater::clear()
57{
58 m_disablekeys.clear();
59}
60
61void KeyRepeater::reset()
62{
63 clear();
64 init();
65}
66
67void KeyRepeater::setRepeatable(int keycode, bool enable)
68{
69 if(enable){
70 QValueList<int>::Iterator it = m_disablekeys.find(keycode);
71 if(it != m_disablekeys.end()){
72 m_disablekeys.remove(it);
73 }
74 } else {
75 if(m_disablekeys.contains(keycode) == false){
76 m_disablekeys.append(keycode);
77 }
78 }
79}
80
81bool KeyRepeater::isRepeatable(int keycode)
82{
83 if(m_disablekeys.contains(keycode)){
84 return(false);
85 } else {
86 return(true);
87 }
88}
89
90void KeyRepeater::autoRepeat()
91{
92 /* key release event */
93#if 0
94 sendKeyEvent(
95 m_unicode,
96 m_keycode,
97 m_modifiers,
98 FALSE,
99 TRUE);
100 /* key press event */
101 sendKeyEvent(
102 m_unicode,
103 m_keycode,
104 m_modifiers,
105 TRUE,
106 TRUE);
107#else
108 emit keyEvent(
109 m_unicode,
110 m_keycode,
111 m_modifiers,
112 FALSE,
113 TRUE);
114 /* key press event */
115 emit keyEvent(
116 m_unicode,
117 m_keycode,
118 m_modifiers,
119 TRUE,
120 TRUE);
121#endif
122 /* start auto repeat */
123 m_pTimer->start(m_repeatperiod);
124#if 0
125 qDebug("autoRepeat[%x][%x][%x]",
126 m_unicode,
127 m_keycode,
128 m_modifiers);
129#endif
130}
131
132void KeyRepeater::statistics()
133{
134 qWarning("KeyRepeater::statistics()");
135 qWarning(" delay[%d] period[%d]", m_repeatdelay, m_repeatperiod);
136 for(QValueList<int>::Iterator it=m_disablekeys.begin();
137 it!=m_disablekeys.end(); ++it){
138 qDebug(" disable[%x]", *it);
139 }
140}