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()) { |
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); |
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) |
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) |
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; |
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 /*! |