Skip to content

Commit

Permalink
Remove QPropertyAnimation from modals to work around a regression on …
Browse files Browse the repository at this point in the history
…Qt 5.10.1 (mujx#87)
  • Loading branch information
mujx committed Feb 17, 2018
1 parent cc5127e commit 5e0cda9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 72 deletions.
15 changes: 0 additions & 15 deletions include/ui/OverlayModal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

#pragma once

#include <QGraphicsOpacityEffect>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QPropertyAnimation>

#include "OverlayWidget.h"

Expand All @@ -30,14 +28,6 @@ class OverlayModal : public OverlayWidget
public:
OverlayModal(QWidget *parent, QWidget *content);

void fadeIn();
void fadeOut();

void setDuration(int duration)
{
duration_ = duration;
animation_->setDuration(duration_);
};
void setColor(QColor color) { color_ = color; }
void setDismissible(bool state) { isDismissible_ = state; }

Expand All @@ -48,13 +38,8 @@ class OverlayModal : public OverlayWidget

private:
QWidget *content_;

int duration_;
QColor color_;

//! Decides whether or not the modal can be removed by clicking into it.
bool isDismissible_ = true;

QGraphicsOpacityEffect *opacity_;
QPropertyAnimation *animation_;
};
8 changes: 3 additions & 5 deletions src/ChatPage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ ChatPage::showQuickSwitcher()

connect(quickSwitcher_.data(), &QuickSwitcher::closing, this, [=]() {
if (!this->quickSwitcherModal_.isNull())
this->quickSwitcherModal_->fadeOut();
this->quickSwitcherModal_->hide();
this->text_input_->setFocus(Qt::FocusReason::PopupFocusReason);
});
}
Expand All @@ -689,7 +689,6 @@ ChatPage::showQuickSwitcher()
quickSwitcherModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), quickSwitcher_.data()),
[=](OverlayModal *modal) { modal->deleteLater(); });
quickSwitcherModal_->setDuration(0);
quickSwitcherModal_->setColor(QColor(30, 30, 30, 170));
}

Expand All @@ -704,7 +703,7 @@ ChatPage::showQuickSwitcher()
}

quickSwitcher_->setRoomList(rooms);
quickSwitcherModal_->fadeIn();
quickSwitcherModal_->show();
}

void
Expand Down Expand Up @@ -922,12 +921,11 @@ ChatPage::showReadReceipts(const QString &event_id)
receiptsModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), receiptsDialog_.data()),
[=](OverlayModal *modal) { modal->deleteLater(); });
receiptsModal_->setDuration(0);
receiptsModal_->setColor(QColor(30, 30, 30, 170));
}

receiptsDialog_->addUsers(cache_->readReceipts(event_id, current_room_));
receiptsModal_->fadeIn();
receiptsModal_->show();
}

void
Expand Down
10 changes: 4 additions & 6 deletions src/MainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ MainWindow::removeOverlayProgressBar()
timer->deleteLater();

if (!progressModal_.isNull())
progressModal_->fadeOut();
progressModal_->hide();

if (!spinner_.isNull())
spinner_->stop();
Expand Down Expand Up @@ -215,8 +215,7 @@ MainWindow::showChatPage(QString userid, QString homeserver, QString token)
QSharedPointer<OverlayModal>(new OverlayModal(this, spinner_.data()),
[=](OverlayModal *modal) { modal->deleteLater(); });
progressModal_->setDismissible(false);
progressModal_->fadeIn();
progressModal_->setDuration(modalOpacityDuration);
progressModal_->show();
}

login_page_->reset();
Expand Down Expand Up @@ -271,16 +270,15 @@ MainWindow::openLeaveRoomDialog(const QString &room_id)
leaveRoomDialog_ = QSharedPointer<dialogs::LeaveRoom>(new dialogs::LeaveRoom(this));

connect(leaveRoomDialog_.data(), &dialogs::LeaveRoom::closing, this, [=](bool leaving) {
leaveRoomModal_->fadeOut();
leaveRoomModal_->hide();

if (leaving)
client_->leaveRoom(roomToLeave);
});

leaveRoomModal_ =
QSharedPointer<OverlayModal>(new OverlayModal(this, leaveRoomDialog_.data()));
leaveRoomModal_->setDuration(0);
leaveRoomModal_->setColor(QColor(30, 30, 30, 170));

leaveRoomModal_->fadeIn();
leaveRoomModal_->show();
}
2 changes: 1 addition & 1 deletion src/RoomList.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ RoomList::leaveEvent(QEvent *event)
void
RoomList::closeJoinRoomDialog(bool isJoining, QString roomAlias)
{
joinRoomModal_->fadeOut();
joinRoomModal_->hide();

if (isJoining)
client_->joinRoom(roomAlias);
Expand Down
10 changes: 4 additions & 6 deletions src/SideBarActions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SideBarActions::SideBarActions(QWidget *parent)
&dialogs::JoinRoom::closing,
this,
[=](bool isJoining, const QString &room) {
joinRoomModal_->fadeOut();
joinRoomModal_->hide();

if (isJoining && !room.isEmpty())
emit joinRoom(room);
Expand All @@ -53,11 +53,10 @@ SideBarActions::SideBarActions(QWidget *parent)
if (joinRoomModal_.isNull()) {
joinRoomModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), joinRoomDialog_.data()));
joinRoomModal_->setDuration(0);
joinRoomModal_->setColor(QColor(30, 30, 30, 170));
}

joinRoomModal_->fadeIn();
joinRoomModal_->show();
});

connect(createRoomAction_, &QAction::triggered, this, [=]() {
Expand All @@ -69,7 +68,7 @@ SideBarActions::SideBarActions(QWidget *parent)
&dialogs::CreateRoom::closing,
this,
[=](bool isCreating, const mtx::requests::CreateRoom &request) {
createRoomModal_->fadeOut();
createRoomModal_->hide();

if (isCreating)
emit createRoom(request);
Expand All @@ -79,11 +78,10 @@ SideBarActions::SideBarActions(QWidget *parent)
if (createRoomModal_.isNull()) {
createRoomModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), createRoomDialog_.data()));
createRoomModal_->setDuration(0);
createRoomModal_->setColor(QColor(30, 30, 30, 170));
}

createRoomModal_->fadeIn();
createRoomModal_->show();
});

addMenu_->addAction(createRoomAction_);
Expand Down
5 changes: 2 additions & 3 deletions src/TopRoomBar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ TopRoomBar::TopRoomBar(QWidget *parent)
&dialogs::InviteUsers::closing,
this,
[=](bool isSending, QStringList invitees) {
inviteUsersModal_->fadeOut();
inviteUsersModal_->hide();

if (isSending && !invitees.isEmpty())
emit inviteUsers(invitees);
Expand All @@ -110,11 +110,10 @@ TopRoomBar::TopRoomBar(QWidget *parent)
if (inviteUsersModal_.isNull()) {
inviteUsersModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), inviteUsersDialog_.data()));
inviteUsersModal_->setDuration(0);
inviteUsersModal_->setColor(QColor(30, 30, 30, 170));
}

inviteUsersModal_->fadeIn();
inviteUsersModal_->show();
});

leaveRoom_ = new QAction(tr("Leave room"), this);
Expand Down
5 changes: 2 additions & 3 deletions src/UserInfoWidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,17 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
if (logoutModal_.isNull()) {
logoutModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), logoutDialog_.data()));
logoutModal_->setDuration(0);
logoutModal_->setColor(QColor(30, 30, 30, 170));
}

logoutModal_->fadeIn();
logoutModal_->show();
});
}

void
UserInfoWidget::closeLogoutDialog(bool isLoggingOut)
{
logoutModal_->fadeOut();
logoutModal_->hide();

if (isLoggingOut)
emit logout();
Expand Down
35 changes: 2 additions & 33 deletions src/ui/OverlayModal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
OverlayModal::OverlayModal(QWidget *parent, QWidget *content)
: OverlayWidget(parent)
, content_{content}
, duration_{500}
, color_{QColor(55, 55, 55)}
{
auto layout = new QVBoxLayout();
Expand All @@ -32,21 +31,6 @@ OverlayModal::OverlayModal(QWidget *parent, QWidget *content)

setLayout(layout);

opacity_ = new QGraphicsOpacityEffect(this);
setGraphicsEffect(opacity_);

opacity_->setOpacity(1);
animation_ = new QPropertyAnimation(opacity_, "opacity", this);
animation_->setStartValue(1);
animation_->setEndValue(0);
animation_->setDuration(duration_);
animation_->setEasingCurve(QEasingCurve::Linear);

connect(animation_, &QPropertyAnimation::finished, [this]() {
if (animation_->direction() == QAbstractAnimation::Forward)
this->close();
});

content->setFocus();
}

Expand All @@ -63,29 +47,14 @@ void
OverlayModal::mousePressEvent(QMouseEvent *e)
{
if (isDismissible_ && content_ && !content_->geometry().contains(e->pos()))
fadeOut();
}

void
OverlayModal::fadeIn()
{
animation_->setDirection(QAbstractAnimation::Backward);
animation_->start();
show();
}

void
OverlayModal::fadeOut()
{
animation_->setDirection(QAbstractAnimation::Forward);
animation_->start();
hide();
}

void
OverlayModal::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape) {
event->accept();
fadeOut();
hide();
}
}

0 comments on commit 5e0cda9

Please sign in to comment.