telutils/dialpad/src/dialpadnumericbuttongrid.cpp
changeset 52 d841fb1cc818
parent 50 2313cb430f28
child 51 12bc758d6a02
equal deleted inserted replaced
50:2313cb430f28 52:d841fb1cc818
   133             int keyCode = DialpadKeyCodeTable[i];
   133             int keyCode = DialpadKeyCodeTable[i];
   134 
   134 
   135             if (keyCode == Qt::Key_Asterisk) {
   135             if (keyCode == Qt::Key_Asterisk) {
   136                 // asterisk is not localized
   136                 // asterisk is not localized
   137                 QChar asterisk('*');
   137                 QChar asterisk('*');
   138                 button(i)->setText(asterisk);
   138                 button(i)->setPrimaryLabel(asterisk);
   139                 button(i)->setSecondaryText(QLatin1String("+"));
   139                 button(i)->setSecondaryLabel(QLatin1String("+"));
   140                 mGeneratedChar.insert(Qt::Key_Asterisk, asterisk);
   140                 mGeneratedChar.insert(Qt::Key_Asterisk, asterisk);
   141                 continue;
   141                 continue;
   142             }
   142             }
   143 
   143 
   144             if (keyCode == Qt::Key_NumberSign) {
   144             if (keyCode == Qt::Key_NumberSign) {
   145                 // number sign is not localized
   145                 // number sign is not localized
   146                 QChar numberSign('#');
   146                 QChar numberSign('#');
   147                 button(i)->setText(numberSign);
   147                 button(i)->setPrimaryLabel(numberSign);
   148                 mGeneratedChar.insert(Qt::Key_NumberSign, numberSign);
   148                 mGeneratedChar.insert(Qt::Key_NumberSign, numberSign);
   149                 continue;
   149                 continue;
   150             }
   150             }
   151 
   151 
   152             int index = i;
   152             int index = i;
   170             } else {
   170             } else {
   171                 // fallback to latin
   171                 // fallback to latin
   172                 numberChar = QChar(keyCode);
   172                 numberChar = QChar(keyCode);
   173             }
   173             }
   174 
   174 
   175             button(i)->setText(numberChar);
   175             button(i)->setPrimaryLabel(numberChar);
   176             mGeneratedChar.insert(keyCode,numberChar);
   176             mGeneratedChar.insert(keyCode,numberChar);
   177 
   177 
   178             //
   178             //
   179             // set alphabets
   179             // set alphabets
   180             //
   180             //
   181             if (keyLabels && keyLabels->chars.count()>=2) {
   181             if (keyLabels && keyLabels->chars.count()>=2) {
   182                 button(i)->setSecondaryText(keyLabels->chars.at(1));
   182                 button(i)->setSecondaryLabel(keyLabels->chars.at(1));
   183                 if (keyLabels->chars.count()>=4) {
   183                 if (keyLabels->chars.count()>=4) {
   184                     button(i)->setSecondary2ndRowText(keyLabels->chars.at(3));
   184                     button(i)->setSecondaryLabelRow2(keyLabels->chars.at(3));
   185                 } else {
   185                 } else {
   186                     button(i)->setSecondary2ndRowText(QString());
   186                     button(i)->setSecondaryLabelRow2(QString());
   187                 }
   187                 }
   188             }
   188             }
   189         }
   189         }
   190 
   190 
   191         updateButtonLabels();
   191         updateButtonLabels();
   358     useTwoRows = false;
   358     useTwoRows = false;
   359 
   359 
   360     for (int i = 0; i < (DialpadRowCount*DialpadColumnCount); i++) {
   360     for (int i = 0; i < (DialpadRowCount*DialpadColumnCount); i++) {
   361         DialpadNumericButton *item = button(i);
   361         DialpadNumericButton *item = button(i);
   362         if (item->state()==HbInputButton::ButtonStatePressed) {
   362         if (item->state()==HbInputButton::ButtonStatePressed) {
   363             if (item->text().length()) {
   363             if (item->primaryLabel().length()) {
   364                 pressedState.append(item->text());
   364                 pressedState.append(item->primaryLabel());
   365                 pressedState.append(QChar(QChar::LineSeparator));
   365                 pressedState.append(QChar(QChar::LineSeparator));
   366             }
   366             }
   367 
   367 
   368             if (item->secondaryText().length()) {
   368             if (item->secondaryLabel().length()) {
   369                 pressedStateSecondary.append(item->secondaryText());
   369                 pressedStateSecondary.append(item->secondaryLabel());
   370                 pressedStateSecondary.append(QChar(QChar::LineSeparator));
   370                 pressedStateSecondary.append(QChar(QChar::LineSeparator));
   371                 if (item->secondary2ndRowText().length()) {
   371                 if (item->secondaryLabelRow2().length()) {
   372                     pressedStateSecondary.append(item->secondary2ndRowText());
   372                     pressedStateSecondary.append(item->secondaryLabelRow2());
   373                     pressedStateSecondary.append(QChar(QChar::LineSeparator));
   373                     pressedStateSecondary.append(QChar(QChar::LineSeparator));
   374                     useTwoRows = true;
   374                     useTwoRows = true;
   375                 }
   375                 }
   376             }
   376             }
   377         } else { // ButtonStateNormal
   377         } else { // ButtonStateNormal
   378             if (item->text().length()) {
   378             if (item->primaryLabel().length()) {
   379                 normalState.append(item->text());
   379                 normalState.append(item->primaryLabel());
   380                 normalState.append(QChar(QChar::LineSeparator));
   380                 normalState.append(QChar(QChar::LineSeparator));
   381             }
   381             }
   382 
   382 
   383             if (item->secondaryText().length()) {
   383             if (item->secondaryLabel().length()) {
   384                 normalStateSecondary.append(item->secondaryText());
   384                 normalStateSecondary.append(item->secondaryLabel());
   385                 normalStateSecondary.append(QChar(QChar::LineSeparator));
   385                 normalStateSecondary.append(QChar(QChar::LineSeparator));
   386                 if (item->secondary2ndRowText().length()) {
   386                 if (item->secondaryLabelRow2().length()) {
   387                     normalStateSecondary.append(item->secondary2ndRowText());
   387                     normalStateSecondary.append(item->secondaryLabelRow2());
   388                     normalStateSecondary.append(QChar(QChar::LineSeparator));
   388                     normalStateSecondary.append(QChar(QChar::LineSeparator));
   389                     useTwoRows = true;
   389                     useTwoRows = true;
   390                 }
   390                 }
   391             }
   391             }
   392         }
   392         }
   474     qreal maxLineWidth = 0;
   474     qreal maxLineWidth = 0;
   475 
   475 
   476     for (int j = 0; j < (DialpadRowCount*DialpadColumnCount); j++) {
   476     for (int j = 0; j < (DialpadRowCount*DialpadColumnCount); j++) {
   477         DialpadNumericButton *item = button(j);
   477         DialpadNumericButton *item = button(j);
   478 
   478 
   479         if ((type==PrimaryText && item->text().isNull()) ||
   479         if ((type==PrimaryText && item->primaryLabel().isNull()) ||
   480             (type==SecondaryText && item->secondaryText().isNull())) {
   480             (type==SecondaryText && item->secondaryLabel().isNull())) {
   481             continue; // no text for this button -> next button
   481             continue; // no text for this button -> next button
   482         }
   482         }
   483 
   483 
   484         if ( ( state==Normal &&
   484         if ( ( state==Normal &&
   485                item->state()==HbInputButton::ButtonStateReleased ) ||
   485                item->state()==HbInputButton::ButtonStateReleased ) ||
   493             } else {
   493             } else {
   494                 layoutPrimaryText(textLayout,*item,cellWidth,
   494                 layoutPrimaryText(textLayout,*item,cellWidth,
   495                                   cellHeight,textHeight);
   495                                   cellHeight,textHeight);
   496 
   496 
   497                 // store line width, for drawing secondary text
   497                 // store line width, for drawing secondary text
   498                 qreal lineWidth = fontMetrics.width(item->text());
   498                 qreal lineWidth = fontMetrics.width(item->primaryLabel());
   499                 if (mMaxPrimaryLineWidth == 0 && (j>0 && j<10) &&
   499                 if (mMaxPrimaryLineWidth == 0 && (j>0 && j<10) &&
   500                     lineWidth > maxLineWidth) {
   500                     lineWidth > maxLineWidth) {
   501                     maxLineWidth = lineWidth;
   501                     maxLineWidth = lineWidth;
   502                     mPrimaryTextBaseline = textHeight/2 - textDescent;
   502                     mPrimaryTextBaseline = textHeight/2 - textDescent;
   503                 }
   503                 }
   516     qreal cellWidth,
   516     qreal cellWidth,
   517     qreal cellHeight,
   517     qreal cellHeight,
   518     qreal textHeight) const
   518     qreal textHeight) const
   519 {
   519 {
   520     QTextLine line = layout.createLine();
   520     QTextLine line = layout.createLine();
   521     line.setNumColumns(button.text().length());
   521     line.setNumColumns(button.primaryLabel().length());
   522     qreal textPositionX = (button.position().x() * cellWidth) +
   522     qreal textPositionX = (button.position().x() * cellWidth) +
   523                     (DialpadPrimaryTextLeftMargin * mUnit)
   523                     (DialpadPrimaryTextLeftMargin * mUnit)
   524                     + buttonBorderSize();
   524                     + buttonBorderSize();
   525     qreal textPositionY = (button.position().y() +
   525     qreal textPositionY = (button.position().y() +
   526                     (0.5 * button.size().height())) *
   526                     (0.5 * button.size().height())) *
   541     qreal textPositionY;
   541     qreal textPositionY;
   542 
   542 
   543     QTextLine line = layout.createLine();
   543     QTextLine line = layout.createLine();
   544 
   544 
   545     if (useTwoRows) {
   545     if (useTwoRows) {
   546         line.setNumColumns(button.secondaryText().length());
   546         line.setNumColumns(button.secondaryLabel().length());
   547 
   547 
   548         textPositionX = (button.position().x() * cellWidth) +
   548         textPositionX = (button.position().x() * cellWidth) +
   549                         (DialpadPrimaryTextLeftMargin * mUnit) +
   549                         (DialpadPrimaryTextLeftMargin * mUnit) +
   550                         mMaxPrimaryLineWidth +
   550                         mMaxPrimaryLineWidth +
   551                         (DialpadPrimarySecondaryMargin * mUnit)
   551                         (DialpadPrimarySecondaryMargin * mUnit)
   552                         + buttonBorderSize();
   552                         + buttonBorderSize();
   553 
   553 
   554         if (button.secondary2ndRowText().length()) {
   554         if (button.secondaryLabelRow2().length()) {
   555             textPositionY = (button.position().y() +
   555             textPositionY = (button.position().y() +
   556                             (0.5 * button.size().height())) *
   556                             (0.5 * button.size().height())) *
   557                             cellHeight;
   557                             cellHeight;
   558 
   558 
   559             QTextLine line2 = layout.createLine();
   559             QTextLine line2 = layout.createLine();
   560             line2.setNumColumns(button.secondary2ndRowText().length());
   560             line2.setNumColumns(button.secondaryLabelRow2().length());
   561             line2.setPosition(QPointF(textPositionX,textPositionY-textHeight));
   561             line2.setPosition(QPointF(textPositionX,textPositionY-textHeight));
   562         } else {
   562         } else {
   563             textPositionY = (button.position().y() +
   563             textPositionY = (button.position().y() +
   564                             (0.5 * button.size().height())) *
   564                             (0.5 * button.size().height())) *
   565                             cellHeight - (0.5 * textHeight);
   565                             cellHeight - (0.5 * textHeight);
   566         }
   566         }
   567     } else {
   567     } else {
   568         line.setNumColumns(button.secondaryText().length());
   568         line.setNumColumns(button.secondaryLabel().length());
   569         textPositionX = (button.position().x() * cellWidth) +
   569         textPositionX = (button.position().x() * cellWidth) +
   570                         (DialpadPrimaryTextLeftMargin * mUnit) +
   570                         (DialpadPrimaryTextLeftMargin * mUnit) +
   571                         mMaxPrimaryLineWidth +
   571                         mMaxPrimaryLineWidth +
   572                         (DialpadPrimarySecondaryMargin * mUnit)
   572                         (DialpadPrimarySecondaryMargin * mUnit)
   573                         + buttonBorderSize();
   573                         + buttonBorderSize();