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

218 lines
5.6 KiB
QML
Raw 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")
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
onEntered: imgClose.state = "areaHover"
onExited: {
if (mouseAreaClose.containsMouse)
return
imgClose.state = ""
}
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
width: 16
2019-06-13 18:06:24 +02:00
height: width
2021-05-16 19:37:55 +02:00
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onEntered: imgClose.state = "iconHover"
onExited: imgClose.state = ""
2021-05-16 19:37:55 +02:00
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 {
margins: 5
2019-06-13 18:06:24 +02:00
top: parent.top
right: parent.right
}
ColorImage {
id: imgClose
source: "qrc:/qml/ScreenPlayWidget/assets/icons/baseline-close-24px.svg"
2019-06-13 18:06:24 +02:00
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
}
},
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]
duration: 250
property: "opacity"
}
}
]
2018-03-08 22:03:05 +01:00
}