forked from RSATom/QuickLayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFboQuickView.cpp
109 lines (86 loc) · 2.52 KB
/
FboQuickView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "FboQuickView.h"
#include <QScopedPointer>
#include <QQuickItem>
FboQuickView::FboQuickView( QOpenGLContext* context /*= 0*/ )
: FboQuickWindow( context ), m_qmlComponent( 0 ), m_rootItem( 0 )
{
}
FboQuickView::~FboQuickView()
{
}
QQmlContext* FboQuickView::rootContext() const
{
return m_qmlEngine.rootContext();
}
void FboQuickView::setSource( const QUrl& source )
{
if( m_rootItem ) {
delete m_rootItem;
m_rootItem = 0;
}
if( m_qmlComponent ) {
delete m_qmlComponent;
m_qmlComponent = 0;
}
if( !source.isEmpty() ) {
m_qmlComponent = new QQmlComponent( &m_qmlEngine, &m_qmlEngine );
connect( m_qmlComponent, &QQmlComponent::statusChanged,
this, &FboQuickView::componentStatusChanged );
m_qmlComponent->loadUrl( source );
}
}
void FboQuickView::setQml( const QString& qml, const QUrl& qmlUrl )
{
if( m_rootItem ) {
delete m_rootItem;
m_rootItem = 0;
}
if( m_qmlComponent ) {
delete m_qmlComponent;
m_qmlComponent = 0;
}
if( !qml.isEmpty() ) {
m_qmlComponent = new QQmlComponent( &m_qmlEngine, &m_qmlEngine );
connect( m_qmlComponent, &QQmlComponent::statusChanged,
this, &FboQuickView::componentStatusChanged );
m_qmlComponent->setData( qml.toUtf8(), qmlUrl );
}
}
void FboQuickView::componentStatusChanged( QQmlComponent::Status status )
{
Q_ASSERT( !m_rootItem );
if( QQmlComponent::Ready != status ) {
Q_EMIT statusChanged( status );
return;
}
QScopedPointer<QObject> rootObject( m_qmlComponent->create() );
m_rootItem = qobject_cast<QQuickItem*>( rootObject.data() );
if( !m_rootItem ) {
Q_EMIT statusChanged( QQmlComponent::Error );
return;
}
contentItem()->setFocus( true );
rootObject.take()->setParent( contentItem() );
m_rootItem->setParentItem( contentItem() );
QResizeEvent event( size(), size() );
resizeEvent( &event );
Q_EMIT statusChanged( QQmlComponent::Ready );
}
void FboQuickView::resizeEvent( QResizeEvent* event )
{
FboQuickWindow::resizeEvent( event );
if( m_rootItem )
m_rootItem->setSize( QSizeF( width(), height() ) );
}
QList<QQmlError> FboQuickView::errors() const
{
if( m_qmlComponent )
return m_qmlComponent->errors();
return QList<QQmlError>();
}
FboQuickView::Status FboQuickView::status() const
{
if( !m_qmlComponent )
return QQmlComponent::Null;
return m_qmlComponent->status();
}