Simplify dialog creation

This commit is contained in:
Konstantinos Sideris 2018-08-11 13:50:56 +03:00
parent a339f5062f
commit aa2f6ce77d
16 changed files with 179 additions and 272 deletions

View file

@ -835,31 +835,15 @@ ChatPage::loadStateFromCache()
void void
ChatPage::showQuickSwitcher() ChatPage::showQuickSwitcher()
{ {
if (quickSwitcher_.isNull()) { auto dialog = new QuickSwitcher(this);
quickSwitcher_ = QSharedPointer<QuickSwitcher>(
new QuickSwitcher(this),
[](QuickSwitcher *switcher) { switcher->deleteLater(); });
connect(quickSwitcher_.data(), connect(dialog, &QuickSwitcher::roomSelected, room_list_, &RoomList::highlightSelectedRoom);
&QuickSwitcher::roomSelected, connect(dialog, &QuickSwitcher::closing, this, [this]() {
room_list_, MainWindow::instance()->hideOverlay();
&RoomList::highlightSelectedRoom);
connect(quickSwitcher_.data(), &QuickSwitcher::closing, this, [this]() {
if (!quickSwitcherModal_.isNull())
quickSwitcherModal_->hide();
text_input_->setFocus(Qt::FocusReason::PopupFocusReason); text_input_->setFocus(Qt::FocusReason::PopupFocusReason);
}); });
}
if (quickSwitcherModal_.isNull()) { MainWindow::instance()->showTransparentOverlayModal(dialog);
quickSwitcherModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), quickSwitcher_.data()),
[](OverlayModal *modal) { modal->deleteLater(); });
quickSwitcherModal_->setColor(QColor(30, 30, 30, 170));
}
quickSwitcherModal_->show();
} }
void void
@ -917,26 +901,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 void
ChatPage::setGroupViewState(bool isEnabled) ChatPage::setGroupViewState(bool isEnabled)
{ {

View file

@ -44,10 +44,6 @@ class UserInfoWidget;
class UserSettings; class UserSettings;
class NotificationsManager; class NotificationsManager;
namespace dialogs {
class ReadReceipts;
}
constexpr int CONSENSUS_TIMEOUT = 1000; constexpr int CONSENSUS_TIMEOUT = 1000;
constexpr int SHOW_CONTENT_TIMEOUT = 3000; constexpr int SHOW_CONTENT_TIMEOUT = 3000;
constexpr int TYPING_REFRESH_TIMEOUT = 10000; constexpr int TYPING_REFRESH_TIMEOUT = 10000;
@ -62,7 +58,6 @@ public:
// Initialize all the components of the UI. // Initialize all the components of the UI.
void bootstrap(QString userid, QString homeserver, QString token); void bootstrap(QString userid, QString homeserver, QString token);
void showQuickSwitcher(); void showQuickSwitcher();
void showReadReceipts(const QString &event_id);
QString currentRoom() const { return current_room_; } QString currentRoom() const { return current_room_; }
static ChatPage *instance() { return instance_; } static ChatPage *instance() { return instance_; }
@ -237,12 +232,6 @@ private:
std::map<QString, QList<QString>> typingUsers_; std::map<QString, QList<QString>> typingUsers_;
QTimer *typingRefresher_; QTimer *typingRefresher_;
QSharedPointer<QuickSwitcher> quickSwitcher_;
QSharedPointer<OverlayModal> quickSwitcherModal_;
QSharedPointer<dialogs::ReadReceipts> receiptsDialog_;
QSharedPointer<OverlayModal> receiptsModal_;
// Global user settings. // Global user settings.
QSharedPointer<UserSettings> userSettings_; QSharedPointer<UserSettings> userSettings_;

View file

@ -19,7 +19,6 @@
#include <QLabel> #include <QLabel>
#include <QLayout> #include <QLayout>
#include <QSharedPointer>
#include <QWidget> #include <QWidget>
class FlatButton; class FlatButton;

View file

@ -42,18 +42,19 @@
#include "dialogs/LeaveRoom.h" #include "dialogs/LeaveRoom.h"
#include "dialogs/Logout.h" #include "dialogs/Logout.h"
#include "dialogs/MemberList.h" #include "dialogs/MemberList.h"
#include "dialogs/ReadReceipts.h"
#include "dialogs/RoomSettings.h" #include "dialogs/RoomSettings.h"
MainWindow *MainWindow::instance_ = nullptr; MainWindow *MainWindow::instance_ = nullptr;
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, progressModal_{nullptr}
, spinner_{nullptr}
{ {
setWindowTitle("nheko"); setWindowTitle("nheko");
setObjectName("MainWindow"); setObjectName("MainWindow");
modal_ = new OverlayModal(this);
restoreWindowSize(); restoreWindowSize();
QFont font("Open Sans"); QFont font("Open Sans");
@ -223,26 +224,20 @@ MainWindow::removeOverlayProgressBar()
connect(timer, &QTimer::timeout, [this, timer]() { connect(timer, &QTimer::timeout, [this, timer]() {
timer->deleteLater(); timer->deleteLater();
if (!progressModal_.isNull()) if (modal_)
progressModal_->hide(); modal_->hide();
if (!spinner_.isNull()) if (spinner_)
spinner_->stop(); spinner_->stop();
progressModal_.reset();
spinner_.reset();
}); });
// FIXME: Snackbar doesn't work if it's initialized in the constructor. // FIXME: Snackbar doesn't work if it's initialized in the constructor.
QTimer::singleShot(0, this, [this]() { QTimer::singleShot(0, this, [this]() {
snackBar_ = QSharedPointer<SnackBar>(new SnackBar(this)); snackBar_ = new SnackBar(this);
connect(chat_page_, connect(chat_page_, &ChatPage::showNotification, snackBar_, &SnackBar::showMessage);
&ChatPage::showNotification,
snackBar_.data(),
&SnackBar::showMessage);
}); });
timer->start(500); timer->start(50);
} }
void void
@ -312,18 +307,10 @@ MainWindow::hasActiveUser()
void void
MainWindow::openUserProfile(const QString &user_id, const QString &room_id) MainWindow::openUserProfile(const QString &user_id, const QString &room_id)
{ {
if (!userProfileDialog_) auto dialog = new dialogs::UserProfile(this);
userProfileDialog_ = dialog->init(user_id, room_id);
QSharedPointer<dialogs::UserProfile>(new dialogs::UserProfile(this));
userProfileDialog_->init(user_id, room_id); showTransparentOverlayModal(dialog);
if (!userProfileModal_)
userProfileModal_ =
QSharedPointer<OverlayModal>(new OverlayModal(this, userProfileDialog_.data()));
userProfileModal_->setContentAlignment(Qt::AlignTop | Qt::AlignHCenter);
userProfileModal_->show();
} }
void void
@ -331,18 +318,13 @@ MainWindow::openRoomSettings(const QString &room_id)
{ {
const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : ""; const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : "";
roomSettingsDialog_ = auto dialog = new dialogs::RoomSettings(roomToSearch, this);
QSharedPointer<dialogs::RoomSettings>(new dialogs::RoomSettings(roomToSearch, this)); connect(dialog, &dialogs::RoomSettings::closing, this, [this]() {
if (modal_)
connect(roomSettingsDialog_.data(), &dialogs::RoomSettings::closing, this, [this]() { modal_->hide();
roomSettingsModal_->hide();
}); });
roomSettingsModal_ = showTransparentOverlayModal(dialog);
QSharedPointer<OverlayModal>(new OverlayModal(this, roomSettingsDialog_.data()));
roomSettingsModal_->setContentAlignment(Qt::AlignTop | Qt::AlignHCenter);
roomSettingsModal_->show();
} }
void void
@ -350,13 +332,8 @@ MainWindow::openMemberListDialog(const QString &room_id)
{ {
const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : ""; const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : "";
memberListDialog_ = modal_->setWidget(new dialogs::MemberList(roomToSearch, this));
QSharedPointer<dialogs::MemberList>(new dialogs::MemberList(roomToSearch, this)); modal_->show();
memberListModal_ =
QSharedPointer<OverlayModal>(new OverlayModal(this, memberListDialog_.data()));
memberListModal_->show();
} }
void void
@ -364,161 +341,146 @@ MainWindow::openLeaveRoomDialog(const QString &room_id)
{ {
auto roomToLeave = room_id.isEmpty() ? chat_page_->currentRoom() : room_id; auto roomToLeave = room_id.isEmpty() ? chat_page_->currentRoom() : room_id;
leaveRoomDialog_ = QSharedPointer<dialogs::LeaveRoom>(new dialogs::LeaveRoom(this)); auto dialog = new dialogs::LeaveRoom(this);
connect(dialog, &dialogs::LeaveRoom::closing, this, [this, roomToLeave](bool leaving) {
connect(leaveRoomDialog_.data(), if (modal_)
&dialogs::LeaveRoom::closing, modal_->hide();
this,
[this, roomToLeave](bool leaving) {
leaveRoomModal_->hide();
if (leaving) if (leaving)
chat_page_->leaveRoom(roomToLeave); chat_page_->leaveRoom(roomToLeave);
}); });
leaveRoomModal_ = showTransparentOverlayModal(dialog, Qt::AlignCenter);
QSharedPointer<OverlayModal>(new OverlayModal(this, leaveRoomDialog_.data()));
leaveRoomModal_->setColor(QColor(30, 30, 30, 170));
leaveRoomModal_->show();
} }
void void
MainWindow::showOverlayProgressBar() MainWindow::showOverlayProgressBar()
{ {
if (spinner_.isNull()) { spinner_ = new LoadingIndicator(this);
spinner_ = QSharedPointer<LoadingIndicator>(
new LoadingIndicator(this),
[](LoadingIndicator *indicator) { indicator->deleteLater(); });
spinner_->setFixedHeight(100); spinner_->setFixedHeight(100);
spinner_->setFixedWidth(100); spinner_->setFixedWidth(100);
spinner_->setObjectName("ChatPageLoadSpinner"); spinner_->setObjectName("ChatPageLoadSpinner");
spinner_->start(); spinner_->start();
}
if (progressModal_.isNull()) { showSolidOverlayModal(spinner_);
progressModal_ =
QSharedPointer<OverlayModal>(new OverlayModal(this, spinner_.data()),
[](OverlayModal *modal) { modal->deleteLater(); });
progressModal_->setColor(QColor(30, 30, 30));
progressModal_->setDismissible(false);
progressModal_->show();
}
} }
void void
MainWindow::openInviteUsersDialog(std::function<void(const QStringList &invitees)> callback) MainWindow::openInviteUsersDialog(std::function<void(const QStringList &invitees)> callback)
{ {
if (inviteUsersDialog_.isNull()) { auto dialog = new dialogs::InviteUsers(this);
inviteUsersDialog_ = connect(dialog,
QSharedPointer<dialogs::InviteUsers>(new dialogs::InviteUsers(this));
connect(inviteUsersDialog_.data(),
&dialogs::InviteUsers::closing, &dialogs::InviteUsers::closing,
this, this,
[this, callback](bool isSending, QStringList invitees) { [this, callback](bool isSending, QStringList invitees) {
inviteUsersModal_->hide(); if (modal_)
modal_->hide();
if (isSending && !invitees.isEmpty()) if (isSending && !invitees.isEmpty())
callback(invitees); callback(invitees);
}); });
}
if (inviteUsersModal_.isNull()) { showTransparentOverlayModal(dialog);
inviteUsersModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), inviteUsersDialog_.data()));
inviteUsersModal_->setColor(QColor(30, 30, 30, 170));
}
inviteUsersModal_->show();
} }
void void
MainWindow::openJoinRoomDialog(std::function<void(const QString &room_id)> callback) MainWindow::openJoinRoomDialog(std::function<void(const QString &room_id)> callback)
{ {
if (joinRoomDialog_.isNull()) { auto dialog = new dialogs::JoinRoom(this);
joinRoomDialog_ = QSharedPointer<dialogs::JoinRoom>(new dialogs::JoinRoom(this)); connect(dialog,
connect(joinRoomDialog_.data(),
&dialogs::JoinRoom::closing, &dialogs::JoinRoom::closing,
this, this,
[this, callback](bool isJoining, const QString &room) { [this, callback](bool isJoining, const QString &room) {
joinRoomModal_->hide(); if (modal_)
modal_->hide();
if (isJoining && !room.isEmpty()) if (isJoining && !room.isEmpty())
callback(room); callback(room);
}); });
}
if (joinRoomModal_.isNull()) { showTransparentOverlayModal(dialog, Qt::AlignCenter);
joinRoomModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), joinRoomDialog_.data()));
}
joinRoomModal_->show();
} }
void void
MainWindow::openCreateRoomDialog( MainWindow::openCreateRoomDialog(
std::function<void(const mtx::requests::CreateRoom &request)> callback) std::function<void(const mtx::requests::CreateRoom &request)> callback)
{ {
if (createRoomDialog_.isNull()) { auto dialog = new dialogs::CreateRoom(this);
createRoomDialog_ = connect(dialog,
QSharedPointer<dialogs::CreateRoom>(new dialogs::CreateRoom(this));
connect(
createRoomDialog_.data(),
&dialogs::CreateRoom::closing, &dialogs::CreateRoom::closing,
this, this,
[this, callback](bool isCreating, const mtx::requests::CreateRoom &request) { [this, callback](bool isCreating, const mtx::requests::CreateRoom &request) {
createRoomModal_->hide(); if (modal_)
modal_->hide();
if (isCreating) if (isCreating)
callback(request); callback(request);
}); });
}
if (createRoomModal_.isNull()) { showTransparentOverlayModal(dialog);
createRoomModal_ = QSharedPointer<OverlayModal>( }
new OverlayModal(MainWindow::instance(), createRoomDialog_.data()));
}
createRoomModal_->show(); 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 void
MainWindow::openLogoutDialog(std::function<void()> callback) MainWindow::openLogoutDialog(std::function<void()> callback)
{ {
if (logoutDialog_.isNull()) { auto dialog = new dialogs::Logout(this);
logoutDialog_ = QSharedPointer<dialogs::Logout>(new dialogs::Logout(this)); connect(dialog, &dialogs::Logout::closing, this, [this, callback](bool logging_out) {
connect(logoutDialog_.data(), if (modal_)
&dialogs::Logout::closing, modal_->hide();
this,
[this, callback](bool logging_out) {
logoutModal_->hide();
if (logging_out) if (logging_out)
callback(); 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;
} }
if (logoutModal_.isNull()) { showTransparentOverlayModal(dialog);
logoutModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), logoutDialog_.data()));
}
logoutModal_->show();
} }
bool bool
MainWindow::hasActiveDialogs() const MainWindow::hasActiveDialogs() const
{ {
return (!leaveRoomModal_.isNull() && leaveRoomModal_->isVisible()) || return !modal_ && modal_->isVisible();
(!progressModal_.isNull() && progressModal_->isVisible()) ||
(!inviteUsersModal_.isNull() && inviteUsersModal_->isVisible()) ||
(!joinRoomModal_.isNull() && joinRoomModal_->isVisible()) ||
(!createRoomModal_.isNull() && createRoomModal_->isVisible()) ||
(!logoutModal_.isNull() && logoutModal_->isVisible());
} }
bool bool
@ -527,3 +489,10 @@ MainWindow::pageSupportsTray() const
return !welcome_page_->isVisible() && !login_page_->isVisible() && return !welcome_page_->isVisible() && !login_page_->isVisible() &&
!register_page_->isVisible(); !register_page_->isVisible();
} }
void
MainWindow::hideOverlay()
{
if (modal_)
modal_->hide();
}

View file

@ -29,6 +29,7 @@
#include "UserSettingsPage.h" #include "UserSettingsPage.h"
#include "WelcomePage.h" #include "WelcomePage.h"
#include "dialogs/UserProfile.h" #include "dialogs/UserProfile.h"
#include "ui/OverlayModal.h"
class ChatPage; class ChatPage;
class LoadingIndicator; class LoadingIndicator;
@ -73,6 +74,14 @@ public:
void openRoomSettings(const QString &room_id = ""); void openRoomSettings(const QString &room_id = "");
void openMemberListDialog(const QString &room_id = ""); void openMemberListDialog(const QString &room_id = "");
void openUserProfile(const QString &user_id, 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: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
@ -138,42 +147,11 @@ private:
ChatPage *chat_page_; ChatPage *chat_page_;
UserSettingsPage *userSettingsPage_; UserSettingsPage *userSettingsPage_;
QSharedPointer<UserSettings> userSettings_; 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. //! Tray icon that shows the unread message count.
TrayIcon *trayIcon_; TrayIcon *trayIcon_;
//! Notifications display. //! Notifications display.
QSharedPointer<SnackBar> snackBar_; SnackBar *snackBar_ = nullptr;
//! Leave room modal. //! Overlay modal used to project other widgets.
QSharedPointer<OverlayModal> leaveRoomModal_; OverlayModal *modal_ = nullptr;
//! Leave room dialog. LoadingIndicator *spinner_ = nullptr;
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_;
}; };

View file

@ -19,7 +19,6 @@
#include <QLabel> #include <QLabel>
#include <QLayout> #include <QLayout>
#include <QSharedPointer>
#include <memory> #include <memory>
class FlatButton; class FlatButton;

View file

@ -24,7 +24,6 @@
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter> #include <QPainter>
#include <QPen> #include <QPen>
#include <QSharedPointer>
#include <QStyle> #include <QStyle>
#include <QStyleOption> #include <QStyleOption>
#include <QVBoxLayout> #include <QVBoxLayout>

View file

@ -4,7 +4,6 @@
#include <QMessageBox> #include <QMessageBox>
#include <QPainter> #include <QPainter>
#include <QPixmap> #include <QPixmap>
#include <QSharedPointer>
#include <QShowEvent> #include <QShowEvent>
#include <QStyleOption> #include <QStyleOption>
#include <QVBoxLayout> #include <QVBoxLayout>

View file

@ -19,9 +19,6 @@ class TextField;
class TextField; class TextField;
class Toggle; class Toggle;
template<class T>
class QSharedPointer;
class EditModal : public QWidget class EditModal : public QWidget
{ {
Q_OBJECT Q_OBJECT

View file

@ -170,8 +170,6 @@ UserProfile::UserProfile(QWidget *parent)
vlayout->setContentsMargins(WIDGET_MARGIN, TOP_WIDGET_MARGIN, WIDGET_MARGIN, WIDGET_MARGIN); vlayout->setContentsMargins(WIDGET_MARGIN, TOP_WIDGET_MARGIN, WIDGET_MARGIN, WIDGET_MARGIN);
qRegisterMetaType<std::vector<DeviceInfo>>(); qRegisterMetaType<std::vector<DeviceInfo>>();
connect(this, &UserProfile::devicesRetrieved, this, &UserProfile::updateDeviceList);
} }
void void
@ -227,10 +225,15 @@ UserProfile::init(const QString &userId, const QString &roomId)
mtx::requests::QueryKeys req; mtx::requests::QueryKeys req;
req.device_keys[userId.toStdString()] = {}; 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( http::client()->query_keys(
req, req,
[user_id = userId.toStdString(), this](const mtx::responses::QueryKeys &res, [user_id = userId.toStdString(), proxy = std::move(proxy), this](
mtx::http::RequestErr err) { const mtx::responses::QueryKeys &res, mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn("failed to query device keys: {} {}", nhlog::net()->warn("failed to query device keys: {} {}",
err->matrix_error.error, err->matrix_error.error,
@ -264,7 +267,7 @@ UserProfile::init(const QString &userId, const QString &roomId)
}); });
if (!deviceInfo.empty()) if (!deviceInfo.empty())
emit devicesRetrieved(QString::fromStdString(user_id), deviceInfo); emit proxy->done(QString::fromStdString(user_id), deviceInfo);
}); });
} }

View file

@ -17,6 +17,14 @@ struct DeviceInfo
Q_DECLARE_METATYPE(std::vector<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 { namespace dialogs {
class DeviceItem : public QWidget class DeviceItem : public QWidget
@ -43,9 +51,6 @@ public:
protected: protected:
void paintEvent(QPaintEvent *) override; void paintEvent(QPaintEvent *) override;
signals:
void devicesRetrieved(const QString &user_id, const std::vector<DeviceInfo> &devices);
private slots: private slots:
void updateDeviceList(const QString &user_id, const std::vector<DeviceInfo> &devices); void updateDeviceList(const QString &user_id, const std::vector<DeviceInfo> &devices);

View file

@ -166,7 +166,7 @@ TimelineItem::init()
connect(showReadReceipts_, &QAction::triggered, this, [this]() { connect(showReadReceipts_, &QAction::triggered, this, [this]() {
if (!event_id_.isEmpty()) if (!event_id_.isEmpty())
ChatPage::instance()->showReadReceipts(event_id_); MainWindow::instance()->openReadReceiptsDialog(event_id_);
}); });
connect(this, &TimelineItem::eventRedacted, this, [this](const QString &event_id) { connect(this, &TimelineItem::eventRedacted, this, [this](const QString &event_id) {

View file

@ -12,17 +12,10 @@ LoadingIndicator::LoadingIndicator(QWidget *parent)
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
setFocusPolicy(Qt::NoFocus); setFocusPolicy(Qt::NoFocus);
timer_ = new QTimer(); timer_ = new QTimer(this);
connect(timer_, SIGNAL(timeout()), this, SLOT(onTimeout())); connect(timer_, SIGNAL(timeout()), this, SLOT(onTimeout()));
} }
LoadingIndicator::~LoadingIndicator()
{
stop();
delete timer_;
}
void void
LoadingIndicator::paintEvent(QPaintEvent *e) LoadingIndicator::paintEvent(QPaintEvent *e)
{ {

View file

@ -13,7 +13,6 @@ class LoadingIndicator : public QWidget
public: public:
LoadingIndicator(QWidget *parent = 0); LoadingIndicator(QWidget *parent = 0);
virtual ~LoadingIndicator();
void paintEvent(QPaintEvent *e); void paintEvent(QPaintEvent *e);

View file

@ -20,18 +20,31 @@
#include "OverlayModal.h" #include "OverlayModal.h"
OverlayModal::OverlayModal(QWidget *parent, QWidget *content) OverlayModal::OverlayModal(QWidget *parent)
: OverlayWidget(parent) : OverlayWidget(parent)
, content_{content}
, color_{QColor(30, 30, 30, 170)} , color_{QColor(30, 30, 30, 170)}
{ {
layout_ = new QVBoxLayout(this); layout_ = new QVBoxLayout(this);
layout_->addWidget(content);
layout_->setSpacing(0); layout_->setSpacing(0);
layout_->setContentsMargins(10, 40, 10, 20); layout_->setContentsMargins(10, 40, 10, 20);
setContentAlignment(Qt::AlignCenter); setContentAlignment(Qt::AlignCenter);
}
content->setFocus(); 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;
}
}
layout_->addWidget(widget);
content_ = widget;
content_->setFocus();
} }
void void

View file

@ -27,12 +27,13 @@
class OverlayModal : public OverlayWidget class OverlayModal : public OverlayWidget
{ {
public: public:
OverlayModal(QWidget *parent, QWidget *content); OverlayModal(QWidget *parent);
void setColor(QColor color) { color_ = color; } void setColor(QColor color) { color_ = color; }
void setDismissible(bool state) { isDismissible_ = state; } void setDismissible(bool state) { isDismissible_ = state; }
void setContentAlignment(QFlags<Qt::AlignmentFlag> flag) { layout_->setAlignment(flag); } void setContentAlignment(QFlags<Qt::AlignmentFlag> flag) { layout_->setAlignment(flag); }
void setWidget(QWidget *widget);
protected: protected:
void paintEvent(QPaintEvent *event) override; void paintEvent(QPaintEvent *event) override;