diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-08-11 13:50:56 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-08-11 13:50:56 +0300 |
commit | aa2f6ce77d924a0dc53325a425215a1b03e72f43 (patch) | |
tree | a6d8b8808a0f31c541aa7cb6af0cfd1f6826776f | |
parent | Add solid background in TypingDisplay (diff) | |
download | nheko-aa2f6ce77d924a0dc53325a425215a1b03e72f43.tar.xz |
Simplify dialog creation
-rw-r--r-- | src/ChatPage.cpp | 50 | ||||
-rw-r--r-- | src/ChatPage.h | 11 | ||||
-rw-r--r-- | src/LoginPage.h | 1 | ||||
-rw-r--r-- | src/MainWindow.cpp | 279 | ||||
-rw-r--r-- | src/MainWindow.h | 48 | ||||
-rw-r--r-- | src/RegisterPage.h | 1 | ||||
-rw-r--r-- | src/TopRoomBar.h | 1 | ||||
-rw-r--r-- | src/dialogs/RoomSettings.cpp | 1 | ||||
-rw-r--r-- | src/dialogs/RoomSettings.h | 3 | ||||
-rw-r--r-- | src/dialogs/UserProfile.cpp | 13 | ||||
-rw-r--r-- | src/dialogs/UserProfile.h | 11 | ||||
-rw-r--r-- | src/timeline/TimelineItem.cpp | 2 | ||||
-rw-r--r-- | src/ui/LoadingIndicator.cpp | 9 | ||||
-rw-r--r-- | src/ui/LoadingIndicator.h | 1 | ||||
-rw-r--r-- | src/ui/OverlayModal.cpp | 21 | ||||
-rw-r--r-- | src/ui/OverlayModal.h | 3 |
16 files changed, 181 insertions, 274 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 71ea0649..8f3c37a4 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -835,31 +835,15 @@ ChatPage::loadStateFromCache() void ChatPage::showQuickSwitcher() { - if (quickSwitcher_.isNull()) { - quickSwitcher_ = QSharedPointer<QuickSwitcher>( - new QuickSwitcher(this), - [](QuickSwitcher *switcher) { switcher->deleteLater(); }); - - connect(quickSwitcher_.data(), - &QuickSwitcher::roomSelected, - room_list_, - &RoomList::highlightSelectedRoom); - - connect(quickSwitcher_.data(), &QuickSwitcher::closing, this, [this]() { - if (!quickSwitcherModal_.isNull()) - quickSwitcherModal_->hide(); - text_input_->setFocus(Qt::FocusReason::PopupFocusReason); - }); - } + auto dialog = new QuickSwitcher(this); - if (quickSwitcherModal_.isNull()) { - quickSwitcherModal_ = QSharedPointer<OverlayModal>( - new OverlayModal(MainWindow::instance(), quickSwitcher_.data()), - [](OverlayModal *modal) { modal->deleteLater(); }); - quickSwitcherModal_->setColor(QColor(30, 30, 30, 170)); - } + connect(dialog, &QuickSwitcher::roomSelected, room_list_, &RoomList::highlightSelectedRoom); + connect(dialog, &QuickSwitcher::closing, this, [this]() { + MainWindow::instance()->hideOverlay(); + text_input_->setFocus(Qt::FocusReason::PopupFocusReason); + }); - quickSwitcherModal_->show(); + MainWindow::instance()->showTransparentOverlayModal(dialog); } void @@ -918,26 +902,6 @@ ChatPage::removeLeftRooms(const std::map<std::string, mtx::responses::LeftRoom> } void -ChatPage::showReadReceipts(const QString &event_id) -{ - if (receiptsDialog_.isNull()) { - receiptsDialog_ = QSharedPointer<dialogs::ReadReceipts>( - new dialogs::ReadReceipts(this), - [](dialogs::ReadReceipts *dialog) { dialog->deleteLater(); }); - } - - if (receiptsModal_.isNull()) { - receiptsModal_ = QSharedPointer<OverlayModal>( - new OverlayModal(MainWindow::instance(), receiptsDialog_.data()), - [](OverlayModal *modal) { modal->deleteLater(); }); - receiptsModal_->setColor(QColor(30, 30, 30, 170)); - } - - receiptsDialog_->addUsers(cache::client()->readReceipts(event_id, current_room_)); - receiptsModal_->show(); -} - -void ChatPage::setGroupViewState(bool isEnabled) { if (!isEnabled) { diff --git a/src/ChatPage.h b/src/ChatPage.h index f032901a..a74748ed 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -44,10 +44,6 @@ class UserInfoWidget; class UserSettings; class NotificationsManager; -namespace dialogs { -class ReadReceipts; -} - constexpr int CONSENSUS_TIMEOUT = 1000; constexpr int SHOW_CONTENT_TIMEOUT = 3000; constexpr int TYPING_REFRESH_TIMEOUT = 10000; @@ -62,7 +58,6 @@ public: // Initialize all the components of the UI. void bootstrap(QString userid, QString homeserver, QString token); void showQuickSwitcher(); - void showReadReceipts(const QString &event_id); QString currentRoom() const { return current_room_; } static ChatPage *instance() { return instance_; } @@ -237,12 +232,6 @@ private: std::map<QString, QList<QString>> typingUsers_; QTimer *typingRefresher_; - QSharedPointer<QuickSwitcher> quickSwitcher_; - QSharedPointer<OverlayModal> quickSwitcherModal_; - - QSharedPointer<dialogs::ReadReceipts> receiptsDialog_; - QSharedPointer<OverlayModal> receiptsModal_; - // Global user settings. QSharedPointer<UserSettings> userSettings_; diff --git a/src/LoginPage.h b/src/LoginPage.h index cf2d024b..ff7ba629 100644 --- a/src/LoginPage.h +++ b/src/LoginPage.h @@ -19,7 +19,6 @@ #include <QLabel> #include <QLayout> -#include <QSharedPointer> #include <QWidget> class FlatButton; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 7cb12caa..b6216feb 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -42,18 +42,19 @@ #include "dialogs/LeaveRoom.h" #include "dialogs/Logout.h" #include "dialogs/MemberList.h" +#include "dialogs/ReadReceipts.h" #include "dialogs/RoomSettings.h" MainWindow *MainWindow::instance_ = nullptr; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) - , progressModal_{nullptr} - , spinner_{nullptr} { setWindowTitle("nheko"); setObjectName("MainWindow"); + modal_ = new OverlayModal(this); + restoreWindowSize(); QFont font("Open Sans"); @@ -223,26 +224,20 @@ MainWindow::removeOverlayProgressBar() connect(timer, &QTimer::timeout, [this, timer]() { timer->deleteLater(); - if (!progressModal_.isNull()) - progressModal_->hide(); + if (modal_) + modal_->hide(); - if (!spinner_.isNull()) + if (spinner_) spinner_->stop(); - - progressModal_.reset(); - spinner_.reset(); }); // FIXME: Snackbar doesn't work if it's initialized in the constructor. QTimer::singleShot(0, this, [this]() { - snackBar_ = QSharedPointer<SnackBar>(new SnackBar(this)); - connect(chat_page_, - &ChatPage::showNotification, - snackBar_.data(), - &SnackBar::showMessage); + snackBar_ = new SnackBar(this); + connect(chat_page_, &ChatPage::showNotification, snackBar_, &SnackBar::showMessage); }); - timer->start(500); + timer->start(50); } void @@ -312,18 +307,10 @@ MainWindow::hasActiveUser() void MainWindow::openUserProfile(const QString &user_id, const QString &room_id) { - if (!userProfileDialog_) - userProfileDialog_ = - QSharedPointer<dialogs::UserProfile>(new dialogs::UserProfile(this)); - - userProfileDialog_->init(user_id, room_id); - - if (!userProfileModal_) - userProfileModal_ = - QSharedPointer<OverlayModal>(new OverlayModal(this, userProfileDialog_.data())); + auto dialog = new dialogs::UserProfile(this); + dialog->init(user_id, room_id); - userProfileModal_->setContentAlignment(Qt::AlignTop | Qt::AlignHCenter); - userProfileModal_->show(); + showTransparentOverlayModal(dialog); } void @@ -331,18 +318,13 @@ MainWindow::openRoomSettings(const QString &room_id) { const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : ""; - roomSettingsDialog_ = - QSharedPointer<dialogs::RoomSettings>(new dialogs::RoomSettings(roomToSearch, this)); - - connect(roomSettingsDialog_.data(), &dialogs::RoomSettings::closing, this, [this]() { - roomSettingsModal_->hide(); + auto dialog = new dialogs::RoomSettings(roomToSearch, this); + connect(dialog, &dialogs::RoomSettings::closing, this, [this]() { + if (modal_) + modal_->hide(); }); - roomSettingsModal_ = - QSharedPointer<OverlayModal>(new OverlayModal(this, roomSettingsDialog_.data())); - - roomSettingsModal_->setContentAlignment(Qt::AlignTop | Qt::AlignHCenter); - roomSettingsModal_->show(); + showTransparentOverlayModal(dialog); } void @@ -350,13 +332,8 @@ MainWindow::openMemberListDialog(const QString &room_id) { const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : ""; - memberListDialog_ = - QSharedPointer<dialogs::MemberList>(new dialogs::MemberList(roomToSearch, this)); - - memberListModal_ = - QSharedPointer<OverlayModal>(new OverlayModal(this, memberListDialog_.data())); - - memberListModal_->show(); + modal_->setWidget(new dialogs::MemberList(roomToSearch, this)); + modal_->show(); } void @@ -364,161 +341,146 @@ MainWindow::openLeaveRoomDialog(const QString &room_id) { auto roomToLeave = room_id.isEmpty() ? chat_page_->currentRoom() : room_id; - leaveRoomDialog_ = QSharedPointer<dialogs::LeaveRoom>(new dialogs::LeaveRoom(this)); - - connect(leaveRoomDialog_.data(), - &dialogs::LeaveRoom::closing, - this, - [this, roomToLeave](bool leaving) { - leaveRoomModal_->hide(); - - if (leaving) - chat_page_->leaveRoom(roomToLeave); - }); + auto dialog = new dialogs::LeaveRoom(this); + connect(dialog, &dialogs::LeaveRoom::closing, this, [this, roomToLeave](bool leaving) { + if (modal_) + modal_->hide(); - leaveRoomModal_ = - QSharedPointer<OverlayModal>(new OverlayModal(this, leaveRoomDialog_.data())); - leaveRoomModal_->setColor(QColor(30, 30, 30, 170)); + if (leaving) + chat_page_->leaveRoom(roomToLeave); + }); - leaveRoomModal_->show(); + showTransparentOverlayModal(dialog, Qt::AlignCenter); } void MainWindow::showOverlayProgressBar() { - if (spinner_.isNull()) { - spinner_ = QSharedPointer<LoadingIndicator>( - new LoadingIndicator(this), - [](LoadingIndicator *indicator) { indicator->deleteLater(); }); - spinner_->setFixedHeight(100); - spinner_->setFixedWidth(100); - spinner_->setObjectName("ChatPageLoadSpinner"); - spinner_->start(); - } + spinner_ = new LoadingIndicator(this); + spinner_->setFixedHeight(100); + spinner_->setFixedWidth(100); + spinner_->setObjectName("ChatPageLoadSpinner"); + spinner_->start(); - if (progressModal_.isNull()) { - progressModal_ = - QSharedPointer<OverlayModal>(new OverlayModal(this, spinner_.data()), - [](OverlayModal *modal) { modal->deleteLater(); }); - progressModal_->setColor(QColor(30, 30, 30)); - progressModal_->setDismissible(false); - progressModal_->show(); - } + showSolidOverlayModal(spinner_); } void MainWindow::openInviteUsersDialog(std::function<void(const QStringList &invitees)> callback) { - if (inviteUsersDialog_.isNull()) { - inviteUsersDialog_ = - QSharedPointer<dialogs::InviteUsers>(new dialogs::InviteUsers(this)); - - connect(inviteUsersDialog_.data(), - &dialogs::InviteUsers::closing, - this, - [this, callback](bool isSending, QStringList invitees) { - inviteUsersModal_->hide(); - - if (isSending && !invitees.isEmpty()) - callback(invitees); - }); - } - - if (inviteUsersModal_.isNull()) { - inviteUsersModal_ = QSharedPointer<OverlayModal>( - new OverlayModal(MainWindow::instance(), inviteUsersDialog_.data())); - inviteUsersModal_->setColor(QColor(30, 30, 30, 170)); - } + auto dialog = new dialogs::InviteUsers(this); + connect(dialog, + &dialogs::InviteUsers::closing, + this, + [this, callback](bool isSending, QStringList invitees) { + if (modal_) + modal_->hide(); + if (isSending && !invitees.isEmpty()) + callback(invitees); + }); - inviteUsersModal_->show(); + showTransparentOverlayModal(dialog); } void MainWindow::openJoinRoomDialog(std::function<void(const QString &room_id)> callback) { - if (joinRoomDialog_.isNull()) { - joinRoomDialog_ = QSharedPointer<dialogs::JoinRoom>(new dialogs::JoinRoom(this)); - - connect(joinRoomDialog_.data(), - &dialogs::JoinRoom::closing, - this, - [this, callback](bool isJoining, const QString &room) { - joinRoomModal_->hide(); - - if (isJoining && !room.isEmpty()) - callback(room); - }); - } + auto dialog = new dialogs::JoinRoom(this); + connect(dialog, + &dialogs::JoinRoom::closing, + this, + [this, callback](bool isJoining, const QString &room) { + if (modal_) + modal_->hide(); - if (joinRoomModal_.isNull()) { - joinRoomModal_ = QSharedPointer<OverlayModal>( - new OverlayModal(MainWindow::instance(), joinRoomDialog_.data())); - } + if (isJoining && !room.isEmpty()) + callback(room); + }); - joinRoomModal_->show(); + showTransparentOverlayModal(dialog, Qt::AlignCenter); } void MainWindow::openCreateRoomDialog( std::function<void(const mtx::requests::CreateRoom &request)> callback) { - if (createRoomDialog_.isNull()) { - createRoomDialog_ = - QSharedPointer<dialogs::CreateRoom>(new dialogs::CreateRoom(this)); - - connect( - createRoomDialog_.data(), - &dialogs::CreateRoom::closing, - this, - [this, callback](bool isCreating, const mtx::requests::CreateRoom &request) { - createRoomModal_->hide(); - - if (isCreating) - callback(request); - }); - } + auto dialog = new dialogs::CreateRoom(this); + connect(dialog, + &dialogs::CreateRoom::closing, + this, + [this, callback](bool isCreating, const mtx::requests::CreateRoom &request) { + if (modal_) + modal_->hide(); - if (createRoomModal_.isNull()) { - createRoomModal_ = QSharedPointer<OverlayModal>( - new OverlayModal(MainWindow::instance(), createRoomDialog_.data())); - } + if (isCreating) + callback(request); + }); - createRoomModal_->show(); + showTransparentOverlayModal(dialog); +} + +void +MainWindow::showTransparentOverlayModal(QWidget *content, QFlags<Qt::AlignmentFlag> flags) +{ + modal_->setWidget(content); + modal_->setColor(QColor(30, 30, 30, 150)); + modal_->setDismissible(true); + modal_->setContentAlignment(flags); + modal_->raise(); + modal_->show(); +} + +void +MainWindow::showSolidOverlayModal(QWidget *content, QFlags<Qt::AlignmentFlag> flags) +{ + modal_->setWidget(content); + modal_->setColor(QColor(30, 30, 30)); + modal_->setDismissible(false); + modal_->setContentAlignment(flags); + modal_->raise(); + modal_->show(); } void MainWindow::openLogoutDialog(std::function<void()> callback) { - if (logoutDialog_.isNull()) { - logoutDialog_ = QSharedPointer<dialogs::Logout>(new dialogs::Logout(this)); - connect(logoutDialog_.data(), - &dialogs::Logout::closing, - this, - [this, callback](bool logging_out) { - logoutModal_->hide(); - - if (logging_out) - callback(); - }); - } + auto dialog = new dialogs::Logout(this); + connect(dialog, &dialogs::Logout::closing, this, [this, callback](bool logging_out) { + if (modal_) + modal_->hide(); - if (logoutModal_.isNull()) { - logoutModal_ = QSharedPointer<OverlayModal>( - new OverlayModal(MainWindow::instance(), logoutDialog_.data())); + if (logging_out) + callback(); + }); + + showTransparentOverlayModal(dialog, Qt::AlignCenter); +} + +void +MainWindow::openReadReceiptsDialog(const QString &event_id) +{ + auto dialog = new dialogs::ReadReceipts(this); + + const auto room_id = chat_page_->currentRoom(); + + try { + dialog->addUsers(cache::client()->readReceipts(event_id, room_id)); + } catch (const lmdb::error &e) { + nhlog::db()->warn("failed to retrieve read receipts for {} {}", + event_id.toStdString(), + chat_page_->currentRoom().toStdString()); + dialog->deleteLater(); + + return; } - logoutModal_->show(); + showTransparentOverlayModal(dialog); } bool MainWindow::hasActiveDialogs() const { - return (!leaveRoomModal_.isNull() && leaveRoomModal_->isVisible()) || - (!progressModal_.isNull() && progressModal_->isVisible()) || - (!inviteUsersModal_.isNull() && inviteUsersModal_->isVisible()) || - (!joinRoomModal_.isNull() && joinRoomModal_->isVisible()) || - (!createRoomModal_.isNull() && createRoomModal_->isVisible()) || - (!logoutModal_.isNull() && logoutModal_->isVisible()); + return !modal_ && modal_->isVisible(); } bool @@ -527,3 +489,10 @@ MainWindow::pageSupportsTray() const return !welcome_page_->isVisible() && !login_page_->isVisible() && !register_page_->isVisible(); } + +void +MainWindow::hideOverlay() +{ + if (modal_) + modal_->hide(); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index 3d9a94d3..0fa49f17 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -29,6 +29,7 @@ #include "UserSettingsPage.h" #include "WelcomePage.h" #include "dialogs/UserProfile.h" +#include "ui/OverlayModal.h" class ChatPage; class LoadingIndicator; @@ -73,6 +74,14 @@ public: void openRoomSettings(const QString &room_id = ""); void openMemberListDialog(const QString &room_id = ""); void openUserProfile(const QString &user_id, const QString &room_id); + void openReadReceiptsDialog(const QString &event_id); + + void hideOverlay(); + void showSolidOverlayModal(QWidget *content, + QFlags<Qt::AlignmentFlag> flags = Qt::AlignCenter); + void showTransparentOverlayModal(QWidget *content, + QFlags<Qt::AlignmentFlag> flags = Qt::AlignTop | + Qt::AlignHCenter); protected: void closeEvent(QCloseEvent *event) override; @@ -138,42 +147,11 @@ private: ChatPage *chat_page_; UserSettingsPage *userSettingsPage_; QSharedPointer<UserSettings> userSettings_; - //! Used to hide undefined states between page transitions. - QSharedPointer<OverlayModal> progressModal_; - QSharedPointer<LoadingIndicator> spinner_; //! Tray icon that shows the unread message count. TrayIcon *trayIcon_; //! Notifications display. - QSharedPointer<SnackBar> snackBar_; - //! Leave room modal. - QSharedPointer<OverlayModal> leaveRoomModal_; - //! Leave room dialog. - QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_; - //! Invite users modal. - QSharedPointer<OverlayModal> inviteUsersModal_; - //! Invite users dialog. - QSharedPointer<dialogs::InviteUsers> inviteUsersDialog_; - //! Join room modal. - QSharedPointer<OverlayModal> joinRoomModal_; - //! Join room dialog. - QSharedPointer<dialogs::JoinRoom> joinRoomDialog_; - //! Create room modal. - QSharedPointer<OverlayModal> createRoomModal_; - //! Create room dialog. - QSharedPointer<dialogs::CreateRoom> createRoomDialog_; - //! Logout modal. - QSharedPointer<OverlayModal> logoutModal_; - //! Logout dialog. - QSharedPointer<dialogs::Logout> logoutDialog_; - //! Room settings modal. - QSharedPointer<OverlayModal> roomSettingsModal_; - //! Room settings dialog. - QSharedPointer<dialogs::RoomSettings> roomSettingsDialog_; - //! Member list modal. - QSharedPointer<OverlayModal> memberListModal_; - //! Member list dialog. - QSharedPointer<dialogs::MemberList> memberListDialog_; - - QSharedPointer<OverlayModal> userProfileModal_; - QSharedPointer<dialogs::UserProfile> userProfileDialog_; + SnackBar *snackBar_ = nullptr; + //! Overlay modal used to project other widgets. + OverlayModal *modal_ = nullptr; + LoadingIndicator *spinner_ = nullptr; }; diff --git a/src/RegisterPage.h b/src/RegisterPage.h index d02de7c4..1f39ab0c 100644 --- a/src/RegisterPage.h +++ b/src/RegisterPage.h @@ -19,7 +19,6 @@ #include <QLabel> #include <QLayout> -#include <QSharedPointer> #include <memory> class FlatButton; diff --git a/src/TopRoomBar.h b/src/TopRoomBar.h index ad74458c..21f8325a 100644 --- a/src/TopRoomBar.h +++ b/src/TopRoomBar.h @@ -24,7 +24,6 @@ #include <QPaintEvent> #include <QPainter> #include <QPen> -#include <QSharedPointer> #include <QStyle> #include <QStyleOption> #include <QVBoxLayout> diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp index df4eaeee..710c3de6 100644 --- a/src/dialogs/RoomSettings.cpp +++ b/src/dialogs/RoomSettings.cpp @@ -4,7 +4,6 @@ #include <QMessageBox> #include <QPainter> #include <QPixmap> -#include <QSharedPointer> #include <QShowEvent> #include <QStyleOption> #include <QVBoxLayout> diff --git a/src/dialogs/RoomSettings.h b/src/dialogs/RoomSettings.h index 192e922f..408804ba 100644 --- a/src/dialogs/RoomSettings.h +++ b/src/dialogs/RoomSettings.h @@ -19,9 +19,6 @@ class TextField; class TextField; class Toggle; -template<class T> -class QSharedPointer; - class EditModal : public QWidget { Q_OBJECT diff --git a/src/dialogs/UserProfile.cpp b/src/dialogs/UserProfile.cpp index c2c42ec4..df334b15 100644 --- a/src/dialogs/UserProfile.cpp +++ b/src/dialogs/UserProfile.cpp @@ -170,8 +170,6 @@ UserProfile::UserProfile(QWidget *parent) vlayout->setContentsMargins(WIDGET_MARGIN, TOP_WIDGET_MARGIN, WIDGET_MARGIN, WIDGET_MARGIN); qRegisterMetaType<std::vector<DeviceInfo>>(); - - connect(this, &UserProfile::devicesRetrieved, this, &UserProfile::updateDeviceList); } void @@ -227,10 +225,15 @@ UserProfile::init(const QString &userId, const QString &roomId) mtx::requests::QueryKeys req; req.device_keys[userId.toStdString()] = {}; + // A proxy object is used to emit the signal instead of the original object + // which might be destroyed by the time the http call finishes. + auto proxy = std::make_shared<Proxy>(); + QObject::connect(proxy.get(), &Proxy::done, this, &UserProfile::updateDeviceList); + http::client()->query_keys( req, - [user_id = userId.toStdString(), this](const mtx::responses::QueryKeys &res, - mtx::http::RequestErr err) { + [user_id = userId.toStdString(), proxy = std::move(proxy), this]( + const mtx::responses::QueryKeys &res, mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to query device keys: {} {}", err->matrix_error.error, @@ -264,7 +267,7 @@ UserProfile::init(const QString &userId, const QString &roomId) }); if (!deviceInfo.empty()) - emit devicesRetrieved(QString::fromStdString(user_id), deviceInfo); + emit proxy->done(QString::fromStdString(user_id), deviceInfo); }); } diff --git a/src/dialogs/UserProfile.h b/src/dialogs/UserProfile.h index 9901771d..7dc1c0c8 100644 --- a/src/dialogs/UserProfile.h +++ b/src/dialogs/UserProfile.h @@ -17,6 +17,14 @@ struct DeviceInfo Q_DECLARE_METATYPE(std::vector<DeviceInfo>) +class Proxy : public QObject +{ + Q_OBJECT + +signals: + void done(const QString &user_id, const std::vector<DeviceInfo> &devices); +}; + namespace dialogs { class DeviceItem : public QWidget @@ -43,9 +51,6 @@ public: protected: void paintEvent(QPaintEvent *) override; -signals: - void devicesRetrieved(const QString &user_id, const std::vector<DeviceInfo> &devices); - private slots: void updateDeviceList(const QString &user_id, const std::vector<DeviceInfo> &devices); diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp index fcbabf5a..ab4461c4 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp @@ -166,7 +166,7 @@ TimelineItem::init() connect(showReadReceipts_, &QAction::triggered, this, [this]() { if (!event_id_.isEmpty()) - ChatPage::instance()->showReadReceipts(event_id_); + MainWindow::instance()->openReadReceiptsDialog(event_id_); }); connect(this, &TimelineItem::eventRedacted, this, [this](const QString &event_id) { diff --git a/src/ui/LoadingIndicator.cpp b/src/ui/LoadingIndicator.cpp index 05b7fff5..c8337089 100644 --- a/src/ui/LoadingIndicator.cpp +++ b/src/ui/LoadingIndicator.cpp @@ -12,17 +12,10 @@ LoadingIndicator::LoadingIndicator(QWidget *parent) setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setFocusPolicy(Qt::NoFocus); - timer_ = new QTimer(); + timer_ = new QTimer(this); connect(timer_, SIGNAL(timeout()), this, SLOT(onTimeout())); } -LoadingIndicator::~LoadingIndicator() -{ - stop(); - - delete timer_; -} - void LoadingIndicator::paintEvent(QPaintEvent *e) { diff --git a/src/ui/LoadingIndicator.h b/src/ui/LoadingIndicator.h index bb33fe6c..e8de0aec 100644 --- a/src/ui/LoadingIndicator.h +++ b/src/ui/LoadingIndicator.h @@ -13,7 +13,6 @@ class LoadingIndicator : public QWidget public: LoadingIndicator(QWidget *parent = 0); - virtual ~LoadingIndicator(); void paintEvent(QPaintEvent *e); diff --git a/src/ui/OverlayModal.cpp b/src/ui/OverlayModal.cpp index 30ebdf5c..abd1827a 100644 --- a/src/ui/OverlayModal.cpp +++ b/src/ui/OverlayModal.cpp @@ -20,18 +20,31 @@ #include "OverlayModal.h" -OverlayModal::OverlayModal(QWidget *parent, QWidget *content) +OverlayModal::OverlayModal(QWidget *parent) : OverlayWidget(parent) - , content_{content} , color_{QColor(30, 30, 30, 170)} { layout_ = new QVBoxLayout(this); - layout_->addWidget(content); layout_->setSpacing(0); layout_->setContentsMargins(10, 40, 10, 20); setContentAlignment(Qt::AlignCenter); +} + +void +OverlayModal::setWidget(QWidget *widget) +{ + // Delete the previous widget + if (layout_->count() > 0) { + QLayoutItem *item; + while ((item = layout_->takeAt(0)) != nullptr) { + delete item->widget(); + delete item; + } + } - content->setFocus(); + layout_->addWidget(widget); + content_ = widget; + content_->setFocus(); } void diff --git a/src/ui/OverlayModal.h b/src/ui/OverlayModal.h index acba7a7a..e1fe8ec0 100644 --- a/src/ui/OverlayModal.h +++ b/src/ui/OverlayModal.h @@ -27,12 +27,13 @@ class OverlayModal : public OverlayWidget { public: - OverlayModal(QWidget *parent, QWidget *content); + OverlayModal(QWidget *parent); void setColor(QColor color) { color_ = color; } void setDismissible(bool state) { isDismissible_ = state; } void setContentAlignment(QFlags<Qt::AlignmentFlag> flag) { layout_->setAlignment(flag); } + void setWidget(QWidget *widget); protected: void paintEvent(QPaintEvent *event) override; |