11 #ifndef hifi_OffscreenQmlSurface_h
12 #define hifi_OffscreenQmlSurface_h
14 #include <qml/OffscreenSurface.h>
15 #include <QtGui/qevent.h>
17 #include <QTouchEvent>
19 #include <ScriptEngine.h>
20 #include <PointerEvent.h>
22 using QmlContextCallback = std::function<void(QQmlContext*)>;
24 class OffscreenQmlSurface :
public hifi::qml::OffscreenSurface {
25 using Parent = hifi::qml::OffscreenSurface;
27 Q_PROPERTY(
bool focusText READ isFocusText NOTIFY focusTextChanged)
29 ~OffscreenQmlSurface();
31 static void addWhitelistContextHandler(
const std::initializer_list<QUrl>& urls,
const QmlContextCallback& callback);
32 static void addWhitelistContextHandler(
const QUrl& url,
const QmlContextCallback& callback) { addWhitelistContextHandler({ { url } }, callback); };
33 static void applyWhiteList(
const QUrl& url,QQmlContext* context);
35 bool isFocusText()
const {
return _focusText; }
36 bool getCleaned() {
return _isCleaned; }
38 bool eventFilter(QObject* originalDestination, QEvent* event)
override;
39 void setKeyboardRaised(QObject*
object,
bool raised,
bool numeric =
false,
bool passwordField =
false);
40 Q_INVOKABLE
void synthesizeKeyPress(QString key, QObject* targetOverride =
nullptr);
41 Q_INVOKABLE
void lowerKeyboard();
42 PointerEvent::EventType choosePointerEventType(QEvent::Type type);
43 Q_INVOKABLE
unsigned int deviceIdByTouchPoint(qreal x, qreal y);
47 void focusObjectChanged(QObject* newFocus);
48 void focusTextChanged(
bool focusText);
49 void audioOutputDeviceChanged(
const QString& deviceName);
52 void webEventReceived(
const QVariant& message);
54 void scriptEventReceived(
const QVariant& message);
56 void fromQml(
const QVariant& message);
59 void focusDestroyed(QObject *obj);
61 void emitScriptEvent(
const QVariant& scriptMessage);
63 void emitWebEvent(
const QVariant& webMessage);
65 void sendToQml(
const QVariant& message);
68 void loadFromQml(
const QUrl& qmlSource, QQuickItem* parent,
const QJSValue& callback)
override;
69 void clearFocusItem();
70 void setFocusText(
bool newFocusText);
71 void initializeEngine(QQmlEngine* engine)
override;
72 void onRootContextCreated(QQmlContext* qmlContext)
override;
75 void onRootCreated()
override;
76 void onItemCreated(QQmlContext* qmlContext, QQuickItem* newItem)
override;
77 QQmlContext* contextForUrl(
const QUrl& url, QQuickItem* parent,
bool forceNewContext =
false)
override;
78 QPointF mapWindowToUi(
const QPointF& sourcePosition, QObject* sourceObject);
81 void onFocusObjectChanged(QObject* newFocus)
override;
84 void hoverBeginEvent(
const PointerEvent& event,
class QTouchDevice& device);
85 void hoverEndEvent(
const PointerEvent& event,
class QTouchDevice& device);
86 bool handlePointerEvent(
const PointerEvent& event,
class QTouchDevice& device,
bool release =
false);
87 void changeAudioOutputDevice(
const QString& deviceName,
bool isHtmlUpdate =
false);
88 void forceHtmlAudioOutputDeviceUpdate();
89 void forceQmlAudioOutputDeviceUpdate();
92 bool _focusText {
false };
93 bool _isCleaned{
false };
94 QQuickItem* _currentFocusItem {
nullptr };
97 QTouchEvent::TouchPoint touchPoint;
98 bool hovering {
false };
99 bool pressed {
false };
103 bool _touchBeginAccepted {
false };
104 std::map<uint32_t, TouchState> _activeTouchPoints;
106 QString _currentAudioOutputDevice;
107 QTimer _audioOutputUpdateTimer;
Represents a 2D or 3D pointer to the scripting engine. Exposed as PointerEvent
Definition: PointerEvent.h:30