2
Copyright (c) 2010 Volker Krause <vkrause@kde.org>
4
This library is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or (at your
7
option) any later version.
9
This library is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12
License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
#include "declarativewidgetbase.h"
22
#include "stylesheetloader.h"
24
#include <QtGui/QGraphicsScene>
25
#include <QtGui/QWidget>
28
bool DeclarativeWidgetBaseHelper::eventFilter( QObject *object, QEvent *event )
30
if ( object == this && event->type() == QEvent::Hide ) {
31
QWidget *widget = static_cast<QWidget*>( object );
32
QMetaObject::invokeMethod( widget, "show", Qt::QueuedConnection );
33
qDebug("Ate hide event");
36
return QGraphicsProxyWidget::eventFilter( object, event );
40
DeclarativeWidgetBaseHelper::DeclarativeWidgetBaseHelper( QWidget * widget, QGraphicsItem * parent, const RegisterFunction & registerFunc )
41
: QGraphicsProxyWidget( parent ),
42
m_registerFunc( registerFunc ),
47
QPalette pal = m_widget->palette();
48
pal.setColor( QPalette::Window, QColor( 0, 0, 0, 0 ) );
49
m_widget->setPalette( pal );
50
StyleSheetLoader::applyStyle( m_widget );
51
setWidget( m_widget );
52
setFocusPolicy( Qt::StrongFocus );
54
m_widget->installEventFilter( this );
58
DeclarativeWidgetBaseHelper::~DeclarativeWidgetBaseHelper()
61
m_widget->removeEventFilter( this );
65
QVariant DeclarativeWidgetBaseHelper::itemChange( GraphicsItemChange change, const QVariant & value )
67
if ( !m_registerFunc.empty() )
68
if ( change == ItemSceneHasChanged )
69
if ( QGraphicsScene* scene = value.value<QGraphicsScene*>() )
70
Q_FOREACH( QGraphicsView * v, scene->views() )
71
m_registerFunc( v, m_widget );
72
return QGraphicsProxyWidget::itemChange ( change, value );