Improve sorting and sizing of completions a bit

This commit is contained in:
Nicolas Werner 2021-03-14 01:24:26 +01:00
parent b82c11bd79
commit 1961312b15
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
53 changed files with 95 additions and 121 deletions

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./ui"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./ui"
@ -62,18 +61,17 @@ Popup {
}
function finishCompletion() {
if(popup.completerName == "room") {
popup.completionSelected(listView.itemAtIndex(currentIndex).modelData.roomid)
}
if (popup.completerName == "room")
popup.completionSelected(listView.itemAtIndex(currentIndex).modelData.roomid);
}
onCompleterNameChanged: {
if (completerName) {
if (completerName == "user") {
if (completerName == "user")
completer = TimelineManager.completerFor(completerName, TimelineManager.timeline.roomId());
} else {
else
completer = TimelineManager.completerFor(completerName);
}
completer.setSearchString("");
} else {
completer = undefined;
@ -99,10 +97,11 @@ Popup {
pixelAligned: true
delegate: Rectangle {
property variant modelData: model
color: model.index == popup.currentIndex ? colors.highlight : colors.base
height: chooser.childrenRect.height + 2 * popup.rowMargin
implicitWidth: fullWidth ? popup.width : chooser.childrenRect.width + 4
property variant modelData: model
MouseArea {
id: mouseArea
@ -111,10 +110,10 @@ Popup {
hoverEnabled: true
onPositionChanged: popup.currentIndex = model.index
onClicked: {
popup.completionClicked(completer.completionAt(model.index))
if(popup.completerName == "room") {
popup.completionSelected(model.roomid)
}
popup.completionClicked(completer.completionAt(model.index));
if (popup.completerName == "room")
popup.completionSelected(model.roomid);
}
Ripple {
@ -200,8 +199,8 @@ Popup {
width: popup.avatarWidth
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
onClicked: {
popup.completionClicked(completer.completionAt(model.index))
popup.completionSelected(model.roomid)
popup.completionClicked(completer.completionAt(model.index));
popup.completionSelected(model.roomid);
}
}

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.12

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./ui"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.5

View file

@ -1,56 +1,62 @@
import QtQuick 2.13
import QtQuick.Layouts 1.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
TextField {
id: input
palette: colors
background: Rectangle {
color: colors.base
}
palette: colors
Rectangle {
id: blueBar
anchors.top: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
color: colors.highlight
height: 1
width: parent.width
Rectangle {
id: blackBar
anchors.verticalCenter: blueBar.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
height: parent.height+1
height: parent.height + 1
width: 0
color: colors.text
states: State {
name: "focused"; when: input.activeFocus == true
name: "focused"
when: input.activeFocus == true
PropertyChanges {
target: blackBar
width: blueBar.width
}
}
transitions: Transition {
from: ""
to: "focused"
reversible: true
NumberAnimation {
NumberAnimation {
target: blackBar
properties: "width"
duration: 500
easing.type: Easing.InOutQuad
alwaysRunToEnd: true
alwaysRunToEnd: true
}
}
}
}
}
background: Rectangle {
color: colors.base
}
}

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./voip"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./delegates"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.9

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtGraphicalEffects 1.0

View file

@ -5,19 +5,31 @@ import im.nheko 1.0
Popup {
id: quickSwitcher
property int textHeight: 32
property int textMargin: 8
property int textHeight: Math.round(Qt.application.font.pixelSize * 2.4)
property int textMargin: Math.round(textHeight / 8)
x: parent.width / 2 - width / 2
y: parent.height / 4 - height / 2
width: parent.width / 2
function delay(delayTime, cb) {
timer.interval = delayTime;
timer.repeat = false;
timer.triggered.connect(cb);
timer.start();
}
width: Math.round(parent.width / 2)
x: Math.round(parent.width / 2 - width / 2)
y: Math.round(parent.height / 4 - height / 2)
modal: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
parent: Overlay.overlay
palette: colors
Overlay.modal: Rectangle {
color: "#aa1E1E1E"
onOpened: {
completerPopup.open();
delay(200, function() {
roomTextInput.forceActiveFocus();
});
}
onClosed: {
completerPopup.close();
}
MatrixTextField {
@ -27,11 +39,9 @@ Popup {
font.pixelSize: Math.ceil(quickSwitcher.textHeight * 0.6)
padding: textMargin
color: colors.text
onTextEdited: {
completerPopup.completer.setSearchString(text)
completerPopup.completer.searchString = text;
}
Keys.onPressed: {
if (event.key == Qt.Key_Up && completerPopup.opened) {
event.accepted = true;
@ -40,7 +50,7 @@ Popup {
event.accepted = true;
completerPopup.down();
} else if (event.matches(StandardKey.InsertParagraphSeparator)) {
completerPopup.finishCompletion()
completerPopup.finishCompletion();
event.accepted = true;
}
}
@ -50,36 +60,30 @@ Popup {
id: completerPopup
x: roomTextInput.x
y: roomTextInput.y + roomTextInput.height + textMargin
y: roomTextInput.y + quickSwitcher.textHeight + quickSwitcher.textMargin
visible: roomTextInput.length > 0
width: parent.width
completerName: "room"
bottomToTop: false
fullWidth: true
avatarHeight: textHeight
avatarWidth: textHeight
avatarHeight: quickSwitcher.textHeight
avatarWidth: quickSwitcher.textHeight
centerRowContent: false
rowMargin: 8
rowSpacing: 6
rowMargin: Math.round(quickSwitcher.textMargin / 2)
rowSpacing: quickSwitcher.textMargin
closePolicy: Popup.NoAutoClose
}
onOpened: {
completerPopup.open()
delay(200, function() {
roomTextInput.forceActiveFocus()
})
}
onClosed: {
completerPopup.close()
}
Connections {
onCompletionSelected: {
TimelineManager.setHistoryView(id)
TimelineManager.highlightRoom(id)
quickSwitcher.close()
TimelineManager.setHistoryView(id);
TimelineManager.highlightRoom(id);
quickSwitcher.close();
}
onCountChanged: {
if (completerPopup.count > 0 && (completerPopup.currentIndex < 0 || completerPopup.currentIndex >= completerPopup.count))
completerPopup.currentIndex = 0;
}
target: completerPopup
}
@ -88,10 +92,8 @@ Popup {
id: timer
}
function delay(delayTime, cb) {
timer.interval = delayTime;
timer.repeat = false;
timer.triggered.connect(cb);
timer.start();
Overlay.modal: Rectangle {
color: "#aa1E1E1E"
}
}

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.6

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./delegates/"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import Qt.labs.platform 1.1 as Platform

View file

@ -1,9 +1,7 @@
// Copyright (C) 2016 Michael Bohlender, <michael.bohlender@kdemail.net>
// Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsystems.com>
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Shamelessly stolen from:
* https://cgit.kde.org/kube.git/tree/framework/qml/ScrollHelper.qml

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.5

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./delegates"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./delegates"
@ -77,13 +76,14 @@ Page {
QuickSwitcher {
}
}
Shortcut {
sequence: "Ctrl+K"
onActivated: {
var quickSwitch = quickSwitcherComponent.createObject(timelineRoot);
TimelineManager.focusTimeline()
TimelineManager.focusTimeline();
quickSwitch.open();
}
}

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.5

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.9

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.9

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./device-verification"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.12

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.12

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.6

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
TextMessage {

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.5

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import ".."

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtMultimedia 5.6

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.12

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import ".."

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.3

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.10

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.3

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.3

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.3

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.3

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.3

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.3

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.3

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "../"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "../"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtGraphicalEffects 1.0

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "../"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.9

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "../"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "../"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.9

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "../"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "../"

View file

@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.9

View file

@ -19,6 +19,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
setSourceModel(model);
QRegularExpression splitPoints("\\s+|-");
// insert all the full texts
for (int i = 0; i < sourceModel()->rowCount(); i++) {
if (i < 7)
mapping.push_back(i);
@ -29,6 +30,19 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
.toLower();
trie_.insert(string1.toUcs4(), i);
auto string2 = sourceModel()
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole2)
.toString()
.toLower();
}
// insert the partial matches
for (int i = 0; i < sourceModel()->rowCount(); i++) {
auto string1 = sourceModel()
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole)
.toString()
.toLower();
for (const auto &e : string1.split(splitPoints)) {
if (!e.isEmpty()) // NOTE(Nico): Use Qt::SkipEmptyParts in Qt 5.14
trie_.insert(e.toUcs4(), i);
@ -40,7 +54,6 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
.toLower();
if (!string2.isEmpty()) {
trie_.insert(string2.toUcs4(), i);
for (const auto &e : string2.split(splitPoints)) {
if (!e.isEmpty()) // NOTE(Nico): Use Qt::SkipEmptyParts in Qt 5.14
trie_.insert(e.toUcs4(), i);
@ -55,7 +68,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
[this](QString s) {
s.remove(":");
s.remove("@");
searchString = s.toLower();
searchString_ = s.toLower();
invalidate();
},
Qt::QueuedConnection);
@ -64,7 +77,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
void
CompletionProxyModel::invalidate()
{
auto key = searchString.toUcs4();
auto key = searchString_.toUcs4();
beginResetModel();
mapping = trie_.search(key, 7, maxMistakes_);
endResetModel();

View file

@ -135,7 +135,8 @@ struct trie
class CompletionProxyModel : public QAbstractProxyModel
{
Q_OBJECT
Q_PROPERTY(
QString searchString READ searchString WRITE setSearchString NOTIFY newSearchString)
public:
CompletionProxyModel(QAbstractItemModel *model,
int max_mistakes = 2,
@ -159,12 +160,13 @@ public slots:
QVariant completionAt(int i) const;
void setSearchString(QString s);
QString searchString() const { return searchString_; }
signals:
void newSearchString(QString);
private:
QString searchString;
QString searchString_;
trie<uint, int> trie_;
std::vector<int> mapping;
int maxMistakes_;