|
1 /* |
|
2 * Copyright (c) 2009 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 * |
|
16 */ |
|
17 #include <w32std.h> |
|
18 #include <QVariant> |
|
19 #include <QKeyEvent> |
|
20 #include <eikon.hrh> |
|
21 #include <coemain.h> |
|
22 #include <e32keys.h> // for EKeyCamera |
|
23 |
|
24 |
|
25 #include "cxuicapturekeyhandler.h" |
|
26 #include "cxutils.h" |
|
27 #include "cxeengine.h" |
|
28 #include "cxenamespace.h" |
|
29 #include "cxefeaturemanager.h" |
|
30 |
|
31 const int CXUI_KEY_PRIORITY = 100; |
|
32 |
|
33 CxuiCaptureKeyHandler::CxuiCaptureKeyHandler(CxeEngine &aEngine) : |
|
34 mAutofocusKeyPressed(false), mCaptureKeyPressed(false), mEngine(aEngine), mWsSession(CCoeEnv::Static()->WsSession()), |
|
35 mWindowGroup(CCoeEnv::Static()->RootWin()) |
|
36 { |
|
37 CX_DEBUG_ENTER_FUNCTION(); |
|
38 |
|
39 // Autofocus key |
|
40 mEngine.featureManager().configuredValues(CxeRuntimeKeys::PRIMARY_CAMERA_AUTOFOCUS_KEYS, |
|
41 mPrimaryCameraAutofocusKeys); |
|
42 |
|
43 // Capture keys for primary camera |
|
44 mEngine.featureManager().configuredValues(CxeRuntimeKeys::PRIMARY_CAMERA_CAPTURE_KEYS, |
|
45 mPrimaryCameraCaptureKeys); |
|
46 |
|
47 int scanCode = 0; |
|
48 int handle = 0; |
|
49 foreach (scanCode, mPrimaryCameraAutofocusKeys) { |
|
50 handle = mWindowGroup.CaptureKeyUpAndDowns(scanCode, 0, 0, CXUI_KEY_PRIORITY); |
|
51 mCapturedKeyUpDownHandles.append(handle); |
|
52 } |
|
53 foreach (scanCode, mPrimaryCameraCaptureKeys) { |
|
54 handle = mWindowGroup.CaptureKeyUpAndDowns(scanCode, 0, 0, CXUI_KEY_PRIORITY); |
|
55 mCapturedKeyUpDownHandles.append(handle); |
|
56 } |
|
57 |
|
58 // Capture key press events... this is done only to make sure other |
|
59 // applications do not react to camera key events. |
|
60 handle = mWindowGroup.CaptureKey(EKeyCamera, 0, 0, CXUI_KEY_PRIORITY); |
|
61 mCapturedKeyHandles.append(handle); |
|
62 |
|
63 CX_DEBUG_EXIT_FUNCTION(); |
|
64 } |
|
65 |
|
66 CxuiCaptureKeyHandler::~CxuiCaptureKeyHandler() |
|
67 { |
|
68 CX_DEBUG_ENTER_FUNCTION(); |
|
69 |
|
70 int handle = 0; |
|
71 foreach (handle, mCapturedKeyUpDownHandles) { |
|
72 mWindowGroup.CancelCaptureKeyUpAndDowns(handle); |
|
73 } |
|
74 foreach (handle, mCapturedKeyHandles) { |
|
75 mWindowGroup.CancelCaptureKey(handle); |
|
76 } |
|
77 |
|
78 CX_DEBUG_EXIT_FUNCTION(); |
|
79 } |
|
80 |
|
81 bool CxuiCaptureKeyHandler::isAutofocusKeyPressed() |
|
82 { |
|
83 return mAutofocusKeyPressed; |
|
84 } |
|
85 |
|
86 bool CxuiCaptureKeyHandler::isCaptureKeyPressed() |
|
87 { |
|
88 return mCaptureKeyPressed; |
|
89 } |
|
90 |
|
91 bool CxuiCaptureKeyHandler::handleKeyEvent(QEvent *event) |
|
92 { |
|
93 CX_DEBUG_ENTER_FUNCTION(); |
|
94 bool eventWasConsumed = false; |
|
95 |
|
96 if (event->type() == QEvent::KeyPress) { |
|
97 QKeyEvent *keyEvent = static_cast<QKeyEvent*> (event); |
|
98 if ( mPrimaryCameraAutofocusKeys.contains(keyEvent->nativeScanCode()) |
|
99 && !mAutofocusKeyPressed ) { |
|
100 |
|
101 mAutofocusKeyPressed = true; |
|
102 eventWasConsumed = true; |
|
103 emit autofocusKeyPressed(); |
|
104 |
|
105 } else if (mPrimaryCameraCaptureKeys.contains(keyEvent->nativeScanCode()) |
|
106 && !mCaptureKeyPressed) { |
|
107 mCaptureKeyPressed = true; |
|
108 eventWasConsumed = true; |
|
109 emit captureKeyPressed(); |
|
110 } |
|
111 } else if (event->type() == QEvent::KeyRelease) { |
|
112 QKeyEvent *keyEvent = static_cast<QKeyEvent*> (event); |
|
113 |
|
114 if ( mPrimaryCameraAutofocusKeys.contains(keyEvent->nativeScanCode()) |
|
115 && mAutofocusKeyPressed ) { |
|
116 |
|
117 mAutofocusKeyPressed = false; |
|
118 eventWasConsumed = true; |
|
119 emit autofocusKeyReleased(); |
|
120 |
|
121 } else if (mPrimaryCameraCaptureKeys.contains(keyEvent->nativeScanCode()) |
|
122 && mCaptureKeyPressed) { |
|
123 |
|
124 mCaptureKeyPressed = false; |
|
125 eventWasConsumed = true; |
|
126 emit captureKeyReleased(); |
|
127 } |
|
128 } |
|
129 CX_DEBUG_EXIT_FUNCTION(); |
|
130 return eventWasConsumed; |
|
131 } |