diff --git a/components/mobileshell/CMakeLists.txt b/components/mobileshell/CMakeLists.txt index e8821856..d5d0af64 100644 --- a/components/mobileshell/CMakeLists.txt +++ b/components/mobileshell/CMakeLists.txt @@ -17,7 +17,6 @@ set(mobileshellplugin_SRCS notifications/notificationfilemenu.cpp homescreen/applicationlistmodel.cpp homescreen/favoritesmodel.cpp - homescreen/homescreenutils.cpp taskswitcher/displaysmodel.cpp ) diff --git a/components/mobileshell/homescreen/applicationlistmodel.h b/components/mobileshell/homescreen/applicationlistmodel.h index 570f7cea..fa610ecd 100644 --- a/components/mobileshell/homescreen/applicationlistmodel.h +++ b/components/mobileshell/homescreen/applicationlistmodel.h @@ -11,10 +11,9 @@ #include #include #include +#include #include -#include "homescreenutils.h" - class QString; namespace KWayland diff --git a/components/mobileshell/homescreen/favoritesmodel.h b/components/mobileshell/homescreen/favoritesmodel.h index d63c8657..2fa5f00b 100644 --- a/components/mobileshell/homescreen/favoritesmodel.h +++ b/components/mobileshell/homescreen/favoritesmodel.h @@ -13,7 +13,6 @@ #include #include "applicationlistmodel.h" -#include "homescreenutils.h" class QString; diff --git a/components/mobileshell/homescreen/homescreenutils.cpp b/components/mobileshell/homescreen/homescreenutils.cpp deleted file mode 100644 index b10d1306..00000000 --- a/components/mobileshell/homescreen/homescreenutils.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - SPDX-FileCopyrightText: 2021 Marco Martin - SPDX-License-Identifier: GPL-2.0-or-later - */ - -#include "homescreenutils.h" -#include "favoritesmodel.h" - -#include -#include -#include - -HomeScreenUtils::HomeScreenUtils(QObject *parent) - : QObject(parent) -{ -} - -HomeScreenUtils::~HomeScreenUtils() = default; - -void HomeScreenUtils::stackBefore(QQuickItem *item1, QQuickItem *item2) -{ - if (!item1 || !item2 || item1 == item2 || item1->parentItem() != item2->parentItem()) { - return; - } - - item1->stackBefore(item2); -} - -void HomeScreenUtils::stackAfter(QQuickItem *item1, QQuickItem *item2) -{ - if (!item1 || !item2 || item1 == item2 || item1->parentItem() != item2->parentItem()) { - return; - } - - item1->stackAfter(item2); -} - -#include "moc_homescreenutils.cpp" diff --git a/components/mobileshell/homescreen/homescreenutils.h b/components/mobileshell/homescreen/homescreenutils.h deleted file mode 100644 index efaebc15..00000000 --- a/components/mobileshell/homescreen/homescreenutils.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - SPDX-FileCopyrightText: 2021 Marco Martin - - SPDX-License-Identifier: GPL-2.0-or-later - */ - -#pragma once - -#include - -class QQuickItem; -class FavoritesModel; - -class HomeScreenUtils : public QObject -{ - Q_OBJECT - -public: - HomeScreenUtils(QObject *parent = 0); - ~HomeScreenUtils() override; - - static HomeScreenUtils *instance() - { - static HomeScreenUtils *model = new HomeScreenUtils; - return model; - } - - Q_INVOKABLE void stackBefore(QQuickItem *item1, QQuickItem *item2); - Q_INVOKABLE void stackAfter(QQuickItem *item1, QQuickItem *item2); - -protected: - // void configChanged() override; - -private: - bool m_showAllApps = false; -}; diff --git a/components/mobileshell/mobileshellplugin.cpp b/components/mobileshell/mobileshellplugin.cpp index 8f2b725f..8360811f 100644 --- a/components/mobileshell/mobileshellplugin.cpp +++ b/components/mobileshell/mobileshellplugin.cpp @@ -14,7 +14,6 @@ #include "homescreen/applicationlistmodel.h" #include "homescreen/favoritesmodel.h" -#include "homescreen/homescreenutils.h" #include "taskswitcher/displaysmodel.h" @@ -59,9 +58,6 @@ void MobileShellPlugin::registerTypes(const char *uri) qmlRegisterSingletonType(uri, 1, 0, "FavoritesModel", [](QQmlEngine *, QJSEngine *) -> QObject * { return FavoritesModel::instance(); }); - qmlRegisterSingletonType(uri, 1, 0, "HomeScreenUtils", [](QQmlEngine *, QJSEngine *) -> QObject * { - return HomeScreenUtils::instance(); - }); // notifications qmlRegisterType(uri, 1, 0, "NotificationThumbnailer"); diff --git a/components/mobileshell/shellutil.cpp b/components/mobileshell/shellutil.cpp index aa41f75c..4438f99a 100644 --- a/components/mobileshell/shellutil.cpp +++ b/components/mobileshell/shellutil.cpp @@ -8,10 +8,6 @@ #include "shellutil.h" -#include -#include -#include - #include #include #include @@ -21,11 +17,7 @@ #include #include #include -#include #include -#include -#include -#include #define FORMAT24H "HH:mm:ss" @@ -45,14 +37,30 @@ ShellUtil::ShellUtil(QObject *parent) }); } -ShellUtil::~ShellUtil() = default; - ShellUtil *ShellUtil::instance() { static ShellUtil *inst = new ShellUtil(nullptr); return inst; } +void ShellUtil::stackItemBefore(QQuickItem *item1, QQuickItem *item2) +{ + if (!item1 || !item2 || item1 == item2 || item1->parentItem() != item2->parentItem()) { + return; + } + + item1->stackBefore(item2); +} + +void ShellUtil::stackItemAfter(QQuickItem *item1, QQuickItem *item2) +{ + if (!item1 || !item2 || item1 == item2 || item1->parentItem() != item2->parentItem()) { + return; + } + + item1->stackAfter(item2); +} + void ShellUtil::executeCommand(const QString &command) { qWarning() << "Executing" << command; diff --git a/components/mobileshell/shellutil.h b/components/mobileshell/shellutil.h index 6b1d3093..5ee3cf4e 100644 --- a/components/mobileshell/shellutil.h +++ b/components/mobileshell/shellutil.h @@ -1,6 +1,6 @@ /* * SPDX-FileCopyrightText: 2015 Marco Martin - * SPDX-FileCopyrightText: 2021 Devin Lin + * SPDX-FileCopyrightText: 2021-2022 Devin Lin * * SPDX-License-Identifier: GPL-2.0-or-later */ @@ -8,10 +8,16 @@ #pragma once #include +#include #include #include +/** + * Miscellaneous class to put utility functions used in the shell. + * + * @author Devin Lin + **/ class ShellUtil : public QObject { Q_OBJECT @@ -19,14 +25,42 @@ class ShellUtil : public QObject public: ShellUtil(QObject *parent = nullptr); - ~ShellUtil() override; static ShellUtil *instance(); -public Q_SLOTS: - void executeCommand(const QString &command); - void launchApp(const QString &app); + /** + * Change the stacking order to have the first item behind the second item. + * + * @param item1 The item to move behind. + * @param item2 The item to move in front. + */ + Q_INVOKABLE void stackItemBefore(QQuickItem *item1, QQuickItem *item2); - bool isSystem24HourFormat(); + /** + * Change the stacking order to have the first item in front of the second item. + * + * @param item1 The item to move in front. + * @param item2 The item to move behind. + */ + Q_INVOKABLE void stackItemAfter(QQuickItem *item1, QQuickItem *item2); + + /** + * Execute the command given. + * + * @param command The command to execute. + */ + Q_INVOKABLE void executeCommand(const QString &command); + + /** + * Launch an application by name. + * + * @param app The name of the application to launch. + */ + Q_INVOKABLE void launchApp(const QString &app); + + /** + * Whether the system is using 24 hour format. + */ + Q_INVOKABLE bool isSystem24HourFormat(); Q_SIGNALS: void isSystem24HourFormatChanged(); diff --git a/components/mobileshell/windowutil.h b/components/mobileshell/windowutil.h index 260c02b4..76bf19e7 100644 --- a/components/mobileshell/windowutil.h +++ b/components/mobileshell/windowutil.h @@ -1,4 +1,5 @@ /* + * SPDX-FileCopyrightText: 2014 Antonis Tsiapaliokas * SPDX-FileCopyrightText: 2022 Devin Lin * * SPDX-License-Identifier: GPL-2.0-or-later @@ -18,6 +19,11 @@ #include #include +/** + * Utility class that provides useful functions related to windows and KWin+KWayland. + * + * @author Devin Lin + **/ class WindowUtil : public QObject { Q_OBJECT @@ -64,6 +70,8 @@ public: /** * Toggle whether we are in the "desktop showing" mode. + * + * @param showingDesktop Whether "desktop showing" mode should be enabled. */ Q_INVOKABLE void requestShowingDesktop(bool showingDesktop); diff --git a/containments/homescreen/package/contents/ui/LauncherDragManager.qml b/containments/homescreen/package/contents/ui/LauncherDragManager.qml index 968e9c05..e84c6afc 100644 --- a/containments/homescreen/package/contents/ui/LauncherDragManager.qml +++ b/containments/homescreen/package/contents/ui/LauncherDragManager.qml @@ -93,9 +93,9 @@ Item { var pos = container.flow.mapFromItem(item, dragCenterX, dragCenterY); if (pos.x < child.x + child.width / 2) { - MobileShell.HomeScreenUtils.stackBefore(spacer, child); + MobileShell.ShellUtil.stackItemBefore(spacer, child); } else { - MobileShell.HomeScreenUtils.stackAfter(spacer, child); + MobileShell.ShellUtil.stackItemAfter(spacer, child); } internal.putItemInDragSpace(item); @@ -129,9 +129,9 @@ Item { spacer.parent = container.flow if (pos.x < child.x + child.width / 2) { - MobileShell.HomeScreenUtils.stackBefore(spacer, child); + MobileShell.ShellUtil.stackItemBefore(spacer, child); } else { - MobileShell.HomeScreenUtils.stackAfter(spacer, child); + MobileShell.ShellUtil.stackItemAfter(spacer, child); } spacer.visible = true; @@ -296,7 +296,7 @@ Item { var child = nearestChild(item, dragCenterX, dragCenterY, container); putInContainerLayout(item, container); - MobileShell.HomeScreenUtils.stackBefore(item, spacer); + MobileShell.ShellUtil.stackItemBefore(item, spacer); spacer.visible = false; spacer.parent = root; } diff --git a/containments/homescreen/package/contents/ui/LauncherRepeater.qml b/containments/homescreen/package/contents/ui/LauncherRepeater.qml index a9cfad38..9ba66537 100644 --- a/containments/homescreen/package/contents/ui/LauncherRepeater.qml +++ b/containments/homescreen/package/contents/ui/LauncherRepeater.qml @@ -116,10 +116,10 @@ Repeater { if (!launcherDragManager.active && parent != parentFromLocation) { parent = parentFromLocation; if (model.applicationLocation === MobileShell.ApplicationListModel.Favorites) { - MobileShell.HomeScreenUtils.stackBefore(delegate, parentFromLocation.children[index]); + MobileShell.ShellUtil.stackItemBefore(delegate, parentFromLocation.children[index]); } else if (model.applicationLocation === MobileShell.ApplicationListModel.Grid) { - MobileShell.HomeScreenUtils.stackBefore(delegate, parentFromLocation.children[Math.max(0, index - MobileShell.ApplicationListModel.favoriteCount)]); + MobileShell.ShellUtil.stackItemBefore(delegate, parentFromLocation.children[Math.max(0, index - MobileShell.ApplicationListModel.favoriteCount)]); } } }