1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-06 19:12:30 +01:00

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.
This commit is contained in:
Elias Steurer 2021-12-12 21:56:37 +01:00
parent d370a78913
commit d9bf1a8558
4 changed files with 31 additions and 80 deletions

View File

@ -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
}

View File

@ -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

View File

@ -37,15 +37,8 @@ QHash<int, QByteArray> MonitorListModel::roleNames() const
{
static const QHash<int, QByteArray> roles {
{ static_cast<int>(MonitorRole::AppID), "m_appID" },
{ static_cast<int>(MonitorRole::MonitorID), "m_monitorID" },
{ static_cast<int>(MonitorRole::Name), "m_name" },
{ static_cast<int>(MonitorRole::Size), "m_size" },
{ static_cast<int>(MonitorRole::AvailableGeometry), "m_availableGeometry" },
{ static_cast<int>(MonitorRole::AvailableVirtualGeometry), "m_availableVirtualGeometry" },
{ static_cast<int>(MonitorRole::Number), "m_number" },
{ static_cast<int>(MonitorRole::Index), "m_index" },
{ static_cast<int>(MonitorRole::Geometry), "m_geometry" },
{ static_cast<int>(MonitorRole::Model), "m_model" },
{ static_cast<int>(MonitorRole::Manufacturer), "m_manufacturer" },
{ static_cast<int>(MonitorRole::PreviewImage), "m_previewImage" },
{ static_cast<int>(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<int>(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<QApplication*>(QGuiApplication::instance());
return app->screens().at(0)->availableVirtualGeometry();
@ -283,7 +256,7 @@ void MonitorListModel::setWallpaperMonitor(const std::shared_ptr<ScreenPlayWallp
std::optional<QString> 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() };
}
}

View File

@ -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<ScreenPlayWallpaper> 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)
{