diff -r bf4420e9fa4d -r 2e16851ffecd ginebra2/PopupWebChromeItem.cpp --- a/ginebra2/PopupWebChromeItem.cpp Fri Jun 11 16:23:26 2010 +0100 +++ b/ginebra2/PopupWebChromeItem.cpp Thu Jul 22 16:30:16 2010 +0100 @@ -1,63 +1,72 @@ /* * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published by +* the Free Software Foundation, version 2.1 of the License. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. * -* Contributors: +* You should have received a copy of the GNU Lesser General Public License +* along with this program. If not, +* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". * -* Description: +* Description: * */ - #include "PopupWebChromeItem.h" #include "ChromeWidget.h" #include "WebChromeSnippet.h" +#include "ExternalEventCharm.h" namespace GVA { PopupWebChromeItem::PopupWebChromeItem( - const QRectF & ownerArea, ChromeWidget * chrome, const QWebElement & element, - QGraphicsItem * parent) -: WebChromeItem(ownerArea, chrome, element, parent) + QGraphicsItem * parent, + bool modal) +: WebChromeItem(chrome, element, parent), + m_modal(modal), + m_externalEventCharm(0) { } PopupWebChromeItem::~PopupWebChromeItem() -{} +{ + delete m_externalEventCharm; +} void PopupWebChromeItem::init(WebChromeSnippet * snippet) { WebChromeItem::init(snippet); + m_externalEventCharm = new ExternalEventCharm(this); // Forward externalMouseEvent signals from context items. QObject::connect( - this, - SIGNAL(externalMouseEvent(int, const QString &, const QString &)), + m_externalEventCharm, + SIGNAL(externalMouseEvent(QEvent *, const QString &, const QString &)), snippet, - SIGNAL(externalMouseEvent(int, const QString &, const QString &))); + SIGNAL(externalMouseEvent(QEvent *, const QString &, const QString &))); } bool PopupWebChromeItem::event(QEvent * e) { - // Check for external events grabbed by this item. - - checkForExternalEvent(this, e); - - switch(e->type()) { + switch (e->type()) { case QEvent::Show: - scene()->installEventFilter(this); + if(snippet() && m_modal) { + chrome()->emitPopupShown(snippet()->objectName()); + } break; case QEvent::Hide: - scene()->removeEventFilter(this); + if(snippet() && m_modal) { + chrome()->emitPopupHidden(snippet()->objectName()); + } break; default: break; } @@ -67,71 +76,4 @@ return WebChromeItem::event(e); } -bool PopupWebChromeItem::eventFilter(QObject * o, QEvent * e) -{ - // Check for external events NOT grabbed by this item. - - checkForExternalEvent(o, e); - - // Don't filter any events. - - return false; -} - -void PopupWebChromeItem::checkForExternalEvent(QObject * o, QEvent * e) -{ - Q_UNUSED(o); - - // Ignore all events when this item is not showing. - - if (!isVisible()) { - return; - } - - // Ignore all but a few mouse press events. - - switch (e->type()) { - case QEvent::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseRelease: - case QEvent::GraphicsSceneMouseDoubleClick: - case QEvent::GraphicsSceneResize: - break; - default: - return; - } - - // Check where the mouse press event occurred. - // If it was outside this item's bounding rectangle, - // then tell the world. - - if(e->type() == QEvent::GraphicsSceneResize) - { - emitExternalEvent(e); - return; - } - - QGraphicsSceneMouseEvent * me = static_cast(e); - - QPointF eventPosition = me->scenePos(); - - QRectF itemGeometry = sceneBoundingRect(); - - if (!itemGeometry.contains(eventPosition)) { - emitExternalEvent(e); - } -} - -void PopupWebChromeItem::emitExternalEvent(QEvent * e) -{ - QString description; - - QDebug stream(&description); - stream << e; - - QString name = description; - name.truncate(name.indexOf('(')); - - emit externalMouseEvent(e->type(), name, description.trimmed()); -} - } // end of namespace GVA