PIVX Core  5.6.99
P2P Digital Currency
expandablebutton.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 The PIVX Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "expandablebutton.h"
6 #include "ui_expandablebutton.h"
7 
8 #include "qtutils.h"
9 
10 #include <QParallelAnimationGroup>
11 #include <QPropertyAnimation>
12 #include <QStyle>
13 #include <iostream>
14 
16  QWidget(parent),
17  ui(new Ui::ExpandableButton),
18  isAnimating(false)
19 {
20  ui->setupUi(this);
21 
22  this->setStyleSheet(parent->styleSheet());
23  ui->pushButton->setCheckable(true);
24  this->layout()->setSizeConstraint(QLayout::SetFixedSize);
25 
26  connect(ui->pushButton, &QPushButton::clicked, this, &ExpandableButton::innerMousePressEvent);
27 }
28 
29 void ExpandableButton::setButtonClassStyle(const char *name, const QVariant &value, bool forceUpdate)
30 {
31  ui->pushButton->setProperty(name, value);
32  if (forceUpdate) {
33  updateStyle(ui->pushButton);
34  }
35 }
36 
37 void ExpandableButton::setIcon(QString path)
38 {
39  ui->pushButton->setIcon(QIcon(path));
40 }
41 
42 void ExpandableButton::setButtonText(const QString& _text)
43 {
44  this->text = _text;
45  if (this->isExpanded) {
46  ui->pushButton->setText(_text);
47  }
48 }
49 
50 void ExpandableButton::setNoIconText(const QString& _text)
51 {
52  notExpandedText = _text;
53  if (!this->isExpanded)
54  ui->pushButton->setText(_text);
55 }
56 
57 void ExpandableButton::setText2(QString text2)
58 {
59  this->text = text2;
60  ui->pushButton->setText(text2);
61 }
62 
64 {
65  delete ui;
66 }
67 
69 {
70  return ui->pushButton->isChecked();
71 }
72 
74 {
75  ui->pushButton->setChecked(check);
76 }
77 
79 {
80  ui->pushButton->setText(notExpandedText);
81  this->setMaximumWidth(36);
82  this->isExpanded = false;
83  update();
84 }
85 
87 {
88  this->setMaximumWidth(100);
89  ui->pushButton->setText(text);
90  this->isExpanded = true;
91 }
92 
94 {
95  if (!this->isAnimating) {
96  setExpanded();
97  Q_EMIT Mouse_Hover();
98  }
99  update();
100 }
101 
103 {
104  if (!keepExpanded) {
105  this->setSmall();
106  }
107  Q_EMIT Mouse_HoverLeave();
108 }
109 
111 {
112  Q_EMIT Mouse_Pressed();
113 }
114 
116 {
117  // TODO: Add callback event
118 }
false
Definition: bls_dkg.cpp:151
void setButtonText(const QString &_text)
virtual void leaveEvent(QEvent *)
void setChecked(bool check)
void Mouse_HoverLeave()
ExpandableButton(QWidget *parent=nullptr)
void setText2(QString text2)
void on_pushButton_clicked(bool checked)
void setNoIconText(const QString &_text)
Ui::ExpandableButton * ui
void setButtonClassStyle(const char *name, const QVariant &value, bool forceUpdate=false)
std::atomic< bool > isAnimating
virtual void enterEvent(QEvent *)
void setIcon(QString path)
void updateStyle(QWidget *widget)
Definition: qtutils.cpp:225
const char * name
Definition: rest.cpp:37