Changeset View
Changeset View
Standalone View
Standalone View
src/qt/modaloverlay.cpp
// Copyright (c) 2016 The Bitcoin Core developers | // Copyright (c) 2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <qt/forms/ui_modaloverlay.h> | #include <qt/forms/ui_modaloverlay.h> | ||||
#include <qt/modaloverlay.h> | #include <qt/modaloverlay.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <qt/guiutil.h> | #include <qt/guiutil.h> | ||||
#include <QEasingCurve> | |||||
#include <QPropertyAnimation> | #include <QPropertyAnimation> | ||||
#include <QResizeEvent> | #include <QResizeEvent> | ||||
ModalOverlay::ModalOverlay(bool enable_wallet, QWidget *parent) | ModalOverlay::ModalOverlay(bool enable_wallet, QWidget *parent) | ||||
: QWidget(parent), ui(new Ui::ModalOverlay), bestHeaderHeight(0), | : QWidget(parent), ui(new Ui::ModalOverlay), bestHeaderHeight(0), | ||||
bestHeaderDate(QDateTime()), layerIsVisible(false), userClosed(false) { | bestHeaderDate(QDateTime()), layerIsVisible(false), userClosed(false) { | ||||
ui->setupUi(this); | ui->setupUi(this); | ||||
connect(ui->closeButton, &QPushButton::clicked, this, | connect(ui->closeButton, &QPushButton::clicked, this, | ||||
&ModalOverlay::closeClicked); | &ModalOverlay::closeClicked); | ||||
if (parent) { | if (parent) { | ||||
parent->installEventFilter(this); | parent->installEventFilter(this); | ||||
raise(); | raise(); | ||||
} | } | ||||
blockProcessTime.clear(); | blockProcessTime.clear(); | ||||
setVisible(false); | setVisible(false); | ||||
if (!enable_wallet) { | if (!enable_wallet) { | ||||
ui->infoText->setVisible(false); | ui->infoText->setVisible(false); | ||||
ui->infoTextStrong->setText( | ui->infoTextStrong->setText( | ||||
tr("%1 is currently syncing. It will download headers " | tr("%1 is currently syncing. It will download headers " | ||||
"and blocks from peers and validate them until reaching the tip " | "and blocks from peers and validate them until reaching the tip " | ||||
"of the block chain.") | "of the block chain.") | ||||
.arg(PACKAGE_NAME)); | .arg(PACKAGE_NAME)); | ||||
} | } | ||||
m_animation.setTargetObject(this); | |||||
m_animation.setPropertyName("pos"); | |||||
m_animation.setDuration(300 /* ms */); | |||||
m_animation.setEasingCurve(QEasingCurve::OutQuad); | |||||
} | } | ||||
ModalOverlay::~ModalOverlay() { | ModalOverlay::~ModalOverlay() { | ||||
delete ui; | delete ui; | ||||
} | } | ||||
bool ModalOverlay::eventFilter(QObject *obj, QEvent *ev) { | bool ModalOverlay::eventFilter(QObject *obj, QEvent *ev) { | ||||
if (obj == parent()) { | if (obj == parent()) { | ||||
if (ev->type() == QEvent::Resize) { | if (ev->type() == QEvent::Resize) { | ||||
QResizeEvent *rev = static_cast<QResizeEvent *>(ev); | QResizeEvent *rev = static_cast<QResizeEvent *>(ev); | ||||
resize(rev->size()); | resize(rev->size()); | ||||
if (!layerIsVisible) { | if (!layerIsVisible) { | ||||
setGeometry(0, height(), width(), height()); | setGeometry(0, height(), width(), height()); | ||||
} | } | ||||
if (m_animation.endValue().toPoint().y() > 0) { | |||||
m_animation.setEndValue(QPoint(0, height())); | |||||
} | |||||
} else if (ev->type() == QEvent::ChildAdded) { | } else if (ev->type() == QEvent::ChildAdded) { | ||||
raise(); | raise(); | ||||
} | } | ||||
} | } | ||||
return QWidget::eventFilter(obj, ev); | return QWidget::eventFilter(obj, ev); | ||||
} | } | ||||
//! Tracks parent widget changes | //! Tracks parent widget changes | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | if ((layerIsVisible && !hide) || (!layerIsVisible && hide) || | ||||
(!hide && userClosed && !userRequested)) { | (!hide && userClosed && !userRequested)) { | ||||
return; | return; | ||||
} | } | ||||
if (!isVisible() && !hide) { | if (!isVisible() && !hide) { | ||||
setVisible(true); | setVisible(true); | ||||
} | } | ||||
setGeometry(0, hide ? 0 : height(), width(), height()); | m_animation.setStartValue(QPoint(0, hide ? 0 : height())); | ||||
// The eventFilter() updates the endValue if it is required for | |||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "pos"); | // QEvent::Resize. | ||||
animation->setDuration(300); | m_animation.setEndValue(QPoint(0, hide ? height() : 0)); | ||||
animation->setStartValue(QPoint(0, hide ? 0 : this->height())); | m_animation.start(QAbstractAnimation::KeepWhenStopped); | ||||
animation->setEndValue(QPoint(0, hide ? this->height() : 0)); | |||||
animation->setEasingCurve(QEasingCurve::OutQuad); | |||||
animation->start(QAbstractAnimation::DeleteWhenStopped); | |||||
layerIsVisible = !hide; | layerIsVisible = !hide; | ||||
} | } | ||||
void ModalOverlay::closeClicked() { | void ModalOverlay::closeClicked() { | ||||
showHide(true); | showHide(true); | ||||
userClosed = true; | userClosed = true; | ||||
} | } |