Skip to content

Commit df3ead0

Browse files
author
Raphael Dumusc
authored
Merge pull request #123 from rdumusc/webengineview
Make QmlStreamer compatible with Qml WebEngineView
2 parents ca13bd6 + 4956a1f commit df3ead0

File tree

10 files changed

+223
-32
lines changed

10 files changed

+223
-32
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ common_find_package(LibJpegTurbo REQUIRED)
3030
common_find_package(OpenGL)
3131
common_find_package(Qt5Concurrent REQUIRED SYSTEM)
3232
common_find_package(Qt5Core REQUIRED)
33+
common_find_package(Qt5Gui COMPONENTS Private) # For Qml WebEngineView
3334
if(APPLE)
3435
common_find_package(Qt5MacExtras)
3536
endif()

deflect/qt/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11

2-
# Copyright (c) 2015, EPFL/Blue Brain Project
3-
# Daniel Nachbaur <daniel.nachbaur@epfl.ch>
2+
# Copyright (c) 2015-2016, EPFL/Blue Brain Project
3+
# Daniel Nachbaur <daniel.nachbaur@epfl.ch>
4+
# Raphael Dumusc <raphael.dumusc@epfl.ch>
45

5-
set(DEFLECTQT_HEADERS EventReceiver.h QmlStreamerImpl.h)
6+
set(DEFLECTQT_HEADERS EventReceiver.h QmlGestures.h QmlStreamerImpl.h)
67
set(DEFLECTQT_PUBLIC_HEADERS QmlStreamer.h)
78
set(DEFLECTQT_SOURCES EventReceiver.cpp QmlStreamer.cpp QmlStreamerImpl.cpp)
89
set(DEFLECTQT_LINK_LIBRARIES
910
PUBLIC Deflect Qt5::Quick PRIVATE Qt5::Qml)
1011
set(DEFLECTQT_INCLUDE_NAME deflect/qt)
1112
set(DEFLECTQT_NAMESPACE deflectqt)
1213
common_library(DeflectQt)
14+
15+
if(TARGET Qt5::Gui)
16+
target_include_directories(DeflectQt SYSTEM PRIVATE
17+
"$<BUILD_INTERFACE:${Qt5Gui_PRIVATE_INCLUDE_DIRS}>")
18+
endif()

deflect/qt/EventReceiver.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,18 @@ void EventReceiver::_onEvent( int socket )
9797
emit wheeled( deflectEvent.mouseX, deflectEvent.mouseY,
9898
deflectEvent.dy );
9999
break;
100-
101-
case Event::EVT_CLICK:
102-
case Event::EVT_DOUBLECLICK:
103100
case Event::EVT_SWIPE_LEFT:
101+
emit swipeLeft();
102+
break;
104103
case Event::EVT_SWIPE_RIGHT:
104+
emit swipeRight();
105+
break;
105106
case Event::EVT_SWIPE_UP:
107+
emit swipeUp();
108+
break;
106109
case Event::EVT_SWIPE_DOWN:
110+
emit swipeDown();
111+
break;
107112
case Event::EVT_KEY_PRESS:
108113
emit keyPress( deflectEvent.key, deflectEvent.modifiers,
109114
QString::fromStdString( deflectEvent.text ));
@@ -112,6 +117,8 @@ void EventReceiver::_onEvent( int socket )
112117
emit keyRelease( deflectEvent.key, deflectEvent.modifiers,
113118
QString::fromStdString( deflectEvent.text ));
114119
break;
120+
case Event::EVT_CLICK:
121+
case Event::EVT_DOUBLECLICK:
115122
default:
116123
break;
117124
}

deflect/qt/EventReceiver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class EventReceiver : public QObject
6767
void wheeled( double x, double y, double dy );
6868
void keyPress( int key, int modifiers, QString text );
6969
void keyRelease( int key, int modifiers, QString text );
70+
void swipeLeft();
71+
void swipeRight();
72+
void swipeUp();
73+
void swipeDown();
7074

7175
private slots:
7276
void _onEvent( int socket );

deflect/qt/QmlGestures.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*********************************************************************/
2+
/* Copyright (c) 2016, EPFL/Blue Brain Project */
3+
/* Raphael Dumusc <raphael.dumusc@epfl.ch> */
4+
/* All rights reserved. */
5+
/* */
6+
/* Redistribution and use in source and binary forms, with or */
7+
/* without modification, are permitted provided that the following */
8+
/* conditions are met: */
9+
/* */
10+
/* 1. Redistributions of source code must retain the above */
11+
/* copyright notice, this list of conditions and the following */
12+
/* disclaimer. */
13+
/* */
14+
/* 2. Redistributions in binary form must reproduce the above */
15+
/* copyright notice, this list of conditions and the following */
16+
/* disclaimer in the documentation and/or other materials */
17+
/* provided with the distribution. */
18+
/* */
19+
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
20+
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
21+
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
22+
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
23+
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
24+
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
25+
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
26+
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
27+
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
28+
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
29+
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
30+
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
31+
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
32+
/* POSSIBILITY OF SUCH DAMAGE. */
33+
/* */
34+
/* The views and conclusions contained in the software and */
35+
/* documentation are those of the authors and should not be */
36+
/* interpreted as representing official policies, either expressed */
37+
/* or implied, of Ecole polytechnique federale de Lausanne. */
38+
/*********************************************************************/
39+
40+
#ifndef QMLGESTURES_H
41+
#define QMLGESTURES_H
42+
43+
#include <QObject>
44+
45+
namespace deflect
46+
{
47+
namespace qt
48+
{
49+
50+
/**
51+
* Expose gesture events as a Qml context property object.
52+
*/
53+
class QmlGestures : public QObject
54+
{
55+
Q_OBJECT
56+
57+
signals:
58+
void swipeLeft();
59+
void swipeRight();
60+
void swipeUp();
61+
void swipeDown();
62+
};
63+
64+
}
65+
}
66+
67+
#endif

deflect/qt/QmlStreamer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include "QmlStreamer.h"
4141
#include "QmlStreamerImpl.h"
4242

43+
#include "../Stream.h"
44+
4345
namespace deflect
4446
{
4547
namespace qt
@@ -68,5 +70,10 @@ QQmlEngine* QmlStreamer::getQmlEngine()
6870
return _impl->getQmlEngine();
6971
}
7072

73+
bool QmlStreamer::sendData( const QByteArray data )
74+
{
75+
return _impl->getStream()->sendData( data.constData(), data.size( ));
76+
}
77+
7178
}
7279
}

deflect/qt/QmlStreamer.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ namespace qt
5959
* This class renders the given QML file in an offscreen fashion and streams
6060
* on each update on the given Deflect stream. It automatically register also
6161
* for Deflect events, which can be directly handled in the QML.
62+
63+
* Users can make connections to the "deflectgestures" context property to react
64+
* to certain gestures received as Event, currently swipe[Left|Right|Up|Down].
65+
*
66+
* When using a WebEngineView, users must call QtWebEngine::initialize() in the
67+
* QApplication before creating the streamer. Also, due to a limitiation in Qt,
68+
* the objectName property of any WebEngineView must be set to "webengineview"
69+
* for it to receive keyboard events.
6270
*/
6371
class QmlStreamer : public QObject
6472
{
@@ -87,6 +95,14 @@ class QmlStreamer : public QObject
8795
/** @return the QML engine. */
8896
DEFLECTQT_API QQmlEngine* getQmlEngine();
8997

98+
/**
99+
* Send data to the Server.
100+
*
101+
* @param data the data buffer
102+
* @return true if the data could be sent, false otherwise
103+
*/
104+
DEFLECTQT_API bool sendData( QByteArray data );
105+
90106
signals:
91107
/** Emitted when the stream has been closed. */
92108
void streamClosed();

0 commit comments

Comments
 (0)