moment/src/gui/Base/HTile.qml

113 lines
2.9 KiB
QML
Raw Normal View History

2019-12-19 22:46:16 +11:00
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Layouts 1.12
HButton {
id: tile
2019-09-15 08:52:43 +10:00
signal leftClicked()
signal rightClicked()
2019-11-07 21:44:53 +11:00
default property alias additionalData: contentItem.data
property real contentOpacity: 1
readonly property alias title: title
readonly property alias additionalInfo: additionalInfo
readonly property alias rightInfo: rightInfo
readonly property alias subtitle: subtitle
2019-12-15 20:37:14 +11:00
property alias contextMenu: contextMenuLoader.sourceComponent
2019-11-07 21:44:53 +11:00
property Component image
2019-11-07 21:44:53 +11:00
contentItem: HRowLayout {
id: contentItem
spacing: tile.spacing
opacity: tile.contentOpacity
2019-11-07 21:44:53 +11:00
HLoader {
sourceComponent: image
}
2019-11-07 21:44:53 +11:00
HColumnLayout {
Layout.fillWidth: true
HRowLayout {
2019-11-07 21:44:53 +11:00
spacing: tile.spacing
2019-11-07 21:44:53 +11:00
HLabel {
id: title
text: "Missing title"
elide: Text.ElideRight
verticalAlignment: Qt.AlignVCenter
Layout.fillWidth: true
Layout.fillHeight: true
2019-11-07 21:44:53 +11:00
}
HRowLayout {
id: additionalInfo
visible: visibleChildren.length > 0
}
2019-11-07 21:44:53 +11:00
HLabel {
id: rightInfo
font.pixelSize: theme.fontSize.small
color: theme.colors.halfDimText
2019-11-07 21:44:53 +11:00
visible: Layout.maximumWidth > 0
Layout.fillHeight: true
2019-11-07 21:44:53 +11:00
Layout.maximumWidth:
2019-12-05 00:08:38 +11:00
text && tile.width >= 160 * theme.uiScale ?
implicitWidth : 0
2019-11-07 21:44:53 +11:00
Behavior on Layout.maximumWidth { HNumberAnimation {} }
}
}
2019-11-07 21:44:53 +11:00
HRichLabel {
id: subtitle
textFormat: Text.StyledText
font.pixelSize: theme.fontSize.small
elide: Text.ElideRight
color: theme.colors.dimText
2019-11-07 21:44:53 +11:00
visible: Layout.maximumHeight > 0
Layout.maximumHeight: text ? implicitWidth : 0
Layout.fillWidth: true
Layout.fillHeight: true
2019-11-07 21:44:53 +11:00
Behavior on Layout.maximumHeight { HNumberAnimation {} }
}
}
}
2019-09-15 08:52:43 +10:00
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: leftClicked()
}
TapHandler {
acceptedButtons: Qt.RightButton
2019-09-15 08:52:43 +10:00
onTapped: {
rightClicked()
2019-12-15 20:37:14 +11:00
if (contextMenu) contextMenuLoader.active = true
2019-09-15 08:52:43 +10:00
}
}
2019-12-15 20:37:14 +11:00
Connections {
enabled: contextMenuLoader.status === Loader.Ready
target: contextMenuLoader.item
onClosed: contextMenuLoader.active = false
}
HLoader {
id: contextMenuLoader
active: false
onLoaded: item.popup()
}
}