|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Private implementation for CxuiCaptureKeyHandler |
|
16 */ |
|
17 |
|
18 #include <QVariant> |
|
19 #include <QKeyEvent> |
|
20 |
|
21 #include "cxuicapturekeyhandler.h" |
|
22 #include "cxuicapturekeyhandler_desktop_p.h" |
|
23 #include "cxutils.h" |
|
24 #include "cxeengine.h" |
|
25 #include "cxenamespace.h" |
|
26 #include "cxefeaturemanager.h" |
|
27 |
|
28 #define CXUIDESKTOP_SCANCODE_LOWERCASE_A 30 |
|
29 #define CXUIDESKTOP_SCANCODE_LOWERCASE_C 46 |
|
30 |
|
31 CxuiCaptureKeyHandlerPrivate::CxuiCaptureKeyHandlerPrivate(CxeEngine &aEngine, CxuiCaptureKeyHandler *parent) : |
|
32 q_ptr(parent), |
|
33 mEngine(aEngine), |
|
34 mAutofocusKeyPressed(false), |
|
35 mCaptureKeyPressed(false) |
|
36 { |
|
37 CX_DEBUG_IN_FUNCTION(); |
|
38 } |
|
39 |
|
40 CxuiCaptureKeyHandlerPrivate::~CxuiCaptureKeyHandlerPrivate() |
|
41 { |
|
42 CX_DEBUG_IN_FUNCTION(); |
|
43 } |
|
44 |
|
45 void CxuiCaptureKeyHandlerPrivate::listenKeys(bool listen) |
|
46 { |
|
47 CX_DEBUG_IN_FUNCTION(); |
|
48 } |
|
49 |
|
50 bool CxuiCaptureKeyHandlerPrivate::handleKeyEvent(QEvent *event) |
|
51 { |
|
52 CX_DEBUG_ENTER_FUNCTION(); |
|
53 Q_Q(CxuiCaptureKeyHandler); |
|
54 |
|
55 bool wasEventConsumed = false; |
|
56 |
|
57 if (event->type() == QEvent::KeyPress) { |
|
58 QKeyEvent *keyEvent = static_cast<QKeyEvent*> (event); |
|
59 if (keyEvent->nativeScanCode() == CXUIDESKTOP_SCANCODE_LOWERCASE_A) { |
|
60 mAutofocusKeyPressed = true; |
|
61 wasEventConsumed = true; |
|
62 emit q->autofocusKeyPressed(); |
|
63 } else if (keyEvent->nativeScanCode() == CXUIDESKTOP_SCANCODE_LOWERCASE_C) { |
|
64 mCaptureKeyPressed = true; |
|
65 wasEventConsumed = true; |
|
66 emit q->captureKeyPressed(); |
|
67 } |
|
68 } else if (event->type() == QEvent::KeyRelease) { |
|
69 QKeyEvent *keyEvent = static_cast<QKeyEvent*> (event); |
|
70 if (keyEvent->nativeScanCode() == CXUIDESKTOP_SCANCODE_LOWERCASE_A) { |
|
71 mAutofocusKeyPressed = false; |
|
72 wasEventConsumed = true; |
|
73 emit q->autofocusKeyReleased(); |
|
74 } else if (keyEvent->nativeScanCode() == CXUIDESKTOP_SCANCODE_LOWERCASE_C) { |
|
75 mCaptureKeyPressed = false; |
|
76 wasEventConsumed = true; |
|
77 emit q->captureKeyReleased(); |
|
78 } |
|
79 } |
|
80 |
|
81 CX_DEBUG_EXIT_FUNCTION(); |
|
82 return wasEventConsumed; |
|
83 } |
|
84 |
|
85 bool CxuiCaptureKeyHandlerPrivate::isAutofocusKeyPressed() |
|
86 { |
|
87 return mAutofocusKeyPressed; |
|
88 } |
|
89 |
|
90 bool CxuiCaptureKeyHandlerPrivate::isCaptureKeyPressed() |
|
91 { |
|
92 return mCaptureKeyPressed; |
|
93 } |