Add screen utilities for screen and center widget on screen

This commit is contained in:
Jonas Kvinge
2023-04-17 21:12:12 +02:00
parent d22712a25b
commit 41d5792b27
10 changed files with 102 additions and 70 deletions

View File

@@ -26,7 +26,6 @@
#include <QWidget>
#include <QMainWindow>
#include <QScreen>
#include <QWindow>
#include <QAbstractItemModel>
#include <QAbstractItemView>
#include <QTreeWidget>
@@ -50,6 +49,7 @@
#include "core/application.h"
#include "core/player.h"
#include "utilities/screenutils.h"
#include "widgets/groupediconview.h"
#include "collection/collectionmodel.h"
@@ -245,17 +245,7 @@ void SettingsDialog::LoadGeometry() {
s.endGroup();
// Center the dialog on the same screen as mainwindow.
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QScreen *screen = mainwindow_->screen();
#else
QScreen *screen = (mainwindow_->window() && mainwindow_->window()->windowHandle() ? mainwindow_->window()->windowHandle()->screen() : nullptr);
#endif
if (screen) {
const QRect sr = screen->availableGeometry();
const QRect wr({}, size().boundedTo(sr.size()));
resize(wr.size());
move(sr.center() - wr.center());
}
Utilities::CenterWidgetOnScreen(Utilities::GetScreen(mainwindow_), this);
}