-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicanimationwidget.cpp
More file actions
205 lines (184 loc) · 5.17 KB
/
picanimationwidget.cpp
File metadata and controls
205 lines (184 loc) · 5.17 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
202
203
204
205
#include "picanimationwidget.h"
#include <QTimer>
#include "protreeitem.h"
#include <QPainter>
PicAnimationWidget::PicAnimationWidget(QWidget *parent) : QWidget(parent)
, m_factor(0.0),m_curItem(nullptr),m_bStart(false)
{
m_timer = new QTimer(this);
connect(m_timer,&QTimer::timeout,this,&PicAnimationWidget::TimeOut);
}
PicAnimationWidget::~PicAnimationWidget()
{
}
void PicAnimationWidget::SetPixmap(QTreeWidgetItem *item)
{
if(!item)
return;
ProTreeItem *treeItem = dynamic_cast<ProTreeItem *>(item);
QString path = treeItem->GetPath();
m_pixmap1.load(path);
m_curItem = treeItem;
if(m_mapItem.find(path) == m_mapItem.end()){
m_mapItem[path] = treeItem;
//发送更新列表逻辑
emit SigUpPreList(item);
}
emit SigSlectItem(item);
ProTreeItem *nextItem = treeItem->GetNextItem();
if(!nextItem)
return;
QString nextPath = nextItem->GetPath();
m_pixmap2.load(nextPath);
if(m_mapItem.find(nextPath) == m_mapItem.end()){
m_mapItem[nextPath] = nextItem;
//发送更新列表逻辑
emit SigUpPreList(nextItem);
}
}
void PicAnimationWidget::Start()
{
emit SigStart();
emit SigStartMusic();
m_factor = 0;
m_timer->start(25);
m_bStart = true;
}
void PicAnimationWidget::Stop()
{
emit SigStop();
emit SigStopMusic();
m_timer->stop();
m_factor = 0;
m_bStart = false;
}
void PicAnimationWidget::paintEvent(QPaintEvent *event)
{
if(m_pixmap1.isNull())
return;
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing,true);
QRect rect = geometry();
int w = rect.width();
int h = rect.height();
m_pixmap1 = m_pixmap1.scaled(w,h,Qt::KeepAspectRatio);
int alpha = 255*(1.0f-m_factor);
QPixmap alphaPixmap(m_pixmap1.size());
alphaPixmap.fill(Qt::transparent);
QPainter p1(&alphaPixmap);
p1.setCompositionMode(QPainter::CompositionMode_Source);
p1.drawPixmap(0,0,m_pixmap1);
p1.setCompositionMode(QPainter::CompositionMode_Destination);
p1.fillRect(alphaPixmap.rect(),QColor(0,0,0,alpha));
p1.end();
int x = (w - m_pixmap1.width())/2;
int y = (h - m_pixmap1.height())/2;
painter.drawPixmap(x,y,alphaPixmap);
if(m_pixmap2.isNull())
return;
m_pixmap2 = m_pixmap2.scaled(w,h,Qt::KeepAspectRatio);
alpha = 255*(m_factor);
QPixmap alphaPixmap2(m_pixmap2.size());
alphaPixmap2.fill(Qt::transparent);
QPainter p2(&alphaPixmap2);
p2.setCompositionMode(QPainter::CompositionMode_Source);
p2.drawPixmap(0, 0, m_pixmap2);
p2.setCompositionMode(QPainter::CompositionMode_DestinationIn);
p2.fillRect(alphaPixmap2.rect(), QColor(0, 0, 0, alpha));
p2.end();
x = (w - m_pixmap2.width()) / 2;
y = (h - m_pixmap2.height()) / 2;
painter.drawPixmap(x, y, alphaPixmap2);
}
void PicAnimationWidget::updateSelectPixmap(QTreeWidgetItem *item)
{
if(!item){
return;
}
ProTreeItem *treeItem = dynamic_cast<ProTreeItem *>(item);
QString path = treeItem->GetPath();
m_pixmap1.load(path);
m_curItem = treeItem;
if(m_mapItem.find(path) == m_mapItem.end()){
m_mapItem[path] = treeItem;
}
ProTreeItem *nextItem = treeItem->GetNextItem();
if(!nextItem)
return;
QString nextPath = treeItem->GetPath();
m_pixmap2.load(nextPath);
if(m_mapItem.find(nextPath) == m_mapItem.end()){
m_mapItem[path] = nextItem;
}
}
void PicAnimationWidget::SlotUpSelectShow(QString path)
{
auto iter = m_mapItem.find(path);
if(iter == m_mapItem.end())
return;
updateSelectPixmap(iter.value());
update();
}
void PicAnimationWidget::SlotPlayAndStop()
{
if(!m_bStart){
m_factor = 0;
m_timer->start(25);
m_bStart = true;
emit SigStartMusic();
}else{
m_timer->stop();
m_factor = 0;
update();
m_bStart = false;
emit SigStopMusic();
}
}
void PicAnimationWidget::SlideNext()
{
Stop();
if(!m_curItem){
return;
}
ProTreeItem *curProItem = dynamic_cast<ProTreeItem *>(m_curItem);
ProTreeItem *nextItem = curProItem->GetNextItem();
if(!nextItem)
return;
SetPixmap(nextItem);
update();
}
void PicAnimationWidget::SlidePre()
{
Stop();
if(!m_curItem)
return;
ProTreeItem *curProItem = dynamic_cast<ProTreeItem *>(m_curItem);
ProTreeItem *PreItem = curProItem->GetPreItem();
if(!PreItem)
return;
SetPixmap(PreItem);
update();
}
void PicAnimationWidget::TimeOut()
{
if(!m_curItem){
Stop();
update();
return;
}
m_factor = m_factor + 0.01;
if(m_factor >= 1){
m_factor = 0;
ProTreeItem *curProItem = dynamic_cast<ProTreeItem *>(m_curItem);
ProTreeItem *nextProItem = curProItem->GetNextItem();
if(!nextProItem){
Stop();
update();
return;
}
SetPixmap(nextProItem);
update();
return;
}
update();
}