author | zecke <zecke> | 2004-04-01 19:59:29 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-01 19:59:29 (UTC) |
commit | 7804289bee604cd1e299f4911fa18dcfda37352f (patch) (unidiff) | |
tree | b36f3c14e11b7d89d9093999ad7503cc26d4aba8 /libopie2 | |
parent | 79e746cae433ca33bbe138ff4ad2704d13215e88 (diff) | |
download | opie-7804289bee604cd1e299f4911fa18dcfda37352f.zip opie-7804289bee604cd1e299f4911fa18dcfda37352f.tar.gz opie-7804289bee604cd1e299f4911fa18dcfda37352f.tar.bz2 |
Finally only two checks left and it is done
Capture keys
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 242 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 11 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget_p.h | 33 |
3 files changed, 216 insertions, 70 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp index 41be1be..3e08416 100644 --- a/libopie2/opieui/okeyconfigwidget.cpp +++ b/libopie2/opieui/okeyconfigwidget.cpp | |||
@@ -1,1109 +1,1211 @@ | |||
1 | #include "okeyconfigwidget.h" | 1 | #include "okeyconfigwidget.h" |
2 | #include "okeyconfigwidget_p.h" | ||
2 | 3 | ||
3 | #include <opie2/olistview.h> | ||
4 | 4 | ||
5 | #include <qgroupbox.h> | 5 | #include <qgroupbox.h> |
6 | #include <qradiobutton.h> | 6 | #include <qradiobutton.h> |
7 | #include <qpushbutton.h> | 7 | #include <qpushbutton.h> |
8 | #include <qbuttongroup.h> | 8 | #include <qbuttongroup.h> |
9 | 9 | ||
10 | #include <qaccel.h> | 10 | #include <qaccel.h> |
11 | #include <qlayout.h> | 11 | #include <qlayout.h> |
12 | #include <qlabel.h> | 12 | #include <qlabel.h> |
13 | #include <qtimer.h> | ||
13 | 14 | ||
14 | 15 | ||
15 | using namespace Opie::Ui; | 16 | using namespace Opie::Ui; |
16 | 17 | ||
17 | 18 | ||
19 | |||
18 | /** | 20 | /** |
19 | * The default Constructor of a OKeyPair. | 21 | * The default Constructor of a OKeyPair. |
20 | * A Key and a Modifier ( Alt/Shift/Ctrl ) | 22 | * A Key and a Modifier ( Alt/Shift/Ctrl ) |
21 | * needs to be supplied. | 23 | * needs to be supplied. |
22 | * Use Qt::Key for the information. | 24 | * Use Qt::Key for the information. |
23 | * The default arguments create an Empty OKeyPair. If you | 25 | * The default arguments create an Empty OKeyPair. If you |
24 | * want to get an empty OKeyPair use the static method for getting | 26 | * want to get an empty OKeyPair use the static method for getting |
25 | * the emptyKey() | 27 | * the emptyKey() |
26 | * | 28 | * |
27 | * @see OKeyPair OKeyPair::emptyKey() | 29 | * @see OKeyPair OKeyPair::emptyKey() |
28 | */ | 30 | */ |
29 | OKeyPair::OKeyPair( int key, int mod ) | 31 | OKeyPair::OKeyPair( int key, int mod ) |
30 | : m_key( key ), m_mod( mod ) | 32 | : m_key( key ), m_mod( mod ) |
31 | {} | 33 | {} |
32 | 34 | ||
33 | /** | 35 | /** |
34 | * The destructor | 36 | * The destructor |
35 | */ | 37 | */ |
36 | OKeyPair::~OKeyPair() {} | 38 | OKeyPair::~OKeyPair() {} |
37 | 39 | ||
38 | 40 | ||
39 | /** | 41 | /** |
40 | * Is this OKeyPair empty/valid? | 42 | * Is this OKeyPair empty/valid? |
41 | */ | 43 | */ |
42 | bool OKeyPair::isEmpty()const { | 44 | bool OKeyPair::isEmpty()const { |
43 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); | 45 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); |
44 | } | 46 | } |
45 | 47 | ||
46 | /** | 48 | /** |
47 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. | 49 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. |
48 | * | 50 | * |
49 | * @see Qt::Key | 51 | * @see Qt::Key |
50 | * @see setKey | 52 | * @see setKey |
51 | */ | 53 | */ |
52 | int OKeyPair::keycode()const { | 54 | int OKeyPair::keycode()const { |
53 | return m_key; | 55 | return m_key; |
54 | } | 56 | } |
55 | 57 | ||
56 | /** | 58 | /** |
57 | * get the modifier key for this OKeyPair. The Modifier State relates | 59 | * get the modifier key for this OKeyPair. The Modifier State relates |
58 | * to the Qt::ButtonState | 60 | * to the Qt::ButtonState |
59 | * | 61 | * |
60 | * @see Qt::ButtonState | 62 | * @see Qt::ButtonState |
61 | * @see setModifier | 63 | * @see setModifier |
62 | */ | 64 | */ |
63 | int OKeyPair::modifier()const { | 65 | int OKeyPair::modifier()const { |
64 | return m_mod; | 66 | return m_mod; |
65 | } | 67 | } |
66 | 68 | ||
67 | 69 | ||
68 | /** | 70 | /** |
69 | * Set the keycode | 71 | * Set the keycode |
70 | * @param key The Keycode to set | 72 | * @param key The Keycode to set |
71 | * | 73 | * |
72 | * @see keycode() | 74 | * @see keycode() |
73 | * @see Qt::Key | 75 | * @see Qt::Key |
74 | */ | 76 | */ |
75 | void OKeyPair::setKeycode( int key ) { | 77 | void OKeyPair::setKeycode( int key ) { |
76 | m_key = key; | 78 | m_key = key; |
77 | } | 79 | } |
78 | 80 | ||
79 | /** | 81 | /** |
80 | * Set the modifier key | 82 | * Set the modifier key |
81 | * | 83 | * |
82 | * @param the Modifier key | 84 | * @param the Modifier key |
83 | * @see Qt::ButtonState | 85 | * @see Qt::ButtonState |
84 | * @see modifier() | 86 | * @see modifier() |
85 | */ | 87 | */ |
86 | void OKeyPair::setModifier( int mod ) { | 88 | void OKeyPair::setModifier( int mod ) { |
87 | m_mod = mod; | 89 | m_mod = mod; |
88 | } | 90 | } |
89 | 91 | ||
90 | /** | 92 | /** |
91 | * Return an OKeyPair for the Return Key without any modifier. | 93 | * Return an OKeyPair for the Return Key without any modifier. |
92 | */ | 94 | */ |
93 | OKeyPair OKeyPair::returnKey() { | 95 | OKeyPair OKeyPair::returnKey() { |
94 | return OKeyPair( Qt::Key_Return, 0 ); | 96 | return OKeyPair( Qt::Key_Return, 0 ); |
95 | } | 97 | } |
96 | 98 | ||
97 | /** | 99 | /** |
98 | * Return an OKeyPair for the Left Arrow Key | 100 | * Return an OKeyPair for the Left Arrow Key |
99 | * without any modifier Key | 101 | * without any modifier Key |
100 | */ | 102 | */ |
101 | OKeyPair OKeyPair::leftArrowKey() { | 103 | OKeyPair OKeyPair::leftArrowKey() { |
102 | return OKeyPair( Qt::Key_Left, 0 ); | 104 | return OKeyPair( Qt::Key_Left, 0 ); |
103 | } | 105 | } |
104 | 106 | ||
105 | /** | 107 | /** |
106 | * Return an OKeyPair for the Right Arrow Key | 108 | * Return an OKeyPair for the Right Arrow Key |
107 | * without any modifier Key | 109 | * without any modifier Key |
108 | */ | 110 | */ |
109 | OKeyPair OKeyPair::rightArrowKey() { | 111 | OKeyPair OKeyPair::rightArrowKey() { |
110 | return OKeyPair( Qt::Key_Right, 0 ); | 112 | return OKeyPair( Qt::Key_Right, 0 ); |
111 | } | 113 | } |
112 | 114 | ||
113 | /** | 115 | /** |
114 | * Return an OKeyPair for the Up Arrow Key | 116 | * Return an OKeyPair for the Up Arrow Key |
115 | * without any modifier Key | 117 | * without any modifier Key |
116 | */ | 118 | */ |
117 | OKeyPair OKeyPair::upArrowKey() { | 119 | OKeyPair OKeyPair::upArrowKey() { |
118 | return OKeyPair( Qt::Key_Up, 0 ); | 120 | return OKeyPair( Qt::Key_Up, 0 ); |
119 | } | 121 | } |
120 | 122 | ||
121 | /** | 123 | /** |
122 | * Return an OKeyPair for the Down Arrow Key | 124 | * Return an OKeyPair for the Down Arrow Key |
123 | * without any modifier Key | 125 | * without any modifier Key |
124 | */ | 126 | */ |
125 | OKeyPair OKeyPair::downArrowKey() { | 127 | OKeyPair OKeyPair::downArrowKey() { |
126 | return OKeyPair( Qt::Key_Down, 0 ); | 128 | return OKeyPair( Qt::Key_Down, 0 ); |
127 | } | 129 | } |
128 | 130 | ||
129 | /** | 131 | /** |
130 | * Return an Empty OKeyPair | 132 | * Return an Empty OKeyPair |
131 | */ | 133 | */ |
132 | OKeyPair OKeyPair::emptyKey() { | 134 | OKeyPair OKeyPair::emptyKey() { |
133 | return OKeyPair(); | 135 | return OKeyPair(); |
134 | } | 136 | } |
135 | 137 | ||
136 | /** | 138 | /** |
137 | * This functions uses the Opie::Core::ODevice::buttons | 139 | * This functions uses the Opie::Core::ODevice::buttons |
138 | * for OKeyPairList | 140 | * for OKeyPairList |
139 | * | 141 | * |
140 | * @see Opie::Core::ODevice | 142 | * @see Opie::Core::ODevice |
141 | * @see Opie::Core::ODeviceButton | 143 | * @see Opie::Core::ODeviceButton |
142 | * @see Opie::Core::ODevice::button | 144 | * @see Opie::Core::ODevice::button |
143 | */ | 145 | */ |
144 | OKeyPair::List OKeyPair::hardwareKeys() { | 146 | OKeyPair::List OKeyPair::hardwareKeys() { |
145 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); | 147 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); |
146 | OKeyPair::List lst; | 148 | OKeyPair::List lst; |
147 | 149 | ||
148 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); | 150 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); |
149 | it != but.end(); ++it ) | 151 | it != but.end(); ++it ) |
150 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); | 152 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); |
151 | 153 | ||
152 | 154 | ||
153 | return lst; | 155 | return lst; |
154 | } | 156 | } |
155 | 157 | ||
156 | /** | 158 | /** |
157 | * Equals operator. Check if two OKeyPairs have the same key and modifier | 159 | * Equals operator. Check if two OKeyPairs have the same key and modifier |
158 | * @see operator!= | 160 | * @see operator!= |
159 | */ | 161 | */ |
160 | bool OKeyPair::operator==( const OKeyPair& pair) { | 162 | bool OKeyPair::operator==( const OKeyPair& pair) { |
161 | if ( m_key != pair.m_key ) return false; | 163 | if ( m_key != pair.m_key ) return false; |
162 | if ( m_mod != pair.m_mod ) return false; | 164 | if ( m_mod != pair.m_mod ) return false; |
163 | 165 | ||
164 | return true; | 166 | return true; |
165 | } | 167 | } |
166 | 168 | ||
167 | /** | 169 | /** |
168 | * Not equal operator. calls the equal operator internally | 170 | * Not equal operator. calls the equal operator internally |
169 | */ | 171 | */ |
170 | bool OKeyPair::operator!=( const OKeyPair& pair) { | 172 | bool OKeyPair::operator!=( const OKeyPair& pair) { |
171 | return !(*this == pair); | 173 | return !(*this == pair); |
172 | } | 174 | } |
173 | 175 | ||
174 | 176 | ||
175 | /** | 177 | /** |
176 | * The normal Constructor to create a OKeyConfigItem | 178 | * The normal Constructor to create a OKeyConfigItem |
177 | * | 179 | * |
178 | * You can set the the key paramater of this item but if | 180 | * You can set the the key paramater of this item but if |
179 | * you use this item with the OKeyConfigManager your setting | 181 | * you use this item with the OKeyConfigManager your setting |
180 | * will be overwritten. | 182 | * will be overwritten. |
181 | * You can also specify a QObject and slot which sould get called | 183 | * You can also specify a QObject and slot which sould get called |
182 | * once this item is activated. This slot only works if you | 184 | * once this item is activated. This slot only works if you |
183 | * use the OKeyConfigManager. | 185 | * use the OKeyConfigManager. |
184 | * The actual Key is read by load() | 186 | * The actual Key is read by load() |
185 | * | 187 | * |
186 | * \code | 188 | * \code |
187 | * void MySlot::create(){ | 189 | * void MySlot::create(){ |
188 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), | 190 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), |
189 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), | 191 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), |
190 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); | 192 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); |
191 | * } | 193 | * } |
192 | * \endcode | 194 | * \endcode |
193 | * | 195 | * |
194 | * @param text The text exposed to the user | 196 | * @param text The text exposed to the user |
195 | * @param config_key The key used in the config | 197 | * @param config_key The key used in the config |
196 | * @param pix A Pixmap associated with this Item | 198 | * @param pix A Pixmap associated with this Item |
197 | * @param def The OKeyPair used as default | 199 | * @param def The OKeyPair used as default |
198 | * @param caller The object where the slot exists | 200 | * @param caller The object where the slot exists |
199 | * @param slot The slot which should get called | 201 | * @param slot The slot which should get called |
200 | * | 202 | * |
201 | */ | 203 | */ |
202 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | 204 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, |
203 | const QPixmap& pix, int id, const OKeyPair& def, | 205 | const QPixmap& pix, int id, const OKeyPair& def, |
204 | QObject *caller, | 206 | QObject *caller, |
205 | const char* slot ) | 207 | const char* slot ) |
206 | : m_text( text ), m_config( config_key ), m_pix( pix ), | 208 | : m_text( text ), m_config( config_key ), m_pix( pix ), |
207 | m_id( id ), m_def( def ), | 209 | m_id( id ), m_def( def ), |
208 | m_obj( caller ), m_str( slot ) {} | 210 | m_obj( caller ), m_str( slot ) {} |
209 | 211 | ||
210 | /** | 212 | /** |
211 | * A special Constructor for converting from an Opie::Core::ODeviceButton | 213 | * A special Constructor for converting from an Opie::Core::ODeviceButton |
212 | * delivered by Opie::Core::ODevice::buttons() | 214 | * delivered by Opie::Core::ODevice::buttons() |
213 | * There is no Config Key set and both default key and key are set | 215 | * There is no Config Key set and both default key and key are set |
214 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier | 216 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier |
215 | * | 217 | * |
216 | * @see Opie::Core::ODevice | 218 | * @see Opie::Core::ODevice |
217 | * @see Opie::Core::ODeviceButton | 219 | * @see Opie::Core::ODeviceButton |
218 | * @see Opie::Core::ODevice::buttons() | 220 | * @see Opie::Core::ODevice::buttons() |
219 | */ | 221 | */ |
220 | OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) | 222 | OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) |
221 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), | 223 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), |
222 | m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) | 224 | m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) |
223 | {} | 225 | {} |
224 | 226 | ||
225 | 227 | ||
226 | /** | 228 | /** |
227 | * Destructor | 229 | * Destructor |
228 | */ | 230 | */ |
229 | OKeyConfigItem::~OKeyConfigItem() {} | 231 | OKeyConfigItem::~OKeyConfigItem() {} |
230 | 232 | ||
231 | 233 | ||
232 | /** | 234 | /** |
233 | * The text exposed to the user | 235 | * The text exposed to the user |
234 | * | 236 | * |
235 | * @see setText | 237 | * @see setText |
236 | */ | 238 | */ |
237 | QString OKeyConfigItem::text()const { | 239 | QString OKeyConfigItem::text()const { |
238 | return m_text; | 240 | return m_text; |
239 | } | 241 | } |
240 | 242 | ||
241 | /** | 243 | /** |
242 | * The pixmap shown to the user for your action/key | 244 | * The pixmap shown to the user for your action/key |
243 | * | 245 | * |
244 | * @see setPixmap | 246 | * @see setPixmap |
245 | */ | 247 | */ |
246 | QPixmap OKeyConfigItem::pixmap()const { | 248 | QPixmap OKeyConfigItem::pixmap()const { |
247 | return m_pix; | 249 | return m_pix; |
248 | } | 250 | } |
249 | 251 | ||
250 | /** | 252 | /** |
251 | * Return the OKeyPair this OKeyConfigItem is configured for. | 253 | * Return the OKeyPair this OKeyConfigItem is configured for. |
252 | * | 254 | * |
253 | * @see setKeyPair | 255 | * @see setKeyPair |
254 | */ | 256 | */ |
255 | OKeyPair OKeyConfigItem::keyPair()const { | 257 | OKeyPair OKeyConfigItem::keyPair()const { |
256 | return m_key; | 258 | return m_key; |
257 | } | 259 | } |
258 | 260 | ||
259 | /** | 261 | /** |
260 | * Return the default OKeyPair | 262 | * Return the default OKeyPair |
261 | * @see setDefaultKeyPair | 263 | * @see setDefaultKeyPair |
262 | */ | 264 | */ |
263 | OKeyPair OKeyConfigItem::defaultKeyPair()const { | 265 | OKeyPair OKeyConfigItem::defaultKeyPair()const { |
264 | return m_def; | 266 | return m_def; |
265 | } | 267 | } |
266 | 268 | ||
267 | 269 | ||
268 | /** | 270 | /** |
269 | * Return the Id you assigned to this item. | 271 | * Return the Id you assigned to this item. |
270 | * setting is only possible by the constructor | 272 | * setting is only possible by the constructor |
271 | */ | 273 | */ |
272 | int OKeyConfigItem::id()const{ | 274 | int OKeyConfigItem::id()const{ |
273 | return m_id; | 275 | return m_id; |
274 | } | 276 | } |
275 | 277 | ||
276 | /** | 278 | /** |
277 | * reutrn the Config Key. Setting it is only possible | 279 | * reutrn the Config Key. Setting it is only possible |
278 | * by the constructor | 280 | * by the constructor |
279 | */ | 281 | */ |
280 | QCString OKeyConfigItem::configKey()const { | 282 | QCString OKeyConfigItem::configKey()const { |
281 | return m_config; | 283 | return m_config; |
282 | } | 284 | } |
283 | 285 | ||
284 | /** | 286 | /** |
285 | * @internal | 287 | * @internal |
286 | */ | 288 | */ |
287 | QObject* OKeyConfigItem::object()const{ | 289 | QObject* OKeyConfigItem::object()const{ |
288 | return m_obj; | 290 | return m_obj; |
289 | } | 291 | } |
290 | 292 | ||
291 | /** | 293 | /** |
292 | * @internal | 294 | * @internal |
293 | */ | 295 | */ |
294 | QCString OKeyConfigItem::slot()const { | 296 | QCString OKeyConfigItem::slot()const { |
295 | return m_str; | 297 | return m_str; |
296 | } | 298 | } |
297 | 299 | ||
298 | /** | 300 | /** |
299 | * Set the text | 301 | * Set the text |
300 | * | 302 | * |
301 | * @param text Set the Text of this Action to text | 303 | * @param text Set the Text of this Action to text |
302 | * @see text() | 304 | * @see text() |
303 | */ | 305 | */ |
304 | void OKeyConfigItem::setText( const QString& text ) { | 306 | void OKeyConfigItem::setText( const QString& text ) { |
305 | m_text = text; | 307 | m_text = text; |
306 | } | 308 | } |
307 | 309 | ||
308 | /** | 310 | /** |
309 | * Set the pixmap of this action | 311 | * Set the pixmap of this action |
310 | * | 312 | * |
311 | * @param pix The Pixmap to set | 313 | * @param pix The Pixmap to set |
312 | * @see pixmap() | 314 | * @see pixmap() |
313 | */ | 315 | */ |
314 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { | 316 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { |
315 | m_pix = pix; | 317 | m_pix = pix; |
316 | } | 318 | } |
317 | 319 | ||
318 | /** | 320 | /** |
319 | * Set the KeyPair the OKeyConfigItem uses. | 321 | * Set the KeyPair the OKeyConfigItem uses. |
320 | * Your set Key could get overwritten if you use | 322 | * Your set Key could get overwritten if you use |
321 | * the manager or GUI to configure the key | 323 | * the manager or GUI to configure the key |
322 | * | 324 | * |
323 | * @param key Set the OKeyPair used | 325 | * @param key Set the OKeyPair used |
324 | * @see keyPair() | 326 | * @see keyPair() |
325 | */ | 327 | */ |
326 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { | 328 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { |
327 | m_key = key; | 329 | m_key = key; |
328 | } | 330 | } |
329 | 331 | ||
330 | /** | 332 | /** |
331 | * Set the default KeyPair. | 333 | * Set the default KeyPair. |
332 | * | 334 | * |
333 | * @param key The default keypair | 335 | * @param key The default keypair |
334 | * @see defaultKeyPair() | 336 | * @see defaultKeyPair() |
335 | */ | 337 | */ |
336 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { | 338 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { |
337 | m_def = key; | 339 | m_def = key; |
338 | } | 340 | } |
339 | 341 | ||
340 | /** | 342 | /** |
341 | * @internal | 343 | * @internal |
342 | */ | 344 | */ |
343 | void OKeyConfigItem::setConfigKey( const QCString& str) { | 345 | void OKeyConfigItem::setConfigKey( const QCString& str) { |
344 | m_config = str; | 346 | m_config = str; |
345 | m_config.detach(); | 347 | m_config.detach(); |
346 | } | 348 | } |
347 | 349 | ||
348 | /** | 350 | /** |
349 | * @internal | 351 | * @internal |
350 | */ | 352 | */ |
351 | void OKeyConfigItem::setId( int id ) { | 353 | void OKeyConfigItem::setId( int id ) { |
352 | m_id = id; | 354 | m_id = id; |
353 | } | 355 | } |
354 | 356 | ||
355 | /** | 357 | /** |
356 | * If the item is not configured isEmpty() will return true | 358 | * If the item is not configured isEmpty() will return true |
357 | * It is empty if no text is present and no default | 359 | * It is empty if no text is present and no default |
358 | * and no configured key | 360 | * and no configured key |
359 | */ | 361 | */ |
360 | bool OKeyConfigItem::isEmpty()const { | 362 | bool OKeyConfigItem::isEmpty()const { |
361 | if ( !m_def.isEmpty() ) return false; | 363 | if ( !m_def.isEmpty() ) return false; |
362 | if ( !m_key.isEmpty() ) return false; | 364 | if ( !m_key.isEmpty() ) return false; |
363 | if ( !m_text.isEmpty() ) return false; | 365 | if ( !m_text.isEmpty() ) return false; |
364 | if ( m_id != -1 ) return false; | 366 | if ( m_id != -1 ) return false; |
365 | 367 | ||
366 | return true; | 368 | return true; |
367 | } | 369 | } |
368 | 370 | ||
369 | /** | 371 | /** |
370 | * Check if the KeyPairs are the same | 372 | * Check if the KeyPairs are the same |
371 | */ | 373 | */ |
372 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { | 374 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { |
373 | /* if ( isEmpty() == conf.isEmpty() ) return true; | 375 | /* if ( isEmpty() == conf.isEmpty() ) return true; |
374 | else if ( isEmpty() != conf.isEmpty() ) return false; | 376 | else if ( isEmpty() != conf.isEmpty() ) return false; |
375 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | 377 | else if ( !isEmpty()!= conf.isEmpty() ) return false; |
376 | */ | 378 | */ |
377 | 379 | ||
378 | if ( m_id != conf.m_id ) return false; | 380 | if ( m_id != conf.m_id ) return false; |
379 | if ( m_obj != conf.m_obj ) return false; | 381 | if ( m_obj != conf.m_obj ) return false; |
380 | if ( m_text != conf.m_text ) return false; | 382 | if ( m_text != conf.m_text ) return false; |
381 | if ( m_key != conf.m_key ) return false; | 383 | if ( m_key != conf.m_key ) return false; |
382 | if ( m_def != conf.m_def ) return false; | 384 | if ( m_def != conf.m_def ) return false; |
383 | 385 | ||
384 | 386 | ||
385 | 387 | ||
386 | return true; | 388 | return true; |
387 | 389 | ||
388 | } | 390 | } |
389 | 391 | ||
390 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) { | 392 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) { |
391 | return !( *this == conf ); | 393 | return !( *this == conf ); |
392 | } | 394 | } |
393 | 395 | ||
394 | /** | 396 | /** |
395 | * \brief c'tor | 397 | * \brief c'tor |
396 | * The Constructor for a OKeyConfigManager | 398 | * The Constructor for a OKeyConfigManager |
397 | * | 399 | * |
398 | * You can use this manager in multiple ways. Either make it handle | 400 | * You can use this manager in multiple ways. Either make it handle |
399 | * QKeyEvents | 401 | * QKeyEvents |
400 | * | 402 | * |
401 | * \code | 403 | * \code |
402 | * Opie::Core::Config conf = oApp->config(); | 404 | * Opie::Core::Config conf = oApp->config(); |
403 | * Opie::Ui::OKeyPairList blackList; | 405 | * Opie::Ui::OKeyPairList blackList; |
404 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); | 406 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); |
405 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); | 407 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); |
406 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, | 408 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, |
407 | * false); | 409 | * false); |
408 | * QListView *view = new QListView(); | 410 | * QListView *view = new QListView(); |
409 | * manager->handleWidget(view); | 411 | * manager->handleWidget(view); |
410 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); | 412 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); |
411 | * manager->load(); | 413 | * manager->load(); |
412 | * | 414 | * |
413 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), | 415 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), |
414 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); | 416 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); |
415 | * | 417 | * |
416 | * .... | 418 | * .... |
417 | * | 419 | * |
418 | * void update(){ | 420 | * void update(){ |
419 | * QDialog diag(true); | 421 | * QDialog diag(true); |
420 | * QHBoxLayout *lay = new QHBoxLayout(&diag); | 422 | * QHBoxLayout *lay = new QHBoxLayout(&diag); |
421 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | 423 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); |
422 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | 424 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); |
423 | * lay->addWidget(wid); | 425 | * lay->addWidget(wid); |
424 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ | 426 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ |
425 | * wid->save(); | 427 | * wid->save(); |
426 | * } | 428 | * } |
427 | * } | 429 | * } |
428 | * | 430 | * |
429 | * .... | 431 | * .... |
430 | * MyListView::keyPressEvent( QKeyEvent* e ){ | 432 | * MyListView::keyPressEvent( QKeyEvent* e ){ |
431 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); | 433 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); |
432 | * if(!item.isEmpty() ){ | 434 | * if(!item.isEmpty() ){ |
433 | * switch(item.id()){ | 435 | * switch(item.id()){ |
434 | * case My_Delete_Key: | 436 | * case My_Delete_Key: |
435 | * break; | 437 | * break; |
436 | * } | 438 | * } |
437 | * } | 439 | * } |
438 | * } | 440 | * } |
439 | * | 441 | * |
440 | * \endcode | 442 | * \endcode |
441 | * | 443 | * |
442 | * @param conf The Config where the KeySetting should be stored | 444 | * @param conf The Config where the KeySetting should be stored |
443 | * @param group The group where the KeySetting will be stored | 445 | * @param group The group where the KeySetting will be stored |
444 | * @param black Which keys shouldn't be allowed to handle | 446 | * @param black Which keys shouldn't be allowed to handle |
445 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | 447 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons |
446 | * @param par The parent/owner of this manager | 448 | * @param par The parent/owner of this manager |
447 | * @param name The name of this object | 449 | * @param name The name of this object |
448 | */ | 450 | */ |
449 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | 451 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, |
450 | const QString& group, | 452 | const QString& group, |
451 | const OKeyPair::List& black, | 453 | const OKeyPair::List& black, |
452 | bool grabkeyboard, QObject* par, | 454 | bool grabkeyboard, QObject* par, |
453 | const char* name) | 455 | const char* name) |
454 | : QObject( par, name ), m_conf( conf ), m_group( group ), | 456 | : QObject( par, name ), m_conf( conf ), m_group( group ), |
455 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ | 457 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ |
456 | if ( m_grab ) | 458 | if ( m_grab ) |
457 | QPEApplication::grabKeyboard(); | 459 | QPEApplication::grabKeyboard(); |
458 | } | 460 | } |
459 | 461 | ||
460 | 462 | ||
461 | /** | 463 | /** |
462 | * Destructor | 464 | * Destructor |
463 | */ | 465 | */ |
464 | OKeyConfigManager::~OKeyConfigManager() { | 466 | OKeyConfigManager::~OKeyConfigManager() { |
465 | if ( m_grab ) | 467 | if ( m_grab ) |
466 | QPEApplication::ungrabKeyboard(); | 468 | QPEApplication::ungrabKeyboard(); |
467 | } | 469 | } |
468 | 470 | ||
469 | /** | 471 | /** |
470 | * Load the Configuration from the OConfig | 472 | * Load the Configuration from the OConfig |
471 | * If a Key is restricted but was in the config we will | 473 | * If a Key is restricted but was in the config we will |
472 | * make it be the empty key paur | 474 | * make it be the empty key paur |
473 | * We will change the group of the OConfig Item! | 475 | * We will change the group of the OConfig Item! |
474 | * | 476 | * |
475 | * @see OKeyPair::emptyKey | 477 | * @see OKeyPair::emptyKey |
476 | */ | 478 | */ |
477 | void OKeyConfigManager::load() { | 479 | void OKeyConfigManager::load() { |
478 | m_conf->setGroup( m_group ); | 480 | m_conf->setGroup( m_group ); |
479 | 481 | ||
480 | /* | 482 | /* |
481 | * Read each item | 483 | * Read each item |
482 | */ | 484 | */ |
483 | int key, mod; | 485 | int key, mod; |
484 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); | 486 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); |
485 | it != m_keys.end(); ++it ) { | 487 | it != m_keys.end(); ++it ) { |
486 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | 488 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); |
487 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | 489 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); |
488 | OKeyPair okey( key, mod ); | 490 | OKeyPair okey( key, mod ); |
489 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | 491 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) |
490 | (*it).setKeyPair( OKeyPair(key, mod) ); | 492 | (*it).setKeyPair( OKeyPair(key, mod) ); |
491 | else | 493 | else |
492 | (*it).setKeyPair( OKeyPair::emptyKey() ); | 494 | (*it).setKeyPair( OKeyPair::emptyKey() ); |
493 | } | 495 | } |
494 | delete m_map; m_map = 0; | 496 | delete m_map; m_map = 0; |
495 | } | 497 | } |
496 | 498 | ||
497 | /** | 499 | /** |
498 | * We will save the current configuration | 500 | * We will save the current configuration |
499 | * to the OConfig. We will change the group. | 501 | * to the OConfig. We will change the group. |
500 | */ | 502 | */ |
501 | void OKeyConfigManager::save() { | 503 | void OKeyConfigManager::save() { |
502 | m_conf->setGroup( m_group ); | 504 | m_conf->setGroup( m_group ); |
503 | 505 | ||
504 | /* | 506 | /* |
505 | * Write each item | 507 | * Write each item |
506 | */ | 508 | */ |
507 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); | 509 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); |
508 | it != m_keys.end(); ++it ) { | 510 | it != m_keys.end(); ++it ) { |
509 | if ( (*it).isEmpty() ) | 511 | if ( (*it).isEmpty() ) |
510 | continue; | 512 | continue; |
511 | OKeyPair pair = (*it).keyPair(); | 513 | OKeyPair pair = (*it).keyPair(); |
512 | OKeyPair deft = (*it).defaultKeyPair(); | 514 | OKeyPair deft = (*it).defaultKeyPair(); |
513 | /* | 515 | /* |
514 | * don't write if it is the default setting | 516 | * don't write if it is the default setting |
515 | * FIXME allow to remove Keys | 517 | * FIXME allow to remove Keys |
516 | if ( (pair.keycode() == deft.keycode()) && | 518 | if ( (pair.keycode() == deft.keycode()) && |
517 | (pair.modifier()== deft.modifier() ) ) | 519 | (pair.modifier()== deft.modifier() ) ) |
518 | return; | 520 | return; |
519 | */ | 521 | */ |
520 | 522 | ||
521 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | 523 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); |
522 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); | 524 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); |
523 | } | 525 | } |
524 | } | 526 | } |
525 | 527 | ||
526 | /** | 528 | /** |
527 | * This is function uses a QMap internally but you can have the same keycode | 529 | * This is function uses a QMap internally but you can have the same keycode |
528 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | 530 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem |
529 | * with same keycode and modifier key. The GUI takes care that a user can't | 531 | * with same keycode and modifier key. The GUI takes care that a user can't |
530 | * cofigure two keys. | 532 | * cofigure two keys. |
531 | * | 533 | * |
532 | * Make sure you call e->ignore if you don't want to handle this event | 534 | * Make sure you call e->ignore if you don't want to handle this event |
533 | */ | 535 | */ |
534 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | 536 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { |
535 | /* | 537 | /* |
536 | * Fix Up issues with Qt/E, my keybard, and virtual input | 538 | * Fix Up issues with Qt/E, my keybard, and virtual input |
537 | * methods | 539 | * methods |
538 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state | 540 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state |
539 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower | 541 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower |
540 | * case ascii | 542 | * case ascii |
541 | */ | 543 | */ |
542 | int key = e->key(); | 544 | int key, mod; |
543 | int mod = e->state(); | 545 | Opie::Ui::Private::fixupKeys( key, mod, e ); |
544 | |||
545 | /* | ||
546 | * virtual keyboard | ||
547 | * else change the button mod only | ||
548 | */ | ||
549 | if ( key == 0 ) { | ||
550 | key = e->ascii(); | ||
551 | if ( key > 96 && key < 123) | ||
552 | key -= 32; | ||
553 | }else{ | ||
554 | int new_mod = 0; | ||
555 | if ( mod & 256 ) | ||
556 | new_mod |= Qt::ShiftButton; | ||
557 | else if ( mod & 512 ) | ||
558 | new_mod |= Qt::ControlButton; | ||
559 | else if ( mod & 1024 ) | ||
560 | new_mod |= Qt::AltButton; | ||
561 | |||
562 | mod = new_mod == 0? mod : new_mod; | ||
563 | } | ||
564 | 546 | ||
565 | OKeyConfigItem::List _keyList = keyList( key ); | 547 | OKeyConfigItem::List _keyList = keyList( key ); |
566 | if ( _keyList.isEmpty() ) | 548 | if ( _keyList.isEmpty() ) |
567 | return OKeyConfigItem(); | 549 | return OKeyConfigItem(); |
568 | 550 | ||
569 | OKeyConfigItem item; | 551 | OKeyConfigItem item; |
570 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); | 552 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); |
571 | ++it ) { | 553 | ++it ) { |
572 | if ( (*it).keyPair().modifier() == mod ) { | 554 | if ( (*it).keyPair().modifier() == mod ) { |
573 | item = *it; | 555 | item = *it; |
574 | break; | 556 | break; |
575 | } | 557 | } |
576 | 558 | ||
577 | } | 559 | } |
578 | 560 | ||
579 | return item; | 561 | return item; |
580 | } | 562 | } |
581 | 563 | ||
582 | /** | 564 | /** |
583 | * Return the associated id of the item or -1 if no item | 565 | * Return the associated id of the item or -1 if no item |
584 | * matched the key | 566 | * matched the key |
585 | * | 567 | * |
586 | * @see handleKeyEvent | 568 | * @see handleKeyEvent |
587 | */ | 569 | */ |
588 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | 570 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { |
589 | return handleKeyEvent( ev ).id(); | 571 | return handleKeyEvent( ev ).id(); |
590 | } | 572 | } |
591 | 573 | ||
592 | /** | 574 | /** |
593 | * Add Key Config to the List of items | 575 | * Add Key Config to the List of items |
594 | */ | 576 | */ |
595 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | 577 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { |
596 | m_keys.append( item ); | 578 | m_keys.append( item ); |
597 | qWarning( "m_keys count is now %d", m_keys.count() ); | 579 | qWarning( "m_keys count is now %d", m_keys.count() ); |
598 | delete m_map; m_map = 0; | 580 | delete m_map; m_map = 0; |
599 | } | 581 | } |
600 | 582 | ||
601 | /** | 583 | /** |
602 | * Remove the Key from the Config. Internal lists will be destroyed | 584 | * Remove the Key from the Config. Internal lists will be destroyed |
603 | * and rebuild on demand later | 585 | * and rebuild on demand later |
604 | */ | 586 | */ |
605 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | 587 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { |
606 | m_keys.remove( item ); | 588 | m_keys.remove( item ); |
607 | qWarning( "m_keys count is now %d", m_keys.count() ); | 589 | qWarning( "m_keys count is now %d", m_keys.count() ); |
608 | delete m_map; m_map = 0; | 590 | delete m_map; m_map = 0; |
609 | } | 591 | } |
610 | 592 | ||
611 | /** | 593 | /** |
612 | * Clears the complete list | 594 | * Clears the complete list |
613 | */ | 595 | */ |
614 | void OKeyConfigManager::clearKeyConfig() { | 596 | void OKeyConfigManager::clearKeyConfig() { |
615 | m_keys.clear(); | 597 | m_keys.clear(); |
616 | delete m_map; m_map = 0; | 598 | delete m_map; m_map = 0; |
617 | } | 599 | } |
618 | 600 | ||
619 | /** | 601 | /** |
620 | * | 602 | * |
621 | */ | 603 | */ |
622 | Opie::Ui::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ | 604 | Opie::Ui::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ |
623 | return m_keys; | 605 | return m_keys; |
624 | } | 606 | } |
625 | 607 | ||
626 | /** | 608 | /** |
627 | * Add this OKeyPair to the blackList. | 609 | * Add this OKeyPair to the blackList. |
628 | * Internal lists will be destroyed | 610 | * Internal lists will be destroyed |
629 | */ | 611 | */ |
630 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | 612 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { |
631 | m_blackKeys.append( key ); | 613 | m_blackKeys.append( key ); |
632 | delete m_map; m_map = 0; | 614 | delete m_map; m_map = 0; |
633 | } | 615 | } |
634 | 616 | ||
635 | 617 | ||
636 | /** | 618 | /** |
637 | * Remove this OKeyPair from the black List | 619 | * Remove this OKeyPair from the black List |
638 | * Internal lists will be destroyed | 620 | * Internal lists will be destroyed |
639 | */ | 621 | */ |
640 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | 622 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { |
641 | m_blackKeys.remove( key ); | 623 | m_blackKeys.remove( key ); |
642 | delete m_map; m_map = 0; | 624 | delete m_map; m_map = 0; |
643 | } | 625 | } |
644 | 626 | ||
645 | 627 | ||
646 | /** | 628 | /** |
647 | * Clear the blackList | 629 | * Clear the blackList |
648 | */ | 630 | */ |
649 | void OKeyConfigManager::clearBlackList() { | 631 | void OKeyConfigManager::clearBlackList() { |
650 | m_blackKeys.clear(); | 632 | m_blackKeys.clear(); |
651 | delete m_map; m_map = 0; | 633 | delete m_map; m_map = 0; |
652 | } | 634 | } |
653 | 635 | ||
654 | 636 | ||
655 | /** | 637 | /** |
656 | * Return a copy of the blackList | 638 | * Return a copy of the blackList |
657 | */ | 639 | */ |
658 | OKeyPair::List OKeyConfigManager::blackList()const { | 640 | OKeyPair::List OKeyConfigManager::blackList()const { |
659 | return m_blackKeys; | 641 | return m_blackKeys; |
660 | } | 642 | } |
661 | 643 | ||
662 | 644 | ||
663 | /** | 645 | /** |
664 | * Ask the Manager to handle KeyEvents for you. | 646 | * Ask the Manager to handle KeyEvents for you. |
665 | * All handled keys will emit a QSignal and return true | 647 | * All handled keys will emit a QSignal and return true |
666 | * that it handled the keyevent | 648 | * that it handled the keyevent |
667 | */ | 649 | */ |
668 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | 650 | void OKeyConfigManager::handleWidget( QWidget* wid ) { |
669 | wid->installEventFilter( this ); | 651 | wid->installEventFilter( this ); |
670 | } | 652 | } |
671 | 653 | ||
672 | /** | 654 | /** |
673 | * @internal | 655 | * @internal |
674 | */ | 656 | */ |
675 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | 657 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { |
676 | if ( !obj->isWidgetType() ) | 658 | if ( !obj->isWidgetType() ) |
677 | return false; | 659 | return false; |
678 | 660 | ||
679 | if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) | 661 | if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) |
680 | return false; | 662 | return false; |
681 | 663 | ||
682 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | 664 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); |
683 | OKeyConfigItem item = handleKeyEvent( key ); | 665 | OKeyConfigItem item = handleKeyEvent( key ); |
684 | 666 | ||
685 | if ( item.isEmpty() ) | 667 | if ( item.isEmpty() ) |
686 | return false; | 668 | return false; |
687 | 669 | ||
688 | QWidget *wid = static_cast<QWidget*>( obj ); | 670 | QWidget *wid = static_cast<QWidget*>( obj ); |
689 | 671 | ||
690 | if ( item.object() && !item.slot().isEmpty() ) { | 672 | if ( item.object() && !item.slot().isEmpty() ) { |
691 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | 673 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), |
692 | item.object(), item.slot().data() ); | 674 | item.object(), item.slot().data() ); |
693 | emit actionActivated(wid, key); | 675 | emit actionActivated(wid, key); |
694 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | 676 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), |
695 | item.object(), item.slot().data() ); | 677 | item.object(), item.slot().data() ); |
696 | } | 678 | } |
697 | emit actionActivated( wid, key, item ); | 679 | emit actionActivated( wid, key, item ); |
698 | 680 | ||
699 | return true; | 681 | return true; |
700 | } | 682 | } |
701 | 683 | ||
702 | /** | 684 | /** |
703 | * @internal | 685 | * @internal |
704 | */ | 686 | */ |
705 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { | 687 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { |
706 | /* | 688 | /* |
707 | * Create the map if not existing anymore | 689 | * Create the map if not existing anymore |
708 | */ | 690 | */ |
709 | if ( !m_map ) { | 691 | if ( !m_map ) { |
710 | m_map = new OKeyMapConfigPrivate; | 692 | m_map = new OKeyMapConfigPrivate; |
711 | /* for every key */ | 693 | /* for every key */ |
712 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); | 694 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); |
713 | it!= m_keys.end(); ++it ) { | 695 | it!= m_keys.end(); ++it ) { |
714 | 696 | ||
715 | bool add = true; | 697 | bool add = true; |
716 | /* see if this key is blocked */ | 698 | /* see if this key is blocked */ |
717 | OKeyPair pair = (*it).keyPair(); | 699 | OKeyPair pair = (*it).keyPair(); |
718 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); | 700 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); |
719 | pairIt != m_blackKeys.end(); ++pairIt ) { | 701 | pairIt != m_blackKeys.end(); ++pairIt ) { |
720 | if ( (*pairIt).keycode() == pair.keycode() && | 702 | if ( (*pairIt).keycode() == pair.keycode() && |
721 | (*pairIt).modifier() == pair.modifier() ) { | 703 | (*pairIt).modifier() == pair.modifier() ) { |
722 | add = false; | 704 | add = false; |
723 | break; | 705 | break; |
724 | } | 706 | } |
725 | } | 707 | } |
726 | /* check if we added it */ | 708 | /* check if we added it */ |
727 | if ( add ) | 709 | if ( add ) |
728 | (*m_map)[pair.keycode()].append( *it ); | 710 | (*m_map)[pair.keycode()].append( *it ); |
729 | } | 711 | } |
730 | } | 712 | } |
731 | return (*m_map)[keycode]; | 713 | return (*m_map)[keycode]; |
732 | } | 714 | } |
733 | 715 | ||
734 | 716 | ||
735 | |||
736 | ///////////////////////// | ||
737 | //////// Widget Starts Here | ||
738 | namespace Opie { | 717 | namespace Opie { |
739 | namespace Ui { | 718 | namespace Ui { |
740 | namespace Private { | 719 | namespace Private { |
741 | static QString keyToString( const OKeyPair& ); | ||
742 | class OKeyListViewItem : public Opie::Ui::OListViewItem { | ||
743 | public: | ||
744 | OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent); | ||
745 | ~OKeyListViewItem(); | ||
746 | |||
747 | void setDefault(); | ||
748 | |||
749 | OKeyConfigItem& item(); | ||
750 | OKeyConfigItem origItem()const; | ||
751 | void setItem( const OKeyConfigItem& item ); | ||
752 | void updateText(); | ||
753 | |||
754 | OKeyConfigManager *manager(); | ||
755 | private: | ||
756 | OKeyConfigItem m_item; | ||
757 | OKeyConfigItem m_origItem; | ||
758 | OKeyConfigManager* m_manager; | ||
759 | |||
760 | }; | ||
761 | 720 | ||
762 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) | 721 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) |
763 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { | 722 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { |
764 | m_origItem = item; | 723 | m_origItem = item; |
765 | setItem( item ); | 724 | setItem( item ); |
766 | } | 725 | } |
767 | OKeyListViewItem::~OKeyListViewItem() {} | 726 | OKeyListViewItem::~OKeyListViewItem() {} |
768 | OKeyConfigItem &OKeyListViewItem::item(){ | 727 | OKeyConfigItem &OKeyListViewItem::item(){ |
769 | return m_item; | 728 | return m_item; |
770 | } | 729 | } |
771 | OKeyConfigItem OKeyListViewItem::origItem() const{ | 730 | OKeyConfigItem OKeyListViewItem::origItem() const{ |
772 | return m_origItem; | 731 | return m_origItem; |
773 | } | 732 | } |
774 | OKeyConfigManager* OKeyListViewItem::manager() { | 733 | OKeyConfigManager* OKeyListViewItem::manager() { |
775 | return m_manager; | 734 | return m_manager; |
776 | } | 735 | } |
777 | void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { | 736 | void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { |
778 | m_item = item; | 737 | m_item = item; |
779 | setPixmap( 0, m_item.pixmap() ); | 738 | setPixmap( 0, m_item.pixmap() ); |
780 | setText ( 1, m_item.text() ); | 739 | setText ( 1, m_item.text() ); |
781 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | 740 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
782 | setText( 2, keyToString( m_item.keyPair() ) ); | 741 | setText( 2, keyToString( m_item.keyPair() ) ); |
783 | 742 | ||
784 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : | 743 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : |
785 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); | 744 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); |
786 | } | 745 | } |
787 | void OKeyListViewItem::updateText() { | 746 | void OKeyListViewItem::updateText() { |
788 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | 747 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
789 | setText( 2, keyToString( m_item.keyPair() ) ); | 748 | setText( 2, keyToString( m_item.keyPair() ) ); |
790 | } | 749 | } |
791 | 750 | ||
792 | QString keyToString( const OKeyPair& pair ) { | 751 | QString keyToString( const OKeyPair& pair ) { |
793 | int mod = 0; | 752 | int mod = 0; |
794 | if ( pair.modifier() & Qt::ShiftButton ) | 753 | if ( pair.modifier() & Qt::ShiftButton ) |
795 | mod |= Qt::SHIFT; | 754 | mod |= Qt::SHIFT; |
796 | if ( pair.modifier() & Qt::ControlButton ) | 755 | if ( pair.modifier() & Qt::ControlButton ) |
797 | mod |= Qt::CTRL; | 756 | mod |= Qt::CTRL; |
798 | if ( pair.modifier() & Qt::AltButton ) | 757 | if ( pair.modifier() & Qt::AltButton ) |
799 | mod |= Qt::ALT; | 758 | mod |= Qt::ALT; |
800 | 759 | ||
801 | return QAccel::keyToString( mod + pair.keycode() ); | 760 | return QAccel::keyToString( mod + pair.keycode() ); |
802 | } | 761 | } |
803 | 762 | ||
763 | void fixupKeys( int& key, int &mod, QKeyEvent* e ) { | ||
764 | key = e->key(); | ||
765 | mod = e->state(); | ||
766 | /* | ||
767 | * virtual keyboard | ||
768 | * else change the button mod only | ||
769 | */ | ||
770 | if ( key == 0 ) { | ||
771 | key = e->ascii(); | ||
772 | if ( key > 96 && key < 123) | ||
773 | key -= 32; | ||
774 | }else{ | ||
775 | int new_mod = 0; | ||
776 | if ( mod & 256 ) | ||
777 | new_mod |= Qt::ShiftButton; | ||
778 | else if ( mod & 512 ) | ||
779 | new_mod |= Qt::ControlButton; | ||
780 | else if ( mod & 1024 ) | ||
781 | new_mod |= Qt::AltButton; | ||
782 | |||
783 | mod = new_mod == 0? mod : new_mod; | ||
784 | } | ||
785 | } | ||
786 | |||
804 | struct OKeyConfigWidgetPrivate{ | 787 | struct OKeyConfigWidgetPrivate{ |
805 | OKeyConfigWidgetPrivate(const QString& = QString::null, | 788 | OKeyConfigWidgetPrivate(const QString& = QString::null, |
806 | OKeyConfigManager* = 0); | 789 | OKeyConfigManager* = 0); |
807 | bool operator==( const OKeyConfigWidgetPrivate& ); | 790 | bool operator==( const OKeyConfigWidgetPrivate& ); |
808 | QString name; | 791 | QString name; |
809 | OKeyConfigManager *manager; | 792 | OKeyConfigManager *manager; |
810 | }; | 793 | }; |
811 | 794 | ||
812 | OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, | 795 | OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, |
813 | OKeyConfigManager* man ) | 796 | OKeyConfigManager* man ) |
814 | : name( _name ), manager( man ){} | 797 | : name( _name ), manager( man ){} |
815 | 798 | ||
816 | bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { | 799 | bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { |
817 | if ( manager != item.manager) return false; | 800 | if ( manager != item.manager) return false; |
818 | if ( name != item.name ) return false; | 801 | if ( name != item.name ) return false; |
819 | 802 | ||
820 | return true; | 803 | return true; |
821 | } | 804 | } |
822 | 805 | ||
823 | } | 806 | } |
824 | } | 807 | } |
825 | } | 808 | } |
826 | 809 | ||
827 | 810 | ||
828 | 811 | ||
829 | //////////////////////// | 812 | //////////////////////// |
830 | 813 | //////////////////////// | |
814 | //////// Widget Starts Here | ||
831 | 815 | ||
832 | 816 | ||
833 | 817 | ||
834 | 818 | ||
835 | /** | 819 | /** |
836 | * | 820 | * |
837 | * This is a c'tor. You still need to pass the OKeyConfigManager | 821 | * This is a c'tor. You still need to pass the OKeyConfigManager |
838 | * and then issue a load. | 822 | * and then issue a load. |
839 | * The default mode is Immediate | 823 | * The default mode is Immediate |
840 | * | 824 | * |
841 | */ | 825 | */ |
842 | OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) | 826 | OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) |
843 | : QWidget( parent, name, fl ) { | 827 | : QWidget( parent, name, fl ) { |
844 | initUi(); | 828 | initUi(); |
845 | } | 829 | } |
846 | 830 | ||
847 | 831 | ||
848 | 832 | ||
849 | /** | 833 | /** |
850 | * c'tor | 834 | * c'tor |
851 | */ | 835 | */ |
852 | OKeyConfigWidget::~OKeyConfigWidget() { | 836 | OKeyConfigWidget::~OKeyConfigWidget() { |
853 | } | 837 | } |
854 | 838 | ||
855 | 839 | ||
856 | /** | 840 | /** |
857 | * @internal | 841 | * @internal |
858 | */ | 842 | */ |
859 | void OKeyConfigWidget::initUi() { | 843 | void OKeyConfigWidget::initUi() { |
860 | QBoxLayout *layout = new QVBoxLayout( this ); | 844 | QBoxLayout *layout = new QVBoxLayout( this ); |
861 | QGridLayout *gridLay = new QGridLayout( 2, 2 ); | 845 | QGridLayout *gridLay = new QGridLayout( 2, 2 ); |
862 | layout->addLayout( gridLay, 10 ); | 846 | layout->addLayout( gridLay, 10 ); |
863 | gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth | 847 | gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth |
864 | 848 | ||
865 | /* | 849 | /* |
866 | * LISTVIEW with the Keys | 850 | * LISTVIEW with the Keys |
867 | */ | 851 | */ |
868 | m_view = new Opie::Ui::OListView( this ); | 852 | m_view = new Opie::Ui::OListView( this ); |
869 | m_view->setFocus(); | 853 | m_view->setFocus(); |
870 | m_view->setAllColumnsShowFocus( true ); | 854 | m_view->setAllColumnsShowFocus( true ); |
871 | m_view->addColumn( tr("Pixmap") ); | 855 | m_view->addColumn( tr("Pixmap") ); |
872 | m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); | 856 | m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); |
873 | m_view->addColumn( tr("Key" ) ); | 857 | m_view->addColumn( tr("Key" ) ); |
874 | m_view->addColumn( tr("Default Key" ) ); | 858 | m_view->addColumn( tr("Default Key" ) ); |
875 | m_view->setRootIsDecorated( true ); | 859 | m_view->setRootIsDecorated( true ); |
876 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), | 860 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), |
877 | this, SLOT(slotListViewItem(QListViewItem*)) ); | 861 | this, SLOT(slotListViewItem(QListViewItem*)) ); |
878 | 862 | ||
879 | gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); | 863 | gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); |
880 | 864 | ||
881 | /* | 865 | /* |
882 | * GROUP with button info | 866 | * GROUP with button info |
883 | */ | 867 | */ |
884 | 868 | ||
885 | QGroupBox *box = new QGroupBox( this ); | 869 | QGroupBox *box = new QGroupBox( this ); |
886 | box ->setTitle( tr("Shortcut for Selected Action") ); | 870 | box ->setTitle( tr("Shortcut for Selected Action") ); |
887 | box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); | 871 | box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); |
888 | layout->addWidget( box, 1 ); | 872 | layout->addWidget( box, 1 ); |
889 | 873 | ||
890 | gridLay = new QGridLayout( box, 3, 4 ); | 874 | gridLay = new QGridLayout( box, 3, 4 ); |
891 | gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); | 875 | gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); |
892 | gridLay->setMargin( 4 ); | 876 | gridLay->setMargin( 4 ); |
893 | 877 | ||
894 | QButtonGroup *gr = new QButtonGroup( box ); | 878 | QButtonGroup *gr = new QButtonGroup( box ); |
895 | gr->hide(); | 879 | gr->hide(); |
896 | gr->setExclusive( true ); | 880 | gr->setExclusive( true ); |
897 | 881 | ||
898 | QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); | 882 | QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); |
899 | connect( rad, SIGNAL(clicked()), | 883 | connect( rad, SIGNAL(clicked()), |
900 | this, SLOT(slotNoKey()) ); | 884 | this, SLOT(slotNoKey()) ); |
901 | gr->insert( rad, 10 ); | 885 | gr->insert( rad, 10 ); |
902 | gridLay->addWidget( rad, 1, 0 ); | 886 | gridLay->addWidget( rad, 1, 0 ); |
903 | m_none = rad; | 887 | m_none = rad; |
904 | 888 | ||
905 | rad = new QRadioButton( tr("&Default" ), box ); | 889 | rad = new QRadioButton( tr("&Default" ), box ); |
906 | connect( rad, SIGNAL(clicked()), | 890 | connect( rad, SIGNAL(clicked()), |
907 | this, SLOT(slotDefaultKey()) ); | 891 | this, SLOT(slotDefaultKey()) ); |
908 | gr->insert( rad, 11 ); | 892 | gr->insert( rad, 11 ); |
909 | gridLay->addWidget( rad, 1, 1 ); | 893 | gridLay->addWidget( rad, 1, 1 ); |
910 | m_def = rad; | 894 | m_def = rad; |
911 | 895 | ||
912 | rad = new QRadioButton( tr("C&ustom"), box ); | 896 | rad = new QRadioButton( tr("C&ustom"), box ); |
913 | connect( rad, SIGNAL(clicked()), | 897 | connect( rad, SIGNAL(clicked()), |
914 | this, SLOT(slotCustomKey()) ); | 898 | this, SLOT(slotCustomKey()) ); |
915 | gr->insert( rad, 12 ); | 899 | gr->insert( rad, 12 ); |
916 | gridLay->addWidget( rad, 1, 2 ); | 900 | gridLay->addWidget( rad, 1, 2 ); |
917 | m_cus = rad; | 901 | m_cus = rad; |
918 | 902 | ||
919 | m_btn = new QPushButton( tr("Configure Key"), box ); | 903 | m_btn = new QPushButton( tr("Configure Key"), box ); |
920 | gridLay->addWidget( m_btn, 1, 4 ); | 904 | gridLay->addWidget( m_btn, 1, 4 ); |
921 | 905 | ||
922 | m_lbl= new QLabel( tr( "Default: " ), box ); | 906 | m_lbl= new QLabel( tr( "Default: " ), box ); |
923 | gridLay->addWidget( m_lbl, 2, 0 ); | 907 | gridLay->addWidget( m_lbl, 2, 0 ); |
924 | 908 | ||
925 | connect(m_btn, SIGNAL(clicked()), | 909 | connect(m_btn, SIGNAL(clicked()), |
926 | this, SLOT(slotConfigure())); | 910 | this, SLOT(slotConfigure())); |
927 | 911 | ||
928 | m_box = box; | 912 | m_box = box; |
929 | } | 913 | } |
930 | 914 | ||
931 | /** | 915 | /** |
932 | * Set the ChangeMode. | 916 | * Set the ChangeMode. |
933 | * You need to call this function prior to load | 917 | * You need to call this function prior to load |
934 | * If you call this function past load the behaviour is undefined | 918 | * If you call this function past load the behaviour is undefined |
935 | * But caling load again is safe | 919 | * But caling load again is safe |
936 | */ | 920 | */ |
937 | void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { | 921 | void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { |
938 | m_mode = mode; | 922 | m_mode = mode; |
939 | } | 923 | } |
940 | 924 | ||
941 | 925 | ||
942 | /** | 926 | /** |
943 | * return the current mode | 927 | * return the current mode |
944 | */ | 928 | */ |
945 | OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { | 929 | OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { |
946 | return m_mode; | 930 | return m_mode; |
947 | } | 931 | } |
948 | 932 | ||
949 | 933 | ||
950 | /** | 934 | /** |
951 | * insert these items before calling load | 935 | * insert these items before calling load |
952 | */ | 936 | */ |
953 | void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { | 937 | void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { |
954 | Opie::Ui::Private::OKeyConfigWidgetPrivate root( str, man ); | 938 | Opie::Ui::Private::OKeyConfigWidgetPrivate root( str, man ); |
955 | m_list.append(root); | 939 | m_list.append(root); |
956 | } | 940 | } |
957 | 941 | ||
958 | 942 | ||
959 | /** | 943 | /** |
960 | * loads the items and allows editing them | 944 | * loads the items and allows editing them |
961 | */ | 945 | */ |
962 | void OKeyConfigWidget::load() { | 946 | void OKeyConfigWidget::load() { |
963 | Opie::Ui::Private::OKeyConfigWidgetPrivateList::Iterator it; | 947 | Opie::Ui::Private::OKeyConfigWidgetPrivateList::Iterator it; |
964 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 948 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
965 | OListViewItem *item = new OListViewItem( m_view, (*it).name ); | 949 | OListViewItem *item = new OListViewItem( m_view, (*it).name ); |
966 | OKeyConfigItem::List list = (*it).manager->keyConfigList(); | 950 | OKeyConfigItem::List list = (*it).manager->keyConfigList(); |
967 | for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt ) | 951 | for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt ) |
968 | (void )new Opie::Ui::Private::OKeyListViewItem(*keyIt, (*it).manager, item ); | 952 | (void )new Opie::Ui::Private::OKeyListViewItem(*keyIt, (*it).manager, item ); |
969 | 953 | ||
970 | } | 954 | } |
971 | } | 955 | } |
972 | 956 | ||
973 | /** | 957 | /** |
974 | * Saves if in Queue Mode. It'll update the supplied | 958 | * Saves if in Queue Mode. It'll update the supplied |
975 | * OKeyConfigManager objects. | 959 | * OKeyConfigManager objects. |
976 | * If in Queue mode it'll just return | 960 | * If in Queue mode it'll just return |
977 | */ | 961 | */ |
978 | void OKeyConfigWidget::save() { | 962 | void OKeyConfigWidget::save() { |
979 | /* | 963 | /* |
980 | * Iterate over all config items | 964 | * Iterate over all config items |
981 | */ | 965 | */ |
982 | QListViewItemIterator it( m_view ); | 966 | QListViewItemIterator it( m_view ); |
983 | while ( it.current() ) { | 967 | while ( it.current() ) { |
984 | if (it.current()->parent() ) { | 968 | if (it.current()->parent() ) { |
985 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( it.current() ); | 969 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( it.current() ); |
986 | OKeyConfigManager *man = item->manager(); | 970 | OKeyConfigManager *man = item->manager(); |
987 | man->removeKeyConfig( item->origItem() ); | 971 | man->removeKeyConfig( item->origItem() ); |
988 | man->addKeyConfig( item->item() ); | 972 | man->addKeyConfig( item->item() ); |
989 | } | 973 | } |
990 | ++it; | 974 | ++it; |
991 | } | 975 | } |
992 | 976 | ||
993 | 977 | ||
994 | } | 978 | } |
995 | 979 | ||
996 | 980 | ||
997 | /** | 981 | /** |
998 | * @internal | 982 | * @internal |
999 | */ | 983 | */ |
1000 | void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { | 984 | void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { |
1001 | if ( !_item || !_item->parent() ) { | 985 | if ( !_item || !_item->parent() ) { |
1002 | m_box->setEnabled( false ); | 986 | m_box->setEnabled( false ); |
1003 | m_none->setChecked( true ); | 987 | m_none->setChecked( true ); |
1004 | m_btn ->setEnabled( false ); | 988 | m_btn ->setEnabled( false ); |
1005 | m_def ->setChecked( false ); | 989 | m_def ->setChecked( false ); |
1006 | m_cus ->setChecked( false ); | 990 | m_cus ->setChecked( false ); |
1007 | }else{ | 991 | }else{ |
1008 | m_box->setEnabled( true ); | 992 | m_box->setEnabled( true ); |
1009 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( _item ); | 993 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( _item ); |
1010 | OKeyConfigItem keyItem= item->item(); | 994 | OKeyConfigItem keyItem= item->item(); |
1011 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); | 995 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); |
1012 | if ( keyItem.keyPair().isEmpty() ) { | 996 | if ( keyItem.keyPair().isEmpty() ) { |
1013 | m_none->setChecked( true ); | 997 | m_none->setChecked( true ); |
1014 | m_btn ->setEnabled( false ); | 998 | m_btn ->setEnabled( false ); |
1015 | m_def ->setChecked( false ); | 999 | m_def ->setChecked( false ); |
1016 | m_cus ->setChecked( false ); | 1000 | m_cus ->setChecked( false ); |
1017 | }else { | 1001 | }else { |
1018 | m_none->setChecked( false ); | 1002 | m_none->setChecked( false ); |
1019 | m_cus ->setChecked( true ); | 1003 | m_cus ->setChecked( true ); |
1020 | m_btn ->setEnabled( true ); | 1004 | m_btn ->setEnabled( true ); |
1021 | m_def ->setChecked( false ); | 1005 | m_def ->setChecked( false ); |
1022 | } | 1006 | } |
1023 | } | 1007 | } |
1024 | } | 1008 | } |
1025 | 1009 | ||
1026 | void OKeyConfigWidget::slotNoKey() { | 1010 | void OKeyConfigWidget::slotNoKey() { |
1027 | qWarning( "No Key" ); | 1011 | qWarning( "No Key" ); |
1028 | m_none->setChecked( true ); | 1012 | m_none->setChecked( true ); |
1029 | m_cus ->setChecked( false ); | 1013 | m_cus ->setChecked( false ); |
1030 | m_btn ->setEnabled( false ); | 1014 | m_btn ->setEnabled( false ); |
1031 | m_def ->setChecked( false ); | 1015 | m_def ->setChecked( false ); |
1032 | 1016 | ||
1033 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1017 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1034 | return; | 1018 | return; |
1035 | 1019 | ||
1036 | 1020 | ||
1037 | 1021 | ||
1038 | /* | 1022 | /* |
1039 | * If immediate we need to remove and readd the key | 1023 | * If immediate we need to remove and readd the key |
1040 | */ | 1024 | */ |
1041 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); | 1025 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); |
1042 | if ( m_mode == Imediate ) | 1026 | updateItem( item, OKeyPair::emptyKey() ); |
1043 | item->manager()->removeKeyConfig( item->item() ); | ||
1044 | item->item().setKeyPair( OKeyPair::emptyKey() ); | ||
1045 | item->updateText(); | ||
1046 | |||
1047 | if ( m_mode == Imediate ) | ||
1048 | item->manager()->addKeyConfig( item->item() ); | ||
1049 | |||
1050 | } | 1027 | } |
1051 | 1028 | ||
1052 | void OKeyConfigWidget::slotDefaultKey() { | 1029 | void OKeyConfigWidget::slotDefaultKey() { |
1053 | m_none->setChecked( false ); | 1030 | m_none->setChecked( false ); |
1054 | m_cus ->setChecked( false ); | 1031 | m_cus ->setChecked( false ); |
1055 | m_btn ->setEnabled( false ); | 1032 | m_btn ->setEnabled( false ); |
1056 | m_def ->setChecked( true ); | 1033 | m_def ->setChecked( true ); |
1057 | 1034 | ||
1058 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1035 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1059 | return; | 1036 | return; |
1060 | 1037 | ||
1061 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); | 1038 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); |
1062 | 1039 | updateItem( item, item->item().defaultKeyPair() ); | |
1063 | /* | ||
1064 | * If immediate we need to remove and readd the key | ||
1065 | */ | ||
1066 | if ( m_mode == Imediate ) | ||
1067 | item->manager()->removeKeyConfig( item->item() ); | ||
1068 | |||
1069 | item->item().setKeyPair( item->item().defaultKeyPair() ); | ||
1070 | item->updateText(); | ||
1071 | |||
1072 | if ( m_mode == Imediate ) | ||
1073 | item->manager()->addKeyConfig( item->item() ); | ||
1074 | } | 1040 | } |
1075 | 1041 | ||
1076 | void OKeyConfigWidget::slotCustomKey() { | 1042 | void OKeyConfigWidget::slotCustomKey() { |
1077 | m_cus ->setChecked( true ); | 1043 | m_cus ->setChecked( true ); |
1078 | m_btn ->setEnabled( true ); | 1044 | m_btn ->setEnabled( true ); |
1079 | m_def ->setChecked( false ); | 1045 | m_def ->setChecked( false ); |
1080 | m_none->setChecked( false ); | 1046 | m_none->setChecked( false ); |
1081 | 1047 | ||
1082 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1048 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1083 | return; | 1049 | return; |
1084 | 1050 | ||
1051 | |||
1085 | } | 1052 | } |
1086 | 1053 | ||
1087 | void OKeyConfigWidget::slotConfigure() { | 1054 | void OKeyConfigWidget::slotConfigure() { |
1055 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | ||
1056 | return; | ||
1057 | |||
1058 | /* FIXME make use of OModalHelper */ | ||
1059 | OKeyChooserConfigDialog dlg( this, "Dialog Name", true ); | ||
1060 | dlg.setCaption(tr("Configure Key")); | ||
1061 | connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) ); | ||
1062 | |||
1063 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { | ||
1064 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); | ||
1065 | updateItem( item, dlg.keyPair() ); | ||
1066 | } | ||
1067 | |||
1068 | |||
1069 | } | ||
1070 | |||
1071 | void OKeyConfigWidget::updateItem( Opie::Ui::Private::OKeyListViewItem *item, | ||
1072 | const OKeyPair& newItem) { | ||
1073 | /* sanity check | ||
1074 | * check against the blacklist of the manager | ||
1075 | * check if another item uses this key which is o(n) at least | ||
1076 | */ | ||
1077 | if ( !newItem.isEmpty() ) { | ||
1078 | |||
1079 | } | ||
1088 | 1080 | ||
1081 | /* | ||
1082 | * If immediate we need to remove and readd the key | ||
1083 | */ | ||
1084 | if ( m_mode == Imediate ) | ||
1085 | item->manager()->removeKeyConfig( item->item() ); | ||
1086 | |||
1087 | item->item().setKeyPair( newItem ); | ||
1088 | item->updateText(); | ||
1089 | |||
1090 | if ( m_mode == Imediate ) | ||
1091 | item->manager()->addKeyConfig( item->item() ); | ||
1089 | } | 1092 | } |
1090 | 1093 | ||
1091 | 1094 | ||
1095 | |||
1096 | ///// | ||
1092 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, | 1097 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, |
1093 | bool mod, WFlags fl ) | 1098 | bool mod, WFlags fl ) |
1094 | : QDialog( par, nam, mod, fl ) { | 1099 | : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) , |
1100 | m_key( 0 ), m_mod( 0 ) { | ||
1101 | setFocusPolicy( StrongFocus ); | ||
1102 | |||
1103 | QHBoxLayout *lay = new QHBoxLayout( this ); | ||
1104 | |||
1105 | QLabel *lbl = new QLabel( tr("Configure Key" ), this ); | ||
1106 | lay->addWidget( lbl ); | ||
1107 | lbl->setFocusPolicy( NoFocus ); | ||
1108 | |||
1109 | m_lbl = new QLabel( this ); | ||
1110 | lay->addWidget( m_lbl ); | ||
1111 | m_lbl->setFocusPolicy( NoFocus ); | ||
1112 | |||
1113 | m_timer = new QTimer( this ); | ||
1114 | connect(m_timer, SIGNAL(timeout()), | ||
1115 | this, SLOT(slotTimeUp()) ); | ||
1095 | } | 1116 | } |
1096 | 1117 | ||
1097 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { | 1118 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { |
1098 | } | 1119 | } |
1099 | 1120 | ||
1100 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ | 1121 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ |
1122 | return m_keyPair; | ||
1101 | } | 1123 | } |
1102 | 1124 | ||
1103 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { | 1125 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { |
1104 | ev->ignore(); | 1126 | QDialog::keyPressEvent( ev ); |
1127 | |||
1128 | if ( ev->isAutoRepeat() ) | ||
1129 | return; | ||
1130 | |||
1131 | qWarning( "Key Press Event" ); | ||
1132 | int mod, key; | ||
1133 | Opie::Ui::Private::fixupKeys( key,mod, ev ); | ||
1134 | |||
1135 | /* either we used software keyboard | ||
1136 | * or we've true support | ||
1137 | */ | ||
1138 | if ( !m_virtKey && !ev->key()) { | ||
1139 | m_virtKey = true; | ||
1140 | m_keyPair = OKeyPair( key, mod ); | ||
1141 | }else{ | ||
1142 | mod = 0; | ||
1143 | switch( key ) { | ||
1144 | case Qt::Key_Control: | ||
1145 | mod = Qt::ControlButton; | ||
1146 | break; | ||
1147 | case Qt::Key_Shift: | ||
1148 | mod = Qt::ShiftButton; | ||
1149 | break; | ||
1150 | case Qt::Key_Alt: | ||
1151 | mod = Qt::AltButton; | ||
1152 | break; | ||
1153 | default: | ||
1154 | break; | ||
1155 | } | ||
1156 | if (mod ) { | ||
1157 | m_mod |= mod; | ||
1158 | }else | ||
1159 | m_key = key; | ||
1160 | |||
1161 | if ( ( !mod || m_key ) && !m_timer->isActive() ) | ||
1162 | m_timer->start( 50, true ); | ||
1163 | |||
1164 | m_keyPair = OKeyPair( m_key, m_mod ); | ||
1165 | } | ||
1166 | |||
1167 | m_lbl->setText( Opie::Ui::Private::keyToString( m_keyPair ) ); | ||
1168 | |||
1105 | } | 1169 | } |
1106 | 1170 | ||
1107 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { | 1171 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { |
1108 | ev->ignore(); | 1172 | m_timer->stop(); |
1173 | QDialog::keyPressEvent( ev ); | ||
1174 | |||
1175 | if ( ev->isAutoRepeat() ) | ||
1176 | return; | ||
1177 | |||
1178 | |||
1179 | if ( m_virtKey && !ev->key()) { | ||
1180 | m_virtKey = false; | ||
1181 | slotTimeUp(); | ||
1182 | }else { | ||
1183 | int mod = 0; | ||
1184 | int key = ev->key(); | ||
1185 | switch( key ) { | ||
1186 | case Qt::Key_Control: | ||
1187 | mod = Qt::ControlButton; | ||
1188 | break; | ||
1189 | case Qt::Key_Shift: | ||
1190 | mod = Qt::ShiftButton; | ||
1191 | break; | ||
1192 | case Qt::Key_Alt: | ||
1193 | mod = Qt::AltButton; | ||
1194 | break; | ||
1195 | default: | ||
1196 | break; | ||
1197 | } | ||
1198 | if (mod ) | ||
1199 | m_mod &= ~mod; | ||
1200 | else | ||
1201 | m_key = key; | ||
1202 | m_keyPair = OKeyPair( m_key, m_mod ); | ||
1203 | m_lbl->setText( Opie::Ui::Private::keyToString( m_keyPair ) ); | ||
1204 | } | ||
1205 | } | ||
1206 | |||
1207 | |||
1208 | void OKeyChooserConfigDialog::slotTimeUp() { | ||
1209 | m_mod = m_key = 0; | ||
1210 | QTimer::singleShot(0, this, SIGNAL(keyCaptured()) ); | ||
1109 | } | 1211 | } |
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h index 8d2a1ef..9e26719 100644 --- a/libopie2/opieui/okeyconfigwidget.h +++ b/libopie2/opieui/okeyconfigwidget.h | |||
@@ -1,309 +1,320 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2004 | 2 | * Copyright (C) 2004 |
3 | * LGPL v2 zecke@handhelds.org | 3 | * LGPL v2 zecke@handhelds.org |
4 | */ | 4 | */ |
5 | 5 | ||
6 | 6 | ||
7 | #ifndef ODP_KEY_CONFIG_WIDGET_H | 7 | #ifndef ODP_KEY_CONFIG_WIDGET_H |
8 | #define ODP_KEY_CONFIG_WIDGET_H | 8 | #define ODP_KEY_CONFIG_WIDGET_H |
9 | 9 | ||
10 | #include <opie2/oconfig.h> | 10 | #include <opie2/oconfig.h> |
11 | #include <opie2/odevice.h> | 11 | #include <opie2/odevice.h> |
12 | 12 | ||
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qpixmap.h> | 14 | #include <qpixmap.h> |
15 | #include <qcstring.h> | 15 | #include <qcstring.h> |
16 | #include <qhbox.h> | 16 | #include <qhbox.h> |
17 | #include <qvaluelist.h> | 17 | #include <qvaluelist.h> |
18 | 18 | ||
19 | class QKeyEvent; | 19 | class QKeyEvent; |
20 | class QLabel; | 20 | class QLabel; |
21 | class QPushButton; | 21 | class QPushButton; |
22 | class QListViewItem; | 22 | class QListViewItem; |
23 | class QRadioButton; | 23 | class QRadioButton; |
24 | class QTimer; | ||
24 | 25 | ||
25 | namespace Opie { | 26 | namespace Opie { |
26 | namespace Ui { | 27 | namespace Ui { |
27 | namespace Private { | 28 | namespace Private { |
28 | class OKeyConfigWidgetPrivate; | 29 | class OKeyConfigWidgetPrivate; |
29 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; | 30 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; |
31 | class OKeyListViewItem; | ||
30 | } | 32 | } |
31 | class OListViewItem; | 33 | class OListViewItem; |
32 | class OListView; | 34 | class OListView; |
33 | 35 | ||
34 | /** | 36 | /** |
35 | * \brief small class representing a Key with possible modifiers | 37 | * \brief small class representing a Key with possible modifiers |
36 | * This class holds information about key code and possible | 38 | * This class holds information about key code and possible |
37 | * modifier state. That is the lowest level of the key input | 39 | * modifier state. That is the lowest level of the key input |
38 | * functions. | 40 | * functions. |
39 | * There are also static methods to get special keys. | 41 | * There are also static methods to get special keys. |
40 | * OKeyPair will be used with \see OKeyConfigItem | 42 | * OKeyPair will be used with \see OKeyConfigItem |
41 | * | 43 | * |
42 | * @since 1.2 | 44 | * @since 1.2 |
43 | */ | 45 | */ |
44 | class OKeyPair { | 46 | class OKeyPair { |
45 | public: | 47 | public: |
46 | typedef QValueList<OKeyPair> List; | 48 | typedef QValueList<OKeyPair> List; |
47 | OKeyPair( int key = -1, int modifier = -1); | 49 | OKeyPair( int key = -1, int modifier = -1); |
48 | ~OKeyPair(); | 50 | ~OKeyPair(); |
49 | 51 | ||
50 | bool operator==( const OKeyPair& ); | 52 | bool operator==( const OKeyPair& ); |
51 | bool operator!=( const OKeyPair& ); | 53 | bool operator!=( const OKeyPair& ); |
52 | 54 | ||
53 | bool isEmpty()const; | 55 | bool isEmpty()const; |
54 | 56 | ||
55 | int keycode()const; | 57 | int keycode()const; |
56 | int modifier()const; | 58 | int modifier()const; |
57 | 59 | ||
58 | void setKeycode( int ); | 60 | void setKeycode( int ); |
59 | void setModifier( int ); | 61 | void setModifier( int ); |
60 | 62 | ||
61 | static OKeyPair returnKey(); | 63 | static OKeyPair returnKey(); |
62 | static OKeyPair leftArrowKey(); | 64 | static OKeyPair leftArrowKey(); |
63 | static OKeyPair rightArrowKey(); | 65 | static OKeyPair rightArrowKey(); |
64 | static OKeyPair upArrowKey(); | 66 | static OKeyPair upArrowKey(); |
65 | static OKeyPair downArrowKey(); | 67 | static OKeyPair downArrowKey(); |
66 | static OKeyPair emptyKey(); | 68 | static OKeyPair emptyKey(); |
67 | static OKeyPair::List hardwareKeys(); | 69 | static OKeyPair::List hardwareKeys(); |
68 | 70 | ||
69 | private: | 71 | private: |
70 | int m_key; | 72 | int m_key; |
71 | int m_mod; | 73 | int m_mod; |
72 | class Private; | 74 | class Private; |
73 | Private* d; | 75 | Private* d; |
74 | }; | 76 | }; |
75 | 77 | ||
76 | /** | 78 | /** |
77 | * A class to represent an OKeyPair. | 79 | * A class to represent an OKeyPair. |
78 | * It consists out of a Text exposed to the user, Config Key Item, | 80 | * It consists out of a Text exposed to the user, Config Key Item, |
79 | * Pixmap, A default OKeyPair and the set OKeyPair. | 81 | * Pixmap, A default OKeyPair and the set OKeyPair. |
80 | * You can also pass an id to it | 82 | * You can also pass an id to it |
81 | * | 83 | * |
82 | * @since 1.1.2 | 84 | * @since 1.1.2 |
83 | */ | 85 | */ |
84 | class OKeyConfigItem { | 86 | class OKeyConfigItem { |
85 | friend class OKeyConfigManager; | 87 | friend class OKeyConfigManager; |
86 | public: | 88 | public: |
87 | typedef QValueList<OKeyConfigItem> List; | 89 | typedef QValueList<OKeyConfigItem> List; |
88 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | 90 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), |
89 | const QPixmap& symbol = QPixmap(), | 91 | const QPixmap& symbol = QPixmap(), |
90 | int id = -1, | 92 | int id = -1, |
91 | const OKeyPair& def = OKeyPair::emptyKey(), | 93 | const OKeyPair& def = OKeyPair::emptyKey(), |
92 | QObject *caller = 0, const char* slot = 0); | 94 | QObject *caller = 0, const char* slot = 0); |
93 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | 95 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); |
94 | ~OKeyConfigItem(); | 96 | ~OKeyConfigItem(); |
95 | 97 | ||
96 | bool operator==( const OKeyConfigItem& ); | 98 | bool operator==( const OKeyConfigItem& ); |
97 | bool operator!=( const OKeyConfigItem& ); | 99 | bool operator!=( const OKeyConfigItem& ); |
98 | 100 | ||
99 | QString text()const; | 101 | QString text()const; |
100 | QPixmap pixmap()const; | 102 | QPixmap pixmap()const; |
101 | int id()const; | 103 | int id()const; |
102 | 104 | ||
103 | 105 | ||
104 | 106 | ||
105 | OKeyPair keyPair()const; | 107 | OKeyPair keyPair()const; |
106 | OKeyPair defaultKeyPair()const; | 108 | OKeyPair defaultKeyPair()const; |
107 | QCString configKey()const; | 109 | QCString configKey()const; |
108 | 110 | ||
109 | 111 | ||
110 | void setText( const QString& text ); | 112 | void setText( const QString& text ); |
111 | void setPixmap( const QPixmap& ); | 113 | void setPixmap( const QPixmap& ); |
112 | void setKeyPair( const OKeyPair& ); | 114 | void setKeyPair( const OKeyPair& ); |
113 | void setDefaultKeyPair( const OKeyPair& ); | 115 | void setDefaultKeyPair( const OKeyPair& ); |
114 | 116 | ||
115 | bool isEmpty()const; | 117 | bool isEmpty()const; |
116 | 118 | ||
117 | protected: | 119 | protected: |
118 | QObject *object()const; | 120 | QObject *object()const; |
119 | QCString slot()const; | 121 | QCString slot()const; |
120 | void setId( int id ); | 122 | void setId( int id ); |
121 | void setConfigKey( const QCString& ); | 123 | void setConfigKey( const QCString& ); |
122 | 124 | ||
123 | private: | 125 | private: |
124 | QString m_text; | 126 | QString m_text; |
125 | QCString m_config; | 127 | QCString m_config; |
126 | QPixmap m_pix; | 128 | QPixmap m_pix; |
127 | int m_id; | 129 | int m_id; |
128 | OKeyPair m_key; | 130 | OKeyPair m_key; |
129 | OKeyPair m_def; | 131 | OKeyPair m_def; |
130 | QObject *m_obj; | 132 | QObject *m_obj; |
131 | QCString m_str; | 133 | QCString m_str; |
132 | class Private; | 134 | class Private; |
133 | Private *d; | 135 | Private *d; |
134 | }; | 136 | }; |
135 | 137 | ||
136 | 138 | ||
137 | 139 | ||
138 | /** | 140 | /** |
139 | * \brief A manager to load and save Key Actions and get notified | 141 | * \brief A manager to load and save Key Actions and get notified |
140 | * This is the Manager for KeyActions. | 142 | * This is the Manager for KeyActions. |
141 | * You can say from which config and group to read data, to grab the | 143 | * You can say from which config and group to read data, to grab the |
142 | * keyboard to handle hardware keys, you can supply a blacklist of | 144 | * keyboard to handle hardware keys, you can supply a blacklist of |
143 | * keys which should not be used by allowed to be used. | 145 | * keys which should not be used by allowed to be used. |
144 | * You can even pass this manager to a Widget to do the configuration for you. | 146 | * You can even pass this manager to a Widget to do the configuration for you. |
145 | * You need to add OKeyConfigItem for your keys and then issue a load() to | 147 | * You need to add OKeyConfigItem for your keys and then issue a load() to |
146 | * read the Key information. | 148 | * read the Key information. |
147 | * You can either handle the QKeyEvent yourself and ask this class if it is | 149 | * You can either handle the QKeyEvent yourself and ask this class if it is |
148 | * handled by your action and let give you the action. Or you can install | 150 | * handled by your action and let give you the action. Or you can install |
149 | * the event filter and get a signal. | 151 | * the event filter and get a signal. |
150 | * You need to load ans save yourself! | 152 | * You need to load ans save yourself! |
151 | * | 153 | * |
152 | * @since 1.1.2 | 154 | * @since 1.1.2 |
153 | */ | 155 | */ |
154 | class OKeyConfigManager : public QObject { | 156 | class OKeyConfigManager : public QObject { |
155 | Q_OBJECT | 157 | Q_OBJECT |
156 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; | 158 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; |
157 | public: | 159 | public: |
158 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, | 160 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, |
159 | const QString& group = QString::null, | 161 | const QString& group = QString::null, |
160 | const OKeyPair::List &block = OKeyPair::List(), | 162 | const OKeyPair::List &block = OKeyPair::List(), |
161 | bool grabkeyboard = false, QObject * par = 0, | 163 | bool grabkeyboard = false, QObject * par = 0, |
162 | const char* name = 0 ); | 164 | const char* name = 0 ); |
163 | ~OKeyConfigManager(); | 165 | ~OKeyConfigManager(); |
164 | 166 | ||
165 | void load(); | 167 | void load(); |
166 | void save(); | 168 | void save(); |
167 | 169 | ||
168 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); | 170 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); |
169 | int handleKeyEventId( QKeyEvent* ); | 171 | int handleKeyEventId( QKeyEvent* ); |
170 | 172 | ||
171 | void addKeyConfig( const OKeyConfigItem& ); | 173 | void addKeyConfig( const OKeyConfigItem& ); |
172 | void removeKeyConfig( const OKeyConfigItem& ); | 174 | void removeKeyConfig( const OKeyConfigItem& ); |
173 | void clearKeyConfig(); | 175 | void clearKeyConfig(); |
174 | 176 | ||
175 | void addToBlackList( const OKeyPair& ); | 177 | void addToBlackList( const OKeyPair& ); |
176 | void removeFromBlackList( const OKeyPair& ); | 178 | void removeFromBlackList( const OKeyPair& ); |
177 | void clearBlackList(); | 179 | void clearBlackList(); |
178 | OKeyPair::List blackList()const; | 180 | OKeyPair::List blackList()const; |
179 | 181 | ||
180 | void handleWidget( QWidget* ); | 182 | void handleWidget( QWidget* ); |
181 | 183 | ||
182 | bool eventFilter( QObject*, QEvent* ); | 184 | bool eventFilter( QObject*, QEvent* ); |
183 | 185 | ||
184 | OKeyConfigItem::List keyConfigList()const; | 186 | OKeyConfigItem::List keyConfigList()const; |
185 | signals: | 187 | signals: |
186 | /** | 188 | /** |
187 | * The Signals are triggered on KeyPress and KeyRelease! | 189 | * The Signals are triggered on KeyPress and KeyRelease! |
188 | * You can check the isDown of the QKeyEvent | 190 | * You can check the isDown of the QKeyEvent |
189 | * @see QKeyEvent | 191 | * @see QKeyEvent |
190 | */ | 192 | */ |
191 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | 193 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); |
192 | 194 | ||
193 | /** | 195 | /** |
194 | * This Signal correspondents to the OKeyConfigItem slot | 196 | * This Signal correspondents to the OKeyConfigItem slot |
195 | * and object | 197 | * and object |
196 | * | 198 | * |
197 | * @see OKeyConfigItem::slot | 199 | * @see OKeyConfigItem::slot |
198 | * @see OKeyConfigItem::object | 200 | * @see OKeyConfigItem::object |
199 | */ | 201 | */ |
200 | void actionActivated( QWidget* par, QKeyEvent* key); | 202 | void actionActivated( QWidget* par, QKeyEvent* key); |
201 | 203 | ||
202 | private: | 204 | private: |
203 | OKeyConfigItem::List keyList( int ); | 205 | OKeyConfigItem::List keyList( int ); |
204 | OKeyConfigItem::List m_keys; | 206 | OKeyConfigItem::List m_keys; |
205 | QValueList<QWidget*> m_widgets; | 207 | QValueList<QWidget*> m_widgets; |
206 | Opie::Core::OConfig *m_conf; | 208 | Opie::Core::OConfig *m_conf; |
207 | QString m_group; | 209 | QString m_group; |
208 | OKeyPair::List m_blackKeys; | 210 | OKeyPair::List m_blackKeys; |
209 | bool m_grab : 1; | 211 | bool m_grab : 1; |
210 | OKeyMapConfigPrivate *m_map; | 212 | OKeyMapConfigPrivate *m_map; |
211 | class Private; | 213 | class Private; |
212 | Private *d; | 214 | Private *d; |
213 | }; | 215 | }; |
214 | 216 | ||
215 | 217 | ||
216 | /** | 218 | /** |
217 | * With this Widget you can let the Keyboard Shortcuts | 219 | * With this Widget you can let the Keyboard Shortcuts |
218 | * be configured by the user. | 220 | * be configured by the user. |
219 | * There are two ways you can use this widget. Either in a tab were | 221 | * There are two ways you can use this widget. Either in a tab were |
220 | * all changes are immediately getting into effect or in a queue | 222 | * all changes are immediately getting into effect or in a queue |
221 | * were you ask for saving. Save won't write the data but only set | 223 | * were you ask for saving. Save won't write the data but only set |
222 | * it to the OKeyConfigManager | 224 | * it to the OKeyConfigManager |
223 | * | 225 | * |
224 | * @since 1.2 | 226 | * @since 1.2 |
225 | */ | 227 | */ |
226 | class OKeyConfigWidget : public QWidget { | 228 | class OKeyConfigWidget : public QWidget { |
227 | Q_OBJECT | 229 | Q_OBJECT |
228 | 230 | ||
229 | public: | 231 | public: |
230 | /** | 232 | /** |
231 | * Immediate Apply the change directly to the underlying OKeyConfigManager | 233 | * Immediate Apply the change directly to the underlying OKeyConfigManager |
232 | * Queue Save all items and then apply when you save() | 234 | * Queue Save all items and then apply when you save() |
233 | */ | 235 | */ |
234 | enum ChangeMode { Imediate, Queue }; | 236 | enum ChangeMode { Imediate, Queue }; |
235 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 237 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
236 | ~OKeyConfigWidget(); | 238 | ~OKeyConfigWidget(); |
237 | 239 | ||
238 | void setChangeMode( enum ChangeMode ); | 240 | void setChangeMode( enum ChangeMode ); |
239 | ChangeMode changeMode()const; | 241 | ChangeMode changeMode()const; |
240 | 242 | ||
241 | void insert( const QString& name, OKeyConfigManager* ); | 243 | void insert( const QString& name, OKeyConfigManager* ); |
242 | 244 | ||
243 | void load(); | 245 | void load(); |
244 | void save(); | 246 | void save(); |
245 | 247 | ||
246 | private slots: | 248 | private slots: |
247 | void slotListViewItem( QListViewItem* ); | 249 | void slotListViewItem( QListViewItem* ); |
248 | void slotNoKey(); | 250 | void slotNoKey(); |
249 | void slotDefaultKey(); | 251 | void slotDefaultKey(); |
250 | void slotCustomKey(); | 252 | void slotCustomKey(); |
251 | void slotConfigure(); | 253 | void slotConfigure(); |
252 | 254 | ||
253 | private: | 255 | private: |
256 | void updateItem( Opie::Ui::Private::OKeyListViewItem* man, | ||
257 | const OKeyPair& newItem); | ||
254 | void initUi(); | 258 | void initUi(); |
255 | Opie::Ui::OListView *m_view; | 259 | Opie::Ui::OListView *m_view; |
256 | Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list; | 260 | Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list; |
257 | QLabel *m_lbl; | 261 | QLabel *m_lbl; |
258 | QPushButton *m_btn; | 262 | QPushButton *m_btn; |
259 | QRadioButton *m_def, *m_cus, *m_none; | 263 | QRadioButton *m_def, *m_cus, *m_none; |
260 | QWidget* m_box; | 264 | QWidget* m_box; |
261 | ChangeMode m_mode; | 265 | ChangeMode m_mode; |
262 | class Private; | 266 | class Private; |
263 | Private *d; | 267 | Private *d; |
264 | }; | 268 | }; |
265 | 269 | ||
266 | 270 | ||
267 | /** | 271 | /** |
268 | * This is a small dialog that allows you to | 272 | * This is a small dialog that allows you to |
269 | * capture a key sequence. | 273 | * capture a key sequence. |
270 | * If you want it to close after a key was captured you | 274 | * If you want it to close after a key was captured you |
271 | * can use this code snippet. | 275 | * can use this code snippet. |
272 | * | 276 | * |
273 | * \code | 277 | * \code |
274 | * OKeyChooserConfigDialog diag(0,0,true); | 278 | * OKeyChooserConfigDialog diag(0,0,true); |
275 | * connect(&diag,SIGNAL(keyCaptured()), | 279 | * connect(&diag,SIGNAL(keyCaptured()), |
276 | * this,SLOT(accept())); | 280 | * this,SLOT(accept())); |
277 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ | 281 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ |
278 | * take_the_key_and_do_something | 282 | * take_the_key_and_do_something |
279 | * } | 283 | * } |
280 | * | 284 | * |
281 | * \endcode | 285 | * \endcode |
282 | * | 286 | * |
283 | */ | 287 | */ |
284 | class OKeyChooserConfigDialog : public QDialog { | 288 | class OKeyChooserConfigDialog : public QDialog { |
285 | Q_OBJECT | 289 | Q_OBJECT |
286 | public: | 290 | public: |
287 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); | 291 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); |
288 | ~OKeyChooserConfigDialog(); | 292 | ~OKeyChooserConfigDialog(); |
289 | 293 | ||
290 | OKeyPair keyPair()const; | 294 | OKeyPair keyPair()const; |
291 | 295 | ||
292 | protected: | 296 | protected: |
293 | void keyPressEvent( QKeyEvent* ); | 297 | void keyPressEvent( QKeyEvent* ); |
294 | void keyReleaseEvent( QKeyEvent* ); | 298 | void keyReleaseEvent( QKeyEvent* ); |
295 | 299 | ||
296 | signals: | 300 | signals: |
297 | void keyCaptured(); | 301 | void keyCaptured(); |
298 | 302 | ||
303 | private slots: | ||
304 | void slotTimeUp(); | ||
305 | |||
299 | private: | 306 | private: |
307 | QTimer *m_timer; | ||
308 | QLabel *m_lbl; | ||
309 | bool m_virtKey : 1; | ||
300 | OKeyPair m_keyPair; | 310 | OKeyPair m_keyPair; |
311 | int m_key, m_mod; | ||
301 | class Private; | 312 | class Private; |
302 | Private *d; | 313 | Private *d; |
303 | }; | 314 | }; |
304 | 315 | ||
305 | } | 316 | } |
306 | } | 317 | } |
307 | 318 | ||
308 | 319 | ||
309 | #endif | 320 | #endif |
diff --git a/libopie2/opieui/okeyconfigwidget_p.h b/libopie2/opieui/okeyconfigwidget_p.h new file mode 100644 index 0000000..e7eaba6 --- a/dev/null +++ b/libopie2/opieui/okeyconfigwidget_p.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * Only Internal implemented in the same .cpp file anyway | ||
3 | */ | ||
4 | #include <opie2/olistview.h> | ||
5 | |||
6 | |||
7 | namespace Opie { | ||
8 | namespace Ui { | ||
9 | namespace Private { | ||
10 | static QString keyToString( const OKeyPair& ); | ||
11 | static void fixupKeys( int&, int&, QKeyEvent* ); | ||
12 | class OKeyListViewItem : public Opie::Ui::OListViewItem { | ||
13 | public: | ||
14 | OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent); | ||
15 | ~OKeyListViewItem(); | ||
16 | |||
17 | void setDefault(); | ||
18 | |||
19 | OKeyConfigItem& item(); | ||
20 | OKeyConfigItem origItem()const; | ||
21 | void setItem( const OKeyConfigItem& item ); | ||
22 | void updateText(); | ||
23 | |||
24 | OKeyConfigManager *manager(); | ||
25 | private: | ||
26 | OKeyConfigItem m_item; | ||
27 | OKeyConfigItem m_origItem; | ||
28 | OKeyConfigManager* m_manager; | ||
29 | |||
30 | }; | ||
31 | } | ||
32 | } | ||
33 | } | ||