|
| 1 | +#include "qt/pivx/expandablebutton.h" |
| 2 | +#include "qt/pivx/forms/ui_expandablebutton.h" |
| 3 | +#include <QParallelAnimationGroup> |
| 4 | +#include <QPropertyAnimation> |
| 5 | +#include <QStyle> |
| 6 | +#include <iostream> |
| 7 | + |
| 8 | +ExpandableButton::ExpandableButton(QWidget *parent) : |
| 9 | + QWidget(parent), |
| 10 | + ui(new Ui::ExpandableButton), |
| 11 | + isAnimating(false) |
| 12 | +{ |
| 13 | + ui->setupUi(this); |
| 14 | + |
| 15 | + this->setStyleSheet(parent->styleSheet()); |
| 16 | + ui->pushButton->setCheckable(true); |
| 17 | + this->layout()->setSizeConstraint(QLayout::SetFixedSize); |
| 18 | + |
| 19 | + connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(mousePressEvent())); |
| 20 | +} |
| 21 | + |
| 22 | +void ExpandableButton::setButtonClassStyle(const char *name, const QVariant &value, bool forceUpdate){ |
| 23 | + ui->pushButton->setProperty(name, value); |
| 24 | + if(forceUpdate){ |
| 25 | + ui->pushButton->style()->unpolish(ui->pushButton); |
| 26 | + ui->pushButton->style()->polish(ui->pushButton); |
| 27 | + ui->pushButton->update(); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +void ExpandableButton::setButtonText(const QString _text){ |
| 32 | + this->text = _text; |
| 33 | +} |
| 34 | + |
| 35 | +void ExpandableButton::setText2(QString text2) |
| 36 | +{ |
| 37 | + this->text = text2; |
| 38 | + ui->pushButton->setText(text2); |
| 39 | +} |
| 40 | + |
| 41 | +ExpandableButton::~ExpandableButton() |
| 42 | +{ |
| 43 | + delete ui; |
| 44 | +} |
| 45 | + |
| 46 | +bool ExpandableButton::isChecked(){ |
| 47 | + return ui->pushButton->isChecked(); |
| 48 | +} |
| 49 | + |
| 50 | +void ExpandableButton::setChecked(bool check){ |
| 51 | + ui->pushButton->setChecked(check); |
| 52 | +} |
| 53 | + |
| 54 | +void ExpandableButton::setSmall() |
| 55 | +{ |
| 56 | + ui->pushButton->setText(""); |
| 57 | + this->setMaximumWidth(36); |
| 58 | + update(); |
| 59 | +} |
| 60 | + |
| 61 | +void ExpandableButton::enterEvent(QEvent *) { |
| 62 | + if(!this->isAnimating){ |
| 63 | + this->isAnimating = true; |
| 64 | + this->setMaximumWidth(100); |
| 65 | + |
| 66 | +// animation = new QPropertyAnimation(this, "maximumWidth"); |
| 67 | +// animation->setDuration(3000); |
| 68 | +// animation->setStartValue(36); |
| 69 | +// animation->setEndValue(100); |
| 70 | + |
| 71 | +// QPropertyAnimation *animation2 = new QPropertyAnimation(this, "text2"); |
| 72 | +// animation2->setDuration(2000); |
| 73 | +// animation2->setStartValue("Wallet Unlocked"); |
| 74 | +// animation2->setEndValue("Wallet Unlocked"); |
| 75 | + |
| 76 | +// QParallelAnimationGroup *group = new QParallelAnimationGroup; |
| 77 | +// group->addAnimation(animation); |
| 78 | +// group->addAnimation(animation2); |
| 79 | + |
| 80 | +// group->start(QAbstractAnimation::DeleteWhenStopped); |
| 81 | + |
| 82 | + ui->pushButton->setText(text); |
| 83 | + //animation->start(QAbstractAnimation::DeleteWhenStopped); |
| 84 | + this->isAnimating = false; |
| 85 | + emit Mouse_Hover(); |
| 86 | + } |
| 87 | + update(); |
| 88 | +} |
| 89 | + |
| 90 | +void ExpandableButton::leaveEvent(QEvent *) { |
| 91 | +// if(animation){ |
| 92 | +// animation->stop(); |
| 93 | +// animation = nullptr; |
| 94 | +// } |
| 95 | + |
| 96 | + if(!keepExpanded){ |
| 97 | + this->setSmall(); |
| 98 | + } |
| 99 | + emit Mouse_HoverLeave(); |
| 100 | +} |
| 101 | + |
| 102 | +void ExpandableButton::mousePressEvent(){ |
| 103 | + emit Mouse_Pressed(); |
| 104 | +} |
| 105 | + |
| 106 | +void ExpandableButton::mousePressEvent(QMouseEvent *ev) |
| 107 | +{ |
| 108 | + emit Mouse_Pressed(); |
| 109 | +} |
| 110 | + |
| 111 | +void ExpandableButton::on_pushButton_clicked(bool checked) |
| 112 | +{ |
| 113 | + // TODO: Add callback event |
| 114 | +} |
0 commit comments