diff --git a/include/ChatPage.h b/include/ChatPage.h index 8332225b..f64d9589 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -110,8 +110,8 @@ private: // Keeps track of the users currently typing on each room. QMap> typingUsers_; - QuickSwitcher *quickSwitcher_ = nullptr; - OverlayModal *quickSwitcherModal_ = nullptr; + QSharedPointer quickSwitcher_; + QSharedPointer quickSwitcherModal_; // Matrix Client API provider. QSharedPointer client_; diff --git a/include/EmojiPickButton.h b/include/EmojiPickButton.h index 041e25a6..d4226165 100644 --- a/include/EmojiPickButton.h +++ b/include/EmojiPickButton.h @@ -43,5 +43,5 @@ private: // Horizontal distance from panel's bottom right corner. int horizontal_distance_ = 70; - EmojiPanel *panel_; + QSharedPointer panel_; }; diff --git a/include/MainWindow.h b/include/MainWindow.h index 85cd5a70..a7a2b2e6 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -83,8 +83,8 @@ private: ChatPage *chat_page_; // Used to hide undefined states between page transitions. - OverlayModal *progress_modal_; - LoadingIndicator *spinner_; + QSharedPointer progressModal_; + QSharedPointer spinner_; // Matrix Client API provider. QSharedPointer client_; diff --git a/include/RoomList.h b/include/RoomList.h index c2f4255d..d7b201f1 100644 --- a/include/RoomList.h +++ b/include/RoomList.h @@ -76,8 +76,8 @@ private: OverlayModal *joinRoomModal_; JoinRoomDialog *joinRoomDialog_; - OverlayModal *leaveRoomModal; - LeaveRoomDialog *leaveRoomDialog_; + QSharedPointer leaveRoomModal_; + QSharedPointer leaveRoomDialog_; QMap> rooms_; diff --git a/include/TopRoomBar.h b/include/TopRoomBar.h index 5d8b394e..2c7af218 100644 --- a/include/TopRoomBar.h +++ b/include/TopRoomBar.h @@ -77,8 +77,8 @@ private: FlatButton *settingsBtn_; - OverlayModal *leaveRoomModal; - LeaveRoomDialog *leaveRoomDialog_; + QSharedPointer leaveRoomModal_; + QSharedPointer leaveRoomDialog_; Avatar *avatar_; diff --git a/include/UserInfoWidget.h b/include/UserInfoWidget.h index 25dc2265..b2c7b876 100644 --- a/include/UserInfoWidget.h +++ b/include/UserInfoWidget.h @@ -68,8 +68,8 @@ private: QImage avatar_image_; - OverlayModal *logoutModal_; - LogoutDialog *logoutDialog_; + QSharedPointer logoutModal_; + QSharedPointer logoutDialog_; int logoutButtonSize_; }; diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 0800fe32..dbffc6d0 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -572,21 +572,26 @@ ChatPage::keyPressEvent(QKeyEvent *event) void ChatPage::showQuickSwitcher() { - if (quickSwitcher_ == nullptr) { - quickSwitcher_ = new QuickSwitcher(this); + if (quickSwitcher_.isNull()) { + quickSwitcher_ = QSharedPointer( + new QuickSwitcher(this), + [=](QuickSwitcher *switcher) { switcher->deleteLater(); }); - connect(quickSwitcher_, + connect(quickSwitcher_.data(), &QuickSwitcher::roomSelected, room_list_, &RoomList::highlightSelectedRoom); - connect(quickSwitcher_, &QuickSwitcher::closing, this, [=]() { - if (this->quickSwitcherModal_ != nullptr) + + connect(quickSwitcher_.data(), &QuickSwitcher::closing, this, [=]() { + if (!this->quickSwitcherModal_.isNull()) this->quickSwitcherModal_->fadeOut(); }); } - if (quickSwitcherModal_ == nullptr) { - quickSwitcherModal_ = new OverlayModal(MainWindow::instance(), quickSwitcher_); + if (quickSwitcherModal_.isNull()) { + quickSwitcherModal_ = QSharedPointer( + new OverlayModal(MainWindow::instance(), quickSwitcher_.data()), + [=](OverlayModal *modal) { modal->deleteLater(); }); quickSwitcherModal_->setDuration(0); quickSwitcherModal_->setColor(QColor(30, 30, 30, 170)); } diff --git a/src/EmojiPickButton.cc b/src/EmojiPickButton.cc index f3e30661..4f7dd59e 100644 --- a/src/EmojiPickButton.cc +++ b/src/EmojiPickButton.cc @@ -30,9 +30,10 @@ EmojiPickButton::enterEvent(QEvent *e) { Q_UNUSED(e); - if (panel_ == nullptr) { - panel_ = new EmojiPanel(this); - connect(panel_, &EmojiPanel::emojiSelected, this, &EmojiPickButton::emojiSelected); + if (panel_.isNull()) { + panel_ = QSharedPointer(new EmojiPanel(this)); + connect( + panel_.data(), &EmojiPanel::emojiSelected, this, &EmojiPickButton::emojiSelected); } QPoint pos(rect().x(), rect().y()); diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 43f4a949..80726683 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#include "MainWindow.h" #include "Config.h" +#include "MainWindow.h" #include #include @@ -29,7 +29,7 @@ MainWindow *MainWindow::instance_ = nullptr; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) - , progress_modal_{ nullptr } + , progressModal_{ nullptr } , spinner_{ nullptr } { QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); @@ -132,18 +132,14 @@ MainWindow::removeOverlayProgressBar() connect(timer, &QTimer::timeout, [=]() { timer->deleteLater(); - if (progress_modal_ != nullptr) { - progress_modal_->deleteLater(); - progress_modal_->fadeOut(); - } + if (!progressModal_.isNull()) + progressModal_->fadeOut(); - if (spinner_ != nullptr) - spinner_->deleteLater(); + if (!spinner_.isNull()) + spinner_->stop(); - spinner_->stop(); - - progress_modal_ = nullptr; - spinner_ = nullptr; + progressModal_.reset(); + spinner_.reset(); }); timer->start(500); @@ -166,18 +162,22 @@ MainWindow::showChatPage(QString userid, QString homeserver, QString token) QTimer::singleShot( modalOpacityDuration + 100, this, [=]() { pageStack_->setCurrentWidget(chat_page_); }); - if (spinner_ == nullptr) { - spinner_ = new LoadingIndicator(this); + if (spinner_.isNull()) { + spinner_ = QSharedPointer( + new LoadingIndicator(this), + [=](LoadingIndicator *indicator) { indicator->deleteLater(); }); spinner_->setColor("#acc7dc"); spinner_->setFixedHeight(120); spinner_->setFixedWidth(120); spinner_->start(); } - if (progress_modal_ == nullptr) { - progress_modal_ = new OverlayModal(this, spinner_); - progress_modal_->fadeIn(); - progress_modal_->setDuration(modalOpacityDuration); + if (progressModal_.isNull()) { + progressModal_ = + QSharedPointer(new OverlayModal(this, spinner_.data()), + [=](OverlayModal *modal) { modal->deleteLater(); }); + progressModal_->fadeIn(); + progressModal_->setDuration(modalOpacityDuration); } login_page_->reset(); diff --git a/src/RoomList.cc b/src/RoomList.cc index 0383be6e..90d8b83c 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -168,16 +168,23 @@ RoomList::setInitialRooms(const QMap> &set void RoomList::openLeaveRoomDialog(const QString &room_id) { - leaveRoomDialog_ = new LeaveRoomDialog(this); - connect(leaveRoomDialog_, &LeaveRoomDialog::closing, this, [=](bool leaving) { - closeLeaveRoomDialog(leaving, room_id); - }); + if (leaveRoomDialog_.isNull()) { + leaveRoomDialog_ = QSharedPointer(new LeaveRoomDialog(this)); - leaveRoomModal = new OverlayModal(MainWindow::instance(), leaveRoomDialog_); - leaveRoomModal->setDuration(0); - leaveRoomModal->setColor(QColor(55, 55, 55, 170)); + connect(leaveRoomDialog_.data(), + &LeaveRoomDialog::closing, + this, + [=](bool leaving) { closeLeaveRoomDialog(leaving, room_id); }); + } - leaveRoomModal->fadeIn(); + if (leaveRoomModal_.isNull()) { + leaveRoomModal_ = QSharedPointer( + new OverlayModal(MainWindow::instance(), leaveRoomDialog_.data())); + leaveRoomModal_->setDuration(0); + leaveRoomModal_->setColor(QColor(30, 30, 30, 170)); + } + + leaveRoomModal_->fadeIn(); } void @@ -266,7 +273,7 @@ RoomList::closeJoinRoomDialog(bool isJoining, QString roomAlias) void RoomList::closeLeaveRoomDialog(bool leaving, const QString &room_id) { - leaveRoomModal->fadeOut(); + leaveRoomModal_->fadeOut(); if (leaving) { client_->leaveRoom(room_id); diff --git a/src/TopRoomBar.cc b/src/TopRoomBar.cc index f8a7e600..3f93cad3 100644 --- a/src/TopRoomBar.cc +++ b/src/TopRoomBar.cc @@ -86,15 +86,24 @@ TopRoomBar::TopRoomBar(QWidget *parent) leaveRoom_ = new QAction(tr("Leave room"), this); connect(leaveRoom_, &QAction::triggered, this, [=]() { - leaveRoomDialog_ = new LeaveRoomDialog(this); - connect( - leaveRoomDialog_, SIGNAL(closing(bool)), this, SLOT(closeLeaveRoomDialog(bool))); + if (leaveRoomDialog_.isNull()) { + leaveRoomDialog_ = + QSharedPointer(new LeaveRoomDialog(this)); - leaveRoomModal = new OverlayModal(MainWindow::instance(), leaveRoomDialog_); - leaveRoomModal->setDuration(100); - leaveRoomModal->setColor(QColor(55, 55, 55, 170)); + connect(leaveRoomDialog_.data(), + SIGNAL(closing(bool)), + this, + SLOT(closeLeaveRoomDialog(bool))); + } - leaveRoomModal->fadeIn(); + if (leaveRoomModal_.isNull()) { + leaveRoomModal_ = QSharedPointer( + new OverlayModal(MainWindow::instance(), leaveRoomDialog_.data())); + leaveRoomModal_->setDuration(0); + leaveRoomModal_->setColor(QColor(30, 30, 30, 170)); + } + + leaveRoomModal_->fadeIn(); }); menu_->addAction(toggleNotifications_); @@ -117,7 +126,7 @@ TopRoomBar::TopRoomBar(QWidget *parent) void TopRoomBar::closeLeaveRoomDialog(bool leaving) { - leaveRoomModal->fadeOut(); + leaveRoomModal_->fadeOut(); if (leaving) { emit leaveRoom(); diff --git a/src/UserInfoWidget.cc b/src/UserInfoWidget.cc index b65329da..09a75a3b 100644 --- a/src/UserInfoWidget.cc +++ b/src/UserInfoWidget.cc @@ -93,18 +93,19 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) // Show the confirmation dialog. connect(logoutButton_, &QPushButton::clicked, this, [=]() { - if (logoutDialog_ == nullptr) { - logoutDialog_ = new LogoutDialog(this); - connect(logoutDialog_, + if (logoutDialog_.isNull()) { + logoutDialog_ = QSharedPointer(new LogoutDialog(this)); + connect(logoutDialog_.data(), SIGNAL(closing(bool)), this, SLOT(closeLogoutDialog(bool))); } - if (logoutModal_ == nullptr) { - logoutModal_ = new OverlayModal(MainWindow::instance(), logoutDialog_); + if (logoutModal_.isNull()) { + logoutModal_ = QSharedPointer( + new OverlayModal(MainWindow::instance(), logoutDialog_.data())); logoutModal_->setDuration(0); - logoutModal_->setColor(QColor(55, 55, 55, 170)); + logoutModal_->setColor(QColor(30, 30, 30, 170)); } logoutModal_->fadeIn();