Center dialogs on current screen (#4024)

* Center dialogs on current sreen

* Center QuitPrompt
This commit is contained in:
El Thoro
2025-06-22 19:22:01 +02:00
committed by GitHub
parent 172d561fb8
commit cb3547e545
4 changed files with 35 additions and 5 deletions

View File

@@ -37,8 +37,8 @@
#endif #endif
Flameshot::Flameshot() Flameshot::Flameshot()
: m_captureWindow(nullptr) : m_haveExternalWidget(false)
, m_haveExternalWidget(false) , m_captureWindow(nullptr)
#if defined(Q_OS_MACOS) #if defined(Q_OS_MACOS)
, m_HotkeyScreenshotCapture(nullptr) , m_HotkeyScreenshotCapture(nullptr)
, m_HotkeyScreenshotHistory(nullptr) , m_HotkeyScreenshotHistory(nullptr)
@@ -221,6 +221,12 @@ void Flameshot::config()
if (m_configWindow == nullptr) { if (m_configWindow == nullptr) {
m_configWindow = new ConfigWindow(); m_configWindow = new ConfigWindow();
m_configWindow->show(); m_configWindow->show();
// Call show() first, otherwise the correct geometry cannot be fetched
// for centering the window on the screen
QRect position = m_configWindow->frameGeometry();
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
position.moveCenter(currentScreen->availableGeometry().center());
m_configWindow->move(position.topLeft());
#if defined(Q_OS_MACOS) #if defined(Q_OS_MACOS)
m_configWindow->activateWindow(); m_configWindow->activateWindow();
m_configWindow->raise(); m_configWindow->raise();
@@ -249,7 +255,14 @@ void Flameshot::history()
historyWidget = nullptr; historyWidget = nullptr;
}); });
} }
historyWidget->show(); historyWidget->show();
// Call show() first, otherwise the correct geometry cannot be fetched
// for centering the window on the screen
QRect position = historyWidget->frameGeometry();
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
position.moveCenter(currentScreen->availableGeometry().center());
historyWidget->move(position.topLeft());
#if defined(Q_OS_MACOS) #if defined(Q_OS_MACOS)
historyWidget->activateWindow(); historyWidget->activateWindow();

View File

@@ -475,7 +475,6 @@ void CaptureWidget::initQuitPrompt()
{ {
m_quitPrompt = new QMessageBox; m_quitPrompt = new QMessageBox;
makeChild(m_quitPrompt); makeChild(m_quitPrompt);
m_quitPrompt->hide();
QString baseSheet = "QDialog { background-color: %1; }" QString baseSheet = "QDialog { background-color: %1; }"
"QLabel, QCheckBox { color: %2 }" "QLabel, QCheckBox { color: %2 }"
@@ -493,6 +492,15 @@ void CaptureWidget::initQuitPrompt()
auto* check = new QCheckBox(tr("Do not show this again")); auto* check = new QCheckBox(tr("Do not show this again"));
m_quitPrompt->setCheckBox(check); m_quitPrompt->setCheckBox(check);
// Call show() first, otherwise the correct geometry cannot be fetched
// for centering the window on the screen
m_quitPrompt->show();
QRect position = m_quitPrompt->frameGeometry();
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
position.moveCenter(currentScreen->availableGeometry().center());
m_quitPrompt->move(position.topLeft());
m_quitPrompt->hide();
QObject::connect(check, &QCheckBox::clicked, [](bool checked) { QObject::connect(check, &QCheckBox::clicked, [](bool checked) {
ConfigHandler().setShowQuitPrompt(!checked); ConfigHandler().setShowQuitPrompt(!checked);
}); });

View File

@@ -5,6 +5,7 @@
#include "./ui_capturelauncher.h" #include "./ui_capturelauncher.h"
#include "src/config/cacheutils.h" #include "src/config/cacheutils.h"
#include "src/core/flameshot.h" #include "src/core/flameshot.h"
#include "src/core/qguiappcurrentscreen.h"
#include "src/utils/globalvalues.h" #include "src/utils/globalvalues.h"
#include "src/utils/screengrabber.h" #include "src/utils/screengrabber.h"
#include "src/utils/screenshotsaver.h" #include "src/utils/screenshotsaver.h"
@@ -84,7 +85,14 @@ CaptureLauncher::CaptureLauncher(QDialog* parent)
ui->screenshotY->setText(QString::number(lastRegion.y())); ui->screenshotY->setText(QString::number(lastRegion.y()));
ui->screenshotWidth->setText(QString::number(lastRegion.width())); ui->screenshotWidth->setText(QString::number(lastRegion.width()));
ui->screenshotHeight->setText(QString::number(lastRegion.height())); ui->screenshotHeight->setText(QString::number(lastRegion.height()));
show(); show();
// Call show() first, otherwise the correct geometry cannot be fetched
// for centering the window on the screen
QRect position = frameGeometry();
QScreen* screen = QGuiAppCurrentScreen().currentScreen();
position.moveCenter(screen->availableGeometry().center());
move(position.topLeft());
} }
// HACK: // HACK:

View File

@@ -23,12 +23,13 @@ InfoWindow::InfoWindow(QWidget* parent)
connect( connect(
ui->CopyInfoButton, &QPushButton::clicked, this, &InfoWindow::copyInfo); ui->CopyInfoButton, &QPushButton::clicked, this, &InfoWindow::copyInfo);
show();
// Call show() first, otherwise the correct geometry cannot be fetched for
// centering the window on the screen
QRect position = frameGeometry(); QRect position = frameGeometry();
QScreen* screen = QGuiAppCurrentScreen().currentScreen(); QScreen* screen = QGuiAppCurrentScreen().currentScreen();
position.moveCenter(screen->availableGeometry().center()); position.moveCenter(screen->availableGeometry().center());
move(position.topLeft()); move(position.topLeft());
show();
} }
InfoWindow::~InfoWindow() InfoWindow::~InfoWindow()