LedDisplay/OmobiDisplayApp/ressources/qml/DisplayTextModelListView.qml

292 lines
7.3 KiB
QML
Raw Normal View History

2020-10-12 14:13:52 +02:00
import QtQuick 2.4
2020-10-11 21:01:21 +02:00
import QtQuick.Controls 2.9
2020-10-12 14:13:52 +02:00
import QtQuick.Layouts 1.9
2020-10-11 21:01:21 +02:00
import de.itsblue.omobidisplayapp 1.0
import QtQuick.Controls.Material 2.0
ListView {
id: control
model: backend.displayTextModel
delegate: DisplayTextDelegate {
id: delegate
width: control.width
onClicked: {
popup.edit(model)
}
}
RoundButton {
anchors {
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
bottomMargin: height * 0.25
}
height: parent.width * 0.15
width: height
text: ""
onClicked: popup.add()
Text {
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pixelSize: height * 0.4
text: "+"
}
}
Dialog {
id: popup
property bool editing
property var editingModel
parent: Overlay.overlay
x: (parent.width - width) / 2
2020-10-12 14:13:52 +02:00
width: parent.width
height: parent.height * 0.7
2020-10-11 21:01:21 +02:00
modal: true
2020-10-12 14:13:52 +02:00
title: editing ? "Edit item" : "New item"
2020-10-11 21:01:21 +02:00
onAccepted: {
if(editing) {
editingModel.active = activeSwitch.checked
editingModel.text = textTextField.text
editingModel.runtime = runtimeSpinBox.value
editingModel.color = colorComboBox.currentText
editingModel.alignment = alignmentComboBox.currentText
editingModel.scroll = scrollSwitch.checked
2020-10-12 14:13:52 +02:00
editingModel.scrollSpeed = scrollSpeedSpinBox.value
2020-10-11 21:01:21 +02:00
editingModel.scrollCount = scrollCountSpinBox.value
2020-10-12 14:13:52 +02:00
editingModel.brightness = brightnessSpinBox.value
2020-10-11 21:01:21 +02:00
}
else {
control.model.append(textTextField.text,
activeSwitch.checked,
runtimeSpinBox.value,
colorComboBox.currentText,
alignmentComboBox.currentText,
scrollSwitch.checked,
2020-10-12 14:13:52 +02:00
scrollSpeedSpinBox.value,
scrollCountSpinBox.value,
brightnessSpinBox.value
2020-10-11 21:01:21 +02:00
)
}
}
2020-10-12 14:13:52 +02:00
onDiscarded: {
control.model.remove(0)
popup.close()
}
2020-10-11 21:01:21 +02:00
contentItem: GridLayout {
property int rowHeight: 50
columns: 2
columnSpacing: 10
Label {
font.bold: true
text: "Active:"
}
Switch {
id: activeSwitch
Layout.fillWidth: true
}
Label {
font.bold: true
text: "Text:"
}
TextField {
id: textTextField
Layout.fillWidth: true
}
Label {
font.bold: true
text: "Runtime (in s):"
}
SpinBox {
id: runtimeSpinBox
Layout.fillWidth: true
}
Label {
font.bold: true
text: "Color:"
}
ComboBox {
id: colorComboBox
Layout.fillWidth: true
model: ["white", "blue", "red", "green"]
}
Label {
font.bold: true
text: "Alignment:"
}
ComboBox {
id: alignmentComboBox
Layout.fillWidth: true
model: ["left", "center", "right"]
}
Label {
font.bold: true
text: "Scroll:"
}
Switch {
id: scrollSwitch
Layout.fillWidth: true
}
2020-10-12 14:13:52 +02:00
Label {
font.bold: true
text: "Scroll speed:"
}
SpinBox {
id: scrollSpeedSpinBox
Layout.fillWidth: true
from: 0
to: 10
}
2020-10-11 21:01:21 +02:00
Label {
font.bold: true
text: "Scroll count:"
}
SpinBox {
id: scrollCountSpinBox
Layout.fillWidth: true
}
2020-10-12 14:13:52 +02:00
Label {
font.bold: true
text: "Brightness:"
}
SpinBox {
id: brightnessSpinBox
Layout.fillWidth: true
from: 0
to: 10
}
}
footer: DialogButtonBox {
// alignment: Qt.AlignHCenter
buttonLayout: DialogButtonBox.GnomeLayout
Button {
flat: true
text: "save"
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
}
2020-10-11 21:01:21 +02:00
Button {
2020-10-12 14:13:52 +02:00
flat: true
text: "cancel"
DialogButtonBox.buttonRole: DialogButtonBox.RejectRole
}
Button {
visible: popup.editing
2020-10-11 21:01:21 +02:00
Material.background: Material.Red
Material.foreground: "white"
2020-10-12 14:13:52 +02:00
flat: false
2020-10-11 21:01:21 +02:00
text: "delete"
2020-10-12 14:13:52 +02:00
DialogButtonBox.buttonRole: DialogButtonBox.DestructiveRole
}
}
enter: Transition {
ParallelAnimation {
NumberAnimation { property: "opacity"; from: 0; to: 1 }
NumberAnimation { property: "y"; from: popup.parent.height - popup.height * 0.75; to: popup.parent.height - popup.height }
}
}
exit: Transition {
ParallelAnimation {
NumberAnimation { property: "opacity"; from: 1; to: 0 }
NumberAnimation { property: "y"; from: popup.parent.height - popup.height; to: popup.parent.height - popup.height * 0.75 }
2020-10-11 21:01:21 +02:00
}
}
function edit(model) {
editingModel = model
editing = true
reset()
activeSwitch.checked = editingModel.active
textTextField.text = editingModel.text
runtimeSpinBox.value = editingModel.runtime
colorComboBox.currentIndex = colorComboBox.model.indexOf(editingModel.color)
alignmentComboBox.currentIndex = alignmentComboBox.model.indexOf(editingModel.alignment)
scrollSwitch.checked = editingModel.scroll
2020-10-12 14:13:52 +02:00
scrollSpeedSpinBox = editingModel.scrollSpeed
2020-10-11 21:01:21 +02:00
scrollCountSpinBox.value = editingModel.scrollCount
2020-10-12 14:13:52 +02:00
brightnessSpinBox = editingModel.brightness
2020-10-11 21:01:21 +02:00
open()
}
function add() {
editing = false
reset()
open()
}
function reset() {
activeSwitch.checked = false
textTextField.text = ""
runtimeSpinBox.value = 0
colorComboBox.currentIndex = 0
alignmentComboBox.currentIndex = 0
scrollSwitch.checked = false
2020-10-12 14:13:52 +02:00
scrollSpeedSpinBox.value = 5
2020-10-11 21:01:21 +02:00
scrollCountSpinBox.value = 0
2020-10-12 14:13:52 +02:00
brightnessSpinBox.value = 10
2020-10-11 21:01:21 +02:00
}
}
}