-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreimplemen.cpp
242 lines (207 loc) · 6.08 KB
/
reimplemen.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//-----本文件是对于NewType.h中定义的类的实现部分-----
#include "widget.h"
QList<ExpansionSlot*> AllExpansionSlot;
//MyItem
void PixmapItem::SetButton(Pixmap up, Pixmap down, String Music,int volume)
{
this->isbutton=true;
this->up=up;
this->down=down;
this->Music=Music;
this->volume=volume;
}
void PixmapItem::SetEvent(String PressFun,ParametersStru PressPar,String ReleaseFun,ParametersStru ReleasePar)
{
this->PressFun=PressFun;
this->PressPar=PressPar;
this->ReleaseFun=ReleaseFun;
this->ReleasePar=ReleasePar;
}
bool PixmapItem::IsRegion()
{
int x=this->x();
int width=this->pixmap().width();
int y=this->y();
int height=this->pixmap().height();
int xmin,ymin,xmax,ymax;
xmin=x;
xmax=x+width;
if(x<0)
{xmin=0;}
if(x+width>WindowsWidth)
{xmax=WindowsWidth;}
ymin=y;
ymax=y+height;
if(y<0)
{ymin=0;}
if(y+height>WindowsHeigh)
{ymax=WindowsHeigh;}
if(xmax<s->mapFromGlobal(QCursor::pos()).x() || xmin>s->mapFromGlobal(QCursor::pos()).x())
{return false;}
if(ymax<s->mapFromGlobal(QCursor::pos()).y() || ymin>s->mapFromGlobal(QCursor::pos()).y())
{return false;}
return true;
}
/*void GraphicsView::mouseReleaseEvent(QMouseEvent *e)
{s->PassMouseReleaseEvent(e);}*/
void GraphicsView::mouseMoveEvent(QMouseEvent *e)
{s->PassMouseMoveEvent(e);}
void PixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
if(isbutton)//如果是按钮就放音乐并且切换图元
{
MusicPlayer *player=new MusicPlayer;
player->singleplay(Music,volume);
this->setPixmap(down);
}
if(PressFun!=NULL_String)//如果有事件,就执行
RunFun(PressFun,PressPar);
//传递本次点击到区域鼠标事件检测区
Pos nowpos=e->pos().toPoint();
nowpos=Pos(this->x()+nowpos.x(),this->y()+nowpos.y());
s->PassMousePressEvent(nowpos);
}
void PixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
{
if(isbutton)//是按钮切回原图元
this->setPixmap(up);
if(ReleaseFun!=NULL_String&&IsRegion())
RunFun(ReleaseFun,ReleasePar);
//传递本次释放到区域鼠标事件检测区
Pos nowpos=e->pos().toPoint();
nowpos=Pos(this->x()+nowpos.x(),this->y()+nowpos.y());
s->PassMouseReleaseEvent(nowpos);
}
//VideoPlayer
VideoPlayer::VideoPlayer(String Path, int Volume, int x, int y, int width, int heigh, bool cycle, String signfun,ParametersStru par,GraphicsScene *scene)
: QWidget(0)
{
mediaPlayer=new QMediaPlayer(0,QMediaPlayer::VideoSurface);
mediaPlayer->setVolume(Volume);
videoItem=new QGraphicsVideoItem;
videoItem->setSize(QSizeF(width,heigh));
scene->addItem(videoItem);
mediaPlayer->setVideoOutput(videoItem);
videoItem->setPos(x,y);//设置视频位置,默认为窗口左上角
this->cycle=cycle;
this->Path=Path;
this->signfun=signfun;
this->par=par;
}
void VideoPlayer::start()
{
mediaPlayer->setMedia(QUrl::fromLocalFile(Path));
mediaPlayer->play();
QObject::connect(mediaPlayer,SIGNAL(stateChanged(QMediaPlayer::State)),this,SLOT(playFinished(QMediaPlayer::State))); //绑定槽,播放后自动销毁
}
void VideoPlayer::playFinished(QMediaPlayer::State state)
{
Q_UNUSED(state);
/*if(state!=QMediaPlayer::StoppedState)
{return;}*/
if(!cycle)
{
if(signfun!=NULL_String)
RunFun(signfun,par);
delete this;
}
else
{mediaPlayer->play();}
}
VideoPlayer::~VideoPlayer()
{
this->mediaPlayer->stop();
delete mediaPlayer;
delete videoItem;
}
//MusicPlayer
void MusicPlayer::singleplay(String name, int volume)
{
this->setMedia(QUrl::fromLocalFile(name));
this->setVolume(volume);
this->play();
QObject::connect(this,SIGNAL(stateChanged(QMediaPlayer::State)),this,SLOT(playFinished(QMediaPlayer::State)));
}
void MusicPlayer::multipleplay(String name,int volume)
{
QUrl backgroundMusicUrl = QUrl::fromLocalFile(name);
if (QFile::exists(backgroundMusicUrl.toLocalFile()))
{
this->setVolume(volume);
cyclelist = new QMediaPlaylist();
QMediaContent media(backgroundMusicUrl);
cyclelist->addMedia(media);
cyclelist->setCurrentIndex(0);
// 设置背景音乐循环播放
cyclelist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
this->setPlaylist(cyclelist);
}
this->play();
}
void MusicPlayer::playFinished(QMediaPlayer::State state)
{
Q_UNUSED(state);
if(this->slotfun!=NULL_String)
RunFun(slotfun,par);
delete this; //播放结束后会自动释放资源
}
MusicPlayer::~MusicPlayer()
{
this->stop();
delete cyclelist;
}
//GraphicsView
GraphicsView::GraphicsView(QWidget *parent, Widget *s, int x, int y, int width, int height):QGraphicsView(parent),s(s)
{
this->setGeometry(x,y,width,height);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //禁用竖直滚动条
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //禁用水平滚动条
}
void GraphicsView::Scale(int sX, int sY)
{scale(sX,sY);}
void GraphicsView::Rotate(float set)
{rotate(set);}
void GraphicsView::SetCenter(int x, int y)
{
this->centerOn(x,y);
this->viewX=x;
this->viewY=y;
}
void GraphicsView::SetCenter(QGraphicsItem *item)
{
this->centerOn(item);
this->viewX=item->x();
this->viewY=item->y();
}
//Item
Item::Item(PixmapItem* pixmapitem,QGraphicsItem *graphicsitem)
{
this->PixmapItemPoniter=pixmapitem;
if(graphicsitem!=nullptr)
this->ItemPointer=graphicsitem;
else
this->ItemPointer=pixmapitem;
for(unsigned int a=0;a<sizeof(this->scPointer)/sizeof(this->scPointer[0]);++a)
this->scPointer[a]=nullptr;
}
Item::~Item()
{
if(PixmapItemPoniter==nullptr)
{delete ItemPointer;}
else
{delete PixmapItemPoniter;}
delete Blur;
delete Color;
}
//JSParStru
void JSParStru::add(QObject *pointer,QString name)
{
pointerVec<<pointer;
nameVec<<name;
}
bool JSParStru::operator !=(const JSParStru &par)
{
if(pointerVec==par.pointerVec&&nameVec==par.nameVec)
{return false;}
return true;
}