From 392a4be858a9ba1d1870041f726e05501bf65c4e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 29 Jan 2022 19:07:27 +0100 Subject: [PATCH] Fix centering dialogs --- src/MainWindow.cpp | 14 +++++--------- src/MainWindow.h | 2 -- src/Utils.cpp | 16 +++++++--------- src/Utils.h | 2 +- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index ab2de2ba..a4661da7 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -422,23 +422,19 @@ MainWindow::openCreateRoomDialog( showDialog(dialog); } -bool -MainWindow::hasActiveDialogs() const -{ - return false; -} - bool MainWindow::pageSupportsTray() const { - return false; //! welcome_page_->isVisible() && !login_page_->isVisible() && - //! !register_page_->isVisible(); + return !http::client()->access_token().empty(); } inline void MainWindow::showDialog(QWidget *dialog) { - // utils::centerWidget(dialog, this); + dialog->setWindowFlags(Qt::WindowType::Dialog | Qt::WindowType::WindowCloseButtonHint | + Qt::WindowType::WindowTitleHint); dialog->raise(); dialog->show(); + utils::centerWidget(dialog, this); + dialog->window()->windowHandle()->setTransientParent(this); } diff --git a/src/MainWindow.h b/src/MainWindow.h index 33e16271..1258bafb 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -83,8 +83,6 @@ private: void showDialog(QWidget *dialog); bool hasActiveUser(); void restoreWindowSize(); - //! Check if there is an open dialog. - bool hasActiveDialogs() const; //! Check if the current page supports the "minimize to tray" functionality. bool pageSupportsTray() const; diff --git a/src/Utils.cpp b/src/Utils.cpp index a9cfde22..0ac37d8e 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -770,20 +771,17 @@ utils::luminance(const QColor &col) } void -utils::centerWidget(QWidget *widget, QWidget *parent) +utils::centerWidget(QWidget *widget, QWindow *parent) { + if (parent) { + widget->window()->windowHandle()->setTransientParent(parent); + return; + } + auto findCenter = [childRect = widget->rect()](QRect hostRect) -> QPoint { return QPoint(hostRect.center().x() - (childRect.width() * 0.5), hostRect.center().y() - (childRect.height() * 0.5)); }; - - if (parent) { - widget->move(parent->window()->frameGeometry().topLeft() + - parent->window()->rect().center() - widget->rect().center()); - return; - } - - // Deprecated in 5.13: widget->move(findCenter(QApplication::desktop()->screenGeometry())); widget->move(findCenter(QGuiApplication::primaryScreen()->geometry())); } diff --git a/src/Utils.h b/src/Utils.h index 87ce1c34..0b6034ac 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -290,7 +290,7 @@ luminance(const QColor &col); //! Center a widget in relation to another widget. void -centerWidget(QWidget *widget, QWidget *parent); +centerWidget(QWidget *widget, QWindow *parent); void restoreCombobox(QComboBox *combo, const QString &value);