-
Notifications
You must be signed in to change notification settings - Fork 9
/
loadingbutton.cpp
47 lines (38 loc) · 1.09 KB
/
loadingbutton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "loadingbutton.h"
#include <QResizeEvent>
#include "components/loading/qprogressindicator.h"
LoadingButton::LoadingButton(QWidget* parent, QPushButton* model)
: LoadingButton(QString(), parent, model) {}
LoadingButton::LoadingButton(const QString& text, QWidget* parent, QPushButton* model)
: QPushButton(text, parent)
, loading(new QProgressIndicator(this))
, showingLabel(true)
{
if (model == nullptr) {
model = this;
}
setMinimumSize(model->width(), model->minimumHeight());
resize(model->width(), model->height());
loading->setMinimumSize(this->minimumSize());
loading->resize(this->width(), this->height());
}
void LoadingButton::startAnimation() {
label = text();
showLabel(false);
}
void LoadingButton::stopAnimation() { showLabel(true); }
void LoadingButton::showLabel(bool show) {
showingLabel = show;
if (show) {
loading->stopAnimation();
setText(label);
}
else {
setText(QString());
loading->startAnimation();
}
}
void LoadingButton::resizeEvent(QResizeEvent* evt) {
QPushButton::resizeEvent(evt);
loading->resize(evt->size());
}