forked from m-garanin/zgui-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenuindicator.cpp
79 lines (63 loc) · 1.53 KB
/
menuindicator.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "menuindicator.h"
MenuIndicator::MenuIndicator(QWidget *parent) :
QPushButton(parent)
{
_inProgress = false;
progressIcon = new QMovie(":/loader.gif");
idleIcon = new QMovie(":/green.gif");
connect(progressIcon, SIGNAL(frameChanged(int)), this, SLOT(setProgressIconFrame(int)));
connect(idleIcon, SIGNAL(frameChanged(int)), this, SLOT(setIdleIconFrame(int)));
if(progressIcon->loopCount() != -1)
connect(progressIcon, SIGNAL(finished()), progressIcon, SLOT(start()));
if(idleIcon->loopCount() != -1)
connect(idleIcon, SIGNAL(finished()), idleIcon, SLOT(start()));
idleIcon->start();
}
MenuIndicator::~MenuIndicator()
{
delete progressIcon;
delete idleIcon;
}
void MenuIndicator::changeState()
{
setState(!_inProgress);
}
void MenuIndicator::setState(bool inProgress)
{
_inProgress = inProgress;
if(_inProgress)
{
this->setProgressIcon();
}
else
{
this->setIdleIcon();
}
emit stateChanged(_inProgress);
}
bool MenuIndicator::getState()
{
return _inProgress;
}
void MenuIndicator::setProgressIconFrame(int)
{
this->setIcon(QIcon(progressIcon->currentPixmap()));
}
void MenuIndicator::setIdleIconFrame(int)
{
this->setIcon(QIcon(idleIcon->currentPixmap()));
}
void MenuIndicator::setIndicatorText(QString text)
{
this->setText(text);
}
void MenuIndicator::setProgressIcon()
{
idleIcon->stop();
progressIcon->start();
}
void MenuIndicator::setIdleIcon()
{
progressIcon->stop();
idleIcon->start();
}