mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
mobileshell: Refactor and collapse stackBefore and stackAfter into ShellUtil
This commit is contained in:
parent
c55500fba0
commit
3969973e51
11 changed files with 74 additions and 105 deletions
|
|
@ -17,7 +17,6 @@ set(mobileshellplugin_SRCS
|
|||
notifications/notificationfilemenu.cpp
|
||||
homescreen/applicationlistmodel.cpp
|
||||
homescreen/favoritesmodel.cpp
|
||||
homescreen/homescreenutils.cpp
|
||||
taskswitcher/displaysmodel.cpp
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@
|
|||
#include <QAbstractListModel>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QQuickItem>
|
||||
#include <QSet>
|
||||
|
||||
#include "homescreenutils.h"
|
||||
|
||||
class QString;
|
||||
|
||||
namespace KWayland
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
#include <QSet>
|
||||
|
||||
#include "applicationlistmodel.h"
|
||||
#include "homescreenutils.h"
|
||||
|
||||
class QString;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2021 Marco Martin <mart@kde.org>
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "homescreenutils.h"
|
||||
#include "favoritesmodel.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QQuickItem>
|
||||
#include <QtQml>
|
||||
|
||||
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"
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2021 Marco Martin <mart@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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;
|
||||
};
|
||||
|
|
@ -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<FavoritesModel>(uri, 1, 0, "FavoritesModel", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
||||
return FavoritesModel::instance();
|
||||
});
|
||||
qmlRegisterSingletonType<HomeScreenUtils>(uri, 1, 0, "HomeScreenUtils", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
||||
return HomeScreenUtils::instance();
|
||||
});
|
||||
|
||||
// notifications
|
||||
qmlRegisterType<NotificationThumbnailer>(uri, 1, 0, "NotificationThumbnailer");
|
||||
|
|
|
|||
|
|
@ -8,10 +8,6 @@
|
|||
|
||||
#include "shellutil.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <qplatformdefs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <KConfigGroup>
|
||||
#include <KIO/ApplicationLauncherJob>
|
||||
#include <KLocalizedString>
|
||||
|
|
@ -21,11 +17,7 @@
|
|||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QGuiApplication>
|
||||
#include <QProcess>
|
||||
#include <QScreen>
|
||||
#include <QStandardPaths>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#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;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
|
||||
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
|
||||
* SPDX-FileCopyrightText: 2021-2022 Devin Lin <devin@kde.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
|
@ -8,10 +8,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QQuickItem>
|
||||
|
||||
#include <KConfigWatcher>
|
||||
#include <KSharedConfig>
|
||||
|
||||
/**
|
||||
* Miscellaneous class to put utility functions used in the shell.
|
||||
*
|
||||
* @author Devin Lin <devin@kde.org>
|
||||
**/
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2014 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
|
||||
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
|
@ -18,6 +19,11 @@
|
|||
#include <KWayland/Client/registry.h>
|
||||
#include <KWayland/Client/surface.h>
|
||||
|
||||
/**
|
||||
* Utility class that provides useful functions related to windows and KWin+KWayland.
|
||||
*
|
||||
* @author Devin Lin <devin@kde.org>
|
||||
**/
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue