-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnowwid.cpp
More file actions
125 lines (102 loc) · 2.89 KB
/
snowwid.cpp
File metadata and controls
125 lines (102 loc) · 2.89 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "snowwid.h"
#include <QWidget>
#include <QDesktopWidget>
#include <QTimer>
#include <QApplication>
#include <QDebug>
snowwid::snowwid(QWidget *parent) :
QWidget(parent)
{
timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(updateTime()));
wid=new QDesktopWidget();
}
void snowwid::setSnowSize(int max,int min)
{
maxSize=max;
minSize=min;
}
void snowwid::setSnowNember(int num)
{
numSnow=num;
}
void snowwid::setSnowOnTop(bool top)
{
onTop=top;
}
void snowwid::updat()
{
topScreen=wid->availableGeometry(this).top();
botScreen=wid->availableGeometry(this).bottom();
leftScreen=wid->availableGeometry(this).left();
rightScreen=wid->availableGeometry(this).right();
QPixmap pix(":/snowflake.png");
for (int i=0;i<numSnow;i++){
int size=maxSize;
int minsise=minSize;
int rndsize=rand() % ++size;
int rnd=rightScreen;
int rndX=rand() % ++rnd;
int rny=botScreen;
int rndy=rand() % ++rny;
int k=300;
dx[i]=rand() % ++k;
xp[i]=2;
snow[i]=new Object;
if(onTop==true){
snow[i]->setWindowFlags(Qt::WindowStaysOnTopHint|Qt::FramelessWindowHint|Qt::WindowType_Mask);
}else{
snow[i]->setWindowFlags(Qt::WindowStaysOnBottomHint|Qt::FramelessWindowHint|Qt::WindowType_Mask);
}
snow[i]->setAttribute(Qt::WA_X11NetWmWindowTypeDock);
snow[i]->setGeometry(rndX,rndy,rndsize+minsise,rndsize+minsise);
snow[i]->setPixmap(pix);
snow[i]->show();
}
oldNum=numSnow;
timer->start();
qDebug() << "Animation Autumn is Snow:"<< "Number :"+QString::number(numSnow)+" timeInterval:"+QString::number(timer->interval());
}
void snowwid::deletAll()
{
timer->stop();
for (int i=0;i<oldNum;i++){
snow[i]->deleteLater();
snow[i]->close();
}
}
void snowwid::updateTime()
{
int rnx=rightScreen-25;
int rnw=2;
for (int i=0;i<numSnow;i++){
qApp->processEvents();
dx[i]++;
int k=100;
int low=rand() % ++k;
if( dx[i]>=low+100){
dx[i]=rand() % ++k;
xp[i]=-xp[i];
}
int xx=rand() % ++rnw;
int xy=rand() % ++rnw;
int rndw=xx-xy;
if(rndw==0)rndw=1;
int rndX=rand() % ++rnx;
if (snow[i]->pos().x()<=leftScreen-snow[i]->width()){
xp[i]=2;
// xp[i]= rightScreen-snow[i]->width()-2;
}
if (snow[i]->pos().x()>=rightScreen){
xp[i]=-2;
}
if (snow[i]->pos().y()>=botScreen-snow[i]->height()){
int size=maxSize;
int minsise=minSize;
int rndsize=rand() % ++size;
snow[i]->setGeometry(rndX,topScreen,rndsize+minsise,rndsize+minsise);
}else{
snow[i]->move(snow[i]->pos().x()+xp[i],snow[i]->pos().y()+2);
}
}
}