Use shared pointer for the modals

remotes/origin/HEAD
Konstantinos Sideris 7 years ago
parent 800d9ecff3
commit bc4b47a5e3
  1. 4
      include/ChatPage.h
  2. 2
      include/EmojiPickButton.h
  3. 4
      include/MainWindow.h
  4. 4
      include/RoomList.h
  5. 4
      include/TopRoomBar.h
  6. 4
      include/UserInfoWidget.h
  7. 19
      src/ChatPage.cc
  8. 7
      src/EmojiPickButton.cc
  9. 34
      src/MainWindow.cc
  10. 25
      src/RoomList.cc
  11. 25
      src/TopRoomBar.cc
  12. 13
      src/UserInfoWidget.cc

@ -110,8 +110,8 @@ private:
// Keeps track of the users currently typing on each room.
QMap<QString, QList<QString>> typingUsers_;
QuickSwitcher *quickSwitcher_ = nullptr;
OverlayModal *quickSwitcherModal_ = nullptr;
QSharedPointer<QuickSwitcher> quickSwitcher_;
QSharedPointer<OverlayModal> quickSwitcherModal_;
// Matrix Client API provider.
QSharedPointer<MatrixClient> client_;

@ -43,5 +43,5 @@ private:
// Horizontal distance from panel's bottom right corner.
int horizontal_distance_ = 70;
EmojiPanel *panel_;
QSharedPointer<EmojiPanel> panel_;
};

@ -83,8 +83,8 @@ private:
ChatPage *chat_page_;
// Used to hide undefined states between page transitions.
OverlayModal *progress_modal_;
LoadingIndicator *spinner_;
QSharedPointer<OverlayModal> progressModal_;
QSharedPointer<LoadingIndicator> spinner_;
// Matrix Client API provider.
QSharedPointer<MatrixClient> client_;

@ -76,8 +76,8 @@ private:
OverlayModal *joinRoomModal_;
JoinRoomDialog *joinRoomDialog_;
OverlayModal *leaveRoomModal;
LeaveRoomDialog *leaveRoomDialog_;
QSharedPointer<OverlayModal> leaveRoomModal_;
QSharedPointer<LeaveRoomDialog> leaveRoomDialog_;
QMap<QString, QSharedPointer<RoomInfoListItem>> rooms_;

@ -77,8 +77,8 @@ private:
FlatButton *settingsBtn_;
OverlayModal *leaveRoomModal;
LeaveRoomDialog *leaveRoomDialog_;
QSharedPointer<OverlayModal> leaveRoomModal_;
QSharedPointer<LeaveRoomDialog> leaveRoomDialog_;
Avatar *avatar_;

@ -68,8 +68,8 @@ private:
QImage avatar_image_;
OverlayModal *logoutModal_;
LogoutDialog *logoutDialog_;
QSharedPointer<OverlayModal> logoutModal_;
QSharedPointer<LogoutDialog> logoutDialog_;
int logoutButtonSize_;
};

@ -572,21 +572,26 @@ ChatPage::keyPressEvent(QKeyEvent *event)
void
ChatPage::showQuickSwitcher()
{
if (quickSwitcher_ == nullptr) {
quickSwitcher_ = new QuickSwitcher(this);
if (quickSwitcher_.isNull()) {
quickSwitcher_ = QSharedPointer<QuickSwitcher>(
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<OverlayModal>(
new OverlayModal(MainWindow::instance(), quickSwitcher_.data()),
[=](OverlayModal *modal) { modal->deleteLater(); });
quickSwitcherModal_->setDuration(0);
quickSwitcherModal_->setColor(QColor(30, 30, 30, 170));
}

@ -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<EmojiPanel>(new EmojiPanel(this));
connect(
panel_.data(), &EmojiPanel::emojiSelected, this, &EmojiPickButton::emojiSelected);
}
QPoint pos(rect().x(), rect().y());

@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MainWindow.h"
#include "Config.h"
#include "MainWindow.h"
#include <QApplication>
#include <QLayout>
@ -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 (spinner_ != nullptr)
spinner_->deleteLater();
if (!progressModal_.isNull())
progressModal_->fadeOut();
if (!spinner_.isNull())
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<LoadingIndicator>(
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<OverlayModal>(new OverlayModal(this, spinner_.data()),
[=](OverlayModal *modal) { modal->deleteLater(); });
progressModal_->fadeIn();
progressModal_->setDuration(modalOpacityDuration);
}
login_page_->reset();

@ -168,16 +168,23 @@ RoomList::setInitialRooms(const QMap<QString, QSharedPointer<RoomSettings>> &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<LeaveRoomDialog>(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); });
}
if (leaveRoomModal_.isNull()) {
leaveRoomModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), leaveRoomDialog_.data()));
leaveRoomModal_->setDuration(0);
leaveRoomModal_->setColor(QColor(30, 30, 30, 170));
}
leaveRoomModal->fadeIn();
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);

@ -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<LeaveRoomDialog>(new LeaveRoomDialog(this));
connect(leaveRoomDialog_.data(),
SIGNAL(closing(bool)),
this,
SLOT(closeLeaveRoomDialog(bool)));
}
leaveRoomModal = new OverlayModal(MainWindow::instance(), leaveRoomDialog_);
leaveRoomModal->setDuration(100);
leaveRoomModal->setColor(QColor(55, 55, 55, 170));
if (leaveRoomModal_.isNull()) {
leaveRoomModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), leaveRoomDialog_.data()));
leaveRoomModal_->setDuration(0);
leaveRoomModal_->setColor(QColor(30, 30, 30, 170));
}
leaveRoomModal->fadeIn();
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();

@ -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<LogoutDialog>(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<OverlayModal>(
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();

Loading…
Cancel
Save