2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-04-28 08:00:28 +10:00
|
|
|
|
2019-08-28 12:46:31 +10:00
|
|
|
Rectangle {
|
2019-12-12 03:42:59 +11:00
|
|
|
id: box
|
2019-08-18 03:01:43 +10:00
|
|
|
color: theme.controls.box.background
|
2020-03-16 06:01:09 +11:00
|
|
|
radius: theme.controls.box.radius
|
2019-12-08 01:59:43 +11:00
|
|
|
implicitWidth: theme.controls.box.defaultWidth
|
2019-08-18 03:01:43 +10:00
|
|
|
implicitHeight: childrenRect.height
|
|
|
|
|
2019-09-09 21:41:48 +10:00
|
|
|
Keys.onReturnPressed: if (clickButtonOnEnter) enterClickButton()
|
|
|
|
Keys.onEnterPressed: Keys.onReturnPressed(event)
|
|
|
|
|
|
|
|
|
|
|
|
property alias buttonModel: buttonRepeater.model
|
2019-04-28 08:00:28 +10:00
|
|
|
property var buttonCallbacks: []
|
2019-09-09 21:41:48 +10:00
|
|
|
property string focusButton: ""
|
|
|
|
property string clickButtonOnEnter: ""
|
2019-04-28 08:00:28 +10:00
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
property bool fillAvailableHeight: false
|
|
|
|
|
|
|
|
property HButton firstButton: null
|
|
|
|
|
2019-08-29 01:54:25 +10:00
|
|
|
default property alias body: interfaceBody.data
|
2019-04-28 08:00:28 +10:00
|
|
|
|
2019-09-09 21:41:48 +10:00
|
|
|
|
|
|
|
function enterClickButton() {
|
2019-07-18 19:18:13 +10:00
|
|
|
for (let i = 0; i < buttonModel.length; i++) {
|
2020-03-08 19:46:20 +11:00
|
|
|
const btn = buttonRepeater.itemAt(i)
|
2019-09-09 21:41:48 +10:00
|
|
|
if (btn.enabled && btn.name === clickButtonOnEnter) btn.clicked()
|
2019-04-28 08:00:28 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 03:01:43 +10:00
|
|
|
|
2019-12-16 19:42:41 +11:00
|
|
|
HNumberAnimation on scale {
|
2019-11-23 01:35:53 +11:00
|
|
|
running: true
|
|
|
|
from: 0
|
|
|
|
to: 1
|
|
|
|
overshoot: 3
|
|
|
|
}
|
|
|
|
|
2019-04-29 02:47:51 +10:00
|
|
|
HColumnLayout {
|
2019-04-28 08:00:28 +10:00
|
|
|
id: mainColumn
|
2019-08-18 03:01:43 +10:00
|
|
|
width: parent.width
|
2019-04-28 08:00:28 +10:00
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
Binding on height {
|
|
|
|
value: box.height
|
|
|
|
when: box.fillAvailableHeight
|
|
|
|
}
|
|
|
|
|
2019-08-18 03:01:43 +10:00
|
|
|
HColumnLayout {
|
|
|
|
id: interfaceBody
|
2019-12-08 20:29:37 +11:00
|
|
|
spacing: theme.spacing * 1.5
|
2019-04-28 11:07:20 +10:00
|
|
|
|
2019-12-08 01:59:43 +11:00
|
|
|
Layout.margins: spacing
|
2019-08-18 03:01:43 +10:00
|
|
|
}
|
2019-04-28 11:07:20 +10:00
|
|
|
|
2019-09-10 02:37:01 +10:00
|
|
|
HGridLayout {
|
|
|
|
id: buttonGrid
|
2019-08-28 12:25:13 +10:00
|
|
|
visible: buttonModel.length > 0
|
2019-12-20 06:56:07 +11:00
|
|
|
flow: width >= buttonRepeater.summedImplicitWidth ?
|
2019-09-10 02:37:01 +10:00
|
|
|
GridLayout.LeftToRight : GridLayout.TopToBottom
|
2019-08-28 12:25:13 +10:00
|
|
|
|
2019-09-10 02:37:01 +10:00
|
|
|
HRepeater {
|
2019-09-09 21:41:48 +10:00
|
|
|
id: buttonRepeater
|
2019-04-28 08:00:28 +10:00
|
|
|
model: []
|
|
|
|
|
2020-03-16 07:07:09 +11:00
|
|
|
onItemAdded: if (index === 0 && box)
|
|
|
|
box.firstButton = buttonRepeater.itemAt(0)
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-03-16 07:07:09 +11:00
|
|
|
onItemRemoved: if (index === 0 && box)
|
|
|
|
box.firstButton = null
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2019-08-21 07:41:24 +10:00
|
|
|
HButton {
|
2019-04-28 08:00:28 +10:00
|
|
|
id: button
|
|
|
|
text: modelData.text
|
2019-08-22 05:45:13 +10:00
|
|
|
icon.name: modelData.iconName || ""
|
2019-08-29 08:21:13 +10:00
|
|
|
icon.color: modelData.iconColor || (
|
2019-12-10 02:35:50 +11:00
|
|
|
name === "ok" || name === "apply" || name === "retry" ?
|
2019-08-29 08:21:13 +10:00
|
|
|
theme.colors.positiveBackground :
|
|
|
|
|
2019-12-10 02:35:50 +11:00
|
|
|
name === "cancel" ?
|
2019-08-29 08:21:13 +10:00
|
|
|
theme.colors.negativeBackground :
|
|
|
|
|
|
|
|
theme.icons.colorize
|
|
|
|
)
|
|
|
|
|
2019-11-12 00:12:31 +11:00
|
|
|
enabled:
|
|
|
|
modelData.enabled === undefined ?
|
|
|
|
true : modelData.enabled
|
|
|
|
|
2019-12-08 09:45:03 +11:00
|
|
|
loading: modelData.loading || false
|
|
|
|
|
2019-11-12 00:12:31 +11:00
|
|
|
disableWhileLoading:
|
|
|
|
modelData.disableWhileLoading === undefined ?
|
|
|
|
true : modelData.disableWhileLoading
|
2019-09-09 21:41:48 +10:00
|
|
|
|
2019-09-09 22:15:28 +10:00
|
|
|
onClicked: buttonCallbacks[name](button)
|
2019-04-28 08:00:28 +10:00
|
|
|
|
2019-09-09 21:41:48 +10:00
|
|
|
Keys.onLeftPressed: previous.forceActiveFocus()
|
|
|
|
Keys.onUpPressed: previous.forceActiveFocus()
|
|
|
|
Keys.onRightPressed: next.forceActiveFocus()
|
|
|
|
Keys.onDownPressed: next.forceActiveFocus()
|
|
|
|
|
|
|
|
Component.onCompleted:
|
2019-12-10 02:35:50 +11:00
|
|
|
if (name === focusButton) forceActiveFocus()
|
2019-09-09 21:41:48 +10:00
|
|
|
|
2019-04-28 08:00:28 +10:00
|
|
|
Layout.fillWidth: true
|
2019-08-18 03:01:43 +10:00
|
|
|
Layout.preferredHeight: theme.baseElementsHeight
|
2019-09-09 21:41:48 +10:00
|
|
|
|
|
|
|
|
|
|
|
property string name: modelData.name
|
|
|
|
|
|
|
|
property Item next: buttonRepeater.itemAt(
|
2019-12-18 08:59:53 +11:00
|
|
|
utils.numberWrapAt(index + 1, buttonRepeater.count),
|
2019-09-09 21:41:48 +10:00
|
|
|
)
|
|
|
|
property Item previous: buttonRepeater.itemAt(
|
2019-12-18 08:59:53 +11:00
|
|
|
utils.numberWrapAt(index - 1, buttonRepeater.count),
|
2019-09-09 21:41:48 +10:00
|
|
|
)
|
2019-04-28 08:00:28 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|