moment/src/qml/Base/HBox.qml

112 lines
3.4 KiB
QML
Raw Normal View History

import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../utils.js" as Utils
2019-08-27 22:46:31 -04:00
Rectangle {
id: interfaceBox
color: theme.controls.box.background
implicitWidth: theme.controls.box.defaultWidth
implicitHeight: childrenRect.height
Keys.onReturnPressed: if (clickButtonOnEnter) enterClickButton()
Keys.onEnterPressed: Keys.onReturnPressed(event)
property alias buttonModel: buttonRepeater.model
property var buttonCallbacks: []
property string focusButton: ""
property string clickButtonOnEnter: ""
2019-08-28 11:54:25 -04:00
default property alias body: interfaceBody.data
function enterClickButton() {
2019-07-18 05:18:13 -04:00
for (let i = 0; i < buttonModel.length; i++) {
let btn = buttonRepeater.itemAt(i)
if (btn.enabled && btn.name === clickButtonOnEnter) btn.clicked()
}
}
HScaleAnimator on scale {
2019-11-22 10:35:53 -04:00
running: true
from: 0
to: 1
overshoot: 3
}
2019-04-28 12:47:51 -04:00
HColumnLayout {
id: mainColumn
width: parent.width
HColumnLayout {
id: interfaceBody
2019-12-08 05:29:37 -04:00
spacing: theme.spacing * 1.5
2019-04-27 21:07:20 -04:00
Layout.margins: spacing
}
2019-04-27 21:07:20 -04:00
HGridLayout {
id: buttonGrid
2019-08-27 22:25:13 -04:00
visible: buttonModel.length > 0
flow: width >= buttonRepeater.childrenImplicitWidth ?
GridLayout.LeftToRight : GridLayout.TopToBottom
2019-08-27 22:25:13 -04:00
HRepeater {
id: buttonRepeater
model: []
2019-08-20 17:41:24 -04:00
HButton {
id: button
text: modelData.text
icon.name: modelData.iconName || ""
2019-08-28 18:21:13 -04:00
icon.color: modelData.iconColor || (
name == "ok" || name == "apply" || name == "retry" ?
theme.colors.positiveBackground :
name == "cancel" ?
theme.colors.negativeBackground :
theme.icons.colorize
)
enabled:
modelData.enabled === undefined ?
true : modelData.enabled
loading: modelData.loading || false
disableWhileLoading:
modelData.disableWhileLoading === undefined ?
true : modelData.disableWhileLoading
onClicked: buttonCallbacks[name](button)
Keys.onLeftPressed: previous.forceActiveFocus()
Keys.onUpPressed: previous.forceActiveFocus()
Keys.onRightPressed: next.forceActiveFocus()
Keys.onDownPressed: next.forceActiveFocus()
Keys.onReturnPressed: if (button.enabled) button.clicked()
Keys.onEnterPressed: Keys.onReturnPressed(event)
Component.onCompleted:
if (name == focusButton) forceActiveFocus()
Layout.fillWidth: true
Layout.preferredHeight: theme.baseElementsHeight
property string name: modelData.name
property Item next: buttonRepeater.itemAt(
Utils.numberWrapAt(index + 1, buttonRepeater.count),
)
property Item previous: buttonRepeater.itemAt(
Utils.numberWrapAt(index - 1, buttonRepeater.count),
)
}
}
}
}
}