FluentUI/example/qml/window/HotloadWindow.qml

98 lines
2.7 KiB
QML
Raw Normal View History

2023-08-24 15:50:37 +08:00
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import FluentUI 1.0
import example 1.0
2023-08-26 17:20:30 +08:00
import "../component"
2023-07-11 16:43:28 +08:00
2023-10-08 19:48:32 +08:00
FluWindow {
2023-07-11 16:43:28 +08:00
id:window
2024-03-09 15:35:48 +08:00
title: qsTr("Hot Loader")
2023-07-11 16:43:28 +08:00
width: 800
height: 600
minimumWidth: 520
minimumHeight: 200
2023-07-18 18:24:06 +08:00
launchMode: FluWindowType.SingleTask
2023-07-11 16:43:28 +08:00
FileWatcher{
id:watcher
onFileChanged: {
loader.reload()
}
}
FluArea{
anchors.fill: parent
FluRemoteLoader{
id:loader
anchors.fill: parent
2024-02-23 12:26:10 +08:00
statusMode: FluStatusLayoutType.Success
2023-07-11 16:43:28 +08:00
lazy: true
errorItem: Item{
FluText{
text:loader.itemLodaer().sourceComponent.errorString()
color:"red"
anchors.fill: parent
2024-03-09 22:19:10 +08:00
wrapMode: Text.WrapAnywhere
2023-07-11 16:43:28 +08:00
padding: 20
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignHCenter
}
}
}
FluText{
2024-03-09 15:35:48 +08:00
text: qsTr("Drag in a qml file")
2023-07-11 16:43:28 +08:00
font.pixelSize: 26
anchors.centerIn: parent
2024-02-23 12:26:10 +08:00
visible: !loader.itemLodaer().item && loader.statusMode === FluStatusLayoutType.Success
2023-07-11 16:43:28 +08:00
}
Rectangle{
radius: 4
anchors.fill: parent
color: "#33333333"
visible: drop_area.containsDrag
}
DropArea{
id:drop_area
anchors.fill: parent
onEntered:
(event)=>{
if(!event.hasUrls){
event.accepted = false
return
}
2023-10-22 12:33:19 +08:00
var url = getUrlByEvent(event)
if(url === ""){
2023-07-11 16:43:28 +08:00
event.accepted = false
return
}
var fileExtension = url.substring(url.lastIndexOf(".") + 1)
if (fileExtension !== "qml") {
event.accepted = false
return
}
return true
}
onDropped:
(event)=>{
2023-10-22 12:33:19 +08:00
var url = getUrlByEvent(event)
if(url !== ""){
loader.source = url
watcher.path = url
loader.reload()
}
2023-07-11 16:43:28 +08:00
}
}
}
2023-10-22 12:33:19 +08:00
function getUrlByEvent(event){
var url = ""
if (event.urls.length === 0) {
url = "file:///"+event.getDataAsString("text/plain")
}else{
url = event.urls[0].toString()
}
return url
}
2023-07-11 16:43:28 +08:00
}