From 3f4915d426e10254e1bac750f9a5c111fc64ddcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= Date: Thu, 28 May 2020 15:58:27 +0200 Subject: [PATCH] Revert "Open and close StartupFeedback using KStartupInfo" This reverts commit b856b78790e4754642562613abcf55144c23edcb. Unfortunately it turned out not to work on Wayland yet. --- CMakeLists.txt | 1 - containments/homescreen/CMakeLists.txt | 2 +- .../homescreen/applicationlistmodel.cpp | 24 +------- .../homescreen/applicationlistmodel.h | 6 -- containments/homescreen/colouraverage.cpp | 58 +++++++++++++++++++ containments/homescreen/colouraverage.h | 32 ++++++++++ containments/homescreen/homescreen.cpp | 4 ++ .../package/contents/ui/launcher/Delegate.qml | 6 +- .../contents/ui/launcher/LauncherGrid.qml | 27 ++++----- .../contents/ui/quicksettings/Delegate.qml | 14 +++++ 10 files changed, 128 insertions(+), 46 deletions(-) create mode 100644 containments/homescreen/colouraverage.cpp create mode 100644 containments/homescreen/colouraverage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f803d562..ca71715d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,6 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS PlasmaQuick Service Notifications - WindowSystem ) find_package(KF5Wayland CONFIG) set_package_properties(KF5Wayland PROPERTIES diff --git a/containments/homescreen/CMakeLists.txt b/containments/homescreen/CMakeLists.txt index 7d4cb998..944cca6c 100644 --- a/containments/homescreen/CMakeLists.txt +++ b/containments/homescreen/CMakeLists.txt @@ -1,6 +1,7 @@ set(homescreen_SRCS homescreen.cpp applicationlistmodel.cpp + colouraverage.cpp ) add_library(plasma_containment_phone_homescreen MODULE ${homescreen_SRCS}) @@ -16,7 +17,6 @@ target_link_libraries(plasma_containment_phone_homescreen KF5::Service KF5::KIOGui KF5::Notifications - KF5::WindowSystem ) diff --git a/containments/homescreen/applicationlistmodel.cpp b/containments/homescreen/applicationlistmodel.cpp index 5f2bdfcf..6316558c 100644 --- a/containments/homescreen/applicationlistmodel.cpp +++ b/containments/homescreen/applicationlistmodel.cpp @@ -39,31 +39,12 @@ constexpr int MAX_FAVOURITES = 5; ApplicationListModel::ApplicationListModel(HomeScreen *parent) : QAbstractListModel(parent), - m_homeScreen(parent), - m_startupInfo(new KStartupInfo(0, this)) + m_homeScreen(parent) { connect(KSycoca::self(), qOverload(&KSycoca::databaseChanged), this, &ApplicationListModel::sycocaDbChanged); - connect(m_startupInfo, &KStartupInfo::gotRemoveStartup, - this, &ApplicationListModel::applicationExited); - - connect(m_startupInfo, &KStartupInfo::gotNewStartup, - this, [=](const KStartupInfoId &, const KStartupInfoData &data) { - applicationStarted(data.name(), data.icon()); - }); - loadSettings(); - - // Debug - connect(this, &ApplicationListModel::applicationStarted, this, [=](const QString &name, const QString &icon) { - qDebug() << "Opening startup feedback for" << name << icon; - }); - - connect(this, &ApplicationListModel::applicationExited, this, []() { - qDebug() << "Removing startup feedback"; - }); - } ApplicationListModel::~ApplicationListModel() = default; @@ -135,8 +116,7 @@ void ApplicationListModel::loadApplications() m_applicationList.clear(); KServiceGroup::Ptr group = KServiceGroup::root(); - if (!group || !group->isValid()) - return; + if (!group || !group->isValid()) return; KServiceGroup::List subGroupList = group->entries(true); QMap orderedList; diff --git a/containments/homescreen/applicationlistmodel.h b/containments/homescreen/applicationlistmodel.h index 12721eec..f33d3fd3 100644 --- a/containments/homescreen/applicationlistmodel.h +++ b/containments/homescreen/applicationlistmodel.h @@ -26,9 +26,6 @@ #include #include -// KDE -#include - #include "homescreen.h" class QString; @@ -105,8 +102,6 @@ Q_SIGNALS: void countChanged(); void favoriteCountChanged(); void maxFavoriteCountChanged(); - void applicationStarted(const QString &name, const QString &icon); - void applicationExited(); private: QList m_applicationList; @@ -117,7 +112,6 @@ private: QStringList m_favorites; QSet m_desktopItems; QHash m_appPositions; - KStartupInfo *m_startupInfo; }; #endif // APPLICATIONLISTMODEL_H diff --git a/containments/homescreen/colouraverage.cpp b/containments/homescreen/colouraverage.cpp new file mode 100644 index 00000000..1e269ed0 --- /dev/null +++ b/containments/homescreen/colouraverage.cpp @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2019 Carson Black * + * * + * 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 . * + ***************************************************************************/ + +#include +#include +#include +#include + +#include "colouraverage.h" + +ColourAverage::ColourAverage(QObject *parent) : QObject(parent) +{ +} + +QColor ColourAverage::averageColour(const QImage &img) { + int r = 0; + int g = 0; + int b = 0; + int c = 0; + + for (int i = 0; i < img.width(); i++) { + for (int ii = 0; ii < img.height(); ii++) { + QRgb pix = img.pixel(i, ii); + if (pix == 0) + continue; + + c++; + r += qRed(pix); + g += qGreen(pix); + b += qBlue(pix); + } + } + r = r / c; + g = g / c; + b = b / c; + + QColor color = QColor::fromRgb(r,g,b); + + color.setHsv(color.hue(), color.saturation() / 4, color.value()); + + return color; +} diff --git a/containments/homescreen/colouraverage.h b/containments/homescreen/colouraverage.h new file mode 100644 index 00000000..0d15f53b --- /dev/null +++ b/containments/homescreen/colouraverage.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * Copyright (C) 2019 Carson Black * + * * + * 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 . * + ***************************************************************************/ +#pragma once + +#include +#include +#include + +class ColourAverage : public QObject +{ + Q_OBJECT + +public: + explicit ColourAverage(QObject *parent = nullptr); + Q_INVOKABLE QColor averageColour(const QImage &img); +}; diff --git a/containments/homescreen/homescreen.cpp b/containments/homescreen/homescreen.cpp index 343695fb..318b0e8c 100644 --- a/containments/homescreen/homescreen.cpp +++ b/containments/homescreen/homescreen.cpp @@ -19,6 +19,7 @@ #include "homescreen.h" #include "applicationlistmodel.h" +#include "colouraverage.h" #include #include @@ -28,6 +29,9 @@ HomeScreen::HomeScreen(QObject *parent, const QVariantList &args) : Plasma::Containment(parent, args) { qmlRegisterUncreatableType("org.kde.phone.homescreen", 1, 0, "ApplicationListModel", QStringLiteral("Cannot create item of type ApplicationListModel")); + qmlRegisterSingletonType("org.kde.phone.homescreen", 1, 0, "ColourAverage", [](QQmlEngine *, QJSEngine *) -> QObject * { + return new ColourAverage(); + }); setHasConfigurationInterface(true); } diff --git a/containments/homescreen/package/contents/ui/launcher/Delegate.qml b/containments/homescreen/package/contents/ui/launcher/Delegate.qml index 9af9508e..85f39c12 100644 --- a/containments/homescreen/package/contents/ui/launcher/Delegate.qml +++ b/containments/homescreen/package/contents/ui/launcher/Delegate.qml @@ -92,7 +92,11 @@ ContainmentLayoutManager.ItemContainer { } contentItem: MouseArea { - onClicked: plasmoid.nativeInterface.applicationListModel.runApplication(modelData.applicationStorageId); + onClicked: { + delegate.launch(delegate.x + (units.smallSpacing * 2), delegate.y + (units.smallSpacing * 2), icon.source, modelData.applicationName) + + plasmoid.nativeInterface.applicationListModel.runApplication(modelData.applicationStorageId); + } //preventStealing: true ColumnLayout { diff --git a/containments/homescreen/package/contents/ui/launcher/LauncherGrid.qml b/containments/homescreen/package/contents/ui/launcher/LauncherGrid.qml index 44035da7..4b751456 100644 --- a/containments/homescreen/package/contents/ui/launcher/LauncherGrid.qml +++ b/containments/homescreen/package/contents/ui/launcher/LauncherGrid.qml @@ -24,7 +24,7 @@ import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 -import org.kde.kirigami 2.13 as Kirigami +import org.kde.kirigami 2.10 as Kirigami import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager import org.kde.plasma.private.nanoshell 2.0 as NanoShell @@ -41,20 +41,6 @@ LauncherContainer { frame.width: width - Connections { - target: plasmoid.nativeInterface.applicationListModel - onApplicationExited: NanoShell.StartupFeedback.close() - onApplicationStarted: (name, icon) => { - NanoShell.StartupFeedback.open( - icon, - name, - root.width * 0.5, - root.height * 0.5, - root.width * 0.2 - ); - } - } - Repeater { parent: root.flow model: plasmoid.nativeInterface.applicationListModel @@ -79,6 +65,17 @@ LauncherContainer { appletsLayout.restoreItem(delegate); } } + onLaunch: (x, y, icon, title) => { + delegate.grabToImage((img) => { + NanoShell.StartupFeedback.open( + icon, + title, + delegate.iconItem.Kirigami.ScenePosition.x + delegate.iconItem.width/2, + delegate.iconItem.Kirigami.ScenePosition.y + delegate.iconItem.height/2, + Math.min(delegate.iconItem.width, delegate.iconItem.height), + ColourAverage.averageColour(img.image)); + }); + } onParentFromLocationChanged: { if (!launcherDragManager.active && parent != parentFromLocation) { parent = parentFromLocation; diff --git a/containments/panel/package/contents/ui/quicksettings/Delegate.qml b/containments/panel/package/contents/ui/quicksettings/Delegate.qml index 39cf2296..339f5265 100644 --- a/containments/panel/package/contents/ui/quicksettings/Delegate.qml +++ b/containments/panel/package/contents/ui/quicksettings/Delegate.qml @@ -58,6 +58,13 @@ ColumnLayout { } else if (model.toggleFunction) { root[model.toggleFunction](); } else if (model.settingsCommand) { + NanoShell.StartupFeedback.open( + model.icon, + model.text, + icon.Kirigami.ScenePosition.x + icon.width/2, + icon.Kirigami.ScenePosition.y + icon.height/2, + Math.min(icon.width, icon.height), + theme.textColor); plasmoid.nativeInterface.executeCommand(model.settingsCommand); root.closeRequested(); } @@ -98,6 +105,13 @@ ColumnLayout { anchors.fill: parent onClicked: { if (model.settingsCommand) { + NanoShell.StartupFeedback.open( + model.icon, + model.text, + icon.Kirigami.ScenePosition.x + icon.width/2, + icon.Kirigami.ScenePosition.y + icon.height/2, + Math.min(icon.width, icon.height), + theme.textColor); //plasmoid.nativeInterface.executeCommand(model.settingsCommand); closeRequested(); } else if (model.toggleFunction) {