detect when mouse is over QML overlays or 2D JS Overlays

This commit is contained in:
Brad Hefta-Gaub 2016-02-23 10:14:44 -08:00
parent 3f7a2eb10a
commit 2db25690f1
8 changed files with 37 additions and 8 deletions

View file

@ -5,6 +5,8 @@ import QtQuick.Controls 1.2
Item {
anchors.fill: parent
anchors.leftMargin: 300
objectName: "StatsItem"
Hifi.Stats {
id: root
objectName: "Stats"
@ -27,6 +29,7 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: { root.expanded = !root.expanded; }
hoverEnabled: true
}
Column {
@ -83,6 +86,7 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: { root.expanded = !root.expanded; }
hoverEnabled: true
}
Column {
id: pingCol
@ -123,6 +127,7 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: { root.expanded = !root.expanded; }
hoverEnabled: true
}
Column {
id: geoCol
@ -172,6 +177,7 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: { root.expanded = !root.expanded; }
hoverEnabled: true
}
Column {
id: octreeCol

View file

@ -304,6 +304,7 @@ FocusScope {
Rectangle {
id: focusDebugger;
objectName: "focusDebugger"
z: 9999; visible: false; color: "red"
ColorAnimation on color { from: "#7fffff00"; to: "#7f0000ff"; duration: 1000; loops: 9999 }
}

View file

@ -2,6 +2,7 @@ import QtQuick 2.5
FocusScope {
id: root
objectName: "FocusHack"
TextInput {
id: textInput;

View file

@ -8,6 +8,22 @@ import ".."
Desktop {
id: desktop
MouseArea {
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
scrollGestureEnabled: false // we don't need/want these
onEntered: ApplicationCompositor.reticleOverDesktop = true
onExited: ApplicationCompositor.reticleOverDesktop = false
onClicked: mouse.accepted = false
onCanceled: mouse.accepted = false
onDoubleClicked: mouse.accepted = false
onPressed: mouse.accepted = false
onReleased: mouse.accepted = false
onWheel: mouse.accepted = false
onPositionChanged: mouse.accepted = false
}
Component.onCompleted: {
WebEngine.settings.javascriptCanOpenWindows = true;
WebEngine.settings.javascriptCanAccessClipboard = false;

View file

@ -6,9 +6,11 @@ import "."
Item {
id: root
anchors.fill: parent
objectName: "MouseMenuHandlerItem"
MouseArea {
id: menuRoot;
objectName: "MouseMenuHandlerMouseArea"
anchors.fill: parent
enabled: d.topMenu !== null
onClicked: {

View file

@ -1259,6 +1259,8 @@ void Application::initializeUi() {
rootContext->setContextProperty("Render", _renderEngine->getConfiguration().get());
rootContext->setContextProperty("Reticle", _compositor.getReticleInterface());
rootContext->setContextProperty("ApplicationCompositor", &_compositor);
_glWidget->installEventFilter(offscreenUi.data());
offscreenUi->setMouseTranslator([=](const QPointF& pt) {
QPointF result = pt;

View file

@ -395,7 +395,7 @@ bool ApplicationCompositor::handleRealMouseMoveEvent(bool sendFakeEvent) {
return false; // let the caller know to process the event
}
glm::vec2 ApplicationCompositor::getReticlePosition() {
glm::vec2 ApplicationCompositor::getReticlePosition() const {
if (qApp->isHMDMode()) {
QMutexLocker locker(&_reticleLock);
return _reticlePositionInHMD;

View file

@ -47,6 +47,7 @@ class ApplicationCompositor : public QObject {
Q_OBJECT
Q_PROPERTY(float alpha READ getAlpha WRITE setAlpha)
Q_PROPERTY(bool reticleOverDesktop READ getReticleOverDesktop WRITE setReticleOverDesktop)
public:
ApplicationCompositor();
~ApplicationCompositor();
@ -84,14 +85,14 @@ public:
float getAlpha() const { return _alpha; }
void setAlpha(float alpha) { _alpha = alpha; }
bool getReticleVisible() { return _reticleVisible; }
bool getReticleVisible() const { return _reticleVisible; }
void setReticleVisible(bool visible) { _reticleVisible = visible; }
float getReticleDepth() { return _reticleDepth; }
float getReticleDepth() const { return _reticleDepth; }
void setReticleDepth(float depth) { _reticleDepth = depth; }
void resetReticleDepth() { _reticleDepth = DEFAULT_RETICLE_DEPTH; }
glm::vec2 getReticlePosition();
glm::vec2 getReticlePosition() const;
void setReticlePosition(glm::vec2 position, bool sendFakeEvent = true);
glm::vec2 getReticleMaximumPosition() const;
@ -106,9 +107,11 @@ public:
bool shouldCaptureMouse() const;
/// if the reticle is pointing to a system overlay (a dialog box for example) then the function returns true otherwise false
bool isReticlePointingAtSystemOverlay() const { return _reticleOverQml; }
bool getReticleOverDesktop() const { return _isOverDesktop; }
void setReticleOverDesktop(bool value) { _isOverDesktop = value; }
private:
bool _isOverDesktop { true };
void displayOverlayTextureStereo(RenderArgs* renderArgs, float aspectRatio, float fov);
void bindCursorTexture(gpu::Batch& batch, uint8_t cursorId = 0);
@ -176,6 +179,7 @@ public:
ReticleInterface(ApplicationCompositor* outer) : QObject(outer), _compositor(outer) {}
Q_INVOKABLE bool isMouseCaptured() { return _compositor->shouldCaptureMouse(); }
Q_INVOKABLE bool isPointingAtSystemOverlay() { return !_compositor->getReticleOverDesktop(); }
Q_INVOKABLE bool getVisible() { return _compositor->getReticleVisible(); }
Q_INVOKABLE void setVisible(bool visible) { _compositor->setReticleVisible(visible); }
@ -188,9 +192,6 @@ public:
Q_INVOKABLE glm::vec2 getMaximumPosition() { return _compositor->getReticleMaximumPosition(); }
Q_INVOKABLE bool isPointingAtSystemOverlay() { return _compositor->isReticlePointingAtSystemOverlay(); }
private:
ApplicationCompositor* _compositor;
};