camerauis/cameraxui/cxui/src/cxuicapturekeyhandler.cpp
author hgs
Thu, 13 May 2010 21:30:19 +0300
changeset 28 3075d9b614e6
parent 19 d9aefe59d544
child 45 24fd82631616
permissions -rw-r--r--
201017_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description:
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
#include <w32std.h>
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include <QVariant>
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
#include <QKeyEvent>
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
#include <eikon.hrh>
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
#include <coemain.h>
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
#include <e32keys.h> // for EKeyCamera
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
#include "cxuicapturekeyhandler.h"
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
#include "cxutils.h"
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include "cxeengine.h"
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
#include "cxenamespace.h"
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
#include "cxefeaturemanager.h"
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
const int CXUI_KEY_PRIORITY = 100;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
CxuiCaptureKeyHandler::CxuiCaptureKeyHandler(CxeEngine &aEngine) :
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
    mAutofocusKeyPressed(false), mCaptureKeyPressed(false), mEngine(aEngine), mWsSession(CCoeEnv::Static()->WsSession()),
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
    mWindowGroup(CCoeEnv::Static()->RootWin())
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
{
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
    CX_DEBUG_ENTER_FUNCTION();
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
    // Autofocus key
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
    mEngine.featureManager().configuredValues(CxeRuntimeKeys::PRIMARY_CAMERA_AUTOFOCUS_KEYS,
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
                                              mPrimaryCameraAutofocusKeys);
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
    // Capture keys for primary camera
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
    mEngine.featureManager().configuredValues(CxeRuntimeKeys::PRIMARY_CAMERA_CAPTURE_KEYS,
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
                                              mPrimaryCameraCaptureKeys);
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
28
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    47
    listenKeys(true);
19
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
    CX_DEBUG_EXIT_FUNCTION();
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
}
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
CxuiCaptureKeyHandler::~CxuiCaptureKeyHandler()
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    52
{
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
    CX_DEBUG_ENTER_FUNCTION();
28
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    54
    listenKeys(false);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    55
    CX_DEBUG_EXIT_FUNCTION();
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    56
}
19
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
28
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    58
/*!
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    59
* Start or stop listening key events.
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    60
* @param listen Should we start (true) or stop (false) listening key events.
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    61
*/
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    62
void CxuiCaptureKeyHandler::listenKeys(bool listen)
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    63
{
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    64
    CX_DEBUG_ENTER_FUNCTION();
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    65
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    66
    if (listen) {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    67
        // Protect from multiple calls
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    68
        if (mCapturedKeyUpDownHandles.empty() && mCapturedKeyHandles.empty()) {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    69
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    70
            int key(0);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    71
            foreach (key, mPrimaryCameraAutofocusKeys) {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    72
                CX_DEBUG(("CxuiCaptureKeyHandler - hooking autofocus key with scan / key code: %d", key));
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    73
                listenKey(key);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    74
            }
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    75
            foreach (key, mPrimaryCameraCaptureKeys) {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    76
                CX_DEBUG(("CxuiCaptureKeyHandler - hooking capture key with scan / key code: %d", key));
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    77
                listenKey(key);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    78
            }
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    79
        }
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    80
    } else {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    81
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    82
        int handle(0);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    83
        foreach (handle, mCapturedKeyUpDownHandles) {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    84
            mWindowGroup.CancelCaptureKeyUpAndDowns(handle);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    85
        }
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    86
        mCapturedKeyUpDownHandles.clear();
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    87
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    88
        foreach (handle, mCapturedKeyHandles) {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    89
            mWindowGroup.CancelCaptureKey(handle);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    90
        }
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
    91
        mCapturedKeyHandles.clear();
19
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    92
    }
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    93
    CX_DEBUG_EXIT_FUNCTION();
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    94
}
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    95
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    96
bool CxuiCaptureKeyHandler::isAutofocusKeyPressed()
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    97
{
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    98
    return mAutofocusKeyPressed;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    99
}
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   100
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   101
bool CxuiCaptureKeyHandler::isCaptureKeyPressed()
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
{
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   103
    return mCaptureKeyPressed;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   104
}
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   105
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   106
bool CxuiCaptureKeyHandler::handleKeyEvent(QEvent *event)
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   107
{
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   108
    CX_DEBUG_ENTER_FUNCTION();
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   109
    bool eventWasConsumed = false;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   110
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   111
    if (event->type() == QEvent::KeyPress) {
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   112
        QKeyEvent *keyEvent = static_cast<QKeyEvent*> (event);
28
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   113
        CX_DEBUG(("CxuiCaptureKeyHandler - key press with nativeVirtualKey(): %d", keyEvent->nativeVirtualKey()));
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   114
        CX_DEBUG(("CxuiCaptureKeyHandler - key press with nativeScanCode(): %d", keyEvent->nativeScanCode()));
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   115
19
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   116
        if ( mPrimaryCameraAutofocusKeys.contains(keyEvent->nativeScanCode())
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   117
            && !mAutofocusKeyPressed ) {
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   118
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   119
            mAutofocusKeyPressed = true;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   120
            eventWasConsumed = true;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   121
            emit autofocusKeyPressed();
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   122
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   123
        } else if (mPrimaryCameraCaptureKeys.contains(keyEvent->nativeScanCode())
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   124
            && !mCaptureKeyPressed) {
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   125
            mCaptureKeyPressed = true;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   126
            eventWasConsumed = true;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   127
            emit captureKeyPressed();
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   128
        }
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   129
    } else if (event->type() == QEvent::KeyRelease) {
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   130
        QKeyEvent *keyEvent = static_cast<QKeyEvent*> (event);
28
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   131
        CX_DEBUG(("CxuiCaptureKeyHandler - key press with nativeVirtualKey(): %d", keyEvent->nativeVirtualKey()));
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   132
        CX_DEBUG(("CxuiCaptureKeyHandler - key press with nativeScanCode(): %d", keyEvent->nativeScanCode()));
19
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   133
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   134
        if ( mPrimaryCameraAutofocusKeys.contains(keyEvent->nativeScanCode())
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   135
            && mAutofocusKeyPressed ) {
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   136
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   137
            mAutofocusKeyPressed = false;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   138
            eventWasConsumed = true;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   139
            emit autofocusKeyReleased();
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   140
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   141
        } else if (mPrimaryCameraCaptureKeys.contains(keyEvent->nativeScanCode())
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   142
            && mCaptureKeyPressed) {
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   143
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   144
            mCaptureKeyPressed = false;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   145
            eventWasConsumed = true;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   146
            emit captureKeyReleased();
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   147
        }
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   148
    }
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   149
    CX_DEBUG_EXIT_FUNCTION();
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   150
    return eventWasConsumed;
d9aefe59d544 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   151
}
28
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   152
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   153
/*!
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   154
* Helper method to listen to given key (key code or scan code).
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   155
* We need to listen to both "key up", "key down" and "key pressed" events to
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   156
* get all the necessary events to handleKeyEvent(). If we e.g. just listen
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   157
* to up/down events, the way native events are translated to QKeyEvents,
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   158
* we only get QEvent::KeyRelease event when partially in background.
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   159
* @param key Keycode or scancode for the key to listen. Both should be listened.
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   160
*/
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   161
void CxuiCaptureKeyHandler::listenKey(int key)
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   162
{
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   163
    // Capture key down and up events
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   164
    int handle = mWindowGroup.CaptureKeyUpAndDowns(key, 0, 0, CXUI_KEY_PRIORITY);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   165
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   166
    // Handle < 0 means error.
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   167
    if (handle >= 0) {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   168
        mCapturedKeyUpDownHandles.append(handle);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   169
    } else {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   170
        CX_DEBUG(("[WARNING] CxuiCaptureKeyHandler - Problem hooking to key-up/key-down with code: %d", key));
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   171
    }
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   172
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   173
    // Capture key press events
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   174
    handle = mWindowGroup.CaptureKey(key, 0, 0, CXUI_KEY_PRIORITY);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   175
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   176
    if (handle >= 0) {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   177
        mCapturedKeyHandles.append(handle);
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   178
    } else {
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   179
        CX_DEBUG(("[WARNING] CxuiCaptureKeyHandler - Problem hooking to key-press with code: %d", key));
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   180
    }
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   181
}
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   182
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   183
3075d9b614e6 201017_1
hgs
parents: 19
diff changeset
   184
// end of file