PIVX Core  5.6.99
P2P Digital Currency
balancebubble.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 The PIVX Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
4 
5 #include "balancebubble.h"
6 #include "ui_balancebubble.h"
7 
8 #include "qtutils.h"
9 
10 #include <QGraphicsOpacityEffect>
11 #include <QPropertyAnimation>
12 #include <QTimer>
13 #include <qt/bitcoinunits.h>
14 
15 BalanceBubble::BalanceBubble(QWidget *parent) :
16  QWidget(parent),
17  ui(new Ui::BalanceBubble)
18 {
19  ui->setupUi(this);
20 
21  ui->frame->setProperty("cssClass", "container-popup");
22  setCssProperty({ui->textTransparent, ui->textShielded}, "amount-small-popup");
23 
24  std::initializer_list<QWidget*> lblTitles = {ui->lblFirst, ui->lblSecond};
25  setCssProperty(lblTitles, "text-title-topbar");
26  QFont font;
27  font.setWeight(QFont::Light);
28  for (QWidget* w : lblTitles) { w->setFont(font); }
29 }
30 
31 void BalanceBubble::updateValues(int64_t nTransparentBalance, int64_t nShieldedBalance, int unit)
32 {
33  QString valueTrans = BitcoinUnits::formatWithUnit(unit, nTransparentBalance, false, BitcoinUnits::separatorAlways);
34  valueTrans = valueTrans.replace(QChar(THIN_SP_CP), QString(","));
35  QString valueShield = BitcoinUnits::formatWithUnit(unit, nShieldedBalance, false, BitcoinUnits::separatorAlways);
36  valueShield = valueShield.replace(QChar(THIN_SP_CP), QString(","));
37 
38  ui->textTransparent->setText(valueTrans);
39  ui->textShielded->setText(valueShield);
40  adjustSize();
41 }
42 
43 void BalanceBubble::showEvent(QShowEvent *event)
44 {
45  QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
46  this->setGraphicsEffect(eff);
47  QPropertyAnimation *anim = new QPropertyAnimation(eff,"opacity");
48  anim->setDuration(400);
49  anim->setStartValue(0);
50  anim->setEndValue(1);
51  anim->setEasingCurve(QEasingCurve::Linear);
52  anim->start(QPropertyAnimation::DeleteWhenStopped);
53 
54  if (!hideTimer) hideTimer = new QTimer(this);
55  connect(hideTimer, &QTimer::timeout, this, &BalanceBubble::hideTimeout);
56  hideTimer->start(7000);
57 }
58 
59 void BalanceBubble::hideEvent(QHideEvent *event)
60 {
61  if (hideTimer) hideTimer->stop();
62  QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
63  this->setGraphicsEffect(eff);
64  QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
65  a->setDuration(800);
66  a->setStartValue(1);
67  a->setEndValue(0);
68  a->setEasingCurve(QEasingCurve::OutBack);
69  a->start(QPropertyAnimation::DeleteWhenStopped);
70 }
71 
73 {
74  hide();
75 }
76 
78 {
79  delete ui;
80 }
#define THIN_SP_CP
Definition: bitcoinunits.h:46
QTimer * hideTimer
Definition: balancebubble.h:32
virtual void hideEvent(QHideEvent *event) override
void updateValues(int64_t nTransparentBalance, int64_t nShieldedBalance, int unit)
Ui::BalanceBubble * ui
Definition: balancebubble.h:31
virtual void showEvent(QShowEvent *event) override
BalanceBubble(QWidget *parent=nullptr)
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
void setCssProperty(std::initializer_list< QWidget * > args, const QString &value)
Definition: qtutils.cpp:334