-
Notifications
You must be signed in to change notification settings - Fork 3
/
EngineAPI.cpp
1048 lines (905 loc) · 30.2 KB
/
EngineAPI.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----本文件是引擎行为层给用户提供的接口的实现-----
#include "widget.h"
#include "configure.h"
#ifdef SelfAdaption
void adaptive(int &x,int &y)
{
x*=adaptiveRatioX;
y*=adaptiveRatioY;
}
void adaptive(float &x,float &y)
{
x*=adaptiveRatioX;
y*=adaptiveRatioY;
}
#endif
Pixmap* Widget::LoadPixmap(String PicPath)
{return new Pixmap(PicPath);}
int Widget::GetPixmapWidth(Pixmap *pixmap)
{return pixmap->width();}
int Widget::GetPixmapHeight(Pixmap *pixmap)
{return pixmap->height();}
Item* Widget::AddPixmapItem(String PicPath,int x,int y,String PressSlotfun,ParametersStru PressPar,String ReleaseSlotfun,ParametersStru ReleasePar,GraphicsScene *scene)
{
Pixmap mainpix(PicPath);
PixmapItem *item=new PixmapItem(mainpix,this);
item->SetEvent(PressSlotfun,PressPar,ReleaseSlotfun,ReleasePar);
scene->addItem(item);
item->setPos(x,y);
Item *ritem=new Item(item);
AllItem<<ritem;
return ritem;
}
Item* Widget::AddPixmapItem(Pixmap *pixmap,int x,int y,String PressSlotfun,ParametersStru PressPar,String ReleaseSlotfun,ParametersStru ReleasePar,GraphicsScene *scene)
{
PixmapItem *item=new PixmapItem(*pixmap,this);
item->SetEvent(PressSlotfun,PressPar,ReleaseSlotfun,ReleasePar);
scene->addItem(item);
item->setPos(x,y);
Item *ritem=new Item(item);
AllItem<<ritem;
return ritem;
}
Item* Widget::AddButtonItem(String PicPath,int x,int y,String ReleaseSlotfun, String PressPic, String PressMusic,int volume, ParametersStru ReleasePar, GraphicsScene *scene)
{
Pixmap mainpix(PicPath);
PixmapItem *item=new PixmapItem(mainpix,this);
if(PressPic!=NULL_String)
{item->SetButton(mainpix,Pixmap(PressPic),PressMusic,volume);}
else
{item->SetButton(mainpix,mainpix,PressMusic,volume);}
item->SetEvent(NULL_String,NULL_ParametersStru,ReleaseSlotfun,ReleasePar);
scene->addItem(item);
item->setPos(x,y);
Item *ritem=new Item(item);
AllItem<<ritem;
return ritem;
}
Item* Widget::AddButtonItem(Pixmap *pixmap,int x,int y,String ReleaseSlotfun, Pixmap *PressPic, String PressMusic,int volume, ParametersStru ReleasePar, GraphicsScene *scene)
{
PixmapItem *item=new PixmapItem(*pixmap,this);
if(PressPic!=nullptr)
{item->SetButton(*pixmap,*PressPic,PressMusic,volume);}
else
{item->SetButton(*pixmap,*pixmap,PressMusic,volume);}
item->SetEvent(NULL_String,NULL_ParametersStru,ReleaseSlotfun,ReleasePar);
scene->addItem(item);
item->setPos(x,y);
Item *ritem=new Item(item);
AllItem<<ritem;
return ritem;
}
Item* Widget::AddTextItem(String Text,String Font,int Size,int CR,int CG,int CB,int x,int y,GraphicsScene *scene)
{return AddTextItem(Text,Font,Size,RGBColor(CR,CG,CB),x,y,scene);}
Item* Widget::AddTextItem(String Text, String Font, int Size, RGBColor color, int x, int y, GraphicsScene *scene)
{
QGraphicsTextItem *text=new QGraphicsTextItem(Text);
text->setFont(QFont(Font,Size));
text->setDefaultTextColor(color);
text->setPos(x,y);
Item *item=new Item(nullptr,text);
AllItem<<item;
scene->addItem(text);
return item;
}
Item* Widget::AddRectItem(int x,int y,int width,int height,GraphicsScene *scene)
{
QGraphicsRectItem *rect=new QGraphicsRectItem(x,y,width,height);
scene->addItem(rect);
Item *item=new Item(nullptr,rect);
AllItem<<item;
return item;
}
Item* Widget::AddEllipseItem(int x,int y,int width,int height,GraphicsScene *scene)
{
QGraphicsEllipseItem *Ellipse=new QGraphicsEllipseItem(x,y,width,height);
scene->addItem(Ellipse);
Item *item=new Item(nullptr,Ellipse);
AllItem<<item;
return item;
}
Item* Widget::AddLineItem(int x,int y,int fx,int fy,GraphicsScene *scene)
{
QGraphicsLineItem *line=new QGraphicsLineItem(x,y,fx,fy);
scene->addItem(line);
Item *item=new Item(nullptr,line);
AllItem<<item;
return item;
}
void Widget::RotationItem(Item* item, float set,Pos originPos)
{
item->ItemPointer->setTransformOriginPoint(QPointF(originPos.x(),originPos.y()));
item->ItemPointer->setRotation(set);
}
void Widget::ScaleItem(Item* item, float set,Pos originPos)
{
item->ItemPointer->setTransformOriginPoint(originPos);
item->ItemPointer->setScale(set);
}
void Widget::BlurRadiusItem(Item* item, float set)
{
if(item->Blur==nullptr)
{item->Blur=new QGraphicsBlurEffect(this);}
item->Blur->setBlurRadius(set);
item->ItemPointer->setGraphicsEffect(item->Blur);
}
/*void Widget::DropShadowItem(Item* item, float shadowX,float shadowY)//还没写完
{
QGraphicsDropShadowEffect *e2 = new QGraphicsDropShadowEffect(this);
e2->setOffset(shadowX,shadowY);
item->ItemPointer->setGraphicsEffect(e2);
}*/
void Widget::MoveItem(Item* item, int x, int y)
{
item->ItemPointer->setPos(x,y);
#ifdef AutoIsColliding
itemMoveEvent();
#endif
}
void Widget::SetOpacityItem(Item* item, float set)
{item->ItemPointer->setOpacity(set);}
void Widget::SetRGBColorItem(Item* item,int R,int G,int B)
{
if(item->Color==nullptr)
{item->Color=new QGraphicsColorizeEffect(this);}
item->Color->setColor(RGBColor(R,G,B));
item->ItemPointer->setGraphicsEffect(item->Color);
}
void Widget::ClearScene(GraphicsScene *scene)
{
for(Item* i:AllItem)
{RemoveItem(i);}
scene->clear();//这句目测没用
}
void Widget::RemoveItem(Item* item)
{
if(item!=nullptr)
{
EndAllAnimation(item);
#ifdef SafetyPriority
SafeSleep(2);//等待目前进行这帧完成
#endif
AllItem.removeAt(AllItem.indexOf(item));
delete item;
}
}
String Widget::GetPath(String str)
{
String path;
QDir dir;
path=dir.currentPath();
path+="/"+str;
return path;
}
void Widget::SetVisibleItem(Item* item,bool Enabled)
{item->ItemPointer->setVisible(Enabled);}
void Widget::SetBackground(String PicturePath,GraphicsScene *scene)
{scene->setBackgroundBrush(Pixmap(PicturePath));}
void Widget::SetBackground(int R,int G,int B)
{SetBackground(RGBColor(R,G,B));}
void Widget::SetBackground(RGBColor color)
{MainScene->setBackgroundBrush(color);}
MusicPlayer* Widget::AddMusic(String name,int volume,bool cycle,String slotfun,ParametersStru par)
{
MusicPlayer *player=new MusicPlayer;
player->slotfun=slotfun; //如果不循环,该槽不会启动
player->par=par;
if(!cycle)
{player->singleplay(name,volume);}
else
{player->multipleplay(name,volume);}
return player;
}
void Widget::SetMusicVolume(MusicPlayer *player,int volume)
{player->setVolume(volume);}
int Widget::GetMusicVolume(MusicPlayer *player)
{return player->volume();}
void Widget::PauseMusic(MusicPlayer *player)
{player->pause();}
void Widget::PlayMusic(MusicPlayer *player)
{player->play();}
void Widget::StopMusic(MusicPlayer *player)
{player->stop();}
CaluThread* Widget::StartThread(String slotfun,ParametersStru par,bool track)
{
ExpansionSlot *slot=FindExpansionSlot(slotfun);
if(slot==nullptr)
{
//非扩展情况
if(track)
{
CaluThread *thread=new CaluThread(slotfun,par);
thread->start();
return thread;
}
RunFun(slotfun,par);
return nullptr;
}
//扩展情况
//即使是非追踪,调用扩展槽还是需要CaluThread,区别只是是否自动回收
CaluThread *thread=new CaluThread(slot,par,track);
thread->start();
if(track)
{return thread;}
return nullptr;
}
void Widget::RemoveThread(CaluThread *thread)
{
thread->quit();
thread->wait();
thread->playFinished();
}
bool Widget::ItemColliding(Item* item1,Item* item2)
{return isColliding(item1->ItemPointer,item2->ItemPointer);}
VideoPlayer* Widget::AddVideo(String path,int Volume,int x,int y,int width,int heigh,bool cycle,String signfun,ParametersStru par,GraphicsScene *scene)
{
VideoPlayer* video=new VideoPlayer(path,Volume,x,y,width,heigh,cycle,signfun,par,scene);
video->start();
return video;
}
void Widget::SetVideoVolume(VideoPlayer *video,int volume)
{video->mediaPlayer->setVolume(volume);}
int Widget::GetVideoVolume(VideoPlayer *video)
{return video->mediaPlayer->volume();}
void Widget::PauseVideo(VideoPlayer *video)
{video->mediaPlayer->pause();}
void Widget::PlayVideo(VideoPlayer *video)
{video->mediaPlayer->play();}
void Widget::StopVideo(VideoPlayer *video)
{video->mediaPlayer->stop();}
void Widget::AnimationRotationItem(Item* item, float set,long time,Pos originPos,String signfun)
{
EndAnimation(item,Rotation);
SC *sc=new SC(GetItemRotation(item),set,time,item,signfun,this);
item->ItemPointer->setTransformOriginPoint(originPos);
item->scPointer[Rotation]=sc;
sc->start(Rotation);
}
void Widget::AnimationRotationItem(Item *item, SCFun scfun, long time,Pos originPos,String signfun)
{
EndAnimation(item,Rotation);
SC *sc=new SC(0,0,time,item,signfun,this);
item->ItemPointer->setTransformOriginPoint(QPointF(originPos.x(),originPos.y()));
item->scPointer[Rotation]=sc;
sc->UesSCFun(scfun);
sc->start(Rotation);
}
void Widget::AnimationScaleItem(Item* item, float set,long time,Pos originPos,String signfun)
{
EndAnimation(item,Scale);
SC *sc=new SC(item->ItemPointer->scale(),set,time,item,signfun,this);
item->ItemPointer->setTransformOriginPoint(QPointF(originPos.x(),originPos.y()));
item->scPointer[Scale]=sc;
sc->start(Scale);
}
void Widget::AnimationScaleItem(Item *item, SCFun scfun, long time,Pos originPos,String signfun)
{
EndAnimation(item,Scale);
SC *sc=new SC(0,0,time,item,signfun,this);
item->ItemPointer->setTransformOriginPoint(QPointF(originPos.x(),originPos.y()));
item->scPointer[Scale]=sc;
sc->UesSCFun(scfun);
sc->start(Scale);
}
void Widget::AnimationBlurRadiusItem(Item* item, float set, long time,String signfun)
{
EndAnimation(item,BlurRadius);
SC *sc=new SC(GetItemBlur(item),set,time,item,signfun,this);
item->scPointer[BlurRadius]=sc;
sc->start(BlurRadius);
}
void Widget::AnimationBlurRadiusItem(Item *item, SCFun scfun, long time, String signfun)
{
EndAnimation(item,BlurRadius);
if(item->Blur==nullptr)
{item->Blur=new QGraphicsBlurEffect(this);}
SC *sc=new SC(0,0,time,item,signfun,this);
item->scPointer[BlurRadius]=sc;
sc->UesSCFun(scfun);
sc->start(BlurRadius);
}
void Widget::AnimationSetOpacityItem(Item* item, float set, long time,String signfun)
{
EndAnimation(item,Opacity);
SC *sc=new SC(GetItemOpacity(item),set,time,item,signfun,this);
item->scPointer[Opacity]=sc;
sc->start(Opacity);
}
void Widget::AnimationSetOpacityItem(Item *item, SCFun scfun, long time, String signfun)
{
EndAnimation(item,Opacity);
SC *sc=new SC(0,0,time,item,signfun,this);
item->scPointer[Opacity]=sc;
sc->UesSCFun(scfun);
sc->start(Opacity);
}
void Widget::AnimationMoveItem(Item* item,int x,int y,long time,String signfun)
{
EndAnimation(item,Move);
SC *sc=new SC(item->ItemPointer->x(),item->ItemPointer->y(),x,y,time,item,signfun,this);
item->scPointer[Move]=sc;
sc->start(Move);
}
void Widget::AnimationMoveItem(Item *item, SCFun scfun, long time, String signfun)
{
EndAnimation(item,Move);
SC *sc=new SC(0,0,0,0,time,item,signfun,this);
item->scPointer[Move]=sc;
sc->UesSCFun(scfun);
sc->start(Move);
}
void Widget::AnimationSetViewCenter(GraphicsView *view, int x, int y, long time, String signfun)
{
SC *sc=new SC(view->viewX,view->viewY,x,y,time,view,signfun,this);
sc->start(20);
}
void Widget::AnimationSetViewCenter(GraphicsView *view, SCFun scfun, long time, String signfun)
{
SC *sc=new SC(0,0,0,0,time,view,signfun,this);
sc->UesSCFun(scfun);
sc->start(20);
}
void Widget::AnimationShearItem(Item* item, float fx, float fy, long time, String signfun)
{
EndAnimation(item,Shear);
SC *sc=new SC(item->ShearX,item->ShearY,fx,fy,time,item,signfun,this);
item->scPointer[Shear]=sc;
sc->start(Shear);
}
void Widget::AnimationShearItem(Item *item, SCFun scfun, long time, String signfun)
{
EndAnimation(item,Shear);
SC *sc=new SC(0,0,0,0,time,item,signfun,this);
item->scPointer[Shear]=sc;
sc->UesSCFun(scfun);
sc->start(Shear);
}
void Widget::AnimationFreeScaleItem(Item *item, float fx, float fy, long time, String signfun)
{
EndAnimation(item,FreeScale);
SC *sc=new SC(item->FreeScaleX,item->FreeScaleY,fx,fy,time,item,signfun,this);
item->scPointer[FreeScale]=sc;
sc->start(FreeScale);
}
void Widget::AnimationFreeScaleItem(Item *item, SCFun scfun, long time, String signfun)
{
EndAnimation(item,FreeScale);
SC *sc=new SC(0,0,0,0,time,item,signfun,this);
item->scPointer[FreeScale]=sc;
sc->UesSCFun(scfun);
sc->start(FreeScale);
}
void Widget::AnimationSetRGBColorItem(Item* item, int R, int G, int B, long time,String signfun)
{
EndAnimation(item,Color);
//当前系数
float CurrentModulus;
float CurrentModulus2;
float CurrentModulus3;
if(item->Color==nullptr)
{
//如果之前没有进行过着色,从0,0,0开始着色
CurrentModulus=0;
CurrentModulus2=0;
CurrentModulus3=0;
item->Color=new QGraphicsColorizeEffect(this);
}
else
{
RGBColor color=item->Color->color();
CurrentModulus=color.red();
CurrentModulus2=color.green();
CurrentModulus3=color.blue();
}
SC *sc=new SC(CurrentModulus,CurrentModulus2,CurrentModulus3,R,G,B,time,item,signfun,this);
item->scPointer[Color]=sc;
sc->start(Color);
}
void Widget::AnimationSetRGBColorItem(Item* item, RGBColor color, long time,String signfun)
{
AnimationSetRGBColorItem(item,color.red(),color.green(),color.blue(),time,signfun);
}
void Widget::AnimationSetRGBColorItem(Item *item, SCFun scfun, long time, String signfun)
{
EndAnimation(item,Color);
SC *sc=new SC(0,0,0,0,0,0,time,item,signfun,this);
item->scPointer[Color]=sc;
sc->UesSCFun(scfun);
sc->start(Color);
}
Item* Widget::AddPicAnimation(QVector<String> address,int x,int y,long time,String signfun,bool cycle,GraphicsScene *scene)
{
assert(!address.isEmpty()); //确认传入的图片容器不为空
PixmapItem *temp=new PixmapItem(address.at(0));//将第一张图片变为图元
scene->addItem(temp);//将第一张图片显示在场景中
temp->setPos(x,y);
Item *item=new Item(temp);
AllItem<<item;
SC *sc=new SC(0,0,time,item,signfun,this);//创建SC实例,这里直接套用双系数的构造函数
item->scPointer[Picture]=sc;
sc->cycle=cycle;//定义是否循环连续播图
for(QVector<String>::iterator iter=address.begin();iter!=address.end();++iter)//遍历容器中的所有图片
{sc->pixmap.push_back(Pixmap(*iter));}//将所有图片压入SC类中储存图片的成员中
sc->start(Picture);
return item;
}
Item* Widget::AddPicAnimation(QVector<Pixmap*> allpixmap, int x, int y, long time, String signfun, bool cycle, GraphicsScene *scene)
{
assert(!allpixmap.isEmpty());
PixmapItem *item=new PixmapItem(*allpixmap.at(0));
Item *ritem=new Item(item);
scene->addItem(item);
item->setPos(x,y);
AllItem<<ritem;
SC *sc=new SC(0,0,time,ritem,signfun,this);
ritem->scPointer[Picture]=sc;
sc->cycle=cycle;
for(Pixmap* i:allpixmap)
{sc->pixmap.push_back(*i);}
sc->start(Picture);
return ritem;
}
void Widget::ChangePicAnimationItem(QVector<String>allpixmap,Item* item,long time,String signfun,bool cycle)
{
assert(!allpixmap.isEmpty());//断言,确认传入的图片容器不为空
EndAnimation(item,Picture);
PixmapItem *temp=item->PixmapItemPoniter;
temp->setPixmap(Pixmap(allpixmap.at(0)));//变更当前图片为图集的第一帧
SC *sc=new SC(0,0,time,item,signfun,this);//创建SC实例
item->scPointer[Picture]=sc;
sc->cycle=cycle;//定义是否循环连续播图
for(QVector<String>::iterator iter=allpixmap.begin();iter!=allpixmap.end();++iter)//遍历容器中的所有图片
{sc->pixmap.push_back(Pixmap(*iter));}//将所有图片压入SC类中储存图片的成员中
sc->start(Picture);
}
void Widget::ChangePicAnimationItem(QVector<Pixmap*> allpixmap, Item *item, long time, String signfun, bool cycle)
{
assert(!allpixmap.isEmpty());//断言,确认传入的图片容器不为空
EndAnimation(item,Picture);
PixmapItem *temp=item->PixmapItemPoniter;
temp->setPixmap(*allpixmap.at(0));//变更当前图片为图集的第一帧
SC *sc=new SC(0,0,time,item,signfun,this);//创建SC实例
item->scPointer[Picture]=sc;
sc->cycle=cycle;//定义是否循环连续播图
for(Pixmap* i:allpixmap)//遍历容器中的所有图片
{sc->pixmap.push_back(*i);}//将所有图片压入SC类中储存图片的成员中
sc->start(Picture);
}
//注意,开启自适应后这两个函数返回的是假坐标,即用户指定的
int Widget::GetItemX(Item* item)
{return item->ItemPointer->x();}
int Widget::GetItemY(Item* item)
{return item->ItemPointer->y();}
int Widget::GetItemR(Item* item)
{return (item->Color==nullptr)?-1:item->Color->color().red();}
int Widget::GetItemG(Item* item)
{return (item->Color==nullptr)?-1:item->Color->color().green();}
int Widget::GetItemB(Item* item)
{return (item->Color==nullptr)?-1:item->Color->color().blue();}
float Widget::GetItemBlur(Item* item)
{return (item->Blur==nullptr)?0:item->Blur->blurRadius();}
float Widget::GetItemOpacity(Item* item)
{return item->ItemPointer->opacity();}
float Widget::GetItemRotation(Item* item)
{return item->ItemPointer->rotation();}
float Widget::GetItemScale(Item* item)
{return item->ItemPointer->scale();}
void Widget::EndAnimation(Item* item,AnimationType choose)
{
if(item->scPointer[choose]!=nullptr)
{
item->scPointer[choose]->over=2;
item->scPointer[choose]=nullptr;
}
}
bool Widget::IsAnimation(Item* item,AnimationType choose)
{return (item->scPointer[choose]!=nullptr)?true:false;}
void Widget::EndAllAnimation(Item* item)
{
EndAnimation(item,Rotation);
EndAnimation(item,Scale);
EndAnimation(item,Move);
EndAnimation(item,BlurRadius);
EndAnimation(item,Opacity);
EndAnimation(item,Color);
EndAnimation(item,Picture);
EndAnimation(item,Shear);
EndAnimation(item,FreeScale);
}
void Widget::SetViewCenter(int x, int y,GraphicsView *gview)
{gview->SetCenter(x,y);}
void Widget::SetViewCenter(Item* item,GraphicsView *gview)
{gview->SetCenter(item->ItemPointer);}
int Widget::GetViewX(GraphicsView *gview)
{return gview->viewX;}
int Widget::GetViewY(GraphicsView *gview)
{return gview->viewY;}
GraphicsView* Widget::AddView(int x, int y, int width, int height)
{
#ifdef SelfAdaption
adaptive(x,y);
adaptive(width,height);
#endif
GraphicsView *view=new GraphicsView(this,this,x,y,width,height);
view->show();
#ifdef SelfAdaption
view->scale(adaptiveRatioX,adaptiveRatioX);
#endif
return view;
}
void Widget::SetViewSize(int x, int y, int width, int height, GraphicsView *gview)
{
#ifdef SelfAdaption
adaptive(x,y);
adaptive(width,height);
#endif
gview->setGeometry(x,y,width,height);
gview->SetCenter(width/2,height/2);
}
int Widget::GetScreenWidth()
{return QApplication::desktop()->width();}
int Widget::GetScreenHeigh()
{return QApplication::desktop()->height();}
GraphicsScene* Widget::AddScene(int width, int height)
{return new GraphicsScene(0,0,width,height);}
void Widget::SetViewScene(GraphicsView *view, GraphicsScene *scene,int viewX,int viewY)
{
view->setScene(scene);
#ifdef SelfAdaption
if(viewX==-1&&viewY==-1)
{
viewX=view->width()/adaptiveRatioX/2;
viewY=view->height()/adaptiveRatioY/2;
}
#endif
SetViewCenter(viewX,viewY);
}
void Widget::SafeSleep(long time)
{
QTimer T1;
QEventLoop Q1;
T1.setSingleShot(true);
connect(&T1,SIGNAL(timeout()),&Q1,SLOT(quit()));
T1.start(time);
Q1.exec();
}
void Widget::SetItemLayer(Item* item,int Layer)
{
//Qt默认都是0,如果在不手动排序的情况下将一个item设为顶层则设为1,底层-1
item->ItemPointer->setZValue(Layer);
}
void Widget::SetItemOrder(Item* Belowitem, Item* Aboveitem)
{Belowitem->ItemPointer->stackBefore(Aboveitem->ItemPointer);}
void Widget::ScaleView(float sX, float sY, GraphicsView *view)
{
#ifdef SelfAdaption
adaptive(sX,sY);
#endif
view->Scale(sX,sY);
}
void Widget::RotateView(float set, GraphicsView *view)
{view->Rotate(set);}
String Widget::ReadTXT(String path,int line)
{
if(path!=PreQFileName)
{
if(PreQFile!=nullptr)
{delete PreQFile;}
PreQFile=new QFile(path);
PreQFileName=path;
}
PreQFile->open(QIODevice::ReadOnly);
QTextStream text(PreQFile);
String concert;
if(line==-1)
{concert=text.readAll();}
else
{concert=text.readLine(line);}
PreQFile->close();
return concert;
}
void Widget::WriteTXT(String path, String text)//这个函数等等再搞,问题超大
{
if(path!=PreQFileName)
{
if(PreQFile!=nullptr)
{delete PreQFile;}
PreQFile=new QFile(path);
PreQFileName=path;
}
PreQFile->open(QFile::Text|QFile::Append);
QTextStream out(PreQFile);
out<<text;
PreQFile->close();
}
void Widget::WriteINI(String path, String section, String var, String value)
{
if(path!=PreQSetName)
{
if(PreQSet!=nullptr)
{delete PreQSet;}
PreQSet=new QSettings(path,QSettings::IniFormat);
PreQSetName=path;
}
PreQSet->setValue("/"+section+"/"+var,value);
}
String Widget::ReadINI(String path, String section, String var)
{
if(path!=PreQSetName)
{
if(PreQSet!=nullptr)
{delete PreQSet;}
PreQSet=new QSettings(path,QSettings::IniFormat);
PreQSetName=path;
}
String result=PreQSet->value("/"+section+"/"+var).toString();
return result;
}
String Widget::AESEncrypt(String str,String key)
{
AesHelper aes(key);
return aes.aesEncrypt(str);
}
String Widget::AESUncrypt(String str,String key)
{
AesHelper aes(key);
return aes.aesUncrypt(str);
}
void Widget::ChangePixmapItem(String path,Item* item)
{item->PixmapItemPoniter->setPixmap(Pixmap(path));}
void Widget::ChangePixmapItem(Pixmap* pixmap,Item* item)
{item->PixmapItemPoniter->setPixmap(*pixmap);}
void Widget::SetItemEvent(Item *item,String PressSlotfun,ParametersStru PressPar,String ReleaseSlotfun,ParametersStru ReleasePar)
{
assert(item->PixmapItemPoniter!=nullptr);
item->PixmapItemPoniter->SetEvent(PressSlotfun,PressPar,ReleaseSlotfun,ReleasePar);
}
void Widget::RemoveFile(String path)
{QFile::remove(path);}
void Widget::ShearItem(Item* item,float X,float Y)
{
QTransform tranform;
tranform.shear(X,Y);
item->ItemPointer->setTransform(tranform);
item->ShearX=X;
item->ShearY=Y;
}
void Widget::FreeScaleItem(Item *item,float X,float Y)
{
QTransform tranform;
tranform.scale(X,Y);
item->ItemPointer->setTransform(tranform);
item->FreeScaleX=X;
item->FreeScaleY=Y;
}
float Widget::GetItemShearX(Item* item)
{return item->ShearX;}
float Widget::GetItemShearY(Item* item)
{return item->ShearY;}
float Widget::GetItemFreeScaleX(Item *item)
{return item->FreeScaleX;}
float Widget::GetItemFreeScaleY(Item *item)
{return item->FreeScaleY;}
void Widget::AddKeyEvent(Qt::Key key,String PressSlotfun,ParametersStru PressPar,String ReleaseSlotfun,ParametersStru ReleasePar)
{
for(InputEvent &i:AllEvent)
{
if(i.key==key)
{
//如果已经有了,不能让空的给覆盖上
if(PressSlotfun!=NULL_String)
{i.PressFun=PressSlotfun;}
if(PressPar!=NULL_ParametersStru)
{i.PressPar=PressPar;}
if(ReleaseSlotfun!=NULL_String)
{i.ReleaseFun=ReleaseSlotfun;}
if(ReleasePar!=NULL_ParametersStru)
{i.ReleasePar=ReleasePar;}
return;
}
}
InputEvent event{key,-1,-1,-1,-1,PressPar,PressSlotfun,ReleasePar,ReleaseSlotfun,};
AllEvent<<event;
}
void Widget::RemoveKeyEvent(Qt::Key key)
{
for(int i=0;i<AllEvent.length();i++)
{
if(AllEvent.at(i).key==key)
{
AllEvent.removeAt(i);
return;
}
}
}
void Widget::AddMouseEvent(int mouseX,int mouseY,int fmouseX,int fmouseY,String PressSlotfun,ParametersStru PressPar,String ReleaseSlotfun,ParametersStru ReleasePar)
{
#ifdef SelfAdaption
adaptive(mouseX,mouseY);
adaptive(fmouseX,fmouseY);
#endif
for(InputEvent &i:AllEvent)
{
if(i.mouseX==mouseX&&i.mouseY==mouseY&&i.fmouseX==fmouseX&&i.fmouseY==fmouseY)
{
//如果已经有了,不能让空的给覆盖上
if(PressSlotfun!=NULL_String)
{i.PressFun=PressSlotfun;}
if(PressPar!=NULL_ParametersStru)
{i.PressPar=PressPar;}
if(ReleaseSlotfun!=NULL_String)
{i.ReleaseFun=ReleaseSlotfun;}
if(ReleasePar!=NULL_ParametersStru)
{i.ReleasePar=ReleasePar;}
return;
}
}
//没有就无所谓了
InputEvent event;
event.mouseX=mouseX;
event.mouseY=mouseY;
event.fmouseX=fmouseX;
event.fmouseY=fmouseY;
event.PressFun=PressSlotfun;
event.PressPar=PressPar;
event.ReleaseFun=ReleaseSlotfun;
event.ReleasePar=ReleasePar;
AllEvent<<event;
}
void Widget::RemoveMouseEvent(int mouseX, int mouseY,int fmouseX,int fmouseY)
{
#ifdef SelfAdaption
adaptive(mouseX,mouseY);
adaptive(fmouseX,fmouseY);
#endif
for(int i=0;i<AllEvent.length();i++)
{
if(AllEvent.at(i).mouseX==mouseX&&AllEvent.at(i).mouseY==mouseY&&AllEvent.at(i).fmouseX==fmouseX&&AllEvent.at(i).fmouseY==fmouseY)
{
AllEvent.removeAt(i);
return;
}
}
}
void Widget::RemoveAllEvent()
{AllEvent.clear();}
void Widget::WaitSign(String signfun)
{
QTimer t;
QEventLoop q;
t.setSingleShot(true);
QByteArray ba = signfun.toLatin1();
const char *function = ba.data();
connect(lfevent,function,&q,SLOT(quit()));
t.start();
q.exec();
}
void Widget::HorizontallyFlip(Item *item)
{
assert(item->PixmapItemPoniter!=nullptr);
Pixmap pixmap=item->PixmapItemPoniter->pixmap();
ChangePixmapItem(mirrorAndChange(&pixmap,true),item);
}
Pixmap* Widget::HorizontallyFlip(Pixmap *pixmap)
{return mirrorAndChange(pixmap,true);}
void Widget::VerticalFlip(Item *item)
{
assert(item->PixmapItemPoniter!=nullptr);
Pixmap pixmap=item->PixmapItemPoniter->pixmap();
ChangePixmapItem(mirrorAndChange(&pixmap,false),item);
}
Pixmap* Widget::VerticalFlip(Pixmap *pixmap)
{return mirrorAndChange(pixmap,false);}
Timer* Widget::StartMultipleTimer(String slotfun,long time)
{
QTimer *timer = new QTimer(this);
QByteArray ba = slotfun.toLatin1();
const char *ch=ba.data();
QObject::connect(timer,SIGNAL(timeout()),this,ch);
timer->start(time);
return timer;
}
void Widget::StartSingleTimer(String slotfun,long time)
{
QByteArray ba = slotfun.toLatin1();
const char *ch=ba.data();
QTimer::singleShot(time,this,ch);
}
Gesture* Widget::LoadGesture(QList<Pos> posSeq, int tolerance, String event)
{return new Gesture(posSeq,tolerance,event,false);}
Gesture* Widget::LoadGesture(LocusFunc locus, int tolerance, ProgressStand standard, int maxProgress, String event)
{return new Gesture(locus,standard,maxProgress,tolerance,event,false);}
void Widget::AddGesture(int mouseX,int mouseY,int fmouseX,int fmouseY,QList<Pos> posSeq,int tolerance,String event)
{AddGesture(mouseX,mouseY,fmouseX,fmouseY,new Gesture(posSeq,tolerance,event,true));}
void Widget::AddGesture(int mouseX, int mouseY, int fmouseX, int fmouseY, LocusFunc locus, int tolerance, ProgressStand standard, int maxProgress, String event)
{AddGesture(mouseX,mouseY,fmouseX,fmouseY,new Gesture(locus,standard,maxProgress,tolerance,event,true));}
void Widget::AddGesture(int mouseX, int mouseY, int fmouseX, int fmouseY, Gesture *gesture)
{
#ifdef SelfAdaption
adaptive(mouseX,mouseY);
adaptive(fmouseX,fmouseY);
#endif
for(GestureArea* i:AllGestureArea)
{
if(i->mouseX==mouseX&&i->mouseY==mouseY&&i->fmouseX==fmouseX&&i->fmouseX==fmouseX)
{
i->allGesture<<gesture; //一个区域拥有很多手势
return;
}
}
GestureArea *ga=new GestureArea(mouseX,mouseY,fmouseX,fmouseY);
ga->allGesture<<gesture;
this->AllGestureArea<<ga;
ga->allGesture<<gesture;
}
void Widget::RemoveGesture(Gesture *gesture)
{
//注意,这个函数对比地址删除。仅在保存创建的手势指针时才管用,再实例化一个一样的手势删除没用
for(GestureArea* i:AllGestureArea)
{i->allGesture.removeAll(gesture);}
delete gesture;
}
void Widget::RemoveGestureArea(int mouseX, int mouseY, int fmouseX, int fmouseY)
{
#ifdef SelfAdaption
adaptive(mouseX,mouseY);
adaptive(fmouseX,fmouseY);
#endif
for(int i=0;i<AllGestureArea.length();i++)
{
if(AllGestureArea[i]->mouseX==mouseX&&
AllGestureArea[i]->mouseY==mouseY&&
AllGestureArea[i]->fmouseX==fmouseX&&
AllGestureArea[i]->fmouseX==fmouseY)
{
delete AllGestureArea[i];
AllGestureArea.removeAt(i);
return;
}
}
}
void Widget::RemoveAllGestureArea()
{
for(GestureArea* i:AllGestureArea)
{delete i;}