src/hbinput/inputwidgets/hbinputbuttongroup.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    20 **
    20 **
    21 ** If you have questions regarding the use of this file, please contact
    21 ** If you have questions regarding the use of this file, please contact
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
       
    25 #include "hbinputbuttongroup.h"
       
    26 #include "hbinputbuttongroup_p.h"
    25 
    27 
    26 #include <QPainter>
    28 #include <QPainter>
    27 #include <QTextLayout>
    29 #include <QTextLayout>
    28 #include <QGraphicsSceneMouseEvent>
    30 #include <QGraphicsSceneMouseEvent>
    29 #include <QTouchEvent>
    31 #include <QTouchEvent>
    40 #include <hbwidgetfeedback.h>
    42 #include <hbwidgetfeedback.h>
    41 #include <hbdeviceprofile.h>
    43 #include <hbdeviceprofile.h>
    42 #include <hbinputregioncollector_p.h>
    44 #include <hbinputregioncollector_p.h>
    43 #include "hbframedrawerpool_p.h"
    45 #include "hbframedrawerpool_p.h"
    44 
    46 
    45 #include "hbinputbuttongroup.h"
       
    46 #include "hbinputbuttongroup_p.h"
       
    47 #include "hbinputbutton.h"
    47 #include "hbinputbutton.h"
    48 
    48 
    49 /// @cond
    49 /// @cond
    50 
    50 
    51 const QString HbNormalBackground("qtg_fr_input_btn_keypad_normal");
    51 const QString HbNormalBackground("qtg_fr_input_btn_keypad_normal");
    92 const qreal HbPreviewMarginInUnits = 3;
    92 const qreal HbPreviewMarginInUnits = 3;
    93 
    93 
    94 const qreal HbTouchAreaSizeInUnits = 8;
    94 const qreal HbTouchAreaSizeInUnits = 8;
    95 
    95 
    96 HbInputButtonGroupPrivate::HbInputButtonGroupPrivate()
    96 HbInputButtonGroupPrivate::HbInputButtonGroupPrivate()
    97  : mUnitValue(0), mGridSize(1, 1), mButtonBorderSize(1.0), mEnabled(true),
    97     : mUnitValue(0), mGridSize(1, 1), mButtonBorderSize(1.0), mEnabled(true),
    98    mButtonPreviewEnabled(false), mCharacterSelectionPreviewEnabled(false),
    98       mButtonPreviewEnabled(false), mCharacterSelectionPreviewEnabled(false),
    99    mMultiTouchEnabled(true), mCharacterSelectionPreview(0), mBackground(0)
    99       mMultiTouchEnabled(true), mCharacterSelectionPreview(0), mBackground(0)
   100 {
   100 {
   101     for (int i = 0; i < HbTextLayoutCount; ++i) {
   101     for (int i = 0; i < HbTextLayoutCount; ++i) {
   102         mTextLayouts.append(0);
   102         mTextLayouts.append(0);
   103     }
   103     }
   104 
   104 
   109 {
   109 {
   110     foreach(HbFrameDrawer *drawer, mButtonDrawers) {
   110     foreach(HbFrameDrawer *drawer, mButtonDrawers) {
   111         HbFrameDrawerPool::release(drawer);
   111         HbFrameDrawerPool::release(drawer);
   112     }
   112     }
   113 
   113 
   114     foreach (HbInputButton *button, mButtonData) {
   114     foreach(HbInputButton *button, mButtonData) {
   115         delete button;
   115         delete button;
   116     }
   116     }
   117     mButtonData.clear();
   117     mButtonData.clear();
   118 
   118 
   119     foreach (QTextLayout *layout, mTextLayouts) {
   119     foreach(QTextLayout *layout, mTextLayouts) {
   120         delete layout;
   120         delete layout;
   121     }
   121     }
   122 
   122 
   123     foreach (QTimer *timer, mLongPressTimers) {
   123     foreach(QTimer *timer, mLongPressTimers) {
   124         delete timer;
   124         delete timer;
   125     }
   125     }
   126 
   126 
   127     delete mCharacterSelectionPreview;
   127     delete mCharacterSelectionPreview;
   128 
   128 
   307         HbInputButton::HbInputButtonState state = static_cast<HbInputButton::HbInputButtonState>(i % HbInputButton::ButtonStateCount);
   307         HbInputButton::HbInputButtonState state = static_cast<HbInputButton::HbInputButtonState>(i % HbInputButton::ButtonStateCount);
   308         mColors.append(HbColorScheme::color(buttonColor(type, state)));
   308         mColors.append(HbColorScheme::color(buttonColor(type, state)));
   309     }
   309     }
   310 }
   310 }
   311 
   311 
   312 void HbInputButtonGroupPrivate::showButtonPreview(HbInputButton * const item)
   312 void HbInputButtonGroupPrivate::showButtonPreview(HbInputButton *const item)
   313 {
   313 {
   314     Q_Q(HbInputButtonGroup);
   314     Q_Q(HbInputButtonGroup);
   315 
   315 
   316     int index = mButtonData.indexOf(item);
   316     int index = mButtonData.indexOf(item);
   317     if (mButtonPreviewEnabled && item->type() != HbInputButton::ButtonTypeFunction &&
   317     if (mButtonPreviewEnabled && item->type() != HbInputButton::ButtonTypeFunction &&
   318         !mButtonPreview.contains(index)) {
   318         !mButtonPreview.contains(index)) {
   319         HbInputButtonGroup *group = new HbInputButtonGroup(QSize(1, 1));
   319         HbInputButtonGroup *group = new HbInputButtonGroup(QSize(1, 1));
   320         mButtonPreview.insert(index, group);
   320         mButtonPreview.insert(index, group);
   321 
   321 
   322         QList<HbInputButton*> buttons;
   322         QList<HbInputButton *> buttons;
   323         HbInputButton *previewItem = 0;
   323         HbInputButton *previewItem = 0;
   324         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
   324         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
   325             int keyCode = -1;
   325             int keyCode = -1;
   326             if (!item->text(HbInputButton::ButtonTextIndexPrimary).isEmpty()) {
   326             if (!item->text(HbInputButton::ButtonTextIndexPrimary).isEmpty()) {
   327                 keyCode = item->text(HbInputButton::ButtonTextIndexPrimary).at(0).unicode();
   327                 keyCode = item->text(HbInputButton::ButtonTextIndexPrimary).at(0).unicode();
   338 
   338 
   339         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   339         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   340         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   340         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   341 
   341 
   342         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   342         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   343         font.setPixelSize(int(fontSize(ButtonTextTypeLabel)));
   343         font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeLabel)));
   344         QFontMetricsF fontMetrics(font);
   344         QFontMetricsF fontMetrics(font);
   345         qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexPrimary));
   345         qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexPrimary));
   346 
   346 
   347         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue;
   347         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue;
   348         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
   348         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
   369         group->setBackground(drawer);
   369         group->setBackground(drawer);
   370         q->mainWindow()->scene()->addItem(group);
   370         q->mainWindow()->scene()->addItem(group);
   371     }
   371     }
   372 }
   372 }
   373 
   373 
   374 void HbInputButtonGroupPrivate::hideButtonPreview(HbInputButton * const item)
   374 void HbInputButtonGroupPrivate::hideButtonPreview(HbInputButton *const item)
   375 {
   375 {
   376     int index = mButtonData.indexOf(item);
   376     int index = mButtonData.indexOf(item);
   377     if (mButtonPreview.contains(index)) {
   377     if (mButtonPreview.contains(index)) {
   378         delete mButtonPreview.take(index);
   378         delete mButtonPreview.take(index);
   379     }
   379     }
   380 }
   380 }
   381 
   381 
   382 void HbInputButtonGroupPrivate::showCharacterSelectionPreview(HbInputButton * const item)
   382 void HbInputButtonGroupPrivate::showCharacterSelectionPreview(HbInputButton *const item)
   383 {
   383 {
   384     Q_Q(HbInputButtonGroup);
   384     Q_Q(HbInputButtonGroup);
   385 
   385 
   386     if (mCharacterSelectionPreviewEnabled && item->type() != HbInputButton::ButtonTypeFunction &&
   386     if (mCharacterSelectionPreviewEnabled && item->type() != HbInputButton::ButtonTypeFunction &&
   387         item->mappedCharacters().count() > 1) {
   387         item->mappedCharacters().count() > 1) {
   388 
   388 
   389         HbWidgetFeedback::triggered(q, Hb::InstantLongPressed);
   389         HbWidgetFeedback::triggered(q, Hb::InstantLongPressed);
   390         
   390 
   391         mProbabilities.clear();
   391         mProbabilities.clear();
   392         q->cancelButtonPress();
   392         q->cancelButtonPress();
   393         
   393 
   394         if (!mCharacterSelectionPreview) {
   394         if (!mCharacterSelectionPreview) {
   395             mCharacterSelectionPreview = new HbDialog();
   395             mCharacterSelectionPreview = new HbDialog();
   396             HbInputRegionCollector::instance()->attach(mCharacterSelectionPreview);
   396             HbInputRegionCollector::instance()->attach(mCharacterSelectionPreview);
   397             mCharacterSelectionPreview->setModal(true);
   397             mCharacterSelectionPreview->setModal(true);
   398             mCharacterSelectionPreview->setBackgroundFaded(false);
   398             mCharacterSelectionPreview->setBackgroundFaded(false);
   403             qreal margin = HbPreviewMarginInUnits * mUnitValue * 0.5;
   403             qreal margin = HbPreviewMarginInUnits * mUnitValue * 0.5;
   404             mCharacterSelectionPreview->setContentsMargins(margin, 0, margin, 0);
   404             mCharacterSelectionPreview->setContentsMargins(margin, 0, margin, 0);
   405         }
   405         }
   406 
   406 
   407         HbInputButtonGroup *group = new HbInputButtonGroup(QSize(item->mappedCharacters().count(), 1));
   407         HbInputButtonGroup *group = new HbInputButtonGroup(QSize(item->mappedCharacters().count(), 1));
   408         QObject::connect(group, SIGNAL(buttonPressed(const QKeyEvent&)), q, SLOT(emitButtonPressed(const QKeyEvent&)));
   408         QObject::connect(group, SIGNAL(buttonPressed(const QKeyEvent &)), q, SLOT(emitButtonPressed(const QKeyEvent &)));
   409         QObject::connect(group, SIGNAL(buttonDoublePressed(const QKeyEvent&)), q, SLOT(emitButtonDoublePressed(const QKeyEvent&)));
   409         QObject::connect(group, SIGNAL(buttonDoublePressed(const QKeyEvent &)), q, SLOT(emitButtonDoublePressed(const QKeyEvent &)));
   410         QObject::connect(group, SIGNAL(buttonReleased(const QKeyEvent&)), q, SLOT(emitButtonReleased(const QKeyEvent&)));
   410         QObject::connect(group, SIGNAL(buttonReleased(const QKeyEvent &)), q, SLOT(emitButtonReleased(const QKeyEvent &)));
   411         QObject::connect(group, SIGNAL(buttonLongPressed(const QKeyEvent&)), q, SLOT(emitButtonLongPressed(const QKeyEvent&)));
   411         QObject::connect(group, SIGNAL(buttonLongPressed(const QKeyEvent &)), q, SLOT(emitButtonLongPressed(const QKeyEvent &)));
   412         QObject::connect(group, SIGNAL(pressedButtonChanged(const QKeyEvent&, const QKeyEvent&)), q, SLOT(emitPressedButtonChanged(const QKeyEvent&, const QKeyEvent&)));
   412         QObject::connect(group, SIGNAL(pressedButtonChanged(const QKeyEvent &, const QKeyEvent &)), q, SLOT(emitPressedButtonChanged(const QKeyEvent &, const QKeyEvent &)));
   413         
   413 
   414         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   414         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   415         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   415         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   416 
   416 
   417         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   417         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   418         font.setPixelSize(int(fontSize(ButtonTextTypeLabel)));
   418         font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeLabel)));
   419         QFontMetricsF fontMetrics(font);
   419         QFontMetricsF fontMetrics(font);
   420         qreal textWidth = fontMetrics.width(item->mappedCharacters());
   420         qreal textWidth = fontMetrics.width(item->mappedCharacters());
   421 
   421 
   422         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue * item->mappedCharacters().count();
   422         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue * item->mappedCharacters().count();
   423         qreal height = HbPreviewHeightInUnits * mUnitValue;
   423         qreal height = HbPreviewHeightInUnits * mUnitValue;
   424         qreal x = q->scenePos().x() + (item->position().x() + 0.5 * item->size().width()) * cellWidth;
   424         qreal x = q->scenePos().x() + (item->position().x() + 0.5 * item->size().width()) * cellWidth;
   425         qreal y = q->scenePos().y() + item->position().y() * cellHeight;
   425         qreal y = q->scenePos().y() + item->position().y() * cellHeight;
   426 
   426 
   427         QList<HbInputButton*> buttons;
   427         QList<HbInputButton *> buttons;
   428         for (int i = 0; i < item->mappedCharacters().count(); ++i) {
   428         for (int i = 0; i < item->mappedCharacters().count(); ++i) {
   429             HbInputButton *previewItem = new HbInputButton(item->keyCode(), QPoint(i, 0));
   429             HbInputButton *previewItem = new HbInputButton(item->keyCode(), QPoint(i, 0));
   430             previewItem->setType(HbInputButton::ButtonTypeLabel);
   430             previewItem->setType(HbInputButton::ButtonTypeLabel);
   431             previewItem->setText(item->mappedCharacters().at(i), HbInputButton::ButtonTextIndexPrimary);
   431             previewItem->setText(item->mappedCharacters().at(i), HbInputButton::ButtonTextIndexPrimary);
   432             buttons.append(previewItem);
   432             buttons.append(previewItem);
   449 void HbInputButtonGroupPrivate::pressEvent(const QPointF &position, bool emitSignal)
   449 void HbInputButtonGroupPrivate::pressEvent(const QPointF &position, bool emitSignal)
   450 {
   450 {
   451     Q_Q(HbInputButtonGroup);
   451     Q_Q(HbInputButtonGroup);
   452 
   452 
   453     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   453     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   454         position.y() >= 0 && position.y() < q->boundingRect().height())) {
   454           position.y() >= 0 && position.y() < q->boundingRect().height())) {
   455         return;
   455         return;
   456     }
   456     }
   457 
   457 
   458     int column = static_cast<int>(position.x() / (q->boundingRect().width() / mGridSize.width()));
   458     int column = static_cast<int>(position.x() / (q->boundingRect().width() / mGridSize.width()));
   459     int row = static_cast<int>(position.y() / (q->boundingRect().height() / mGridSize.height()));
   459     int row = static_cast<int>(position.y() / (q->boundingRect().height() / mGridSize.height()));
   461     int index = mButtonGridPositions.value(QPair<int, int>(column, row), -1);
   461     int index = mButtonGridPositions.value(QPair<int, int>(column, row), -1);
   462 
   462 
   463     if (index >= 0 && index < mButtonData.count()) {
   463     if (index >= 0 && index < mButtonData.count()) {
   464         HbInputButton *item = mButtonData.at(index);
   464         HbInputButton *item = mButtonData.at(index);
   465 
   465 
   466         if ((item->state() != HbInputButton::ButtonStateReleased && 
   466         if ((item->state() != HbInputButton::ButtonStateReleased &&
   467             item->state() != HbInputButton::ButtonStateLatched) ||
   467              item->state() != HbInputButton::ButtonStateLatched) ||
   468             (mCharacterSelectionPreview && mCharacterSelectionPreview->isVisible())) {
   468             (mCharacterSelectionPreview && mCharacterSelectionPreview->isVisible())) {
   469             if (item->state() == HbInputButton::ButtonStateDisabled) {
   469             if (item->state() == HbInputButton::ButtonStateDisabled) {
   470                 startLongPress(index);
   470                 startLongPress(index);
   471             }
   471             }
   472             return;
   472             return;
   499 void HbInputButtonGroupPrivate::doublePressEvent(const QPointF &position, bool emitSignal)
   499 void HbInputButtonGroupPrivate::doublePressEvent(const QPointF &position, bool emitSignal)
   500 {
   500 {
   501     Q_Q(HbInputButtonGroup);
   501     Q_Q(HbInputButtonGroup);
   502 
   502 
   503     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   503     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   504         position.y() >= 0 && position.y() < q->boundingRect().height())) {
   504           position.y() >= 0 && position.y() < q->boundingRect().height())) {
   505         return;
   505         return;
   506     }
   506     }
   507 
   507 
   508     int column = static_cast<int>(position.x() / (q->boundingRect().width() / mGridSize.width()));
   508     int column = static_cast<int>(position.x() / (q->boundingRect().width() / mGridSize.width()));
   509     int row = static_cast<int>(position.y() / (q->boundingRect().height() / mGridSize.height()));
   509     int row = static_cast<int>(position.y() / (q->boundingRect().height() / mGridSize.height()));
   511     int index = mButtonGridPositions.value(QPair<int, int>(column, row), -1);
   511     int index = mButtonGridPositions.value(QPair<int, int>(column, row), -1);
   512 
   512 
   513     if (index >= 0 && index < mButtonData.count()) {
   513     if (index >= 0 && index < mButtonData.count()) {
   514         HbInputButton *item = mButtonData.at(index);
   514         HbInputButton *item = mButtonData.at(index);
   515 
   515 
   516         if ((item->state() != HbInputButton::ButtonStateReleased && 
   516         if ((item->state() != HbInputButton::ButtonStateReleased &&
   517             item->state() != HbInputButton::ButtonStateLatched) ||
   517              item->state() != HbInputButton::ButtonStateLatched) ||
   518             (mCharacterSelectionPreview && mCharacterSelectionPreview->isVisible())) {
   518             (mCharacterSelectionPreview && mCharacterSelectionPreview->isVisible())) {
   519             if (item->state() == HbInputButton::ButtonStateDisabled) {
   519             if (item->state() == HbInputButton::ButtonStateDisabled) {
   520                 startLongPress(index);
   520                 startLongPress(index);
   521             }
   521             }
   522             return;
   522             return;
   560 
   560 
   561     if (newPosition.x() >= 0 && newPosition.x() < q->boundingRect().width() &&
   561     if (newPosition.x() >= 0 && newPosition.x() < q->boundingRect().width() &&
   562         newPosition.y() >= 0 && newPosition.y() < q->boundingRect().height() &&
   562         newPosition.y() >= 0 && newPosition.y() < q->boundingRect().height() &&
   563         oldPosition.x() >= 0 && oldPosition.x() < q->boundingRect().width() &&
   563         oldPosition.x() >= 0 && oldPosition.x() < q->boundingRect().width() &&
   564         oldPosition.y() >= 0 && oldPosition.y() < q->boundingRect().height()) {
   564         oldPosition.y() >= 0 && oldPosition.y() < q->boundingRect().height()) {
   565         
   565 
   566         if (oldIndex != newIndex) {
   566         if (oldIndex != newIndex) {
   567             releaseEvent(oldPosition, false);
   567             releaseEvent(oldPosition, false);
   568             pressEvent(newPosition, false);
   568             pressEvent(newPosition, false);
   569 
   569 
   570             QString text;
   570             QString text;
   591 void HbInputButtonGroupPrivate::releaseEvent(const QPointF &position, bool emitSignal)
   591 void HbInputButtonGroupPrivate::releaseEvent(const QPointF &position, bool emitSignal)
   592 {
   592 {
   593     Q_Q(HbInputButtonGroup);
   593     Q_Q(HbInputButtonGroup);
   594 
   594 
   595     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   595     if (!(position.x() >= 0 && position.x() < q->boundingRect().width() &&
   596         position.y() >= 0 && position.y() < q->boundingRect().height())) {
   596           position.y() >= 0 && position.y() < q->boundingRect().height())) {
   597         return;
   597         return;
   598     }
   598     }
   599 
   599 
   600     int column = static_cast<int>(position.x() / (q->boundingRect().width() / mGridSize.width()));
   600     int column = static_cast<int>(position.x() / (q->boundingRect().width() / mGridSize.width()));
   601     int row = static_cast<int>(position.y() / (q->boundingRect().height() / mGridSize.height()));
   601     int row = static_cast<int>(position.y() / (q->boundingRect().height() / mGridSize.height()));
   656     if (index >= 0 && index < mButtonData.count()) {
   656     if (index >= 0 && index < mButtonData.count()) {
   657         HbInputButton *item = mButtonData.at(index);
   657         HbInputButton *item = mButtonData.at(index);
   658 
   658 
   659         if (item->autoRepeat() &&
   659         if (item->autoRepeat() &&
   660             (item->state() == HbInputButton::ButtonStatePressed ||
   660             (item->state() == HbInputButton::ButtonStatePressed ||
   661             item->state() == HbInputButton::ButtonStateLatched)) {
   661              item->state() == HbInputButton::ButtonStateLatched)) {
   662             mLongPressButtons.append(index);
   662             mLongPressButtons.append(index);
   663             mLongPressTimers.append(timer);
   663             mLongPressTimers.append(timer);
   664             timer->start(HbAutoRepeatTimeout);
   664             timer->start(HbAutoRepeatTimeout);
   665 
   665 
   666             HbWidgetFeedback::triggered(q, Hb::InstantKeyRepeated);
   666             HbWidgetFeedback::triggered(q, Hb::InstantKeyRepeated);
   703 
   703 
   704     QRectF touchArea = QRectF(position.x() - 0.5 * cellWidth, position.y() - 0.5 * cellHeight,
   704     QRectF touchArea = QRectF(position.x() - 0.5 * cellWidth, position.y() - 0.5 * cellHeight,
   705                               HbTouchAreaSizeInUnits * mUnitValue, HbTouchAreaSizeInUnits * mUnitValue);
   705                               HbTouchAreaSizeInUnits * mUnitValue, HbTouchAreaSizeInUnits * mUnitValue);
   706 
   706 
   707     qreal probabilities = 0;
   707     qreal probabilities = 0;
   708     foreach (HbInputButton *button, mButtonData) {
   708     foreach(HbInputButton *button, mButtonData) {
   709         QRectF intersection = button->boundingRect().intersected(touchArea);
   709         QRectF intersection = button->boundingRect().intersected(touchArea);
   710 
   710 
   711         if (intersection.isValid()) {
   711         if (intersection.isValid()) {
   712             qreal probability = intersection.width() * intersection.height() / (touchArea.width() * touchArea.height());
   712             qreal probability = intersection.width() * intersection.height() / (touchArea.width() * touchArea.height());
   713             probabilities += probability;
   713             probabilities += probability;
   732 
   732 
   733     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   733     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   734 
   734 
   735     int typeIndex = index % HbTextTypeCount / HbInputButton::ButtonStateCount;
   735     int typeIndex = index % HbTextTypeCount / HbInputButton::ButtonStateCount;
   736     if (typeIndex == HbInputButton::ButtonTypeLabel) {
   736     if (typeIndex == HbInputButton::ButtonTypeLabel) {
   737       font.setPixelSize(int(fontSize(ButtonTextTypeLabel)));
   737         font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeLabel)));
   738     } else {
   738     } else {
   739       font.setPixelSize(int(fontSize(ButtonTextTypeSingle)));
   739         font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeSingle)));
   740     }
   740     }
   741 
   741 
   742     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   742     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   743     QFontMetricsF fontMetrics(font);
   743     QFontMetricsF fontMetrics(font);
   744 
   744 
   745     // Create text line for each button with primary text and correct type and state. Layout it
   745     // Create text line for each button with primary text and correct type and state. Layout it
   746     // to correct position
   746     // to correct position
   747     mTextLayouts.at(index)->beginLayout();
   747     mTextLayouts.at(index)->beginLayout();
   748     foreach (HbInputButton *item, mButtonData) {
   748     foreach(HbInputButton *item, mButtonData) {
   749         int layoutIndex = item->type() * HbInputButton::ButtonStateCount + item->state() + HbTextTypeCount;
   749         int layoutIndex = item->type() * HbInputButton::ButtonStateCount + item->state() + HbTextTypeCount;
   750         if (!mEnabled) {
   750         if (!mEnabled) {
   751             layoutIndex = item->type() * HbInputButton::ButtonStateCount + HbInputButton::ButtonStateDisabled + HbTextTypeCount;
   751             layoutIndex = item->type() * HbInputButton::ButtonStateCount + HbInputButton::ButtonStateDisabled + HbTextTypeCount;
   752         }
   752         }
   753         if (index == layoutIndex && !item->text(HbInputButton::ButtonTextIndexPrimary).isEmpty() &&
   753         if (index == layoutIndex && !item->text(HbInputButton::ButtonTextIndexPrimary).isEmpty() &&
   756             item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull() &&
   756             item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull() &&
   757             item->text(HbInputButton::ButtonTextIndexSecondarySecondRow).isEmpty() &&
   757             item->text(HbInputButton::ButtonTextIndexSecondarySecondRow).isEmpty() &&
   758             item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull()) {
   758             item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull()) {
   759             qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexPrimary));
   759             qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexPrimary));
   760             qreal textHeight = fontMetrics.height();
   760             qreal textHeight = fontMetrics.height();
   761             
   761 
   762             QTextLine line = mTextLayouts.at(index)->createLine();
   762             QTextLine line = mTextLayouts.at(index)->createLine();
   763             line.setNumColumns(item->text(HbInputButton::ButtonTextIndexPrimary).length());
   763             line.setNumColumns(item->text(HbInputButton::ButtonTextIndexPrimary).length());
   764 
   764 
   765             if (typeIndex == HbInputButton::ButtonTypeLabel) {
   765             if (typeIndex == HbInputButton::ButtonTypeLabel) {
   766                 layoutTextLine(ButtonTextTypeLabel, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   766                 layoutTextLine(HbInputButtonGroup::ButtonTextTypeLabel, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   767             } else {
   767             } else {
   768                 layoutTextLine(ButtonTextTypeSingle, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   768                 layoutTextLine(HbInputButtonGroup::ButtonTextTypeSingle, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   769             }
   769             }
   770         }
   770         }
   771     }
   771     }
   772     mTextLayouts.at(index)->endLayout();
   772     mTextLayouts.at(index)->endLayout();
   773     mTextLayouts.at(index)->setCacheEnabled(true);
   773     mTextLayouts.at(index)->setCacheEnabled(true);
   777 {
   777 {
   778     qreal cellWidth = size.width() / mGridSize.width();
   778     qreal cellWidth = size.width() / mGridSize.width();
   779     qreal cellHeight = size.height() / mGridSize.height();
   779     qreal cellHeight = size.height() / mGridSize.height();
   780 
   780 
   781     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   781     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   782       font.setPixelSize(int(fontSize(ButtonTextTypePrimary)));
   782     font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypePrimary)));
   783 
   783 
   784     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   784     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   785     QFontMetricsF fontMetrics(font);
   785     QFontMetricsF fontMetrics(font);
   786 
   786 
   787     // Create text line for each button with primary text and correct type and state. Layout it
   787     // Create text line for each button with primary text and correct type and state. Layout it
   788     // to correct position
   788     // to correct position
   789     mTextLayouts.at(index)->beginLayout();
   789     mTextLayouts.at(index)->beginLayout();
   790     foreach (HbInputButton *item, mButtonData) {
   790     foreach(HbInputButton *item, mButtonData) {
   791         int layoutIndex = item->type() * HbInputButton::ButtonStateCount + item->state();
   791         int layoutIndex = item->type() * HbInputButton::ButtonStateCount + item->state();
   792         if (!mEnabled) {
   792         if (!mEnabled) {
   793             layoutIndex = item->type() * HbInputButton::ButtonStateCount + HbInputButton::ButtonStateDisabled;
   793             layoutIndex = item->type() * HbInputButton::ButtonStateCount + HbInputButton::ButtonStateDisabled;
   794         }
   794         }
   795         if (index == layoutIndex && !item->text(HbInputButton::ButtonTextIndexPrimary).isEmpty() &&
   795         if (index == layoutIndex && !item->text(HbInputButton::ButtonTextIndexPrimary).isEmpty() &&
   796             item->icon(HbInputButton::ButtonIconIndexPrimary).isNull() &&
   796             item->icon(HbInputButton::ButtonIconIndexPrimary).isNull() &&
   797             !(item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow).isEmpty() &&
   797             !(item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow).isEmpty() &&
   798             item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull() &&
   798               item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull() &&
   799             item->text(HbInputButton::ButtonTextIndexSecondarySecondRow).isEmpty() &&
   799               item->text(HbInputButton::ButtonTextIndexSecondarySecondRow).isEmpty() &&
   800             item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull())) {
   800               item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull())) {
   801             qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexPrimary));
   801             qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexPrimary));
   802             qreal textHeight = fontMetrics.height();
   802             qreal textHeight = fontMetrics.height();
   803 
   803 
   804             QTextLine line = mTextLayouts.at(index)->createLine();
   804             QTextLine line = mTextLayouts.at(index)->createLine();
   805             line.setNumColumns(item->text(HbInputButton::ButtonTextIndexPrimary).length());
   805             line.setNumColumns(item->text(HbInputButton::ButtonTextIndexPrimary).length());
   806 
   806 
   807             layoutTextLine(ButtonTextTypePrimary, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   807             layoutTextLine(HbInputButtonGroup::ButtonTextTypePrimary, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   808         }
   808         }
   809     }
   809     }
   810     mTextLayouts.at(index)->endLayout();
   810     mTextLayouts.at(index)->endLayout();
   811     mTextLayouts.at(index)->setCacheEnabled(true);
   811     mTextLayouts.at(index)->setCacheEnabled(true);
   812 }
   812 }
   815 {
   815 {
   816     qreal cellWidth = size.width() / mGridSize.width();
   816     qreal cellWidth = size.width() / mGridSize.width();
   817     qreal cellHeight = size.height() / mGridSize.height();
   817     qreal cellHeight = size.height() / mGridSize.height();
   818 
   818 
   819     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   819     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   820       font.setPixelSize(int(fontSize(ButtonTextTypeSecondaryFirstRow)));
   820     font.setPixelSize(int(fontSize(HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow)));
   821 
   821 
   822     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   822     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   823     QFontMetricsF fontMetrics(font);
   823     QFontMetricsF fontMetrics(font);
   824 
   824 
   825     // Create text line for each button with secondary first row or second row text and correct type and state.
   825     // Create text line for each button with secondary first row or second row text and correct type and state.
   826     // Layout it to correct position
   826     // Layout it to correct position
   827     mTextLayouts.at(index)->beginLayout();
   827     mTextLayouts.at(index)->beginLayout();
   828     foreach (HbInputButton *item, mButtonData) {
   828     foreach(HbInputButton *item, mButtonData) {
   829         int layoutIndex = item->type() * HbInputButton::ButtonStateCount + item->state() + HbTextTypeCount * 2;
   829         int layoutIndex = item->type() * HbInputButton::ButtonStateCount + item->state() + HbTextTypeCount * 2;
   830         if (!mEnabled) {
   830         if (!mEnabled) {
   831             layoutIndex = item->type() * HbInputButton::ButtonStateCount + HbInputButton::ButtonStateDisabled + HbTextTypeCount * 2;
   831             layoutIndex = item->type() * HbInputButton::ButtonStateCount + HbInputButton::ButtonStateDisabled + HbTextTypeCount * 2;
   832         }
   832         }
   833         if (index == layoutIndex) {
   833         if (index == layoutIndex) {
   834             if (!item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow).isEmpty() && 
   834             if (!item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow).isEmpty() &&
   835                 item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull()) {
   835                 item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull()) {
   836                 qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow));
   836                 qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow));
   837                 qreal textHeight = fontMetrics.height();
   837                 qreal textHeight = fontMetrics.height();
   838 
   838 
   839                 QTextLine line = mTextLayouts.at(index)->createLine();
   839                 QTextLine line = mTextLayouts.at(index)->createLine();
   840                 line.setNumColumns(item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow).length());
   840                 line.setNumColumns(item->text(HbInputButton::ButtonTextIndexSecondaryFirstRow).length());
   841 
   841 
   842                 layoutTextLine(ButtonTextTypeSecondaryFirstRow, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   842                 layoutTextLine(HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   843             }
   843             }
   844 
   844 
   845             if (!item->text(HbInputButton::ButtonTextIndexSecondarySecondRow).isEmpty() && 
   845             if (!item->text(HbInputButton::ButtonTextIndexSecondarySecondRow).isEmpty() &&
   846                 item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull()) {
   846                 item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull()) {
   847                 qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexSecondarySecondRow));
   847                 qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexSecondarySecondRow));
   848                 qreal textHeight = fontMetrics.height();
   848                 qreal textHeight = fontMetrics.height();
   849 
   849 
   850                 QTextLine line = mTextLayouts.at(index)->createLine();
   850                 QTextLine line = mTextLayouts.at(index)->createLine();
   851                 line.setNumColumns(item->text(HbInputButton::ButtonTextIndexSecondarySecondRow).length());
   851                 line.setNumColumns(item->text(HbInputButton::ButtonTextIndexSecondarySecondRow).length());
   852 
   852 
   853                 layoutTextLine(ButtonTextTypeSecondarySecondRow, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   853                 layoutTextLine(HbInputButtonGroup::ButtonTextTypeSecondarySecondRow, item, QSizeF(cellWidth, cellHeight), line, QSizeF(textWidth, textHeight));
   854             }
   854             }
   855         }
   855         }
   856     }
   856     }
   857     mTextLayouts.at(index)->endLayout();
   857     mTextLayouts.at(index)->endLayout();
   858     mTextLayouts.at(index)->setCacheEnabled(true);
   858     mTextLayouts.at(index)->setCacheEnabled(true);
   859 }
   859 }
   860 
   860 
   861 void HbInputButtonGroupPrivate::layoutTextLine(HbInputButtonTextType textType, const HbInputButton *button, const QSizeF &cellSize,
   861 void HbInputButtonGroupPrivate::layoutTextLine(HbInputButtonGroup::HbInputButtonTextType textType, const HbInputButton *button, const QSizeF &cellSize,
   862                                                QTextLine &textLine, const QSizeF &textSize)
   862         QTextLine &textLine, const QSizeF &textSize)
   863 {
   863 {
   864     qreal textPositionX = 0.0;
   864     qreal textPositionX = 0.0;
   865     qreal textPositionY = 0.0;
   865     qreal textPositionY = 0.0;
   866     if (textType == ButtonTextTypeSingle ||
   866     if (textType == HbInputButtonGroup::ButtonTextTypeSingle ||
   867         textType == ButtonTextTypeLabel) {
   867         textType == HbInputButtonGroup::ButtonTextTypeLabel) {
   868         textPositionX = (button->position().x() + 0.5 * button->size().width()) * cellSize.width() - 0.5 * textSize.width();
   868         textPositionX = (button->position().x() + 0.5 * button->size().width()) * cellSize.width() - 0.5 * textSize.width();
   869         textPositionY = (button->position().y() + 0.5 * button->size().height()) * cellSize.height() - 0.5 * textSize.height();
   869         textPositionY = (button->position().y() + 0.5 * button->size().height()) * cellSize.height() - 0.5 * textSize.height();
   870     } else if (textType == ButtonTextTypePrimary) {
   870     } else if (textType == HbInputButtonGroup::ButtonTextTypePrimary) {
   871         textPositionX = button->position().x() * cellSize.width() + HbHorizontalMarginInUnits * mUnitValue + mButtonBorderSize;
   871         textPositionX = button->position().x() * cellSize.width() + HbHorizontalMarginInUnits * mUnitValue + mButtonBorderSize;
   872         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();
   873     } else if (textType == ButtonTextTypeSecondaryFirstRow) {
   873     } else if (textType == HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow) {
   874         textPositionX = (button->position().x() + button->size().width()) * cellSize.width() -
   874         textPositionX = (button->position().x() + button->size().width()) * cellSize.width() -
   875             textSize.width() - HbHorizontalMarginInUnits * mUnitValue - mButtonBorderSize;
   875                         textSize.width() - HbHorizontalMarginInUnits * mUnitValue - mButtonBorderSize;
   876         textPositionY = (button->position().y() + button->size().height()) * cellSize.height() -
   876         textPositionY = (button->position().y() + button->size().height()) * cellSize.height() -
   877             textSize.height() - HbVerticalMarginInUnits * mUnitValue - mButtonBorderSize;
   877                         textSize.height() - HbVerticalMarginInUnits * mUnitValue - mButtonBorderSize;
   878     } else if (textType == ButtonTextTypeSecondarySecondRow) {
   878     } else if (textType == HbInputButtonGroup::ButtonTextTypeSecondarySecondRow) {
   879         textPositionX = (button->position().x() + button->size().width()) * cellSize.width() -
   879         textPositionX = (button->position().x() + button->size().width()) * cellSize.width() -
   880             textSize.width() - HbHorizontalMarginInUnits * mUnitValue - mButtonBorderSize;
   880                         textSize.width() - HbHorizontalMarginInUnits * mUnitValue - mButtonBorderSize;
   881         textPositionY = button->position().y() * cellSize.height() + HbVerticalMarginInUnits * mUnitValue + mButtonBorderSize;
   881         textPositionY = button->position().y() * cellSize.height() + HbVerticalMarginInUnits * mUnitValue + mButtonBorderSize;
   882     }
   882     }
   883     textLine.setPosition(QPointF(textPositionX, textPositionY));
   883     textLine.setPosition(QPointF(textPositionX, textPositionY));
   884 }
   884 }
   885 
   885 
   939         }
   939         }
   940     }
   940     }
   941     return QString("");
   941     return QString("");
   942 }
   942 }
   943 
   943 
   944 qreal HbInputButtonGroupPrivate::fontSize(HbInputButtonTextType textType)
   944 qreal HbInputButtonGroupPrivate::fontSize(HbInputButtonGroup::HbInputButtonTextType textType)
   945 {
   945 {
   946     if (textType == ButtonTextTypeSingle) {
   946     if (textType == HbInputButtonGroup::ButtonTextTypeSingle) {
   947         return HbTextSizeInUnits * mUnitValue;
   947         return HbTextSizeInUnits * mUnitValue;
   948     } else if (textType == ButtonTextTypePrimary) {
   948     } else if (textType == HbInputButtonGroup::ButtonTextTypePrimary) {
   949         return HbPrimaryTextSizeInUnits * mUnitValue;
   949         return HbPrimaryTextSizeInUnits * mUnitValue;
   950     } else if (textType == ButtonTextTypeSecondaryFirstRow ||
   950     } else if (textType == HbInputButtonGroup::ButtonTextTypeSecondaryFirstRow ||
   951         textType == ButtonTextTypeSecondarySecondRow) {
   951                textType == HbInputButtonGroup::ButtonTextTypeSecondarySecondRow) {
   952         return HbSecondaryTextSizeInUnits * mUnitValue;
   952         return HbSecondaryTextSizeInUnits * mUnitValue;
   953     } else if (textType == ButtonTextTypeLabel) {
   953     } else if (textType == HbInputButtonGroup::ButtonTextTypeLabel) {
   954         return HbLabelTextSizeInUnits * mUnitValue;
   954         return HbLabelTextSizeInUnits * mUnitValue;
   955     }
   955     }
   956     return 0;
   956     return 0;
   957 }
   957 }
   958 
   958 
   991 
   991 
   992 /*!
   992 /*!
   993 Constructor
   993 Constructor
   994 */
   994 */
   995 HbInputButtonGroup::HbInputButtonGroup(QGraphicsItem *parent)
   995 HbInputButtonGroup::HbInputButtonGroup(QGraphicsItem *parent)
   996  : HbWidget(*new HbInputButtonGroupPrivate, parent)
   996     : HbWidget(*new HbInputButtonGroupPrivate, parent)
   997 {
   997 {
   998     Q_D(HbInputButtonGroup);
   998     Q_D(HbInputButtonGroup);
   999 
   999 
  1000     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1000     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1001 
  1001 
  1002     setAcceptedMouseButtons(Qt::LeftButton);
  1002     setAcceptedMouseButtons(Qt::LeftButton);
       
  1003     setFlag(QGraphicsItem::ItemHasNoContents,false);
  1003 }
  1004 }
  1004 
  1005 
  1005 /*!
  1006 /*!
  1006 Constructor
  1007 Constructor
  1007 */
  1008 */
  1008 HbInputButtonGroup::HbInputButtonGroup(HbInputButtonGroupPrivate &dd, QGraphicsItem *parent)
  1009 HbInputButtonGroup::HbInputButtonGroup(HbInputButtonGroupPrivate &dd, QGraphicsItem *parent)
  1009  : HbWidget(dd, parent)
  1010     : HbWidget(dd, parent)
  1010 {
  1011 {
  1011     Q_D(HbInputButtonGroup);
  1012     Q_D(HbInputButtonGroup);
  1012 
  1013 
  1013     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1014     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1014 
  1015 
  1015     setAcceptedMouseButtons(Qt::LeftButton);
  1016     setAcceptedMouseButtons(Qt::LeftButton);
       
  1017     setFlag(QGraphicsItem::ItemHasNoContents,false);
  1016 }
  1018 }
  1017 
  1019 
  1018 /*!
  1020 /*!
  1019 Constructor
  1021 Constructor
  1020 */
  1022 */
  1021 HbInputButtonGroup::HbInputButtonGroup(const QSize &size, QGraphicsItem *parent)
  1023 HbInputButtonGroup::HbInputButtonGroup(const QSize &size, QGraphicsItem *parent)
  1022  : HbWidget(*new HbInputButtonGroupPrivate, parent)
  1024     : HbWidget(*new HbInputButtonGroupPrivate, parent)
  1023 {
  1025 {
  1024     Q_D(HbInputButtonGroup);
  1026     Q_D(HbInputButtonGroup);
  1025 
  1027 
  1026     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1028     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1027 
  1029 
  1028     setAcceptedMouseButtons(Qt::LeftButton);
  1030     setAcceptedMouseButtons(Qt::LeftButton);
  1029     
  1031 
  1030     setGridSize(size);
  1032     setGridSize(size);
       
  1033     setFlag(QGraphicsItem::ItemHasNoContents,false);
  1031 }
  1034 }
  1032 
  1035 
  1033 /*!
  1036 /*!
  1034 Constructor
  1037 Constructor
  1035 */
  1038 */
  1036 HbInputButtonGroup::HbInputButtonGroup(HbInputButtonGroupPrivate &dd, const QSize &size, QGraphicsItem *parent)
  1039 HbInputButtonGroup::HbInputButtonGroup(HbInputButtonGroupPrivate &dd, const QSize &size, QGraphicsItem *parent)
  1037  : HbWidget(dd, parent)
  1040     : HbWidget(dd, parent)
  1038 {
  1041 {
  1039     Q_D(HbInputButtonGroup);
  1042     Q_D(HbInputButtonGroup);
  1040 
  1043 
  1041     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1044     d->mUnitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
  1042 
  1045 
  1043     setAcceptedMouseButtons(Qt::LeftButton);
  1046     setAcceptedMouseButtons(Qt::LeftButton);
  1044     
  1047 
  1045     setGridSize(size);
  1048     setGridSize(size);
       
  1049     setFlag(QGraphicsItem::ItemHasNoContents,false);
  1046 }
  1050 }
  1047 
  1051 
  1048 /*!
  1052 /*!
  1049 Destructor
  1053 Destructor
  1050 */
  1054 */
  1088     return d->mGridSize;
  1092     return d->mGridSize;
  1089 }
  1093 }
  1090 
  1094 
  1091 /*!
  1095 /*!
  1092 Sets the button data and updates button group based on the new data.
  1096 Sets the button data and updates button group based on the new data.
  1093 Takes ownership of the button items. Button items that are not in the new list 
  1097 Takes ownership of the button items. Button items that are not in the new list
  1094 will be destroyed.
  1098 will be destroyed.
  1095 
  1099 
  1096 \sa buttons
  1100 \sa buttons
  1097 \sa button
  1101 \sa button
  1098 */
  1102 */
  1099 void HbInputButtonGroup::setButtons(const QList<HbInputButton*> &data)
  1103 void HbInputButtonGroup::setButtons(const QList<HbInputButton *> &data)
  1100 {
  1104 {
  1101     Q_D(HbInputButtonGroup);
  1105     Q_D(HbInputButtonGroup);
  1102 
  1106 
  1103     foreach (HbInputButton *button, d->mButtonData) {
  1107     foreach(HbInputButton *button, d->mButtonData) {
  1104         if (!data.contains(button)) {
  1108         if (!data.contains(button)) {
  1105             delete button;
  1109             delete button;
  1106         }
  1110         }
  1107     }
  1111     }
  1108     d->mButtonData = data;
  1112     d->mButtonData = data;
  1184         HbInputButton *item = d->mButtonData.at(index);
  1188         HbInputButton *item = d->mButtonData.at(index);
  1185         if (item->keyCode() == keyCode) {
  1189         if (item->keyCode() == keyCode) {
  1186             break;
  1190             break;
  1187         }
  1191         }
  1188     }
  1192     }
  1189     
  1193 
  1190     setButton(data, index);
  1194     setButton(data, index);
  1191 }
  1195 }
  1192 
  1196 
  1193 /*!
  1197 /*!
  1194 Returns button data.
  1198 Returns button data.
  1195 Ownership of the returned button items is not transferred.
  1199 Ownership of the returned button items is not transferred.
  1196 
  1200 
  1197 \sa setButtons
  1201 \sa setButtons
  1198 \sa setButton
  1202 \sa setButton
  1199 */
  1203 */
  1200 QList<HbInputButton*> HbInputButtonGroup::buttons() const
  1204 QList<HbInputButton *> HbInputButtonGroup::buttons() const
  1201 {
  1205 {
  1202     Q_D(const HbInputButtonGroup);
  1206     Q_D(const HbInputButtonGroup);
  1203 
  1207 
  1204     return d->mButtonData;
  1208     return d->mButtonData;
  1205 }
  1209 }
  1229 \sa setButton
  1233 \sa setButton
  1230 */
  1234 */
  1231 HbInputButton *HbInputButtonGroup::button(int column, int row) const
  1235 HbInputButton *HbInputButtonGroup::button(int column, int row) const
  1232 {
  1236 {
  1233     Q_D(const HbInputButtonGroup);
  1237     Q_D(const HbInputButtonGroup);
  1234     
  1238 
  1235     int index = -1;
  1239     int index = -1;
  1236     if (d->mButtonGridPositions.contains(QPair<int, int>(column, row))) {
  1240     if (d->mButtonGridPositions.contains(QPair<int, int>(column, row))) {
  1237         index = d->mButtonGridPositions.value(QPair<int, int>(column, row), -1);
  1241         index = d->mButtonGridPositions.value(QPair<int, int>(column, row), -1);
  1238     }
  1242     }
  1239     return button(index);
  1243     return button(index);
  1248 */
  1252 */
  1249 HbInputButton *HbInputButtonGroup::button(HbInputButton::HbInputButtonKeyCode keyCode) const
  1253 HbInputButton *HbInputButtonGroup::button(HbInputButton::HbInputButtonKeyCode keyCode) const
  1250 {
  1254 {
  1251     Q_D(const HbInputButtonGroup);
  1255     Q_D(const HbInputButtonGroup);
  1252 
  1256 
  1253     foreach (HbInputButton *button, d->mButtonData) {
  1257     foreach(HbInputButton *button, d->mButtonData) {
  1254         if (button->keyCode() == keyCode) {
  1258         if (button->keyCode() == keyCode) {
  1255             return button;
  1259             return button;
  1256         }
  1260         }
  1257     }
  1261     }
  1258     return 0;
  1262     return 0;
  1263 are mapped to buttons which keycode is equal or bigger than HbInputButtonKeyCustom.
  1267 are mapped to buttons which keycode is equal or bigger than HbInputButtonKeyCustom.
  1264 Ownership of the actions is not transferred.
  1268 Ownership of the actions is not transferred.
  1265 
  1269 
  1266 \sa customButtonActions
  1270 \sa customButtonActions
  1267 */
  1271 */
  1268 void HbInputButtonGroup::setCustomButtonActions(const QList<HbAction*> &actions)
  1272 void HbInputButtonGroup::setCustomButtonActions(const QList<HbAction *> &actions)
  1269 {
  1273 {
  1270     Q_D(HbInputButtonGroup);
  1274     Q_D(HbInputButtonGroup);
  1271 
  1275 
  1272     disconnect(this, SLOT(updateCustomButtons()));
  1276     disconnect(this, SLOT(updateCustomButtons()));
  1273     disconnect(this, SLOT(_q_customActionDestroyed(QObject *)));
  1277     disconnect(this, SLOT(_q_customActionDestroyed(QObject *)));
  1274 
  1278 
  1275     d->mCustomActions = actions;
  1279     d->mCustomActions = actions;
  1276 
  1280 
  1277     foreach (HbAction *action, d->mCustomActions) {
  1281     foreach(HbAction *action, d->mCustomActions) {
  1278         connect(action, SIGNAL(changed()), this, SLOT(updateCustomButtons()));
  1282         connect(action, SIGNAL(changed()), this, SLOT(updateCustomButtons()));
  1279         connect(action, SIGNAL(destroyed(QObject *)), this, SLOT(_q_customActionDestroyed(QObject *)));
  1283         connect(action, SIGNAL(destroyed(QObject *)), this, SLOT(_q_customActionDestroyed(QObject *)));
  1280     }
  1284     }
  1281 
  1285 
  1282     d->updateCustomActions();
  1286     d->updateCustomActions();
  1289 Returns current custom actions.
  1293 Returns current custom actions.
  1290 Ownership of the actions is not transferred.
  1294 Ownership of the actions is not transferred.
  1291 
  1295 
  1292 \sa setCustomButtonActions
  1296 \sa setCustomButtonActions
  1293 */
  1297 */
  1294 QList<HbAction*> HbInputButtonGroup::customButtonActions() const
  1298 QList<HbAction *> HbInputButtonGroup::customButtonActions() const
  1295 {
  1299 {
  1296     Q_D(const HbInputButtonGroup);
  1300     Q_D(const HbInputButtonGroup);
  1297 
  1301 
  1298     return d->mCustomActions;
  1302     return d->mCustomActions;
  1299 }
  1303 }
  1405 \sa setMultiTouchEnabled
  1409 \sa setMultiTouchEnabled
  1406 */
  1410 */
  1407 bool HbInputButtonGroup::isMultiTouchEnabled() const
  1411 bool HbInputButtonGroup::isMultiTouchEnabled() const
  1408 {
  1412 {
  1409     Q_D(const HbInputButtonGroup);
  1413     Q_D(const HbInputButtonGroup);
  1410     
  1414 
  1411     return d->mMultiTouchEnabled;
  1415     return d->mMultiTouchEnabled;
  1412 }
  1416 }
  1413 
  1417 
  1414 /*!
  1418 /*!
  1415 Sets button group background graphics.
  1419 Sets button group background graphics.
  1419 {
  1423 {
  1420     Q_D(HbInputButtonGroup);
  1424     Q_D(HbInputButtonGroup);
  1421 
  1425 
  1422     HbFrameDrawerPool::release(d->mBackground);
  1426     HbFrameDrawerPool::release(d->mBackground);
  1423     d->mBackground = background;
  1427     d->mBackground = background;
       
  1428 }
       
  1429 
       
  1430 /*!
       
  1431 Returns font size for given text type
       
  1432 */
       
  1433 qreal HbInputButtonGroup::fontSize(HbInputButtonTextType textType)
       
  1434 {
       
  1435     Q_D(HbInputButtonGroup);
       
  1436 
       
  1437     return d->fontSize(textType);
  1424 }
  1438 }
  1425 
  1439 
  1426 /*!
  1440 /*!
  1427 Returns all possible buttons the user could have intended to press
  1441 Returns all possible buttons the user could have intended to press
  1428 for the last registered touch along with their corresponding probabilities.
  1442 for the last registered touch along with their corresponding probabilities.
  1462 }
  1476 }
  1463 
  1477 
  1464 /*!
  1478 /*!
  1465 Draws the button group.
  1479 Draws the button group.
  1466 */
  1480 */
  1467 void HbInputButtonGroup::paint(QPainter* painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  1481 void HbInputButtonGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  1468 {
  1482 {
  1469     Q_UNUSED(option);
  1483     Q_UNUSED(option);
  1470     Q_UNUSED(widget);
  1484     Q_UNUSED(widget);
  1471 
  1485 
  1472     Q_D(HbInputButtonGroup);
  1486     Q_D(HbInputButtonGroup);
  1487             qreal width = item->size().width() * cellWidth - 2 * d->mButtonBorderSize;
  1501             qreal width = item->size().width() * cellWidth - 2 * d->mButtonBorderSize;
  1488             qreal height = item->size().height() * cellHeight - 2 * d->mButtonBorderSize;
  1502             qreal height = item->size().height() * cellHeight - 2 * d->mButtonBorderSize;
  1489 
  1503 
  1490             painter->save();
  1504             painter->save();
  1491             painter->translate(x, y);
  1505             painter->translate(x, y);
  1492             d->mButtonDrawers.at(i)->paint(painter, QRectF(0, 0, width, height));        
  1506             d->mButtonDrawers.at(i)->paint(painter, QRectF(0, 0, width, height));
  1493             painter->restore();
  1507             painter->restore();
  1494         }
  1508         }
  1495 
  1509 
  1496         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
  1510         if (!item->icon(HbInputButton::ButtonIconIndexPrimary).isNull()) {
  1497             qreal x = item->position().x() * cellWidth;
  1511             qreal x = item->position().x() * cellWidth;
  1511             item->icon(HbInputButton::ButtonIconIndexPrimary).paint(painter, QRectF(x, y, width, height));
  1525             item->icon(HbInputButton::ButtonIconIndexPrimary).paint(painter, QRectF(x, y, width, height));
  1512         }
  1526         }
  1513 
  1527 
  1514         if (!item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull()) {
  1528         if (!item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).isNull()) {
  1515             qreal x = (item->position().x() + item->size().width()) * cellWidth -
  1529             qreal x = (item->position().x() + item->size().width()) * cellWidth -
  1516                 HbSecondaryIconSizeInUnits * d->mUnitValue - HbHorizontalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1530                       HbSecondaryIconSizeInUnits * d->mUnitValue - HbHorizontalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1517             qreal y = (item->position().y() + item->size().height()) * cellHeight -
  1531             qreal y = (item->position().y() + item->size().height()) * cellHeight -
  1518                 HbSecondaryIconSizeInUnits * d->mUnitValue - HbVerticalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1532                       HbSecondaryIconSizeInUnits * d->mUnitValue - HbVerticalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1519             qreal width = HbSecondaryIconSizeInUnits * d->mUnitValue;
  1533             qreal width = HbSecondaryIconSizeInUnits * d->mUnitValue;
  1520             qreal height = HbSecondaryIconSizeInUnits * d->mUnitValue;
  1534             qreal height = HbSecondaryIconSizeInUnits * d->mUnitValue;
  1521 
  1535 
  1522             Qt::Alignment alignment = static_cast<Qt::Alignment>(Qt::AlignVCenter | Qt::AlignRight);
  1536             Qt::Alignment alignment = static_cast<Qt::Alignment>(Qt::AlignVCenter | Qt::AlignRight);
  1523             item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).paint(painter, QRectF(x, y, width, height), Qt::KeepAspectRatio, alignment);
  1537             item->icon(HbInputButton::ButtonIconIndexSecondaryFirstRow).paint(painter, QRectF(x, y, width, height), Qt::KeepAspectRatio, alignment);
  1524         }
  1538         }
  1525 
  1539 
  1526         if (!item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull()) {
  1540         if (!item->icon(HbInputButton::ButtonIconIndexSecondarySecondRow).isNull()) {
  1527             qreal x = (item->position().x() + item->size().width()) * cellWidth -
  1541             qreal x = (item->position().x() + item->size().width()) * cellWidth -
  1528                 HbSecondaryIconSizeInUnits * d->mUnitValue - HbHorizontalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1542                       HbSecondaryIconSizeInUnits * d->mUnitValue - HbHorizontalMarginInUnits * d->mUnitValue - d->mButtonBorderSize;
  1529             qreal y = item->position().y() * cellHeight + HbVerticalMarginInUnits * d->mUnitValue + d->mButtonBorderSize;
  1543             qreal y = item->position().y() * cellHeight + HbVerticalMarginInUnits * d->mUnitValue + d->mButtonBorderSize;
  1530             qreal width = HbSecondaryIconSizeInUnits * d->mUnitValue;
  1544             qreal width = HbSecondaryIconSizeInUnits * d->mUnitValue;
  1531             qreal height = HbSecondaryIconSizeInUnits * d->mUnitValue;
  1545             qreal height = HbSecondaryIconSizeInUnits * d->mUnitValue;
  1532 
  1546 
  1533             Qt::Alignment alignment = static_cast<Qt::Alignment>(Qt::AlignVCenter | Qt::AlignRight);
  1547             Qt::Alignment alignment = static_cast<Qt::Alignment>(Qt::AlignVCenter | Qt::AlignRight);
  1560         event->ignore();
  1574         event->ignore();
  1561         return false;
  1575         return false;
  1562     }
  1576     }
  1563 
  1577 
  1564     if (event->type() == QEvent::TouchBegin) {
  1578     if (event->type() == QEvent::TouchBegin) {
  1565         QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event);
  1579         QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
  1566         foreach (QTouchEvent::TouchPoint point, touchEvent->touchPoints()) {
  1580         foreach(const QTouchEvent::TouchPoint &point, touchEvent->touchPoints()) {
  1567             if (!point.isPrimary() && d->mMultiTouchEnabled) {         
  1581             if (!point.isPrimary() && d->mMultiTouchEnabled) {
  1568                 d->pressEvent(point.pos());
  1582                 d->pressEvent(point.pos());
  1569             }
  1583             }
  1570         }
  1584         }
  1571     } else if (event->type() == QEvent::TouchUpdate) {
  1585     } else if (event->type() == QEvent::TouchUpdate) {
  1572         QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event);
  1586         QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
  1573         foreach (QTouchEvent::TouchPoint point, touchEvent->touchPoints()) {
  1587         foreach(const QTouchEvent::TouchPoint &point, touchEvent->touchPoints()) {
  1574             if (!point.isPrimary() && d->mMultiTouchEnabled) {
  1588             if (!point.isPrimary() && d->mMultiTouchEnabled) {
  1575                 if (point.state() & Qt::TouchPointPressed) {
  1589                 if (point.state() & Qt::TouchPointPressed) {
  1576                     d->pressEvent(point.pos());
  1590                     d->pressEvent(point.pos());
  1577                 } else if (point.state() & Qt::TouchPointMoved) {
  1591                 } else if (point.state() & Qt::TouchPointMoved) {
  1578                     d->moveEvent(point.lastPos(), point.pos());
  1592                     d->moveEvent(point.lastPos(), point.pos());
  1580                     d->releaseEvent(point.pos());
  1594                     d->releaseEvent(point.pos());
  1581                 }
  1595                 }
  1582             }
  1596             }
  1583         }
  1597         }
  1584     } else if (event->type() == QEvent::TouchEnd) {
  1598     } else if (event->type() == QEvent::TouchEnd) {
  1585         QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event);
  1599         QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
  1586         foreach (QTouchEvent::TouchPoint point, touchEvent->touchPoints()) {
  1600         foreach(const QTouchEvent::TouchPoint &point, touchEvent->touchPoints()) {
  1587             if (!point.isPrimary() && d->mMultiTouchEnabled) {  
  1601             if (!point.isPrimary() && d->mMultiTouchEnabled) {
  1588                 d->releaseEvent(point.pos());
  1602                 d->releaseEvent(point.pos());
  1589             }
  1603             }
  1590         }
  1604         }
  1591     } else if (event->type() == QEvent::GraphicsSceneMousePress) {
  1605     } else if (event->type() == QEvent::GraphicsSceneMousePress) {
  1592         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);
  1606         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1593         d->pressEvent(mouseEvent->pos());
  1607         d->pressEvent(mouseEvent->pos());
  1594     } else if (event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
  1608     } else if (event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
  1595         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);
  1609         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1596         d->doublePressEvent(mouseEvent->pos());
  1610         d->doublePressEvent(mouseEvent->pos());
  1597     } else if (event->type() == QEvent::GraphicsSceneMouseMove) {
  1611     } else if (event->type() == QEvent::GraphicsSceneMouseMove) {
  1598         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);
  1612         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1599         d->moveEvent(mouseEvent->lastPos(), mouseEvent->pos());
  1613         d->moveEvent(mouseEvent->lastPos(), mouseEvent->pos());
  1600     } else if (event->type() == QEvent::GraphicsSceneMouseRelease) {
  1614     } else if (event->type() == QEvent::GraphicsSceneMouseRelease) {
  1601         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);
  1615         QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
  1602         d->releaseEvent(mouseEvent->pos());
  1616         d->releaseEvent(mouseEvent->pos());
  1603         cancelButtonPress();
  1617         cancelButtonPress();
  1604     } else {
  1618     } else {
  1605         return HbWidget::event(event);
  1619         return HbWidget::event(event);
  1606     }
  1620     }
  1630 Updates theme graphics
  1644 Updates theme graphics
  1631  */
  1645  */
  1632 void HbInputButtonGroup::changeEvent(QEvent *event)
  1646 void HbInputButtonGroup::changeEvent(QEvent *event)
  1633 {
  1647 {
  1634     Q_D(HbInputButtonGroup);
  1648     Q_D(HbInputButtonGroup);
  1635    
  1649 
  1636     if (event->type() == HbEvent::ThemeChanged) {
  1650     if (event->type() == HbEvent::ThemeChanged) {
  1637         if (d->mBackground) {
  1651         if (d->mBackground) {
  1638             d->mBackground->themeChanged();
  1652             d->mBackground->themeChanged();
  1639         }
  1653         }
  1640 
  1654 
  1641         foreach (HbFrameDrawer *drawer, d->mButtonDrawers) {
  1655         foreach(HbFrameDrawer *drawer, d->mButtonDrawers) {
  1642             drawer->themeChanged();
  1656             drawer->themeChanged();
  1643         }
  1657         }
  1644 
  1658 
  1645         d->updateColorArray();
  1659         d->updateColorArray();
  1646 
  1660