Fix centering dialogs

This commit is contained in:
Nicolas Werner 2022-01-29 19:07:27 +01:00
parent 1d6d9e65af
commit 392a4be858
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
4 changed files with 13 additions and 21 deletions

View file

@ -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);
}

View file

@ -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;

View file

@ -17,6 +17,7 @@
#include <QStringBuilder>
#include <QTextBoundaryFinder>
#include <QTextDocument>
#include <QWindow>
#include <QXmlStreamReader>
#include <array>
@ -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()));
}

View file

@ -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);