mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Use required properties and delegate pooling for room list
This commit is contained in:
parent
d61a9c718a
commit
f7ffcb4846
2 changed files with 38 additions and 26 deletions
|
@ -165,7 +165,7 @@ endif()
|
||||||
#
|
#
|
||||||
# Discover Qt dependencies.
|
# Discover Qt dependencies.
|
||||||
#
|
#
|
||||||
find_package(Qt5 5.12 COMPONENTS Core Widgets LinguistTools Concurrent Svg Multimedia Qml QuickControls2 QuickWidgets REQUIRED)
|
find_package(Qt5 5.15 COMPONENTS Core Widgets LinguistTools Concurrent Svg Multimedia Qml QuickControls2 QuickWidgets REQUIRED)
|
||||||
find_package(Qt5QuickCompiler)
|
find_package(Qt5QuickCompiler)
|
||||||
find_package(Qt5DBus)
|
find_package(Qt5DBus)
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
import "./dialogs"
|
import "./dialogs"
|
||||||
import Qt.labs.platform 1.1 as Platform
|
import Qt.labs.platform 1.1 as Platform
|
||||||
import QtQml 2.12
|
import QtQml 2.12
|
||||||
import QtQuick 2.12
|
import QtQuick 2.15
|
||||||
import QtQuick.Controls 2.5
|
import QtQuick.Controls 2.15
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
import im.nheko 1.0
|
import im.nheko 1.0
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ Page {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
height: parent.height
|
height: parent.height
|
||||||
model: Rooms
|
model: Rooms
|
||||||
|
reuseItems: true
|
||||||
|
|
||||||
ScrollHelper {
|
ScrollHelper {
|
||||||
flickable: parent
|
flickable: parent
|
||||||
|
@ -111,17 +112,28 @@ Page {
|
||||||
property color unimportantText: Nheko.colors.buttonText
|
property color unimportantText: Nheko.colors.buttonText
|
||||||
property color bubbleBackground: Nheko.colors.highlight
|
property color bubbleBackground: Nheko.colors.highlight
|
||||||
property color bubbleText: Nheko.colors.highlightedText
|
property color bubbleText: Nheko.colors.highlightedText
|
||||||
|
required property string roomName
|
||||||
|
required property string roomId
|
||||||
|
required property string avatarUrl
|
||||||
|
required property string time
|
||||||
|
required property string lastMessage
|
||||||
|
required property var tags
|
||||||
|
required property bool isInvite
|
||||||
|
required property bool isSpace
|
||||||
|
required property int notificationCount
|
||||||
|
required property bool hasLoudNotification
|
||||||
|
required property bool hasUnreadMessages
|
||||||
|
|
||||||
color: background
|
color: background
|
||||||
height: avatarSize + 2 * Nheko.paddingMedium
|
height: avatarSize + 2 * Nheko.paddingMedium
|
||||||
width: ListView.view.width
|
width: ListView.view.width
|
||||||
state: "normal"
|
state: "normal"
|
||||||
ToolTip.visible: hovered.hovered && collapsed
|
ToolTip.visible: hovered.hovered && collapsed
|
||||||
ToolTip.text: model.roomName
|
ToolTip.text: roomName
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "highlight"
|
name: "highlight"
|
||||||
when: hovered.hovered && !((Rooms.currentRoom && model.roomId == Rooms.currentRoom.roomId()) || Rooms.currentRoomPreview.roomid == model.roomId)
|
when: hovered.hovered && !((Rooms.currentRoom && roomId == Rooms.currentRoom.roomId()) || Rooms.currentRoomPreview.roomid == roomId)
|
||||||
|
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: roomItem
|
target: roomItem
|
||||||
|
@ -135,7 +147,7 @@ Page {
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "selected"
|
name: "selected"
|
||||||
when: (Rooms.currentRoom && model.roomId == Rooms.currentRoom.roomId()) || Rooms.currentRoomPreview.roomid == model.roomId
|
when: (Rooms.currentRoom && roomId == Rooms.currentRoom.roomId()) || Rooms.currentRoomPreview.roomid == roomId
|
||||||
|
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: roomItem
|
target: roomItem
|
||||||
|
@ -154,7 +166,7 @@ Page {
|
||||||
acceptedButtons: Qt.RightButton
|
acceptedButtons: Qt.RightButton
|
||||||
onSingleTapped: {
|
onSingleTapped: {
|
||||||
if (!TimelineManager.isInvite)
|
if (!TimelineManager.isInvite)
|
||||||
roomContextMenu.show(model.roomId, model.tags);
|
roomContextMenu.show(roomId, tags);
|
||||||
|
|
||||||
}
|
}
|
||||||
gesturePolicy: TapHandler.ReleaseWithinBounds
|
gesturePolicy: TapHandler.ReleaseWithinBounds
|
||||||
|
@ -162,10 +174,10 @@ Page {
|
||||||
|
|
||||||
TapHandler {
|
TapHandler {
|
||||||
margin: -Nheko.paddingSmall
|
margin: -Nheko.paddingSmall
|
||||||
onSingleTapped: Rooms.setCurrentRoom(model.roomId)
|
onSingleTapped: Rooms.setCurrentRoom(roomId)
|
||||||
onLongPressed: {
|
onLongPressed: {
|
||||||
if (!TimelineManager.isInvite)
|
if (!isInvite)
|
||||||
roomContextMenu.show(model.roomId, model.tags);
|
roomContextMenu.show(roomId, tags);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,8 +203,8 @@ Page {
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
height: avatarSize
|
height: avatarSize
|
||||||
width: avatarSize
|
width: avatarSize
|
||||||
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
|
url: avatarUrl.replace("mxc://", "image://MxcImage/")
|
||||||
displayName: model.roomName
|
displayName: roomName
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: collapsedNotificationBubble
|
id: collapsedNotificationBubble
|
||||||
|
@ -200,13 +212,13 @@ Page {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.margins: -Nheko.paddingSmall
|
anchors.margins: -Nheko.paddingSmall
|
||||||
visible: collapsed && model.notificationCount > 0
|
visible: collapsed && notificationCount > 0
|
||||||
enabled: false
|
enabled: false
|
||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignRight
|
||||||
height: fontMetrics.averageCharacterWidth * 3
|
height: fontMetrics.averageCharacterWidth * 3
|
||||||
width: height
|
width: height
|
||||||
radius: height / 2
|
radius: height / 2
|
||||||
color: model.hasLoudNotification ? Nheko.theme.red : roomItem.bubbleBackground
|
color: hasLoudNotification ? Nheko.theme.red : roomItem.bubbleBackground
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
@ -217,8 +229,8 @@ Page {
|
||||||
fontSizeMode: Text.Fit
|
fontSizeMode: Text.Fit
|
||||||
font.bold: true
|
font.bold: true
|
||||||
font.pixelSize: fontMetrics.font.pixelSize * 0.8
|
font.pixelSize: fontMetrics.font.pixelSize * 0.8
|
||||||
color: model.hasLoudNotification ? "white" : roomItem.bubbleText
|
color: hasLoudNotification ? "white" : roomItem.bubbleText
|
||||||
text: model.notificationCount > 99 ? "99+" : model.notificationCount
|
text: notificationCount > 99 ? "99+" : notificationCount
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -244,7 +256,7 @@ Page {
|
||||||
Layout.alignment: Qt.AlignBottom
|
Layout.alignment: Qt.AlignBottom
|
||||||
color: roomItem.importantText
|
color: roomItem.importantText
|
||||||
elideWidth: textContent.width - timestamp.width - Nheko.paddingMedium
|
elideWidth: textContent.width - timestamp.width - Nheko.paddingMedium
|
||||||
fullText: model.roomName
|
fullText: roomName
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,12 +267,12 @@ Page {
|
||||||
Label {
|
Label {
|
||||||
id: timestamp
|
id: timestamp
|
||||||
|
|
||||||
visible: !model.isInvite && !model.isSpace
|
visible: !isInvite && !isSpace
|
||||||
width: visible ? 0 : undefined
|
width: visible ? 0 : undefined
|
||||||
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
|
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
|
||||||
font.pixelSize: fontMetrics.font.pixelSize * 0.9
|
font.pixelSize: fontMetrics.font.pixelSize * 0.9
|
||||||
color: roomItem.unimportantText
|
color: roomItem.unimportantText
|
||||||
text: model.time
|
text: time
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -268,14 +280,14 @@ Page {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
spacing: 0
|
spacing: 0
|
||||||
visible: !model.isSpace
|
visible: !isSpace
|
||||||
height: visible ? 0 : undefined
|
height: visible ? 0 : undefined
|
||||||
|
|
||||||
ElidedLabel {
|
ElidedLabel {
|
||||||
color: roomItem.unimportantText
|
color: roomItem.unimportantText
|
||||||
font.pixelSize: fontMetrics.font.pixelSize * 0.9
|
font.pixelSize: fontMetrics.font.pixelSize * 0.9
|
||||||
elideWidth: textContent.width - (notificationBubble.visible ? notificationBubble.width : 0) - Nheko.paddingSmall
|
elideWidth: textContent.width - (notificationBubble.visible ? notificationBubble.width : 0) - Nheko.paddingSmall
|
||||||
fullText: model.lastMessage
|
fullText: lastMessage
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,12 +298,12 @@ Page {
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: notificationBubble
|
id: notificationBubble
|
||||||
|
|
||||||
visible: model.notificationCount > 0
|
visible: notificationCount > 0
|
||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignRight
|
||||||
height: fontMetrics.averageCharacterWidth * 3
|
height: fontMetrics.averageCharacterWidth * 3
|
||||||
width: height
|
width: height
|
||||||
radius: height / 2
|
radius: height / 2
|
||||||
color: model.hasLoudNotification ? Nheko.theme.red : roomItem.bubbleBackground
|
color: hasLoudNotification ? Nheko.theme.red : roomItem.bubbleBackground
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
@ -302,8 +314,8 @@ Page {
|
||||||
fontSizeMode: Text.Fit
|
fontSizeMode: Text.Fit
|
||||||
font.bold: true
|
font.bold: true
|
||||||
font.pixelSize: fontMetrics.font.pixelSize * 0.8
|
font.pixelSize: fontMetrics.font.pixelSize * 0.8
|
||||||
color: model.hasLoudNotification ? "white" : roomItem.bubbleText
|
color: hasLoudNotification ? "white" : roomItem.bubbleText
|
||||||
text: model.notificationCount > 99 ? "99+" : model.notificationCount
|
text: notificationCount > 99 ? "99+" : notificationCount
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -320,7 +332,7 @@ Page {
|
||||||
height: parent.height - Nheko.paddingSmall * 2
|
height: parent.height - Nheko.paddingSmall * 2
|
||||||
width: 3
|
width: 3
|
||||||
color: Nheko.colors.highlight
|
color: Nheko.colors.highlight
|
||||||
visible: model.hasUnreadMessages
|
visible: hasUnreadMessages
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue