Commit 105c8444 authored by Filipe Azevedo's avatar Filipe Azevedo

Add support for searching for emoji

parent 093998c2
......@@ -1509,6 +1509,21 @@ void EmojiProxyModel::setGroup(Emoji::Group group)
invalidateFilter();
}
QString EmojiProxyModel::filter() const
{
return filterRegExp().pattern();
}
void EmojiProxyModel::setFilter(const QString &filter)
{
if (filterRegExp().pattern() == filter) {
return;
}
setFilterWildcard(filter);
emit filterChanged();
}
bool EmojiProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
......
......@@ -67,6 +67,7 @@ class EmojiProxyModel : public QSortFilterProxyModel
Q_OBJECT
Q_PROPERTY(Emoji::Group group READ group WRITE setGroup NOTIFY groupChanged)
Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
public:
using QSortFilterProxyModel::QSortFilterProxyModel;
......@@ -74,8 +75,12 @@ public:
Emoji::Group group() const;
void setGroup(Emoji::Group group);
QString filter() const;
void setFilter(const QString &filter);
signals:
void groupChanged();
void filterChanged();
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
......
......@@ -97,6 +97,7 @@ Popup {
ListElement { label: "💡"; group: Emoji.Group.Objects }
ListElement { label: "🔣"; group: Emoji.Group.Symbols }
ListElement { label: "🏁"; group: Emoji.Group.Flags }
ListElement { label: "🔍"; group: Emoji.Group.Invalid }
}
delegate: ItemDelegate {
......@@ -130,6 +131,8 @@ Popup {
return qsTr('Symbols');
case Emoji.Group.Flags:
return qsTr('Flags');
case Emoji.Group.Invalid:
return qsTr('Search');
}
}
ToolTip.visible: hovered
......@@ -139,5 +142,44 @@ Popup {
}
}
}
TextField {
id: searchField
Timer {
id: searchTimer
interval: 500
onTriggered: root.model.filter = searchField.text
}
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
visible: root.model.group === Emoji.Group.Invalid
placeholderText: qsTr("Search emoji")
selectByMouse: true
background: Item {}
rightPadding: clearButton.width
ToolButton {
id: clearButton
visible: searchField.text !== ''
icon.name: 'edit-clear'
focusPolicy: Qt.NoFocus
anchors {
verticalCenter: parent.verticalCenter
right: parent.right
}
onClicked: searchField.clear()
}
onTextChanged: searchTimer.restart()
onVisibleChanged: if (visible) forceActiveFocus()
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment