src/hbinput/inputwidgets/hbinputbuttongroup.cpp
changeset 3 11d3954df52a
parent 2 06ff229162e9
child 5 627c4a0fd0e7
equal deleted inserted replaced
2:06ff229162e9 3:11d3954df52a
    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 
    25 
       
    26 #include <QDebug>
    26 #include <QPainter>
    27 #include <QPainter>
    27 #include <QTextLayout>
    28 #include <QTextLayout>
    28 #include <QGraphicsSceneMouseEvent>
    29 #include <QGraphicsSceneMouseEvent>
    29 #include <QTouchEvent>
    30 #include <QTouchEvent>
    30 #include <QTimer>
    31 #include <QTimer>
    31 #include <QGraphicsDropShadowEffect>
       
    32 
    32 
    33 #include <hbmainwindow.h>
    33 #include <hbmainwindow.h>
    34 #include <hbaction.h>
    34 #include <hbaction.h>
    35 #include <hbevent.h>
    35 #include <hbevent.h>
    36 #include <hbcolorscheme.h>
    36 #include <hbcolorscheme.h>
   326 
   326 
   327         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   327         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   328         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   328         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   329 
   329 
   330         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   330         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   331         font.setPixelSize(fontSize(ButtonTextTypeLabel));
   331 	  font.setPixelSize(int(fontSize(ButtonTextTypeLabel)));
   332         QFontMetricsF fontMetrics(font);
   332         QFontMetricsF fontMetrics(font);
   333         qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexPrimary));
   333         qreal textWidth = fontMetrics.width(item->text(HbInputButton::ButtonTextIndexPrimary));
   334 
   334 
   335         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue;
   335         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue;
   336         if (width < HbPreviewWidthInUnits * mUnitValue) {
   336         if (width < HbPreviewWidthInUnits * mUnitValue) {
   346         qreal y = item->position().y() * cellHeight - height;
   346         qreal y = item->position().y() * cellHeight - height;
   347         group->setGeometry(QRectF(x, y, width, height));
   347         group->setGeometry(QRectF(x, y, width, height));
   348         if (q->parentItem()) {
   348         if (q->parentItem()) {
   349             group->setZValue(q->parentItem()->zValue() + 1);
   349             group->setZValue(q->parentItem()->zValue() + 1);
   350         }
   350         }
   351         
       
   352         QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
       
   353         effect->setBlurRadius(8);
       
   354         group->setGraphicsEffect(effect);
       
   355 
   351 
   356         group->setButtonBorderSize(0);
   352         group->setButtonBorderSize(0);
   357         HbFrameDrawer *drawer = HbFrameDrawerPool::get(HbPreviewBackground, HbFrameDrawer::ThreePiecesHorizontal, QSizeF(width, height));
   353         HbFrameDrawer *drawer = HbFrameDrawerPool::get(HbPreviewBackground, HbFrameDrawer::ThreePiecesHorizontal, QSizeF(width, height));
   358         drawer->setFillWholeRect(true);
   354         drawer->setFillWholeRect(true);
   359         group->setBackground(drawer);
   355         group->setBackground(drawer);
   387             mCharacterSelectionPreview->setDismissPolicy(HbPopup::TapAnywhere);
   383             mCharacterSelectionPreview->setDismissPolicy(HbPopup::TapAnywhere);
   388             mCharacterSelectionPreview->setFlag(QGraphicsItem::ItemIsPanel, true);
   384             mCharacterSelectionPreview->setFlag(QGraphicsItem::ItemIsPanel, true);
   389             mCharacterSelectionPreview->setActive(false);
   385             mCharacterSelectionPreview->setActive(false);
   390             qreal margin = HbPreviewMarginInUnits * mUnitValue * 0.5;
   386             qreal margin = HbPreviewMarginInUnits * mUnitValue * 0.5;
   391             mCharacterSelectionPreview->setContentsMargins(margin, 0, margin, 0);
   387             mCharacterSelectionPreview->setContentsMargins(margin, 0, margin, 0);
   392             QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
       
   393             effect->setBlurRadius(8);
       
   394             mCharacterSelectionPreview->setGraphicsEffect(effect);
       
   395         }
   388         }
   396 
   389 
   397         HbInputButtonGroup *group = new HbInputButtonGroup(QSize(item->mappedCharacters().count(), 1));
   390         HbInputButtonGroup *group = new HbInputButtonGroup(QSize(item->mappedCharacters().count(), 1));
   398         QObject::connect(group, SIGNAL(buttonPressed(const QKeyEvent&)), q, SLOT(emitButtonPressed(const QKeyEvent&)));
   391         QObject::connect(group, SIGNAL(buttonPressed(const QKeyEvent&)), q, SLOT(emitButtonPressed(const QKeyEvent&)));
   399         QObject::connect(group, SIGNAL(buttonDoublePressed(const QKeyEvent&)), q, SLOT(emitButtonDoublePressed(const QKeyEvent&)));
   392         QObject::connect(group, SIGNAL(buttonDoublePressed(const QKeyEvent&)), q, SLOT(emitButtonDoublePressed(const QKeyEvent&)));
   403         
   396         
   404         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   397         qreal cellWidth = q->boundingRect().width() / mGridSize.width();
   405         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   398         qreal cellHeight = q->boundingRect().height() / mGridSize.height();
   406 
   399 
   407         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   400         QFont font = HbFontSpec(HbFontSpec::Primary).font();
   408         font.setPixelSize(fontSize(ButtonTextTypeLabel));
   401 	  font.setPixelSize(int(fontSize(ButtonTextTypeLabel)));
   409         QFontMetricsF fontMetrics(font);
   402         QFontMetricsF fontMetrics(font);
   410         qreal textWidth = fontMetrics.width(item->mappedCharacters());
   403         qreal textWidth = fontMetrics.width(item->mappedCharacters());
   411 
   404 
   412         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue * item->mappedCharacters().count();
   405         qreal width = textWidth + HbPreviewMarginInUnits * mUnitValue * item->mappedCharacters().count();
   413         qreal height = HbPreviewHeightInUnits * mUnitValue;
   406         qreal height = HbPreviewHeightInUnits * mUnitValue;
   721 
   714 
   722     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   715     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   723 
   716 
   724     int typeIndex = index % HbTextTypeCount / HbInputButton::ButtonStateCount;
   717     int typeIndex = index % HbTextTypeCount / HbInputButton::ButtonStateCount;
   725     if (typeIndex == HbInputButton::ButtonTypeLabel) {
   718     if (typeIndex == HbInputButton::ButtonTypeLabel) {
   726         font.setPixelSize(fontSize(ButtonTextTypeLabel));
   719       font.setPixelSize(int(fontSize(ButtonTextTypeLabel)));
   727     } else {
   720     } else {
   728         font.setPixelSize(fontSize(ButtonTextTypeSingle));
   721       font.setPixelSize(int(fontSize(ButtonTextTypeSingle)));
   729     }
   722     }
   730 
   723 
   731     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   724     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   732     QFontMetricsF fontMetrics(font);
   725     QFontMetricsF fontMetrics(font);
   733 
   726 
   766 {
   759 {
   767     qreal cellWidth = size.width() / mGridSize.width();
   760     qreal cellWidth = size.width() / mGridSize.width();
   768     qreal cellHeight = size.height() / mGridSize.height();
   761     qreal cellHeight = size.height() / mGridSize.height();
   769 
   762 
   770     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   763     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   771     font.setPixelSize(fontSize(ButtonTextTypePrimary));
   764       font.setPixelSize(int(fontSize(ButtonTextTypePrimary)));
   772 
   765 
   773     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   766     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   774     QFontMetricsF fontMetrics(font);
   767     QFontMetricsF fontMetrics(font);
   775 
   768 
   776     // Create text line for each button with primary text and correct type and state. Layout it
   769     // Create text line for each button with primary text and correct type and state. Layout it
   804 {
   797 {
   805     qreal cellWidth = size.width() / mGridSize.width();
   798     qreal cellWidth = size.width() / mGridSize.width();
   806     qreal cellHeight = size.height() / mGridSize.height();
   799     qreal cellHeight = size.height() / mGridSize.height();
   807 
   800 
   808     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   801     QFont font = HbFontSpec(HbFontSpec::Primary).font();
   809     font.setPixelSize(fontSize(ButtonTextTypeSecondaryFirstRow));
   802       font.setPixelSize(int(fontSize(ButtonTextTypeSecondaryFirstRow)));
   810 
   803 
   811     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   804     mTextLayouts[index] = new QTextLayout(textContent.value(index), font);
   812     QFontMetricsF fontMetrics(font);
   805     QFontMetricsF fontMetrics(font);
   813 
   806 
   814     // Create text line for each button with secondary first row or second row text and correct type and state.
   807     // Create text line for each button with secondary first row or second row text and correct type and state.
  1116             d->mButtonData.replace(index, data);
  1109             d->mButtonData.replace(index, data);
  1117         } else {
  1110         } else {
  1118             d->mButtonData.removeAt(index);
  1111             d->mButtonData.removeAt(index);
  1119         }
  1112         }
  1120     } else {
  1113     } else {
  1121         d->mButtonData.append(data);
  1114         if (data) {
       
  1115             d->mButtonData.append(data);
       
  1116         }
  1122     }
  1117     }
  1123     setButtons(d->mButtonData);
  1118     setButtons(d->mButtonData);
  1124 }
  1119 }
  1125 
  1120 
  1126 /*!
  1121 /*!
  1134 */
  1129 */
  1135 void HbInputButtonGroup::setButton(HbInputButton *data, int column, int row)
  1130 void HbInputButtonGroup::setButton(HbInputButton *data, int column, int row)
  1136 {
  1131 {
  1137     Q_D(HbInputButtonGroup);
  1132     Q_D(HbInputButtonGroup);
  1138 
  1133 
  1139     int index = d->mButtonGridPositions.value(QPair<int, int>(column, row));
  1134     int index = -1;
       
  1135     if (d->mButtonGridPositions.contains(QPair<int, int>(column, row))) {
       
  1136         index = d->mButtonGridPositions.value(QPair<int, int>(column, row));
       
  1137     }
  1140     setButton(data, index);
  1138     setButton(data, index);
  1141 }
  1139 }
  1142 
  1140 
  1143 /*!
  1141 /*!
  1144 Sets the button item and updates button group based on the new data.
  1142 Sets the button item and updates button group based on the new data.
  1205 */
  1203 */
  1206 HbInputButton *HbInputButtonGroup::button(int column, int row) const
  1204 HbInputButton *HbInputButtonGroup::button(int column, int row) const
  1207 {
  1205 {
  1208     Q_D(const HbInputButtonGroup);
  1206     Q_D(const HbInputButtonGroup);
  1209     
  1207     
  1210     int index = d->mButtonGridPositions.value(QPair<int, int>(column, row));
  1208     int index = -1;
       
  1209     if (d->mButtonGridPositions.contains(QPair<int, int>(column, row))) {
       
  1210         index = d->mButtonGridPositions.value(QPair<int, int>(column, row));
       
  1211     }
  1211     return button(index);
  1212     return button(index);
  1212 }
  1213 }
  1213 
  1214 
  1214 /*!
  1215 /*!
  1215 Returns button data.
  1216 Returns button data.