telutils/dialpad/src/dialpadkeypad.cpp
changeset 13 e32024264ebb
parent 12 ae8abd0db65c
child 15 d7fc66ccd6fb
equal deleted inserted replaced
12:ae8abd0db65c 13:e32024264ebb
    30 #include "dialpadbutton.h"
    30 #include "dialpadbutton.h"
    31 #include "dialpadinputfield.h"
    31 #include "dialpadinputfield.h"
    32 
    32 
    33 static const int DialpadRowCount = 5;
    33 static const int DialpadRowCount = 5;
    34 static const int DialpadColumnCount = 3;
    34 static const int DialpadColumnCount = 3;
       
    35 static const QString handsetIcon("qtg_mono_call");
       
    36 static const QString vmbxIcon("qtg_mono_voice_mailbox");
    35 
    37 
    36 static const int DialpadButtonToKeyCodeTable[DialpadButtonCount] =
    38 static const int DialpadButtonToKeyCodeTable[DialpadButtonCount] =
    37 {
    39 {
    38     Qt::Key_1,        Qt::Key_2,      Qt::Key_3,
    40     Qt::Key_1,        Qt::Key_2,      Qt::Key_3,
    39     Qt::Key_4,        Qt::Key_5,      Qt::Key_6,
    41     Qt::Key_4,        Qt::Key_5,      Qt::Key_6,
    42                       Qt::Key_Yes
    44                       Qt::Key_Yes
    43     // Qt::Key_BackSpace is in input field
    45     // Qt::Key_BackSpace is in input field
    44 };
    46 };
    45 
    47 
    46 DialpadKeypad::DialpadKeypad(
    48 DialpadKeypad::DialpadKeypad(
       
    49     const HbMainWindow& mainWindow,
    47     DialpadInputField& inputField,
    50     DialpadInputField& inputField,
    48     QGraphicsItem* parent) :
    51     QGraphicsItem* parent) :
    49     HbWidget(parent), mInputField(inputField),
    52     HbWidget(parent),
       
    53     mMainWindow(mainWindow),
       
    54     mInputField(inputField),
    50     mLongPressDuration(0)
    55     mLongPressDuration(0)
    51 {
    56 {
    52     // create signal mappers
    57     // create signal mappers
    53     mKeyPressedSignalMapper = new QSignalMapper(this);
    58     mKeyPressedSignalMapper = new QSignalMapper(this);
    54     connect(mKeyPressedSignalMapper,SIGNAL(mapped(int)),
    59     connect(mKeyPressedSignalMapper,SIGNAL(mapped(int)),
    84         buttonName.setNum(keyCode);
    89         buttonName.setNum(keyCode);
    85         button->setObjectName(buttonName);
    90         button->setObjectName(buttonName);
    86 
    91 
    87         if (keyCode==Qt::Key_Yes) {
    92         if (keyCode==Qt::Key_Yes) {
    88             button->setStyle(mCallButtonStyle);
    93             button->setStyle(mCallButtonStyle);
    89             HbIcon callIcon(":/qtg_mono_answer_call.svg"); // todo correct icon
    94             HbIcon callIcon(handsetIcon); // todo correct icon
    90             button->setIcon(callIcon);
    95             button->setIcon(callIcon);
    91         } else {
    96         } else {
    92             button->setStyle(mNormalButtonStyle);
    97             button->setStyle(mNormalButtonStyle);
    93         }
    98         }
    94 
    99 
    95         if (keyCode==Qt::Key_1) {
   100         if (keyCode==Qt::Key_1) {
    96             HbIcon mboxIcon(":/qtg_mono_voice_mailbox.svg");
   101             HbIcon mboxIcon(vmbxIcon);
    97             button->setIcon(mboxIcon);
   102             button->setIcon(mboxIcon);
    98         }
   103         }
    99 
   104 
   100         // for Yes-key clicked() signal is enough
   105         // for Yes-key clicked() signal is enough
   101         if (keyCode!=Qt::Key_Yes) {
   106         if (keyCode!=Qt::Key_Yes) {
   256 }
   261 }
   257 
   262 
   258 void DialpadKeypad::postKeyEvent(QEvent::Type type, int key)
   263 void DialpadKeypad::postKeyEvent(QEvent::Type type, int key)
   259 {
   264 {
   260     QKeyEvent *keyEvent = new QKeyEvent(type, key, Qt::NoModifier);
   265     QKeyEvent *keyEvent = new QKeyEvent(type, key, Qt::NoModifier);
   261     HbApplication::postEvent(hbInstance->allMainWindows().at(0),keyEvent);
   266     HbApplication::postEvent(const_cast<HbMainWindow*>(&mMainWindow),keyEvent);
   262 }
   267 }
   263 
   268 
   264 void DialpadKeypad::sendKeyEventToEditor(QEvent::Type type, int key)
   269 void DialpadKeypad::sendKeyEventToEditor(QEvent::Type type, int key)
   265 {
   270 {
   266     QKeyEvent keyEvent(type, key, Qt::NoModifier, mGeneratedChar.value(key));
   271     QKeyEvent keyEvent(type, key, Qt::NoModifier, mGeneratedChar.value(key));
   295 
   300 
   296 void DialpadKeypad::showEvent(QShowEvent *event)
   301 void DialpadKeypad::showEvent(QShowEvent *event)
   297 {
   302 {
   298     HbWidget::showEvent(event);
   303     HbWidget::showEvent(event);
   299 
   304 
   300     // set fixed row and column dimensions
   305     if (parentWidget()->isVisible()) {
   301     QSizeF effectiveSize(rect().width(),
   306         // first show event comes before dialpad is open
   302                          rect().height());
   307         // set fixed row and column dimensions
   303 
   308         QSizeF effectiveSize(rect().width(),
   304     qreal width = effectiveSize.width() / DialpadColumnCount;
   309                              rect().height());
   305     qreal height = effectiveSize.height() / DialpadRowCount;
   310 
   306 
   311         qreal width = effectiveSize.width() / DialpadColumnCount;
   307     for (int i=0; i < DialpadColumnCount ;i++) {
   312         qreal height = effectiveSize.height() / DialpadRowCount;
   308         mGridLayout->setColumnFixedWidth(i, width);
   313 
   309     }
   314         for (int i=0; i < DialpadColumnCount ;i++) {
   310 
   315             mGridLayout->setColumnFixedWidth(i, width);
   311     for (int i=0; i < DialpadRowCount ;i++) {
   316         }
   312         mGridLayout->setRowFixedHeight(i, height);
   317 
   313     }
   318         for (int i=0; i < DialpadRowCount ;i++) {
   314 }
   319             mGridLayout->setRowFixedHeight(i, height);
       
   320         }
       
   321     }
       
   322 }