-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSleeper.h
76 lines (72 loc) · 1.78 KB
/
Sleeper.h
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
/*******************************************
* Written in 2014 by Kamil Niemczyk
*
* PL:
* ! Kod kopiować wraz z tym komentarzem !
* W przypadku wprowadzenia zmian
* dopisać się do listy autorów kodu.
* Rozprowadzać bezpłatnie.
* Wyrażam zgodę na używanie programu oraz
* jego kodu w celach dydaktycznych.
*
* EN:
* ! Copy only with this comment !
* In case of any changes add your nick/name
* to authors list.
* Distribute free of charge.
* I agree to use this program and its code
* for educational purposes.
*******************************************/
#ifndef SLEEPER_HH
#define SLEEPER_HH
#include <QThread>
#include <QWidget>
#include <QLineEdit>
#include <QCoreApplication>
// na potrzeby animacji, utworzona by skorzystać z przeciążonych metod *sleep()
class Sleeper : public QThread
{
QWidget * p;
unsigned long * value1;
QLineEdit * value2;
public:
Sleeper() : QThread() {}
Sleeper(unsigned long * animationTimeout, QLineEdit *animationLineEdit) : QThread()
{
value1=animationTimeout;
value2=animationLineEdit;
}
Sleeper(QWidget * parent=0) : QThread()
{
p=parent;
}
void usleep(unsigned long usecs)
{
QThread::usleep(usecs);
p->repaint();
QCoreApplication::processEvents();
}
void msleep(unsigned long msecs)
{
QThread::msleep(msecs);
p->repaint();
QCoreApplication::processEvents();
}
void sleep(unsigned long secs){
QThread::sleep(secs);
p->repaint();
QCoreApplication::processEvents();
}
void updateAnimation()
{
if(value2 != NULL){
QString skipchars("-_!,;. \t");
foreach(QChar ch, skipchars)
value2->setText(value2->text().remove(ch));
int czasMs = value2->text().toInt();
if(czasMs > 0)
*value1 = czasMs;
}
}
};
#endif // SLEEPER_HH