ginebra2/PopupWebChromeItem.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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 *
     4 *
     9 * Initial Contributors:
     5 * This program is free software: you can redistribute it and/or modify
    10 * Nokia Corporation - initial contribution.
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
    11 *
     8 *
    12 * Contributors:
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
       
    18 
    21 
    19 #include "PopupWebChromeItem.h"
    22 #include "PopupWebChromeItem.h"
    20 #include "ChromeWidget.h"
    23 #include "ChromeWidget.h"
    21 #include "WebChromeSnippet.h"
    24 #include "WebChromeSnippet.h"
       
    25 #include "ExternalEventCharm.h"
    22 
    26 
    23 namespace GVA {
    27 namespace GVA {
    24 
    28 
    25 PopupWebChromeItem::PopupWebChromeItem(
    29 PopupWebChromeItem::PopupWebChromeItem(
    26         const QRectF & ownerArea,
       
    27         ChromeWidget * chrome,
    30         ChromeWidget * chrome,
    28         const QWebElement & element,
    31         const QWebElement & element,
    29         QGraphicsItem * parent)
    32         QGraphicsItem * parent,
    30 : WebChromeItem(ownerArea, chrome, element, parent)
    33         bool modal)
       
    34 : WebChromeItem(chrome, element, parent),
       
    35   m_modal(modal),
       
    36   m_externalEventCharm(0)
    31 {
    37 {
    32 }
    38 }
    33 
    39 
    34 PopupWebChromeItem::~PopupWebChromeItem()
    40 PopupWebChromeItem::~PopupWebChromeItem()
    35 {}
    41 {
       
    42     delete m_externalEventCharm;
       
    43 }
    36 
    44 
    37 void PopupWebChromeItem::init(WebChromeSnippet * snippet)
    45 void PopupWebChromeItem::init(WebChromeSnippet * snippet)
    38 {
    46 {
    39     WebChromeItem::init(snippet);
    47     WebChromeItem::init(snippet);
       
    48     m_externalEventCharm = new ExternalEventCharm(this);
    40 
    49 
    41     // Forward externalMouseEvent signals from context items.
    50     // Forward externalMouseEvent signals from context items.
    42     QObject::connect(
    51     QObject::connect(
    43             this,
    52             m_externalEventCharm,
    44             SIGNAL(externalMouseEvent(int, const QString &, const QString &)),
    53             SIGNAL(externalMouseEvent(QEvent *, const QString &, const QString &)),
    45             snippet,
    54             snippet,
    46             SIGNAL(externalMouseEvent(int, const QString &, const QString &)));
    55             SIGNAL(externalMouseEvent(QEvent *, const QString &, const QString &)));
    47 }
    56 }
    48 
    57 
    49 bool PopupWebChromeItem::event(QEvent * e)
    58 bool PopupWebChromeItem::event(QEvent * e)
    50 {
    59 {
    51     // Check for external events grabbed by this item.
    60     switch (e->type()) {
    52 
       
    53     checkForExternalEvent(this, e);
       
    54 
       
    55     switch(e->type()) {
       
    56       case QEvent::Show:
    61       case QEvent::Show:
    57         scene()->installEventFilter(this);
    62         if(snippet() && m_modal) {
       
    63             chrome()->emitPopupShown(snippet()->objectName());
       
    64         }
    58         break;
    65         break;
    59       case QEvent::Hide:
    66       case QEvent::Hide:
    60         scene()->removeEventFilter(this);
    67         if(snippet() && m_modal) {
       
    68             chrome()->emitPopupHidden(snippet()->objectName());
       
    69         }
    61         break;
    70         break;
    62       default: break;
    71       default: break;
    63     }
    72     }
    64 
    73 
    65     // Let the parent class handle the event.
    74     // Let the parent class handle the event.
    66 
    75 
    67     return WebChromeItem::event(e);
    76     return WebChromeItem::event(e);
    68 }
    77 }
    69 
    78 
    70 bool PopupWebChromeItem::eventFilter(QObject * o, QEvent * e)
       
    71 {
       
    72     // Check for external events NOT grabbed by this item.
       
    73 
       
    74     checkForExternalEvent(o, e);
       
    75 
       
    76     // Don't filter any events.
       
    77 
       
    78     return false;
       
    79 }
       
    80 
       
    81 void PopupWebChromeItem::checkForExternalEvent(QObject * o, QEvent * e)
       
    82 {
       
    83     Q_UNUSED(o);
       
    84 
       
    85     // Ignore all events when this item is not showing.
       
    86 
       
    87     if (!isVisible()) {
       
    88         return;
       
    89     }
       
    90 
       
    91     // Ignore all but a few mouse press events.
       
    92 
       
    93     switch (e->type()) {
       
    94     case QEvent::GraphicsSceneMousePress:
       
    95     case QEvent::GraphicsSceneMouseRelease:
       
    96     case QEvent::GraphicsSceneMouseDoubleClick:
       
    97     case QEvent::GraphicsSceneResize:
       
    98         break;
       
    99     default:
       
   100         return;
       
   101     }
       
   102 
       
   103     // Check where the mouse press event occurred.
       
   104     // If it was outside this item's bounding rectangle,
       
   105     // then tell the world.
       
   106 
       
   107     if(e->type() == QEvent::GraphicsSceneResize)
       
   108     {
       
   109     	emitExternalEvent(e);
       
   110     	return;
       
   111     }
       
   112     
       
   113     QGraphicsSceneMouseEvent * me = static_cast<QGraphicsSceneMouseEvent*>(e);
       
   114 
       
   115     QPointF eventPosition = me->scenePos();
       
   116 
       
   117     QRectF itemGeometry = sceneBoundingRect();
       
   118 
       
   119     if (!itemGeometry.contains(eventPosition)) {
       
   120         emitExternalEvent(e);
       
   121     }
       
   122 }
       
   123 
       
   124 void PopupWebChromeItem::emitExternalEvent(QEvent * e)
       
   125 {
       
   126     QString description;
       
   127 
       
   128     QDebug stream(&description);
       
   129     stream << e;
       
   130 
       
   131     QString name = description;
       
   132     name.truncate(name.indexOf('('));
       
   133 
       
   134     emit externalMouseEvent(e->type(), name, description.trimmed());
       
   135 }
       
   136 
       
   137 } // end of namespace GVA
    79 } // end of namespace GVA