1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00
ScreenPlay/ScreenPlayWidget/qml/Widget.qml

256 lines
7.1 KiB
QML
Raw Permalink Normal View History

import QtQuick
import QtQuick.Controls
import QtWebEngine
import ScreenPlayWidget
import ScreenPlay.Enums.InstalledType
import ScreenPlayUtil as Util
2018-03-08 22:03:05 +01:00
Item {
id: root
// We must set a default size not not
// trigger render errors.
width: 200
height: 100
state: "out"
opacity: 0
Connections {
target: Widget
function onQmlExit() {
if (Qt.platform.os === "windows")
2023-02-02 15:25:26 +01:00
Widget.setWindowBlur(0);
loader.source = "";
animFadeOut.start();
2020-01-10 15:26:53 +01:00
}
function onQmlSceneValueReceived(key, value) {
2023-02-02 15:25:26 +01:00
var obj2 = 'import QtQuick; Item {Component.onCompleted: loader.item.' + key + ' = ' + value + '; }';
var newObject = Qt.createQmlObject(obj2.toString(), root, "err");
newObject.destroy(10000);
}
2021-05-16 19:37:55 +02:00
2021-05-14 13:11:12 +02:00
// Replace wallpaper with QML Scene
function onReloadQML(oldType) {
2023-02-02 15:25:26 +01:00
loader.sourceComponent = undefined;
loader.source = "";
Widget.clearComponentCache();
loader.source = Qt.resolvedUrl(Widget.projectSourceFileAbsolute);
2020-01-23 09:48:48 +01:00
}
}
2019-06-13 18:06:24 +02:00
OpacityAnimator {
id: animFadeOut
from: 1
to: 0
target: root
2019-06-13 18:06:24 +02:00
duration: 800
easing.type: Easing.InOutQuad
onFinished: Widget.destroyThis()
2019-06-13 18:06:24 +02:00
}
Image {
id: bgNoise
source: "qrc:/qml/ScreenPlayWidget/assets/image/noisy-texture-3.png"
anchors.fill: parent
fillMode: Image.Tile
opacity: 0
}
2023-02-18 14:30:06 +01:00
Connections {
ignoreUnknownSignals: true
target: loader.item
// Some width do not know their implicit size,
// see the xkcd example.
function onImplicitWidthChanged() {
print();
root.width = loader.item.implicitWidth;
2023-02-18 14:30:06 +01:00
}
function onImplicitHeightChanged() {
root.height = loader.item.implicitHeight;
2023-02-18 14:30:06 +01:00
}
}
Loader {
id: loader
opacity: 0
anchors.fill: parent
asynchronous: true
Component.onCompleted: {
switch (Widget.type) {
case InstalledType.QMLWidget:
2023-02-02 15:25:26 +01:00
loader.source = Qt.resolvedUrl(Widget.projectSourceFileAbsolute);
break;
case InstalledType.HTMLWidget:
2023-02-02 15:25:26 +01:00
loader.sourceComponent = webViewComponent;
break;
}
}
onStatusChanged: {
if (loader.status == Loader.Ready && loader.source !== "") {
if (loader.item.implicitWidth === 0 || loader.item.implicitHeight === 0) {
print("Implicit size is 0, using root size");
loader.item.implicitWidth = root.width;
loader.item.implicitHeight = root.height;
2023-02-18 14:13:23 +01:00
}
// Resize to loaded widget size
// Note: We must use implicit* here to not
// break the set values.
2023-02-02 15:25:26 +01:00
root.width = loader.item.implicitWidth;
root.height = loader.item.implicitHeight;
Widget.show();
root.state = "in";
}
}
}
Component {
id: webViewComponent
2021-05-16 19:37:55 +02:00
WebEngineView {
id: webView
2021-05-16 19:37:55 +02:00
backgroundColor: "transparent"
anchors.fill: parent
onJavaScriptConsoleMessage: print(lineNumber, message)
Component.onCompleted: {
2023-02-02 15:25:26 +01:00
webView.url = Qt.resolvedUrl(Widget.sourcePath);
}
}
}
Item {
id: nav
height: 20
anchors {
top: parent.top
right: parent.right
left: parent.left
}
Rectangle {
id: bg
anchors.fill: parent
color: "black"
opacity: 0
2018-11-24 14:28:02 +01:00
}
MouseArea {
id: mouseArea
height: 20
property var clickPos
2018-03-21 18:56:58 +01:00
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
onEntered: imgClose.state = "areaHover"
onExited: {
if (mouseAreaClose.containsMouse)
return;
imgClose.state = "";
}
2021-05-16 19:37:55 +02:00
onPressed: function (mouse) {
clickPos = {
"x": mouse.x,
"y": mouse.y
};
}
onPositionChanged: {
if (mouseArea.pressed)
Widget.setPos(Widget.cursorPos().x - clickPos.x, Widget.cursorPos().y - clickPos.y);
}
2019-06-13 18:06:24 +02:00
}
MouseArea {
id: mouseAreaClose
width: 16
height: width
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onEntered: imgClose.state = "iconHover"
onExited: imgClose.state = ""
onClicked: {
if (Qt.platform.os === "windows")
Widget.setWindowBlur(0);
animFadeOut.start();
}
anchors {
margins: 1
top: parent.top
right: parent.right
}
ColorImage {
id: imgClose
source: "qrc:/qml/ScreenPlayWidget/assets/icons/baseline-close-24px.svg"
anchors.centerIn: parent
width: parent.width
height: parent.height
sourceSize: Qt.size(width, height)
opacity: 0
color: "white"
states: [
State {
name: "areaHover"
PropertyChanges {
target: imgClose
opacity: .5
}
2023-06-11 10:07:39 +02:00
PropertyChanges {
target: bg
opacity: .3
}
},
State {
name: "iconHover"
PropertyChanges {
target: imgClose
opacity: 1
}
}
]
transitions: [
Transition {
PropertyAnimation {
duration: 250
target: imgClose
property: "opacity"
}
}
]
}
2019-06-13 18:06:24 +02:00
}
}
states: [
State {
name: "in"
PropertyChanges {
target: root
opacity: 1
}
PropertyChanges {
target: bgNoise
opacity: 0.05
}
PropertyChanges {
target: loader
opacity: 1
}
}
]
transitions: [
Transition {
from: "out"
to: "in"
PropertyAnimation {
targets: [root, bgNoise, loader, bg]
duration: 250
property: "opacity"
}
}
]
2018-03-08 22:03:05 +01:00
}