mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 23:36:44 +02:00
commit
83d9d4d4be
5 changed files with 59 additions and 41 deletions
|
@ -3,8 +3,7 @@ import QtWebEngine 1.1
|
||||||
|
|
||||||
WebEngineView {
|
WebEngineView {
|
||||||
id: root
|
id: root
|
||||||
property var originalUrl
|
property var newUrl;
|
||||||
property int lastFixupTime: 0
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
console.log("Connecting JS messaging to Hifi Logging")
|
console.log("Connecting JS messaging to Hifi Logging")
|
||||||
|
@ -14,19 +13,26 @@ WebEngineView {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME hack to get the URL with the auth token included. Remove when we move to Qt 5.6
|
||||||
|
Timer {
|
||||||
|
id: urlReplacementTimer
|
||||||
|
running: false
|
||||||
|
repeat: false
|
||||||
|
interval: 50
|
||||||
|
onTriggered: url = newUrl;
|
||||||
|
}
|
||||||
|
|
||||||
onUrlChanged: {
|
onUrlChanged: {
|
||||||
var currentUrl = url.toString();
|
console.log("Url changed to " + url);
|
||||||
var newUrl = urlHandler.fixupUrl(currentUrl).toString();
|
var originalUrl = url.toString();
|
||||||
if (newUrl != currentUrl) {
|
newUrl = urlHandler.fixupUrl(originalUrl).toString();
|
||||||
var now = new Date().valueOf();
|
if (newUrl !== originalUrl) {
|
||||||
if (url === originalUrl && (now - lastFixupTime < 100)) {
|
root.stop();
|
||||||
console.warn("URL fixup loop detected")
|
if (urlReplacementTimer.running) {
|
||||||
|
console.warn("Replacement timer already running");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
originalUrl = url
|
urlReplacementTimer.start();
|
||||||
lastFixupTime = now
|
|
||||||
url = newUrl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,7 @@ import "../controls"
|
||||||
|
|
||||||
Frame {
|
Frame {
|
||||||
id: frame
|
id: frame
|
||||||
// The frame fills the parent, which should be the size of the content.
|
|
||||||
// The frame decorations use negative anchor margins to extend beyond
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
// FIXME needed?
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors { margins: -iconSize; topMargin: -iconSize * ((window && window.closable) ? 2 : 1); }
|
anchors { margins: -iconSize; topMargin: -iconSize * ((window && window.closable) ? 2 : 1); }
|
||||||
anchors.fill: parent;
|
anchors.fill: parent;
|
||||||
|
@ -18,8 +14,6 @@ Frame {
|
||||||
|
|
||||||
// Allow dragging of the window
|
// Allow dragging of the window
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: dragMouseArea
|
|
||||||
hoverEnabled: true
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
drag.target: window
|
drag.target: window
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ import "../js/Utils.js" as Utils
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: frame
|
id: frame
|
||||||
|
// Frames always fill their parents, but their decorations may extend
|
||||||
|
// beyond the window via negative margin sizes
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
// Convenience accessor for the window
|
// Convenience accessor for the window
|
||||||
property alias window: frame.parent
|
property alias window: frame.parent
|
||||||
|
|
|
@ -5,10 +5,6 @@ import "../controls"
|
||||||
|
|
||||||
Frame {
|
Frame {
|
||||||
id: frame
|
id: frame
|
||||||
// The frame fills the parent, which should be the size of the content.
|
|
||||||
// The frame decorations use negative anchor margins to extend beyond
|
|
||||||
anchors.fill: parent
|
|
||||||
property alias window: frame.parent
|
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
@ -16,15 +12,6 @@ Frame {
|
||||||
visible: window.visible
|
visible: window.visible
|
||||||
color: "#7f7f7f7f";
|
color: "#7f7f7f7f";
|
||||||
radius: 3;
|
radius: 3;
|
||||||
MouseArea {
|
|
||||||
enabled: window.visible
|
|
||||||
anchors.fill: parent
|
|
||||||
acceptedButtons: Qt.AllButtons
|
|
||||||
onClicked: {}
|
|
||||||
onDoubleClicked: {}
|
|
||||||
onPressAndHold: {}
|
|
||||||
onReleased: {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,11 @@ Fadable {
|
||||||
implicitHeight: content.height
|
implicitHeight: content.height
|
||||||
implicitWidth: content.width
|
implicitWidth: content.width
|
||||||
x: -1; y: -1
|
x: -1; y: -1
|
||||||
|
enabled: visible
|
||||||
|
|
||||||
|
signal windowDestroyed();
|
||||||
|
|
||||||
property int modality: Qt.NonModal
|
property int modality: Qt.NonModal
|
||||||
|
|
||||||
readonly property bool topLevelWindow: true
|
readonly property bool topLevelWindow: true
|
||||||
property string title
|
property string title
|
||||||
// Should the window be closable control?
|
// Should the window be closable control?
|
||||||
|
@ -37,7 +39,6 @@ Fadable {
|
||||||
property bool resizable: false
|
property bool resizable: false
|
||||||
property vector2d minSize: Qt.vector2d(100, 100)
|
property vector2d minSize: Qt.vector2d(100, 100)
|
||||||
property vector2d maxSize: Qt.vector2d(1280, 720)
|
property vector2d maxSize: Qt.vector2d(1280, 720)
|
||||||
enabled: visible
|
|
||||||
|
|
||||||
// The content to place inside the window, determined by the client
|
// The content to place inside the window, determined by the client
|
||||||
default property var content
|
default property var content
|
||||||
|
@ -53,27 +54,39 @@ Fadable {
|
||||||
propagateComposedEvents: true
|
propagateComposedEvents: true
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
acceptedButtons: Qt.AllButtons
|
acceptedButtons: Qt.AllButtons
|
||||||
|
enabled: window.visible
|
||||||
onPressed: {
|
onPressed: {
|
||||||
//console.log("Pressed on activator area");
|
//console.log("Pressed on activator area");
|
||||||
window.raise();
|
window.raise();
|
||||||
mouse.accepted = false;
|
mouse.accepted = false;
|
||||||
}
|
}
|
||||||
// Debugging
|
|
||||||
// onEntered: console.log("activator entered")
|
|
||||||
// onExited: console.log("activator exited")
|
|
||||||
// onContainsMouseChanged: console.log("Activator contains mouse " + containsMouse)
|
|
||||||
// onPositionChanged: console.log("Activator mouse position " + mouse.x + " x " + mouse.y)
|
|
||||||
// Rectangle { anchors.fill:parent; color: "#7f00ff00" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signal windowDestroyed();
|
// This mouse area serves to swallow mouse events while the mouse is over the window
|
||||||
|
// to prevent things like mouse wheel events from reaching the application and changing
|
||||||
|
// the camera if the user is scrolling through a list and gets to the end.
|
||||||
|
property var swallower: MouseArea {
|
||||||
|
width: frame.decoration.width
|
||||||
|
height: frame.decoration.height
|
||||||
|
x: frame.decoration.anchors.margins
|
||||||
|
y: frame.decoration.anchors.topMargin
|
||||||
|
hoverEnabled: true
|
||||||
|
acceptedButtons: Qt.AllButtons
|
||||||
|
enabled: window.visible
|
||||||
|
onClicked: {}
|
||||||
|
onDoubleClicked: {}
|
||||||
|
onPressAndHold: {}
|
||||||
|
onReleased: {}
|
||||||
|
onWheel: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Default to a standard frame. Can be overriden to provide custom
|
// Default to a standard frame. Can be overriden to provide custom
|
||||||
// frame styles, like a full desktop frame to simulate a modal window
|
// frame styles, like a full desktop frame to simulate a modal window
|
||||||
property var frame: DefaultFrame { }
|
property var frame: DefaultFrame { }
|
||||||
|
|
||||||
|
|
||||||
children: [ frame, content, activator ]
|
children: [ swallower, frame, content, activator ]
|
||||||
|
|
||||||
Component.onCompleted: raise();
|
Component.onCompleted: raise();
|
||||||
Component.onDestruction: windowDestroyed();
|
Component.onDestruction: windowDestroyed();
|
||||||
|
@ -124,12 +137,27 @@ Fadable {
|
||||||
|
|
||||||
Keys.onPressed: {
|
Keys.onPressed: {
|
||||||
switch(event.key) {
|
switch(event.key) {
|
||||||
|
case Qt.Key_Control:
|
||||||
|
case Qt.Key_Shift:
|
||||||
|
case Qt.Key_Meta:
|
||||||
|
case Qt.Key_Alt:
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
case Qt.Key_W:
|
case Qt.Key_W:
|
||||||
if (window.closable && (event.modifiers === Qt.ControlModifier)) {
|
if (window.closable && (event.modifiers === Qt.ControlModifier)) {
|
||||||
visible = false
|
visible = false
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
}
|
}
|
||||||
break
|
// fall through
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Consume unmodified keyboard entries while the window is focused, to prevent them
|
||||||
|
// from propagating to the application
|
||||||
|
if (event.modifiers === Qt.NoModifier) {
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue