telutils/dialpad/src/dialpadkeypad.cpp
author hgs
Wed, 21 Jul 2010 18:26:52 +0300
changeset 33 8d5d7fcf9b59
parent 32 1f002146abb4
child 38 bc103bfb69cf
permissions -rw-r--r--
201027
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*!
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
ae8abd0db65c Revision: 201007
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".
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description: Dialpad keypad
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    18
#include <QLocale>
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    19
#include <QSignalMapper>
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    20
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
#include <hbinstance.h>
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
#include <hbinputkeymapfactory.h>
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
#include <hbinputkeymap.h>
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
#include <hbinpututils.h>
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
#include <hbinputsettingproxy.h>
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
#include <hbinputlanguage.h>
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include <hbapplication.h>
33
hgs
parents: 32
diff changeset
    28
#include <hbcolorscheme.h>
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
#include <hblineedit.h>
33
hgs
parents: 32
diff changeset
    30
#include <hbfontspec.h>
hgs
parents: 32
diff changeset
    31
#include <hbevent.h>
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
33
hgs
parents: 32
diff changeset
    33
#include "dialpadnumericbutton.h"
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
#include "dialpadkeypad.h"
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
#include "dialpadbutton.h"
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
#include "dialpadinputfield.h"
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    38
static const int DialpadRowCount = 4;
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
static const int DialpadColumnCount = 3;
32
1f002146abb4 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    40
static const QLatin1String handsetIcon("qtg_mono_call");
1f002146abb4 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    41
static const QLatin1String vmbxIcon("qtg_mono_voice_mailbox");
33
hgs
parents: 32
diff changeset
    42
// layout values in units
hgs
parents: 32
diff changeset
    43
static const qreal DialpadPrimaryTextSize = 5.5;
hgs
parents: 32
diff changeset
    44
static const qreal DialpadSecondaryTextSize = 4.0;
hgs
parents: 32
diff changeset
    45
static const qreal DialpadIconSize = 4.0;
hgs
parents: 32
diff changeset
    46
static const qreal DialpadPrimaryTextLeftMargin  = 1.5;
hgs
parents: 32
diff changeset
    47
static const qreal DialpadPrimarySecondaryMargin  = 0.75;
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    49
static const int DialpadKeyCodeTable[DialpadRowCount*DialpadColumnCount] =
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
{
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
    Qt::Key_1,        Qt::Key_2,      Qt::Key_3,
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    52
    Qt::Key_4,        Qt::Key_5,      Qt::Key_6,
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
    Qt::Key_7,        Qt::Key_8,      Qt::Key_9,
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    54
    Qt::Key_Asterisk, Qt::Key_0,      Qt::Key_NumberSign
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    55
    // Qt::Key_Yes and Qt::Key_BackSpace are handled separately
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
};
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
DialpadKeypad::DialpadKeypad(
13
e32024264ebb Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 12
diff changeset
    59
    const HbMainWindow& mainWindow,
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
    DialpadInputField& inputField,
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
    QGraphicsItem* parent) :
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    62
    HbInputButtonGroup(parent),
13
e32024264ebb Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 12
diff changeset
    63
    mMainWindow(mainWindow),
33
hgs
parents: 32
diff changeset
    64
    mInputField(inputField),
hgs
parents: 32
diff changeset
    65
    mMaxPrimaryLineWidth(0)
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
{
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    67
    setObjectName("keypad");
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    68
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    69
    // create clicked signal mapper
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
    mKeyClickedSignalMapper = new QSignalMapper(this);
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
    connect(mKeyClickedSignalMapper,SIGNAL(mapped(int)),
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
            SLOT(handleKeyClicked(int)));
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    74
    // connect backspace signals
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
    connect(&mInputField.backspaceButton(),SIGNAL(clicked()),
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
            mKeyClickedSignalMapper,SLOT(map()));
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
    mKeyClickedSignalMapper->setMapping(&mInputField.backspaceButton(),
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
                                        Qt::Key_Backspace);
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
    // create keypad
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    81
    setGridSize(QSize(DialpadColumnCount, DialpadRowCount));
33
hgs
parents: 32
diff changeset
    82
    setButtonBorderSize(0);    
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    83
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    84
    QList<HbInputButton*> buttons;
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    86
    for (int i = 0; i < DialpadRowCount * DialpadColumnCount; ++i) {
33
hgs
parents: 32
diff changeset
    87
        DialpadNumericButton *item = new DialpadNumericButton(
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    88
            DialpadKeyCodeTable[i],
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    89
            QPoint(i % DialpadColumnCount, i / DialpadColumnCount));
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    90
        buttons.append(item);
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    91
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    92
        item->setType(HbInputButton::ButtonTypeNormal);
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    93
    }
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    94
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    95
    setButtons(buttons);
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    96
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    97
    // connect keypad signals
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    98
    QObject::connect(this, SIGNAL(buttonPressed(const QKeyEvent&)),
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
    99
                     this, SLOT(sendKeyPressEvent(const QKeyEvent&)));
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   100
    QObject::connect(this, SIGNAL(buttonReleased(const QKeyEvent&)),
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   101
                     this, SLOT(sendKeyReleaseEvent(const QKeyEvent&)));
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   102
    QObject::connect(this, SIGNAL(buttonLongPressed(const QKeyEvent&)),
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   103
                     this, SLOT(sendLongPressEvent(const QKeyEvent&)));
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   104
    QObject::connect(this, SIGNAL(pressedButtonChanged(const QKeyEvent&,
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   105
                                                       const QKeyEvent&)),
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   106
                     this, SLOT(handleKeyChangeEvent(const QKeyEvent&,
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   107
                                                     const QKeyEvent&)));
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   108
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   109
    // create call button (parent layouts this)
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   110
    mCallButton = new DialpadButton(parent);
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   111
    mCallButton->setButtonType(DialpadButton::CallButton);
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   112
    mCallButton->setIcon(HbIcon(handsetIcon));
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   113
    QString buttonName;
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   114
    buttonName.setNum(Qt::Key_Yes);
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   115
    mCallButton->setObjectName(buttonName);
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   116
    connect(mCallButton,SIGNAL(clicked()),
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   117
            mKeyClickedSignalMapper,SLOT(map()));
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   118
    connect(mCallButton,SIGNAL(longPress(QPointF)),
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   119
            mKeyClickedSignalMapper,SLOT(map()));
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   120
    mKeyClickedSignalMapper->setMapping(mCallButton,
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   121
                                        Qt::Key_Yes);
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   122
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   123
    // set button texts
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   124
    setButtonTexts();
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   125
    // set button icons
33
hgs
parents: 32
diff changeset
   126
    button(0)->setIcon(HbIcon(vmbxIcon));
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   127
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   128
    // update button texts when input language is changed
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   129
    connect(HbInputSettingProxy::instance(),
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   130
            SIGNAL(globalInputLanguageChanged(HbInputLanguage)),
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   131
            this,SLOT(setButtonTexts()));
33
hgs
parents: 32
diff changeset
   132
hgs
parents: 32
diff changeset
   133
    updateColorArray();
hgs
parents: 32
diff changeset
   134
hgs
parents: 32
diff changeset
   135
    mUnit = HbDeviceProfile::profile(this).unitValue();
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   136
}
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   137
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   138
DialpadKeypad::~DialpadKeypad()
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   139
{
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   140
}
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   141
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   142
void DialpadKeypad::setButtonTexts()
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   143
{
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   144
    HbInputLanguage inputLanguage =
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   145
        HbInputSettingProxy::instance()->globalInputLanguage();
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   146
    const HbKeymap *keymap =
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   147
        HbKeymapFactory::instance()->keymap(inputLanguage.language());
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   148
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   149
    mGeneratedChar.clear();
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   150
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   151
    if (keymap) {
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   152
        int buttonCount = (DialpadRowCount*DialpadColumnCount);
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   153
        for (int i = 0; i < buttonCount; i++) {
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   154
            int keyCode = DialpadKeyCodeTable[i];
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   155
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
            if (keyCode == Qt::Key_Asterisk) {
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   157
                // asterisk is not localized
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   158
                QChar asterisk('*');
33
hgs
parents: 32
diff changeset
   159
                button(i)->setText(asterisk);
hgs
parents: 32
diff changeset
   160
                button(i)->setSecondaryText(QLatin1String("+"));
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   161
                mGeneratedChar.insert(Qt::Key_Asterisk, asterisk);
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
                continue;
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
            }
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   165
            if (keyCode == Qt::Key_NumberSign) {
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
                // number sign is not localized
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
                QChar numberSign('#');
33
hgs
parents: 32
diff changeset
   168
                button(i)->setText(numberSign);
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
                mGeneratedChar.insert(Qt::Key_NumberSign, numberSign);
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   170
                continue;
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
            }
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   172
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   173
            int index = i;
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   174
            if (keyCode==Qt::Key_0) {
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   175
                index = i-1;
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   176
            }
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   177
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   178
            const HbMappedKey *key =
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   179
                keymap->keyForIndex(HbKeyboardVirtual12Key, index);
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   180
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   181
            if (key) {
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
                QChar numberChar =
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   183
                    HbInputUtils::findFirstNumberCharacterBoundToKey(
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   184
                        key,
33
hgs
parents: 32
diff changeset
   185
                        inputLanguage.language(),
hgs
parents: 32
diff changeset
   186
                        HbInputUtils::inputDigitType(inputLanguage.language()));
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   187
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   188
                // button text
33
hgs
parents: 32
diff changeset
   189
                button(i)->setText(numberChar);
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   190
                mGeneratedChar.insert(keyCode,numberChar);
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   191
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   192
                // additional text (letters)
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   193
                int numberOfCharacters;
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   194
                if (keyCode==Qt::Key_7 || keyCode == Qt::Key_9) {
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   195
                    numberOfCharacters = 4;
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   196
                } else if (keyCode==Qt::Key_0||keyCode==Qt::Key_1) {
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   197
                    numberOfCharacters = 0;
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   198
                } else {
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   199
                    numberOfCharacters = 3;
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   200
                }
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   201
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   202
                QString characters = key->characters(HbModifierNone);
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   203
33
hgs
parents: 32
diff changeset
   204
                if (numberOfCharacters!=0 && keyCode!=Qt::Key_1) {
hgs
parents: 32
diff changeset
   205
                    button(i)->setSecondaryText(characters.left(numberOfCharacters));
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   206
                }
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   207
            }
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   208
        }
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   209
    }
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   210
}
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   211
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   212
void DialpadKeypad::handleKeyClicked(int key)
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   213
{
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   214
    // concerns only yes and backspace keys
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   215
    postKeyEvent(QEvent::KeyPress, key);
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   216
    postKeyEvent(QEvent::KeyRelease, key);
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   217
}
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
void DialpadKeypad::postKeyEvent(QEvent::Type type, int key)
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   220
{
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   221
    // send simulated key to application
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   222
    QKeyEvent *keyEvent = new QKeyEvent(type, key, Qt::NoModifier);
13
e32024264ebb Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 12
diff changeset
   223
    HbApplication::postEvent(const_cast<HbMainWindow*>(&mMainWindow),keyEvent);
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   224
}
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   225
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   226
void DialpadKeypad::sendKeyEventToEditor(QEvent::Type type, int key)
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   227
{
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   228
    // send key event to editor
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   229
    QKeyEvent keyEvent(type, key, Qt::NoModifier, mGeneratedChar.value(key));
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   230
    HbApplication::sendEvent(&mInputField.editor(), &keyEvent);
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   231
}
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   232
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   233
void DialpadKeypad::sendKeyPressEvent(const QKeyEvent& event)
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   234
{
33
hgs
parents: 32
diff changeset
   235
    updateButtonLabels();
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   236
    mPressedNumericKey = event.key();
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   237
    postKeyEvent(QEvent::KeyPress, event.key());
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   238
}
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   239
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   240
void DialpadKeypad::sendKeyReleaseEvent(const QKeyEvent& event)
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   241
{
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   242
    if (mPressedNumericKey) {
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   243
        // short press, update editor here
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   244
        sendKeyEventToEditor(QEvent::KeyPress, event.key());
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   245
    }
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   246
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   247
    postKeyEvent(QEvent::KeyRelease, event.key());    
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   248
}
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   249
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   250
void DialpadKeypad::sendLongPressEvent(const QKeyEvent& event)
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   251
{
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   252
    sendKeyEventToEditor(QEvent::KeyPress, event.key());
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   253
    mPressedNumericKey = 0;
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   254
}
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   255
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   256
void DialpadKeypad::handleKeyChangeEvent(
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   257
    const QKeyEvent& releaseEvent,
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   258
    const QKeyEvent& pressEvent)
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   259
{
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   260
    Q_UNUSED(pressEvent)
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   261
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   262
    postKeyEvent(QEvent::KeyRelease, releaseEvent.key());
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   263
    cancelButtonPress();
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   264
}
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   265
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   266
void DialpadKeypad::setCallButtonEnabled(bool enabled)
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   267
{
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   268
    mCallButton->setEnabled(enabled);
12
ae8abd0db65c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   269
}
19
e44a8c097b15 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   270
e44a8c097b15 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   271
void DialpadKeypad::resetButtons()
e44a8c097b15 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   272
{
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   273
    cancelButtonPress();
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   274
    mCallButton->setDown(false);
19
e44a8c097b15 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   275
}
31
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   276
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   277
DialpadButton& DialpadKeypad::callButton() const
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   278
{
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   279
    return *mCallButton;
a2467631ae02 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 27
diff changeset
   280
}
33
hgs
parents: 32
diff changeset
   281
hgs
parents: 32
diff changeset
   282
DialpadNumericButton* DialpadKeypad::button(int i) const
hgs
parents: 32
diff changeset
   283
{
hgs
parents: 32
diff changeset
   284
    return static_cast<DialpadNumericButton*>(HbInputButtonGroup::button(i));
hgs
parents: 32
diff changeset
   285
}
hgs
parents: 32
diff changeset
   286
hgs
parents: 32
diff changeset
   287
void DialpadKeypad::updateButtonLabels()
hgs
parents: 32
diff changeset
   288
{
hgs
parents: 32
diff changeset
   289
    // update numeric buttons according to button state (pressed/released)
hgs
parents: 32
diff changeset
   290
    updateIconColor();
hgs
parents: 32
diff changeset
   291
    updateTextLayouts(rect().size());
hgs
parents: 32
diff changeset
   292
}
hgs
parents: 32
diff changeset
   293
hgs
parents: 32
diff changeset
   294
void DialpadKeypad::paint(
hgs
parents: 32
diff changeset
   295
    QPainter* painter,
hgs
parents: 32
diff changeset
   296
    const QStyleOptionGraphicsItem* option,
hgs
parents: 32
diff changeset
   297
    QWidget* widget)
hgs
parents: 32
diff changeset
   298
{
hgs
parents: 32
diff changeset
   299
    Q_UNUSED(option);
hgs
parents: 32
diff changeset
   300
    Q_UNUSED(widget);
hgs
parents: 32
diff changeset
   301
hgs
parents: 32
diff changeset
   302
    // Paints empty buttons
hgs
parents: 32
diff changeset
   303
    HbInputButtonGroup::paint(painter,option,widget);
hgs
parents: 32
diff changeset
   304
hgs
parents: 32
diff changeset
   305
    qreal cellWidth = boundingRect().width() / gridSize().width();
hgs
parents: 32
diff changeset
   306
    qreal cellHeight = boundingRect().height() / gridSize().height();
hgs
parents: 32
diff changeset
   307
hgs
parents: 32
diff changeset
   308
    // Draw icons
hgs
parents: 32
diff changeset
   309
    for (int i = 0; i < DialpadRowCount * DialpadColumnCount; i++) {
hgs
parents: 32
diff changeset
   310
        DialpadNumericButton *item = button(i);
hgs
parents: 32
diff changeset
   311
hgs
parents: 32
diff changeset
   312
        if (!item->icon().isNull()) {
hgs
parents: 32
diff changeset
   313
            // icon is centered to button
hgs
parents: 32
diff changeset
   314
            qreal x = (item->position().x() * cellWidth) + (cellWidth / 2) -
hgs
parents: 32
diff changeset
   315
                      ((DialpadIconSize * mUnit) / 2);
hgs
parents: 32
diff changeset
   316
            qreal y = (item->position().y() * cellHeight) +  (cellHeight / 2) -
hgs
parents: 32
diff changeset
   317
                      ((DialpadIconSize * mUnit) / 2);
hgs
parents: 32
diff changeset
   318
hgs
parents: 32
diff changeset
   319
            qreal width = DialpadIconSize * mUnit;
hgs
parents: 32
diff changeset
   320
            qreal height = DialpadIconSize * mUnit;
hgs
parents: 32
diff changeset
   321
hgs
parents: 32
diff changeset
   322
            Qt::Alignment alignment =
hgs
parents: 32
diff changeset
   323
                static_cast<Qt::Alignment>(Qt::AlignVCenter | Qt::AlignHCenter);
hgs
parents: 32
diff changeset
   324
            item->icon().paint(painter,
hgs
parents: 32
diff changeset
   325
                               QRectF(x,y,width,height),
hgs
parents: 32
diff changeset
   326
                               Qt::KeepAspectRatio,
hgs
parents: 32
diff changeset
   327
                               alignment);
hgs
parents: 32
diff changeset
   328
        }                      
hgs
parents: 32
diff changeset
   329
    }
hgs
parents: 32
diff changeset
   330
hgs
parents: 32
diff changeset
   331
    // Draw texts
hgs
parents: 32
diff changeset
   332
    QPen origPen = painter->pen();
hgs
parents: 32
diff changeset
   333
    for (int i = 0; i < mTextLayouts.count(); ++i) {
hgs
parents: 32
diff changeset
   334
        if (i==SecondaryText) {
hgs
parents: 32
diff changeset
   335
            // dimmed in normal state
hgs
parents: 32
diff changeset
   336
            painter->setPen(mColors.at(Pressed+1));
hgs
parents: 32
diff changeset
   337
        } else {
hgs
parents: 32
diff changeset
   338
            // otherwise normal or pressed color
hgs
parents: 32
diff changeset
   339
            painter->setPen(mColors.at(i/TextTypeCount));
hgs
parents: 32
diff changeset
   340
        }
hgs
parents: 32
diff changeset
   341
        mTextLayouts.at(i)->draw(painter, QPointF(0, 0));
hgs
parents: 32
diff changeset
   342
    }
hgs
parents: 32
diff changeset
   343
    painter->setPen(origPen);
hgs
parents: 32
diff changeset
   344
}
hgs
parents: 32
diff changeset
   345
hgs
parents: 32
diff changeset
   346
void DialpadKeypad::updateColorArray()
hgs
parents: 32
diff changeset
   347
{
hgs
parents: 32
diff changeset
   348
    mColors.clear();
hgs
parents: 32
diff changeset
   349
hgs
parents: 32
diff changeset
   350
    QColor normalColor = HbColorScheme::color("qtc_input_button_normal");
hgs
parents: 32
diff changeset
   351
    mColors.insert(Normal, normalColor);
hgs
parents: 32
diff changeset
   352
hgs
parents: 32
diff changeset
   353
    QColor pressedColor = HbColorScheme::color("qtc_input_button_pressed");
hgs
parents: 32
diff changeset
   354
    mColors.insert(Pressed, pressedColor);
hgs
parents: 32
diff changeset
   355
hgs
parents: 32
diff changeset
   356
    // this is used for alphabets shown dimmed, use alpha until exact color
hgs
parents: 32
diff changeset
   357
    // is specified
hgs
parents: 32
diff changeset
   358
    QColor disabledColor = HbColorScheme::color("qtc_input_button_normal");
hgs
parents: 32
diff changeset
   359
    disabledColor.setAlpha(128);
hgs
parents: 32
diff changeset
   360
    mColors.insert(Pressed+1, disabledColor);
hgs
parents: 32
diff changeset
   361
}
hgs
parents: 32
diff changeset
   362
hgs
parents: 32
diff changeset
   363
void DialpadKeypad::updateIconColor()
hgs
parents: 32
diff changeset
   364
{
hgs
parents: 32
diff changeset
   365
    for (int i = 0; i < (DialpadRowCount * DialpadColumnCount); i++) {
hgs
parents: 32
diff changeset
   366
        DialpadNumericButton *item = button(i);
hgs
parents: 32
diff changeset
   367
hgs
parents: 32
diff changeset
   368
        if (item->state()==HbInputButton::ButtonStatePressed) {
hgs
parents: 32
diff changeset
   369
            item->icon().setColor(mColors.at(Pressed));
hgs
parents: 32
diff changeset
   370
        } else {
hgs
parents: 32
diff changeset
   371
            item->icon().setColor(mColors.at(Normal));
hgs
parents: 32
diff changeset
   372
        }
hgs
parents: 32
diff changeset
   373
    }
hgs
parents: 32
diff changeset
   374
}
hgs
parents: 32
diff changeset
   375
hgs
parents: 32
diff changeset
   376
void DialpadKeypad::cancelButtonPress()
hgs
parents: 32
diff changeset
   377
{
hgs
parents: 32
diff changeset
   378
    HbInputButtonGroup::cancelButtonPress();
hgs
parents: 32
diff changeset
   379
    updateButtonLabels();
hgs
parents: 32
diff changeset
   380
}
hgs
parents: 32
diff changeset
   381
hgs
parents: 32
diff changeset
   382
void DialpadKeypad::setGeometry(const QRectF &rect)
hgs
parents: 32
diff changeset
   383
{
hgs
parents: 32
diff changeset
   384
    HbInputButtonGroup::setGeometry(rect);
hgs
parents: 32
diff changeset
   385
    updateTextLayouts(rect.size());
hgs
parents: 32
diff changeset
   386
}
hgs
parents: 32
diff changeset
   387
hgs
parents: 32
diff changeset
   388
void DialpadKeypad::changeEvent(QEvent *event)
hgs
parents: 32
diff changeset
   389
{
hgs
parents: 32
diff changeset
   390
    HbInputButtonGroup::changeEvent(event);
hgs
parents: 32
diff changeset
   391
hgs
parents: 32
diff changeset
   392
    if (event->type() == HbEvent::ThemeChanged) {
hgs
parents: 32
diff changeset
   393
        updateColorArray();
hgs
parents: 32
diff changeset
   394
        updateIconColor();
hgs
parents: 32
diff changeset
   395
    }
hgs
parents: 32
diff changeset
   396
}
hgs
parents: 32
diff changeset
   397
hgs
parents: 32
diff changeset
   398
void DialpadKeypad::updateTextLayouts(const QSizeF &size)
hgs
parents: 32
diff changeset
   399
{
hgs
parents: 32
diff changeset
   400
    if (!size.width() && !size.height()) {
hgs
parents: 32
diff changeset
   401
        return;
hgs
parents: 32
diff changeset
   402
    }
hgs
parents: 32
diff changeset
   403
hgs
parents: 32
diff changeset
   404
    // get normal and pressed state texts
hgs
parents: 32
diff changeset
   405
    QList<QString> textContent;
hgs
parents: 32
diff changeset
   406
    resolveTextContent(textContent);
hgs
parents: 32
diff changeset
   407
hgs
parents: 32
diff changeset
   408
    // layout the texts
hgs
parents: 32
diff changeset
   409
    createTextLayouts(size, textContent);
hgs
parents: 32
diff changeset
   410
}
hgs
parents: 32
diff changeset
   411
hgs
parents: 32
diff changeset
   412
void DialpadKeypad::resolveTextContent(QList<QString> &content)
hgs
parents: 32
diff changeset
   413
{
hgs
parents: 32
diff changeset
   414
    QString normalState;
hgs
parents: 32
diff changeset
   415
    QString normalStateSecondary;
hgs
parents: 32
diff changeset
   416
    QString pressedState;
hgs
parents: 32
diff changeset
   417
    QString pressedStateSecondary;
hgs
parents: 32
diff changeset
   418
hgs
parents: 32
diff changeset
   419
    for (int i = 0; i < (DialpadRowCount*DialpadColumnCount); i++) {
hgs
parents: 32
diff changeset
   420
        DialpadNumericButton *item = button(i);
hgs
parents: 32
diff changeset
   421
        if (item->state()==HbInputButton::ButtonStatePressed) {
hgs
parents: 32
diff changeset
   422
            if (item->text().length()) {
hgs
parents: 32
diff changeset
   423
                pressedState.append(item->text());
hgs
parents: 32
diff changeset
   424
                pressedState.append(QChar(QChar::LineSeparator));
hgs
parents: 32
diff changeset
   425
            }
hgs
parents: 32
diff changeset
   426
hgs
parents: 32
diff changeset
   427
            if (item->secondaryText().length()) {
hgs
parents: 32
diff changeset
   428
                pressedStateSecondary.append(item->secondaryText());
hgs
parents: 32
diff changeset
   429
                pressedStateSecondary.append(QChar(QChar::LineSeparator));
hgs
parents: 32
diff changeset
   430
            }
hgs
parents: 32
diff changeset
   431
        } else { // ButtonStateNormal
hgs
parents: 32
diff changeset
   432
            if (item->text().length()) {
hgs
parents: 32
diff changeset
   433
                normalState.append(item->text());
hgs
parents: 32
diff changeset
   434
                normalState.append(QChar(QChar::LineSeparator));
hgs
parents: 32
diff changeset
   435
            }
hgs
parents: 32
diff changeset
   436
hgs
parents: 32
diff changeset
   437
            if (item->secondaryText().length()) {
hgs
parents: 32
diff changeset
   438
                normalStateSecondary.append(item->secondaryText());
hgs
parents: 32
diff changeset
   439
                normalStateSecondary.append(QChar(QChar::LineSeparator));
hgs
parents: 32
diff changeset
   440
            }
hgs
parents: 32
diff changeset
   441
        }
hgs
parents: 32
diff changeset
   442
    }
hgs
parents: 32
diff changeset
   443
hgs
parents: 32
diff changeset
   444
    content.insert(PrimaryText, normalState);
hgs
parents: 32
diff changeset
   445
    content.insert(SecondaryText, normalStateSecondary);
hgs
parents: 32
diff changeset
   446
    content.insert(TextTypeCount + Pressed, pressedState);
hgs
parents: 32
diff changeset
   447
    content.insert(StateCount + SecondaryText, pressedStateSecondary);
hgs
parents: 32
diff changeset
   448
}
hgs
parents: 32
diff changeset
   449
hgs
parents: 32
diff changeset
   450
void DialpadKeypad::createTextLayouts(
hgs
parents: 32
diff changeset
   451
    const QSizeF &size, const QList<QString> &content)
hgs
parents: 32
diff changeset
   452
{
hgs
parents: 32
diff changeset
   453
    // clear old layouts
hgs
parents: 32
diff changeset
   454
    qDeleteAll(mTextLayouts);
hgs
parents: 32
diff changeset
   455
    mTextLayouts.clear();
hgs
parents: 32
diff changeset
   456
hgs
parents: 32
diff changeset
   457
    if (content.count()==2) {
hgs
parents: 32
diff changeset
   458
        // line width is measured only when all buttons are in normal state
hgs
parents: 32
diff changeset
   459
        mMaxPrimaryLineWidth = 0;
hgs
parents: 32
diff changeset
   460
    }
hgs
parents: 32
diff changeset
   461
hgs
parents: 32
diff changeset
   462
    QFont primaryfFont = HbFontSpec(HbFontSpec::Primary).font();
hgs
parents: 32
diff changeset
   463
    primaryfFont.setPixelSize(DialpadPrimaryTextSize * mUnit);
hgs
parents: 32
diff changeset
   464
hgs
parents: 32
diff changeset
   465
    QFont secondaryFont = HbFontSpec(HbFontSpec::Secondary).font();
hgs
parents: 32
diff changeset
   466
    secondaryFont.setPixelSize(DialpadSecondaryTextSize * mUnit);
hgs
parents: 32
diff changeset
   467
hgs
parents: 32
diff changeset
   468
    for (int i=0; i < (StateCount*TextTypeCount); i++ ) {
hgs
parents: 32
diff changeset
   469
        QString text = content.at(i);
hgs
parents: 32
diff changeset
   470
hgs
parents: 32
diff changeset
   471
        if (!text.isNull()) {
hgs
parents: 32
diff changeset
   472
            QTextLayout* textLayout;
hgs
parents: 32
diff changeset
   473
            int type;
hgs
parents: 32
diff changeset
   474
hgs
parents: 32
diff changeset
   475
            if (i%TextTypeCount) {
hgs
parents: 32
diff changeset
   476
                textLayout = new QTextLayout(text,secondaryFont);
hgs
parents: 32
diff changeset
   477
                type = SecondaryText;
hgs
parents: 32
diff changeset
   478
            } else {
hgs
parents: 32
diff changeset
   479
                textLayout = new QTextLayout(text,primaryfFont);
hgs
parents: 32
diff changeset
   480
                type = PrimaryText;
hgs
parents: 32
diff changeset
   481
            }
hgs
parents: 32
diff changeset
   482
hgs
parents: 32
diff changeset
   483
            mTextLayouts.append(textLayout);
hgs
parents: 32
diff changeset
   484
hgs
parents: 32
diff changeset
   485
            textLayout->beginLayout();
hgs
parents: 32
diff changeset
   486
hgs
parents: 32
diff changeset
   487
            int state = (i>=TextTypeCount) ? Pressed : Normal;
hgs
parents: 32
diff changeset
   488
hgs
parents: 32
diff changeset
   489
            layoutTextLines(size,*textLayout,state,type);
hgs
parents: 32
diff changeset
   490
hgs
parents: 32
diff changeset
   491
            textLayout->endLayout();
hgs
parents: 32
diff changeset
   492
hgs
parents: 32
diff changeset
   493
            textLayout->setCacheEnabled(true);
hgs
parents: 32
diff changeset
   494
        }
hgs
parents: 32
diff changeset
   495
    }
hgs
parents: 32
diff changeset
   496
}
hgs
parents: 32
diff changeset
   497
hgs
parents: 32
diff changeset
   498
void DialpadKeypad::layoutTextLines(
hgs
parents: 32
diff changeset
   499
    const QSizeF &size,
hgs
parents: 32
diff changeset
   500
    QTextLayout &textLayout,
hgs
parents: 32
diff changeset
   501
    int state,
hgs
parents: 32
diff changeset
   502
    int type)
hgs
parents: 32
diff changeset
   503
{
hgs
parents: 32
diff changeset
   504
    QFontMetricsF fontMetrics(textLayout.font());
hgs
parents: 32
diff changeset
   505
    qreal textHeight = fontMetrics.height();
hgs
parents: 32
diff changeset
   506
hgs
parents: 32
diff changeset
   507
    qreal cellWidth = size.width() / gridSize().width();
hgs
parents: 32
diff changeset
   508
    qreal cellHeight = size.height() / gridSize().height();
hgs
parents: 32
diff changeset
   509
    qreal maxLineWidth = 0;
hgs
parents: 32
diff changeset
   510
hgs
parents: 32
diff changeset
   511
    for (int j = 0; j < (DialpadRowCount*DialpadColumnCount); j++) {
hgs
parents: 32
diff changeset
   512
        DialpadNumericButton *item = button(j);
hgs
parents: 32
diff changeset
   513
hgs
parents: 32
diff changeset
   514
        if ((type==PrimaryText && item->text().isNull()) ||
hgs
parents: 32
diff changeset
   515
            (type==SecondaryText && item->secondaryText().isNull())) {
hgs
parents: 32
diff changeset
   516
            continue; // no text for this button -> next button
hgs
parents: 32
diff changeset
   517
        }
hgs
parents: 32
diff changeset
   518
hgs
parents: 32
diff changeset
   519
        if ( ( state==Normal &&
hgs
parents: 32
diff changeset
   520
               item->state()==HbInputButton::ButtonStateReleased ) ||
hgs
parents: 32
diff changeset
   521
             ( state==Pressed &&
hgs
parents: 32
diff changeset
   522
               item->state()==HbInputButton::ButtonStatePressed ) ) {
hgs
parents: 32
diff changeset
   523
hgs
parents: 32
diff changeset
   524
            QTextLine line = textLayout.createLine();
hgs
parents: 32
diff changeset
   525
hgs
parents: 32
diff changeset
   526
            qreal textPositionX = 0;
hgs
parents: 32
diff changeset
   527
            qreal textPositionY = 0;
hgs
parents: 32
diff changeset
   528
hgs
parents: 32
diff changeset
   529
            if (line.isValid()) {
hgs
parents: 32
diff changeset
   530
                line.setNumColumns(item->text().length());
hgs
parents: 32
diff changeset
   531
                // layout text line
hgs
parents: 32
diff changeset
   532
                if (type==SecondaryText) {
hgs
parents: 32
diff changeset
   533
                    if (j==9) {
hgs
parents: 32
diff changeset
   534
                        // + is centered to button
hgs
parents: 32
diff changeset
   535
                        qreal lineWidth = fontMetrics.width(item->text());
hgs
parents: 32
diff changeset
   536
                        textPositionX = (item->position().x() * cellWidth) +
hgs
parents: 32
diff changeset
   537
                                        (cellWidth / 2) -
hgs
parents: 32
diff changeset
   538
                                        (lineWidth / 2);
hgs
parents: 32
diff changeset
   539
                        textPositionY = (item->position().y() +
hgs
parents: 32
diff changeset
   540
                                        (0.5 * item->size().height())) *
hgs
parents: 32
diff changeset
   541
                                        cellHeight - (0.5 * textHeight);
hgs
parents: 32
diff changeset
   542
hgs
parents: 32
diff changeset
   543
                    } else {
hgs
parents: 32
diff changeset
   544
                        textPositionX = (item->position().x() * cellWidth) +
hgs
parents: 32
diff changeset
   545
                                        (DialpadPrimaryTextLeftMargin * mUnit) +
hgs
parents: 32
diff changeset
   546
                                        mMaxPrimaryLineWidth +
hgs
parents: 32
diff changeset
   547
                                        (DialpadPrimarySecondaryMargin * mUnit)
hgs
parents: 32
diff changeset
   548
                                        + buttonBorderSize();
hgs
parents: 32
diff changeset
   549
                        textPositionY = (item->position().y() +
hgs
parents: 32
diff changeset
   550
                                        (0.5 * item->size().height())) *
hgs
parents: 32
diff changeset
   551
                                        cellHeight - (0.5 * textHeight);
hgs
parents: 32
diff changeset
   552
                    }                    
hgs
parents: 32
diff changeset
   553
                } else {
hgs
parents: 32
diff changeset
   554
                    textPositionX = (item->position().x() * cellWidth) +
hgs
parents: 32
diff changeset
   555
                                    (DialpadPrimaryTextLeftMargin * mUnit)
hgs
parents: 32
diff changeset
   556
                                    + buttonBorderSize();
hgs
parents: 32
diff changeset
   557
                    textPositionY = (item->position().y() +
hgs
parents: 32
diff changeset
   558
                                    (0.5 * item->size().height())) *
hgs
parents: 32
diff changeset
   559
                                    cellHeight - (0.5 * textHeight);
hgs
parents: 32
diff changeset
   560
hgs
parents: 32
diff changeset
   561
                    // store line width, for drawing secondary text
hgs
parents: 32
diff changeset
   562
                    qreal lineWidth = fontMetrics.width(item->text());
hgs
parents: 32
diff changeset
   563
                    if (mMaxPrimaryLineWidth == 0 && (j>0 && j<10) &&
hgs
parents: 32
diff changeset
   564
                        lineWidth > maxLineWidth) {
hgs
parents: 32
diff changeset
   565
                        maxLineWidth = lineWidth;
hgs
parents: 32
diff changeset
   566
                    }
hgs
parents: 32
diff changeset
   567
                }
hgs
parents: 32
diff changeset
   568
            }
hgs
parents: 32
diff changeset
   569
hgs
parents: 32
diff changeset
   570
            line.setPosition(QPointF(textPositionX, textPositionY));
hgs
parents: 32
diff changeset
   571
        }
hgs
parents: 32
diff changeset
   572
    }
hgs
parents: 32
diff changeset
   573
hgs
parents: 32
diff changeset
   574
    mMaxPrimaryLineWidth = maxLineWidth;
hgs
parents: 32
diff changeset
   575
}