Skip to content

Commit cb3547e

Browse files
authored
Center dialogs on current screen (flameshot-org#4024)
* Center dialogs on current sreen * Center QuitPrompt
1 parent 172d561 commit cb3547e

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

src/core/flameshot.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
#endif
3838

3939
Flameshot::Flameshot()
40-
: m_captureWindow(nullptr)
41-
, m_haveExternalWidget(false)
40+
: m_haveExternalWidget(false)
41+
, m_captureWindow(nullptr)
4242
#if defined(Q_OS_MACOS)
4343
, m_HotkeyScreenshotCapture(nullptr)
4444
, m_HotkeyScreenshotHistory(nullptr)
@@ -221,6 +221,12 @@ void Flameshot::config()
221221
if (m_configWindow == nullptr) {
222222
m_configWindow = new ConfigWindow();
223223
m_configWindow->show();
224+
// Call show() first, otherwise the correct geometry cannot be fetched
225+
// for centering the window on the screen
226+
QRect position = m_configWindow->frameGeometry();
227+
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
228+
position.moveCenter(currentScreen->availableGeometry().center());
229+
m_configWindow->move(position.topLeft());
224230
#if defined(Q_OS_MACOS)
225231
m_configWindow->activateWindow();
226232
m_configWindow->raise();
@@ -249,7 +255,14 @@ void Flameshot::history()
249255
historyWidget = nullptr;
250256
});
251257
}
258+
252259
historyWidget->show();
260+
// Call show() first, otherwise the correct geometry cannot be fetched
261+
// for centering the window on the screen
262+
QRect position = historyWidget->frameGeometry();
263+
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
264+
position.moveCenter(currentScreen->availableGeometry().center());
265+
historyWidget->move(position.topLeft());
253266

254267
#if defined(Q_OS_MACOS)
255268
historyWidget->activateWindow();

src/widgets/capture/capturewidget.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ void CaptureWidget::initQuitPrompt()
475475
{
476476
m_quitPrompt = new QMessageBox;
477477
makeChild(m_quitPrompt);
478-
m_quitPrompt->hide();
479478

480479
QString baseSheet = "QDialog { background-color: %1; }"
481480
"QLabel, QCheckBox { color: %2 }"
@@ -493,6 +492,15 @@ void CaptureWidget::initQuitPrompt()
493492
auto* check = new QCheckBox(tr("Do not show this again"));
494493
m_quitPrompt->setCheckBox(check);
495494

495+
// Call show() first, otherwise the correct geometry cannot be fetched
496+
// for centering the window on the screen
497+
m_quitPrompt->show();
498+
QRect position = m_quitPrompt->frameGeometry();
499+
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
500+
position.moveCenter(currentScreen->availableGeometry().center());
501+
m_quitPrompt->move(position.topLeft());
502+
m_quitPrompt->hide();
503+
496504
QObject::connect(check, &QCheckBox::clicked, [](bool checked) {
497505
ConfigHandler().setShowQuitPrompt(!checked);
498506
});

src/widgets/capturelauncher.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "./ui_capturelauncher.h"
66
#include "src/config/cacheutils.h"
77
#include "src/core/flameshot.h"
8+
#include "src/core/qguiappcurrentscreen.h"
89
#include "src/utils/globalvalues.h"
910
#include "src/utils/screengrabber.h"
1011
#include "src/utils/screenshotsaver.h"
@@ -84,7 +85,14 @@ CaptureLauncher::CaptureLauncher(QDialog* parent)
8485
ui->screenshotY->setText(QString::number(lastRegion.y()));
8586
ui->screenshotWidth->setText(QString::number(lastRegion.width()));
8687
ui->screenshotHeight->setText(QString::number(lastRegion.height()));
88+
8789
show();
90+
// Call show() first, otherwise the correct geometry cannot be fetched
91+
// for centering the window on the screen
92+
QRect position = frameGeometry();
93+
QScreen* screen = QGuiAppCurrentScreen().currentScreen();
94+
position.moveCenter(screen->availableGeometry().center());
95+
move(position.topLeft());
8896
}
8997

9098
// HACK:

src/widgets/infowindow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ InfoWindow::InfoWindow(QWidget* parent)
2323
connect(
2424
ui->CopyInfoButton, &QPushButton::clicked, this, &InfoWindow::copyInfo);
2525

26+
show();
27+
// Call show() first, otherwise the correct geometry cannot be fetched for
28+
// centering the window on the screen
2629
QRect position = frameGeometry();
2730
QScreen* screen = QGuiAppCurrentScreen().currentScreen();
2831
position.moveCenter(screen->availableGeometry().center());
2932
move(position.topLeft());
30-
31-
show();
3233
}
3334

3435
InfoWindow::~InfoWindow()

0 commit comments

Comments
 (0)