2015-07-13 18:16:02 +00:00
|
|
|
import QtQuick 2.5
|
|
|
|
|
import QtQuick.Controls 1.4
|
|
|
|
|
import QtQuick.Dialogs 1.2
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: greySheet
|
|
|
|
|
state: "HIDDEN"
|
2015-07-13 21:22:06 +00:00
|
|
|
color: Qt.rgba(0, 0, 0, showOpacity)
|
2015-07-13 18:16:02 +00:00
|
|
|
|
|
|
|
|
property real showOpacity: .5
|
|
|
|
|
property int animationTime: 300
|
|
|
|
|
|
|
|
|
|
/// Emitted immediately when opening, before fade-in animation
|
|
|
|
|
signal opening
|
|
|
|
|
/// Emitted when opened, following fade-in animation
|
|
|
|
|
signal opened
|
|
|
|
|
/// Emitted immediately when closing, before fade-out animation
|
|
|
|
|
signal closing
|
|
|
|
|
/// Emitted when closed, following fade-out animation
|
|
|
|
|
signal closed
|
|
|
|
|
|
2015-07-13 21:22:06 +00:00
|
|
|
function showForm(formType, params, closedCallback) {
|
|
|
|
|
if (formType.status === Component.Error)
|
|
|
|
|
console.log(formType.errorString())
|
2015-07-14 19:06:00 +00:00
|
|
|
if (!params instanceof Object)
|
|
|
|
|
params = {app: app}
|
|
|
|
|
else
|
|
|
|
|
params.app = app
|
2015-07-13 21:22:06 +00:00
|
|
|
|
2015-07-14 19:06:00 +00:00
|
|
|
var form = formType.createObject(formContainer, params)
|
|
|
|
|
formContainer.data = [form]
|
2015-07-24 19:55:58 +00:00
|
|
|
form.canceled.connect(function(){state = "HIDDEN"; internal.callbackArgs = []})
|
|
|
|
|
form.completed.connect(function(){state = "HIDDEN"; internal.callbackArgs = arguments})
|
2015-07-13 18:16:02 +00:00
|
|
|
if (closedCallback instanceof Function)
|
|
|
|
|
internal.callback = closedCallback
|
2015-07-27 20:01:16 +00:00
|
|
|
// Notify the form that it's about to go live
|
|
|
|
|
form.display({})
|
2015-07-13 18:16:02 +00:00
|
|
|
state = "SHOWN"
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 19:33:52 +00:00
|
|
|
FocusScope {
|
|
|
|
|
id: scope
|
2015-07-13 18:16:02 +00:00
|
|
|
anchors.fill: parent
|
2015-07-14 19:33:52 +00:00
|
|
|
|
|
|
|
|
// Do not let focus leave this scope while form is open
|
|
|
|
|
onFocusChanged: if (enabled && !focus) forceActiveFocus()
|
|
|
|
|
|
|
|
|
|
Keys.onEscapePressed: greySheet.state = "HIDDEN"
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
id: mouseTrap
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
onClicked: {
|
|
|
|
|
mouse.accepted = true
|
|
|
|
|
greySheet.state = "HIDDEN"
|
|
|
|
|
}
|
|
|
|
|
acceptedButtons: Qt.AllButtons
|
|
|
|
|
}
|
|
|
|
|
MouseArea {
|
|
|
|
|
// This mouse area blocks clicks inside the form from reaching the mouseTrap
|
|
|
|
|
anchors.fill: formContainer
|
|
|
|
|
acceptedButtons: Qt.AllButtons
|
|
|
|
|
onClicked: mouse.accepted = true
|
|
|
|
|
}
|
|
|
|
|
Item {
|
|
|
|
|
id: formContainer
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
width: parent.width / 2
|
|
|
|
|
height: parent.height / 2
|
2015-07-13 18:16:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
states: [
|
|
|
|
|
State {
|
|
|
|
|
name: "HIDDEN"
|
|
|
|
|
PropertyChanges {
|
|
|
|
|
target: greySheet
|
2015-07-13 21:22:06 +00:00
|
|
|
opacity: 0
|
2015-07-13 18:16:02 +00:00
|
|
|
enabled: false
|
|
|
|
|
}
|
|
|
|
|
StateChangeScript {
|
|
|
|
|
name: "preHidden"
|
|
|
|
|
script: {
|
|
|
|
|
greySheet.closing()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
StateChangeScript {
|
|
|
|
|
name: "postHidden"
|
|
|
|
|
script: {
|
|
|
|
|
greySheet.closed()
|
2015-07-13 21:22:06 +00:00
|
|
|
formContainer.data = []
|
2015-07-13 18:16:02 +00:00
|
|
|
if (internal.callback instanceof Function)
|
2015-07-29 20:36:03 +00:00
|
|
|
internal.callback.apply(this, internal.callbackArgs)
|
2015-07-13 21:22:06 +00:00
|
|
|
internal.callback = undefined
|
2015-07-24 19:55:58 +00:00
|
|
|
internal.callbackArgs = []
|
2015-07-13 18:16:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
State {
|
|
|
|
|
name: "SHOWN"
|
|
|
|
|
PropertyChanges {
|
|
|
|
|
target: greySheet
|
2015-07-13 21:22:06 +00:00
|
|
|
opacity: 1
|
2015-07-13 18:16:02 +00:00
|
|
|
enabled: true
|
|
|
|
|
}
|
|
|
|
|
StateChangeScript {
|
|
|
|
|
name: "preShown"
|
|
|
|
|
script: {
|
|
|
|
|
greySheet.opening()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
StateChangeScript {
|
|
|
|
|
name: "postShown"
|
|
|
|
|
script: {
|
|
|
|
|
greySheet.opened()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
transitions: [
|
|
|
|
|
Transition {
|
|
|
|
|
from: "HIDDEN"
|
|
|
|
|
to: "SHOWN"
|
2015-07-13 21:22:06 +00:00
|
|
|
SequentialAnimation {
|
|
|
|
|
ScriptAction { scriptName: "preShown" }
|
|
|
|
|
PropertyAnimation {
|
|
|
|
|
target: greySheet
|
|
|
|
|
property: "opacity"
|
|
|
|
|
duration: animationTime
|
|
|
|
|
}
|
|
|
|
|
ScriptAction { scriptName: "postShown" }
|
2015-07-13 18:16:02 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Transition {
|
|
|
|
|
from: "SHOWN"
|
|
|
|
|
to: "HIDDEN"
|
2015-07-13 21:22:06 +00:00
|
|
|
SequentialAnimation {
|
|
|
|
|
ScriptAction { scriptName: "preHidden" }
|
|
|
|
|
PropertyAnimation {
|
|
|
|
|
target: greySheet
|
|
|
|
|
property: "opacity"
|
|
|
|
|
duration: animationTime
|
|
|
|
|
}
|
|
|
|
|
ScriptAction { scriptName: "postHidden" }
|
2015-07-13 18:16:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
|
id: internal
|
|
|
|
|
property var callback
|
2015-07-24 19:55:58 +00:00
|
|
|
property var callbackArgs
|
2015-07-13 18:16:02 +00:00
|
|
|
}
|
|
|
|
|
}
|