2023-09-26 14:16:53 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtGraphicalEffects 1.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
|
|
|
import shared.status 1.0
|
2023-10-25 15:20:02 +00:00
|
|
|
import shared.controls.delegates 1.0
|
2023-09-26 14:16:53 +00:00
|
|
|
|
2023-10-09 08:45:16 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2023-09-26 14:16:53 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
Control {
|
|
|
|
id: root
|
|
|
|
|
2023-10-09 08:45:16 +00:00
|
|
|
required property var imagePreviewArray
|
|
|
|
/*
|
|
|
|
Expected roles:
|
|
|
|
string title
|
|
|
|
string url
|
|
|
|
bool unfurled
|
|
|
|
bool immutable
|
|
|
|
string hostname
|
|
|
|
string description
|
|
|
|
int linkType
|
|
|
|
int thumbnailWidth
|
|
|
|
int thumbnailHeight
|
|
|
|
string thumbnailUrl
|
|
|
|
string thumbnailDataUri
|
|
|
|
*/
|
2023-09-26 14:16:53 +00:00
|
|
|
required property var linkPreviewModel
|
2023-10-09 08:45:16 +00:00
|
|
|
required property bool showLinkPreviewSettings
|
2023-09-26 14:16:53 +00:00
|
|
|
|
|
|
|
readonly property alias hoveredUrl: d.hoveredUrl
|
2023-10-09 08:45:16 +00:00
|
|
|
readonly property bool hasContent: imagePreviewArray.length > 0 || showLinkPreviewSettings || linkPreviewRepeater.count > 0
|
2023-09-26 14:16:53 +00:00
|
|
|
|
|
|
|
signal imageRemoved(int index)
|
|
|
|
signal imageClicked(var chatImage)
|
|
|
|
signal linkReload(string link)
|
|
|
|
signal linkClicked(string link)
|
2023-10-09 08:45:16 +00:00
|
|
|
|
|
|
|
signal enableLinkPreview()
|
|
|
|
signal enableLinkPreviewForThisMessage()
|
|
|
|
signal disableLinkPreview()
|
|
|
|
signal dismissLinkPreviewSettings()
|
|
|
|
signal dismissLinkPreview(int index)
|
2023-09-26 14:16:53 +00:00
|
|
|
|
|
|
|
horizontalPadding: 12
|
|
|
|
topPadding: 12
|
|
|
|
|
|
|
|
contentItem: Item {
|
|
|
|
id: opacityMaskWrapper
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
implicitWidth: flickable.implicitWidth
|
|
|
|
implicitHeight: flickable.implicitHeight
|
|
|
|
|
|
|
|
opacity: 0
|
|
|
|
|
2023-09-26 14:20:59 +00:00
|
|
|
WheelHandler {
|
|
|
|
target: flickable
|
|
|
|
property: "contentX"
|
|
|
|
acceptedDevices: PointerDevice.Mouse
|
|
|
|
onActiveChanged: if(!active) flickable.returnToBounds()
|
|
|
|
}
|
|
|
|
|
2023-09-26 14:16:53 +00:00
|
|
|
Flickable {
|
|
|
|
id: flickable
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.leftMargin: root.leftPadding
|
|
|
|
anchors.rightMargin: root.rightPadding
|
|
|
|
anchors.bottomMargin: root.bottomPadding
|
|
|
|
anchors.topMargin: root.topPadding
|
|
|
|
|
|
|
|
implicitHeight: contentHeight
|
|
|
|
implicitWidth: contentWidth
|
|
|
|
|
|
|
|
contentWidth: layout.width
|
|
|
|
contentHeight: layout.height
|
|
|
|
|
2023-10-09 08:45:16 +00:00
|
|
|
onFlickStarted: settingsContextMenu.close()
|
|
|
|
|
2023-09-26 14:16:53 +00:00
|
|
|
RowLayout {
|
|
|
|
id: layout
|
|
|
|
spacing: 8
|
|
|
|
StatusChatInputImageArea {
|
|
|
|
id: imageArea
|
|
|
|
Layout.preferredHeight: 64
|
|
|
|
spacing: layout.spacing
|
2023-10-09 08:45:16 +00:00
|
|
|
imageSource: imagePreviewArray
|
2023-09-26 14:16:53 +00:00
|
|
|
onImageClicked: root.imageClicked(chatImage)
|
|
|
|
onImageRemoved: root.imageRemoved(index)
|
2023-10-09 08:45:16 +00:00
|
|
|
visible: !!imagePreviewArray && imagePreviewArray.length > 0
|
2023-09-26 14:16:53 +00:00
|
|
|
}
|
|
|
|
Repeater {
|
2023-10-09 08:45:16 +00:00
|
|
|
id: linkPreviewRepeater
|
2023-09-26 14:16:53 +00:00
|
|
|
model: d.filteredModel
|
2023-10-25 15:20:02 +00:00
|
|
|
delegate: LinkPreviewMiniCardDelegate {
|
2023-10-13 13:36:07 +00:00
|
|
|
required property int index
|
2023-09-26 14:16:53 +00:00
|
|
|
|
2023-10-09 08:45:16 +00:00
|
|
|
onClose: root.dismissLinkPreview(d.filteredModel.mapToSource(index))
|
2023-09-26 14:16:53 +00:00
|
|
|
onRetry: root.linkReload(url)
|
|
|
|
onClicked: root.linkClicked(url)
|
2023-10-09 08:45:16 +00:00
|
|
|
onRightClicked: settingsContextMenu.popup()
|
2023-09-26 14:16:53 +00:00
|
|
|
onContainsMouseChanged: {
|
|
|
|
if (containsMouse) {
|
|
|
|
d.hoveredUrl = url
|
|
|
|
} else if (d.hoveredUrl === url) {
|
|
|
|
d.hoveredUrl = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Component.onDestruction: {
|
|
|
|
if(d.hoveredUrl === url) {
|
|
|
|
d.hoveredUrl = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-09 08:45:16 +00:00
|
|
|
LinkPreviewSettingsCard {
|
|
|
|
id: settingsCard
|
|
|
|
visible: root.showLinkPreviewSettings
|
|
|
|
onDismiss: root.dismissLinkPreviewSettings()
|
|
|
|
onEnableLinkPreviewForThisMessage: root.enableLinkPreviewForThisMessage()
|
|
|
|
onEnableLinkPreview: root.enableLinkPreview()
|
|
|
|
onDisableLinkPreview: root.disableLinkPreview()
|
|
|
|
}
|
2023-09-26 14:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-26 14:20:59 +00:00
|
|
|
|
|
|
|
Rectangle {
|
2023-09-26 14:16:53 +00:00
|
|
|
id: horizontalClipMask
|
|
|
|
anchors.fill: opacityMaskWrapper
|
|
|
|
visible: false
|
|
|
|
gradient: Gradient {
|
2023-09-26 14:20:59 +00:00
|
|
|
orientation: Gradient.Horizontal
|
2023-09-26 14:16:53 +00:00
|
|
|
GradientStop { position: 0.0; color: "transparent" }
|
|
|
|
GradientStop { position: root.horizontalPadding / horizontalClipMask.width; color: "white" }
|
|
|
|
GradientStop { position: 1 - root.horizontalPadding / horizontalClipMask.width; color: "white" }
|
|
|
|
GradientStop { position: 1; color: "transparent" }
|
|
|
|
}
|
|
|
|
}
|
2023-09-26 14:20:59 +00:00
|
|
|
|
2023-09-26 14:16:53 +00:00
|
|
|
OpacityMask {
|
|
|
|
anchors.fill: opacityMaskWrapper
|
|
|
|
source: opacityMaskWrapper
|
|
|
|
maskSource: horizontalClipMask
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
property string hoveredUrl: ""
|
|
|
|
property SortFilterProxyModel filteredModel: SortFilterProxyModel {
|
|
|
|
id: filteredModel
|
|
|
|
sourceModel: root.linkPreviewModel
|
|
|
|
filters: [
|
|
|
|
ExpressionFilter {
|
2023-11-17 16:28:31 +00:00
|
|
|
expression: !model.immutable || model.unfurled // Filter out immutable links that haven't been unfurled yet
|
2023-09-26 14:16:53 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2023-10-09 08:45:16 +00:00
|
|
|
|
2023-10-13 12:49:05 +00:00
|
|
|
LinkPreviewSettingsCardMenu {
|
2023-10-09 08:45:16 +00:00
|
|
|
id: settingsContextMenu
|
|
|
|
|
|
|
|
onEnableLinkPreviewForThisMessage: root.enableLinkPreviewForThisMessage()
|
|
|
|
onEnableLinkPreview: root.enableLinkPreview()
|
|
|
|
onDisableLinkPreview: root.disableLinkPreview()
|
|
|
|
}
|
2023-09-26 14:16:53 +00:00
|
|
|
}
|