phoneapp/phoneuiview2/src/phoneuiqtview.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 30 ebdbd102c78a
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
40:bab96b7ed1a4 51:f39ed5e045e0
    25 #include <hbmenu.h>
    25 #include <hbmenu.h>
    26 
    26 
    27 #include <xqserviceutil.h>
    27 #include <xqserviceutil.h>
    28 #include <xqkeycapture.h>
    28 #include <xqkeycapture.h>
    29 #include <dialpad.h>
    29 #include <dialpad.h>
       
    30 #include <dialpadkeyhandler.h>
    30 
    31 
    31 #include "phoneuiqtview.h"
    32 #include "phoneuiqtview.h"
    32 #include "phoneaction.h"
    33 #include "phoneaction.h"
    33 #include "qtphonelog.h"
    34 #include "qtphonelog.h"
    34 
    35 
    35 PhoneUIQtView::PhoneUIQtView (HbMainWindow &window, QGraphicsItem *parent) :
    36 PhoneUIQtView::PhoneUIQtView (HbMainWindow &window, QGraphicsItem *parent) :
    36     HbView (parent),
    37     HbView (parent),
    37     m_window(window),
    38     m_window(window),
       
    39     m_bubbleManager(0),
       
    40     m_signalMapper(0),
    38     m_volumeSlider (0),
    41     m_volumeSlider (0),
    39     m_expandSignalMapper(0),
    42     m_expandSignalMapper(0),
    40     m_participantListSignalMapper(0),
    43     m_participantListSignalMapper(0),
    41     m_volumeCommandId(0),
    44     m_volumeCommandId(0),
       
    45     m_backAction(0),
       
    46     m_dialpad(0),
       
    47     m_menuSignalMapper(0),
    42     m_keyCapture(0),
    48     m_keyCapture(0),
    43     m_networkInfo(0)
    49     m_networkInfo(0),
       
    50     m_dialpadKeyHandler(0),
       
    51     m_restrictedMode(false)
    44 {
    52 {
    45     // Set network name
    53     // Set network name
    46     m_networkInfo = new QSystemNetworkInfo(this);
    54     m_networkInfo = new QSystemNetworkInfo(this);
    47     QString networkName = m_networkInfo->networkName(QSystemNetworkInfo::GsmMode);
    55     QString networkName = m_networkInfo->networkName(QSystemNetworkInfo::WcdmaMode);
    48     connect(m_networkInfo, SIGNAL (networkNameChanged(QSystemNetworkInfo::NetworkMode,QString)), this, SLOT(networkNameChanged(QSystemNetworkInfo::NetworkMode, QString)));
    56     if(networkName.isEmpty()) {
       
    57         networkName = m_networkInfo->networkName(QSystemNetworkInfo::GsmMode);
       
    58     }
       
    59     connect(m_networkInfo, SIGNAL (networkNameChanged(QSystemNetworkInfo::NetworkMode,QString)),
       
    60             this, SLOT(networkNameChanged(QSystemNetworkInfo::NetworkMode, QString)));
    49     setTitle(networkName);
    61     setTitle(networkName);
    50 
    62 
    51     // Capturing long press of end key
    63     // Capturing long press of end key
    52     m_keyCapture = new XqKeyCapture();
    64     m_keyCapture = new XqKeyCapture();
    53     m_keyCapture->captureLongKey(Qt::Key_No);
       
    54     m_keyCapture->captureKey(Qt::Key_No);
       
    55     
    65     
    56     // Dialpad
    66     // Dialpad
    57     m_dialpad = new Dialpad(m_window);
    67     m_dialpad = new Dialpad(m_window);
    58     m_dialpad->setCallButtonEnabled(false);
    68     m_dialpad->setCallButtonEnabled(false);
    59     m_dialpad->setTapOutsideDismiss(true);
    69     m_dialpad->setTapOutsideDismiss(true);
    60     connect(&m_dialpad->editor(),SIGNAL(contentsChanged()),
       
    61             SLOT(onEditorContentChanged()));
       
    62     connect(m_dialpad,SIGNAL(aboutToClose()),this,
    70     connect(m_dialpad,SIGNAL(aboutToClose()),this,
    63                 SLOT(dialpadClosed()));
    71                 SLOT(dialpadClosed()));
    64                 
    72     
    65     // Call handling widget
    73     // Call handling widget
    66     m_bubbleManager = new BubbleManager (this);
    74     m_bubbleManager = new BubbleManager (this);
    67     setWidget(m_bubbleManager);
    75     setWidget(m_bubbleManager);
    68 
    76 
    69     // Set event filter
    77     // Set event filter
    83     m_backAction = new HbAction(Hb::BackNaviAction, this);
    91     m_backAction = new HbAction(Hb::BackNaviAction, this);
    84     connect(m_backAction, SIGNAL(triggered()), this, SLOT(backButtonClicked()));
    92     connect(m_backAction, SIGNAL(triggered()), this, SLOT(backButtonClicked()));
    85     setNavigationAction(m_backAction);
    93     setNavigationAction(m_backAction);
    86 
    94 
    87     createToolBarActions();
    95     createToolBarActions();
       
    96 
       
    97     // Set restricted mode off, normal state
       
    98     setRestrictedMode(false);
    88 }
    99 }
    89 
   100 
    90 PhoneUIQtView::~PhoneUIQtView ()
   101 PhoneUIQtView::~PhoneUIQtView ()
    91 {
   102 {
    92 
   103     qDeleteAll(m_toolbarActions);
    93     foreach (HbAction *action, m_toolbarActions ) {
       
    94         delete action;
       
    95     }
       
    96     m_window.removeEventFilter(this);
   104     m_window.removeEventFilter(this);
    97     delete m_volumeSlider;
   105     delete m_volumeSlider;
    98     delete m_dialpad;
   106     delete m_dialpad;
    99 }
   107 }
   100 
   108 
   163     if (m_participantListSignalMapper) {
   171     if (m_participantListSignalMapper) {
   164         m_bubbleManager->clearParticipantListActions();
   172         m_bubbleManager->clearParticipantListActions();
   165 
   173 
   166         foreach (HbAction *action, m_participantListActions ) {
   174         foreach (HbAction *action, m_participantListActions ) {
   167             m_participantListSignalMapper->removeMappings(action);
   175             m_participantListSignalMapper->removeMappings(action);
   168             delete action;
   176         }
   169         }
   177 		qDeleteAll(m_participantListActions);
   170 
       
   171         m_participantListActions.clear();
   178         m_participantListActions.clear();
   172         delete m_participantListSignalMapper;
   179         delete m_participantListSignalMapper;
   173         m_participantListSignalMapper = 0;
   180         m_participantListSignalMapper = 0;
   174     }
   181     }
   175 
   182 
   363 }
   370 }
   364 
   371 
   365 void PhoneUIQtView::clearAndHideDialpad()
   372 void PhoneUIQtView::clearAndHideDialpad()
   366 {
   373 {
   367     m_dialpad->editor().setText(QString(""));
   374     m_dialpad->editor().setText(QString(""));
   368     hideDialpad();
   375     m_dialpad->closeDialpad();
       
   376 }
       
   377 
       
   378 void PhoneUIQtView::clearDialpad()
       
   379 {
       
   380     m_dialpad->editor().setText(QString(""));
   369 }
   381 }
   370 
   382 
   371 void PhoneUIQtView::bringToForeground()
   383 void PhoneUIQtView::bringToForeground()
   372 {
   384 {
   373     m_window.show();
   385     m_window.show();
   374     m_window.raise();
       
   375 }
   386 }
   376 
   387 
   377 void PhoneUIQtView::setMenuActions(const QList<PhoneAction*>& actions)
   388 void PhoneUIQtView::setMenuActions(const QList<PhoneAction*>& actions)
   378 {
   389 {
   379 
   390 
   397 HbMenu &PhoneUIQtView::menuReference()
   408 HbMenu &PhoneUIQtView::menuReference()
   398 {
   409 {
   399     return *menu();
   410     return *menu();
   400 }
   411 }
   401 
   412 
       
   413 void PhoneUIQtView::captureKey(Qt::Key key, bool capture)
       
   414 {
       
   415     if (capture) {
       
   416         if (!m_keyCaptures.contains(key)) {
       
   417             m_keyCapture->captureLongKey(key);
       
   418             m_keyCapture->captureKey(key);
       
   419             m_keyCaptures.append(key);
       
   420         }
       
   421     } else {
       
   422         if (m_keyCaptures.contains(key)) {
       
   423             m_keyCapture->cancelCaptureKey(key);
       
   424             m_keyCapture->cancelCaptureLongKey(key);
       
   425             m_keyCaptures.removeOne(key);
       
   426         }
       
   427     }
       
   428 }
       
   429 
   402 void PhoneUIQtView::handleOrientationChange(Qt::Orientation orientation)
   430 void PhoneUIQtView::handleOrientationChange(Qt::Orientation orientation)
   403 {
   431 {
   404     if (orientation==Qt::Horizontal) {
   432     if (orientation==Qt::Horizontal) {
   405         toolBar()->setOrientation(Qt::Horizontal);
   433         toolBar()->setOrientation(Qt::Horizontal);
   406     }
   434     }
   424 void PhoneUIQtView::dialpadClosed()
   452 void PhoneUIQtView::dialpadClosed()
   425 {
   453 {
   426     emit dialpadIsAboutToClose();
   454     emit dialpadIsAboutToClose();
   427 }
   455 }
   428 
   456 
   429 bool PhoneUIQtView::eventFilter(QObject * /*watched*/, QEvent * event)
   457 bool PhoneUIQtView::eventFilter(QObject *watched, QEvent * event)
   430 {
   458 {
       
   459     Q_UNUSED(watched);
   431     PHONE_DEBUG2("PhoneUIQtView::eventFilter event type:", event->type());
   460     PHONE_DEBUG2("PhoneUIQtView::eventFilter event type:", event->type());
       
   461     
       
   462     // Allow send key only when there is callbutton enabled or no text in input field
       
   463     bool sendKeyAllowed = m_dialpad->isCallButtonEnabled() || 
       
   464             (m_dialpad->editor().text().length() == 0);
       
   465     
   432     if(event->type() == QEvent::KeyPress) {
   466     if(event->type() == QEvent::KeyPress) {
   433         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
   467         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
   434         PHONE_DEBUG2("PhoneUIQtView::eventFilter pressed key:", keyEvent->key());
   468         PHONE_DEBUG2("PhoneUIQtView::eventFilter pressed key:", keyEvent->key());
   435         PHONE_DEBUG2("PhoneUIQtView::eventFilter isAutoRepeat:", keyEvent->isAutoRepeat());
   469         PHONE_DEBUG2("PhoneUIQtView::eventFilter isAutoRepeat:", keyEvent->isAutoRepeat());
   436         emit keyPressed(keyEvent);        
   470         if ( (keyEvent->key() != Qt::Key_Yes && keyEvent->key() != Qt::Key_Enter) ||
   437         keyEvent->accept();
   471                 sendKeyAllowed) {
       
   472             emit keyPressed(keyEvent);        
       
   473             keyEvent->accept();
       
   474         }
   438         
   475         
   439         return false;
   476         return false;
   440     } else if(event->type() == QEvent::KeyRelease) {
   477     } else if(event->type() == QEvent::KeyRelease) {
   441         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
   478         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
   442         PHONE_DEBUG2("PhoneUIQtView::eventFilter released key:", keyEvent->key());
   479         PHONE_DEBUG2("PhoneUIQtView::eventFilter released key:", keyEvent->key());
   443         emit keyReleased(keyEvent);
   480         if ( (keyEvent->key() != Qt::Key_Yes && keyEvent->key() != Qt::Key_Enter) ||
   444         keyEvent->accept();
   481                 sendKeyAllowed) {
   445         
   482             emit keyReleased(keyEvent);
       
   483             keyEvent->accept();
       
   484         }
   446         return false;
   485         return false;
   447     } else if (event->type() == QEvent::WindowActivate){
   486     } else if (event->type() == QEvent::WindowActivate){
   448         PHONE_DEBUG("PhoneUIQtView::eventFilter WindowActivate");
   487         PHONE_DEBUG("PhoneUIQtView::eventFilter WindowActivate");
   449         emit windowActivated();
   488         emit windowActivated();
   450         return false;
   489         return false;
   457     }
   496     }
   458 }
   497 }
   459 
   498 
   460 void PhoneUIQtView::setDialpadPosition()
   499 void PhoneUIQtView::setDialpadPosition()
   461 {
   500 {
   462     // workaround to tsw error JMKN-83NAPU (fix coming in MCL wk14)
   501     QRectF screenRect(m_window.layoutRect());
   463     // QRectF screenRect(m_window.layoutRect());
       
   464     QRectF screenRect = (m_window.orientation() == Qt::Horizontal) ?
       
   465                         QRectF(0,0,640,360) : QRectF(0,0,360,640);
       
   466                         	
   502                         	
   467     if (m_window.orientation() == Qt::Horizontal) {
   503     if (m_window.orientation() == Qt::Horizontal) {
   468             // dialpad takes half of the screen
   504             // dialpad takes half of the screen
   469         m_dialpad->setPos(QPointF(screenRect.width()/2,
   505         m_dialpad->setPos(QPointF(screenRect.width()/2,
   470                                   this->scenePos().y()));
   506                                   this->scenePos().y()));
   504     QCoreApplication::quit();
   540     QCoreApplication::quit();
   505 }
   541 }
   506 
   542 
   507 void PhoneUIQtView::setBackButtonVisible(bool visible)
   543 void PhoneUIQtView::setBackButtonVisible(bool visible)
   508 {
   544 {
   509     if (visible) {
   545     if (!m_restrictedMode) {
   510         setNavigationAction(m_backAction);
   546         m_backAction->setEnabled(visible);
   511         }
   547     }
   512     else {
   548 }
   513         setNavigationAction(0);
   549 
   514     }
   550 void PhoneUIQtView::setRestrictedMode(bool restrictedMode)
       
   551 {
       
   552     m_restrictedMode = restrictedMode;
       
   553     m_backAction->setEnabled(!restrictedMode);
       
   554     m_dialpad->setCallButtonEnabled(false);
       
   555     m_dialpad->editor().setText(""); // Clead dialpad
       
   556     if (m_restrictedMode) {
       
   557         delete m_dialpadKeyHandler;
       
   558         m_dialpadKeyHandler = 0;
       
   559         m_dialpadKeyHandler = new DialpadKeyHandler(
       
   560                 m_dialpad, DialpadKeyHandler::EmergencyCall, this);
       
   561         disconnect(&m_dialpad->editor(),SIGNAL(contentsChanged()),
       
   562                 this, SLOT(onEditorContentChanged())); // Let emergency handler do updating 
       
   563     } else {
       
   564         delete m_dialpadKeyHandler;
       
   565         m_dialpadKeyHandler = 0;
       
   566         // enable key sequence handling during a call
       
   567         m_dialpadKeyHandler = new DialpadKeyHandler(
       
   568                 m_dialpad, DialpadKeyHandler::KeySequence, this);
       
   569         connect(&m_dialpad->editor(),SIGNAL(contentsChanged()),
       
   570                 SLOT(onEditorContentChanged())); // Update our self
       
   571     }
       
   572     
   515 }
   573 }
   516 
   574 
   517 void PhoneUIQtView::networkNameChanged(QSystemNetworkInfo::NetworkMode mode, const QString &netName)
   575 void PhoneUIQtView::networkNameChanged(QSystemNetworkInfo::NetworkMode mode, const QString &netName)
   518 {
   576 {
   519     if(mode == QSystemNetworkInfo::GsmMode) {
   577     if((mode == QSystemNetworkInfo::GsmMode) || 
       
   578        (mode == QSystemNetworkInfo::WcdmaMode)) {
   520         setTitle(netName);
   579         setTitle(netName);
   521     }	
   580     }	
   522 }
   581 }
       
   582