Commit 22d1fd2f authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

emojier: only allow searching on "All" category

It's weird to search on recent or within a category
parent e45e40a9
......@@ -121,6 +121,8 @@ protected:
QVector<Emoji> m_emoji;
};
#include <QElapsedTimer>
class EmojiModel : public AbstractEmojiModel
{
Q_OBJECT
......@@ -129,6 +131,8 @@ public:
enum EmojiRole { CategoryRole = Qt::UserRole + 1 };
EmojiModel() {
QElapsedTimer time;
time.start();
QLocale locale;
const auto bcp = locale.bcp47Name();
const QString dictName = "ibus/dicts/emoji-" + QString(bcp).replace(QLatin1Char('-'), QLatin1Char('_')) + ".dict";
......@@ -178,6 +182,7 @@ public:
m_categories = categories.values();
m_categories.sort();
m_categories.prepend({});
m_categories.prepend(QStringLiteral(":find:"));
m_categories.prepend(QStringLiteral(":recent:"));
}
......
......@@ -3,5 +3,6 @@
<qresource>
<file>ui/emojier.qml</file>
<file>ui/CategoryPage.qml</file>
<file>ui/CategoryAction.qml</file>
</qresource>
</RCC>
/*
* Copyright (C) 2019 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import org.kde.kirigami 2.6 as Kirigami
Kirigami.Action {
property string category
checked: window.pageStack.get(0).title === text
text: category
icon.name: "image://text/" + emoji.findFirstEmojiForCategory(category)
onTriggered: {
window.pageStack.replace("qrc:/ui/CategoryPage.qml", {title: text, category: category, model: emoji })
}
}
......@@ -29,18 +29,10 @@ Kirigami.ScrollablePage
id: view
property alias model: emojiModel.sourceModel
property alias category: filter.category
property bool showSearch: false
leftPadding: 0
rightPadding: 0
actions.main: Kirigami.Action {
icon.name: "search"
tooltip: i18n("Search...")
shortcut: StandardKey.Find
onTriggered: {
checked = !checked
}
}
titleDelegate: RowLayout {
Layout.fillWidth: true
Layout.preferredWidth: view.width
......@@ -53,6 +45,7 @@ Kirigami.ScrollablePage
id: searchField
Layout.fillWidth: true
placeholderText: i18n("Search...")
visible: view.showSearch
onTextChanged: {
emojiModel.search = text
if (emojiView.currentIndex < 0) {
......@@ -63,11 +56,9 @@ Kirigami.ScrollablePage
if (emojiView.currentItem)
emojiView.currentItem.reportEmoji()
}
visible: view.actions.main.checked
onVisibleChanged: if (visible) forceActiveFocus()
Component.onCompleted: if (visible) Qt.callLater(forceActiveFocus)
Keys.onEscapePressed: {
text = ""
view.actions.main.checked = false
selectAll()
}
}
}
......
......@@ -61,6 +61,24 @@ Kirigami.ApplicationWindow
window.pageStack.replace("qrc:/ui/CategoryPage.qml", {title: text, category: "", model: recentEmojiModel})
}
}
Kirigami.Action {
id: searchAction
checked: window.pageStack.get(0).title === text
text: i18n("Search")
icon.name: "search"
shortcut: StandardKey.Find
onTriggered: {
window.pageStack.replace("qrc:/ui/CategoryPage.qml", {title: text, category: "", model: emoji, showSearch: true })
}
}
CategoryAction {
id: allAction
text: i18n("All")
icon.name: "view-list-icons"
category: ""
}
globalDrawer: Kirigami.GlobalDrawer {
id: drawer
......@@ -74,7 +92,8 @@ Kirigami.ApplicationWindow
for(var i in categories) {
var cat = categories[i]
actions.push(cat === ":recent:" ? recentAction :
cat.length === 0 ? categoryActionComponent.createObject(drawer, { category: cat, text: i18n("All"), "icon.name": "view-list-icons" })
cat === ":find:" ? searchAction :
cat.length === 0 ? allAction
: categoryActionComponent.createObject(drawer, { category: cat }))
}
return actions;
......@@ -84,16 +103,7 @@ Kirigami.ApplicationWindow
Component {
id: categoryActionComponent
Kirigami.Action {
property string category
checked: window.pageStack.get(0).title === text
text: category
icon.name: "image://text/" + emoji.findFirstEmojiForCategory(category)
onTriggered: {
window.pageStack.replace("qrc:/ui/CategoryPage.qml", {title: text, category: category, model: emoji })
}
}
CategoryAction {}
}
}
}
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