From d9bf1a85589c94f778be6586c0b68402147a68a8 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Sun, 12 Dec 2021 21:56:37 +0100 Subject: [PATCH] Refactor monitor list model to no longer contain QScreen* This is because we no longer use QScreen data because of wrong informations when using scaling with width and height. Also most of the member where not in use anyways because of always empty strings in members like manufacturer. --- ScreenPlay/qml/Monitors/MonitorSelection.qml | 24 ++------- .../qml/Monitors/MonitorSelectionItem.qml | 15 +++--- ScreenPlay/src/monitorlistmodel.cpp | 49 +++++-------------- ScreenPlay/src/monitorlistmodel.h | 23 +++------ 4 files changed, 31 insertions(+), 80 deletions(-) diff --git a/ScreenPlay/qml/Monitors/MonitorSelection.qml b/ScreenPlay/qml/Monitors/MonitorSelection.qml index b6ca8212..8c82e595 100644 --- a/ScreenPlay/qml/Monitors/MonitorSelection.qml +++ b/ScreenPlay/qml/Monitors/MonitorSelection.qml @@ -62,7 +62,7 @@ Rectangle { } function resize() { - var absoluteDesktopSize = ScreenPlay.monitorListModel.getAbsoluteDesktopSize(); + var absoluteDesktopSize = ScreenPlay.monitorListModel.absoluteDesktopSize(); var isWidthGreaterThanHeight = false; var windowsDelta = 0; if (absoluteDesktopSize.width < absoluteDesktopSize.height) { @@ -135,18 +135,10 @@ Rectangle { delegate: MonitorSelectionItem { id: delegate - monitorID: m_monitorID - monitorName: m_name appID: m_appID - height: m_availableGeometry.height - width: m_availableGeometry.width - x: m_availableGeometry.x - y: m_availableGeometry.y - monitorManufacturer: m_manufacturer - monitorModel: m_model - monitorSize: m_availableGeometry + geometry: m_geometry fontSize: root.fontSize - index: m_number + index: m_index previewImage: m_previewImage installedType: m_installedType monitorWithoutContentSelectable: root.monitorWithoutContentSelectable @@ -167,15 +159,5 @@ Rectangle { } -// layer.effect: InnerShadow { -// cached: true -// fast: true -// smooth: true -// radius: 32 -// spread: 0.8 -// verticalOffset: 3 -// color: "#55000000" -// } - // Width of the Sidebar or Space that should be used } diff --git a/ScreenPlay/qml/Monitors/MonitorSelectionItem.qml b/ScreenPlay/qml/Monitors/MonitorSelectionItem.qml index d33f044c..2204dbf2 100644 --- a/ScreenPlay/qml/Monitors/MonitorSelectionItem.qml +++ b/ScreenPlay/qml/Monitors/MonitorSelectionItem.qml @@ -7,11 +7,14 @@ import ScreenPlay.Enums.InstalledType 1.0 Item { id: root - property rect monitorSize: Qt.rect(0, 0, 0, 0) - property string monitorModel - property string monitorManufacturer - property string monitorName - property string monitorID + property rect geometry + onGeometryChanged: { + root.width = geometry.width + root.height = geometry.height + root.x = geometry.x + root.y = geometry.y + } + property string previewImage property string appID property var installedType: InstalledType.QMLWallpaper @@ -34,7 +37,7 @@ Item { } Text { - text: monitorSize.width + "x" + monitorSize.height + text: geometry.width + "x" + geometry.height color: Material.foreground horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter diff --git a/ScreenPlay/src/monitorlistmodel.cpp b/ScreenPlay/src/monitorlistmodel.cpp index cb468956..7caa2178 100644 --- a/ScreenPlay/src/monitorlistmodel.cpp +++ b/ScreenPlay/src/monitorlistmodel.cpp @@ -37,15 +37,8 @@ QHash MonitorListModel::roleNames() const { static const QHash roles { { static_cast(MonitorRole::AppID), "m_appID" }, - { static_cast(MonitorRole::MonitorID), "m_monitorID" }, - { static_cast(MonitorRole::Name), "m_name" }, - { static_cast(MonitorRole::Size), "m_size" }, - { static_cast(MonitorRole::AvailableGeometry), "m_availableGeometry" }, - { static_cast(MonitorRole::AvailableVirtualGeometry), "m_availableVirtualGeometry" }, - { static_cast(MonitorRole::Number), "m_number" }, + { static_cast(MonitorRole::Index), "m_index" }, { static_cast(MonitorRole::Geometry), "m_geometry" }, - { static_cast(MonitorRole::Model), "m_model" }, - { static_cast(MonitorRole::Manufacturer), "m_manufacturer" }, { static_cast(MonitorRole::PreviewImage), "m_previewImage" }, { static_cast(MonitorRole::InstalledType), "m_installedType" }, }; @@ -86,32 +79,10 @@ QVariant MonitorListModel::data(const QModelIndex& index, int role) const } else { return QVariant(""); } - case MonitorRole::MonitorID: { - QScreen* screen = m_monitorList.at(row).m_screen; - - QVariant id = QString::number(screen->size().width()) - + "x" + QString::number(screen->size().height()) - + "_" + QString::number(screen->availableGeometry().x()) - + "x" + QString::number(screen->availableGeometry().y()); - - return id; - } - case MonitorRole::Name: - return m_monitorList.at(row).m_screen->name(); - case MonitorRole::Size: - return m_monitorList.at(row).m_screen->size(); - case MonitorRole::AvailableGeometry: - return m_monitorList.at(row).m_availableGeometry; - case MonitorRole::AvailableVirtualGeometry: - return m_monitorList.at(row).m_screen->availableVirtualGeometry(); - case MonitorRole::Number: - return m_monitorList.at(row).m_number; + case MonitorRole::Index: + return m_monitorList.at(row).m_index; case MonitorRole::Geometry: return m_monitorList.at(row).m_screen->geometry(); - case MonitorRole::Model: - return m_monitorList.at(row).m_screen->model(); - case MonitorRole::Manufacturer: - return m_monitorList.at(row).m_screen->manufacturer(); case MonitorRole::InstalledType: if (m_monitorList.at(row).m_activeWallpaper) { return static_cast(m_monitorList.at(row).m_activeWallpaper->type()); @@ -143,7 +114,9 @@ void MonitorListModel::loadMonitors() // This offset lets us center the monitor selection view in the center int offsetX = 0; int offsetY = 0; - for (int i = 0; i < monitors.iMonitors.size(); i++) { + const int moinitorCount = monitors.iMonitors.size(); + + for (int i = 0; i < moinitorCount; i++) { const int x = monitors.rcMonitors[i].left; const int y = monitors.rcMonitors[i].top; if (x < 0) { @@ -154,18 +127,18 @@ void MonitorListModel::loadMonitors() } } - for (int i = 0; i < monitors.iMonitors.size(); i++) { + for (int i = 0; i < moinitorCount; i++) { const int width = std::abs(monitors.rcMonitors[i].right - monitors.rcMonitors[i].left); const int height = std::abs(monitors.rcMonitors[i].top - monitors.rcMonitors[i].bottom); const int x = monitors.rcMonitors[i].left; const int y = monitors.rcMonitors[i].top; - QRect availableVirtualGeometry( + QRect geometry( x + offsetX, y + offsetY, width, height); beginInsertRows(index, m_monitorList.size(), m_monitorList.size()); - m_monitorList.append(Monitor { i, availableVirtualGeometry, QApplication::screens().at(i) }); + m_monitorList.append(Monitor { i, geometry, QApplication::screens().at(i) }); endInsertRows(); } #else @@ -251,7 +224,7 @@ void MonitorListModel::closeWallpaper(const QString& appID) * \brief MonitorListModel::getAbsoluteDesktopSize * \return */ -QRect MonitorListModel::getAbsoluteDesktopSize() const +QRect MonitorListModel::absoluteDesktopSize() const { auto* app = static_cast(QGuiApplication::instance()); return app->screens().at(0)->availableVirtualGeometry(); @@ -283,7 +256,7 @@ void MonitorListModel::setWallpaperMonitor(const std::shared_ptr MonitorListModel::getAppIDByMonitorIndex(const int index) const { for (auto& monitor : m_monitorList) { - if (monitor.m_number == index && monitor.m_activeWallpaper) { + if (monitor.m_index == index && monitor.m_activeWallpaper) { return { monitor.m_activeWallpaper->appID() }; } } diff --git a/ScreenPlay/src/monitorlistmodel.h b/ScreenPlay/src/monitorlistmodel.h index 311ec59e..74cf4c67 100644 --- a/ScreenPlay/src/monitorlistmodel.h +++ b/ScreenPlay/src/monitorlistmodel.h @@ -58,17 +58,17 @@ namespace ScreenPlay { struct Monitor { Monitor( - const int number, - const QRect& availableGeometry, + const int index, + const QRect& geometry, QScreen* screen) { - m_number = number; - m_availableGeometry = availableGeometry; + m_index = index; + m_geometry = geometry; m_screen = screen; } - QRect m_availableGeometry; - int m_number { 0 }; + int m_index { 0 }; + QRect m_geometry; QScreen* m_screen { nullptr }; std::shared_ptr m_activeWallpaper { nullptr }; }; @@ -81,15 +81,8 @@ public: enum class MonitorRole { AppID = Qt::UserRole, - MonitorID, - Name, - Size, - AvailableGeometry, - AvailableVirtualGeometry, - Number, + Index, Geometry, - Model, - Manufacturer, PreviewImage, InstalledType, }; @@ -114,7 +107,7 @@ public slots: void reset(); void clearActiveWallpaper(); void closeWallpaper(const QString& appID); - QRect getAbsoluteDesktopSize() const; + QRect absoluteDesktopSize() const; void screenAdded(QScreen* screen) {