This introduces a new base delegate that handles sizing the content of delegate in the timeline, i.e. it handles all the size helper stuff. This is then used for all the other main delegates: - messages - state - read marker This means they now all have identical base code to do the sizing (read marker still had legacy code). Because the new base delegate is called `TimelineDelegate` both `TimelineContainer` and `MessageDelegate` have been renamed: - MessageDelegate -> TextDelegate - this never made sense before images, videos, etc are all technically messages in Matrix parlance - TimelineContainer -> MessageDelegate - this has always really been the base for messages Note - this is mostly groundwork for dealing with the layout polish loop spam which will hopefully be fixed in part 2 with a bubble rework.
98 lines
3.1 KiB
QML
98 lines
3.1 KiB
QML
// SPDX-FileCopyrightText: 2022 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 2.15
|
|
import QtQuick.Controls 2.15 as QQC2
|
|
|
|
import org.kde.kirigami 2.15 as Kirigami
|
|
|
|
import org.kde.neochat 1.0
|
|
|
|
/**
|
|
* @brief The base Item for all delegates in the timeline.
|
|
*
|
|
* This component handles the placing of the main content for a delegate in the
|
|
* timeline. The component is designed for all delegates, positioning them in the
|
|
* timeline with variable padding depending on the window width.
|
|
*
|
|
* This component also supports always setting the delegate to fill the available
|
|
* width in the timeline, e.g. in compact mode.
|
|
*/
|
|
Item {
|
|
id: root
|
|
|
|
/**
|
|
* @brief The Item representing the delegate's main content.
|
|
*/
|
|
property Item contentItem
|
|
|
|
/**
|
|
* @brief Whether the delegate should always stretch to the maximum available width.
|
|
*/
|
|
property bool alwaysMaxWidth: false
|
|
|
|
/**
|
|
* @brief The padding to the left of the content.
|
|
*/
|
|
property real leftPadding: Kirigami.Units.largeSpacing
|
|
|
|
/**
|
|
* @brief The padding to the right of the content.
|
|
*/
|
|
property real rightPadding: Config.compactLayout && root.ListView.view.width >= Kirigami.Units.gridUnit * 20 ? Kirigami.Units.gridUnit * 2 + Kirigami.Units.largeSpacing : Kirigami.Units.largeSpacing
|
|
|
|
width: parent?.width
|
|
implicitHeight: contentItemParent.implicitHeight
|
|
|
|
Item {
|
|
id: contentItemParent
|
|
anchors.top: parent.top
|
|
anchors.bottom: parent.bottom
|
|
anchors.leftMargin: state === "alignLeft" ? Kirigami.Units.largeSpacing : 0
|
|
|
|
state: Config.compactLayout || root.alwaysMaxWidth ? "alignLeft" : "alignCenter"
|
|
// Align left when in compact mode and center when using bubbles
|
|
states: [
|
|
State {
|
|
name: "alignLeft"
|
|
AnchorChanges {
|
|
target: contentItemParent
|
|
anchors.horizontalCenter: undefined
|
|
anchors.left: parent ? parent.left : undefined
|
|
}
|
|
},
|
|
State {
|
|
name: "alignCenter"
|
|
AnchorChanges {
|
|
target: contentItemParent
|
|
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined
|
|
anchors.left: undefined
|
|
}
|
|
}
|
|
]
|
|
|
|
width: (Config.compactLayout || root.alwaysMaxWidth ? root.width : delegateSizeHelper.currentWidth) - root.leftPadding - root.rightPadding
|
|
implicitHeight: root.contentItem?.implicitHeight ?? 0
|
|
}
|
|
|
|
DelegateSizeHelper {
|
|
id: delegateSizeHelper
|
|
startBreakpoint: Kirigami.Units.gridUnit * 46
|
|
endBreakpoint: Kirigami.Units.gridUnit * 66
|
|
startPercentWidth: 100
|
|
endPercentWidth: 85
|
|
maxWidth: Kirigami.Units.gridUnit * 60
|
|
|
|
parentWidth: root.width
|
|
}
|
|
|
|
onContentItemChanged: {
|
|
if (!contentItem) {
|
|
return;
|
|
}
|
|
|
|
contentItem.parent = contentItemParent;
|
|
contentItem.anchors.fill = contentItem.parent;
|
|
}
|
|
}
|