infowindow: Pop up infowindow at screen center (#318)

Currently info window will pop up at the topleft corner of the screen,
which is rather bothering. This patch will move the window to
screen center when popped up.

Since QGuiApplication::ScreenAt() is introduced since Qt 5.10, the
code will only take effect when compiled against Qt >= 5.10.

Signed-off-by: Boyuan Yang <073plan@gmail.com>
This commit is contained in:
Boyuan Yang
2018-08-19 12:33:00 -04:00
committed by Dharkael
parent 52d9815450
commit 36c62f6e81

View File

@@ -23,6 +23,13 @@
#include <QLabel>
#include <QKeyEvent>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
#include <QCursor>
#include <QRect>
#include <QScreen>
#include <QGuiApplication>
#endif
// InfoWindow show basic information about the usage of Flameshot
InfoWindow::InfoWindow(QWidget *parent) : QWidget(parent) {
@@ -30,6 +37,13 @@ InfoWindow::InfoWindow(QWidget *parent) : QWidget(parent) {
setWindowIcon(QIcon(":img/app/flameshot.svg"));
setWindowTitle(tr("About"));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
QRect position = frameGeometry();
QScreen *screen = QGuiApplication::screenAt(QCursor::pos());
position.moveCenter(screen->availableGeometry().center());
move(position.topLeft());
#endif
m_layout = new QVBoxLayout(this);
m_layout->setAlignment(Qt::AlignHCenter);
initLabels();