2017-10-14 10:42:07 +02:00
|
|
|
import QtQuick 2.9
|
2017-10-05 11:17:23 +02:00
|
|
|
import QtQuick.Dialogs 1.2
|
2017-10-05 10:32:17 +02:00
|
|
|
|
|
|
|
Rectangle {
|
2017-11-21 10:11:40 +01:00
|
|
|
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"
|
2017-10-05 11:17:23 +02:00
|
|
|
//FIXME in 5.10 with an enum
|
|
|
|
property bool isVideo: false
|
2017-10-14 10:42:07 +02:00
|
|
|
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: ""
|
|
|
|
|
2017-11-21 10:11:40 +01:00
|
|
|
function reset(){
|
|
|
|
fileDropperSingleFile.state = "empty"
|
|
|
|
previewImage.source = ""
|
|
|
|
videoPreviewLoader.source = ""
|
|
|
|
}
|
|
|
|
|
2017-10-14 19:30:06 +02:00
|
|
|
onStateChanged: {
|
2017-10-16 19:08:18 +02:00
|
|
|
if (fileDropperSingleFile.state === "error") {
|
2017-10-14 19:30:06 +02:00
|
|
|
stateChangedTimer.start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Timer {
|
2017-10-16 19:08:18 +02:00
|
|
|
id: stateChangedTimer
|
2017-10-14 19:30:06 +02:00
|
|
|
onTriggered: {
|
|
|
|
fileDropperSingleFile.state = "empty"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-14 10:42:07 +02:00
|
|
|
Image {
|
|
|
|
id: previewImage
|
|
|
|
anchors.fill: parent
|
2017-10-14 19:32:28 +02:00
|
|
|
anchors.margins: 2
|
2017-10-14 10:42:07 +02:00
|
|
|
z: 98
|
2017-10-16 19:08:18 +02:00
|
|
|
fillMode: Image.PreserveAspectCrop
|
2017-10-14 10:42:07 +02:00
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
|
2017-10-05 10:32:17 +02:00
|
|
|
FontLoader {
|
|
|
|
id: font_LibreBaskerville
|
|
|
|
source: "qrc:/assets/fonts/LibreBaskerville-Italic.ttf"
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: column
|
2017-10-14 10:42:07 +02:00
|
|
|
height: imageIcon.height + txtSplashInput.contentHeight
|
2017-10-05 10:32:17 +02:00
|
|
|
anchors {
|
2017-10-14 10:42:07 +02:00
|
|
|
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 {
|
2017-10-14 10:42:07 +02:00
|
|
|
top: parent.top
|
2017-10-05 10:32:17 +02:00
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Text {
|
|
|
|
id: txtSplashInput
|
|
|
|
text: descriptionTitle
|
|
|
|
anchors {
|
2017-10-14 10:42:07 +02:00
|
|
|
top: imageIcon.bottom
|
2017-10-05 10:32:17 +02:00
|
|
|
topMargin: 10
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
2017-10-14 10:42:07 +02:00
|
|
|
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 {
|
2017-10-14 10:42:07 +02:00
|
|
|
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-14 10:42:07 +02:00
|
|
|
|
2017-10-05 10:32:17 +02:00
|
|
|
onDropped: {
|
|
|
|
fileDropperSingleFile.state = "fileDropped"
|
2017-10-14 10:42:07 +02:00
|
|
|
if (drop.hasUrls) {
|
|
|
|
if (isVideo) {
|
|
|
|
if (validateVideoFileExtension(drop.urls[0])) {
|
2017-10-14 19:30:06 +02:00
|
|
|
externalFilePath = drop.urls[0]
|
2017-10-16 19:08:18 +02:00
|
|
|
videoPreviewLoader.setSource(
|
|
|
|
"CreateVideoPreviewSmall.qml", {
|
|
|
|
source: externalFilePath
|
|
|
|
})
|
2017-10-14 10:42:07 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (validateImageFileExtension(drop.urls[0])) {
|
2017-10-14 19:30:06 +02:00
|
|
|
externalFilePath = drop.urls[0]
|
2017-10-14 10:42:07 +02:00
|
|
|
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"
|
|
|
|
}
|
2017-10-05 11:17:23 +02:00
|
|
|
|
2017-10-14 10:42:07 +02:00
|
|
|
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 = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-14 10:42:07 +02:00
|
|
|
}
|
|
|
|
Loader {
|
2017-10-16 19:08:18 +02:00
|
|
|
id: videoPreviewLoader
|
2017-10-14 10:42:07 +02:00
|
|
|
asynchronous: true
|
|
|
|
anchors.fill: parent
|
2017-10-14 19:32:28 +02:00
|
|
|
anchors.margins: 2
|
2017-11-21 10:11:40 +01:00
|
|
|
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"
|
|
|
|
}
|
2017-10-14 19:30:06 +02:00
|
|
|
},
|
|
|
|
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
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|