-
Notifications
You must be signed in to change notification settings - Fork 33
/
widget.cpp
6397 lines (5334 loc) · 205 KB
/
widget.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 "ui_widget.h"
#include<QMediaPlayer>
#include<QMediaPlaylist>
#include<QFileDialog>
#include<QUrl>
#include<QDir>
#include<QSqlDatabase>
#include<QSqlQuery>
#include<QSqlQueryModel>
#include<QSqlTableModel>
#include<QMenu>
#include<dwmapi.h>
#include<windowsx.h>
#include<QPainter>
#include<QScrollBar>
#include<qmath.h>
#include<QShortcut>
#include<QMessageBox>
#include<QProgressBar>
#include<QProgressDialog>
#include"dialog.h"
#include<QGraphicsDropShadowEffect>
#include<QFile>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
setAutoFillBackground(true);
ui->lineEdit->setPlaceholderText(("输入歌手或歌曲"));
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
effect->setOffset(1,1);
effect->setColor(QColor(0,0,0,100));
effect->setBlurRadius(15);
ui->frame->setGraphicsEffect(effect);
ui->frame->setAutoFillBackground(true);
currentFileName.push_back("D:/");
currentFileName.push_back("D:/");
currentFileName.push_back("D:/");
currentFileName.push_back("D:/");
CreateSortCut();
init_else();
init_icon();
init_list();
init_tooltip();
init_win();
init_action();
init_Connect();
ListItemToolTip();
}
inline void Widget::init_else()
{
labelText1.push_back("You may only be a person in this world,");
labelText2.push_back("but for someone,you're the world.");
labelText1.push_back("May there be enough clouds in your life");
labelText2.push_back(" to make a beautiful sunset.");
labelText1.push_back("The best feeling the world is when you");
labelText2.push_back(" know your heart is smiling.");
labelText1.push_back("Love begins with a smile,grows with a");
labelText2.push_back(" kiss and ends with a tear.");
labelText1.push_back("Life is not lack of beauty,but lack");
labelText2.push_back(" of the eyes to find beauty.");
labelText1.push_back("The shortest distance between");
labelText2.push_back(" two people is a smile.");
labelText1.push_back("Life is not about waiting for the storm to pass.");
labelText2.push_back("It's about learning to dance in the rain.");
labelText1.push_back("In order to be irrepaceable,one");
labelText2.push_back(" must always be different.");
labelText1.push_back("The minute you think of giving up,think of");
labelText2.push_back("the reason why you held on so long.");
labelText1.push_back("Life is a shipwreck,but we must not");
labelText2.push_back(" forget to sing in the lifeboats.");
labelText1.push_back("Give everything a shot.You never know what or");
labelText2.push_back("who is going to change your life.");
ui->listWidget->verticalScrollBar()->setCursor(Qt::PointingHandCursor);
ui->listWidget_2->verticalScrollBar()->setCursor(Qt::PointingHandCursor);
ui->listWidget_3->verticalScrollBar()->setCursor(Qt::PointingHandCursor);
ui->listWidget_4->verticalScrollBar()->setCursor(Qt::PointingHandCursor);
QString listWidgetStyle = "QScrollBar:vertical"
"{"
"width:8px;"
"background-color:transparent;"
"margin:0px,0px,0px,0px;"
" padding-top:12px; /*上预留位置*/"
" padding-bottom:12px; /*下预留位置*/"
"}"
" QScrollBar::handle:vertical"
" {"
"width:8px;"
" background-color:rgba(255,255,255,0.2);"
" border-radius:4px;"
" min-height:20px;"
" }"
" QScrollBar::handle:vertical:hover"
" {"
" width:9px;"
" background-color:rgba(255,255,255,0.5);"
" border-radius:4px;"
" min-height:20;"
" }"
" QScrollBar::add-line:vertical"
" {"
" height:12px;"
" width:10px;"
" border-image:url(:/selectfile/scroll/3.png);"
" subcontrol-position:bottom;"
" }"
" QScrollBar::sub-line:vertical"
" {"
" height:12px;"
"width:10px;"
" border-image:url(:/selectfile/scroll/1.png);"
"subcontrol-position:top;"
" }"
" QScrollBar::add-line:vertical:hover"
" {"
" height:12px;"
"width:10px;"
" border-image:url(:/selectfile/scroll/4.png);"
"subcontrol-position:bottom;"
" }"
" QScrollBar::sub-line:vertical:hover"
" {"
" height:12px;"
" width:10px;"
" border-image:url(:/selectfile/scroll/2.png);"
" subcontrol-position:top;"
" }"
" QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical"
" {"
" background-color:transparent;"
" border-radius:4px;"
"}";
ui->listWidget_2->verticalScrollBar()->setStyleSheet(listWidgetStyle);
ui->listWidget_3->verticalScrollBar()->setStyleSheet(listWidgetStyle);
ui->listWidget->verticalScrollBar()->setStyleSheet(listWidgetStyle);
ui->listWidget_4->verticalScrollBar()->setStyleSheet(listWidgetStyle);
ui->listWidget_5->verticalScrollBar()->setStyleSheet(listWidgetStyle);
Music=new Dialog();//小播放器
Music->setWindowFlags(Qt::FramelessWindowHint);//设置窗体类型
QSqlQuery query;
query.exec("select * from WALLPAPER_DATA");//主窗口壁纸数据
query.next();
QString FileName=query.value(0).toString();
QString FileName1;
if(FileName.isEmpty())
{
FileName1 = ":/image/image/background/bg8.jpg";
}
else
{
FileName1 = FileName;
}
query.exec("select * from TRA_DATA");//主窗口透明度数据
query.next();
QString Values=query.value(0).toString();
if(Values.isEmpty())
{
transparency=1;
}
else
{
transparency=Values.toDouble();
}
ui->frame->setWindowOpacity(transparency);//设置透明度
ui->frame->setStyleSheet(QString("QFrame#frame{border-radius:5px;border-image: url(%1);}").arg(FileName1));
music=new QMediaPlayer(this);
playlist =new QMediaPlaylist(this);//本地音乐播放列表
playlist->setPlaybackMode(QMediaPlaylist::Loop);//随机播放
playlist_2=new QMediaPlaylist(this);//我喜欢播放列表
playlist_2->setPlaybackMode(QMediaPlaylist::Loop);//随机播放
playlist_3=new QMediaPlaylist(this);//我的收藏播放列表
playlist_3->setPlaybackMode(QMediaPlaylist::Loop);//随机播放
playlist_4 = new QMediaPlaylist(this);
playlist_4->setPlaybackMode(QMediaPlaylist::Loop);
ui->verticalSlider->hide();
ui->verticalSlider->setValue(100);
ui->horizontalSlider->setValue(0);
ui->stackedWidget->setCurrentIndex(0);
ui->pushButton_10->setStyleSheet("QPushButton"
"{"
"background-image: url(:/image/image/image-hover/music-hover.png);"
"background-repeat:no-repeat;"
"background-position:center center;"
"border:none;"
"}"
"QPushButton:hover{"
"background-image: url(:/image/image/image-hover/music-hover.png);"
"background-repeat:no-repeat;"
"background-position:center center;"
"}"
"QPushButton:pressed{"
"background-image: url(:/image/image/image/music.png);"
"background-repeat:no-repeat;"
"background-position:center center;"
"}"
);
}
inline void Widget::init_win()
{
QMenu *ToolMenu=new QMenu(this);//任务栏菜单
if(QtWin::isCompositionEnabled())
{
QtWin::enableBlurBehindWindow(ToolMenu);
}
else
{
QtWin::disableBlurBehindWindow(ToolMenu);
ToolMenu->hide();
}
toolbar=new QWinThumbnailToolBar(this);
toolbar->setWindow(windowHandle());
next=new QWinThumbnailToolButton(this);//下一首
pre=new QWinThumbnailToolButton(this);//上一首
pause=new QWinThumbnailToolButton(this);//播放暂停
next->setToolTip(("下一首"));
next->setIcon(QIcon(":/image/image/next1.png"));
connect(next,&QWinThumbnailToolButton::clicked,this,&Widget::action9_slot);//下一首->action10_slot槽
pre->setToolTip(("上一首"));
pre->setIcon(QIcon(":/image/image/pre1.png"));
connect(pre,&QWinThumbnailToolButton::clicked,this,&Widget::action10_slot);//上一首->action9_slot槽
pause->setToolTip(("暂停"));
pause->setIcon(QIcon(":/image/image/bf13.png"));
connect(pause,&QWinThumbnailToolButton::clicked,this,&Widget::on_pushButton_2_clicked);//播放/暂停->on_pushButton_2_clicked槽
toolbar->addButton(pre);//任务栏增加按钮
toolbar->addButton(pause);//任务栏增加按钮
toolbar->addButton(next);//任务栏增加按钮
Taskbotton=new QWinTaskbarButton(this);//任务栏
TaskProgress=new QWinTaskbarProgress(this);//进度条
Taskbotton->setWindow(windowHandle());
TaskProgress=Taskbotton->progress();//获取任务栏的进度条
connect(ui->horizontalSlider,&QSlider::valueChanged,TaskProgress,&QWinTaskbarProgress::setValue);//进度条数值改变->设置任务栏进度条数值
connect(ui->horizontalSlider,&QSlider::rangeChanged,TaskProgress,&QWinTaskbarProgress::setRange);//进度条范围改变->设置任务栏进度条范围
}
inline void Widget::init_Connect(){
connect(music,&QMediaPlayer::metaDataAvailableChanged,this,&Widget::updateInfo);//音乐歌名改变->更新显示文本
connect(music,&QMediaPlayer::positionChanged,this,&Widget::updatePosition);//播放的位置改变->更新进度条播放位置
connect(music,&QMediaPlayer::durationChanged,this,&Widget::updateDuration);//播放歌曲改变->更新进度条
connect(ui->horizontalSlider,&QSlider::sliderMoved,music,&QMediaPlayer::setPosition);//进度条移动->更新音乐的播放位置
connect(playlist,&QMediaPlaylist::currentIndexChanged,this,&Widget::updatalistwidget_3);//本地音乐播放列表位置改变->更新listWidget_3的位置
connect(playlist_2,&QMediaPlaylist::currentIndexChanged,this,&Widget::updatalistwidget_2);//我喜欢播放列表位置改变->更新listWidget_2的位置
connect(playlist_3,&QMediaPlaylist::currentIndexChanged,this,&Widget::updatalistwidget);//我的收藏播放列表位置改变->更新listWidget的位置
connect(action1,&QAction::triggered,this,&Widget::action1_slot);//添加至本地音乐动作点击->执行action1_slot槽
connect(action2,&QAction::triggered,this,&Widget::action2_slot);//添加我喜欢动作点击->执行action2_slot槽
connect(action3,&QAction::triggered,this,&Widget::action3_slot);//添加我的收藏动作点击->执行action3_slot槽
connect(action4_1,&QAction::triggered,this,&Widget::action4_1_slot);//透明度加动作点击->执行action4_1_slot槽
connect(action4_2,&QAction::triggered,this,&Widget::action4_2_slot);//透明度减动作点击->执行action4_2_slot槽
connect(action5_1,&QAction::triggered,this,&Widget::action5_1_slot);//默认皮肤1动作点击->执行action5_1_slot槽
connect(action5_2,&QAction::triggered,this,&Widget::action5_2_slot);//默认皮肤2动作点击->执行action5_2_slot槽
connect(action5_3,&QAction::triggered,this,&Widget::action5_3_slot);//自定义皮肤动作点击->执行action5_3_slot槽
connect(action5_4,&QAction::triggered,this,&Widget::action5_4_slot);//3
connect(action6,&QAction::triggered,this,&Widget::action6_slot);//关于动作点击->执行action6_slot槽
connect(action7,&QAction::triggered,this,&Widget::action7_slot);//使用介绍动作点击->执行action7_slot槽
connect(action8,&QAction::triggered,this,&Widget::action8_slot);//退出动作点击->执行action8_slot槽
connect(ClearALL_1,&QAction::triggered,this,&Widget::ClearALL_1_slot);//清除本地音乐动作点击->执行ClearALL_1_slot槽
connect(ClearALL_2,&QAction::triggered,this,&Widget::ClearALL_2_slot);//清除我喜欢动作点击->执行ClearALL_2_slot槽
connect(ClearALL_3,&QAction::triggered,this,&Widget::ClearALL_3_slot);//清除我的收藏动作点击->执行ClearALL_3_slot槽
connect(ClearALL_4,&QAction::triggered,this,&Widget::ClearALL_4_slot);//清除所有音乐动作点击->执行ClearALL_4_slot槽
connect(action13,&QAction::triggered,this,&Widget::action8_slot);//退出动作点击->执行action8_slot槽
connect(action9,&QAction::triggered,this,&Widget::action9_slot);//播放上一首动作点击->执行action9_slot槽
connect(action10,&QAction::triggered,this,&Widget::action10_slot);//播放下一首动作点击->执行action10_slot槽
connect(action11,&QAction::triggered,this,&Widget::action11_slot);//暂停动作点击->执行action11_slot槽
connect(action11_1,&QAction::triggered,this,&Widget::action11_1_slot);//播放动作点击->执行action11_1_slot槽
connect(action12_1,&QAction::triggered,this,&Widget::action12_1_slot);//顺序播放动作点击->执行action12_1_slot槽
connect(action12_2,&QAction::triggered,this,&Widget::action12_2_slot);//随机播放动作点击->执行action12_2_slot槽
connect(action12_3,&QAction::triggered,this,&Widget::action12_3_slot);//单曲循环播放动作点击->执行action12_3_slot槽
connect(ui->verticalSlider,&QSlider::valueChanged,this,&Widget::changeVolume);//音量进度条置的改变->音量改变
connect(music,&QMediaPlayer::stateChanged,this,&Widget::music_stateChang);//音乐的播放状态改变->执行music_stateChang槽
connect(Music,&Dialog::Data,this,&Widget::Data_slot);//接收极简播放器的数据
connect(detila,&QAction::triggered,this,&Widget::detila_slot);//歌曲详情动作点击->执行detila_slot槽
connect(playlist,&QMediaPlaylist::playbackModeChanged,this,&Widget::PlaylistModel_slot);//播放列表模型改变->执行Widget::PlaylistModel_slot槽
connect(location,&QAction::triggered,this,&Widget::on_pushButton_7_clicked);//定位动作点击->执行on_pushButton_7_clicked槽
connect(ClearHistory,&QAction::triggered,this,&Widget::ClearHistory_Slot);
}
inline void Widget::init_tooltip()
{
ui->horizontalSlider->setToolTip(("播放进度"));
ui->pushButton->setToolTip(("添加歌曲"));
ui->pushButton_2->setToolTip(("暂停"));
ui->pushButton_3->setToolTip(("下一首"));
ui->pushButton_4->setToolTip(("上一首"));
ui->pushButton_5->setToolTip(("设置"));
ui->pushButton_6->setToolTip(("更换皮肤"));
ui->pushButton_7->setToolTip(("定位"));
ui->pushButton_8->setToolTip(("音量"));
ui->pushButton_9->setToolTip(("顺序播放"));
ui->pushButton_10->setToolTip(("本地音乐"));
ui->pushButton_11->setToolTip(("我喜欢"));
ui->pushButton_12->setToolTip(("我的收藏"));
ui->pushButton_13->setToolTip(("切换至极简模式/双击"));
ui->pushButton_15->setToolTip(("隐藏播放列表"));
ui->pushButton_17->setToolTip(("关闭"));
ui->pushButton_16->setToolTip(("最小化"));
}
inline void Widget::init_icon()
{
ui->pushButton_2->setIconSize(QSize(48,48));//暂停/播放
ui->pushButton_2->setIcon(QIcon(":/image/image/image/pase.png"));
ui->pushButton_2->setStyleSheet(PaseStyle());
ui->pushButton_15->setIconSize(QSize(32,32));//隐藏/显示播放列表
ui->pushButton_15->setIcon(QIcon(":/image/image/image/left.png"));
ui->pushButton_15->setStyleSheet(HideListStyle());
ui->pushButton_9->setIconSize(QSize(32,32));//播放模式
ui->pushButton_9->setIcon(QIcon(":/image/image/image/loop.png"));
ui->pushButton_9->setStyleSheet(LoopStyle());
ui->pushButton_14->setIconSize(QSize(32,32));//我喜欢
ui->pushButton_14->setIcon(QIcon(":/image/image/image/Ilike.png"));
ui->pushButton_14->setStyleSheet(IlikeStyle());
ui->pushButton_8->setIconSize(QSize(32,32));//音量
ui->pushButton_8->setStyleSheet(VoiceStyle());
ui->pushButton_8->setIcon(QIcon(":/image/image/image/music-voice.png"));
}
inline void Widget::init_action()
{
action1=new QAction(this);//添加至本地音乐
action2=new QAction(this);//添加至我喜欢
action3=new QAction(this);//添加至我的收藏
action1->setIcon(QIcon(":/image/image/music_32px_1125557_easyicon.net.png"));
action1->setText(("添加至本地音乐"));
action1->setShortcut(QKeySequence("Ctrl+O"));
action2->setIcon(QIcon(":/image/image/like_outline_32px_1101681_easyicon.net.png"));
action2->setText(("添加至我喜欢"));
action2->setShortcut(QKeySequence("Ctrl+A"));
action3->setIcon(QIcon(":/image/image/list_32px_1074296_easyicon.net.png"));
action3->setText(("添加至我的收藏"));
action3->setShortcut(QKeySequence("Ctrl+Z"));
QMenu *menu1=new QMenu(this);//添加菜单
menu1->addAction(action1);
menu1->addAction(action2);
menu1->addAction(action3);
add=new QAction(this);//添加歌曲
add->setIcon(QIcon(":/image/image/add.png"));
add->setText(("添加歌曲"));
add->setMenu(menu1);
menu1->setStyleSheet(
MenuStyle()
);
ui->pushButton->setMenu(menu1);
location=new QAction(this);//定位
location->setText(("定位"));
location->setIcon(QIcon(":/image/image/location_32px_1074876_easyicon.net.png"));
action4=new QAction(this);//设置透明度
action5=new QAction(this);//设置皮肤
action5_1=new QAction(this);//默认皮肤1
action5_2=new QAction(this);//默认皮肤2
action5_3=new QAction(this);//自定义皮肤
action5_4 = new QAction(this);
action6=new QAction(this);//关于
action7=new QAction(this);//使用介绍
action8=new QAction(this);//退出
ClearALL=new QAction(this);//清除
ClearALL_1=new QAction(this);//清除本地音乐
ClearALL_2=new QAction(this);//清除我喜欢
ClearALL_3=new QAction(this);//清除我的收藏
ClearALL_4=new QAction(this);//清除所有
ClearHistory = new QAction(this);//清除历史记录
action4->setIcon(QIcon(":/image/image/ooopic_1500874104.png"));
action4->setText(("设置透明度 "));
action4_1=new QAction(this);//透明度加
action4_2=new QAction(this);//透明度减
action4_1->setIcon(QIcon(":/image/image/add.png"));
action4_1->setText(("+5%"));
action4_1->setShortcut(QKeySequence("Ctrl++"));
action4_2->setIcon(QIcon(":/image/image/sub.png"));
action4_2->setText(("-5%"));
action4_2->setShortcut(QKeySequence("Ctrl+-"));
QMenu *temp=new QMenu(this);//透明度菜单
temp->addAction(action4_1);
temp->addAction(action4_2);
temp->setStyleSheet(
MenuStyle()
);
action4->setMenu(temp);
action5->setIcon(QIcon(":/image/image/pf.png"));
action5->setText(("设置皮肤"));
action5_1->setIcon(QIcon(":/image/image/pf2.png"));
action5_1->setText(("绿色"));
action5_2->setIcon(QIcon(":/image/image/pf5.png"));
action5_2->setText(("动漫"));
action5_4->setIcon(QIcon(":/image/image/pf.png"));
action5_4->setText(("蓝色"));
action5_3->setIcon(QIcon(":/image/image/pf4.png"));
action5_3->setText(("自定义"));
action5_3->setShortcut(QKeySequence("Ctrl+X"));
QMenu *ChangeBackGroundMenu=new QMenu(this);//设置皮肤菜单
ChangeBackGroundMenu->addAction(action5_1);
ChangeBackGroundMenu->addAction(action5_2);
ChangeBackGroundMenu->addAction(action5_4);
ChangeBackGroundMenu->addAction(action5_3);
ChangeBackGroundMenu->setStyleSheet(
MenuStyle()
);
action5->setMenu(ChangeBackGroundMenu);
ui->pushButton_6->setMenu(ChangeBackGroundMenu);
action6->setIcon(QIcon(":/image/image/ooopic_1500873230.png"));
action6->setText(("关于"));
action7->setIcon(QIcon(":/image/image/ooopic_1500873272.png"));
action7->setText(("使用介绍"));
ClearALL->setIcon(QIcon(":/image/image/edit_clear_locationbar_ltr_32px_539686_easyicon.net.png"));
ClearALL->setText(("清除"));
ClearALL_1->setIcon(QIcon(":/image/image/Music_32px_1144946_easyicon.net.png"));
ClearALL_1->setText(("清除本地音乐列表"));
ClearALL_1->setShortcut(QKeySequence("Ctrl+M"));
ClearALL_2->setIcon(QIcon(":/image/image/like_outline_32px_1170275_easyicon.net.png"));
ClearALL_2->setText(("清除我喜欢列表"));
ClearALL_2->setShortcut(QKeySequence("Ctrl+N"));
ClearALL_3->setIcon(QIcon(":/image/image/list_32px_1142913_easyicon.net.png"));
ClearALL_3->setText(("清除我的收藏"));
ClearALL_3->setShortcut(QKeySequence("Ctrl+B"));
ClearALL_4->setIcon(QIcon(":/image/image/playlist_27.690544412607px_1187707_easyicon.net.png"));
ClearALL_4->setText(("清除所有列表"));
ClearALL_4->setShortcut(QKeySequence("Ctrl+V"));
ClearHistory->setIcon(QIcon(":/image/image/nextbo.png"));
ClearHistory->setText(("清除历史记录"));
ClearHistory->setShortcut(QKeySequence("Ctrl+Shift+S"));
QMenu *M=new QMenu(this);//清除菜单
M->addAction(ClearALL_1);
M->addAction(ClearALL_2);
M->addAction(ClearALL_3);
M->addAction(ClearALL_4);
M->addAction(ClearHistory);
M->setStyleSheet(MenuStyle());
ClearALL->setMenu(M);
action8->setIcon(QIcon(":/image/image/tc.png"));
action8->setText(("退出"));
action8->setShortcut(QKeySequence("Ctrl+Q"));
QMenu *menu2=new QMenu(this);//设置键菜单
menu2->addAction(action4);
menu2->addAction(action5);
menu2->addAction(action6);
menu2->addAction(action7);
menu2->addAction(ClearALL);
menu2->addAction(action8);
menu2->setStyleSheet(MenuStyle());
ui->pushButton_5->setMenu(menu2);
action9=new QAction(this);//播放上一首
action9->setIcon(QIcon(":/image/image/pre1.png"));
action9->setText(("播放上一首"));
action10=new QAction(this);//播放下一首
action10->setIcon(QIcon(":/image/image/next1.png"));
action10->setText(("播放下一首"));
action11=new QAction(this);//暂停
action11->setIcon(QIcon(":/image/image/zangting.png"));
action11->setText(("暂停"));
action11_1=new QAction(this);//播放
action11_1->setIcon(QIcon(":/image/image/bf2.png"));
action11_1->setText(("播放"));
action12=new QAction(this);//播放模式
action12->setIcon(QIcon(":/image/image/moshi1.png"));
action12->setText(("播放模式"));
action12_1=new QAction(this);//顺序播放
action12_1->setIcon(QIcon(":/image/image/player-icons_32px_1137007_easyicon.net.png"));
action12_1->setText(("顺序播放"));
action12_2=new QAction(this);//随机播放
action12_2->setIcon(QIcon(":/image/image/player-icons_32px_1137005_easyicon.net.png"));
action12_2->setText(("随机播放"));
action12_3=new QAction(this);//单曲循环
action12_3->setIcon(QIcon(":/image/image/player-icons_32px_1137006_easyicon.net.png"));
action12_3->setText(("单曲循环"));
QMenu *temp1=new QMenu(this);//播放模式菜单
temp1->addAction(action12_1);
temp1->addAction(action12_2);
temp1->addAction(action12_3);
temp1->setStyleSheet(
MenuStyle()
);
action12->setMenu(temp1);
action13=new QAction(this);//退出
action13->setIcon(QIcon(":/image/image/tc.png"));
action13->setShortcut(QKeySequence("Ctrl+Q"));
action13->setText(("退出"));
detila = new QAction(this);//歌曲详情
detila->setIcon(QIcon(":/image/image/inf.png"));
detila->setText(("歌曲信息"));
}
inline void Widget::init_list()
{
QSqlQuery query;
model=new QSqlTableModel(this);//本地音乐列表数据库模型
model->setTable("LocalMusic");
model->select();
model_2=new QSqlTableModel(this);//我喜欢列表数据库模型
model_2->setTable("LikeMusic");
model_2->select();
model_3=new QSqlTableModel(this);//我的收藏数据库模型
model_3->setTable(" CollectMusic");
model_3->select();
query.exec("select * from LocalMusic");
while(query.next())//初始化本地音乐播放列表
{
QString Name=query.value(1).toString();
QString FileName=query.value(2).toString();
if(!Name.isEmpty()&&!FileName.isEmpty())
{
QListWidgetItem *item1=new QListWidgetItem;
item1->setIcon(QIcon(":/image/image/Music_32px_1144946_easyicon.net.png"));
item1->setText(Name);
ui->listWidget_3->addItem(item1);
playlist->addMedia(QUrl::fromLocalFile(FileName));
list1.push_back(0);
FilePath.push_back(FileName);
}
}
query.exec("select * from LikeMusic");
while(query.next())//初始化我喜欢播放列表
{
QString Name=query.value(1).toString();
QString FileName=query.value(2).toString();
if(!Name.isEmpty()&&!FileName.isEmpty())
{
QListWidgetItem *item4=new QListWidgetItem;
item4->setIcon(QIcon(":/image/image/like_outline_32px_1170275_easyicon.net.png"));
item4->setText(Name);
ui->listWidget_2->addItem(item4);
playlist_2->addMedia(QUrl::fromLocalFile(FileName));
}
}
query.exec("select * from CollectMusic");
while(query.next())//初始化我的收藏播放列表
{
QString Name=query.value(1).toString();
QString FileName=query.value(2).toString();
if(!Name.isEmpty()&&!FileName.isEmpty())
{
QListWidgetItem *item5=new QListWidgetItem;
item5->setIcon(QIcon(":/image/image/music_not_25.570093457944px_1171234_easyicon.net.png"));
item5->setText(Name);
ui->listWidget->addItem(item5);
playlist_3->addMedia(QUrl::fromLocalFile(FileName));
}
}
music->setPlaylist(playlist);
ui->listWidget_5->clear();
}
inline QString Widget::MusicListStyle(){
return "QPushButton"
" {"
"background-image:url(:/image/image/image/music.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image/music.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/music.png);"
"}";
}
inline QString Widget::MenuStyle()
{
return " QMenu {"
" background: white; "
"border-radius:2px;"
"border:1px solid rgb(200,200,200);"
" }"
" QMenu::item {"
" background-color: transparent;"
" padding:5px 30px;"
" margin:0px 0px;"
" border-bottom:0px solid #DBDBDB;"
"}"
" QMenu::item:selected { "
"background-color: aqua;"
"}";
}
inline QString Widget::PlayStyle()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/play.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/play-hover.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/play.png);"
"}";
}
inline QString Widget::PaseStyle()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/pase.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/pase-hover.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/pase.png);"
"}";
}
inline QString Widget::IlikeStyle()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/Ilike.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/Ilike-hover.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/Ilike.png);"
"}";
}
inline QString Widget::Ilike1Style()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/Ilike1.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/Ilike1-hover.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/Ilike1.png);"
"}";
}
inline QString Widget::ShowListStyle()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/right.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/right-hover.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/right.png);"
"}";
}
inline QString Widget::HideListStyle()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/left.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/left-light.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/left.png);"
"}";
}
inline QString Widget::RandomStyle()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/play-random.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/play-random-hover.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/play-random.png);"
"}";
}
inline QString Widget::LoopStyle()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/loop.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/loop-hover.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/loop.png);"
"}";
}
inline QString Widget::LoopOneStyle()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/loop-one.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/loop-one-hover.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/loop-one.png);"
"}";
}
inline QString Widget::VoiceStyle()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/music-voice.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/music-voice-hover.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/music-voice.png);"
"}";
}
inline QString Widget::NoVoiceStyle()
{
return "QPushButton"
" {"
"background-image:url(:/image/image/image/none-music.png);"
" background-repeat:no-repeat;"
" background-position:center center;"
" border:none;"
" }"
"QPushButton:hover{"
" background-repeat:no-repeat;"
" background-position:center center;"
"background-image:url(:/image/image/image-hover/none-music-hover.png);"
" }"
" QPushButton:pressed{"
"background-repeat:no-repeat;"
" background-position:center center;"
" background-image:url(:/image/image/image/none-music.png);"
"}";
}
Widget::~Widget()//析构
{
delete ui;
}
static QString Time(qint64 time)//转换时间
{
qint64 seconds=time/1000;
const qint64 minutes=seconds/60;
seconds-=minutes*60;
return QStringLiteral("%1:%2")
.arg(minutes, 2, 10, QLatin1Char('0'))
.arg(seconds, 2, 10, QLatin1Char('0'));
}
void Widget::updateInfo()//更新文本
{
QString info;
info=("正在播放: ");
if(music->isMetaDataAvailable())
{
QString title=music->metaData(QStringLiteral("Title")).toString();
if(!title.isEmpty())
{
info+=title;
}
else
{
info+=("未知歌曲");
}
info+="-";
QString author=music->metaData(QStringLiteral("Author")).toString();
if(!author.isEmpty())
{
info+=author;
}
else
{
info+=("未知作者");
}
}
//判断该歌曲是不是我喜欢歌曲
ui->label->setText(info);
if(music->playlist()==playlist_2)
{
ui->pushButton_14->setIcon(QIcon(":/image/image/image/Ilike1.png"));
ui->pushButton_14->setStyleSheet(Ilike1Style());
ui->pushButton_14->setToolTip(("我喜欢"));
}
else if(music->playlist()==playlist_3)
{
ui->pushButton_14->setIcon(QIcon(":/image/image/image/music.png"));
ui->pushButton_14->setStyleSheet(MusicListStyle());