Changeset View
Changeset View
Standalone View
Standalone View
src/qt/modaloverlay.cpp
Show All 29 Lines | 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) setGeometry(0, height(), width(), height()); | if (!layerIsVisible) { | ||||
setGeometry(0, height(), width(), 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 | ||||
bool ModalOverlay::event(QEvent *ev) { | bool ModalOverlay::event(QEvent *ev) { | ||||
if (ev->type() == QEvent::ParentAboutToChange) { | if (ev->type() == QEvent::ParentAboutToChange) { | ||||
if (parent()) parent()->removeEventFilter(this); | if (parent()) { | ||||
parent()->removeEventFilter(this); | |||||
} | |||||
} else if (ev->type() == QEvent::ParentChange) { | } else if (ev->type() == QEvent::ParentChange) { | ||||
if (parent()) { | if (parent()) { | ||||
parent()->installEventFilter(this); | parent()->installEventFilter(this); | ||||
raise(); | raise(); | ||||
} | } | ||||
} | } | ||||
return QWidget::event(ev); | return QWidget::event(ev); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | void ModalOverlay::tipUpdate(int count, const QDateTime &blockDate, | ||||
// show the last block date | // show the last block date | ||||
ui->newestBlockDate->setText(blockDate.toString()); | ui->newestBlockDate->setText(blockDate.toString()); | ||||
// show the percentage done according to nVerificationProgress | // show the percentage done according to nVerificationProgress | ||||
ui->percentageProgress->setText( | ui->percentageProgress->setText( | ||||
QString::number(nVerificationProgress * 100, 'f', 2) + "%"); | QString::number(nVerificationProgress * 100, 'f', 2) + "%"); | ||||
ui->progressBar->setValue(nVerificationProgress * 100); | ui->progressBar->setValue(nVerificationProgress * 100); | ||||
if (!bestHeaderDate.isValid()) | if (!bestHeaderDate.isValid()) { | ||||
// not syncing | // not syncing | ||||
return; | return; | ||||
} | |||||
// estimate the number of headers left based on nPowTargetSpacing | // estimate the number of headers left based on nPowTargetSpacing | ||||
// and check if the gui is not aware of the best header (happens rarely) | // and check if the gui is not aware of the best header (happens rarely) | ||||
int estimateNumHeadersLeft = bestHeaderDate.secsTo(currentDate) / | int estimateNumHeadersLeft = bestHeaderDate.secsTo(currentDate) / | ||||
Params().GetConsensus().nPowTargetSpacing; | Params().GetConsensus().nPowTargetSpacing; | ||||
bool hasBestHeader = bestHeaderHeight >= count; | bool hasBestHeader = bestHeaderHeight >= count; | ||||
// show remaining number of blocks | // show remaining number of blocks | ||||
if (estimateNumHeadersLeft < HEADER_HEIGHT_DELTA_SYNC && hasBestHeader) { | if (estimateNumHeadersLeft < HEADER_HEIGHT_DELTA_SYNC && hasBestHeader) { | ||||
ui->numberOfBlocksLeft->setText( | ui->numberOfBlocksLeft->setText( | ||||
QString::number(bestHeaderHeight - count)); | QString::number(bestHeaderHeight - count)); | ||||
} else { | } else { | ||||
ui->numberOfBlocksLeft->setText( | ui->numberOfBlocksLeft->setText( | ||||
tr("Unknown. Syncing Headers (%1)...").arg(bestHeaderHeight)); | tr("Unknown. Syncing Headers (%1)...").arg(bestHeaderHeight)); | ||||
ui->expectedTimeLeft->setText(tr("Unknown...")); | ui->expectedTimeLeft->setText(tr("Unknown...")); | ||||
} | } | ||||
} | } | ||||
void ModalOverlay::toggleVisibility() { | void ModalOverlay::toggleVisibility() { | ||||
showHide(layerIsVisible, true); | showHide(layerIsVisible, true); | ||||
if (!layerIsVisible) userClosed = true; | if (!layerIsVisible) { | ||||
userClosed = true; | |||||
} | |||||
} | } | ||||
void ModalOverlay::showHide(bool hide, bool userRequested) { | void ModalOverlay::showHide(bool hide, bool userRequested) { | ||||
if ((layerIsVisible && !hide) || (!layerIsVisible && hide) || | if ((layerIsVisible && !hide) || (!layerIsVisible && hide) || | ||||
(!hide && userClosed && !userRequested)) | (!hide && userClosed && !userRequested)) { | ||||
return; | return; | ||||
} | |||||
if (!isVisible() && !hide) setVisible(true); | if (!isVisible() && !hide) { | ||||
setVisible(true); | |||||
} | |||||
setGeometry(0, hide ? 0 : height(), width(), height()); | setGeometry(0, hide ? 0 : height(), width(), height()); | ||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "pos"); | QPropertyAnimation *animation = new QPropertyAnimation(this, "pos"); | ||||
animation->setDuration(300); | animation->setDuration(300); | ||||
animation->setStartValue(QPoint(0, hide ? 0 : this->height())); | animation->setStartValue(QPoint(0, hide ? 0 : this->height())); | ||||
animation->setEndValue(QPoint(0, hide ? this->height() : 0)); | animation->setEndValue(QPoint(0, hide ? this->height() : 0)); | ||||
animation->setEasingCurve(QEasingCurve::OutQuad); | animation->setEasingCurve(QEasingCurve::OutQuad); | ||||
animation->start(QAbstractAnimation::DeleteWhenStopped); | animation->start(QAbstractAnimation::DeleteWhenStopped); | ||||
layerIsVisible = !hide; | layerIsVisible = !hide; | ||||
} | } | ||||
void ModalOverlay::closeClicked() { | void ModalOverlay::closeClicked() { | ||||
showHide(true); | showHide(true); | ||||
userClosed = true; | userClosed = true; | ||||
} | } |