diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-09-21 11:30:02 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-09-21 11:30:02 +0300 |
commit | 2a2b52e07fcc36b73f97a35d7f2c76dc162fe519 (patch) | |
tree | 094054556c5097250503d4dbe56a5aca22a3c6a5 | |
parent | Add method to center widgets & clean up unused headers (diff) | |
download | nheko-2a2b52e07fcc36b73f97a35d7f2c76dc162fe519.tar.xz |
Center dialogs around the main window
-rw-r--r-- | src/MainWindow.cpp | 36 | ||||
-rw-r--r-- | src/MainWindow.h | 1 |
2 files changed, 19 insertions, 18 deletions
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::function<void(const QStringList &invitees callback(invitees); }); - dialog->raise(); - dialog->show(); + showDialog(dialog); } void @@ -383,8 +379,7 @@ MainWindow::openJoinRoomDialog(std::function<void(const QString &room_id)> 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. |