From 24c383d98a5f27d8fcf37c3e5b532d526b143f8d Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sat, 1 Dec 2018 15:33:11 +0200 Subject: [PATCH] refactor:screens from dock to universalSettings --- app/dock/dockview.cpp | 17 ----------------- app/dock/dockview.h | 8 -------- app/universalsettings.cpp | 17 +++++++++++++++++ app/universalsettings.h | 9 +++++++++ .../contents/configuration/BehaviorConfig.qml | 10 +++++----- 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/app/dock/dockview.cpp b/app/dock/dockview.cpp index aad5958cc..a0b3639b1 100644 --- a/app/dock/dockview.cpp +++ b/app/dock/dockview.cpp @@ -306,23 +306,6 @@ void DockView::removeDock() } } -QQmlListProperty DockView::screens() -{ - return QQmlListProperty(this, nullptr, &countScreens, &atScreens); -} - -int DockView::countScreens(QQmlListProperty *property) -{ - Q_UNUSED(property) - return qGuiApp->screens().count(); -} - -QScreen *DockView::atScreens(QQmlListProperty *property, int index) -{ - Q_UNUSED(property) - return qGuiApp->screens().at(index); -} - bool DockView::settingsWindowIsShown() { auto configView = qobject_cast(m_configView); diff --git a/app/dock/dockview.h b/app/dock/dockview.h index 758c22859..3b03e0a5f 100644 --- a/app/dock/dockview.h +++ b/app/dock/dockview.h @@ -33,7 +33,6 @@ #include #include -#include #include #include #include @@ -91,8 +90,6 @@ class DockView : public PlasmaQuick::ContainmentView Q_PROPERTY(Latte::View::Positioner *positioner READ positioner NOTIFY positionerChanged) Q_PROPERTY(VisibilityManager *visibility READ visibility NOTIFY visibilityChanged) - Q_PROPERTY(QQmlListProperty screens READ screens) - Q_PROPERTY(QRect absoluteGeometry READ absGeometry NOTIFY absGeometryChanged) Q_PROPERTY(QRect localGeometry READ localGeometry WRITE setLocalGeometry NOTIFY localGeometryChanged) Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged) @@ -167,11 +164,6 @@ public: KWayland::Client::PlasmaShellSurface *surface(); void reconsiderScreen(); - QQmlListProperty screens(); - //! is needed by screens() - static int countScreens(QQmlListProperty *property); - //! is needed by screens() - static QScreen *atScreens(QQmlListProperty *property, int index); //! these are signals that create crashes, such a example is the availableScreenRectChanged from corona //! when its containment is destroyed diff --git a/app/universalsettings.cpp b/app/universalsettings.cpp index 4c8c0eab5..5312d2bc8 100644 --- a/app/universalsettings.cpp +++ b/app/universalsettings.cpp @@ -550,4 +550,21 @@ float UniversalSettings::luminasFromFile(QString imageFile, int edge) return m_runningActivitiesModel->luminasFromFile(imageFile, edge); } +QQmlListProperty UniversalSettings::screens() +{ + return QQmlListProperty(this, nullptr, &countScreens, &atScreens); +} + +int UniversalSettings::countScreens(QQmlListProperty *property) +{ + Q_UNUSED(property) + return qGuiApp->screens().count(); +} + +QScreen *UniversalSettings::atScreens(QQmlListProperty *property, int index) +{ + Q_UNUSED(property) + return qGuiApp->screens().at(index); +} + } diff --git a/app/universalsettings.h b/app/universalsettings.h index f5bf0efb6..b9bc80eac 100644 --- a/app/universalsettings.h +++ b/app/universalsettings.h @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include @@ -54,6 +56,9 @@ class UniversalSettings : public QObject Q_PROPERTY(Latte::Dock::MouseSensitivity mouseSensitivity READ mouseSensitivity WRITE setMouseSensitivity NOTIFY mouseSensitivityChanged) Q_PROPERTY(QAbstractItemModel *runningActivitiesModel READ runningActivitiesModel NOTIFY runningActivitiesModelChanged) + + Q_PROPERTY(QQmlListProperty screens READ screens) + public: UniversalSettings(KSharedConfig::Ptr config, QObject *parent = nullptr); ~UniversalSettings() override; @@ -104,6 +109,10 @@ public: QAbstractItemModel *runningActivitiesModel() const; void setRunningActivitiesModel(SortedActivitiesModel *model); + QQmlListProperty screens(); + static int countScreens(QQmlListProperty *property); //! is needed by screens() + static QScreen *atScreens(QQmlListProperty *property, int index); //! is needed by screens() + public slots: Q_INVOKABLE QString splitterIconPath(); Q_INVOKABLE QString trademarkIconPath(); diff --git a/shell/package/contents/configuration/BehaviorConfig.qml b/shell/package/contents/configuration/BehaviorConfig.qml index a7b930981..1e462890d 100644 --- a/shell/package/contents/configuration/BehaviorConfig.qml +++ b/shell/package/contents/configuration/BehaviorConfig.qml @@ -85,7 +85,7 @@ PlasmaComponents.Page { visible: true function updateScreens() { - if (dock.screens.length > 1) + if (universalSettings.screens.length > 1) screenRow.visible = true; else screenRow.visible = false; @@ -99,16 +99,16 @@ PlasmaComponents.Page { //the dock automatically to primaryScreen in order for the user //to has always a dock with tasks shown var screenExists = false - for (var i = 0; i < dock.screens.length; i++) { - if (dock.screens[i].name === dock.positioner.currentScreenName) + for (var i = 0; i < universalSettings.screens.length; i++) { + if (universalSettings.screens[i].name === dock.positioner.currentScreenName) screenExists = true; } if (!screenExists && !dock.onPrimary) screens.push(rtlSpace + dock.positioner.currentScreenName); - for (var i = 0; i < dock.screens.length; i++) { - screens.push(rtlSpace + dock.screens[i].name) + for (var i = 0; i < universalSettings.screens.length; i++) { + screens.push(rtlSpace + universalSettings.screens[i].name) } screenCmb.model = screens;