From e2c71c3844de35f20b9c7af8c513c993cf06cebb Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 19 Dec 2013 16:57:29 +0100 Subject: Check if the window is still centered once a second and move it if neccessary. This is needed to account for resolution changes while the vmChooser is being displayed. --- src/dialog.cpp | 20 ++++++++++++++++++++ src/dialog.h | 4 ++++ src/main.cpp | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/dialog.cpp b/src/dialog.cpp index 21c5620..8ff215e 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "ui_dialog.h" #include "save_restore_session.h" @@ -18,6 +20,13 @@ Dialog::Dialog(QWidget *parent) pvsSettings_ = NULL; ui->PVSOptionsGroupBox->hide(); + + // Re-center dialog every second to account for resolution changes + QRect desktopRect = QApplication::desktop()->availableGeometry(this); + oldCenter_ = desktopRect.center(); + centerTimer_ = new QTimer(this); + connect(centerTimer_, SIGNAL(timeout()), this, SLOT(on_centerTimer())); + centerTimer_->start(1000); } Dialog::~Dialog() { @@ -212,3 +221,14 @@ void Dialog::setTheme() { ui->label_l->setStyleSheet(label_l_style); ui->label_r->setStyleSheet(label_r_style); } + +void Dialog::on_centerTimer() { + // center dialog on primary screen + QRect desktopRect = QApplication::desktop()->availableGeometry(this); + QPoint center = desktopRect.center(); + if (center != oldCenter_) { + this->move(center.x() - this->width() / 2, center.y() - this->height() / 2); + oldCenter_ = center; + } +} + diff --git a/src/dialog.h b/src/dialog.h index 805ed08..cc3627a 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -11,6 +11,7 @@ namespace Ui { class Dialog; } +class QTimer; class Dialog : public QDialog { Q_OBJECT @@ -30,6 +31,8 @@ class Dialog : public QDialog { Ui::Dialog *ui; SessionTreeModel *model_; QSettings *pvsSettings_; + QPoint oldCenter_; + QTimer *centerTimer_; void readPVSSettings(); void writePVSSettings(); @@ -39,6 +42,7 @@ class Dialog : public QDialog { void on_pushButtonStart_clicked(); void on_pushButtonAbort_clicked(); void on_treeView_activated(QModelIndex index); + void on_centerTimer(); }; #endif // DIALOG_H diff --git a/src/main.cpp b/src/main.cpp index 774f166..e5b8ce5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -220,7 +220,7 @@ int main(int argc, char *argv[]) { w.selectSession(defaultSession); w.show(); - // center dialog on screen + // center dialog on primary screen QRect desktopRect = QApplication::desktop()->availableGeometry(&w); QPoint center = desktopRect.center(); w.move(center.x()-w.width()*0.5, center.y()-w.height()*0.5); -- cgit v1.2.3-55-g7522