ginebra2/Charms/ExternalEventCharm.cpp
changeset 16 3c88a81ff781
parent 9 b39122337a00
equal deleted inserted replaced
14:6aeb7a756187 16:3c88a81ff781
    17 *
    17 *
    18 * Description:
    18 * Description:
    19 */
    19 */
    20 
    20 
    21 #include "ExternalEventCharm.h"
    21 #include "ExternalEventCharm.h"
       
    22 #include "qstmgestureevent.h"
    22 
    23 
    23 namespace GVA {
    24 namespace GVA {
    24 
    25 
    25 const QString ExternalEventCharm::s_mouseClick = "MouseClick";
    26 const QString ExternalEventCharm::s_mouseClick = "MouseClick";
    26 static const int KLongPressThreshold = 30;
    27 static const int KLongPressThreshold = 30;
    36 {
    37 {
    37 }
    38 }
    38 
    39 
    39 bool ExternalEventCharm::eventFilter(QObject *object, QEvent *event) {
    40 bool ExternalEventCharm::eventFilter(QObject *object, QEvent *event) {
    40     checkForExternalEvent(this, event);
    41     checkForExternalEvent(this, event);
       
    42     checkForExternalGesture(event);
    41 
    43 
    42     switch (event->type()) {
    44     switch (event->type()) {
    43       case QEvent::Show:
    45       case QEvent::Show:
    44       {
    46       {
    45           scene()->installEventFilter(this);
    47           if(scene())
       
    48           	scene()->installEventFilter(this);
    46           break;
    49           break;
    47       }
    50       }
    48       case QEvent::Hide:
    51       case QEvent::Hide:
    49       {
    52       {
    50           scene()->removeEventFilter(this);
    53           if(scene())
       
    54           	scene()->removeEventFilter(this);
    51           break;
    55           break;
    52       }
    56       }
    53       default: break;
    57       default: break;
    54     }
    58     }
    55 
    59 
   100         else
   104         else
   101             emitExternalEvent(e);
   105             emitExternalEvent(e);
   102     }
   106     }
   103 }
   107 }
   104 
   108 
       
   109 
       
   110 bool ExternalEventCharm::checkForExternalGesture(QEvent* event)
       
   111 {
       
   112     if (event->type() != QEvent::Gesture) return false;
       
   113     bool emitClick = false;
       
   114     bool isGestureStarted = false;
       
   115     bool isGestureEnded = false;
       
   116     QStm_Gesture* gesture = getQStmGesture(event);
       
   117     if (gesture) {
       
   118         QStm_GestureType gtype = gesture->getGestureStmType();
       
   119         QPoint gpos = gesture->position();
       
   120         isGestureStarted = (gtype == QStmTouchGestureType);
       
   121         isGestureEnded = (gtype == QStmMaybeTapGestureType ||
       
   122                                gesture->isGestureEnded());
       
   123 
       
   124         if (isGestureStarted || isGestureEnded) {
       
   125             QGraphicsObject *item = static_cast<QGraphicsObject*>(m_object);
       
   126             QPointF pos = qstmMapToScene(gpos, item);
       
   127             if (isGestureStarted) {
       
   128                 m_pressed = true;
       
   129             }
       
   130             else if (isGestureEnded) {
       
   131                 if (m_pressed) {
       
   132                     emitClick = true;
       
   133                     m_pressed = false;
       
   134                 }
       
   135             }
       
   136 
       
   137             if (!item->sceneBoundingRect().contains(pos)) {
       
   138 
       
   139                 QGraphicsSceneMouseEvent me(emitClick ? QEvent::GraphicsSceneMouseRelease :
       
   140                                                         QEvent::GraphicsSceneMousePress);
       
   141 
       
   142                 qstmSetGraphicsSceneMouseEvent(pos, item, me);
       
   143                 if(emitClick) {
       
   144                     emit externalMouseEvent(&me, s_mouseClick, "");
       
   145                 }
       
   146                 else {
       
   147                     emitExternalEvent(&me);
       
   148                 }
       
   149             }
       
   150         }
       
   151     }
       
   152     return isGestureStarted || isGestureEnded;
       
   153 }
       
   154 
   105 void ExternalEventCharm::emitExternalEvent(QEvent * e)
   155 void ExternalEventCharm::emitExternalEvent(QEvent * e)
   106 {
   156 {
   107     QString description;
   157     QString description;
   108 
   158 
   109     QDebug stream(&description);
   159     QDebug stream(&description);