#include "mymaindlg.h"
#include "ui_mymaindlg.h"
#include<QDialog>
#include "skinbox.h"
#include <QFileDialog>
#include <QTimer>
#include <QDateTime>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QMediaPlaylist>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QMessageBox>
#include <QToolTip>
#include <QTime>
#include <QScrollBar>
#include <QEvent>
#include <QMouseEvent>
#include <QListWidgetItem>
#include <QDebug>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGraphicsOpacityEffect>
#include <QTableWidgetItem>
#include <QDropEvent>
#include <QDesktopWidget>
#include <QCursor>
MyMainDlg::MyMainDlg(QWidget *parent) :QDialog(parent),ui(new Ui::MyMainDlg)
{
ui->setupUi(this);
QDir dir("D://ExcellentLrc");//创建保存歌词的文件夹
if(!dir.exists())
dir.mkdir("D://ExcellentLrc");
QDir dir2("D://ExcellentMusic");
if(!dir2.exists())
dir2.mkdir("D://ExcellentMusic");
QDir dir3("D://ExcellentAlbum");
if(!dir3.exists())
dir3.mkdir("D://ExcellentAlbum");
nowplaywid=new MusicMarqueeWidget(this);
nowplaywid->setGeometry(5,25,175,20);
stack=new QStackedWidget(this);
mymaintable=new mymaintablewidget(stack);//添加widget
mynetmaintable=new mymaintablewidget(stack);//添加网络列表
addtips=new QLabel("点击按钮添加\n或拖动文件到界面", mymaintable);
addtips->setGeometry(5,150,180,50);
addtips->setStyleSheet("color: white;font-size: 14px;font-family :微软雅黑");
box=new skinbox(this);
mynetwork=new MyNetWork;//网络
downdlg=new downloadinfodlg(this);
lrcdlg=new searchlrcdlg(this);
lrcdlg->setModal(true);//模太对话框
lrc=new MyLrc;
lrcshowedit=new QTextEdit(this);
lrcshowedit->setStyleSheet("QTextEdit{background:transparent}");
lrcshowedit->setFrameStyle(QFrame::NoFrame);
lrcshowedit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
lrcshowedit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
lrcshowedit->setReadOnly(true);
lrcshowedit->setFont(QFont("微软雅黑", 10, QFont::Thin));
lrcshowedit->setTextColor(Qt::white);
lrcshowedit->setContextMenuPolicy(Qt::CustomContextMenu);
lrcshowedit->setFocusPolicy(Qt::NoFocus);
lrcshowedit->viewport()->installEventFilter(this);//事件
lrcshowedit->viewport()->setCursor(QCursor(QPixmap(":/image/cursor_hand.png")));//原始形状的cursor
/////////////////////////////////////////netsearch的形成
searchsongui();//查找歌曲页面的ui
searchdownui();//下载歌曲页面的ui
/////////////////////////////////////////////////////////////
loadlab=new QLabel(searchtable);//以搜索显示的tablewidget为父窗口
movie=new QMovie("image/loading.gif");
loadlab->setMovie(movie);
movie->start();
loadlab->raise();
loadlab->setGeometry(65,150,64,64);
loadlab->hide();
stack->addWidget( lrcshowedit);//textedit
stack->addWidget( mymaintable);//tablewidet主界面的
stack->addWidget(mynetmaintable);//tablewidet
stack->addWidget(netseauiwidget);//widget
stack->addWidget(tabwidget);//tabwidget
stack->setGeometry(55,132,194,444);
ui->widget_search->raise();//位于最上层
ui->widget_search->hide();
ui->lineEdit_search->setTextMargins(13,0,0,0);//为图标留下地方
///////////////////////////////////////////////////////////////////////////////滚动条样式
this->setAcceptDrops(true);//darg和drop事件
this->setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏
this->setWindowTitle("极视听音乐播放器");
////////////////////////////两个定时器
timer = new QTimer();
timer->start(1000);
timer2 = new QTimer();
timer2->start(200);
/////////////////////////////////////////////////控件样式
setDialogStyleSheet();//样式
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ui->listWidget_side->viewport()->installEventFilter(this);
ui->horizontalSlider_vol->installEventFilter(this);//用于点击slider即到
ui->horizontalSlider->installEventFilter(this);//用于点击slider即到
ui->listWidget_side->setMouseTracking(true);
nowplaywid->installEventFilter(this);
ui->label_title->installEventFilter(this);
ui->label_pic->installEventFilter(this);
mymaintable->setContextMenuPolicy(Qt::CustomContextMenu);
mynetmaintable->setContextMenuPolicy(Qt::CustomContextMenu);
ui->horizontalSlider_vol->setRange(0,100);
ui->pushButton_playpause->setToolTip("播放");
/////////////////////////////////////////开关
changevol=true;//vol的按钮改变
checkbox=0;
previousitem=-1;
m_MousePressed=false;
lrcmove=false;
nowplaylist=1;//正在播放列表
/////////////////////////////////////
netplayList=new QMediaPlaylist;
player=new QMediaPlayer;
///////////////////////////////////////////////////
trayiconmenu();//设置系统图标菜单
setbtnmenu();//播放模式菜单与添加菜单
connect(mymaintable,SIGNAL(itemDoubleClicked(QTableWidgetItem*)),this,SLOT(mytabledoubleclick(QTableWidgetItem *)));
connect(mynetmaintable,SIGNAL(itemDoubleClicked(QTableWidgetItem*)),this,SLOT(mynetmaintabledoublclick(QTableWidgetItem*)));
connect(lrcdlg,SIGNAL(getlrcshow(QByteArray)),this,SLOT(replyLrc(QByteArray)));//lrc对话框获取
connect(box,SIGNAL(listbktransparent(int)),this,SLOT(setplaylistopa(int)));//设置播放列表的背景透明度
connect(box,SIGNAL(skinChange(QString)),downdlg,SLOT(setbk(QString)));//为下载dlg设置背景图片
connect(box,SIGNAL(skinChange(QString)),this,SLOT(setBk(QString)));//为歌词dlg设置背景图片
connect(box,SIGNAL(skinChange(QString)),lrcdlg,SLOT(setBk(QString)));//为歌词dlg设置背景图片
connect(downdlg,SIGNAL(downbtninfo(int,QString)),this,SLOT(downloadsonginfo(int,QString)));//获取下载对话框的信息
connect(searchtable,SIGNAL(itemClicked(QTableWidgetItem*)),this,SLOT(searchtableitemclick(QTableWidgetItem*)));
connect(searchtable,SIGNAL(entered(QModelIndex)),this,SLOT(seatabent(QModelIndex)));
connect(mynetwork,SIGNAL(dolrcworkfinished(QByteArray)),this,SLOT(replyLrc(QByteArray)));//mynetwork连接信号与槽返回的lrc显示
connect(mynetwork,SIGNAL(doworkfinished(QByteArray)),this,SLOT(slotmynetwork(QByteArray)));//由mynetwork发的信号槽
connect(ui->pushButton_location,SIGNAL(clicked()),this,SLOT(scrolltoitem()));//定位
connect(lrc,SIGNAL(changeselect(bool)),ui->checkBox,SLOT(setChecked(bool)));//用于显示歌词checkbox的选中
connect(mynetmaintable, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShownetContextMenu(const QPoint&)));//网络列表的
connect(mymaintable, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowContextMenu(const QPoint&)));
connect(lrcshowedit,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(showlrcshoweditmenu(const QPoint&)));
connect(ui->listWidget_side,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int)));
connect(timer2,SIGNAL(timeout()),this,SLOT(timerEvent2()));
connect(timer,SIGNAL(timeout()),this,SLOT(timerEvent()));
connect(player,SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),this,SLOT(chagnplaybtnsty2(QMediaPlayer::MediaStatus)));
connect(player,SIGNAL(stateChanged(QMediaPlayer::State)),this,SLOT(changplaybtbsty(QMediaPlayer::State)));//改变播放按钮的样式
connect(player,SIGNAL(currentMediaChanged(QMediaContent)),this,SLOT(shownowplaylabel(QMediaContent)));//显示正在播放的歌曲label
connect(player,SIGNAL(currentMediaChanged(QMediaContent)),this,SLOT(seteditlrc(QMediaContent)));//