1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 19:42:45 +01:00
ScreenPlay/qml/FileDropperSingleFile.qml

229 lines
5.9 KiB
QML
Raw Normal View History

import QtQuick 2.9
import QtQuick.Dialogs 1.2
2017-10-05 10:32:17 +02:00
Rectangle {
id: fileDropperSingleFile
2017-10-05 10:32:17 +02:00
property color background: "white"
property string descriptionTitle: "value"
property url imagePath: "qrc:/assets/icons/icon_plus.svg"
//FIXME in 5.10 with an enum
property bool isVideo: false
property url externalFilePath
2017-10-16 19:08:18 +02:00
property string helpText: "help"
2017-10-05 10:32:17 +02:00
color: fileDropperSingleFile.background
border.color: "#C2C2C2"
border.width: 2
radius: 4
state: ""
function reset(){
fileDropperSingleFile.state = "empty"
previewImage.source = ""
videoPreviewLoader.source = ""
}
onStateChanged: {
2017-10-16 19:08:18 +02:00
if (fileDropperSingleFile.state === "error") {
stateChangedTimer.start()
}
}
Timer {
2017-10-16 19:08:18 +02:00
id: stateChangedTimer
onTriggered: {
fileDropperSingleFile.state = "empty"
}
}
Image {
id: previewImage
anchors.fill: parent
2017-10-14 19:32:28 +02:00
anchors.margins: 2
z: 98
2017-10-16 19:08:18 +02:00
fillMode: Image.PreserveAspectCrop
visible: false
}
2017-10-05 10:32:17 +02:00
FontLoader {
id: font_LibreBaskerville
source: "qrc:/assets/fonts/LibreBaskerville-Italic.ttf"
}
Item {
id: column
height: imageIcon.height + txtSplashInput.contentHeight
2017-10-05 10:32:17 +02:00
anchors {
right: parent.right
left: parent.left
2017-10-05 10:32:17 +02:00
verticalCenter: parent.verticalCenter
}
Image {
id: imageIcon
width: 32
height: 32
sourceSize.height: 32
sourceSize.width: 32
source: fileDropperSingleFile.imagePath
anchors {
top: parent.top
2017-10-05 10:32:17 +02:00
horizontalCenter: parent.horizontalCenter
}
}
Text {
id: txtSplashInput
text: descriptionTitle
anchors {
top: imageIcon.bottom
2017-10-05 10:32:17 +02:00
topMargin: 10
horizontalCenter: parent.horizontalCenter
}
height: 40
2017-10-05 10:32:17 +02:00
font.pointSize: 12
color: "#626262"
horizontalAlignment: Text.AlignHCenter
font.family: font_LibreBaskerville.name
font.italic: true
renderType: Text.NativeRendering
}
}
2017-10-16 19:08:18 +02:00
Text {
id: helpTextWrapper
color: "#626262"
anchors.fill: parent
anchors.margins: 20
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.family: font_LibreBaskerville.name
font.italic: true
wrapMode: Text.WordWrap
font.pointSize: 12
opacity: 0
renderType: Text.NativeRendering
text: helpText
}
2017-10-05 10:32:17 +02:00
DropArea {
id: dropper
2017-10-05 10:32:17 +02:00
anchors.fill: parent
2017-10-16 19:08:18 +02:00
focus: true
2017-10-05 10:32:17 +02:00
onEntered: {
fileDropperSingleFile.state = "fileEntered"
}
2017-10-05 10:32:17 +02:00
onDropped: {
fileDropperSingleFile.state = "fileDropped"
if (drop.hasUrls) {
if (isVideo) {
if (validateVideoFileExtension(drop.urls[0])) {
externalFilePath = drop.urls[0]
2017-10-16 19:08:18 +02:00
videoPreviewLoader.setSource(
"CreateVideoPreviewSmall.qml", {
source: externalFilePath
})
}
} else {
if (validateImageFileExtension(drop.urls[0])) {
externalFilePath = drop.urls[0]
previewImage.source = drop.urls[0]
previewImage.visible = true
}
}
}
2017-10-05 10:32:17 +02:00
}
2017-10-16 19:08:18 +02:00
2017-10-05 10:32:17 +02:00
onExited: {
fileDropperSingleFile.state = "empty"
}
function validateImageFileExtension(filePath) {
var tmp = filePath.split('.').pop()
return tmp === "png" || tmp === "jpg"
}
function validateVideoFileExtension(filePath) {
var tmp = filePath.split('.').pop()
return tmp === "vp9" || tmp === "mp4"
}
2017-10-16 19:08:18 +02:00
MouseArea {
anchors.fill: parent
focus: true
z: 99
hoverEnabled: true
onHoveredChanged: {
if (containsMouse && videoPreviewLoader.source.toString() === "") {
fileDropperSingleFile.state = "hover"
} else {
fileDropperSingleFile.state = ""
}
}
}
}
Loader {
2017-10-16 19:08:18 +02:00
id: videoPreviewLoader
asynchronous: true
anchors.fill: parent
2017-10-14 19:32:28 +02:00
anchors.margins: 2
z: 300
2017-10-05 10:32:17 +02:00
}
states: [
State {
name: "fileEntered"
PropertyChanges {
target: fileDropperSingleFile
color: "#d9d9d9"
}
},
State {
name: "fileDropped"
PropertyChanges {
target: fileDropperSingleFile
color: "#ffbf49"
}
},
State {
name: "empty"
PropertyChanges {
target: fileDropperSingleFile
color: "white"
}
},
State {
name: "error"
PropertyChanges {
target: fileDropperSingleFile
color: "#ff4d4d"
}
2017-10-16 19:08:18 +02:00
},
State {
name: "hover"
PropertyChanges {
target: column
opacity: 0
}
PropertyChanges {
target: helpTextWrapper
opacity: 1
}
2017-10-05 10:32:17 +02:00
}
]
transitions: [
Transition {
from: "*"
to: "*"
ColorAnimation {
duration: 200
}
2017-10-16 19:08:18 +02:00
NumberAnimation {
property: "opacity"
duration: 200
}
2017-10-05 10:32:17 +02:00
}
]
}