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

@@ -27,7 +27,6 @@
#include <QWidget>
#include <QDialog>
#include <QScreen>
#include <QWindow>
#include <QMainWindow>
#include <QAbstractItemModel>
#include <QtAlgorithms>
@@ -58,6 +57,7 @@
#include "core/iconloader.h"
#include "core/mainwindow.h"
#include "utilities/screenutils.h"
#include "widgets/fileview.h"
#include "transcodedialog.h"
#include "transcoder.h"
@@ -194,17 +194,7 @@ void TranscodeDialog::LoadGeometry() {
s.endGroup();
// Center the window on the same screen as the 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);
}