matrixion/qml/components/AvatarListTile.qml

122 lines
3.9 KiB
QML
Raw Permalink Normal View History

2021-08-06 02:45:47 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-08-06 02:45:47 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
2022-04-16 03:13:01 +03:00
import "../"
2021-08-06 02:45:47 +03:00
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import im.nheko
2021-08-06 02:45:47 +03:00
Rectangle {
id: tile
2022-04-16 03:13:01 +03:00
property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 2.3)
required property string avatarUrl
2022-04-11 05:18:16 +03:00
property color background: timelineRoot.palette.window
property color bubbleBackground: timelineRoot.palette.highlight
property color bubbleText: timelineRoot.palette.highlightedText
2021-08-06 02:45:47 +03:00
property bool crop: true
2022-04-16 03:13:01 +03:00
property color importantText: timelineRoot.palette.text
required property int index
property alias roomid: avatar.roomid
2022-04-16 03:13:01 +03:00
required property int selectedIndex
required property string subtitle
required property string title
property color unimportantText: timelineRoot.palette.placeholderText
property alias userid: avatar.userid
2021-08-06 02:45:47 +03:00
color: background
height: avatarSize + 2 * Nheko.paddingMedium
state: "normal"
2022-04-16 03:13:01 +03:00
width: ListView.view.width
2021-08-06 02:45:47 +03:00
states: [
State {
name: "highlight"
when: hovered.hovered && !(index == selectedIndex)
PropertyChanges {
2022-04-11 05:18:16 +03:00
background: timelineRoot.palette.dark
bubbleBackground: timelineRoot.palette.highlight
bubbleText: timelineRoot.palette.highlightedText
2022-04-16 03:13:01 +03:00
importantText: timelineRoot.palette.brightText
target: tile
unimportantText: timelineRoot.palette.brightText
2021-08-06 02:45:47 +03:00
}
},
State {
name: "selected"
when: index == selectedIndex
PropertyChanges {
2022-04-11 05:18:16 +03:00
background: timelineRoot.palette.highlight
bubbleBackground: timelineRoot.palette.highlightedText
bubbleText: timelineRoot.palette.highlight
2022-04-16 03:13:01 +03:00
importantText: timelineRoot.palette.highlightedText
target: tile
unimportantText: timelineRoot.palette.highlightedText
2021-08-06 02:45:47 +03:00
}
}
]
HoverHandler {
id: hovered
}
RowLayout {
anchors.fill: parent
anchors.margins: Nheko.paddingMedium
2022-04-16 03:13:01 +03:00
spacing: Nheko.paddingMedium
2021-08-06 02:45:47 +03:00
Avatar {
id: avatar
Layout.alignment: Qt.AlignVCenter
2022-04-16 03:13:01 +03:00
crop: tile.crop
displayName: title
enabled: false
2021-08-06 02:45:47 +03:00
height: avatarSize
url: tile.avatarUrl.replace("mxc://", "image://MxcImage/")
2022-04-16 03:13:01 +03:00
width: avatarSize
2021-08-06 02:45:47 +03:00
}
ColumnLayout {
id: textContent
Layout.alignment: Qt.AlignLeft
Layout.fillWidth: true
Layout.minimumWidth: 100
Layout.preferredWidth: parent.width - avatar.width
spacing: Nheko.paddingSmall
2022-04-16 03:13:01 +03:00
width: parent.width - avatar.width
2021-08-06 02:45:47 +03:00
RowLayout {
Layout.fillWidth: true
spacing: 0
ElidedLabel {
Layout.alignment: Qt.AlignBottom
color: tile.importantText
elideWidth: textContent.width - Nheko.paddingMedium
fullText: title
textFormat: Text.PlainText
}
Item {
Layout.fillWidth: true
}
}
RowLayout {
Layout.fillWidth: true
spacing: 0
ElidedLabel {
color: tile.unimportantText
elideWidth: textContent.width - Nheko.paddingSmall
2022-04-16 03:13:01 +03:00
font.pixelSize: fontMetrics.font.pixelSize * 0.9
2021-08-06 02:45:47 +03:00
fullText: subtitle
textFormat: Text.PlainText
}
Item {
Layout.fillWidth: true
}
}
}
}
}