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

208 lines
5.2 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import QtWebEngine
import ScreenPlayWidget
import ScreenPlay.Enums.InstalledType
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")
Widget.setWindowBlur(0)
loader.source = ""
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 + '; }'
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) {
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
}
Loader {
id: loader
opacity: 0
anchors.fill: parent
asynchronous: true
Component.onCompleted: {
switch (Widget.type) {
case InstalledType.QMLWidget:
loader.source = Qt.resolvedUrl(Widget.projectSourceFileAbsolute)
break
case InstalledType.HTMLWidget:
loader.sourceComponent = webViewComponent
break
}
}
onStatusChanged: {
if (loader.status == Loader.Ready && loader.source !== "") {
// Resize to loaded widget size
// Note: We must use implicit* here to not
// break the set values.
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: {
webView.url = Qt.resolvedUrl(Widget.sourcePath)
}
}
}
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: function (mouse) {
clickPos = {
"x": mouse.x,
"y": mouse.y
}
}
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)
animFadeOut.start()
2021-05-16 19:37:55 +02:00
}
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
source: "qrc:/qml/ScreenPlayWidget/assets/icons/baseline-close-24px.svg"
2019-06-13 18:06:24 +02:00
anchors.centerIn: parent
2021-05-16 19:37:55 +02:00
opacity: 0.15
OpacityAnimator {
target: parent
duration: 300
}
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: {
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
}
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]
duration: 250
property: "opacity"
}
}
]
2018-03-08 22:03:05 +01:00
}