You may have noticed that the room list acts a bit... odd. You usually can't scroll all the way down with a scrollwheel, it just stops. It's possible to continue a little bit more with the scrollbar. And sometimes the scrollbar doesn't know how big it's actually supposed to be, commonly occuring when switching from a large room list to a smaller one. I narrowed it down the same usual problem with views in QtQuick: variable sized delegates! Using GammaRay I figured out that for the delegates currently in use they're slightly different: 46 pixels for regular room delegates, 42 pixels for section headers and the "Find your Friends" button was also different. *Technically* TableView (and by extension TreeView) is supposed to allow variable-sized delegates, and we should be able to advertise that with rowHeightProvider. I tried a bunch of different solutions and none of them worked reliably, so I took the usual sledgehammer approach of making all of the delegates the same size. This fixes all of the obvious bugs with the room list I could see, with the one visual downside of making the section headers slightly taller. But since I spent some time improving the tap targets, this is only a visual change and not a functional one. I also made sure to test it in compact mode, and everything shrinks as expected.
92 lines
2.8 KiB
QML
92 lines
2.8 KiB
QML
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
|
|
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
import QtQuick
|
|
import QtQuick.Controls as QQC2
|
|
import QtQuick.Layouts
|
|
|
|
import org.kde.kirigami as Kirigami
|
|
import org.kde.kirigamiaddons.delegates as Delegates
|
|
|
|
import org.kde.neochat
|
|
|
|
Delegates.RoundedItemDelegate {
|
|
id: root
|
|
|
|
required property TreeView treeView
|
|
required property bool isTreeNode
|
|
required property bool expanded
|
|
required property bool hasChildren
|
|
required property int depth
|
|
required property string displayName
|
|
required property int row
|
|
required property bool current
|
|
onCurrentChanged: if (current) {
|
|
collapseButton.forceActiveFocus(Qt.TabFocusReason);
|
|
}
|
|
required property bool selected
|
|
|
|
property bool collapsed: false
|
|
|
|
implicitWidth: treeView.width
|
|
|
|
hoverEnabled: false
|
|
activeFocusOnTab: false
|
|
background: null
|
|
|
|
Keys.onEnterPressed: root.treeView.toggleExpanded(row)
|
|
Keys.onReturnPressed: root.treeView.toggleExpanded(row)
|
|
Keys.onSpacePressed: root.treeView.toggleExpanded(row)
|
|
|
|
contentItem: Item {
|
|
implicitHeight: Math.max(layout.implicitHeight, Kirigami.Units.gridUnit + (NeoChatConfig.compactRoomList ? 0 : Kirigami.Units.largeSpacing * 2))
|
|
|
|
RowLayout {
|
|
id: layout
|
|
|
|
anchors.fill: parent
|
|
|
|
spacing: 0
|
|
|
|
Kirigami.ListSectionHeader {
|
|
visible: !root.collapsed
|
|
horizontalPadding: 0
|
|
topPadding: 0
|
|
bottomPadding: 0
|
|
text: root.collapsed ? "" : root.displayName
|
|
|
|
onClicked: root.treeView.toggleExpanded(root.row)
|
|
|
|
Layout.fillWidth: true
|
|
Layout.alignment: Qt.AlignVCenter
|
|
}
|
|
QQC2.ToolButton {
|
|
id: collapseButton
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
|
|
|
icon {
|
|
name: root.expanded ? "go-up" : "go-down"
|
|
width: Kirigami.Units.iconSizes.small
|
|
height: Kirigami.Units.iconSizes.small
|
|
}
|
|
text: root.expanded ? i18nc("Collapse <section name>", "Collapse %1", root.displayName) : i18nc("Expand <section name", "Expand %1", root.displayName)
|
|
display: QQC2.Button.IconOnly
|
|
|
|
activeFocusOnTab: false
|
|
|
|
QQC2.ToolTip.text: text
|
|
QQC2.ToolTip.visible: hovered
|
|
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
|
|
|
onClicked: root.treeView.toggleExpanded(root.row)
|
|
}
|
|
}
|
|
|
|
// Reduce the size of the tap target, this is smaller the ginormous section header ItemDelegate
|
|
TapHandler {
|
|
onTapped: root.treeView.toggleExpanded(root.row)
|
|
}
|
|
}
|
|
}
|