commit ea5b4c276ca5c76ebb871ea713965ed6b1bc343f Author: Himprakash Deka Date: Mon Jun 20 20:26:16 2022 +0530 Initial Commit diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..90ae120 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,361 @@ +### GNU GENERAL PUBLIC LICENSE + +Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +### Preamble + +The licenses for most software are designed to take away your freedom +to share and change it. By contrast, the GNU General Public License is +intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, +we want its recipients to know that what they have is not the +original, so that any problems introduced by others will not reflect +on the original authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at +all. + +The precise terms and conditions for copying, distribution and +modification follow. + +### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +**0.** This License applies to any program or other work which +contains a notice placed by the copyright holder saying it may be +distributed under the terms of this General Public License. The +"Program", below, refers to any such program or work, and a "work +based on the Program" means either the Program or any derivative work +under copyright law: that is to say, a work containing the Program or +a portion of it, either verbatim or with modifications and/or +translated into another language. (Hereinafter, translation is +included without limitation in the term "modification".) Each licensee +is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the Program +(independent of having been made by running the Program). Whether that +is true depends on what the Program does. + +**1.** You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a +fee. + +**2.** You may modify your copy or copies of the Program or any +portion of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + +**a)** You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + + +**b)** You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any part +thereof, to be licensed as a whole at no charge to all third parties +under the terms of this License. + + +**c)** If the modified program normally reads commands interactively +when run, you must cause it, when started running for such interactive +use in the most ordinary way, to print or display an announcement +including an appropriate copyright notice and a notice that there is +no warranty (or else, saying that you provide a warranty) and that +users may redistribute the program under these conditions, and telling +the user how to view a copy of this License. (Exception: if the +Program itself is interactive but does not normally print such an +announcement, your work based on the Program is not required to print +an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +**3.** You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + +**a)** Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections 1 +and 2 above on a medium customarily used for software interchange; or, + + +**b)** Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your cost of +physically performing source distribution, a complete machine-readable +copy of the corresponding source code, to be distributed under the +terms of Sections 1 and 2 above on a medium customarily used for +software interchange; or, + + +**c)** Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is allowed +only for noncommercial distribution and only if you received the +program in object code or executable form with such an offer, in +accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +**4.** You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt otherwise +to copy, modify, sublicense or distribute the Program is void, and +will automatically terminate your rights under this License. However, +parties who have received copies, or rights, from you under this +License will not have their licenses terminated so long as such +parties remain in full compliance. + +**5.** You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +**6.** Each time you redistribute the Program (or any work based on +the Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +**7.** If, as a consequence of a court judgment or allegation of +patent infringement or for any other reason (not limited to patent +issues), conditions are imposed on you (whether by court order, +agreement or otherwise) that contradict the conditions of this +License, they do not excuse you from the conditions of this License. +If you cannot distribute so as to satisfy simultaneously your +obligations under this License and any other pertinent obligations, +then as a consequence you may not distribute the Program at all. For +example, if a patent license would not permit royalty-free +redistribution of the Program by all those who receive copies directly +or indirectly through you, then the only way you could satisfy both it +and this License would be to refrain entirely from distribution of the +Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +**8.** If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +**9.** The Free Software Foundation may publish revised and/or new +versions of the General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Program does not specify a +version number of this License, you may choose any version ever +published by the Free Software Foundation. + +**10.** If you wish to incorporate parts of the Program into other +free programs whose distribution conditions are different, write to +the author to ask for permission. For software which is copyrighted by +the Free Software Foundation, write to the Free Software Foundation; +we sometimes make exceptions for this. Our decision will be guided by +the two goals of preserving the free status of all derivatives of our +free software and of promoting the sharing and reuse of software +generally. + +**NO WARRANTY** + +**11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +**12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + +### END OF TERMS AND CONDITIONS + +### How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these +terms. + +To do so, attach the following notices to the program. It is safest to +attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + one line to give the program's name and an idea of what it does. + Copyright (C) yyyy name of author + + 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) any later version. + + 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +Also add information on how to contact you by electronic and paper +mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details + type `show w'. This is free software, and you are welcome + to redistribute it under certain conditions; type `show c' + for details. + +The hypothetical commands \`show w' and \`show c' should show the +appropriate parts of the General Public License. Of course, the +commands you use may be called something other than \`show w' and +\`show c'; they could even be mouse-clicks or menu items--whatever +suits your program. + +You should also get your employer (if you work as a programmer) or +your school, if any, to sign a "copyright disclaimer" for the program, +if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright + interest in the program `Gnomovision' + (which makes passes at compilers) written + by James Hacker. + + signature of Ty Coon, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, +you may consider it more useful to permit linking proprietary +applications with the library. If this is what you want to do, use the +[GNU Lesser General Public +License](https://www.gnu.org/licenses/lgpl.html) instead of this +License. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..afa1335 --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# Simple Kickoff + +This is a simplified fork of Kickoff which is KDE Plasma Desktop's default Application launcher. The design is minimalized without compromising on power and important features. + +## Powerful Plasma Search +The search bar uses `Plasma Search`, which is the same search provider used in the default Kickoff, Krunner and the Overview effect which supports powerful plugins. + +###### **NOTE:** The initial codebase was copied from Kickoff which can be found in `/usr/share/plasma/plasmoids/org.kde.plasma.kickoff/`, on every Linux system that has KDE Plasma installed. + +## Prerequisites: +* Linux based Operating System + +* [KDE Plasma Desktop Environment](https://kde.org/plasma-desktop/) + +## Installation + +**Get it on:** + +[KDE store](https://store.kde.org/p/1819888) + +[Pling](https://www.pling.com/p/1819888) + +[Opendesktop](https://www.opendesktop.org/p/1819888) + +* Install it directly from any of the above mentioned sources. + + or + + If you download the file however, extract it, open a terminal in the directory containing the `metadata.desktop` file and execute the following command: + + ``` + kpackagetool5 -t Plasma/Applet --install + ``` + +## Changes made over default Kickoff: + +* Removed the Places tab and page +* Removed the Configure button (This feature can still be accessed by right clicking the widget icon and `Configure Simple Application Launcher..`) +* Unified design: Removed the header and footer, and every component now shares the same background + +## Gallery: + +![](assets/20220620_195604_Nordic_Round_List.png) + +![](assets/20220620_195604_Nordic_Round_Grid.png) + +![](assets/20220620_195930_Sweet_List.png) + +![](assets/20220620_195930_Sweet_Grid.png) + +![](assets/20220620_200013_Breeze_List.png) + +![](assets/20220620_200013_Breeze_Grid.png) diff --git a/assets/20220620_195604_Nordic_Round_Grid.png b/assets/20220620_195604_Nordic_Round_Grid.png new file mode 100644 index 0000000..9008b53 Binary files /dev/null and b/assets/20220620_195604_Nordic_Round_Grid.png differ diff --git a/assets/20220620_195604_Nordic_Round_List.png b/assets/20220620_195604_Nordic_Round_List.png new file mode 100644 index 0000000..77cb03a Binary files /dev/null and b/assets/20220620_195604_Nordic_Round_List.png differ diff --git a/assets/20220620_195930_Sweet_Grid.png b/assets/20220620_195930_Sweet_Grid.png new file mode 100644 index 0000000..fe30b76 Binary files /dev/null and b/assets/20220620_195930_Sweet_Grid.png differ diff --git a/assets/20220620_195930_Sweet_List.png b/assets/20220620_195930_Sweet_List.png new file mode 100644 index 0000000..d1bebab Binary files /dev/null and b/assets/20220620_195930_Sweet_List.png differ diff --git a/assets/20220620_200013_Breeze_Grid.png b/assets/20220620_200013_Breeze_Grid.png new file mode 100644 index 0000000..d6b9c61 Binary files /dev/null and b/assets/20220620_200013_Breeze_Grid.png differ diff --git a/assets/20220620_200013_Breeze_List.png b/assets/20220620_200013_Breeze_List.png new file mode 100644 index 0000000..d69bad2 Binary files /dev/null and b/assets/20220620_200013_Breeze_List.png differ diff --git a/contents/config/config.qml b/contents/config/config.qml new file mode 100644 index 0000000..dfe81f9 --- /dev/null +++ b/contents/config/config.qml @@ -0,0 +1,17 @@ +/* + SPDX-FileCopyrightText: 2013 Marco Martin + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +import QtQuick 2.0 + +import org.kde.plasma.configuration 2.0 as PlasmaConfig + +PlasmaConfig.ConfigModel { + PlasmaConfig.ConfigCategory { + name: i18n("General") + icon: "preferences-desktop-plasma" + source: "ConfigGeneral.qml" + } +} diff --git a/contents/config/main.xml b/contents/config/main.xml new file mode 100644 index 0000000..0d20277 --- /dev/null +++ b/contents/config/main.xml @@ -0,0 +1,49 @@ + + + + + + + start-here-kde + + + + preferred://browser,org.kde.kontact.desktop,systemsettings.desktop,org.kde.dolphin.desktop,ktp-contactlist.desktop,org.kde.discover.desktop + + + + suspend,hibernate,reboot,shutdown + + + + 0 + + + + false + + + + systemsettings.desktop,org.kde.kinfocenter.desktop,org.kde.discover.desktop + + + + 0 + + + + 1 + + + + false + + + + false + + + diff --git a/contents/ui/ActionMenu.qml b/contents/ui/ActionMenu.qml new file mode 100644 index 0000000..9d27175 --- /dev/null +++ b/contents/ui/ActionMenu.qml @@ -0,0 +1,85 @@ +/* + SPDX-FileCopyrightText: 2013 Aurélien Gâteau + SPDX-FileCopyrightText: 2014-2015 Eike Hein + SPDX-FileCopyrightText: 2021 Mikel Johnson + SPDX-FileCopyrightText: 2021 Noah Davis + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +pragma Singleton // NOTE: Singletons are shared between all instances of a plasmoid + +import QtQuick 2.15 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.plasmoid 2.0 +import org.kde.plasma.components 2.0 as PC2 // for Menu + MenuItem +import "code/tools.js" as Tools + +Item { + id: root + property var actionList: menu.visualParent ? menu.visualParent.actionList : null + + // Workaround for `plasmoid` context property not working in singletons. + // Only one action menu can be open at a time, so this should be safe to use. + property Plasmoid plasmoid: null + + // Not a QQC1 Menu. It's actually a custom QObject that uses a QMenu. + readonly property PC2.Menu menu: PC2.Menu { + id: menu + visualParent: null + placement: PlasmaCore.Types.BottomPosedLeftAlignedPopup + } + + visible: false + + Instantiator { + active: actionList != null + model: actionList + delegate: menuItemComponent + onObjectAdded: menu.addMenuItem(object) + onObjectRemoved: menu.removeMenuItem(object) + } + + Component { id: menuComponent; PC2.Menu {} } + + Component { + id: menuItemComponent + PC2.MenuItem { + id: menuItem + required property var modelData + property PC2.Menu subMenu: if (modelData.subActions) { + return menuComponent.createObject(menuItem, {visualParent: menuItem.action}) + } else { + return null + } + + text: modelData.text ? modelData.text : "" + enabled: modelData.type !== "title" && ("enabled" in modelData ? modelData.enabled : true) + separator: modelData.type === "separator" + section: modelData.type === "title" + icon: modelData.icon ? modelData.icon : null + checkable: modelData.hasOwnProperty("checkable") ? modelData.checkable : false + checked: modelData.hasOwnProperty("checked") ? modelData.checked : false + + Instantiator { + active: menuItem.subMenu != null + model: modelData.subActions + delegate: menuItemComponent + onObjectAdded: subMenu.addMenuItem(object) + onObjectRemoved: subMenu.removeMenuItem(object) + } + + onClicked: { + const modelActionTriggered = Tools.triggerAction( + menu.visualParent.view.model, + menu.visualParent.index, + modelData.actionId, + modelData.actionArgument + ) + if (modelActionTriggered) { + root.plasmoid.expanded = false + } + } + } + } +} diff --git a/contents/ui/ApplicationsPage.qml b/contents/ui/ApplicationsPage.qml new file mode 100644 index 0000000..feeeb9f --- /dev/null +++ b/contents/ui/ApplicationsPage.qml @@ -0,0 +1,144 @@ +/* + * SPDX-FileCopyrightText: 2021 Noah Davis + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +import QtQuick 2.15 +import QtQuick.Layouts 1.15 +import QtQuick.Templates 2.15 as T +import QtQml 2.15 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.private.kicker 0.1 as Kicker + +BasePage { + id: root + property real preferredLeaveButtonsWidth: 0 + property real stackViewWidth: contentAreaItem.width + sideBarComponent: KickoffListView { + id: sideBar + preferredWidth: root.preferredLeaveButtonsWidth + focus: true // needed for Loaders + model: plasmoid.rootItem.rootModel + delegate: KickoffItemDelegate { + width: view.availableWidth + isCategory: model.hasChildren + } + } + contentAreaComponent: VerticalStackView { + id: stackView + readonly property string preferredFavoritesViewObjectName: plasmoid.configuration.favoritesDisplay == 0 ? "favoritesGridView" : "favoritesListView" + readonly property Component preferredFavoritesViewComponent: plasmoid.configuration.favoritesDisplay == 0 ? favoritesGridViewComponent : favoritesListViewComponent + readonly property string preferredAppsViewObjectName: plasmoid.configuration.applicationsDisplay == 0 ? "applicationsGridView" : "applicationsListView" + readonly property Component preferredAppsViewComponent: plasmoid.configuration.applicationsDisplay == 0 ? applicationsGridViewComponent : applicationsListViewComponent + // NOTE: The 0 index modelForRow isn't supposed to be used. That's just how it works. + property int appsModelRow: 1 + readonly property Kicker.AppsModel appsModel: plasmoid.rootItem.rootModel.modelForRow(appsModelRow) + focus: true + initialItem: preferredFavoritesViewComponent + + Component { + id: favoritesListViewComponent + DropAreaListView { + id: favoritesListView + objectName: "favoritesListView" + mainContentView: true + focus: true + model: plasmoid.rootItem.rootModel.favoritesModel + preferredHeight: sideBar.implicitHeight + } + } + + Component { + id: favoritesGridViewComponent + DropAreaGridView { + id: favoritesGridView + objectName: "favoritesGridView" + focus: true + model: plasmoid.rootItem.rootModel.favoritesModel + preferredHeight: sideBar.implicitHeight + } + } + + Component { + id: applicationsListViewComponent + KickoffListView { + id: applicationsListView + objectName: "applicationsListView" + mainContentView: true + model: stackView.appsModel + section.property: model && model.description == "KICKER_ALL_MODEL" ? "display" : "" + section.criteria: ViewSection.FirstCharacter + preferredHeight: sideBar.implicitHeight + } + } + + Component { + id: applicationsGridViewComponent + KickoffGridView { + id: applicationsGridView + objectName: "applicationsGridView" + model: stackView.appsModel + preferredHeight: sideBar.implicitHeight + } + } + + onPreferredFavoritesViewComponentChanged: { + if (root.sideBarItem != null && root.sideBarItem.currentIndex === 0) { + stackView.replace(stackView.preferredFavoritesViewComponent) + } + } + onPreferredAppsViewComponentChanged: { + if (root.sideBarItem != null && root.sideBarItem.currentIndex > 1) { + stackView.replace(stackView.preferredAppsViewComponent) + } + } + + Connections { + target: root.sideBarItem + function onCurrentIndexChanged() { + // Only update row index if the condition is met. + // The 0 index modelForRow isn't supposed to be used. That's just how it works. + if (root.sideBarItem.currentIndex > 0) { + appsModelRow = root.sideBarItem.currentIndex + } + if (root.sideBarItem.currentIndex === 0 + && stackView.currentItem.objectName !== stackView.preferredFavoritesViewObjectName) { + stackView.replace(stackView.preferredFavoritesViewComponent) + } else if (root.sideBarItem.currentIndex === 1 + && stackView.currentItem.objectName !== "applicationsListView") { + // Always use list view for alphabetical apps view since grid view doesn't have sections + // TODO: maybe find a way to have a list view with grids in each section? + stackView.replace(applicationsListViewComponent) + } else if (root.sideBarItem.currentIndex > 1 + && stackView.currentItem.objectName !== stackView.preferredAppsViewObjectName) { + stackView.replace(stackView.preferredAppsViewComponent) + } + } + } + Connections { + target: plasmoid + function onExpandedChanged() { + if(!plasmoid.expanded) { + plasmoid.rootItem.contentArea.currentItem.forceActiveFocus() + } + } + } + } + // NormalPage doesn't get destroyed when deactivated, so the binding uses + // StackView.status and visible. This way the bindings are reset when + // NormalPage is Activated again. + Binding { + target: plasmoid.rootItem + property: "sideBar" + value: root.sideBarItem + when: root.T.StackView.status === T.StackView.Active && root.visible + restoreMode: Binding.RestoreBinding + } + Binding { + target: plasmoid.rootItem + property: "contentArea" + value: root.contentAreaItem.currentItem // NOT just root.contentAreaItem + when: root.T.StackView.status === T.StackView.Active && root.visible + restoreMode: Binding.RestoreBinding + } +} diff --git a/contents/ui/BasePage.qml b/contents/ui/BasePage.qml new file mode 100644 index 0000000..2fc2306 --- /dev/null +++ b/contents/ui/BasePage.qml @@ -0,0 +1,80 @@ +/* + Copyright (C) 2011 Martin Gräßlin + Copyright (C) 2012 Marco Martin + Copyright (C) 2015-2018 Eike Hein + Copyright (C) 2021 by Mikel Johnson + Copyright (C) 2021 by Noah Davis + + 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) any later version. + + 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +import QtQuick 2.15 +import QtQuick.Layouts 1.15 +import QtQuick.Templates 2.15 as T +import QtQml 2.15 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 3.0 as PC3 +import org.kde.plasma.private.kicker 0.1 as Kicker + +FocusScope { + id: root + property real preferredSideBarWidth: implicitSideBarWidth + property real preferredSideBarHeight: implicitSideBarHeight + + property alias sideBarComponent: sideBarLoader.sourceComponent + property alias sideBarItem: sideBarLoader.item + property alias contentAreaComponent: contentAreaLoader.sourceComponent + property alias contentAreaItem: contentAreaLoader.item + + property alias implicitSideBarWidth: sideBarLoader.implicitWidth + property alias implicitSideBarHeight: sideBarLoader.implicitHeight + + implicitWidth: root.preferredSideBarWidth + contentAreaLoader.implicitWidth + implicitHeight: root.preferredSideBarHeight + + Kicker.TriangleMouseFilter { + id: sideBarFilter + anchors { + left: parent.left + top: parent.top + bottom: parent.bottom + } + implicitWidth: root.preferredSideBarWidth + implicitHeight: root.preferredSideBarHeight + edge: LayoutMirroring.enabled ? Qt.LeftEdge : Qt.RightEdge + Loader { + id: sideBarLoader + anchors { + left: parent.left + top: parent.top + } + // backtab is implicitly set by the last button in Header.qml + KeyNavigation.tab: root.contentAreaItem + KeyNavigation.right: contentAreaLoader + Keys.onUpPressed: plasmoid.rootItem.header.nextItemInFocusChain().forceActiveFocus(Qt.BacktabFocusReason) + } + } + Loader { + id: contentAreaLoader + focus: true + anchors { + left: sideBarFilter.right + top: parent.top + } + KeyNavigation.backtab: root.sideBarItem + Keys.onTabPressed: plasmoid.rootItem.header.leaveButtons.nextItemInFocusChain().forceActiveFocus(Qt.BacktabFocusReason) + KeyNavigation.left: sideBarLoader + Keys.onUpPressed: plasmoid.rootItem.searchField.forceActiveFocus(Qt.BacktabFocusReason) + } +} diff --git a/contents/ui/ConfigGeneral.qml b/contents/ui/ConfigGeneral.qml new file mode 100644 index 0000000..0ab59a1 --- /dev/null +++ b/contents/ui/ConfigGeneral.qml @@ -0,0 +1,193 @@ +/* + SPDX-FileCopyrightText: 2013 David Edmundson + SPDX-FileCopyrightText: 2021 Mikel Johnson + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +import QtQuick 2.15 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.5 + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons +import org.kde.kirigami 2.5 as Kirigami + +ColumnLayout { + + property string cfg_icon: plasmoid.configuration.icon + property int cfg_favoritesDisplay: plasmoid.configuration.favoritesDisplay + property int cfg_applicationsDisplay: plasmoid.configuration.applicationsDisplay + property alias cfg_alphaSort: alphaSort.checked + property var cfg_systemFavorites: String(plasmoid.configuration.systemFavorites) + property int cfg_primaryActions: plasmoid.configuration.primaryActions + + Kirigami.FormLayout { + Button { + id: iconButton + + Kirigami.FormData.label: i18n("Icon:") + + implicitWidth: previewFrame.width + PlasmaCore.Units.smallSpacing * 2 + implicitHeight: previewFrame.height + PlasmaCore.Units.smallSpacing * 2 + + KQuickAddons.IconDialog { + id: iconDialog + onIconNameChanged: cfg_icon = iconName || "start-here-kde" + } + + onPressed: iconMenu.opened ? iconMenu.close() : iconMenu.open() + + PlasmaCore.FrameSvgItem { + id: previewFrame + anchors.centerIn: parent + imagePath: plasmoid.location === PlasmaCore.Types.Vertical || plasmoid.location === PlasmaCore.Types.Horizontal + ? "widgets/panel-background" : "widgets/background" + width: PlasmaCore.Units.iconSizes.large + fixedMargins.left + fixedMargins.right + height: PlasmaCore.Units.iconSizes.large + fixedMargins.top + fixedMargins.bottom + + PlasmaCore.IconItem { + anchors.centerIn: parent + width: PlasmaCore.Units.iconSizes.large + height: width + source: cfg_icon + } + } + + Menu { + id: iconMenu + + // Appear below the button + y: +parent.height + + MenuItem { + text: i18nc("@item:inmenu Open icon chooser dialog", "Choose…") + icon.name: "document-open-folder" + onClicked: iconDialog.open() + } + MenuItem { + text: i18nc("@item:inmenu Reset icon to default", "Clear Icon") + icon.name: "edit-clear" + onClicked: cfg_icon = "start-here-kde" + } + } + } + + Item { + Kirigami.FormData.isSection: true + } + + CheckBox { + id: alphaSort + text: i18n("Always sort applications alphabetically") + } + + Button { + icon.name: "settings-configure" + text: i18n("Configure enabled search plugins") + onClicked: KQuickAddons.KCMShell.openSystemSettings("kcm_plasmasearch") + } + + Item { + Kirigami.FormData.isSection: true + } + + RadioButton { + id: showFavoritesInGrid + Kirigami.FormData.label: i18n("Show favorites:") + text: i18nc("Part of a sentence: 'Show favorites in a grid'", "In a grid") + ButtonGroup.group: favoritesDisplayGroup + property int index: 0 + checked: plasmoid.configuration.favoritesDisplay == index + } + + RadioButton { + id: showFavoritesInList + text: i18nc("Part of a sentence: 'Show favorites in a list'", "In a list") + ButtonGroup.group: favoritesDisplayGroup + property int index: 1 + checked: plasmoid.configuration.favoritesDisplay == index + } + + RadioButton { + id: showAppsInGrid + Kirigami.FormData.label: i18n("Show other applications:") + text: i18nc("Part of a sentence: 'Show other applications in a grid'", "In a grid") + ButtonGroup.group: applicationsDisplayGroup + property int index: 0 + checked: plasmoid.configuration.applicationsDisplay == index + } + + RadioButton { + id: showAppsInList + text: i18nc("Part of a sentence: 'Show other applications in a list'", "In a list") + ButtonGroup.group: applicationsDisplayGroup + property int index: 1 + checked: plasmoid.configuration.applicationsDisplay == index + } + + Item { + Kirigami.FormData.isSection: true + } + + RadioButton { + id: powerActionsButton + Kirigami.FormData.label: i18n("Show buttons for:") + text: i18n("Power") + ButtonGroup.group: radioGroup + property string actions: "suspend,hibernate,reboot,shutdown" + property int index: 0 + checked: plasmoid.configuration.primaryActions == index + } + + RadioButton { + id: sessionActionsButton + text: i18n("Session") + ButtonGroup.group: radioGroup + property string actions: "lock-screen,logout,save-session,switch-user" + property int index: 1 + checked: plasmoid.configuration.primaryActions == index + } + + RadioButton { + id: allActionsButton + text: i18n("Power and session") + ButtonGroup.group: radioGroup + property string actions: "lock-screen,logout,save-session,switch-user,suspend,hibernate,reboot,shutdown" + property int index: 3 + checked: plasmoid.configuration.primaryActions == index + } + } + + ButtonGroup { + id: favoritesDisplayGroup + onCheckedButtonChanged: { + if (checkedButton) { + cfg_favoritesDisplay = checkedButton.index + } + } + } + + ButtonGroup { + id: applicationsDisplayGroup + onCheckedButtonChanged: { + if (checkedButton) { + cfg_applicationsDisplay = checkedButton.index + } + } + } + + ButtonGroup { + id: radioGroup + onCheckedButtonChanged: { + if (checkedButton) { + cfg_primaryActions = checkedButton.index + cfg_systemFavorites = checkedButton.actions + } + } + } + + Item { + Layout.fillHeight: true + } +} diff --git a/contents/ui/DropAreaGridView.qml b/contents/ui/DropAreaGridView.qml new file mode 100644 index 0000000..9017fd8 --- /dev/null +++ b/contents/ui/DropAreaGridView.qml @@ -0,0 +1,20 @@ +/* + * SPDX-FileCopyrightText: 2021 Noah Davis + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +import QtQuick 2.15 +import QtQml 2.15 +import org.kde.plasma.core 2.0 as PlasmaCore + +KickoffGridView { + id: root + KickoffDropArea { + z: -1 + parent: root + anchors.fill: parent + targetView: root.view + scrollUpMargin: root.header.height * 2 + scrollDownMargin: root.footer.height * 2 + } +} diff --git a/contents/ui/DropAreaListView.qml b/contents/ui/DropAreaListView.qml new file mode 100644 index 0000000..2acc20e --- /dev/null +++ b/contents/ui/DropAreaListView.qml @@ -0,0 +1,20 @@ +/* + * SPDX-FileCopyrightText: 2021 Noah Davis + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +import QtQuick 2.15 +import QtQml 2.15 +import org.kde.plasma.core 2.0 as PlasmaCore + +KickoffListView { + id: root + KickoffDropArea { + z: -1 + parent: root + anchors.fill: parent + targetView: root.view + scrollUpMargin: root.header.height * 2 + scrollDownMargin: root.footer.height * 2 + } +} diff --git a/contents/ui/EmptyPage.qml b/contents/ui/EmptyPage.qml new file mode 100644 index 0000000..8cc859f --- /dev/null +++ b/contents/ui/EmptyPage.qml @@ -0,0 +1,26 @@ +/* SPDX-FileCopyrightText: 2021 Noah Davis + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +import QtQuick 2.15 +import QtQuick.Templates 2.15 as T + +/** + * This is meant to be a very basic page that behaves like most pages do, + * but inherits no externally defined content or behavior. + */ +T.Page { + id: root + // implicitHeader/FooterWidth and implicitHeader/FooterHeight are 0 when header/footer is not visible + // using a custom implementation that only checks if defined. + property real implicitHeaderWidth2: header ? header.implicitWidth : 0 + property real implicitHeaderHeight2: header ? header.implicitHeight : 0 + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + contentWidth + leftPadding + rightPadding, + implicitHeaderWidth2) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + contentHeight + topPadding + bottomPadding + + (implicitHeaderHeight2 > 0 ? implicitHeaderHeight2 + spacing : 0)) + + Accessible.ignored: true +} diff --git a/contents/ui/FullRepresentation.qml b/contents/ui/FullRepresentation.qml new file mode 100644 index 0000000..e1b2022 --- /dev/null +++ b/contents/ui/FullRepresentation.qml @@ -0,0 +1,115 @@ +/* + SPDX-FileCopyrightText: 2011 Martin Gräßlin + SPDX-FileCopyrightText: 2012 Gregor Taetzner + SPDX-FileCopyrightText: 2012 Marco Martin + SPDX-FileCopyrightText: 2013 2014 David Edmundson + SPDX-FileCopyrightText: 2014 Sebastian Kügler + SPDX-FileCopyrightText: 2021 Mikel Johnson + SPDX-FileCopyrightText: 2021 by Noah Davis + + SPDX-License-Identifier: GPL-2.0-or-later +*/ +import QtQuick 2.15 +import QtQuick.Templates 2.15 as T +import QtQuick.Layouts 1.15 +import QtQml 2.15 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.private.kicker 0.1 as Kicker +import org.kde.plasma.components 3.0 as PC3 + +EmptyPage { + id: root + + Layout.minimumWidth: implicitWidth + Layout.minimumHeight: implicitHeight + + /* NOTE: Important things to know about keyboard input handling: + * + * - Key events are passed up to parent items until the end is reached. + * Be mindful of this when using `Keys.forwardTo`. + * + * - Keys defaults to BeforeItem while KeyNavigation defaults to AfterItem. + * + * - When Keys and KeyNavigation are using the same priority, it seems like + * the one declared first in the QML file gets priority over the other. + * + * - Except for Keys.onPressed, all Keys.on*Pressed signals automatically + * set `event.accepted = true`. + * + * - If you do `item.forceActiveFocus()` and `item` is a focus scope, the + * children of `item` won't necessarily get focus. It seems like + * `forceActiveFocus()` is better for forcing a specific thing to be focused + * while KeyNavigation is better at passing focus down to children of the + * thing you want to focus when dealing with focus scopes. + * + * - KeyNavigation uses BacktabFocusReason (TabFocusReason if mirrored) for left, + * TabFocusReason (BacktabFocusReason if mirrored) for right, + * BacktabFocusReason for up and TabFocusReason for down. + */ + + header: Header { + id: header + preferredStackViewWidth: applicationsPage.stackViewWidth + Binding { + target: plasmoid.rootItem + property: "header" + value: header + restoreMode: Binding.RestoreBinding + } + } + + contentItem: VerticalStackView { + id: contentItemStackView + focus: true + movementTransitionsEnabled: true + // Not using a component to prevent it from being destroyed + initialItem: ApplicationsPage { + id: applicationsPage + preferredLeaveButtonsWidth: header.leaveButtons.width + objectName: "applicationsPage" + } + + Component { + id: searchViewComponent + KickoffListView { + id: searchView + objectName: "searchView" + mainContentView: true + implicitWidth: applicationsPage.implicitWidth + implicitHeight: applicationsPage.implicitHeight + // Forces the function be re-run every time runnerModel.count changes. + // This is absolutely necessary to make the search view work reliably. + model: plasmoid.rootItem.runnerModel.count ? plasmoid.rootItem.runnerModel.modelForRow(0) : null + delegate: KickoffItemDelegate { + width: view.availableWidth + isSearchResult: true + } + activeFocusOnTab: true + // always focus the first item in the header focus chain + KeyNavigation.tab: root.header.nextItemInFocusChain() + T.StackView.onActivated: { + plasmoid.rootItem.sideBar = null + plasmoid.rootItem.contentArea = searchView + } + } + } + + Keys.priority: Keys.AfterItem + // This is here rather than root because events are implicitly forwarded + // to parent items. Don't want to send multiple events to searchField. + Keys.forwardTo: plasmoid.rootItem.searchField + + Connections { + target: root.header + function onSearchTextChanged() { + if (root.header.searchText.length === 0 && contentItemStackView.currentItem.objectName != "applicationsPage") { + contentItemStackView.reverseTransitions = true + contentItemStackView.replace(applicationsPage) + } else if (root.header.searchText.length > 0 && contentItemStackView.currentItem.objectName != "searchView") { + contentItemStackView.reverseTransitions = false + contentItemStackView.replace(searchViewComponent) + } + } + } + } +} diff --git a/contents/ui/Header.qml b/contents/ui/Header.qml new file mode 100644 index 0000000..599a6bc --- /dev/null +++ b/contents/ui/Header.qml @@ -0,0 +1,134 @@ +/* + SPDX-FileCopyrightText: 2014 Sebastian Kügler + SPDX-FileCopyrightText: 2020 Carl Schwan + SPDX-FileCopyrightText: 2021 Mikel Johnson + SPDX-FileCopyrightText: 2021 Noah Davis + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +import QtQuick 2.15 +import QtQuick.Layouts 1.15 +import QtQuick.Templates 2.15 as T +import QtGraphicalEffects 1.15 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 3.0 as PC3 +import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.kirigami 2.13 as Kirigami +import org.kde.kcoreaddons 1.0 as KCoreAddons +import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons + +EmptyPage { + id: root + + property alias searchText: searchField.text + readonly property alias leaveButtons: leaveButtons + property real preferredStackViewWidth: 0 + + contentHeight: Math.max(searchField.implicitHeight, leaveButtons.implicitHeight) + + LeaveButtons { + id: leaveButtons + anchors.left: parent.left + height: parent.height + Keys.onLeftPressed: searchField.forceActiveFocus(Qt.TabFocusReason) + Keys.onRightPressed: searchField.forceActiveFocus(Qt.TabFocusReason) + Keys.onDownPressed: if (plasmoid.rootItem.sideBar) { + plasmoid.rootItem.sideBar.forceActiveFocus(Qt.TabFocusReason) + } else { + plasmoid.rootItem.contentArea.forceActiveFocus(Qt.TabFocusReason) + } + } + + RowLayout { + id: rowLayout + height: parent.height + anchors.right: parent.right + width: preferredStackViewWidth + Keys.onDownPressed: plasmoid.rootItem.contentArea.forceActiveFocus(Qt.TabFocusReason) + + PC3.TextField { + id: searchField + Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter + Layout.fillWidth: true + focus: true + placeholderText: i18n("Search") + clearButtonShown: true + Accessible.editable: true + Accessible.searchEdit: true + inputMethodHints: Qt.ImhNoPredictiveText + Binding { + target: plasmoid.rootItem + property: "searchField" + value: searchField + } + Connections { + target: plasmoid + function onExpandedChanged() { + if(!plasmoid.expanded) { + searchField.clear() + } + } + } + Shortcut { + sequence: StandardKey.Find + onActivated: { + searchField.forceActiveFocus(Qt.ShortcutFocusReason) + searchField.selectAll() + } + } + onTextEdited: { + searchField.forceActiveFocus(Qt.ShortcutFocusReason) + } + onAccepted: { + plasmoid.rootItem.contentArea.currentItem.action.triggered() + plasmoid.rootItem.contentArea.currentItem.forceActiveFocus(Qt.ShortcutFocusReason) + } + Keys.priority: Keys.AfterItem + Keys.forwardTo: plasmoid.rootItem.contentArea.view + Keys.onLeftPressed: if (activeFocus) { + if (LayoutMirroring.enabled) { + nextItemInFocusChain().forceActiveFocus(Qt.TabFocusReason) + } else { + nextItemInFocusChain(false).forceActiveFocus(Qt.BacktabFocusReason) + } + } + Keys.onRightPressed: if (activeFocus) { + if (!LayoutMirroring.enabled) { + nextItemInFocusChain().forceActiveFocus(Qt.TabFocusReason) + } else { + nextItemInFocusChain(false).forceActiveFocus(Qt.BacktabFocusReason) + } + } + } + + PC3.ToolButton { + id: pinButton + checkable: true + checked: plasmoid.configuration.pin + icon.name: "window-pin" + text: i18n("Keep Open") + display: PC3.ToolButton.IconOnly + PC3.ToolTip.text: text + PC3.ToolTip.delay: Kirigami.Units.toolTipDelay + PC3.ToolTip.visible: hovered + Binding { + target: plasmoid + property: "hideOnWindowDeactivate" + value: !plasmoid.configuration.pin + } + KeyNavigation.tab: if (plasmoid.rootItem.sideBar) { + return plasmoid.rootItem.sideBar + } else { + return nextItemInFocusChain() + } + Keys.onLeftPressed: if (!LayoutMirroring.enabled) { + nextItemInFocusChain(false).forceActiveFocus(Qt.BacktabFocusReason) + } + Keys.onRightPressed: if (LayoutMirroring.enabled) { + nextItemInFocusChain(false).forceActiveFocus(Qt.BacktabFocusReason) + } + onToggled: plasmoid.configuration.pin = checked + } + } +} diff --git a/contents/ui/HorizontalStackView.qml b/contents/ui/HorizontalStackView.qml new file mode 100644 index 0000000..00780fe --- /dev/null +++ b/contents/ui/HorizontalStackView.qml @@ -0,0 +1,59 @@ +/* + * SPDX-FileCopyrightText: 2021 Noah Davis + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +import QtQuick 2.15 +import QtQuick.Templates 2.15 as T +import org.kde.plasma.core 2.0 as PlasmaCore + +T.StackView { + id: root + property bool reverseTransitions: false + property bool movementTransitionsEnabled: true + implicitWidth: implicitContentWidth + leftPadding + rightPadding + implicitHeight: implicitContentHeight + topPadding + bottomPadding + clip: busy + contentItem: currentItem + Accessible.ignored: true + popEnter: enterTransition + popExit: exitTransition + pushEnter: enterTransition + pushExit: exitTransition + replaceEnter: enterTransition + replaceExit: exitTransition + // Using NumberAnimation instead of XAnimator because the latter wasn't always smooth enough + Transition { + id: enterTransition + NumberAnimation { + properties: "x" + from: (root.reverseTransitions ? -0.5 : 0.5) * (root.mirrored ? -1 : 1) * -root.width + to: 0 + duration: root.movementTransitionsEnabled ? PlasmaCore.Units.longDuration : 0 + easing.type: Easing.OutCubic + } + NumberAnimation { property: "opacity" + from: 0.0 + to: 1.0 + duration: PlasmaCore.Units.longDuration + easing.type: Easing.OutCubic + } + } + Transition { + id: exitTransition + NumberAnimation { + property: "x" + from: 0 + to: (root.reverseTransitions ? -0.5 : 0.5) * (root.mirrored ? -1 : 1) * root.width + duration: root.movementTransitionsEnabled ? PlasmaCore.Units.longDuration : 0 + easing.type: Easing.OutCubic + } + NumberAnimation { + property: "opacity" + from: 1.0 + to: 0.0 + duration: PlasmaCore.Units.longDuration + easing.type: Easing.OutCubic + } + } +} diff --git a/contents/ui/Kickoff.qml b/contents/ui/Kickoff.qml new file mode 100644 index 0000000..7864e01 --- /dev/null +++ b/contents/ui/Kickoff.qml @@ -0,0 +1,235 @@ +/* + SPDX-FileCopyrightText: 2011 Martin Gräßlin + SPDX-FileCopyrightText: 2012 Gregor Taetzner + SPDX-FileCopyrightText: 2012 Marco Martin + SPDX-FileCopyrightText: 2013 David Edmundson + SPDX-FileCopyrightText: 2015 Eike Hein + SPDX-FileCopyrightText: 2021 Mikel Johnson + SPDX-FileCopyrightText: 2021 Noah Davis + + SPDX-License-Identifier: GPL-2.0-or-later +*/ +import QtQuick 2.15 +import QtQuick.Layouts 1.15 +import QtQml 2.15 +import org.kde.plasma.plasmoid 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 3.0 as PC3 +import org.kde.plasma.private.kicker 0.1 as Kicker + +Item { + id: kickoff + + // The properties are defined here instead of the singleton because each + // instance of Kickoff requires different instances of these properties + + property bool inPanel: plasmoid.location === PlasmaCore.Types.TopEdge + || plasmoid.location === PlasmaCore.Types.RightEdge + || plasmoid.location === PlasmaCore.Types.BottomEdge + || plasmoid.location === PlasmaCore.Types.LeftEdge + property bool vertical: plasmoid.formFactor === PlasmaCore.Types.Vertical + + // Used to prevent the width from changing frequently when the scrollbar appears or disappears + property bool mayHaveGridWithScrollBar: plasmoid.configuration.applicationsDisplay === 0 + || (plasmoid.configuration.favoritesDisplay === 0 && plasmoid.rootItem.rootModel.favoritesModel.count > 16) + + //BEGIN Models + property Kicker.RootModel rootModel: Kicker.RootModel { + autoPopulate: false + + appletInterface: plasmoid + + flat: true // have categories, but no subcategories + sorted: plasmoid.configuration.alphaSort + showSeparators: false + showTopLevelItems: true + + showAllApps: true + showAllAppsCategorized: false + showRecentApps: false + showRecentDocs: false + showRecentContacts: false + showPowerSession: false + showFavoritesPlaceholder: true + + Component.onCompleted: { + favoritesModel.initForClient("org.kde.plasma.kickoff.favorites.instance-" + plasmoid.id) + + if (!plasmoid.configuration.favoritesPortedToKAstats) { + if (favoritesModel.count < 1) { + favoritesModel.portOldFavorites(plasmoid.configuration.favorites); + } + plasmoid.configuration.favoritesPortedToKAstats = true; + } + + refresh(); + } + } + + property Kicker.RunnerModel runnerModel: Kicker.RunnerModel { + query: kickoff.searchField ? kickoff.searchField.text : "" + appletInterface: plasmoid + mergeResults: true + favoritesModel: rootModel.favoritesModel + } + + property Kicker.ComputerModel computerModel: Kicker.ComputerModel { + appletInterface: plasmoid + favoritesModel: rootModel.favoritesModel + systemApplications: plasmoid.configuration.systemApplications + Component.onCompleted: { + //systemApplications = plasmoid.configuration.systemApplications; + } + } + + property Kicker.RecentUsageModel recentUsageModel: Kicker.RecentUsageModel { + favoritesModel: rootModel.favoritesModel + } + + property Kicker.RecentUsageModel frequentUsageModel: Kicker.RecentUsageModel { + favoritesModel: rootModel.favoritesModel + ordering: 1 // Popular / Frequently Used + } + //END + + //BEGIN UI elements + // Set in FullRepresentation.qml + property Item header: null + + // Set in Header.qml + property PC3.TextField searchField: null + + // Set in FullRepresentation.qml, ApplicationPage.qml, PlacesPage.qml + property Item sideBar: null // is null when searching + property Item contentArea: null // is searchView when searching + + // Set in NormalPage.qml + property Item footer: null + //END + + //BEGIN Metrics + readonly property PlasmaCore.FrameSvgItem backgroundMetrics: PlasmaCore.FrameSvgItem { + // Inset defaults to a negative value when not set by margin hints + readonly property real leftPadding: margins.left - Math.max(inset.left, 0) + readonly property real rightPadding: margins.right - Math.max(inset.right, 0) + readonly property real topPadding: margins.top - Math.max(inset.top, 0) + readonly property real bottomPadding: margins.bottom - Math.max(inset.bottom, 0) + readonly property real spacing: leftPadding + visible: false + imagePath: plasmoid.formFactor === PlasmaCore.Types.Planar ? "widgets/background" : "dialogs/background" + } + //END + + Plasmoid.switchWidth: plasmoid.fullRepresentationItem ? plasmoid.fullRepresentationItem.Layout.minimumWidth : -1 + Plasmoid.switchHeight: plasmoid.fullRepresentationItem ? plasmoid.fullRepresentationItem.Layout.minimumHeight : -1 + + Plasmoid.preferredRepresentation: plasmoid.compactRepresentation + + Plasmoid.fullRepresentation: FullRepresentation { focus: true } + + Plasmoid.icon: plasmoid.configuration.icon + + Plasmoid.compactRepresentation: MouseArea { + id: compactRoot + + implicitWidth: PlasmaCore.Units.iconSizeHints.panel + implicitHeight: PlasmaCore.Units.iconSizeHints.panel + + Layout.minimumWidth: { + if (!kickoff.inPanel) { + return PlasmaCore.Units.iconSizes.small + } + + if (kickoff.vertical) { + return -1; + } else { + return Math.min(PlasmaCore.Units.iconSizeHints.panel, parent.height) * buttonIcon.aspectRatio; + } + } + + Layout.minimumHeight: { + if (!kickoff.inPanel) { + return PlasmaCore.Units.iconSizes.small + } + + if (kickoff.vertical) { + return Math.min(PlasmaCore.Units.iconSizeHints.panel, parent.width) * buttonIcon.aspectRatio; + } else { + return -1; + } + } + + Layout.maximumWidth: { + if (!kickoff.inPanel) { + return -1; + } + + if (kickoff.vertical) { + return PlasmaCore.Units.iconSizeHints.panel; + } else { + return Math.min(PlasmaCore.Units.iconSizeHints.panel, parent.height) * buttonIcon.aspectRatio; + } + } + + Layout.maximumHeight: { + if (!kickoff.inPanel) { + return -1; + } + + if (kickoff.vertical) { + return Math.min(PlasmaCore.Units.iconSizeHints.panel, parent.width) * buttonIcon.aspectRatio; + } else { + return PlasmaCore.Units.iconSizeHints.panel; + } + } + + hoverEnabled: true + // For some reason, onClicked can cause the plasmoid to expand after + // releasing sometimes in plasmoidviewer. + // plasmashell doesn't seem to have this issue. + onClicked: plasmoid.expanded = !plasmoid.expanded + + DropArea { + id: compactDragArea + anchors.fill: parent + } + + Timer { + id: expandOnDragTimer + // this is an interaction and not an animation, so we want it as a constant + interval: 250 + running: compactDragArea.containsDrag + onTriggered: plasmoid.expanded = true + } + + PlasmaCore.IconItem { + id: buttonIcon + + readonly property double aspectRatio: (kickoff.vertical ? implicitHeight / implicitWidth + : implicitWidth / implicitHeight) + + anchors.fill: parent + source: plasmoid.icon + active: parent.containsMouse || compactDragArea.containsDrag + smooth: true + roundToIconSize: aspectRatio === 1 + } + } + + Kicker.ProcessRunner { + id: processRunner; + } + + function action_menuedit() { + processRunner.runMenuEditor(); + } + + Component.onCompleted: { + if (plasmoid.hasOwnProperty("activationTogglesExpanded")) { + plasmoid.activationTogglesExpanded = true + } + if (plasmoid.immutability !== PlasmaCore.Types.SystemImmutable) { + plasmoid.setAction("menuedit", i18n("Edit Applications…"), "kmenuedit"); + } + } +} // root diff --git a/contents/ui/KickoffDropArea.qml b/contents/ui/KickoffDropArea.qml new file mode 100644 index 0000000..46aef01 --- /dev/null +++ b/contents/ui/KickoffDropArea.qml @@ -0,0 +1,46 @@ +/* + * SPDX-FileCopyrightText: 2021 Noah Davis + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +import QtQuick 2.15 +import QtQml 2.15 +import org.kde.plasma.core 2.0 as PlasmaCore + +DropArea { + id: root + required property Flickable targetView + property bool enableAutoScroll: targetView.height < targetView.contentHeight + property real scrollUpMargin: 0 + property real scrollDownMargin: 0 + enabled: plasmoid.immutability !== PlasmaCore.Types.SystemImmutable + onPositionChanged: if (drag.source instanceof KickoffItemDelegate) { + const source = drag.source + const view = drag.source.view + if (source.view === root.targetView && !view.move.running && !view.moveDisplaced.running) { + const pos = mapToItem(view.contentItem, drag.x, drag.y) + const targetIndex = view.indexAt(pos.x, pos.y) + if (targetIndex >= 0 && targetIndex !== source.index) { + view.model.moveRow(source.index, targetIndex) + // itemIndex changes directly after moving, + // we can just set the currentIndex to it then. + view.currentIndex = source.index + } + } + } + SmoothedAnimation { + target: root.targetView + property: "contentY" + to: 0 + velocity: 200 * PlasmaCore.Units.devicePixelRatio + running: root.enableAutoScroll && root.containsDrag && root.drag.y <= root.scrollUpMargin + } + SmoothedAnimation { + target: root.targetView + property: "contentY" + to: root.targetView.contentHeight - root.targetView.height + velocity: 200 * PlasmaCore.Units.devicePixelRatio + running: root.enableAutoScroll && root.containsDrag && root.drag.y >= root.height - root.scrollDownMargin + } +} + diff --git a/contents/ui/KickoffGridView.qml b/contents/ui/KickoffGridView.qml new file mode 100644 index 0000000..b1d77a7 --- /dev/null +++ b/contents/ui/KickoffGridView.qml @@ -0,0 +1,255 @@ +/* + SPDX-FileCopyrightText: 2015 Eike Hein + SPDX-FileCopyrightText: 2021 Mikel Johnson + SPDX-FileCopyrightText: 2021 Noah Davis + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +import QtQuick 2.15 +import QtQml 2.15 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 3.0 as PC3 +import org.kde.kirigami 2.16 as Kirigami + +// ScrollView makes it difficult to control implicit size using the contentItem. +// Using EmptyPage instead. +EmptyPage { + id: root + property alias model: view.model + property alias count: view.count + property alias currentIndex: view.currentIndex + property alias currentItem: view.currentItem + property alias delegate: view.delegate + property alias view: view + property real preferredHeight: 0 + + leftPadding: 0 + rightPadding: 0 + topPadding: 0 + bottomPadding: 0 + + clip: view.height < view.contentHeight + + header: MouseArea { + implicitHeight: KickoffSingleton.listItemMetrics.margins.top + hoverEnabled: true + onEntered: { + if (containsMouse) { + let targetIndex = view.indexAt(mouseX + view.contentX, view.contentY) + if (targetIndex >= 0) { + view.currentIndex = targetIndex + view.forceActiveFocus(Qt.MouseFocusReason) + } + } + } + } + + footer: MouseArea { + implicitHeight: KickoffSingleton.listItemMetrics.margins.bottom + hoverEnabled: true + onEntered: { + if (containsMouse) { + let targetIndex = view.indexAt(mouseX + view.contentX, view.height + view.contentY - 1) + if (targetIndex >= 0) { + view.currentIndex = targetIndex + view.forceActiveFocus(Qt.MouseFocusReason) + } + } + } + } + + GridView { + id: view + readonly property real availableWidth: (verticalScrollBar.visible ? (width - verticalScrollBar.width) : width) + readonly property real availableHeight: height + readonly property int columns: Math.floor(availableWidth / cellWidth) + readonly property int rows: Math.floor(availableHeight / cellHeight) + property bool movedWithKeyboard: false + + // NOTE: parent is the contentItem that Control subclasses automatically + // create when no contentItem is set, but content is added. + // There are lots of ways to try to center the content of a GridView + // and many of them have bad visual flaws. This way works pretty well. + // Not center aligning when there might be a scrollbar to keep click target positions consistent. + + Accessible.description: i18n("Grid with %1 rows, %2 columns", rows, columns) // can't use i18np here + + implicitWidth: verticalScrollBar.visible ? (view.cellWidth * 4 + verticalScrollBar.width) : view.cellWidth * 4 + implicitHeight: preferredHeight + + cellHeight: KickoffSingleton.gridCellSize + cellWidth: KickoffSingleton.gridCellSize + + currentIndex: count > 0 ? 0 : -1 + focus: true + interactive: height < contentHeight + pixelAligned: true + reuseItems: true + boundsBehavior: Flickable.StopAtBounds + // default keyboard navigation doesn't allow focus reasons to be used + // and eats up/down key events when at the beginning or end of the list. + keyNavigationEnabled: false + keyNavigationWraps: false + + highlightMoveDuration: 0 + highlight: PlasmaCore.FrameSvgItem { + // The default Z value for delegates is 1. The default Z value for the section delegate is 2. + // The highlight gets a value of 3 while the drag is active and then goes back to the default value of 0. + z: root.currentItem && root.currentItem.Drag.active ? + 3 : 0 + opacity: view.activeFocus + || (plasmoid.rootItem.contentArea === root + && plasmoid.rootItem.searchField.activeFocus) ? 1 : 0.5 + width: view.cellWidth + height: view.cellHeight + imagePath: "widgets/viewitem" + prefix: "hover" + visible: plasmoid.rootItem.contentArea !== root + || ActionMenu.menu.status !== 1 + } + + delegate: KickoffItemDelegate { + id: itemDelegate + icon.width: PlasmaCore.Units.iconSizes.large + icon.height: PlasmaCore.Units.iconSizes.large + display: PC3.AbstractButton.TextUnderIcon + width: view.cellWidth + Accessible.role: Accessible.Cell + } + + move: normalTransition + moveDisplaced: normalTransition + + Transition { + id: normalTransition + NumberAnimation { + duration: PlasmaCore.Units.shortDuration + properties: "x, y" + easing.type: Easing.OutCubic + } + } + + PC3.ScrollBar.vertical: PC3.ScrollBar { + id: verticalScrollBar + z: 2 + height: root.height + anchors.right: parent.right + } + + Kirigami.WheelHandler { + target: view + filterMouseEvents: true + // `20 * Qt.styleHints.wheelScrollLines` is the default speed. + // `* PlasmaCore.Units.devicePixelRatio` is needed on X11 + // because Plasma doesn't support Qt scaling. + horizontalStepSize: 20 * Qt.styleHints.wheelScrollLines * PlasmaCore.Units.devicePixelRatio + verticalStepSize: 20 * Qt.styleHints.wheelScrollLines * PlasmaCore.Units.devicePixelRatio + } + + Connections { + target: plasmoid + function onExpandedChanged() { + if(!plasmoid.expanded) { + view.currentIndex = 0 + view.positionViewAtBeginning() + } + } + } + + // Used to block hover events temporarily after using keyboard navigation. + // If you have one hand on the touch pad or mouse and another hand on the keyboard, + // it's easy to accidentally reset the highlight/focus position to the mouse position. + Timer { + id: movedWithKeyboardTimer + interval: 200 + onTriggered: view.movedWithKeyboard = false + } + + function focusCurrentItem(event, focusReason) { + currentItem.forceActiveFocus(focusReason) + event.accepted = true + } + + Keys.onMenuPressed: if (currentItem !== null) { + currentItem.forceActiveFocus(Qt.ShortcutFocusReason) + currentItem.openActionMenu() + } + Keys.onPressed: { + let targetX = currentItem ? currentItem.x : contentX + let targetY = currentItem ? currentItem.y : contentY + let targetIndex = currentIndex + // supports mirroring + let atLeft = currentIndex % columns === 0 + // at the top of a given column and in the top row + let atTop = currentIndex < columns + // supports mirroring + let atRight = currentIndex % columns === columns - 1 + // at bottom of a given column, not necessarily in the last row + let atBottom = currentIndex >= count - columns + // Implements the keyboard navigation described in https://www.w3.org/TR/wai-aria-practices-1.2/#grid + if (count > 1) { + switch (event.key) { + case Qt.Key_Left: if (!atLeft && !plasmoid.rootItem.searchField.activeFocus) { + moveCurrentIndexLeft() + focusCurrentItem(event, Qt.BacktabFocusReason) + } break + case Qt.Key_Up: if (!atTop) { + moveCurrentIndexUp() + focusCurrentItem(event, Qt.BacktabFocusReason) + } break + case Qt.Key_Right: if (!atRight && !plasmoid.rootItem.searchField.activeFocus) { + moveCurrentIndexRight() + focusCurrentItem(event, Qt.TabFocusReason) + } break + case Qt.Key_Down: if (!atBottom) { + moveCurrentIndexDown() + focusCurrentItem(event, Qt.TabFocusReason) + } break + case Qt.Key_Home: if (event.modifiers === Qt.ControlModifier && currentIndex !== 0) { + currentIndex = 0 + focusCurrentItem(event, Qt.BacktabFocusReason) + } else if (!atLeft) { + targetIndex -= currentIndex % columns + currentIndex = Math.max(targetIndex, 0) + focusCurrentItem(event, Qt.BacktabFocusReason) + } break + case Qt.Key_End: if (event.modifiers === Qt.ControlModifier && currentIndex !== count - 1) { + currentIndex = count - 1 + focusCurrentItem(event, Qt.TabFocusReason) + } else if (!atRight) { + targetIndex += columns - 1 - (currentIndex % columns) + currentIndex = Math.min(targetIndex, count - 1) + focusCurrentItem(event, Qt.TabFocusReason) + } break + case Qt.Key_PageUp: if (!atTop) { + targetY = targetY - height + 1 + targetIndex = indexAt(targetX, targetY) + // TODO: Find a more efficient, but accurate way to do this + while (targetIndex === -1) { + targetY += 1 + targetIndex = indexAt(targetX, targetY) + } + currentIndex = Math.max(targetIndex, 0) + focusCurrentItem(event, Qt.BacktabFocusReason) + } break + case Qt.Key_PageDown: if (!atBottom) { + targetY = targetY + height - 1 + targetIndex = indexAt(targetX, targetY) + // TODO: Find a more efficient, but accurate way to do this + while (targetIndex === -1) { + targetY -= 1 + targetIndex = indexAt(targetX, targetY) + } + currentIndex = Math.min(targetIndex, count - 1) + focusCurrentItem(event, Qt.TabFocusReason) + } break + } + } + movedWithKeyboard = event.accepted + if (movedWithKeyboard) { + movedWithKeyboardTimer.restart() + } + } + } +} diff --git a/contents/ui/KickoffItemDelegate.qml b/contents/ui/KickoffItemDelegate.qml new file mode 100644 index 0000000..99bd6ae --- /dev/null +++ b/contents/ui/KickoffItemDelegate.qml @@ -0,0 +1,259 @@ +/* + Copyright (C) 2011 Martin Gräßlin + Copyright (C) 2012 Gregor Taetzner + Copyright 2014 Sebastian Kügler + Copyright (C) 2015-2018 Eike Hein + Copyright (C) 2021 by Mikel Johnson + Copyright (C) 2021 by Noah Davis + + 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) any later version. + + 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +import QtQuick 2.15 +import QtQml 2.15 +import QtQuick.Layouts 1.15 +import QtQuick.Templates 2.15 as T +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 3.0 as PC3 +import org.kde.kirigami 2.16 as Kirigami +import "code/tools.js" as Tools + +T.ItemDelegate { + id: root + + // model properties + required property var model + required property int index + required property url url + required property var decoration + required property string description + + readonly property Flickable view: ListView.view ?? GridView.view + readonly property bool textUnderIcon: display === PC3.AbstractButton.TextUnderIcon + property bool isCategory: false + readonly property bool hasActionList: model && (model.favoriteId !== null || ("hasActionList" in model && model.hasActionList === true)) + property var actionList: null + property bool isSearchResult: false + readonly property bool menuClosed: ActionMenu.menu.status == 3 // corresponds to DialogStatus.Closed + + property bool dragEnabled: enabled && !root.isCategory + && plasmoid.immutability !== PlasmaCore.Types.SystemImmutable + + function openActionMenu(x = undefined, y = undefined) { + if (!root.hasActionList) { return } + // fill actionList only when needed to prevent slowness when changing app categories rapidly. + if (root.actionList === null) { + let allActions = model.actionList + const favoriteActions = Tools.createFavoriteActions( + i18n, //i18n() function callback + view.model.favoritesModel, + model.favoriteId) + if (favoriteActions) { + if (allActions && allActions.length > 0) { + allActions.push({ "type": "separator" }); + allActions.push.apply(allActions, favoriteActions); + } else { + allActions = favoriteActions; + } + } + root.actionList = allActions + } + ActionMenu.plasmoid = plasmoid + ActionMenu.menu.visualParent = root + if (x !== undefined && y !== undefined) { + ActionMenu.menu.open(x, y) + } else { + ActionMenu.menu.openRelative() + } + } + + // The default Z value for delegates is 1. The default Z value for the section delegate is 2. + // The highlight gets a value of 3 while the drag is active and then goes back to the default value of 0. + z: Drag.active ? 4 : 1 + + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitContentWidth + leftPadding + rightPadding) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitContentHeight + topPadding + bottomPadding) + + // We use an increased fixed vertical padding to improve touch usability + leftPadding: KickoffSingleton.listItemMetrics.margins.left + + (!textUnderIcon && mirrored ? KickoffSingleton.fontMetrics.descent : 0) + rightPadding: KickoffSingleton.listItemMetrics.margins.right + + (!textUnderIcon && !mirrored ? KickoffSingleton.fontMetrics.descent : 0) + topPadding: PlasmaCore.Units.smallSpacing*2 + bottomPadding: PlasmaCore.Units.smallSpacing*2 + + spacing: KickoffSingleton.fontMetrics.descent + + enabled: !model.disabled + hoverEnabled: false + + icon.width: PlasmaCore.Units.iconSizes.smallMedium + icon.height: PlasmaCore.Units.iconSizes.smallMedium + + text: model.name ?? model.display + Accessible.description: root.description != root.text ? root.description : "" + + // Using an action so that it can be replaced or manually triggered + // using `model` () instead of `root.model` leads to errors about + // `model` not having the trigger() function + action: T.Action { + onTriggered: { + // Unless we're showing search results, eat the activation if we + // don't have focus, to prevent the return/enter key from + // inappropriately activating unfocused items + if (!root.activeFocus && !root.isSearchResult) { + return; + } + view.currentIndex = index + // if successfully triggered, close popup + if(view.model.trigger && view.model.trigger(index, "", null)) { + if (plasmoid.hideOnWindowDeactivate) { + plasmoid.expanded = false; + } + } + } + } + + background: null + contentItem: GridLayout { + baselineOffset: label.y + label.baselineOffset + columnSpacing: parent.spacing + rowSpacing: parent.spacing + flow: root.textUnderIcon ? GridLayout.TopToBottom : GridLayout.LeftToRight + PlasmaCore.IconItem { + id: iconItem + Layout.alignment: root.textUnderIcon ? Qt.AlignHCenter | Qt.AlignBottom : Qt.AlignLeft | Qt.AlignVCenter + implicitWidth: root.icon.width + implicitHeight: root.icon.height + animated: false + usesPlasmaTheme: false + source: root.decoration || root.icon.name || root.icon.source + } + PC3.Label { + id: label + Layout.alignment: root.textUnderIcon ? Qt.AlignHCenter | Qt.AlignTop : Qt.AlignLeft | Qt.AlignVCenter + Layout.fillWidth: true + Layout.preferredHeight: root.textUnderIcon && lineCount === 1 ? implicitHeight * 2 : implicitHeight + text: root.text + elide: Text.ElideRight + horizontalAlignment: root.textUnderIcon ? Text.AlignHCenter : Text.AlignLeft + verticalAlignment: root.textUnderIcon ? Text.AlignTop : Text.AlignVCenter + maximumLineCount: 2 + wrapMode: Text.Wrap + textFormat: root.model && root.model.isMultilineText ? Text.StyledText : Text.PlainText + } + } + + PC3.Label { + id: descriptionLabel + parent: root + anchors { + left: root.contentItem.left + right: root.contentItem.right + baseline: root.contentItem.baseline + leftMargin: root.textUnderIcon ? 0 : root.implicitContentWidth + root.spacing + baselineOffset: root.textUnderIcon ? implicitHeight : 0 + } + visible: !textUnderIcon && text.length > 0 && text !== root.text && label.lineCount === 1 + enabled: false + text: root.description + elide: Text.ElideRight + horizontalAlignment: root.textUnderIcon ? Text.AlignHCenter : Text.AlignRight + verticalAlignment: root.textUnderIcon ? Text.AlignTop : Text.AlignVCenter + maximumLineCount: 1 + } + + Drag.active: mouseArea.drag.active + Drag.dragType: Drag.Automatic + Drag.mimeData: { "text/uri-list" : root.url } + Drag.onDragFinished: Drag.imageSource = "" + + MouseArea { + id: mouseArea + parent: root + anchors.fill: parent + anchors.margins: 1 + // Flickable margins are not mirrored, so disable layout mirroring + LayoutMirroring.enabled: false + // Only for ListView since extending margins for GridView is hard + anchors.leftMargin: root.view instanceof ListView ? -root.view.leftMargin : anchors.margins + anchors.rightMargin: root.view instanceof ListView ? -root.view.rightMargin : anchors.margins + hoverEnabled: root.view && !root.view.movedWithKeyboard + // Fix VerticalStackView animation causing view currentIndex + // to change while delegates are moving under the mouse cursor + && plasmoid.fullRepresentationItem && !plasmoid.fullRepresentationItem.contentItem.busy + acceptedButtons: Qt.LeftButton | Qt.RightButton + drag { + axis: Drag.XAndYAxis + target: root.dragEnabled ? dragItem : undefined + } + // Using this Item fixes drag and drop causing delegates + // to reset to a 0 X position and overlapping each other. + Item { id: dragItem } + // Using onPositionChanged instead of onEntered to prevent changing + // categories while scrolling with the mouse wheel. + onPositionChanged: { + // forceActiveFocus() touches multiple items, so check for + // activeFocus first to be more efficient. + if (!root.activeFocus) { + root.forceActiveFocus(Qt.MouseFocusReason) + } + // No need to check currentIndex first because it's + // built into QQuickListView::setCurrentIndex() already + root.view.currentIndex = index + } + onPressed: { + // Select and focus on press to improve responsiveness and touch feedback + view.currentIndex = index + root.forceActiveFocus(Qt.MouseFocusReason) + // We normally try to open right click menus on press like Qt Widgets + if (mouse.button === Qt.RightButton) { + root.openActionMenu(mouseX, mouseY) + } else if (mouse.button === Qt.LeftButton && root.dragEnabled && root.Drag.imageSource == "") { + iconItem.grabToImage((result) => { + return root.Drag.imageSource = result.url + }) + } + } + onClicked: if (mouse.button === Qt.LeftButton) { + root.action.trigger() + } + onPressAndHold: if (mouse.button === Qt.LeftButton) { + /* TODO: make press and hold to open menu exclusive to touch. + * I (ndavis) tried `if (lastDeviceType & ~(PointerDevice.Mouse | PointerDevice.TouchPad))` + * with a TapHandler. lastDeviceType was gotten from the EventPoint argument of the + * grabChanged() signal. ngraham said it wouldn't work because it was preventing single + * taps on touch. I didn't have a touch screen to test it with. + * + * TODO: find a good way to expose the context menu to touch input that doesn't conflict with + * flick to scroll or drag to reorder act like right click on press and hold (with touch). + */ + root.openActionMenu(mouseX, mouseY) + } + } + + PC3.ToolTip.text: { + if (label.truncated && descriptionLabel.truncated) { + return `${text} (${description})` + } else if (descriptionLabel.truncated) { + return description + } else { + return text + } + } + PC3.ToolTip.visible: mouseArea.containsMouse && ((label.visible && label.truncated) || (descriptionLabel.visible && descriptionLabel.truncated)) + PC3.ToolTip.delay: Kirigami.Units.toolTipDelay +} diff --git a/contents/ui/KickoffListView.qml b/contents/ui/KickoffListView.qml new file mode 100644 index 0000000..ffe20c0 --- /dev/null +++ b/contents/ui/KickoffListView.qml @@ -0,0 +1,220 @@ +/* + SPDX-FileCopyrightText: 2011 Martin Gräßlin + SPDX-FileCopyrightText: 2012 Gregor Taetzner + SPDX-FileCopyrightText: 2015-2018 Eike Hein + SPDX-FileCopyrightText: 2021 Mikel Johnson + SPDX-FileCopyrightText: 2021 Noah Davis + + SPDX-License-Identifier: GPL-2.0-or-later +*/ +import QtQuick 2.15 +import QtQml 2.15 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 3.0 as PC3 +import org.kde.kirigami 2.16 as Kirigami + +// ScrollView makes it difficult to control implicit size using the contentItem. +// Using EmptyPage instead. +EmptyPage { + id: root + property alias model: view.model + property alias count: view.count + property alias currentIndex: view.currentIndex + property alias currentItem: view.currentItem + property alias delegate: view.delegate + property alias section: view.section + property alias view: view + property real preferredHeight: 0 + property real preferredWidth: 0 + property bool mainContentView: false + + clip: view.height < view.contentHeight + + header: MouseArea { + implicitHeight: KickoffSingleton.listItemMetrics.margins.top + hoverEnabled: true + onEntered: { + if (containsMouse) { + let targetIndex = view.indexAt(mouseX + view.contentX, view.contentY) + if (targetIndex >= 0) { + view.currentIndex = targetIndex + view.forceActiveFocus(Qt.MouseFocusReason) + } + } + } + } + + leftPadding: 0 + rightPadding: mainContentView ? 0 : plasmoid.rootItem.backgroundMetrics.rightPadding + topPadding: 0 + bottomPadding: 0 + + contentItem: ListView { + id: view + readonly property real availableWidth: (verticalScrollBar.visible ? (width - verticalScrollBar.width) : width) + readonly property real availableHeight: height + property bool movedWithKeyboard: false + + Accessible.role: Accessible.List + + implicitWidth: mainContentView ? KickoffSingleton.gridCellSize * 4 : (preferredWidth ? preferredWidth : contentWidth) + implicitHeight: mainContentView ? preferredHeight : contentHeight + + currentIndex: count > 0 ? 0 : -1 + focus: true + interactive: height < contentHeight + pixelAligned: true + reuseItems: true + boundsBehavior: Flickable.StopAtBounds + // default keyboard navigation doesn't allow focus reasons to be used + // and eats up/down key events when at the beginning or end of the list. + keyNavigationEnabled: false + keyNavigationWraps: false + + // This is actually needed. The highlight will animate from thin to wide otherwise. + highlightResizeDuration: 0 + highlightMoveDuration: 0 + highlight: PlasmaCore.FrameSvgItem { + // The default Z value for delegates is 1. The default Z value for the section delegate is 2. + // The highlight gets a value of 3 while the drag is active and then goes back to the default value of 0. + z: root.currentItem && root.currentItem.Drag.active ? + 3 : 0 + opacity: view.activeFocus + || (plasmoid.rootItem.contentArea === root + && plasmoid.rootItem.searchField.activeFocus) ? 1 : 0.5 + imagePath: "widgets/viewitem" + prefix: "hover" + visible: plasmoid.rootItem.contentArea !== root + || ActionMenu.menu.status !== 1 + } + + delegate: KickoffItemDelegate { + width: view.availableWidth + } + + section { + property: "group" + criteria: ViewSection.FullString + delegate: PC3.Label { + //readonly property bool visualFocus: false + width: Math.min(Math.ceil(implicitWidth), view.availableWidth) + height: KickoffSingleton.listDelegateHeight + horizontalAlignment: section.length === 1 ? Text.AlignHCenter : Text.AlignLeft + verticalAlignment: Text.AlignVCenter + maximumLineCount: 1 + elide: Text.ElideRight + font.pixelSize: KickoffSingleton.listDelegateContentHeight + enabled: false + text: section.length === 1 ? section.toUpperCase() : section + } + } + + move: normalTransition + moveDisplaced: normalTransition + + Transition { + id: normalTransition + NumberAnimation { + duration: PlasmaCore.Units.shortDuration + properties: "x, y" + easing.type: Easing.OutCubic + } + } + + PC3.ScrollBar.vertical: PC3.ScrollBar { + id: verticalScrollBar + z: 2 + height: root.height + anchors.right: parent.right + } + + Kirigami.WheelHandler { + target: view + filterMouseEvents: true + // `20 * Qt.styleHints.wheelScrollLines` is the default speed. + // `* PlasmaCore.Units.devicePixelRatio` is needed on X11 + // because Plasma doesn't support Qt scaling. + horizontalStepSize: 20 * Qt.styleHints.wheelScrollLines * PlasmaCore.Units.devicePixelRatio + verticalStepSize: 20 * Qt.styleHints.wheelScrollLines * PlasmaCore.Units.devicePixelRatio + } + + Connections { + target: plasmoid + function onExpandedChanged() { + if(!plasmoid.expanded) { + view.currentIndex = 0 + view.positionViewAtBeginning() + } + } + } + + Timer { + id: movedWithKeyboardTimer + interval: 200 + onTriggered: view.movedWithKeyboard = false + } + + function focusCurrentItem(event, focusReason) { + currentItem.forceActiveFocus(focusReason) + event.accepted = true + } + + Keys.onMenuPressed: if (currentItem !== null) { + currentItem.forceActiveFocus(Qt.ShortcutFocusReason) + currentItem.openActionMenu() + } + Keys.onPressed: { + let targetX = currentItem ? currentItem.x : contentX + let targetY = currentItem ? currentItem.y : contentY + let targetIndex = currentIndex + let atFirst = currentIndex === 0 + let atLast = currentIndex === count - 1 + if (count > 1) { + switch (event.key) { + case Qt.Key_Up: if (!atFirst) { + decrementCurrentIndex() + focusCurrentItem(event, Qt.BacktabFocusReason) + } break + case Qt.Key_Down: if (!atLast) { + incrementCurrentIndex() + focusCurrentItem(event, Qt.TabFocusReason) + } break + case Qt.Key_Home: if (!atFirst) { + currentIndex = 0 + focusCurrentItem(event, Qt.BacktabFocusReason) + } break + case Qt.Key_End: if (!atLast) { + currentIndex = count - 1 + focusCurrentItem(event, Qt.TabFocusReason) + } break + case Qt.Key_PageUp: if (!atFirst) { + targetY = targetY - height + 1 + targetIndex = indexAt(targetX, targetY) + // TODO: Find a more efficient, but accurate way to do this + while (targetIndex === -1) { + targetY += 1 + targetIndex = indexAt(targetX, targetY) + } + currentIndex = Math.max(targetIndex, 0) + focusCurrentItem(event, Qt.BacktabFocusReason) + } break + case Qt.Key_PageDown: if (!atLast) { + targetY = targetY + height - 1 + targetIndex = indexAt(targetX, targetY) + // TODO: Find a more efficient, but accurate way to do this + while (targetIndex === -1) { + targetY -= 1 + targetIndex = indexAt(targetX, targetY) + } + currentIndex = Math.min(targetIndex, count - 1) + focusCurrentItem(event, Qt.TabFocusReason) + } break + } + } + movedWithKeyboard = event.accepted + if (movedWithKeyboard) { + movedWithKeyboardTimer.restart() + } + } + } +} diff --git a/contents/ui/KickoffSingleton.qml b/contents/ui/KickoffSingleton.qml new file mode 100644 index 0000000..4d35f57 --- /dev/null +++ b/contents/ui/KickoffSingleton.qml @@ -0,0 +1,96 @@ +/* SPDX-FileCopyrightText: 2021 Noah Davis + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +pragma Singleton // NOTE: Singletons are shared between all instances of a plasmoid + +import QtQml.Models 2.15 +import QtQuick 2.15 +import QtQuick.Templates 2.15 as T +import QtQml 2.15 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 3.0 as PC3 +import org.kde.plasma.private.kicker 0.1 as Kicker + +// Using Item because it has a default property. +// Trying to create a default property for a QtObject seems to cause segfaults. +Item { + id: root + visible: false + + //BEGIN Models and Data Sources + readonly property PlasmaCore.DataSource powerManagement: PlasmaCore.DataSource { + engine: "powermanagement" + connectedSources: ["PowerDevil"] + // For some reason, these signal handlers need to be here for `data` to actually contain data. + onSourceAdded: { + disconnectSource(source); + connectSource(source); + } + onSourceRemoved: { + disconnectSource(source); + } + } + //END + + //BEGIN Reusable Objects + readonly property PlasmaCore.Svg lineSvg: PlasmaCore.Svg { + imagePath: "widgets/line" + } + readonly property PlasmaCore.Svg arrowsSvg: PlasmaCore.Svg { + imagePath: "widgets/arrows" + } + //END + + //BEGIN Metrics + readonly property PlasmaCore.FrameSvgItem listItemMetrics: PlasmaCore.FrameSvgItem { + visible: false + imagePath: "widgets/listitem" + prefix: "normal" + } + + readonly property FontMetrics fontMetrics: FontMetrics { + id: fontMetrics + font: PlasmaCore.Theme.defaultFont + } + + readonly property real gridCellSize: gridDelegate.implicitHeight + readonly property real listDelegateHeight: listDelegate.implicitHeight + readonly property real listDelegateContentHeight: listDelegate.implicitContentHeight + //END + + //BEGIN Private + KickoffItemDelegate { + id: gridDelegate + visible: false + enabled: false + icon.width: PlasmaCore.Units.iconSizes.large + icon.height: PlasmaCore.Units.iconSizes.large + model: null + index: -1 + text: "asdf" + url: "" + decoration: "start-here-kde" + description: "asdf" + display: PC3.AbstractButton.TextUnderIcon + width: implicitHeight + action: null + indicator: null + } + KickoffItemDelegate { + id: listDelegate + visible: false + enabled: false + icon.width: PlasmaCore.Units.iconSizes.smallMedium + icon.height: PlasmaCore.Units.iconSizes.smallMedium + model: null + index: -1 + text: "asdf" + url: "" + decoration: "start-here-kde" + description: "asdf" + action: null + indicator: null + } + //END +} diff --git a/contents/ui/LeaveButtons.qml b/contents/ui/LeaveButtons.qml new file mode 100644 index 0000000..c1a7276 --- /dev/null +++ b/contents/ui/LeaveButtons.qml @@ -0,0 +1,120 @@ +/* + SPDX-FileCopyrightText: 2020 Mikel Johnson + SPDX-FileCopyrightText: 2021 Kai Uwe Broulik + + SPDX-License-Identifier: GPL-2.0-or-later +*/ +import QtQuick 2.15 +import QtQuick.Layouts 1.15 +import org.kde.plasma.private.kicker 0.1 as Kicker +import org.kde.plasma.components 2.0 as PC2 // for Menu + MenuItem +import org.kde.plasma.components 3.0 as PC3 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.kirigami 2.16 as Kirigami + +RowLayout { + id: root + property alias leave: leaveButton + + Kicker.SystemModel { + id: systemModel + favoritesModel: plasmoid.rootItem.rootModel.systemFavoritesModel + } + + Item { + Layout.fillWidth: plasmoid.configuration.primaryActions === 3 + } + + Repeater { + id: buttonRepeater + model: systemModel + delegate: PC3.ToolButton { + id: buttonDelegate + text: model.display + icon.name: model.decoration + // TODO: Don't generate items that will never be seen. Maybe DelegateModel can help? + visible: String(plasmoid.configuration.systemFavorites).includes(model.favoriteId) + onClicked: systemModel.trigger(index, "", null) + display: PC3.AbstractButton.IconOnly; + Layout.rightMargin: model.favoriteId === "switch-user" && plasmoid.configuration.primaryActions === 3 ? PlasmaCore.Units.gridUnit : undefined + + PC3.ToolTip.text: text + PC3.ToolTip.delay: Kirigami.Units.toolTipDelay + PC3.ToolTip.visible: display === PC3.AbstractButton.IconOnly && hovered + + Keys.onLeftPressed: if (LayoutMirroring.enabled) { + nextItemInFocusChain().forceActiveFocus(Qt.BacktabFocusReason) + } else if (index > (plasmoid.configuration.primaryActions === 0 ? 3 : 0)) { + nextItemInFocusChain(false).forceActiveFocus(Qt.TabFocusReason) + } + Keys.onRightPressed: if (!LayoutMirroring.enabled) { + nextItemInFocusChain().forceActiveFocus(Qt.BacktabFocusReason) + } else if (index < buttonRepeater.count - 1 || leaveButton.visible) { + nextItemInFocusChain(false).forceActiveFocus(Qt.TabFocusReason) + } + } + } + + Item { + Layout.fillWidth: plasmoid.configuration.primaryActions !== 3 + } + + PC3.ToolButton { + id: leaveButton + readonly property int currentId: plasmoid.configuration.primaryActions + Accessible.role: Accessible.ButtonMenu + icon.width: PlasmaCore.Units.iconSizes.smallMedium + icon.height: PlasmaCore.Units.iconSizes.smallMedium + icon.name: ["system-log-out", "system-shutdown", "view-more-symbolic", ""][currentId]; + display: PC3.AbstractButton.IconOnly; + visible: plasmoid.configuration.primaryActions !== 3 + // Make it look pressed while the menu is open + down: contextMenu.status === PC2.DialogStatus.Open || pressed + PC3.ToolTip.text: [i18n("Leave"), i18n("Power"), i18n("More"), ""][leaveButton.currentId] + PC3.ToolTip.visible: leaveButton.hovered + PC3.ToolTip.delay: Kirigami.Units.toolTipDelay + Keys.onLeftPressed: if (LayoutMirroring.enabled) { + nextItemInFocusChain().forceActiveFocus(Qt.BacktabFocusReason) + } else { + nextItemInFocusChain(false).forceActiveFocus(Qt.BacktabFocusReason) + } + Keys.onRightPressed: if (!LayoutMirroring.enabled) { + nextItemInFocusChain().forceActiveFocus(Qt.BacktabFocusReason) + } else { + nextItemInFocusChain(false).forceActiveFocus(Qt.BacktabFocusReason) + } + onPressed: contextMenu.openRelative() + } + + Instantiator { + model: systemModel + // Not a QQC1 MenuItem. It's actually a custom QQuickItem. + delegate: PC2.MenuItem { + text: model.display + icon: model.decoration + // TODO: Don't generate items that will never be seen. Maybe DelegateModel can help? + visible: !String(plasmoid.configuration.systemFavorites).includes(model.favoriteId) + Accessible.role: Accessible.MenuItem + onClicked: systemModel.trigger(index, "", null) + } + onObjectAdded: contextMenu.addMenuItem(object) + onObjectRemoved: contextMenu.removeMenuItem(object) + } + + // Not a QQC1 Menu. It's actually a custom QObject that uses a QMenu. + PC2.Menu { + id: contextMenu + visualParent: leaveButton + placement: { + switch (plasmoid.location) { + case PlasmaCore.Types.LeftEdge: + case PlasmaCore.Types.RightEdge: + case PlasmaCore.Types.TopEdge: + return PlasmaCore.Types.BottomPosedRightAlignedPopup; + case PlasmaCore.Types.BottomEdge: + default: + return PlasmaCore.Types.TopPosedRightAlignedPopup; + } + } + } +} diff --git a/contents/ui/VerticalStackView.qml b/contents/ui/VerticalStackView.qml new file mode 100644 index 0000000..f92012d --- /dev/null +++ b/contents/ui/VerticalStackView.qml @@ -0,0 +1,61 @@ +/* + * SPDX-FileCopyrightText: 2021 Noah Davis + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +import QtQuick 2.15 +import QtQuick.Templates 2.15 as T +import org.kde.plasma.core 2.0 as PlasmaCore + +T.StackView { + id: root + property bool reverseTransitions: false + property bool movementTransitionsEnabled: false + implicitWidth: implicitContentWidth + leftPadding + rightPadding + implicitHeight: implicitContentHeight + topPadding + bottomPadding + clip: busy + contentItem: currentItem + Accessible.ignored: true + popEnter: enterTransition + popExit: exitTransition + pushEnter: enterTransition + pushExit: exitTransition + replaceEnter: enterTransition + replaceExit: exitTransition + // Using NumberAnimation instead of YAnimator because the latter wasn't always smooth enough + Transition { + id: enterTransition + NumberAnimation { + properties: "y" + from: (root.reverseTransitions ? -0.5 : 0.5) * -root.height + to: 0 + duration: root.movementTransitionsEnabled ? PlasmaCore.Units.longDuration : 0 + easing.type: Easing.OutCubic + } + NumberAnimation { property: "opacity" + from: 0.0 + to: 1.0 + duration: PlasmaCore.Units.longDuration + easing.type: Easing.OutCubic + } + } + Transition { + id: exitTransition + NumberAnimation { + property: "y" + from: 0 + to: (root.reverseTransitions ? -0.5 : 0.5) * root.height + duration: root.movementTransitionsEnabled ? PlasmaCore.Units.longDuration : 0 + easing.type: Easing.OutCubic + } + NumberAnimation { + property: "opacity" + from: 1.0 + to: 0.0 + duration: PlasmaCore.Units.longDuration + easing.type: Easing.OutCubic + } + } + + // NOTE: Not using animations because they tended to look too jumpy +} diff --git a/contents/ui/code/tools.js b/contents/ui/code/tools.js new file mode 100644 index 0000000..eb27d6c --- /dev/null +++ b/contents/ui/code/tools.js @@ -0,0 +1,189 @@ +/* + SPDX-FileCopyrightText: 2013 Aurélien Gâteau + SPDX-FileCopyrightText: 2013-2015 Eike Hein + SPDX-FileCopyrightText: 2017 Ivan Cukic + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +.pragma library + +function fillActionMenu(i18n, actionMenu, actionList, favoriteModel, favoriteId) { + // Accessing actionList can be a costly operation, so we don't + // access it until we need the menu. + + var actions = createFavoriteActions(i18n, favoriteModel, favoriteId); + + if (actions) { + if (actionList && actionList.length > 0) { + var separator = { "type": "separator" }; + actionList.push(separator); + // actionList = actions.concat(actionList); // this crashes Qt O.o + actionList.push.apply(actionList, actions); + } else { + actionList = actions; + } + } + + actionMenu.actionList = actionList; +} + +function createFavoriteActions(i18n, favoriteModel, favoriteId) { + if (!favoriteModel || !favoriteId || !favoriteModel.enabled) { + return null; + } + + + if (favoriteModel.activities === undefined || + favoriteModel.activities.runningActivities.length <= 1) { + var action = {}; + + if (favoriteModel.isFavorite(favoriteId)) { + action.text = i18n("Remove from Favorites"); + action.icon = "bookmark-remove"; + action.actionId = "_kicker_favorite_remove"; + } else if (favoriteModel.maxFavorites == -1 || favoriteModel.count < favoriteModel.maxFavorites) { + action.text = i18n("Add to Favorites"); + action.icon = "bookmark-new"; + action.actionId = "_kicker_favorite_add"; + } else { + return null; + } + + action.actionArgument = { favoriteModel: favoriteModel, favoriteId: favoriteId }; + + return [action]; + + } else { + var actions = []; + + var linkedActivities = favoriteModel.linkedActivitiesFor(favoriteId); + + var activities = favoriteModel.activities.runningActivities; + + // Adding the item to link/unlink to all activities + + var linkedToAllActivities = + !(linkedActivities.indexOf(":global") === -1); + + actions.push({ + text : i18n("On All Activities"), + checkable : true, + + actionId : linkedToAllActivities ? + "_kicker_favorite_remove_from_activity" : + "_kicker_favorite_set_to_activity", + checked : linkedToAllActivities, + + actionArgument : { + favoriteModel: favoriteModel, + favoriteId: favoriteId, + favoriteActivity: "" + } + }); + + + // Adding items for each activity separately + + var addActivityItem = function(activityId, activityName) { + var linkedToThisActivity = + !(linkedActivities.indexOf(activityId) === -1); + + actions.push({ + text : activityName, + checkable : true, + checked : linkedToThisActivity && !linkedToAllActivities, + + actionId : + // If we are on all activities, and the user clicks just one + // specific activity, unlink from everything else + linkedToAllActivities ? "_kicker_favorite_set_to_activity" : + + // If we are linked to the current activity, just unlink from + // that single one + linkedToThisActivity ? "_kicker_favorite_remove_from_activity" : + + // Otherwise, link to this activity, but do not unlink from + // other ones + "_kicker_favorite_add_to_activity", + + actionArgument : { + favoriteModel : favoriteModel, + favoriteId : favoriteId, + favoriteActivity : activityId + } + }); + }; + + // Adding the item to link/unlink to the current activity + + addActivityItem(favoriteModel.activities.currentActivity, i18n("On the Current Activity")); + + actions.push({ + type: "separator", + actionId: "_kicker_favorite_separator" + }); + + // Adding the items for each activity + + activities.forEach(function(activityId) { + addActivityItem(activityId, favoriteModel.activityNameForId(activityId)); + }); + + return [{ + text : i18n("Show in Favorites"), + icon : "favorite", + subActions : actions + }]; + } +} + +function triggerAction(model, index, actionId, actionArgument) { + function startsWith(txt, needle) { + return txt.substr(0, needle.length) === needle; + } + + if (startsWith(actionId, "_kicker_favorite_")) { + handleFavoriteAction(actionId, actionArgument); + return; + } + + var closeRequested = model.trigger(index, actionId, actionArgument); + + if (closeRequested) { + return true; + } + + return false; +} + +function handleFavoriteAction(actionId, actionArgument) { + var favoriteId = actionArgument.favoriteId; + var favoriteModel = actionArgument.favoriteModel; + + console.log(actionId); + + if (favoriteModel === null || favoriteId == null) { + return null; + } + + if (actionId == "_kicker_favorite_remove") { + console.log("Removing from all activities"); + favoriteModel.removeFavorite(favoriteId); + } else if (actionId == "_kicker_favorite_add") { + console.log("Adding to global activity"); + favoriteModel.addFavorite(favoriteId); + } else if (actionId == "_kicker_favorite_remove_from_activity") { + console.log("Removing from a specific activity"); + favoriteModel.removeFavoriteFrom(favoriteId, actionArgument.favoriteActivity); + + } else if (actionId == "_kicker_favorite_add_to_activity") { + console.log("Adding to another activity"); + favoriteModel.addFavoriteTo(favoriteId, actionArgument.favoriteActivity); + + } else if (actionId == "_kicker_favorite_set_to_activity") { + console.log("Removing the item from the favourites, and re-adding it just to be on a specific activity"); + favoriteModel.setFavoriteOn(favoriteId, actionArgument.favoriteActivity); + + } +} diff --git a/contents/ui/qmldir b/contents/ui/qmldir new file mode 100644 index 0000000..a2ceb73 --- /dev/null +++ b/contents/ui/qmldir @@ -0,0 +1,2 @@ +singleton KickoffSingleton 1.0 KickoffSingleton.qml +singleton ActionMenu 1.0 ActionMenu.qml diff --git a/metadata.desktop b/metadata.desktop new file mode 100644 index 0000000..04a20f3 --- /dev/null +++ b/metadata.desktop @@ -0,0 +1,19 @@ +[Desktop Entry] +Name=Simple Application Launcher +Comment=A Simplified fork of Kickoff Application Launcher Menu + +Type=Service +Icon=start-here-kde +X-KDE-ServiceTypes=Plasma/Applet + +X-Plasma-API=declarativeappletscript +X-Plasma-MainScript=ui/Kickoff.qml +X-Plasma-Provides=org.kde.plasma.launchermenu +X-Plasma-RequiredExtensions=LaunchApp + +X-KDE-PluginInfo-Author=various +X-KDE-PluginInfo-Name=org.kde.plasma.simplekickoff +X-KDE-PluginInfo-Version=2.2 +X-KDE-PluginInfo-Category=Application Launchers +X-KDE-PluginInfo-License=GPL-2.0+ +X-KDE-PluginInfo-EnabledByDefault=true diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..c20ce27 --- /dev/null +++ b/metadata.json @@ -0,0 +1,135 @@ +{ + "KPlugin": { + "Authors": [ + { + "Email": "plasma-devel@kde.org", + "Name": "Martin Graesslin", + "Name[ar]": "Martin Graesslin", + "Name[az]": "Martin Graesslin", + "Name[ca@valencia]": "Martin Graesslin", + "Name[ca]": "Martin Graesslin", + "Name[cs]": "Martin Graesslin", + "Name[de]": "Martin Graesslin", + "Name[en_GB]": "Martin Graesslin", + "Name[es]": "Martin Graesslin", + "Name[eu]": "Martin Graesslin", + "Name[fi]": "Martin Graesslin", + "Name[fr]": "Martin Graesslin", + "Name[hu]": "Martin Graesslin", + "Name[ia]": "Martin Graesslin", + "Name[id]": "Martin Graesslin", + "Name[it]": "Martin Graesslin", + "Name[ko]": "Martin Graesslin", + "Name[lt]": "Martin Graesslin", + "Name[nl]": "Martin Graesslin", + "Name[nn]": "Martin Graesslin", + "Name[pl]": "Martin Graesslin", + "Name[pt_BR]": "Martin Graesslin", + "Name[ro]": "Martin Graesslin", + "Name[ru]": "Martin Graesslin", + "Name[sk]": "Martin Graesslin", + "Name[sl]": "Martin Graesslin", + "Name[sv]": "Martin Graesslin", + "Name[ta]": "மார்ட்டின் கிராஸ்லின்", + "Name[tr]": "Martin Graesslin", + "Name[uk]": "Martin Graesslin", + "Name[vi]": "Martin Graesslin", + "Name[x-test]": "xxMartin Graesslinxx", + "Name[zh_CN]": "Martin Graesslin" + }, + { + "Email": "mikel5764@gmail.com", + "Name": "Mikel Johnson", + "Name[ar]": "Mikel Johnson", + "Name[az]": "Mikel Johnson", + "Name[ca@valencia]": "Mikel Johnson", + "Name[ca]": "Mikel Johnson", + "Name[cs]": "Mikel Johnson", + "Name[de]": "Mikel Johnson", + "Name[en_GB]": "Mikel Johnson", + "Name[es]": "Mikel Johnson", + "Name[eu]": "Mikel Johnson", + "Name[fi]": "Mikel Johnson", + "Name[fr]": "Mikel Johnson", + "Name[hu]": "Mikel Johnson", + "Name[ia]": "Mikel Johnson", + "Name[id]": "Mikel Johnson", + "Name[it]": "Mikel Johnson", + "Name[ko]": "Mikel Johnson", + "Name[lt]": "Mikel Johnson", + "Name[nl]": "Mikel Johnson", + "Name[nn]": "Mikel Johnson", + "Name[pl]": "Mikel Johnson", + "Name[pt_BR]": "Mikel Johnson", + "Name[ro]": "Mikel Johnson", + "Name[ru]": "Mikel Johnson", + "Name[sk]": "Mikel Johnson", + "Name[sl]": "Mikel Johnson", + "Name[sv]": "Mikel Johnson", + "Name[ta]": "மிக்கேல் ஜான்ஸன்", + "Name[tr]": "Mikel Johnson", + "Name[uk]": "Mikel Johnson", + "Name[vi]": "Mikel Johnson", + "Name[x-test]": "xxMikel Johnsonxx", + "Name[zh_CN]": "Mikel Johnson" + }, + { + "Email": "himprakashd@gmail.com", + "Name": "Himprakash Deka" + } + ], + "Category": "Application Launchers", + "Description": "Launcher to start applications", + "Description[ar]": "مطلق لبدء التّطبيقات", + "Description[az]": "Tətbiqləri açmaq üçün başladıcı", + "Description[ca@valencia]": "Iniciador per a iniciar aplicacions", + "Description[ca]": "Llançador per a iniciar aplicacions", + "Description[cs]": "Aplikace pro spouštění aplikací", + "Description[de]": "Ermöglicht den Aufruf verschiedenster Programme", + "Description[en_GB]": "Launcher to start applications", + "Description[es]": "Lanzador para iniciar aplicaciones", + "Description[eu]": "Aplikazioak abiatzeko abiarazlea", + "Description[fi]": "Sovellusten käynnistysvalikko", + "Description[fr]": "Lanceur pour démarrer des applications", + "Description[hu]": "Alkalmazásindító", + "Description[ia]": "Lanceator pro initiar applicationes", + "Description[id]": "Peluncur untuk meluncurkan aplikasi", + "Description[it]": "Avviatore per far partire le applicazioni", + "Description[ko]": "프로그램을 시작하는 실행기", + "Description[lt]": "Programų paleidimo paleidyklė", + "Description[nl]": "Applet voor het starten van programma's", + "Description[nn]": "Moderne programstartar", + "Description[pa]": "ਐਪਲੀਕੇਸ਼ਨ ਚਲਾਉਣ ਲਈ ਲਾਂਚਰ", + "Description[pl]": "Uruchamiacz do uruchamiana programów", + "Description[pt_BR]": "Lançador para iniciar aplicativos", + "Description[ro]": "Lansator pentru a porni aplicații", + "Description[ru]": "Современное меню запуска приложений", + "Description[sk]": "Spúšťač na spúšťanie aplikácií", + "Description[sl]": "Zaganjalnik za zagon programov", + "Description[sv]": "Startprogram för att köra program", + "Description[ta]": "செயலிகளை துவக்க உதவும் ஏவி", + "Description[tr]": "Uygulamaları başlatmak için çalıştırıcı", + "Description[uk]": "Програма для запуску програм", + "Description[vi]": "Trình khởi chạy để khởi động ứng dụng", + "Description[x-test]": "xxLauncher to start applicationsxx", + "Description[zh_CN]": "应用程序启动器", + "EnabledByDefault": true, + "Icon": "start-here-kde", + "Id": "org.kde.plasma.simplekickoff", + "License": "GPL-2.0+", + "Name": "Simple Application Launcher", + "ServiceTypes": [ + "Plasma/Applet" + ], + "Version": "2.2", + "Website": "https://www.github.com/hide-techno-tips/simple-kickoff-for-plasma" + }, + "X-Plasma-API": "declarativeappletscript", + "X-Plasma-MainScript": "ui/Kickoff.qml", + "X-Plasma-Provides": [ + "org.kde.plasma.launchermenu" + ], + "X-Plasma-RequiredExtensions": [ + "LaunchApp" + ] +}