diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 72424d12..55eb2679 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -31,6 +31,7 @@ #include "RegisterPage.h" #include "TrayIcon.h" #include "UserSettingsPage.h" +#include "Utils.h" #include "WelcomePage.h" #include "ui/LoadingIndicator.h" #include "ui/OverlayModal.h" @@ -310,8 +311,7 @@ MainWindow::openUserProfile(const QString &user_id, const QString &room_id) auto dialog = new dialogs::UserProfile(this); dialog->init(user_id, room_id); - dialog->raise(); - dialog->show(); + showDialog(dialog); } void @@ -321,8 +321,7 @@ MainWindow::openRoomSettings(const QString &room_id) auto dialog = new dialogs::RoomSettings(roomToSearch, this); - dialog->raise(); - dialog->show(); + showDialog(dialog); } void @@ -331,8 +330,7 @@ MainWindow::openMemberListDialog(const QString &room_id) const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : ""; auto dialog = new dialogs::MemberList(roomToSearch, this); - dialog->raise(); - dialog->show(); + showDialog(dialog); } void @@ -345,8 +343,7 @@ MainWindow::openLeaveRoomDialog(const QString &room_id) chat_page_->leaveRoom(roomToLeave); }); - dialog->raise(); - dialog->show(); + showDialog(dialog); } void @@ -370,8 +367,7 @@ MainWindow::openInviteUsersDialog(std::functionraise(); - dialog->show(); + showDialog(dialog); } void @@ -383,8 +379,7 @@ MainWindow::openJoinRoomDialog(std::function callb callback(room); }); - dialog->raise(); - dialog->show(); + showDialog(dialog); } void @@ -397,8 +392,7 @@ MainWindow::openCreateRoomDialog( this, [callback](const mtx::requests::CreateRoom &request) { callback(request); }); - dialog->raise(); - dialog->show(); + showDialog(dialog); } void @@ -430,8 +424,7 @@ MainWindow::openLogoutDialog() connect( dialog, &dialogs::Logout::loggingOut, this, [this]() { chat_page_->initiateLogout(); }); - dialog->raise(); - dialog->show(); + showDialog(dialog); } void @@ -452,8 +445,7 @@ MainWindow::openReadReceiptsDialog(const QString &event_id) return; } - dialog->raise(); - dialog->show(); + showDialog(dialog); } bool @@ -475,3 +467,11 @@ MainWindow::hideOverlay() if (modal_) modal_->hide(); } + +inline void +MainWindow::showDialog(QWidget *dialog) +{ + utils::centerWidget(dialog, this); + dialog->raise(); + dialog->show(); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index 0931099d..2336a929 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -129,6 +129,7 @@ private slots: void removeOverlayProgressBar(); private: + void showDialog(QWidget *dialog); bool hasActiveUser(); void restoreWindowSize(); //! Check if there is an open dialog.