2023-02-22 01:48:49 +03:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2021-03-14 04:45:20 +03:00
|
|
|
//
|
2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2021-01-12 04:22:40 +03:00
|
|
|
import "./ui"
|
2021-12-30 07:46:30 +03:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2020-11-20 03:22:36 +03:00
|
|
|
import im.nheko 1.0
|
|
|
|
|
2022-02-21 06:06:49 +03:00
|
|
|
Control {
|
2020-11-20 03:22:36 +03:00
|
|
|
id: popup
|
|
|
|
|
2021-12-30 07:46:30 +03:00
|
|
|
property alias currentIndex: listView.currentIndex
|
2022-05-27 17:31:54 +03:00
|
|
|
property string roomId
|
2020-11-20 03:22:36 +03:00
|
|
|
property string completerName
|
|
|
|
property var completer
|
2020-11-24 04:35:38 +03:00
|
|
|
property bool bottomToTop: true
|
2021-02-21 21:31:50 +03:00
|
|
|
property bool fullWidth: false
|
2021-02-24 11:08:01 +03:00
|
|
|
property bool centerRowContent: true
|
2021-02-23 19:06:21 +03:00
|
|
|
property int avatarHeight: 24
|
|
|
|
property int avatarWidth: 24
|
2021-02-24 17:02:13 +03:00
|
|
|
property int rowMargin: 0
|
|
|
|
property int rowSpacing: 5
|
2021-01-27 21:19:21 +03:00
|
|
|
property alias count: listView.count
|
2020-11-20 03:22:36 +03:00
|
|
|
|
2020-11-24 19:32:45 +03:00
|
|
|
signal completionClicked(string completion)
|
2021-02-22 20:38:42 +03:00
|
|
|
signal completionSelected(string id)
|
2020-11-24 19:32:45 +03:00
|
|
|
|
2020-11-20 03:22:36 +03:00
|
|
|
function up() {
|
2020-11-24 04:35:38 +03:00
|
|
|
if (bottomToTop)
|
|
|
|
down_();
|
|
|
|
else
|
|
|
|
up_();
|
|
|
|
}
|
|
|
|
|
|
|
|
function down() {
|
|
|
|
if (bottomToTop)
|
|
|
|
up_();
|
|
|
|
else
|
|
|
|
down_();
|
|
|
|
}
|
|
|
|
|
|
|
|
function up_() {
|
2020-11-20 03:22:36 +03:00
|
|
|
currentIndex = currentIndex - 1;
|
|
|
|
if (currentIndex == -2)
|
2020-11-24 04:35:38 +03:00
|
|
|
currentIndex = listView.count - 1;
|
2020-11-20 03:22:36 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
function down_() {
|
2020-11-20 03:22:36 +03:00
|
|
|
currentIndex = currentIndex + 1;
|
2020-11-24 04:35:38 +03:00
|
|
|
if (currentIndex >= listView.count)
|
2020-11-20 03:22:36 +03:00
|
|
|
currentIndex = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function currentCompletion() {
|
2020-11-24 04:35:38 +03:00
|
|
|
if (currentIndex > -1 && currentIndex < listView.count)
|
2020-11-20 03:22:36 +03:00
|
|
|
return completer.completionAt(currentIndex);
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-02-22 21:48:31 +03:00
|
|
|
function finishCompletion() {
|
2021-03-14 03:24:26 +03:00
|
|
|
if (popup.completerName == "room")
|
|
|
|
popup.completionSelected(listView.itemAtIndex(currentIndex).modelData.roomid);
|
2022-05-27 17:31:54 +03:00
|
|
|
else if (popup.completerName == "user")
|
|
|
|
popup.completionSelected(listView.itemAtIndex(currentIndex).modelData.userid);
|
2021-03-14 03:24:26 +03:00
|
|
|
|
2021-02-22 21:48:31 +03:00
|
|
|
}
|
|
|
|
|
2022-05-27 17:31:54 +03:00
|
|
|
function changeCompleter() {
|
2020-11-24 04:35:38 +03:00
|
|
|
if (completerName) {
|
2022-05-27 17:31:54 +03:00
|
|
|
completer = TimelineManager.completerFor(completerName, completerName == "room" ? "" : (popup.roomId != "" ? popup.roomId : room.roomId));
|
2020-11-24 04:35:38 +03:00
|
|
|
completer.setSearchString("");
|
|
|
|
} else {
|
2020-11-20 04:38:08 +03:00
|
|
|
completer = undefined;
|
2020-11-24 04:35:38 +03:00
|
|
|
}
|
2022-02-21 06:06:49 +03:00
|
|
|
currentIndex = -1
|
2020-11-20 03:22:36 +03:00
|
|
|
}
|
2022-05-27 17:31:54 +03:00
|
|
|
onCompleterNameChanged: changeCompleter()
|
|
|
|
onRoomIdChanged: changeCompleter()
|
2022-03-01 03:59:06 +03:00
|
|
|
|
|
|
|
bottomPadding: 1
|
|
|
|
leftPadding: 1
|
|
|
|
topPadding: 1
|
|
|
|
rightPadding: 1
|
2022-02-21 06:06:49 +03:00
|
|
|
|
|
|
|
contentItem: ListView {
|
2020-11-24 04:35:38 +03:00
|
|
|
id: listView
|
2020-11-20 03:22:36 +03:00
|
|
|
|
2022-02-21 06:06:49 +03:00
|
|
|
// If we have fewer than 7 items, just use the list view's content height.
|
|
|
|
// Otherwise, we want to show 7 items. Each item consists of row spacing between rows, row margins
|
|
|
|
// on each side of a row, 1px of padding above the first item and below the last item, and nominally
|
|
|
|
// some kind of content height. avatarHeight is used for just about every delegate, so we're using
|
|
|
|
// that until we find something better. Put is all together and you have the formula below!
|
|
|
|
implicitHeight: Math.min(contentHeight, 6*rowSpacing + 7*(popup.avatarHeight + 2*rowMargin))
|
2021-12-30 07:46:30 +03:00
|
|
|
clip: true
|
|
|
|
ScrollHelper {
|
|
|
|
flickable: parent
|
|
|
|
anchors.fill: parent
|
|
|
|
enabled: !Settings.mobileMode
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: deadTimer
|
|
|
|
interval: 50
|
|
|
|
}
|
|
|
|
|
|
|
|
onContentYChanged: deadTimer.restart()
|
|
|
|
|
2022-06-12 18:49:20 +03:00
|
|
|
// Broken, see https://bugreports.qt.io/browse/QTBUG-102811
|
|
|
|
//reuseItems: true
|
2022-02-21 06:06:49 +03:00
|
|
|
implicitWidth: listView.contentItem.childrenRect.width
|
2020-11-24 04:35:38 +03:00
|
|
|
model: completer
|
|
|
|
verticalLayoutDirection: popup.bottomToTop ? ListView.BottomToTop : ListView.TopToBottom
|
2021-02-24 17:02:13 +03:00
|
|
|
spacing: rowSpacing
|
2021-03-06 21:48:24 +03:00
|
|
|
pixelAligned: true
|
2021-12-30 07:46:30 +03:00
|
|
|
highlightFollowsCurrentItem: true
|
2020-11-20 03:22:36 +03:00
|
|
|
|
2023-02-08 22:19:35 +03:00
|
|
|
displayMarginBeginning: height / 2
|
|
|
|
displayMarginEnd: height / 2
|
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
delegate: Rectangle {
|
2021-03-14 03:24:26 +03:00
|
|
|
property variant modelData: model
|
|
|
|
|
2021-05-13 09:23:56 +03:00
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlight : Nheko.colors.base
|
2021-12-30 07:46:30 +03:00
|
|
|
height: chooser.child.implicitHeight + 2 * popup.rowMargin
|
2022-03-01 03:59:06 +03:00
|
|
|
implicitWidth: fullWidth ? ListView.view.width : chooser.child.implicitWidth + 4
|
2020-11-20 03:22:36 +03:00
|
|
|
|
2020-11-24 19:32:45 +03:00
|
|
|
MouseArea {
|
2021-01-12 04:22:40 +03:00
|
|
|
id: mouseArea
|
|
|
|
|
2020-11-24 19:32:45 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
2021-12-30 07:46:30 +03:00
|
|
|
onPositionChanged: if (!listView.moving && !deadTimer.running) popup.currentIndex = model.index
|
2021-02-22 20:38:42 +03:00
|
|
|
onClicked: {
|
2021-12-30 07:46:30 +03:00
|
|
|
popup.completionClicked(completer.completionAt(model.index));
|
|
|
|
if (popup.completerName == "room")
|
|
|
|
popup.completionSelected(model.roomid);
|
2022-05-27 17:31:54 +03:00
|
|
|
else if (popup.completerName == "user")
|
|
|
|
popup.completionSelected(model.userid);
|
2021-02-22 20:38:42 +03:00
|
|
|
}
|
2022-01-02 08:22:27 +03:00
|
|
|
}
|
|
|
|
Ripple {
|
|
|
|
color: Qt.rgba(Nheko.colors.base.r, Nheko.colors.base.g, Nheko.colors.base.b, 0.5)
|
2020-11-24 19:32:45 +03:00
|
|
|
}
|
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
DelegateChooser {
|
|
|
|
id: chooser
|
2020-11-20 03:22:36 +03:00
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
roleValue: popup.completerName
|
2021-02-24 17:02:13 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: popup.rowMargin
|
2021-12-30 07:46:30 +03:00
|
|
|
enabled: false
|
2020-11-20 06:33:11 +03:00
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "user"
|
2020-11-20 06:33:11 +03:00
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
RowLayout {
|
|
|
|
id: del
|
2020-11-20 06:33:11 +03:00
|
|
|
|
2022-05-27 17:31:54 +03:00
|
|
|
anchors.centerIn: centerRowContent ? parent : undefined
|
2021-02-24 17:02:13 +03:00
|
|
|
spacing: rowSpacing
|
2020-11-20 06:33:11 +03:00
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
Avatar {
|
2021-02-23 19:06:21 +03:00
|
|
|
height: popup.avatarHeight
|
|
|
|
width: popup.avatarWidth
|
2020-11-24 04:35:38 +03:00
|
|
|
displayName: model.displayName
|
2021-09-01 04:53:12 +03:00
|
|
|
userid: model.userid
|
2020-11-24 04:35:38 +03:00
|
|
|
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
|
2022-05-27 17:31:54 +03:00
|
|
|
enabled: false
|
2020-11-24 04:35:38 +03:00
|
|
|
}
|
2020-11-20 06:33:11 +03:00
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
Label {
|
|
|
|
text: model.displayName
|
2021-05-13 09:23:56 +03:00
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.text
|
2020-11-20 06:33:11 +03:00
|
|
|
}
|
|
|
|
|
2020-11-24 21:06:31 +03:00
|
|
|
Label {
|
|
|
|
text: "(" + model.userid + ")"
|
2021-05-13 09:23:56 +03:00
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.buttonText
|
2020-11-24 21:06:31 +03:00
|
|
|
}
|
|
|
|
|
2020-11-20 03:22:36 +03:00
|
|
|
}
|
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
}
|
2020-11-20 06:33:11 +03:00
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "emoji"
|
2020-11-20 06:33:11 +03:00
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
RowLayout {
|
|
|
|
id: del
|
2020-11-20 06:33:11 +03:00
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
anchors.centerIn: parent
|
2021-02-24 17:02:13 +03:00
|
|
|
spacing: rowSpacing
|
2020-11-20 06:33:11 +03:00
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
Label {
|
|
|
|
text: model.unicode
|
2021-05-13 09:23:56 +03:00
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.text
|
2020-11-24 04:35:38 +03:00
|
|
|
font: Settings.emojiFont
|
|
|
|
}
|
2020-11-20 06:33:11 +03:00
|
|
|
|
2020-11-24 04:35:38 +03:00
|
|
|
Label {
|
|
|
|
text: model.shortName
|
2021-05-13 09:23:56 +03:00
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.text
|
2020-11-20 06:33:11 +03:00
|
|
|
}
|
|
|
|
|
2020-11-20 03:22:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-09 06:58:19 +03:00
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "command"
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
id: del
|
|
|
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
spacing: rowSpacing
|
|
|
|
|
|
|
|
Label {
|
|
|
|
text: model.name
|
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.text
|
|
|
|
font.bold: true
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
text: model.description
|
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.buttonText
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-12-27 08:23:36 +03:00
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "customEmoji"
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
id: del
|
|
|
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
spacing: rowSpacing
|
|
|
|
|
|
|
|
Avatar {
|
|
|
|
height: popup.avatarHeight
|
|
|
|
width: popup.avatarWidth
|
|
|
|
displayName: model.shortcode
|
|
|
|
//userid: model.shortcode
|
|
|
|
url: model.url.replace("mxc://", "image://MxcImage/")
|
2022-05-27 17:31:54 +03:00
|
|
|
enabled: false
|
2021-12-27 08:23:36 +03:00
|
|
|
crop: false
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
text: model.shortcode
|
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.text
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
text: "(" + model.packname + ")"
|
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.buttonText
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-15 22:17:17 +03:00
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "room"
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
id: del
|
|
|
|
|
2021-02-24 17:02:13 +03:00
|
|
|
anchors.centerIn: centerRowContent ? parent : undefined
|
|
|
|
spacing: rowSpacing
|
2021-02-15 22:17:17 +03:00
|
|
|
|
|
|
|
Avatar {
|
2021-02-23 19:06:21 +03:00
|
|
|
height: popup.avatarHeight
|
|
|
|
width: popup.avatarWidth
|
2021-03-14 04:50:44 +03:00
|
|
|
displayName: model.roomName
|
2021-09-01 04:53:12 +03:00
|
|
|
roomid: model.roomid
|
2021-02-15 22:17:17 +03:00
|
|
|
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
|
2022-05-27 17:31:54 +03:00
|
|
|
enabled: false
|
2021-02-15 22:17:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
2021-02-21 21:31:50 +03:00
|
|
|
text: model.roomName
|
2021-03-06 21:48:24 +03:00
|
|
|
font.pixelSize: popup.avatarHeight * 0.5
|
2021-05-13 09:23:56 +03:00
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.text
|
2021-06-06 00:20:23 +03:00
|
|
|
textFormat: Text.RichText
|
2021-02-21 21:31:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "roomAliases"
|
|
|
|
|
2021-02-15 22:17:17 +03:00
|
|
|
RowLayout {
|
|
|
|
id: del
|
|
|
|
|
|
|
|
anchors.centerIn: parent
|
2021-02-24 17:02:13 +03:00
|
|
|
spacing: rowSpacing
|
2021-02-15 22:17:17 +03:00
|
|
|
|
|
|
|
Avatar {
|
2021-02-23 19:06:21 +03:00
|
|
|
height: popup.avatarHeight
|
|
|
|
width: popup.avatarWidth
|
2021-03-14 04:50:44 +03:00
|
|
|
displayName: model.roomName
|
2021-09-01 04:53:12 +03:00
|
|
|
roomid: model.roomid
|
2021-02-15 22:17:17 +03:00
|
|
|
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
|
2022-05-27 17:31:54 +03:00
|
|
|
enabled: false
|
2021-02-15 22:17:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
text: model.roomName
|
2021-05-13 09:23:56 +03:00
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.text
|
2021-06-06 00:20:23 +03:00
|
|
|
textFormat: Text.RichText
|
2021-02-15 22:17:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
text: "(" + model.roomAlias + ")"
|
2021-05-13 09:23:56 +03:00
|
|
|
color: model.index == popup.currentIndex ? Nheko.colors.highlightedText : Nheko.colors.buttonText
|
2021-06-06 00:20:23 +03:00
|
|
|
textFormat: Text.RichText
|
2021-02-15 22:17:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-20 03:22:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
background: Rectangle {
|
2021-05-13 09:23:56 +03:00
|
|
|
color: Nheko.colors.base
|
|
|
|
border.color: Nheko.colors.mid
|
2020-11-20 03:22:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|