Commit 2deea1b4 authored by Devin Lin's avatar Devin Lin 🎨
Browse files

components: Port Direction enum to c++ to improve load times

According to flame graph testing with qmlprofiler, this caused quite some overhead in QML.
parent 2d6d0c67
......@@ -13,6 +13,7 @@ set(mobileshellplugin_SRCS
savedquicksettingsmodel.cpp
shellutil.cpp
windowutil.cpp
components/direction.cpp
notifications/notificationthumbnailer.cpp
notifications/notificationfilemenu.cpp
homescreen/applicationlistmodel.cpp
......
/*
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "direction.h"
/*
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QObject>
class Direction : public QObject
{
Q_OBJECT
public:
enum Type { None = 0, Up, Down, Left, Right };
Q_ENUM(Type)
};
......@@ -9,6 +9,8 @@
#include <QQmlContext>
#include <QQuickItem>
#include "components/direction.h"
#include "notifications/notificationfilemenu.h"
#include "notifications/notificationthumbnailer.h"
......@@ -48,8 +50,8 @@ void MobileShellPlugin::registerTypes(const char *uri)
return WindowUtil::instance();
});
// taskswitcher
qmlRegisterType<DisplaysModel>(uri, 1, 0, "DisplaysModel");
// components
qmlRegisterType<Direction>(uri, 1, 0, "Direction");
// homescreen
qmlRegisterSingletonType<ApplicationListModel>(uri, 1, 0, "ApplicationListModel", [](QQmlEngine *, QJSEngine *) -> QObject * {
......@@ -63,6 +65,9 @@ void MobileShellPlugin::registerTypes(const char *uri)
qmlRegisterType<NotificationThumbnailer>(uri, 1, 0, "NotificationThumbnailer");
qmlRegisterType<NotificationFileMenu>(uri, 1, 0, "NotificationFileMenu");
// taskswitcher
qmlRegisterType<DisplaysModel>(uri, 1, 0, "DisplaysModel");
// qml modules
// /actiondrawer
......@@ -72,7 +77,6 @@ void MobileShellPlugin::registerTypes(const char *uri)
// /components
qmlRegisterType(resolvePath("components/BaseItem.qml"), uri, 1, 0, "BaseItem");
qmlRegisterType(resolvePath("components/Direction.qml"), uri, 1, 0, "Direction");
qmlRegisterType(resolvePath("components/StartupFeedback.qml"), uri, 1, 0, "StartupFeedback");
qmlRegisterType(resolvePath("components/VelocityCalculator.qml"), uri, 1, 0, "VelocityCalculator");
......
......@@ -15,8 +15,6 @@ import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import "../components" as Components
Item {
id: root
......@@ -60,7 +58,7 @@ Item {
/**
* Direction the panel is currently moving in.
*/
property int direction: Components.Direction.None
property int direction: MobileShell.Direction.None
/**
* The mode of the action drawer (portrait or landscape).
......@@ -111,8 +109,8 @@ Item {
offset = 0;
}
root.direction = (oldOffset === offset)
? Components.Direction.None
: (offset > oldOffset ? Components.Direction.Down : Components.Direction.Up);
? MobileShell.Direction.None
: (offset > oldOffset ? MobileShell.Direction.Down : MobileShell.Direction.Up);
oldOffset = offset;
......@@ -152,7 +150,7 @@ Item {
// close immediately, so that we don't have to wait PlasmaCore.Units.longDuration
root.visible = false;
close();
} else if (root.direction === Components.Direction.None || !root.opened) {
} else if (root.direction === MobileShell.Direction.None || !root.opened) {
if (root.offset < openThreshold) {
close();
} else {
......@@ -161,12 +159,12 @@ Item {
} else if (root.offset > contentContainerLoader.maximizedQuickSettingsOffset) {
expand();
} else if (root.offset > contentContainerLoader.minimizedQuickSettingsOffset) {
if (root.direction === Components.Direction.Down) {
if (root.direction === MobileShell.Direction.Down) {
expand();
} else {
open();
}
} else if (root.direction === Components.Direction.Down) {
} else if (root.direction === MobileShell.Direction.Down) {
open();
} else {
close();
......
/*
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
QtObject {
enum Type {
None = 0,
Up,
Down,
Left,
Right
}
}
......@@ -21,7 +21,6 @@
<file>qml/actiondrawer/PortraitContentContainer.qml</file>
<file>qml/components/BaseItem.qml</file>
<file>qml/components/Direction.qml</file>
<file>qml/components/StartupFeedback.qml</file>
<file>qml/components/util.js</file>
<file>qml/components/VelocityCalculator.qml</file>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment