Skip to content

Commit 9a42ee5

Browse files
committed
Center window on screen
1 parent 995e2dd commit 9a42ee5

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/mainwindow.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <QMainWindow>
2121
#include <QWidget>
2222
#include <QApplication>
23+
#include <QScreen>
2324
#include <QAbstractItemModel>
2425
#include <QItemSelectionModel>
2526
#include <QItemSelection>
@@ -148,7 +149,7 @@ MainWindow::MainWindow(Application *app, const CommandlineOptions &options, QWid
148149
connect(ui_->button_restore, SIGNAL(clicked()), SLOT(Restore()));
149150
connect(ui_->button_back, SIGNAL(clicked()), SLOT(Reset()));
150151
connect(ui_->button_cancel, SIGNAL(clicked()), SLOT(Cancel()));
151-
connect(ui_->button_exit, SIGNAL(clicked()), SLOT(MaybeExit()));
152+
connect(ui_->button_exit, SIGNAL(clicked()), SLOT(Exit()));
152153
connect(ui_->button_select_all, SIGNAL(clicked()), ui_->file_view_container->view(), SLOT(SelectAll()));
153154
connect(ui_->button_unselect_all, SIGNAL(clicked()), ui_->file_view_container->view(), SLOT(UnSelectAll()));
154155

@@ -216,6 +217,14 @@ void MainWindow::LoadGeometry() {
216217
}
217218
s.endGroup();
218219

220+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
221+
QScreen *screen = QGuiApplication::screenAt(pos());
222+
const QRect sr = screen->availableGeometry();
223+
const QRect wr({}, frameSize().boundedTo(sr.size()));
224+
resize(wr.size());
225+
move(sr.center() - wr.center());
226+
#endif
227+
219228
}
220229

221230
void MainWindow::SaveGeometry() {
@@ -403,14 +412,6 @@ void MainWindow::ConnectionFailure(const QString &error) {
403412

404413
}
405414

406-
void MainWindow::MaybeExit() {
407-
408-
if (ui_->stackedWidget->currentWidget() != ui_->progress) {
409-
qApp->quit();
410-
}
411-
412-
}
413-
414415
void MainWindow::Cancel() {
415416

416417
if (ui_->stackedWidget->currentWidget() == ui_->progress) {

src/mainwindow.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class MainWindow : public QMainWindow {
8181
void ConnectionFailure(const QString &error);
8282

8383
void Reset();
84-
void MaybeExit();
8584
void Cancel();
8685
void Restore();
8786

0 commit comments

Comments
 (0)