From cc04ebd45f7b670b0d7c6331c691f731fa182b2a Mon Sep 17 00:00:00 2001 From: Nick Tiskov Date: Sat, 27 Jul 2013 22:57:33 +0400 Subject: [PATCH] Try to center AutoExpandableDialog on the same screen as main window If main window is unavailable use the screen, where the mouse cursor is. --- src/autoexpandabledialog.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/autoexpandabledialog.cpp b/src/autoexpandabledialog.cpp index 2190b67a3..ae8724b73 100644 --- a/src/autoexpandabledialog.cpp +++ b/src/autoexpandabledialog.cpp @@ -30,6 +30,7 @@ #include +#include "mainwindow.h" #include "autoexpandabledialog.h" #include "ui_autoexpandabledialog.h" @@ -100,9 +101,21 @@ void AutoExpandableDialog::showEvent(QShowEvent *e) { setFixedHeight(height()); // Update geometry: center on screen - int sx = QApplication::desktop()->width(); - int sy = QApplication::desktop()->height(); + QDesktopWidget *desk = QApplication::desktop(); + MainWindow *wnd = qobject_cast(QApplication::activeWindow()); + QPoint p = QCursor::pos(); + + int screenNum = 0; + if (wnd == 0) + screenNum = desk->screenNumber(p); + else if (!wnd->isHidden()) + screenNum = desk->screenNumber(wnd); + else + screenNum = desk->screenNumber(p); + + QRect screenRes = desk->screenGeometry(screenNum); + QRect geom = geometry(); - geom.moveCenter(QPoint(sx / 2, sy / 2)); + geom.moveCenter(QPoint(screenRes.width() / 2, screenRes.height() / 2)); setGeometry(geom); }