src/hbinput/inputwidgets/hbinputbuttongroup.cpp
changeset 7 923ff622b8b9
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
   156 
   156 
   157         if (i < mButtonDrawers.count()) {
   157         if (i < mButtonDrawers.count()) {
   158             if (drawer != mButtonDrawers.at(i)) {
   158             if (drawer != mButtonDrawers.at(i)) {
   159                 HbFrameDrawerPool::release(mButtonDrawers.at(i));
   159                 HbFrameDrawerPool::release(mButtonDrawers.at(i));
   160                 mButtonDrawers.replace(i, drawer);
   160                 mButtonDrawers.replace(i, drawer);
       
   161             } else {
       
   162                 HbFrameDrawerPool::release(drawer);
   161             }
   163             }
   162         } else {
   164         } else {
   163             mButtonDrawers.append(drawer);
   165             mButtonDrawers.append(drawer);
   164         }
   166         }
   165 
   167 
   311 
   313 
   312 void HbInputButtonGroupPrivate::showButtonPreview(HbInputButton *const item)
   314 void HbInputButtonGroupPrivate::showButtonPreview(HbInputButton *const item)
   313 {
   315 {
   314     Q_Q(HbInputButtonGroup);
   316     Q_Q(HbInputButtonGroup);
   315 
   317 
       
   318     // Button preview should be shown only for non-function buttons if preview
       
   319     // is enabled for this button group. Space key is handled as a special case
       
   320     // and no preview will be shown for that although it is not function button.
   316     int index = mButtonData.indexOf(item);
   321     int index = mButtonData.indexOf(item);
   317     if (mButtonPreviewEnabled && item->type() != HbInputButton::ButtonTypeFunction &&
   322     if (mButtonPreviewEnabled && !mButtonPreview.contains(index) &&
   318         !mButtonPreview.contains(index)) {
   323         item->type() != HbInputButton::ButtonTypeFunction &&
       
   324         item->keyCode() != HbInputButton::ButtonKeyCodeSpace) {
       
   325 
   319         HbInputButtonGroup *group = new HbInputButtonGroup(QSize(1, 1));
   326         HbInputButtonGroup *group = new HbInputButtonGroup(QSize(1, 1));
   320         mButtonPreview.insert(index, group);
   327         mButtonPreview.insert(index, group);
   321 
   328 
       
   329         // Create preview button and add it to the new button group
   322         QList<HbInputButton *> buttons;
   330         QList<HbInputButton *> buttons;
   323         HbInputButton *previewItem = 0;
   331         HbInputButton *previewItem = 0;
   324         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
   332         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
   325             int keyCode = -1;
   333             int keyCode = -1;
   326             if (!item->text(HbInputButton::ButtonTextIndexPrimary).isEmpty()) {
   334             if (!item->text(HbInputButton::ButtonTextIndexPrimary).isEmpty()) {
   337         group->setButtons(buttons);
   345         group->setButtons(buttons);
   338 
   346 
   339         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   347         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   340         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   348         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   341 
   349 
       
   350         // Calculate text size
   342         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   351         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   343         font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeLabel)));
   352         font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeLabel)));
   344         QFontMetricsF fontMetrics(font);
   353         QFontMetricsF fontMetrics(font);
   345         qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexPrimary));
   354         qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexPrimary));
   346 
   355 
       
   356         // Calculate preview size
   347         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue;
   357         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue;
   348         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
   358         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
   349             width = item->boundingRect().width();
   359             width = item->boundingRect().width();
   350         } else if (width < HbPreviewWidthInUnits * mUnitValue) {
   360         } else if (width < HbPreviewWidthInUnits * mUnitValue) {
   351             width = HbPreviewWidthInUnits * mUnitValue;
   361             width = HbPreviewWidthInUnits * mUnitValue;
   381 
   391 
   382 void HbInputButtonGroupPrivate::showCharacterSelectionPreview(HbInputButton *const item)
   392 void HbInputButtonGroupPrivate::showCharacterSelectionPreview(HbInputButton *const item)
   383 {
   393 {
   384     Q_Q(HbInputButtonGroup);
   394     Q_Q(HbInputButtonGroup);
   385 
   395 
       
   396     // Character preview should be shown only for non-function buttons which contains more
       
   397     // than one character if preview is enabled for this button group
   386     if (mCharacterSelectionPreviewEnabled && item->type() != HbInputButton::ButtonTypeFunction &&
   398     if (mCharacterSelectionPreviewEnabled && item->type() != HbInputButton::ButtonTypeFunction &&
   387         item->mappedCharacters().count() > 1) {
   399         item->mappedCharacters().count() > 1) {
   388 
   400 
   389         HbWidgetFeedback::triggered(q, Hb::InstantLongPressed);
   401         if (item->type() == HbInputButton::ButtonTypeFunction) {
       
   402             HbWidgetFeedback::triggered(q, Hb::InstantLongPressed, Hb::ModifierInputFunctionButton);
       
   403         }
       
   404         else {
       
   405             HbWidgetFeedback::triggered(q, Hb::InstantLongPressed);
       
   406         }
   390 
   407 
   391         mProbabilities.clear();
   408         mProbabilities.clear();
   392         q->cancelButtonPress();
   409         q->cancelButtonPress();
   393 
   410 
       
   411         // Create and initialize character preview
   394         if (!mCharacterSelectionPreview) {
   412         if (!mCharacterSelectionPreview) {
   395             mCharacterSelectionPreview = new HbDialog();
   413             mCharacterSelectionPreview = new HbDialog();
   396             HbInputRegionCollector::instance()->attach(mCharacterSelectionPreview);
   414             HbInputRegionCollector::instance()->attach(mCharacterSelectionPreview);
   397             mCharacterSelectionPreview->setModal(true);
   415             mCharacterSelectionPreview->setModal(true);
   398             mCharacterSelectionPreview->setBackgroundFaded(false);
   416             mCharacterSelectionPreview->setBackgroundFaded(false);
   412         QObject::connect(group, SIGNAL(pressedButtonChanged(const QKeyEvent &, const QKeyEvent &)), q, SLOT(emitPressedButtonChanged(const QKeyEvent &, const QKeyEvent &)));
   430         QObject::connect(group, SIGNAL(pressedButtonChanged(const QKeyEvent &, const QKeyEvent &)), q, SLOT(emitPressedButtonChanged(const QKeyEvent &, const QKeyEvent &)));
   413 
   431 
   414         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   432         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   415         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   433         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   416 
   434 
       
   435         // Calculate text size
   417         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   436         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   418         font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeLabel)));
   437         font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeLabel)));
   419         QFontMetricsF fontMetrics(font);
   438         QFontMetricsF fontMetrics(font);
   420         qreal textWidth = fontMetrics.width(item->mappedCharacters());
   439         qreal textWidth = fontMetrics.width(item->mappedCharacters());
   421 
   440 
   422         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue * item->mappedCharacters().count();
   441         // Calculate preview size
       
   442         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue * (item->mappedCharacters().count() - 1);
   423         qreal height = HbPreviewHeightInUnits * mUnitValue;
   443         qreal height = HbPreviewHeightInUnits * mUnitValue;
   424         qreal x = q->scenePos().x() + (item->position().x() + 0.5 * item->size().width()) * cellWidth;
   444         qreal x = q->scenePos().x() + (item->position().x() + 0.5 * item->size().width()) * cellWidth;
   425         qreal y = q->scenePos().y() + item->position().y() * cellHeight;
   445         qreal y = q->scenePos().y() + item->position().y() * cellHeight;
   426 
   446 
       
   447         // Create character preview button and add it to the created button group
   427         QList<HbInputButton *> buttons;
   448         QList<HbInputButton *> buttons;
   428         for (int i = 0; i < item->mappedCharacters().count(); ++i) {
   449         for (int i = 0; i < item->mappedCharacters().count(); ++i) {
   429             HbInputButton *previewItem = new HbInputButton(item->keyCode(), QPoint(i, 0));
   450             HbInputButton *previewItem = new HbInputButton(item->keyCode(), QPoint(i, 0));
   430             previewItem->setType(HbInputButton::ButtonTypeLabel);
   451             previewItem->setType(HbInputButton::ButtonTypeLabel);
   431             previewItem->setText(item->mappedCharacters().at(i), HbInputButton::ButtonTextIndexPrimary);
   452             previewItem->setText(item->mappedCharacters().at(i), HbInputButton::ButtonTextIndexPrimary);
   432             buttons.append(previewItem);
   453             buttons.append(previewItem);
   433         }
   454         }
   434         group->setButtons(buttons);
   455         group->setButtons(buttons);
   435         group->setButtonBorderSize(0);
   456         group->setButtonBorderSize(0);
   436 
   457 
   437         mCharacterSelectionPreview->setPreferredSize(QSizeF(width, height));
   458         group->setPreferredSize(QSizeF(width, height));
   438         mCharacterSelectionPreview->setPreferredPos(QPointF(x, y), HbPopup::BottomEdgeCenter);
   459         mCharacterSelectionPreview->setPreferredPos(QPointF(x, y), HbPopup::BottomEdgeCenter);
   439         mCharacterSelectionPreview->setContentWidget(group);
   460         mCharacterSelectionPreview->setContentWidget(group);
   440 
   461 
   441         HbFrameDrawer *drawer = HbFrameDrawerPool::get(HbPreviewBackground, HbFrameDrawer::ThreePiecesHorizontal, QSizeF(width, height));
   462         HbFrameDrawer *drawer = HbFrameDrawerPool::get(HbPreviewBackground, HbFrameDrawer::ThreePiecesHorizontal, QSizeF(width, height));
   442         drawer->setFillWholeRect(true);
   463         drawer->setFillWholeRect(true);
   448 
   469 
   449 void HbInputButtonGroupPrivate::pressEvent(const QPointF &position, bool emitSignal)
   470 void HbInputButtonGroupPrivate::pressEvent(const QPointF &position, bool emitSignal)
   450 {
   471 {
   451     Q_Q(HbInputButtonGroup);
   472     Q_Q(HbInputButtonGroup);
   452 
   473 
       
   474     // Ignore press events outside button group
   453     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   475     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   454           position.y() >= 0 && position.y() < q->boundingRect().height())) {
   476           position.y() >= 0 && position.y() < q->boundingRect().height())) {
   455         return;
   477         return;
   456     }
   478     }
   457 
   479 
   469             if (item->state() == HbInputButton::ButtonStateDisabled) {
   491             if (item->state() == HbInputButton::ButtonStateDisabled) {
   470                 startLongPress(index);
   492                 startLongPress(index);
   471             }
   493             }
   472             return;
   494             return;
   473         }
   495         }
   474 
   496         
   475         HbWidgetFeedback::triggered(q, Hb::InstantPressed);
   497         if (item->type() == HbInputButton::ButtonTypeFunction) {
       
   498             HbWidgetFeedback::triggered(q, Hb::InstantPressed, Hb::ModifierInputFunctionButton);
       
   499         }
       
   500         else {
       
   501             HbWidgetFeedback::triggered(q, Hb::InstantPressed);        
       
   502         }
   476 
   503 
   477         item->setState(HbInputButton::ButtonStatePressed);
   504         item->setState(HbInputButton::ButtonStatePressed);
   478         updateGraphics(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   505         updateGraphics(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   479         updateTextLayouts(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   506         updateTextLayouts(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   480         q->update();
   507         q->update();
   498 
   525 
   499 void HbInputButtonGroupPrivate::doublePressEvent(const QPointF &position, bool emitSignal)
   526 void HbInputButtonGroupPrivate::doublePressEvent(const QPointF &position, bool emitSignal)
   500 {
   527 {
   501     Q_Q(HbInputButtonGroup);
   528     Q_Q(HbInputButtonGroup);
   502 
   529 
       
   530     // Ignore double press events outside button group
   503     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   531     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   504           position.y() >= 0 && position.y() < q->boundingRect().height())) {
   532           position.y() >= 0 && position.y() < q->boundingRect().height())) {
   505         return;
   533         return;
   506     }
   534     }
   507 
   535 
   520                 startLongPress(index);
   548                 startLongPress(index);
   521             }
   549             }
   522             return;
   550             return;
   523         }
   551         }
   524 
   552 
   525         HbWidgetFeedback::triggered(q, Hb::InstantPressed);
   553         if (item->type() == HbInputButton::ButtonTypeFunction) {
       
   554             HbWidgetFeedback::triggered(q, Hb::InstantPressed, Hb::ModifierInputFunctionButton);
       
   555         }
       
   556         else {
       
   557             HbWidgetFeedback::triggered(q, Hb::InstantPressed);        
       
   558         }
   526 
   559 
   527         item->setState(HbInputButton::ButtonStatePressed);
   560         item->setState(HbInputButton::ButtonStatePressed);
   528         updateGraphics(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   561         updateGraphics(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   529         updateTextLayouts(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   562         updateTextLayouts(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   530         q->update();
   563         q->update();
   556     int newRow = static_cast<int>(newPosition.y() / (q->boundingRect().height() / mGridSize.height()));
   589     int newRow = static_cast<int>(newPosition.y() / (q->boundingRect().height() / mGridSize.height()));
   557 
   590 
   558     int oldIndex = mButtonGridPositions.value(QPair<int, int>(oldColumn, oldRow), -1);
   591     int oldIndex = mButtonGridPositions.value(QPair<int, int>(oldColumn, oldRow), -1);
   559     int newIndex = mButtonGridPositions.value(QPair<int, int>(newColumn, newRow), -1);
   592     int newIndex = mButtonGridPositions.value(QPair<int, int>(newColumn, newRow), -1);
   560 
   593 
       
   594     // Check if movement happens inside button group
   561     if (newPosition.x() >= 0 && newPosition.x() < q->boundingRect().width() &&
   595     if (newPosition.x() >= 0 && newPosition.x() < q->boundingRect().width() &&
   562         newPosition.y() >= 0 && newPosition.y() < q->boundingRect().height() &&
   596         newPosition.y() >= 0 && newPosition.y() < q->boundingRect().height() &&
   563         oldPosition.x() >= 0 && oldPosition.x() < q->boundingRect().width() &&
   597         oldPosition.x() >= 0 && oldPosition.x() < q->boundingRect().width() &&
   564         oldPosition.y() >= 0 && oldPosition.y() < q->boundingRect().height()) {
   598         oldPosition.y() >= 0 && oldPosition.y() < q->boundingRect().height()) {
   565 
   599 
   581             QKeyEvent pressEvent(QEvent::KeyPress, newItem->keyCode(), Qt::NoModifier, text);
   615             QKeyEvent pressEvent(QEvent::KeyPress, newItem->keyCode(), Qt::NoModifier, text);
   582 
   616 
   583             q->emitPressedButtonChanged(releaseEvent, pressEvent);
   617             q->emitPressedButtonChanged(releaseEvent, pressEvent);
   584         }
   618         }
   585     } else {
   619     } else {
       
   620         // Move event came from outside button group so create new release and press events
       
   621         // for old and new position. If one of the positions is inside button group
       
   622         // a new event will get generated.
   586         releaseEvent(oldPosition, false);
   623         releaseEvent(oldPosition, false);
   587         pressEvent(newPosition);
   624         pressEvent(newPosition);
   588     }
   625     }
   589 }
   626 }
   590 
   627 
   591 void HbInputButtonGroupPrivate::releaseEvent(const QPointF &position, bool emitSignal)
   628 void HbInputButtonGroupPrivate::releaseEvent(const QPointF &position, bool emitSignal)
   592 {
   629 {
   593     Q_Q(HbInputButtonGroup);
   630     Q_Q(HbInputButtonGroup);
   594 
   631 
       
   632     // Ignore release events outside button group
   595     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   633     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   596           position.y() >= 0 && position.y() < q->boundingRect().height())) {
   634           position.y() >= 0 && position.y() < q->boundingRect().height())) {
   597         return;
   635         return;
   598     }
   636     }
   599 
   637 
   609 
   647 
   610         if (item->state() != HbInputButton::ButtonStatePressed) {
   648         if (item->state() != HbInputButton::ButtonStatePressed) {
   611             return;
   649             return;
   612         }
   650         }
   613 
   651 
   614         HbWidgetFeedback::triggered(q, Hb::InstantReleased);
   652         if (item->type() == HbInputButton::ButtonTypeFunction) {
       
   653             HbWidgetFeedback::triggered(q, Hb::InstantReleased, Hb::ModifierInputFunctionButton);
       
   654         }
       
   655         else {
       
   656             HbWidgetFeedback::triggered(q, Hb::InstantReleased);
       
   657         }
   615 
   658 
   616         item->setState(HbInputButton::ButtonStateReleased);
   659         item->setState(HbInputButton::ButtonStateReleased);
   617         updateGraphics(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   660         updateGraphics(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   618         updateTextLayouts(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   661         updateTextLayouts(QSizeF(q->boundingRect().width(), q->boundingRect().height()));
   619         q->update();
   662         q->update();
   623         }
   666         }
   624 
   667 
   625         hideButtonPreview(item);
   668         hideButtonPreview(item);
   626 
   669 
   627         if (emitSignal) {
   670         if (emitSignal) {
   628             HbWidgetFeedback::triggered(q, Hb::InstantClicked);
   671             if (item->type() == HbInputButton::ButtonTypeFunction) {
       
   672                 HbWidgetFeedback::triggered(q, Hb::InstantClicked, Hb::ModifierInputFunctionButton);
       
   673             }
       
   674             else {
       
   675                 HbWidgetFeedback::triggered(q, Hb::InstantClicked);
       
   676             }
   629             int actionIndex = item->keyCode() - HbInputButton::ButtonKeyCodeCustom;
   677             int actionIndex = item->keyCode() - HbInputButton::ButtonKeyCodeCustom;
   630             if (actionIndex >= 0 && actionIndex < mCustomActions.count()) {
   678             if (actionIndex >= 0 && actionIndex < mCustomActions.count()) {
   631                 emit q->aboutToActivateCustomAction(mCustomActions.at(actionIndex));
   679                 emit q->aboutToActivateCustomAction(mCustomActions.at(actionIndex));
   632                 mCustomActions.at(actionIndex)->activate(QAction::Trigger);
   680                 mCustomActions.at(actionIndex)->activate(QAction::Trigger);
   633             } else {
   681             } else {
   654     mLongPressTimers.removeAt(0);
   702     mLongPressTimers.removeAt(0);
   655 
   703 
   656     if (index >= 0 && index < mButtonData.count()) {
   704     if (index >= 0 && index < mButtonData.count()) {
   657         HbInputButton *item = mButtonData.at(index);
   705         HbInputButton *item = mButtonData.at(index);
   658 
   706 
       
   707         // Handle autorepeating buttons
   659         if (item->autoRepeat() &&
   708         if (item->autoRepeat() &&
   660             (item->state() == HbInputButton::ButtonStatePressed ||
   709             (item->state() == HbInputButton::ButtonStatePressed ||
   661              item->state() == HbInputButton::ButtonStateLatched)) {
   710              item->state() == HbInputButton::ButtonStateLatched)) {
   662             mLongPressButtons.append(index);
   711             mLongPressButtons.append(index);
   663             mLongPressTimers.append(timer);
   712             mLongPressTimers.append(timer);
   664             timer->start(HbAutoRepeatTimeout);
   713             timer->start(HbAutoRepeatTimeout);
   665 
   714 
   666             HbWidgetFeedback::triggered(q, Hb::InstantKeyRepeated);
   715             if (item->type() == HbInputButton::ButtonTypeFunction) {
       
   716                 HbWidgetFeedback::triggered(q, Hb::InstantKeyRepeated, Hb::ModifierInputFunctionButton);
       
   717             }
       
   718             else {
       
   719                 HbWidgetFeedback::triggered(q, Hb::InstantKeyRepeated);
       
   720             }
   667 
   721 
   668             QString text;
   722             QString text;
   669             if (item->type() == HbInputButton::ButtonTypeLabel) {
   723             if (item->type() == HbInputButton::ButtonTypeLabel) {
   670                 text = item->text(HbInputButton::ButtonTextIndexPrimary);
   724                 text = item->text(HbInputButton::ButtonTextIndexPrimary);
   671             }
   725             }
   672             QKeyEvent releaeEvent(QEvent::KeyRelease, item->keyCode(), Qt::NoModifier, text, true);
   726             int keycode = item->keyCode();
       
   727             QKeyEvent releaeEvent(QEvent::KeyRelease, keycode, Qt::NoModifier, text, true);
   673             q->emitButtonReleased(releaeEvent);
   728             q->emitButtonReleased(releaeEvent);
   674             QKeyEvent pressEvent(QEvent::KeyPress, item->keyCode(), Qt::NoModifier, text, true);
   729             QKeyEvent pressEvent(QEvent::KeyPress, keycode, Qt::NoModifier, text, true);
   675             q->emitButtonPressed(pressEvent);
   730             q->emitButtonPressed(pressEvent);
   676         } else {
   731         } else {
   677             if (mCharacterSelectionPreviewEnabled && item->type() != HbInputButton::ButtonTypeFunction && item->mappedCharacters().count() > 1) {
   732             // Buttons that doesn't support autorepeat can either show character preview
       
   733             // or generate a long press
       
   734             if (mCharacterSelectionPreviewEnabled && item->type() != HbInputButton::ButtonTypeFunction
       
   735                 && item->mappedCharacters().count() > 1) {
   678                 showCharacterSelectionPreview(item);
   736                 showCharacterSelectionPreview(item);
   679             } else {
   737             } else {
   680                 HbWidgetFeedback::triggered(q, Hb::InstantLongPressed);
   738                 if (item->type() == HbInputButton::ButtonTypeFunction) {
   681 
   739                     HbWidgetFeedback::triggered(q, Hb::InstantLongPressed, Hb::ModifierInputFunctionButton);
   682                 delete timer;
   740                 }
       
   741                 else {
       
   742                     HbWidgetFeedback::triggered(q, Hb::InstantLongPressed);
       
   743                 }
   683 
   744 
   684                 QString text;
   745                 QString text;
   685                 if (item->type() == HbInputButton::ButtonTypeLabel) {
   746                 if (item->type() == HbInputButton::ButtonTypeLabel) {
   686                     text = item->text(HbInputButton::ButtonTextIndexPrimary);
   747                     text = item->text(HbInputButton::ButtonTextIndexPrimary);
   687                 }
   748                 }
   688                 QKeyEvent event(QEvent::KeyPress, item->keyCode(), Qt::NoModifier, text, true);
   749                 QKeyEvent event(QEvent::KeyPress, item->keyCode(), Qt::NoModifier, text, true);
   689                 q->emitButtonLongPressed(event);
   750                 q->emitButtonLongPressed(event);
   690             }
   751             }
       
   752             delete timer;
   691         }
   753         }
   692     }
   754     }
   693 }
   755 }
   694 
   756 
   695 void HbInputButtonGroupPrivate::calculateButtonProbabilities(const QPointF &position)
   757 void HbInputButtonGroupPrivate::calculateButtonProbabilities(const QPointF &position)
   702     qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   764     qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   703 
   765 
   704     QRectF touchArea = QRectF(position.x() - 0.5 * cellWidth, position.y() - 0.5 * cellHeight,
   766     QRectF touchArea = QRectF(position.x() - 0.5 * cellWidth, position.y() - 0.5 * cellHeight,
   705                               HbTouchAreaSizeInUnits * mUnitValue, HbTouchAreaSizeInUnits * mUnitValue);
   767                               HbTouchAreaSizeInUnits * mUnitValue, HbTouchAreaSizeInUnits * mUnitValue);
   706 
   768 
       
   769     // Calculate probabilities based on the intersection area of "touch area" and button area
   707     qreal probabilities = 0;
   770     qreal probabilities = 0;
   708     foreach(HbInputButton *button, mButtonData) {
   771     foreach(HbInputButton *button, mButtonData) {
   709         QRectF intersection = button->boundingRect().intersected(touchArea);
   772         QRectF intersection = button->boundingRect().intersected(touchArea);
   710 
   773 
   711         if (intersection.isValid()) {
   774         if (intersection.isValid()) {
   811     mTextLayouts.at(index)->setCacheEnabled(true);
   874     mTextLayouts.at(index)->setCacheEnabled(true);
   812 }
   875 }
   813 
   876 
   814 void HbInputButtonGroupPrivate::createSecondaryTextLayout(int index, const QHash<int, QString> &textContent, const QSizeF &size)
   877 void HbInputButtonGroupPrivate::createSecondaryTextLayout(int index, const QHash<int, QString> &textContent, const QSizeF &size)
   815 {
   878 {
   816     qreal cellWidth = size.width() / mGridSize.width();
       
   817     qreal cellHeight = size.height() / mGridSize.height();
       
   818 
       
   819     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   879     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   820     font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow)));
   880     font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow)));
   821 
   881 
   822     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   882     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   823     QFontMetricsF fontMetrics(font);
   883     QFontMetricsF fontMetrics(font);
   829         int layoutIndex = item->type() * HbInputButton::ButtonStateCount + item->state() + HbTextTypeCount * 2;
   889         int layoutIndex = item->type() * HbInputButton::ButtonStateCount + item->state() + HbTextTypeCount * 2;
   830         if (!mEnabled) {
   890         if (!mEnabled) {
   831             layoutIndex = item->type() * HbInputButton::ButtonStateCount + HbInputButton::ButtonStateDisabled + HbTextTypeCount * 2;
   891             layoutIndex = item->type() * HbInputButton::ButtonStateCount + HbInputButton::ButtonStateDisabled + HbTextTypeCount * 2;
   832         }
   892         }
   833         if (index == layoutIndex) {
   893         if (index == layoutIndex) {
   834             if (!item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow).isEmpty() &&
   894             // Layout secondary text for first row
   835                 item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull()) {
   895             layoutSecondaryText(index, item, fontMetrics, size,
   836                 qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow));
   896                                 HbInputButton::ButtonTextIndexSecondaryFirstRow,
   837                 qreal textHeight = fontMetrics.height();
   897                                 HbInputButton::ButtonIconIndexSecondaryFirstRow,
   838 
   898                                 HbInputButton::ButtonTextIndexSecondarySecondRow,
   839                 QTextLine line = mTextLayouts.at(index)->createLine();
   899                                 HbInputButton::ButtonIconIndexSecondarySecondRow,
   840                 line.setNumColumns(item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow).length());
   900                                 HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow);
   841 
   901                                 
   842                 layoutTextLine(HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   902 
   843             }
   903             // Layout secondary text for second row
   844 
   904             layoutSecondaryText(index, item, fontMetrics, size,
   845             if (!item->text(HbInputButton::ButtonTextIndexSecondarySecondRow).isEmpty() &&
   905                                 HbInputButton::ButtonTextIndexSecondarySecondRow,
   846                 item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull()) {
   906                                 HbInputButton::ButtonIconIndexSecondarySecondRow,
   847                 qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexSecondarySecondRow));
   907                                 HbInputButton::ButtonTextIndexSecondaryFirstRow,
   848                 qreal textHeight = fontMetrics.height();
   908                                 HbInputButton::ButtonIconIndexSecondaryFirstRow,
   849 
   909                                 HbInputButtonGroup::ButtonTextTypeSecondarySecondRow);
   850                 QTextLine line = mTextLayouts.at(index)->createLine();
       
   851                 line.setNumColumns(item->text(HbInputButton::ButtonTextIndexSecondarySecondRow).length());
       
   852 
       
   853                 layoutTextLine(HbInputButtonGroup::ButtonTextTypeSecondarySecondRow, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
       
   854             }
       
   855         }
   910         }
   856     }
   911     }
   857     mTextLayouts.at(index)->endLayout();
   912     mTextLayouts.at(index)->endLayout();
   858     mTextLayouts.at(index)->setCacheEnabled(true);
   913     mTextLayouts.at(index)->setCacheEnabled(true);
   859 }
   914 }
   860 
   915 
       
   916 void HbInputButtonGroupPrivate::layoutSecondaryText(int index, HbInputButton *item, QFontMetricsF &fontMetrics, const QSizeF &size,
       
   917                                                     HbInputButton::HbInputButtonTextIndex firstTextIndex,
       
   918                                                     HbInputButton::HbInputButtonIconIndex firstIconIndex,
       
   919                                                     HbInputButton::HbInputButtonTextIndex secondTextIndex,
       
   920                                                     HbInputButton::HbInputButtonIconIndex secondIconIndex,
       
   921                                                     HbInputButtonGroup::HbInputButtonTextType textType)
       
   922 {
       
   923     qreal cellWidth = size.width() / mGridSize.width();
       
   924     qreal cellHeight = size.height() / mGridSize.height();
       
   925 
       
   926     if (!item->text(firstTextIndex).isEmpty() &&
       
   927         item->icon(firstIconIndex).isNull()) {
       
   928         qreal textWidth = fontMetrics.width(item->text(firstTextIndex));
       
   929         qreal textHeight = fontMetrics.height();
       
   930 
       
   931         QTextLine line = mTextLayouts.at(index)->createLine();
       
   932         line.setNumColumns(item->text(firstTextIndex).length());
       
   933 
       
   934         if (item->text(HbInputButton::ButtonTextIndexPrimary).isEmpty() && 
       
   935             item->icon(HbInputButton::ButtonIconIndexPrimary).isNull() &&
       
   936             item->text(secondTextIndex).isEmpty() && 
       
   937             item->icon(secondIconIndex).isNull()) {
       
   938             layoutTextLine(HbInputButtonGroup::ButtonTextTypeSingle, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
       
   939         } else {
       
   940             layoutTextLine(textType, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
       
   941         }
       
   942     }
       
   943 }
       
   944 
   861 void HbInputButtonGroupPrivate::layoutTextLine(HbInputButtonGroup::HbInputButtonTextType textType, const HbInputButton *button, const QSizeF &cellSize,
   945 void HbInputButtonGroupPrivate::layoutTextLine(HbInputButtonGroup::HbInputButtonTextType textType, const HbInputButton *button, const QSizeF &cellSize,
   862         QTextLine &textLine, const QSizeF &textSize)
   946         QTextLine &textLine, const QSizeF &textSize)
   863 {
   947 {
   864     qreal textPositionX = 0.0;
   948     qreal textPositionX = 0.0;
   865     qreal textPositionY = 0.0;
   949     qreal textPositionY = 0.0;
   866     if (textType == HbInputButtonGroup::ButtonTextTypeSingle ||
   950     
   867         textType == HbInputButtonGroup::ButtonTextTypeLabel) {
   951     switch(textType) {
   868         textPositionX = (button->position().x() + 0.5 * button->size().width()) * cellSize.width() - 0.5 * textSize.width();
   952         case HbInputButtonGroup::ButtonTextTypeSingle:
   869         textPositionY = (button->position().y() + 0.5 * button->size().height()) * cellSize.height() - 0.5 * textSize.height();
   953         case HbInputButtonGroup::ButtonTextTypeLabel:
   870     } else if (textType == HbInputButtonGroup::ButtonTextTypePrimary) {
   954             textPositionX = (button->position().x() + 0.5 * button->size().width()) * cellSize.width() - 0.5 * textSize.width();
   871         textPositionX = button->position().x() * cellSize.width() + HbHorizontalMarginInUnits * mUnitValue + mButtonBorderSize;
   955             textPositionY = (button->position().y() + 0.5 * button->size().height()) * cellSize.height() - 0.5 * textSize.height();
   872         textPositionY = (button->position().y() + 0.5 * button->size().height()) * cellSize.height() - 0.5 * textSize.height();
   956             break;
   873     } else if (textType == HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow) {
   957 
   874         textPositionX = (button->position().x() + button->size().width()) * cellSize.width() -
   958         case HbInputButtonGroup::ButtonTextTypePrimary:
   875                         textSize.width() - HbHorizontalMarginInUnits * mUnitValue - mButtonBorderSize;
   959             textPositionX = button->position().x() * cellSize.width() + HbHorizontalMarginInUnits * mUnitValue + mButtonBorderSize;
   876         textPositionY = (button->position().y() + button->size().height()) * cellSize.height() -
   960             textPositionY = (button->position().y() + 0.5 * button->size().height()) * cellSize.height() - 0.5 * textSize.height();
   877                         textSize.height() - HbVerticalMarginInUnits * mUnitValue - mButtonBorderSize;
   961             break;
   878     } else if (textType == HbInputButtonGroup::ButtonTextTypeSecondarySecondRow) {
   962 
   879         textPositionX = (button->position().x() + button->size().width()) * cellSize.width() -
   963         case HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow:
   880                         textSize.width() - HbHorizontalMarginInUnits * mUnitValue - mButtonBorderSize;
   964             textPositionX = (button->position().x() + button->size().width()) * cellSize.width() -
   881         textPositionY = button->position().y() * cellSize.height() + HbVerticalMarginInUnits * mUnitValue + mButtonBorderSize;
   965                             textSize.width() - HbHorizontalMarginInUnits * mUnitValue - mButtonBorderSize;
       
   966             textPositionY = (button->position().y() + button->size().height()) * cellSize.height() -
       
   967                             textSize.height() - HbVerticalMarginInUnits * mUnitValue - mButtonBorderSize;
       
   968             break;
       
   969 
       
   970         case HbInputButtonGroup::ButtonTextTypeSecondarySecondRow:
       
   971             textPositionX = (button->position().x() + button->size().width()) * cellSize.width() -
       
   972                             textSize.width() - HbHorizontalMarginInUnits * mUnitValue - mButtonBorderSize;
       
   973             textPositionY = button->position().y() * cellSize.height() + HbVerticalMarginInUnits * mUnitValue + mButtonBorderSize;
       
   974             break;
       
   975 
       
   976         default:
       
   977             break;
   882     }
   978     }
   883     textLine.setPosition(QPointF(textPositionX, textPositionY));
   979     textLine.setPosition(QPointF(textPositionX, textPositionY));
   884 }
   980 }
   885 
   981 
   886 QString HbInputButtonGroupPrivate::buttonGraphics(HbInputButton::HbInputButtonType type, HbInputButton::HbInputButtonState state)
   982 QString HbInputButtonGroupPrivate::buttonGraphics(HbInputButton::HbInputButtonType type, HbInputButton::HbInputButtonState state)
   941     return QString("");
  1037     return QString("");
   942 }
  1038 }
   943 
  1039 
   944 qreal HbInputButtonGroupPrivate::fontSize(HbInputButtonGroup::HbInputButtonTextType textType)
  1040 qreal HbInputButtonGroupPrivate::fontSize(HbInputButtonGroup::HbInputButtonTextType textType)
   945 {
  1041 {
   946     if (textType == HbInputButtonGroup::ButtonTextTypeSingle) {
  1042     switch(textType) {
   947         return HbTextSizeInUnits * mUnitValue;
  1043         case HbInputButtonGroup::ButtonTextTypeSingle:
   948     } else if (textType == HbInputButtonGroup::ButtonTextTypePrimary) {
  1044             return HbTextSizeInUnits * mUnitValue;
   949         return HbPrimaryTextSizeInUnits * mUnitValue;
  1045 
   950     } else if (textType == HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow ||
  1046         case HbInputButtonGroup::ButtonTextTypePrimary:
   951                textType == HbInputButtonGroup::ButtonTextTypeSecondarySecondRow) {
  1047             return HbPrimaryTextSizeInUnits * mUnitValue;
   952         return HbSecondaryTextSizeInUnits * mUnitValue;
  1048 
   953     } else if (textType == HbInputButtonGroup::ButtonTextTypeLabel) {
  1049         case HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow:
   954         return HbLabelTextSizeInUnits * mUnitValue;
  1050         case HbInputButtonGroup::ButtonTextTypeSecondarySecondRow:
   955     }
  1051             return HbSecondaryTextSizeInUnits * mUnitValue;
   956     return 0;
  1052 
       
  1053         case HbInputButtonGroup::ButtonTextTypeLabel:
       
  1054             return HbLabelTextSizeInUnits * mUnitValue;
       
  1055 
       
  1056         default:
       
  1057             return 0;
       
  1058     }
   957 }
  1059 }
   958 
  1060 
   959 void HbInputButtonGroupPrivate::startLongPress(int index)
  1061 void HbInputButtonGroupPrivate::startLongPress(int index)
   960 {
  1062 {
   961     Q_Q(HbInputButtonGroup);
  1063     Q_Q(HbInputButtonGroup);
   998     Q_D(HbInputButtonGroup);
  1100     Q_D(HbInputButtonGroup);
   999 
  1101 
  1000     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1102     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1001 
  1103 
  1002     setAcceptedMouseButtons(Qt::LeftButton);
  1104     setAcceptedMouseButtons(Qt::LeftButton);
  1003     setFlag(QGraphicsItem::ItemHasNoContents,false);
       
  1004 }
  1105 }
  1005 
  1106 
  1006 /*!
  1107 /*!
  1007 Constructor
  1108 Constructor
  1008 */
  1109 */
  1012     Q_D(HbInputButtonGroup);
  1113     Q_D(HbInputButtonGroup);
  1013 
  1114 
  1014     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1115     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1015 
  1116 
  1016     setAcceptedMouseButtons(Qt::LeftButton);
  1117     setAcceptedMouseButtons(Qt::LeftButton);
  1017     setFlag(QGraphicsItem::ItemHasNoContents,false);
       
  1018 }
  1118 }
  1019 
  1119 
  1020 /*!
  1120 /*!
  1021 Constructor
  1121 Constructor
  1022 */
  1122 */
  1028     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1128     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1029 
  1129 
  1030     setAcceptedMouseButtons(Qt::LeftButton);
  1130     setAcceptedMouseButtons(Qt::LeftButton);
  1031 
  1131 
  1032     setGridSize(size);
  1132     setGridSize(size);
  1033     setFlag(QGraphicsItem::ItemHasNoContents,false);
       
  1034 }
  1133 }
  1035 
  1134 
  1036 /*!
  1135 /*!
  1037 Constructor
  1136 Constructor
  1038 */
  1137 */
  1044     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1143     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1045 
  1144 
  1046     setAcceptedMouseButtons(Qt::LeftButton);
  1145     setAcceptedMouseButtons(Qt::LeftButton);
  1047 
  1146 
  1048     setGridSize(size);
  1147     setGridSize(size);
  1049     setFlag(QGraphicsItem::ItemHasNoContents,false);
       
  1050 }
  1148 }
  1051 
  1149 
  1052 /*!
  1150 /*!
  1053 Destructor
  1151 Destructor
  1054 */
  1152 */
  1483     Q_UNUSED(option);
  1581     Q_UNUSED(option);
  1484     Q_UNUSED(widget);
  1582     Q_UNUSED(widget);
  1485 
  1583 
  1486     Q_D(HbInputButtonGroup);
  1584     Q_D(HbInputButtonGroup);
  1487 
  1585 
       
  1586     // Draw button group background
  1488     if (d->mBackground) {
  1587     if (d->mBackground) {
  1489         d->mBackground->paint(painter, QRectF(0, 0, boundingRect().width(), boundingRect().height()));
  1588         d->mBackground->paint(painter, QRectF(0, 0, boundingRect().width(), boundingRect().height()));
  1490     }
  1589     }
  1491 
  1590 
  1492     qreal cellWidth = boundingRect().width() / d->mGridSize.width();
  1591     qreal cellWidth = boundingRect().width() / d->mGridSize.width();
  1493     qreal cellHeight = boundingRect().height() / d->mGridSize.height();
  1592     qreal cellHeight = boundingRect().height() / d->mGridSize.height();
  1494 
  1593 
  1495     for (int i = 0; i < d->mButtonData.count(); ++i) {
  1594     for (int i = 0; i < d->mButtonData.count(); ++i) {
  1496         HbInputButton *item = d->mButtonData.at(i);
  1595         HbInputButton *item = d->mButtonData.at(i);
  1497 
  1596 
       
  1597         // Draw button backgrounds
  1498         if (d->mButtonDrawers.at(i)) {
  1598         if (d->mButtonDrawers.at(i)) {
  1499             qreal x = item->position().x() * cellWidth + d->mButtonBorderSize;
  1599             qreal x = item->position().x() * cellWidth + d->mButtonBorderSize;
  1500             qreal y = item->position().y() * cellHeight + d->mButtonBorderSize;
  1600             qreal y = item->position().y() * cellHeight + d->mButtonBorderSize;
  1501             qreal width = item->size().width() * cellWidth - 2 * d->mButtonBorderSize;
  1601             qreal width = item->size().width() * cellWidth - 2 * d->mButtonBorderSize;
  1502             qreal height = item->size().height() * cellHeight - 2 * d->mButtonBorderSize;
  1602             qreal height = item->size().height() * cellHeight - 2 * d->mButtonBorderSize;
  1505             painter->translate(x, y);
  1605             painter->translate(x, y);
  1506             d->mButtonDrawers.at(i)->paint(painter, QRectF(0, 0, width, height));
  1606             d->mButtonDrawers.at(i)->paint(painter, QRectF(0, 0, width, height));
  1507             painter->restore();
  1607             painter->restore();
  1508         }
  1608         }
  1509 
  1609 
       
  1610         // Draw primary icons
  1510         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
  1611         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
  1511             qreal x = item->position().x() * cellWidth;
  1612             qreal x = item->position().x() * cellWidth;
  1512             qreal y = item->position().y() * cellHeight;
  1613             qreal y = item->position().y() * cellHeight;
  1513             qreal width = item->size().width() * cellWidth;
  1614             qreal width = item->size().width() * cellWidth;
  1514             qreal height = item->size().height() * cellHeight;
  1615             qreal height = item->size().height() * cellHeight;
  1523                 height = HbPrimaryIconSizeInUnits * d->mUnitValue;
  1624                 height = HbPrimaryIconSizeInUnits * d->mUnitValue;
  1524             }
  1625             }
  1525             item->icon(HbInputButton::ButtonIconIndexPrimary).paint(painter, QRectF(x, y, width, height));
  1626             item->icon(HbInputButton::ButtonIconIndexPrimary).paint(painter, QRectF(x, y, width, height));
  1526         }
  1627         }
  1527 
  1628 
       
  1629         // Draw secondary icons on first row
  1528         if (!item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull()) {
  1630         if (!item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull()) {
  1529             qreal x = (item->position().x() + item->size().width()) * cellWidth -
  1631             qreal x = (item->position().x() + item->size().width()) * cellWidth -
  1530                       HbSecondaryIconSizeInUnits * d->mUnitValue - HbHorizontalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1632                       HbSecondaryIconSizeInUnits * d->mUnitValue - HbHorizontalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1531             qreal y = (item->position().y() + item->size().height()) * cellHeight -
  1633             qreal y = (item->position().y() + item->size().height()) * cellHeight -
  1532                       HbSecondaryIconSizeInUnits * d->mUnitValue - HbVerticalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1634                       HbSecondaryIconSizeInUnits * d->mUnitValue - HbVerticalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1535 
  1637 
  1536             Qt::Alignment alignment = static_cast<Qt::Alignment>(Qt::AlignVCenter | Qt::AlignRight);
  1638             Qt::Alignment alignment = static_cast<Qt::Alignment>(Qt::AlignVCenter | Qt::AlignRight);
  1537             item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).paint(painter, QRectF(x, y, width, height), Qt::KeepAspectRatio, alignment);
  1639             item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).paint(painter, QRectF(x, y, width, height), Qt::KeepAspectRatio, alignment);
  1538         }
  1640         }
  1539 
  1641 
       
  1642         // Draw secondary icons on second row
  1540         if (!item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull()) {
  1643         if (!item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull()) {
  1541             qreal x = (item->position().x() + item->size().width()) * cellWidth -
  1644             qreal x = (item->position().x() + item->size().width()) * cellWidth -
  1542                       HbSecondaryIconSizeInUnits * d->mUnitValue - HbHorizontalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1645                       HbSecondaryIconSizeInUnits * d->mUnitValue - HbHorizontalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1543             qreal y = item->position().y() * cellHeight + HbVerticalMarginInUnits * d->mUnitValue + d->mButtonBorderSize;
  1646             qreal y = item->position().y() * cellHeight + HbVerticalMarginInUnits * d->mUnitValue + d->mButtonBorderSize;
  1544             qreal width = HbSecondaryIconSizeInUnits * d->mUnitValue;
  1647             qreal width = HbSecondaryIconSizeInUnits * d->mUnitValue;
  1548             item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).paint(painter, QRectF(x, y, width, height), Qt::KeepAspectRatio, alignment);
  1651             item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).paint(painter, QRectF(x, y, width, height), Qt::KeepAspectRatio, alignment);
  1549         }
  1652         }
  1550 
  1653 
  1551     }
  1654     }
  1552 
  1655 
       
  1656     // Draw button texts
  1553     for (int i = 0; i < HbTextLayoutCount; ++i) {
  1657     for (int i = 0; i < HbTextLayoutCount; ++i) {
  1554         painter->save();
  1658         painter->save();
  1555         painter->setPen(d->mColors.at(i % HbTextTypeCount));
  1659         painter->setPen(d->mColors.at(i % HbTextTypeCount));
  1556 
  1660 
  1557         if (d->mTextLayouts.at(i)) {
  1661         if (d->mTextLayouts.at(i)) {
  1573     if (!d->mEnabled) {
  1677     if (!d->mEnabled) {
  1574         event->ignore();
  1678         event->ignore();
  1575         return false;
  1679         return false;
  1576     }
  1680     }
  1577 
  1681 
  1578     if (event->type() == QEvent::TouchBegin) {
  1682     switch(event->type()) {
  1579         QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
  1683         case QEvent::TouchBegin: {
  1580         foreach(const QTouchEvent::TouchPoint &point, touchEvent->touchPoints()) {
  1684             QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
  1581             if (!point.isPrimary() && d->mMultiTouchEnabled) {
  1685             foreach(const QTouchEvent::TouchPoint &point, touchEvent->touchPoints()) {
  1582                 d->pressEvent(point.pos());
  1686                 if (!point.isPrimary() && d->mMultiTouchEnabled) {
  1583             }
       
  1584         }
       
  1585     } else if (event->type() == QEvent::TouchUpdate) {
       
  1586         QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
       
  1587         foreach(const QTouchEvent::TouchPoint &point, touchEvent->touchPoints()) {
       
  1588             if (!point.isPrimary() && d->mMultiTouchEnabled) {
       
  1589                 if (point.state() & Qt::TouchPointPressed) {
       
  1590                     d->pressEvent(point.pos());
  1687                     d->pressEvent(point.pos());
  1591                 } else if (point.state() & Qt::TouchPointMoved) {
  1688                 }
  1592                     d->moveEvent(point.lastPos(), point.pos());
  1689             }
  1593                 } else if (point.state() & Qt::TouchPointReleased) {
  1690             break;
       
  1691         }
       
  1692 
       
  1693         case QEvent::TouchUpdate: {
       
  1694             QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
       
  1695             foreach(const QTouchEvent::TouchPoint &point, touchEvent->touchPoints()) {
       
  1696                 if (!point.isPrimary() && d->mMultiTouchEnabled) {
       
  1697                     if (point.state() & Qt::TouchPointPressed) {
       
  1698                         d->pressEvent(point.pos());
       
  1699                     } else if (point.state() & Qt::TouchPointMoved) {
       
  1700                         d->moveEvent(point.lastPos(), point.pos());
       
  1701                     } else if (point.state() & Qt::TouchPointReleased) {
       
  1702                         d->releaseEvent(point.pos());
       
  1703                     }
       
  1704                 }
       
  1705             }
       
  1706             break;
       
  1707         }
       
  1708 
       
  1709         case QEvent::TouchEnd: {
       
  1710             QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
       
  1711             foreach(const QTouchEvent::TouchPoint &point, touchEvent->touchPoints()) {
       
  1712                 if (!point.isPrimary() && d->mMultiTouchEnabled) {
  1594                     d->releaseEvent(point.pos());
  1713                     d->releaseEvent(point.pos());
  1595                 }
  1714                 }
  1596             }
  1715             }
  1597         }
  1716             break;
  1598     } else if (event->type() == QEvent::TouchEnd) {
  1717         }
  1599         QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
  1718 
  1600         foreach(const QTouchEvent::TouchPoint &point, touchEvent->touchPoints()) {
  1719         case QEvent::GraphicsSceneMousePress: {
  1601             if (!point.isPrimary() && d->mMultiTouchEnabled) {
  1720             QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1602                 d->releaseEvent(point.pos());
  1721             d->pressEvent(mouseEvent->pos());
  1603             }
  1722             break;
  1604         }
  1723         }
  1605     } else if (event->type() == QEvent::GraphicsSceneMousePress) {
  1724 
  1606         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1725         case QEvent::GraphicsSceneMouseDoubleClick: {
  1607         d->pressEvent(mouseEvent->pos());
  1726             QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1608     } else if (event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
  1727             d->doublePressEvent(mouseEvent->pos());
  1609         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1728             break;
  1610         d->doublePressEvent(mouseEvent->pos());
  1729         }
  1611     } else if (event->type() == QEvent::GraphicsSceneMouseMove) {
  1730 
  1612         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1731         case QEvent::GraphicsSceneMouseMove: {
  1613         d->moveEvent(mouseEvent->lastPos(), mouseEvent->pos());
  1732             QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1614     } else if (event->type() == QEvent::GraphicsSceneMouseRelease) {
  1733             d->moveEvent(mouseEvent->lastPos(), mouseEvent->pos());
  1615         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1734             break;
  1616         d->releaseEvent(mouseEvent->pos());
  1735         }
  1617         cancelButtonPress();
  1736 
  1618     } else {
  1737         case QEvent::GraphicsSceneMouseRelease: {
  1619         return HbWidget::event(event);
  1738             QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
       
  1739             d->releaseEvent(mouseEvent->pos());
       
  1740             cancelButtonPress();
       
  1741             break;
       
  1742         }
       
  1743 
       
  1744         default:
       
  1745             return HbWidget::event(event);
  1620     }
  1746     }
  1621     return true;
  1747     return true;
  1622 }
  1748 }
  1623 
  1749 
  1624 /*!
  1750 /*!
  1757 {
  1883 {
  1758     Q_D(HbInputButtonGroup);
  1884     Q_D(HbInputButtonGroup);
  1759 
  1885 
  1760     ungrabMouse();
  1886     ungrabMouse();
  1761 
  1887 
  1762     for (int i = 0; i < d->mButtonData.count(); ++i) {
  1888     // Cancel long press timers
  1763         if (d->mButtonData.at(i)->state() == HbInputButton::ButtonStatePressed) {
  1889     d->mLongPressButtons.clear();
  1764             d->mButtonData.at(i)->setState(HbInputButton::ButtonStateReleased);
  1890     foreach (QTimer *timer, d->mLongPressTimers) {
  1765         }
  1891         delete timer;
  1766         d->hideButtonPreview(d->mButtonData.at(i));
  1892     }
  1767 
  1893     d->mLongPressTimers.clear();
  1768         if (d->mLongPressButtons.contains(i)) {
  1894 
  1769             int listIndex = d->mLongPressButtons.indexOf(i);
  1895     // Release all buttons and close previews
  1770             delete d->mLongPressTimers.at(listIndex);
  1896     foreach (HbInputButton *button, d->mButtonData) {
  1771             d->mLongPressTimers.removeAt(listIndex);
  1897         if (button->state() == HbInputButton::ButtonStatePressed) {
  1772             d->mLongPressButtons.removeAt(listIndex);
  1898             button->setState(HbInputButton::ButtonStateReleased);
  1773         }
  1899         }
       
  1900         d->hideButtonPreview(button);
  1774     }
  1901     }
  1775     if (d->mCharacterSelectionPreview) {
  1902     if (d->mCharacterSelectionPreview) {
  1776         d->mCharacterSelectionPreview->hide();
  1903         d->mCharacterSelectionPreview->hide();
  1777     }
  1904     }
  1778 
  1905