-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscanwidget.cpp
More file actions
executable file
·201 lines (175 loc) · 5.66 KB
/
scanwidget.cpp
File metadata and controls
executable file
·201 lines (175 loc) · 5.66 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <QFrame>
#include <QTime>
#include <QTimer>
#include <QGraphicsItemAnimation>
#include <QTimeLine>
#include <QPropertyAnimation>
#include "scanwidget.h"
#define MAXIMAGECOUNT 10
ScanWidget::ScanWidget(int imageNum,QStringList imageName,QString musicName)
{
//set the widget property
this->setGeometry(300,180,350,350);
//create view and scene
setupScene();
QPropertyAnimation* anim[MAXIMAGECOUNT];
QLabel *imageLabel[MAXIMAGECOUNT];
imageGroup = new QSequentialAnimationGroup;
//create image flash
for(int i=0;i<imageNum;i++)
{
//add image
QString imagename = imageName.at(i);
QPixmap *pixmap = new QPixmap(imagename);
imageLabel[i] = new QLabel;
imageLabel[i]->setPixmap(*pixmap);
imageLabel[i]->setGeometry(QRect(-400,-400,220,190));
scene->addWidget(imageLabel[i]);
anim[i] = new QPropertyAnimation(imageLabel[i],"pos");
anim[i]->setDuration(10000);
switch(i)
{
case 0:
anim[i]->setStartValue(QPoint(-400,-400));
anim[i]->setEndValue(QPoint(100,100));
anim[i]->setEasingCurve(QEasingCurve::SineCurve);
break;
case 1:
anim[i]->setStartValue(QPoint(-400,-100));
anim[i]->setEndValue(QPoint(200,-100));
anim[i]->setEasingCurve(QEasingCurve::Linear);
break;
case 2:
anim[i]->setStartValue(QPoint(150,-100));
anim[i]->setEndValue(QPoint(-400,-100));
anim[i]->setEasingCurve(QEasingCurve::Linear);
break;
case 3:
anim[i]->setStartValue(QPoint(150,-400));
anim[i]->setEndValue(QPoint(-300,100));
anim[i]->setEasingCurve(QEasingCurve::SineCurve);
break;
case 4:
anim[i]->setStartValue(QPoint(-100,-330));
anim[i]->setEndValue(QPoint(-100,300));
anim[i]->setEasingCurve(QEasingCurve::InCirc);
break;
case 5:
anim[i]->setStartValue(QPoint(-100,300));
anim[i]->setEndValue(QPoint(-100,-330));
anim[i]->setEasingCurve(QEasingCurve::OutCirc);
break;
default :
anim[i]->setStartValue(QPoint(-400,-400));
anim[i]->setEndValue(QPoint(100,100));
anim[i]->setEasingCurve(QEasingCurve::SineCurve);
break;
}
imageGroup->addAnimation(anim[i]);
}
imageGroup->setLoopCount(10);
//create music
music = Phonon::createPlayer(Phonon::MusicCategory,Phonon::MediaSource(musicName));
timeLabel = new QLabel;
//create buttons
createBtns();
//change current time
QTimer *timer = new QTimer();
connect(timer,SIGNAL(timeout()),this,SLOT(showTime()));
timer->start(1000);
//set scan layout
QVBoxLayout *scanLayout = new QVBoxLayout(this);
scanLayout->addWidget(view);
scanLayout->addLayout(btnLayout);
}
//create buttons
void ScanWidget::createBtns()
{
QFrame * frame = new QFrame;
//create play button
playBtn = new QPushButton(frame);
playBtn->setMaximumSize(40,40);
playBtn->setIconSize(QSize(playBtn->width(),playBtn->height()));
playBtn->setIcon(QIcon("./image/play.png"));
playBtn->setToolTip(tr("play"));
connect(playBtn,SIGNAL(clicked()),this,SLOT(playButtonClicked()));
//create pause button
pauseBtn = new QPushButton(frame);
pauseBtn->setMaximumSize(40,40);
pauseBtn->setIconSize(QSize(pauseBtn->width(),pauseBtn->height()));
pauseBtn->setIcon(QIcon("./image/pause.png"));
pauseBtn->setToolTip(tr("Pause"));
connect(pauseBtn,SIGNAL(clicked()),this,SLOT(pauseButtonCLicked()));
//create stop button
stopBtn = new QPushButton(frame);
stopBtn->setMaximumSize(40,40);
stopBtn->setIconSize(QSize(stopBtn->width(),stopBtn->height()));
stopBtn->setIcon(QIcon("./image/stop.png"));
stopBtn->setToolTip(tr("Stop"));
connect(stopBtn,SIGNAL(clicked()),this,SLOT(stopButtonClicked()));
//button layout
btnLayout = new QHBoxLayout;
btnLayout->addWidget(timeLabel);
btnLayout->addWidget(playBtn);
btnLayout->addWidget(pauseBtn);
btnLayout->addWidget(stopBtn);
}
//set up scene
void ScanWidget::setupScene()
{
//create scene
scene = new QGraphicsScene;
scene->setSceneRect(QRectF(-40,-40,80,80));
scene->setBackgroundBrush(QBrush());
//create view
view = new QGraphicsView;
view->setScene(scene);
view->setMinimumSize(80,80);
//initial scene
QString imageName="./image/search.png";
QPixmap *pixmap = new QPixmap(imageName);
pixItem = new PixItem(pixmap);
scene->addItem(pixItem);
pixItem->setPos(0,0);
}
//when clicked the play button
void ScanWidget::playButtonClicked()
{
music->play();
imageGroup->start();
}
//when clicked the pause button
void ScanWidget::pauseButtonCLicked()
{
music->pause();
imageGroup->pause();
}
//when clicked the stop button
void ScanWidget::stopButtonClicked()
{
music->stop();
imageGroup->stop();
}
//show music time
void ScanWidget::showTime()
{
QString time;
time="Time:"+getMusicTime();
timeLabel->setText(time);
}
//get music total time
QString ScanWidget::getMusicTime()
{
qint64 totalTimeValue = music->totalTime();
qint64 currentTimeValue = music->currentTime();
QTime currentTime(0,(currentTimeValue/60000)%60,(currentTimeValue/1000)%60);
QTime totalTime(0,(totalTimeValue/60000)%60,(totalTimeValue/1000)%60);
QString timeStr =currentTime.toString("mm:ss")+"|"+totalTime.toString("mm:ss");
return timeStr;
}
//close widget
void ScanWidget::closeEvent(QCloseEvent *)
{
music->stop();
imageGroup->stop();
}