telutils/dialpad/tsrc/dialpadtest/dialpadtestview.cpp
branchRCL_3
changeset 19 7d48bed6ce0c
equal deleted inserted replaced
18:594d59766373 19:7d48bed6ce0c
       
     1 /*!
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtGui>
       
    19 #include <hbtoolbar.h>
       
    20 #include <hbaction.h>
       
    21 #include <hblabel.h>
       
    22 #include <hbdialog.h>
       
    23 #include <hbmainwindow.h>
       
    24 #include <hbmenu.h>
       
    25 #include <hblistwidget.h>
       
    26 #include <hblistwidgetitem.h>
       
    27 #include <hblineedit.h>
       
    28 #include <hbmessagebox.h>
       
    29 
       
    30 #include "dialpadtestview.h"
       
    31 #include "dialpad.h"
       
    32 #include "dialpadkeyhandler.h"
       
    33 
       
    34 DialpadTestView::DialpadTestView( HbMainWindow& mainWindow ) :
       
    35     mMainWindow(mainWindow), mTapOutsideDismiss(0)
       
    36 {
       
    37     setTitle("DialpadTest");
       
    38 
       
    39     // create toolbar with launch dialer action
       
    40     HbToolBar* tb = toolBar();
       
    41     if (mMainWindow.orientation()==Qt::Horizontal) {
       
    42         tb->setOrientation(mMainWindow.orientation());
       
    43     }
       
    44 
       
    45     tb->addAction("");
       
    46     tb->addAction(HbIcon(":/qtg_large_tb_dialler.svg"),"",this,SLOT(openDialpad()));
       
    47     tb->addAction("");
       
    48 
       
    49 
       
    50     // create menu
       
    51     menu()->addAction("Switch orientation",this,SLOT(switchOrientation()));
       
    52     connect(&mMainWindow,
       
    53             SIGNAL(orientationChanged(Qt::Orientation)),
       
    54             SLOT(onOrientationChange(Qt::Orientation)));
       
    55 
       
    56     menu()->addAction("Tap outside dismiss",this,SLOT(setTapOutsideDismiss()));
       
    57 
       
    58     // create view widget (recent calls list mockup)
       
    59     createListWidget();
       
    60 
       
    61     // create dialpad popup
       
    62     mDialpad = new Dialpad(); // Note! no parent for popup
       
    63     mDialpad->setCallButtonEnabled(false);
       
    64     connect(mDialpad,SIGNAL(aboutToClose()),SLOT(onDialpadClosed()));
       
    65     connect(&mDialpad->editor(),SIGNAL(contentsChanged()),
       
    66             SLOT(onEditorContentChanged()));
       
    67 
       
    68     // create key event handler
       
    69     mLongPressTimer = new QTimer(this);
       
    70     mLongPressTimer->setSingleShot(true);
       
    71     connect(mLongPressTimer,SIGNAL(timeout()),this,SLOT(handleLongKeyPress()));
       
    72     
       
    73     mKeyhandler = new DialpadKeyHandler(mDialpad, mMainWindow, this);
       
    74     
       
    75     mMainWindow.installEventFilter(this);
       
    76 }
       
    77 
       
    78 DialpadTestView::~DialpadTestView()
       
    79 {
       
    80     delete mDialpad;
       
    81 }
       
    82 
       
    83 void DialpadTestView::openDialpad()
       
    84 {
       
    85     toolBar()->hide();
       
    86     setDialpadPosition();
       
    87     mDialpad->openDialpad();
       
    88 }
       
    89 
       
    90 void DialpadTestView::onDialpadClosed()
       
    91 {
       
    92     toolBar()->show();
       
    93     mDialpad->editor().setText(QString());
       
    94 }
       
    95 
       
    96 void DialpadTestView::onEditorContentChanged()
       
    97 {
       
    98     mDialpad->setCallButtonEnabled(
       
    99         mDialpad->editor().text().length());
       
   100 }
       
   101 
       
   102 void DialpadTestView::setDialpadPosition()
       
   103 {
       
   104     QRectF screenRect(mMainWindow.layoutRect());
       
   105 
       
   106     if (mMainWindow.orientation() == Qt::Horizontal) {
       
   107         // dialpad takes half of the screen
       
   108         mDialpad->setPos(QPointF(screenRect.width()/2,
       
   109                                  this->scenePos().y()));
       
   110         mDialpad->resize(screenRect.width()/2,
       
   111                          (screenRect.height()-scenePos().y()));
       
   112     } else {
       
   113         qreal screenHeight = screenRect.height();
       
   114         mDialpad->setPos(0, screenHeight/2.25);
       
   115         mDialpad->resize(screenRect.width(),screenHeight - screenHeight/2.25);
       
   116     }
       
   117 }
       
   118 
       
   119 void DialpadTestView::switchOrientation()
       
   120 {
       
   121     if (mMainWindow.orientation()==Qt::Vertical) {
       
   122         mMainWindow.setOrientation(Qt::Horizontal);
       
   123 
       
   124     } else {
       
   125         mMainWindow.setOrientation(Qt::Vertical);
       
   126     }
       
   127 }
       
   128 
       
   129 void DialpadTestView::onOrientationChange(Qt::Orientation orientation)
       
   130 {
       
   131     if (orientation==Qt::Horizontal) {
       
   132         toolBar()->setOrientation(Qt::Horizontal);
       
   133     }
       
   134 
       
   135     setDialpadPosition();
       
   136 }
       
   137 
       
   138 void DialpadTestView::createListWidget()
       
   139 {
       
   140     mListWidget = new HbListWidget(this);
       
   141     for (int i=0; i<10; i++) {
       
   142         HbListWidgetItem* listItem = new HbListWidgetItem;
       
   143         QString logEvent("Log event ");
       
   144         QString index; index.setNum(i+1);
       
   145         logEvent.append(index);
       
   146         listItem->setText(logEvent);
       
   147         QString phoneNum("+35850123456");
       
   148         phoneNum.append(index);
       
   149         listItem->setSecondaryText(phoneNum);
       
   150         HbIcon icon(":/qgn_prop_pb_comm_call_large.svg");
       
   151         listItem->setIcon(icon);
       
   152         mListWidget->addItem(listItem);
       
   153     }
       
   154     setWidget(mListWidget);
       
   155 }
       
   156 
       
   157 bool DialpadTestView::eventFilter(QObject* watched, QEvent * event)
       
   158 {
       
   159     if (watched!=&mMainWindow) {
       
   160         return false;
       
   161     }
       
   162 
       
   163     if (event->type() == QEvent::KeyPress) {
       
   164         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
   165         qDebug() << "KeyEventHandler: key press:" << keyEvent->key();
       
   166 
       
   167         mPressedKey = keyEvent->text();
       
   168 
       
   169         if (keyEvent->key()>=Qt::Key_0 && keyEvent->key()<=Qt::Key_9) {
       
   170             mLongPressTimer->stop();
       
   171             mLongPressTimer->start(1500);
       
   172         }
       
   173 
       
   174         return false;
       
   175     } else if (event->type() == QEvent::KeyRelease) {
       
   176         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
   177         qDebug() << "KeyEventHandler: key release:" << keyEvent->key();
       
   178 
       
   179         mLongPressTimer->stop();
       
   180 
       
   181         if (keyEvent->key()==Qt::Key_Yes ||
       
   182             keyEvent->key()==Qt::Key_Enter) {
       
   183             handleDial();
       
   184         }
       
   185 
       
   186         return false;
       
   187     }
       
   188 
       
   189     return false;
       
   190 }
       
   191 
       
   192 bool DialpadTestView::event(QEvent * event)
       
   193 {
       
   194     if (event->type() == QEvent::LayoutDirectionChange) {
       
   195         setDialpadPosition();
       
   196     }
       
   197 
       
   198     return HbView::event(event);
       
   199 }
       
   200 
       
   201 void DialpadTestView::handleLongKeyPress()
       
   202 {
       
   203     QString msg;
       
   204     msg.append("Long press: ");
       
   205     msg.append(mPressedKey);
       
   206 
       
   207     HbMessageBox::information(msg);
       
   208 }
       
   209 
       
   210 void DialpadTestView::handleDial()
       
   211 {
       
   212     QString msg;
       
   213     if (mDialpad->editor().text().length()) {
       
   214         msg.append("Dialing to number: ");
       
   215         msg.append(mDialpad->editor().text());
       
   216     } else {
       
   217         msg.append("Please, enter phone number first");
       
   218     }
       
   219 
       
   220     HbMessageBox::information(msg);
       
   221 }
       
   222 
       
   223 void DialpadTestView::setTapOutsideDismiss()
       
   224 {
       
   225     mTapOutsideDismiss = !mTapOutsideDismiss;
       
   226     mDialpad->setTapOutsideDismiss(mTapOutsideDismiss);
       
   227 }