telutils/dialpad/src/dialpadkeypad.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     1 /*!
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Dialpad keypad
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QLocale>
       
    19 #include <QSignalMapper>
       
    20 
       
    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>
       
    28 #include <hbcolorscheme.h>
       
    29 #include <hblineedit.h>
       
    30 #include <hbfontspec.h>
       
    31 #include <hbevent.h>
       
    32 
       
    33 #include "dialpadnumericbutton.h"
       
    34 #include "dialpadkeypad.h"
       
    35 #include "dialpadbutton.h"
       
    36 #include "dialpadinputfield.h"
       
    37 
       
    38 static const int DialpadRowCount = 4;
       
    39 static const int DialpadColumnCount = 3;
       
    40 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 
       
    58 DialpadKeypad::DialpadKeypad(
       
    59     const HbMainWindow& mainWindow,
       
    60     DialpadInputField& inputField,
       
    61     QGraphicsItem* parent) :
       
    62     HbInputButtonGroup(parent),
       
    63     mMainWindow(mainWindow),
       
    64     mInputField(inputField),
       
    65     mMaxPrimaryLineWidth(0)
       
    66 {
       
    67     setObjectName("keypad");
       
    68 
       
    69     // create clicked signal mapper
       
    70     mKeyClickedSignalMapper = new QSignalMapper(this);
       
    71     connect(mKeyClickedSignalMapper,SIGNAL(mapped(int)),
       
    72             SLOT(handleKeyClicked(int)));
       
    73 
       
    74     // connect backspace signals
       
    75     connect(&mInputField.backspaceButton(),SIGNAL(clicked()),
       
    76             mKeyClickedSignalMapper,SLOT(map()));
       
    77     mKeyClickedSignalMapper->setMapping(&mInputField.backspaceButton(),
       
    78                                         Qt::Key_Backspace);
       
    79 
       
    80     // create keypad
       
    81     setGridSize(QSize(DialpadColumnCount, DialpadRowCount));
       
    82     setButtonBorderSize(0);    
       
    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);
       
   112     mCallButton->setIcon(HbIcon(handsetIcon));
       
   113     QString buttonName;
       
   114     buttonName.setNum(Qt::Key_Yes);
       
   115     mCallButton->setObjectName(buttonName);
       
   116     connect(mCallButton,SIGNAL(clicked()),
       
   117             mKeyClickedSignalMapper,SLOT(map()));
       
   118     connect(mCallButton,SIGNAL(longPress(QPointF)),
       
   119             mKeyClickedSignalMapper,SLOT(map()));
       
   120     mKeyClickedSignalMapper->setMapping(mCallButton,
       
   121                                         Qt::Key_Yes);
       
   122 
       
   123     // set button texts
       
   124     setButtonTexts();
       
   125     // set button icons
       
   126     button(0)->setIcon(HbIcon(vmbxIcon));
       
   127 
       
   128     // update button texts when input language is changed
       
   129     connect(HbInputSettingProxy::instance(),
       
   130             SIGNAL(globalInputLanguageChanged(HbInputLanguage)),
       
   131             this,SLOT(setButtonTexts()));
       
   132 
       
   133     updateColorArray();
       
   134 
       
   135     mUnit = HbDeviceProfile::profile(this).unitValue();
       
   136 }
       
   137 
       
   138 DialpadKeypad::~DialpadKeypad()
       
   139 {
       
   140 }
       
   141 
       
   142 void DialpadKeypad::setButtonTexts()
       
   143 {
       
   144     HbInputLanguage inputLanguage =
       
   145         HbInputSettingProxy::instance()->globalInputLanguage();
       
   146     const HbKeymap *keymap =
       
   147         HbKeymapFactory::instance()->keymap(inputLanguage.language());
       
   148 
       
   149     mGeneratedChar.clear();
       
   150 
       
   151     if (keymap) {
       
   152         int buttonCount = (DialpadRowCount*DialpadColumnCount);
       
   153         for (int i = 0; i < buttonCount; i++) {
       
   154             int keyCode = DialpadKeyCodeTable[i];
       
   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 }
       
   211 
       
   212 void DialpadKeypad::handleKeyClicked(int key)
       
   213 {
       
   214     // concerns only yes and backspace keys
       
   215     postKeyEvent(QEvent::KeyPress, key);
       
   216     postKeyEvent(QEvent::KeyRelease, key);
       
   217 }
       
   218 
       
   219 void DialpadKeypad::postKeyEvent(QEvent::Type type, int key)
       
   220 {
       
   221     // send simulated key to application
       
   222     QKeyEvent *keyEvent = new QKeyEvent(type, key, Qt::NoModifier);
       
   223     HbApplication::postEvent(const_cast<HbMainWindow*>(&mMainWindow),keyEvent);
       
   224 }
       
   225 
       
   226 void DialpadKeypad::sendKeyEventToEditor(QEvent::Type type, int key)
       
   227 {
       
   228     // send key event to editor
       
   229     QKeyEvent keyEvent(type, key, Qt::NoModifier, mGeneratedChar.value(key));
       
   230     HbApplication::sendEvent(&mInputField.editor(), &keyEvent);
       
   231 }
       
   232 
       
   233 void DialpadKeypad::sendKeyPressEvent(const QKeyEvent& event)
       
   234 {
       
   235     updateButtonLabels();
       
   236     mPressedNumericKey = event.key();
       
   237     postKeyEvent(QEvent::KeyPress, event.key());
       
   238 }
       
   239 
       
   240 void DialpadKeypad::sendKeyReleaseEvent(const QKeyEvent& event)
       
   241 {
       
   242     updateButtonLabels();
       
   243 
       
   244     if (mPressedNumericKey) {
       
   245         // short press, update editor here
       
   246         sendKeyEventToEditor(QEvent::KeyPress, event.key());
       
   247     }
       
   248 
       
   249     postKeyEvent(QEvent::KeyRelease, event.key());    
       
   250 }
       
   251 
       
   252 void DialpadKeypad::sendLongPressEvent(const QKeyEvent& event)
       
   253 {
       
   254     sendKeyEventToEditor(QEvent::KeyPress, event.key());
       
   255     mPressedNumericKey = 0;
       
   256 }
       
   257 
       
   258 void DialpadKeypad::handleKeyChangeEvent(
       
   259     const QKeyEvent& releaseEvent,
       
   260     const QKeyEvent& pressEvent)
       
   261 {
       
   262     Q_UNUSED(pressEvent)
       
   263 
       
   264     postKeyEvent(QEvent::KeyRelease, releaseEvent.key());
       
   265     cancelButtonPress();
       
   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 }
       
   383 
       
   384 void DialpadKeypad::setGeometry(const QRectF &rect)
       
   385 {
       
   386     HbInputButtonGroup::setGeometry(rect);
       
   387     updateTextLayouts(rect.size());
       
   388 }
       
   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 }