From b8c8fed655bd54b9bc805fd599577e87a239788d Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 2 Jun 2017 18:04:51 +0300 Subject: [PATCH] Show confirmation dialog on logout Minor stylistic refactoring closes #29 --- CMakeLists.txt | 2 ++ include/LogoutDialog.h | 36 +++++++++++++++++++++++++ include/MainWindow.h | 4 +++ include/UserInfoWidget.h | 10 +++++++ src/LoginPage.cc | 3 --- src/LogoutDialog.cc | 57 ++++++++++++++++++++++++++++++++++++++++ src/MainWindow.cc | 9 +++++++ src/RegisterPage.cc | 2 -- src/TextInputWidget.cc | 3 --- src/TopRoomBar.cc | 1 - src/UserInfoWidget.cc | 38 ++++++++++++++++++++++++--- src/WelcomePage.cc | 2 -- src/ui/FlatButton.cc | 3 ++- 13 files changed, 155 insertions(+), 15 deletions(-) create mode 100644 include/LogoutDialog.h create mode 100644 src/LogoutDialog.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index f50f618d..f6f88e4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,7 @@ set(SRC_FILES src/Login.cc src/LoginPage.cc src/LoginSettings.cc + src/LogoutDialog.cc src/MainWindow.cc src/MatrixClient.cc src/Profile.cc @@ -171,6 +172,7 @@ qt5_wrap_cpp(MOC_HEADERS include/TimelineViewManager.h include/LoginPage.h include/LoginSettings.h + include/LogoutDialog.h include/MainWindow.h include/MatrixClient.h include/RegisterPage.h diff --git a/include/LogoutDialog.h b/include/LogoutDialog.h new file mode 100644 index 00000000..a2d313c7 --- /dev/null +++ b/include/LogoutDialog.h @@ -0,0 +1,36 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +#include "FlatButton.h" + +class LogoutDialog : public QFrame +{ + Q_OBJECT +public: + explicit LogoutDialog(QWidget *parent = nullptr); + +signals: + void closing(bool isLoggingOut); + +private: + FlatButton *confirmBtn_; + FlatButton *cancelBtn_; +}; diff --git a/include/MainWindow.h b/include/MainWindow.h index 536cea13..9d0a601f 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -38,6 +38,8 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + static MainWindow *instance(); + protected: void closeEvent(QCloseEvent *event); @@ -62,6 +64,8 @@ private slots: private: bool hasActiveUser(); + static MainWindow *instance_; + // The initial welcome screen. WelcomePage *welcome_page_; diff --git a/include/UserInfoWidget.h b/include/UserInfoWidget.h index 1b819577..10c770d8 100644 --- a/include/UserInfoWidget.h +++ b/include/UserInfoWidget.h @@ -24,6 +24,8 @@ #include "Avatar.h" #include "FlatButton.h" +#include "LogoutDialog.h" +#include "OverlayModal.h" class UserInfoWidget : public QWidget { @@ -45,6 +47,9 @@ signals: protected: void resizeEvent(QResizeEvent *event) override; +private slots: + void closeLogoutDialog(bool isLoggingOut); + private: Avatar *userAvatar_; @@ -62,4 +67,9 @@ private: QString user_id_; QImage avatar_image_; + + OverlayModal *logoutModal_; + LogoutDialog *logoutDialog_; + + int logoutButtonSize_; }; diff --git a/src/LoginPage.cc b/src/LoginPage.cc index 4514b607..4329baad 100644 --- a/src/LoginPage.cc +++ b/src/LoginPage.cc @@ -37,12 +37,10 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) back_button_ = new FlatButton(this); back_button_->setMinimumSize(QSize(30, 30)); back_button_->setForegroundColor("#333333"); - back_button_->setCursor(QCursor(Qt::PointingHandCursor)); advanced_settings_button_ = new FlatButton(this); advanced_settings_button_->setMinimumSize(QSize(30, 30)); advanced_settings_button_->setForegroundColor("#333333"); - advanced_settings_button_->setCursor(QCursor(Qt::PointingHandCursor)); QIcon icon; icon.addFile(":/icons/icons/left-angle.png", QSize(), QIcon::Normal, QIcon::Off); @@ -105,7 +103,6 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) login_button_->setBackgroundColor(QColor("#333333")); login_button_->setForegroundColor(QColor("white")); login_button_->setMinimumSize(350, 65); - login_button_->setCursor(QCursor(Qt::PointingHandCursor)); login_button_->setFontSize(17); login_button_->setCornerRadius(3); diff --git a/src/LogoutDialog.cc b/src/LogoutDialog.cc new file mode 100644 index 00000000..b8d55449 --- /dev/null +++ b/src/LogoutDialog.cc @@ -0,0 +1,57 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "LogoutDialog.h" +#include "Theme.h" + +LogoutDialog::LogoutDialog(QWidget *parent) + : QFrame(parent) +{ + setMaximumSize(400, 400); + setStyleSheet("background-color: #f9f9f9"); + + auto layout = new QVBoxLayout(this); + layout->setSpacing(30); + layout->setMargin(20); + + auto buttonLayout = new QHBoxLayout(); + buttonLayout->setSpacing(0); + buttonLayout->setMargin(0); + + confirmBtn_ = new FlatButton("OK", this); + confirmBtn_->setFontSize(12); + + cancelBtn_ = new FlatButton(tr("CANCEL"), this); + cancelBtn_->setFontSize(12); + + buttonLayout->addStretch(1); + buttonLayout->addWidget(confirmBtn_); + buttonLayout->addWidget(cancelBtn_); + + auto label = new QLabel(tr("Logout. Are you sure?"), this); + label->setFont(QFont("Open Sans", 14)); + label->setStyleSheet("color: #333333"); + + layout->addWidget(label); + layout->addLayout(buttonLayout); + + connect(confirmBtn_, &QPushButton::clicked, [=]() { emit closing(true); }); + connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false); }); +} diff --git a/src/MainWindow.cc b/src/MainWindow.cc index ce7ca206..783ad5ff 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -22,6 +22,8 @@ #include #include +MainWindow *MainWindow::instance_ = nullptr; + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , progress_modal_{nullptr} @@ -148,6 +150,8 @@ void MainWindow::showChatPage(QString userid, QString homeserver, QString token) login_page_->reset(); chat_page_->bootstrap(userid, homeserver, token); + + instance_ = this; } void MainWindow::showWelcomePage() @@ -204,6 +208,11 @@ bool MainWindow::hasActiveUser() settings.contains("auth/user_id"); } +MainWindow *MainWindow::instance() +{ + return instance_; +} + MainWindow::~MainWindow() { } diff --git a/src/RegisterPage.cc b/src/RegisterPage.cc index 33df0b62..867ac7f1 100644 --- a/src/RegisterPage.cc +++ b/src/RegisterPage.cc @@ -35,7 +35,6 @@ RegisterPage::RegisterPage(QSharedPointer client, QWidget *parent) back_button_ = new FlatButton(this); back_button_->setMinimumSize(QSize(30, 30)); - back_button_->setCursor(QCursor(Qt::PointingHandCursor)); QIcon icon; icon.addFile(":/icons/icons/left-angle.png", QSize(), QIcon::Normal, QIcon::Off); @@ -109,7 +108,6 @@ RegisterPage::RegisterPage(QSharedPointer client, QWidget *parent) register_button_->setBackgroundColor(QColor("#333333")); register_button_->setForegroundColor(QColor("white")); register_button_->setMinimumSize(350, 65); - register_button_->setCursor(QCursor(Qt::PointingHandCursor)); register_button_->setFontSize(17); register_button_->setCornerRadius(3); diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc index 796a1353..82cc8b4e 100644 --- a/src/TextInputWidget.cc +++ b/src/TextInputWidget.cc @@ -50,7 +50,6 @@ TextInputWidget::TextInputWidget(QWidget *parent) top_layout_->setMargin(0); send_file_button_ = new FlatButton(this); - send_file_button_->setCursor(Qt::PointingHandCursor); QIcon send_file_icon; send_file_icon.addFile(":/icons/icons/clip-dark.png", QSize(), QIcon::Normal, QIcon::Off); @@ -64,7 +63,6 @@ TextInputWidget::TextInputWidget(QWidget *parent) input_->setStyleSheet("color: #333333; font-size: 13px; border-radius: 0; padding-top: 10px;"); send_message_button_ = new FlatButton(this); - send_message_button_->setCursor(Qt::PointingHandCursor); send_message_button_->setForegroundColor(QColor("#acc7dc")); QIcon send_message_icon; @@ -73,7 +71,6 @@ TextInputWidget::TextInputWidget(QWidget *parent) send_message_button_->setIconSize(QSize(24, 24)); emoji_button_ = new EmojiPickButton(this); - emoji_button_->setCursor(Qt::PointingHandCursor); emoji_button_->setForegroundColor(QColor("#acc7dc")); QIcon emoji_icon; diff --git a/src/TopRoomBar.cc b/src/TopRoomBar.cc index 2f04129e..4b4c8aa5 100644 --- a/src/TopRoomBar.cc +++ b/src/TopRoomBar.cc @@ -52,7 +52,6 @@ TopRoomBar::TopRoomBar(QWidget *parent) settingsBtn_ = new FlatButton(this); settingsBtn_->setForegroundColor(QColor("#acc7dc")); - settingsBtn_->setCursor(QCursor(Qt::PointingHandCursor)); settingsBtn_->setFixedSize(buttonSize_, buttonSize_); settingsBtn_->setCornerRadius(buttonSize_ / 2); diff --git a/src/UserInfoWidget.cc b/src/UserInfoWidget.cc index 2fca8925..361689ef 100644 --- a/src/UserInfoWidget.cc +++ b/src/UserInfoWidget.cc @@ -16,14 +16,19 @@ */ #include +#include #include "FlatButton.h" +#include "MainWindow.h" #include "UserInfoWidget.h" UserInfoWidget::UserInfoWidget(QWidget *parent) : QWidget(parent) , display_name_("User") , user_id_("@user:homeserver.org") + , logoutModal_{nullptr} + , logoutDialog_{nullptr} + , logoutButtonSize_{32} { QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); setSizePolicy(sizePolicy); @@ -72,19 +77,46 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) logoutButton_ = new FlatButton(this); logoutButton_->setForegroundColor(QColor("#555459")); - logoutButton_->setCursor(QCursor(Qt::PointingHandCursor)); + logoutButton_->setFixedSize(logoutButtonSize_, logoutButtonSize_); + logoutButton_->setCornerRadius(logoutButtonSize_ / 2); QIcon icon; icon.addFile(":/icons/icons/power-button-off.png", QSize(), QIcon::Normal, QIcon::Off); logoutButton_->setIcon(icon); - logoutButton_->setIconSize(QSize(16, 16)); + logoutButton_->setIconSize(QSize(logoutButtonSize_ / 2, logoutButtonSize_ / 2)); buttonLayout_->addWidget(logoutButton_); topLayout_->addLayout(buttonLayout_); - connect(logoutButton_, SIGNAL(clicked()), this, SIGNAL(logout())); + // Show the confirmation dialog. + connect(logoutButton_, &QPushButton::clicked, this, [=]() { + if (logoutDialog_ == nullptr) { + logoutDialog_ = new LogoutDialog(this); + connect(logoutDialog_, SIGNAL(closing(bool)), this, SLOT(closeLogoutDialog(bool))); + } + + if (logoutModal_ == nullptr) { + logoutModal_ = new OverlayModal(MainWindow::instance(), logoutDialog_); + logoutModal_->setDuration(100); + logoutModal_->setColor(QColor(55, 55, 55, 170)); + } + + logoutModal_->fadeIn(); + }); +} + +void UserInfoWidget::closeLogoutDialog(bool isLoggingOut) +{ + logoutModal_->fadeOut(); + + if (isLoggingOut) { + // Waiting for the modal to fade out. + QTimer::singleShot(100, this, [=]() { + emit logout(); + }); + } } UserInfoWidget::~UserInfoWidget() diff --git a/src/WelcomePage.cc b/src/WelcomePage.cc index b88c4db1..67d64120 100644 --- a/src/WelcomePage.cc +++ b/src/WelcomePage.cc @@ -61,7 +61,6 @@ WelcomePage::WelcomePage(QWidget *parent) register_button_->setBackgroundColor(QColor("#333333")); register_button_->setForegroundColor(QColor("white")); register_button_->setMinimumSize(240, 60); - register_button_->setCursor(QCursor(Qt::PointingHandCursor)); register_button_->setFontSize(14); register_button_->setCornerRadius(3); @@ -69,7 +68,6 @@ WelcomePage::WelcomePage(QWidget *parent) login_button_->setBackgroundColor(QColor("#333333")); login_button_->setForegroundColor(QColor("white")); login_button_->setMinimumSize(240, 60); - login_button_->setCursor(QCursor(Qt::PointingHandCursor)); login_button_->setFontSize(14); login_button_->setCornerRadius(3); diff --git a/src/ui/FlatButton.cc b/src/ui/FlatButton.cc index a4f42a5d..183b2294 100644 --- a/src/ui/FlatButton.cc +++ b/src/ui/FlatButton.cc @@ -29,6 +29,7 @@ void FlatButton::init() setStyle(&ThemeManager::instance()); setAttribute(Qt::WA_Hover); setMouseTracking(true); + setCursor(QCursor(Qt::PointingHandCursor)); QPainterPath path; path.addRoundedRect(rect(), corner_radius_, corner_radius_); @@ -336,7 +337,7 @@ void FlatButton::mousePressEvent(QMouseEvent *event) ripple->setOpacityStartValue(0.35); ripple->setColor(foregroundColor()); ripple->radiusAnimation()->setDuration(250); - ripple->opacityAnimation()->setDuration(400); + ripple->opacityAnimation()->setDuration(250); ripple_overlay_->addRipple(ripple); }