mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-08-26 13:42:37 +00:00
Try to center AutoExpandableDialog on the same screen as main window
If main window is unavailable use the screen, where the mouse cursor is.
This commit is contained in:
parent
de3108e1e5
commit
cc04ebd45f
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
|
|
||||||
|
#include "mainwindow.h"
|
||||||
#include "autoexpandabledialog.h"
|
#include "autoexpandabledialog.h"
|
||||||
#include "ui_autoexpandabledialog.h"
|
#include "ui_autoexpandabledialog.h"
|
||||||
|
|
||||||
@ -100,9 +101,21 @@ void AutoExpandableDialog::showEvent(QShowEvent *e) {
|
|||||||
setFixedHeight(height());
|
setFixedHeight(height());
|
||||||
|
|
||||||
// Update geometry: center on screen
|
// Update geometry: center on screen
|
||||||
int sx = QApplication::desktop()->width();
|
QDesktopWidget *desk = QApplication::desktop();
|
||||||
int sy = QApplication::desktop()->height();
|
MainWindow *wnd = qobject_cast<MainWindow*>(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();
|
QRect geom = geometry();
|
||||||
geom.moveCenter(QPoint(sx / 2, sy / 2));
|
geom.moveCenter(QPoint(screenRes.width() / 2, screenRes.height() / 2));
|
||||||
setGeometry(geom);
|
setGeometry(geom);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user