Warning, /plasma/plasma-desktop/emojier/app/ui/Emojier.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2019 Aleix Pol Gonzalez <aleixpol@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 import QtQuick 2.11
0008 import QtQuick.Layouts 1.3
0009 import org.kde.kirigami 2.6 as Kirigami
0010 import org.kde.plasma.emoji
0011 
0012 Kirigami.ApplicationWindow
0013 {
0014     id: window
0015 
0016     minimumWidth: Math.round(minimumHeight * 1.25)
0017     width: Kirigami.Units.gridUnit * 25
0018     height: Kirigami.Units.gridUnit * 25
0019 
0020     EmojiModel {
0021         id: emoji
0022     }
0023 
0024     RecentEmojiModel {
0025         id: recentEmojiModel
0026     }
0027 
0028     function report(thing, description) {
0029         if (!visible)
0030             return;
0031         CopyHelper.copyTextToClipboard(thing)
0032         recentEmojiModel.includeRecent(thing, description);
0033         window.showPassiveNotification(i18n("%1 copied to the clipboard", thing))
0034     }
0035 
0036     Kirigami.Action {
0037         id: recentAction
0038         checked: window.pageStack.get(0).title === text
0039         text: i18n("Recent")
0040 
0041         icon.name: "document-open-recent-symbolic"
0042         onTriggered: {
0043             window.pageStack.replace(Qt.resolvedUrl("CategoryPage.qml"), {title: text, category: "", model: recentEmojiModel, showClearHistoryButton: true})
0044         }
0045     }
0046     Kirigami.Action {
0047         id: searchAction
0048         checked: window.pageStack.get(0).title === text
0049         text: i18n("Search")
0050         icon.name: "search"
0051         shortcut: StandardKey.Find
0052 
0053         onTriggered: {
0054             window.pageStack.replace(Qt.resolvedUrl("CategoryPage.qml"), {title: text, category: "", model: emoji, showSearch: true })
0055         }
0056     }
0057 
0058     CategoryAction {
0059         id: allAction
0060         text: i18n("All")
0061         icon.name: "view-list-icons"
0062         category: ""
0063     }
0064 
0065     Component {
0066         id: drawerComponent
0067 
0068         Kirigami.GlobalDrawer {
0069             id: drawer
0070 
0071             title: i18n("Categories")
0072             collapsible: !topContent.activeFocus
0073             collapsed: true
0074             modal: false
0075 
0076             header: Kirigami.AbstractApplicationHeader {
0077                 topPadding: Kirigami.Units.smallSpacing
0078                 bottomPadding: Kirigami.Units.smallSpacing
0079                 leftPadding: Kirigami.Units.largeSpacing
0080                 rightPadding: Kirigami.Units.smallSpacing
0081 
0082                 Kirigami.Heading {
0083                     level: 1
0084                     text: drawer.title
0085                     textFormat: Text.PlainText
0086                     Layout.fillWidth: true
0087                 }
0088             }
0089 
0090             function getIcon(category: string) {
0091                 switch (category.trim()) {
0092                     case 'Activities': return 'games-highscores'
0093                     case 'Animals and Nature': return 'animal'
0094                     case 'Flags': return 'flag'
0095                     case 'Food and Drink': return 'food'
0096                     case 'Objects': return 'object'
0097                     case 'People and Body': return 'user'
0098                     case 'Smileys and Emotion': return 'smiley'
0099                     case 'Symbols': return 'checkmark'
0100                     case 'Travel and Places': return 'globe'
0101                     default: return 'folder'
0102                 }
0103             }
0104 
0105             Instantiator {
0106                 id: instantiator
0107                 property int loadCount: 0
0108                 asynchronous: true
0109                 model: emoji.categories
0110                 CategoryAction {
0111                     category: modelData
0112                     icon.name: drawer.getIcon(category)
0113                 }
0114                 onObjectAdded: (index, object) => {
0115                     if (++loadCount !== model.length) {
0116                         return;
0117                     }
0118 
0119                     let actions = [recentAction, searchAction, allAction];
0120                     for (let i = 0; i < count; ++i) {
0121                         actions.push(this.objectAt(i));
0122                     }
0123                     drawer.actions = actions;
0124                     // The extra gridUnit is to account for the header that appears when expanded
0125                     window.minimumHeight = Qt.binding(() => drawer.contentHeight + Kirigami.Units.gridUnit * 2);
0126 
0127                 }
0128             }
0129         }
0130     }
0131 
0132     Component.onCompleted: {
0133         recentAction.trigger();
0134 
0135         const incubator = drawerComponent.incubateObject(window);
0136         if (incubator.status !== Component.Ready) {
0137             incubator.onStatusChanged = function(status) {
0138                 if (status === Component.Ready) {
0139                     window.globalDrawer = incubator.object;
0140                 }
0141             };
0142         } else {
0143             window.globalDrawer = incubator.object;
0144         }
0145     }
0146 }