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