Changeset View
Changeset View
Standalone View
Standalone View
applets/kimpanel/backend/ibus/emojier/ui/emojier.qml
Show All 22 Lines | |||||
23 | import QtQuick.Controls 2.11 as QQC2 | 23 | import QtQuick.Controls 2.11 as QQC2 | ||
24 | import org.kde.kirigami 2.6 as Kirigami | 24 | import org.kde.kirigami 2.6 as Kirigami | ||
25 | import org.kde.plasma.emoji 1.0 | 25 | import org.kde.plasma.emoji 1.0 | ||
26 | 26 | | |||
27 | Kirigami.ApplicationWindow | 27 | Kirigami.ApplicationWindow | ||
28 | { | 28 | { | ||
29 | id: window | 29 | id: window | ||
30 | 30 | | |||
31 | width: Kirigami.Units.gridUnit * 25 | ||||
32 | height: Kirigami.Units.gridUnit * 25 | ||||
33 | | ||||
31 | EmojiModel { | 34 | EmojiModel { | ||
32 | id: emoji | 35 | id: emoji | ||
33 | } | 36 | } | ||
34 | 37 | | |||
35 | RecentEmojiModel { | 38 | RecentEmojiModel { | ||
36 | id: recentEmojiModel | 39 | id: recentEmojiModel | ||
37 | } | 40 | } | ||
38 | 41 | | |||
39 | function report(thing, description) { | 42 | function report(thing, description) { | ||
40 | if (!visible) | 43 | if (!visible) | ||
41 | return; | 44 | return; | ||
42 | console.log("Copied to clipboard:", thing) | 45 | console.log("Copied to clipboard:", thing) | ||
43 | CopyHelper.copyTextToClipboard(thing) | 46 | CopyHelper.copyTextToClipboard(thing) | ||
44 | recentEmojiModel.includeRecent(thing, description); | 47 | recentEmojiModel.includeRecent(thing, description); | ||
45 | visible = false | 48 | window.showPassiveNotification(i18n("%1 copied to the clipboard", thing)) | ||
46 | } | 49 | } | ||
47 | 50 | | |||
48 | onVisibilityChanged: { | 51 | onVisibilityChanged: { | ||
49 | if (visible) | 52 | if (visible) | ||
50 | globalDrawer.actions[recentEmojiModel.count === 0 ? 1 : 0].trigger() | 53 | globalDrawer.actions[recentEmojiModel.count === 0 ? 1 : 0].trigger() | ||
51 | } | 54 | } | ||
52 | 55 | | |||
56 | Kirigami.Action { | ||||
57 | id: recentAction | ||||
58 | checked: window.pageStack.get(0).title === text | ||||
59 | text: i18n("Recent") | ||||
60 | enabled: recentEmojiModel.count > 0 | ||||
61 | | ||||
62 | icon.name: "document-open-recent-symbolic" | ||||
63 | onTriggered: { | ||||
64 | window.pageStack.replace("qrc:/ui/CategoryPage.qml", {title: text, category: "", model: recentEmojiModel}) | ||||
65 | } | ||||
66 | } | ||||
67 | Kirigami.Action { | ||||
68 | id: searchAction | ||||
69 | checked: window.pageStack.get(0).title === text | ||||
70 | text: i18n("Search") | ||||
71 | icon.name: "search" | ||||
72 | shortcut: StandardKey.Find | ||||
73 | | ||||
74 | onTriggered: { | ||||
75 | window.pageStack.replace("qrc:/ui/CategoryPage.qml", {title: text, category: "", model: emoji, showSearch: true }) | ||||
76 | } | ||||
77 | } | ||||
78 | | ||||
79 | CategoryAction { | ||||
80 | id: allAction | ||||
81 | text: i18n("All") | ||||
82 | icon.name: "view-list-icons" | ||||
83 | category: "" | ||||
84 | } | ||||
85 | | ||||
53 | globalDrawer: Kirigami.GlobalDrawer { | 86 | globalDrawer: Kirigami.GlobalDrawer { | ||
54 | id: drawer | 87 | id: drawer | ||
55 | title: i18n("Categories") | 88 | title: i18n("Categories") | ||
56 | collapsible: !topContent.activeFocus | 89 | collapsible: !topContent.activeFocus | ||
57 | collapsed: true | 90 | collapsed: true | ||
58 | modal: false | 91 | modal: false | ||
59 | 92 | | |||
60 | function createCategoryActions(categories) { | 93 | function createCategoryActions(categories) { | ||
61 | var actions = [] | 94 | var actions = [] | ||
62 | for(var i in categories) { | 95 | for(var i in categories) { | ||
63 | var cat = categories[i]; | 96 | var cat = categories[i] | ||
64 | var catAction = categoryActionComponent.createObject(drawer, { category: cat }); | 97 | actions.push(cat === ":recent:" ? recentAction : | ||
65 | actions.push(catAction) | 98 | cat === ":find:" ? searchAction : | ||
99 | cat.length === 0 ? allAction | ||||
100 | : categoryActionComponent.createObject(drawer, { category: cat })) | ||||
66 | } | 101 | } | ||
67 | return actions; | 102 | return actions; | ||
68 | } | 103 | } | ||
69 | 104 | | |||
70 | actions: createCategoryActions(emoji.categories) | 105 | actions: createCategoryActions(emoji.categories) | ||
71 | 106 | | |||
72 | Component { | 107 | Component { | ||
73 | id: categoryActionComponent | 108 | id: categoryActionComponent | ||
74 | Kirigami.Action { | 109 | CategoryAction {} | ||
75 | readonly property bool isRecent: category === ":recent:" | | |||
76 | property string category | | |||
77 | checked: window.pageStack.get(0).title === text | | |||
78 | text: category.length === 0 ? i18n("All") | | |||
79 | : isRecent ? i18n("Recent") | | |||
80 | : category; | | |||
81 | enabled: !isRecent || recentEmojiModel.count > 0 | | |||
82 | | ||||
83 | icon.name: isRecent ? "document-open-recent-symbolic" | | |||
84 | : category.length === 0 ? "view-list-icons" | | |||
85 | : "image://text/" + emoji.findFirstEmojiForCategory(category) | | |||
86 | onTriggered: { | | |||
87 | window.pageStack.replace("qrc:/ui/CategoryPage.qml", {title: text, category: isRecent ? "" : category, model: isRecent ? recentEmojiModel : emoji }) | | |||
88 | } | | |||
89 | } | | |||
90 | } | 110 | } | ||
91 | } | 111 | } | ||
92 | } | 112 | } |