1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-18 16:32:33 +02:00
ScreenPlay/ScreenPlayWidget/qml/Widget.qml

192 lines
4.5 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import QtWebEngine
import ScreenPlayWidget 1.0
import ScreenPlay.Enums.InstalledType 1.0
2018-03-08 22:03:05 +01:00
Item {
2018-03-08 22:03:05 +01:00
id: mainWindow
2021-05-16 19:37:55 +02:00
anchors.fill: parent
Connections {
function onQmlExit() {
if(Qt.platform.os === "windows")
Widget.setWindowBlur(0);
2021-05-16 19:37:55 +02:00
animFadeOut.start();
2020-01-10 15:26:53 +01:00
}
function onQmlSceneValueReceived(key, value) {
var obj2 = 'import QtQuick; Item {Component.onCompleted: loader.item.' + key + ' = ' + value + '; }';
2021-05-16 19:37:55 +02:00
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) {
2021-05-16 19:37:55 +02:00
loader.sourceComponent = undefined;
loader.source = "";
Widget.clearComponentCache();
loader.source = Qt.resolvedUrl(Widget.projectSourceFileAbsolute);
2020-01-23 09:48:48 +01:00
}
2021-05-14 13:11:12 +02:00
2021-05-16 19:37:55 +02:00
target: Widget
2020-01-23 09:48:48 +01:00
}
2019-06-13 18:06:24 +02:00
OpacityAnimator {
id: animFadeOut
2021-05-16 19:37:55 +02:00
2019-06-13 18:06:24 +02:00
from: 1
to: 0
target: parent
duration: 800
easing.type: Easing.InOutQuad
onFinished: Widget.destroyThis()
2019-06-13 18:06:24 +02:00
}
Rectangle {
2018-11-24 14:28:02 +01:00
id: bgColor
2021-05-16 19:37:55 +02:00
anchors.fill: parent
color: "white"
2021-05-16 19:37:55 +02:00
opacity: 0.15
}
Image {
id: bg
2021-05-16 19:37:55 +02:00
source: "qrc:/assets/image/noisy-texture-3.png"
anchors.fill: parent
2021-05-16 19:37:55 +02:00
opacity: 0.05
fillMode: Image.Tile
}
Loader {
id: loader
2021-05-16 19:37:55 +02:00
anchors.fill: parent
asynchronous: true
Component.onCompleted: {
switch (Widget.type) {
case InstalledType.QMLWidget:
2021-05-16 19:37:55 +02:00
loader.source = Qt.resolvedUrl(Widget.projectSourceFileAbsolute);
break;
case InstalledType.HTMLWidget:
2021-05-16 19:37:55 +02:00
loader.sourceComponent = webViewComponent;
break;
}
}
onStatusChanged: {
if (loader.status == Loader.Ready) {
2021-05-16 19:37:55 +02:00
if (loader.item.widgetBackground !== undefined)
bgColor.color = loader.item.widgetBackground;
if (loader.item.widgetBackgroundOpacity !== undefined)
bgColor.opacity = loader.item.widgetBackgroundOpacity;
if (loader.item.widgetWidth !== undefined && loader.item.widgetHeight !== undefined)
Widget.setWidgetSize(loader.item.widgetWidth, loader.item.widgetHeight);
}
}
}
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: {
2021-05-16 19:37:55 +02:00
webView.url = Qt.resolvedUrl(Widget.sourcePath);
}
}
2021-05-16 19:37:55 +02:00
}
MouseArea {
id: mouseArea
2021-05-16 19:37:55 +02:00
property var clickPos
2021-05-16 19:37:55 +02:00
anchors.fill: parent
2019-06-13 18:06:24 +02:00
hoverEnabled: true
onPressed: {
clickPos = {
"x": mouse.x,
"y": mouse.y
2021-05-16 19:37:55 +02:00
};
}
onPositionChanged: {
2021-05-16 19:37:55 +02:00
if (mouseArea.pressed)
Widget.setPos(Widget.cursorPos().x - clickPos.x, Widget.cursorPos().y - clickPos.y);
2018-11-24 14:28:02 +01:00
}
2018-03-21 18:56:58 +01:00
}
2019-06-13 18:06:24 +02:00
MouseArea {
id: mouseAreaClose
2021-05-16 19:37:55 +02:00
2019-06-13 18:06:24 +02:00
width: 20
height: width
2021-05-16 19:37:55 +02:00
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onEntered: imgClose.opacity = 1
onExited: imgClose.opacity = 0.15
onClicked: {
if(Qt.platform.os === "windows")
Widget.setWindowBlur(0);
2021-05-16 19:37:55 +02:00
animFadeOut.start();
}
2019-06-13 18:06:24 +02:00
anchors {
top: parent.top
right: parent.right
}
Image {
id: imgClose
2021-05-16 19:37:55 +02:00
2019-06-13 18:06:24 +02:00
source: "qrc:/assets/icons/baseline-close-24px.svg"
anchors.centerIn: parent
2021-05-16 19:37:55 +02:00
opacity: 0.15
OpacityAnimator {
target: parent
duration: 300
}
2021-05-16 19:37:55 +02:00
2019-06-13 18:06:24 +02:00
}
2021-05-16 19:37:55 +02:00
2019-06-13 18:06:24 +02:00
}
2019-06-13 18:06:24 +02:00
MouseArea {
id: mouseAreaResize
2021-05-16 19:37:55 +02:00
property point clickPosition
2019-06-13 18:06:24 +02:00
width: 20
height: width
cursorShape: Qt.SizeFDiagCursor
onPressed: {
2021-05-16 19:37:55 +02:00
clickPosition = Qt.point(mouseX, mouseY);
2019-06-13 18:06:24 +02:00
}
onPositionChanged: {
2021-05-16 19:37:55 +02:00
if (mouseAreaResize.pressed)
Widget.setWidgetSize(clickPosition.x + mouseX, clickPosition.y + mouseY);
2019-06-13 18:06:24 +02:00
}
2021-05-16 19:37:55 +02:00
anchors {
bottom: parent.bottom
right: parent.right
}
2019-06-13 18:06:24 +02:00
}
2021-05-16 19:37:55 +02:00
2018-03-08 22:03:05 +01:00
}