#include "widget.h"
#include "mainbottomwidget.h"
#include "maintopwidget.h"
#include "../find/findwidget.h"
#include "../video/videowidget.h"
#include "../music/musicwidget.h"
#include <QApplication>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QFileInfoList>
#include <QDir>
#include <QStackedWidget>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QLabel>
#include <QIcon>
#include <QMouseEvent>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QMediaMetaData>
#include <QVideoWidget>
#include <QMessageBox>
#include <QTime>
Widget::Widget(QWidget *parent) : QWidget(parent), m_mousePress(false),volume(60)
{
this->initUI();
this->initAnim();
initMediaPlayer(); //初始化媒体播放器
createContextMenu(); //初始化右键菜单
createSystemTrayIcon(); //初始化系统托盘
//createTaskbar(); //创建任务栏进度条
//createThumbnailToolBar(); //创建任务栏播放条
this->initConnect();
addFolderSong(); //加载默认播放文件夹
m_musicWidget->setPlaylist(playList);
connect(m_musicWidget,SIGNAL(setCurrentIndex(int)),this,SLOT(playTo(int)));
connect(m_musicWidget,SIGNAL(openFolder()),this,SLOT(importSongs()));
}
void Widget::mousePressEvent(QMouseEvent *event)
{
//只能是鼠标左键移动和改变大小
if(event->button() == Qt::LeftButton)
{
m_mousePress = true;
}
//窗口移动距离
m_movePoint = event->globalPos() - pos();
}
void Widget::mouseReleaseEvent(QMouseEvent *)
{
m_mousePress = false;
}
void Widget::mouseMoveEvent(QMouseEvent *event)
{
//移动窗口
if(m_mousePress)
{
QPoint movePpos = event->globalPos();
move(movePpos - m_movePoint);
}
}
void Widget::initUI()
{
this->resize(900, 440);
setWindowFlags(Qt::FramelessWindowHint);
this->setWindowIcon(QIcon(":/images/widget/title1.png"));
this->setWindowTitle(tr("mateMusic"));
m_topWidget = new MainTopWidget(this);
m_bottomWidget = new MainBottomWidget(this);
m_stackWidget = new QStackedWidget(this);
m_stackWidget->setGeometry(QRect(x(),y(),900,600));
m_stackWidget->move(QPoint(this->x(),this->y()));
m_stackWidget->lower();
//m_stackWidget->hide();
m_findWidget = new FindWidget;
m_stackWidget->addWidget(m_findWidget);
m_videoWidget = new VideoWidget;
m_stackWidget->addWidget(m_videoWidget);
m_musicWidget = new MusicWidget;
m_stackWidget->addWidget(m_musicWidget);
}
void Widget::initMediaPlayer()
{
playList=new QMediaPlaylist;
playList->setPlaybackMode(QMediaPlaylist::Loop);
player=new QMediaPlayer;
player->setPlaylist(playList);
player->setVolume(volume);
}
void Widget::createContextMenu()
{
// seperatorAction1=new QAction(this);
// seperatorAction1->setSeparator(true);
// seperatorAction2=new QAction(this);
// seperatorAction2->setSeparator(true);
// seperatorAction3=new QAction(this);
// seperatorAction3->setSeparator(true);
// seperatorAction4=new QAction(this);
// seperatorAction4->setSeparator(true);
// seperatorAction5=new QAction(this);
// seperatorAction5->setSeparator(true);
// addAction(ui->action_SongList);
// addAction(ui->action_Import);
// addAction(seperatorAction1);
// addAction(ui->action_Last);
// addAction(ui->action_Play);
// addAction(ui->action_Stop);
// addAction(ui->action_Next);
// addAction(seperatorAction2);
// addAction(ui->action_Mode1);
// addAction(ui->action_Mode2);
// addAction(ui->action_Mode3);
// addAction(ui->action_Mode4);
// addAction(seperatorAction3);
// addAction(ui->action_SoundPlus);
// addAction(ui->action_SoundReduce);
// addAction(seperatorAction4);
// addAction(ui->action_Support);
// addAction(ui->action_About);
// addAction(seperatorAction5);
// addAction(ui->action_Quit);
// setContextMenuPolicy(Qt::ActionsContextMenu);
}
void Widget::createSystemTrayIcon()
{
// trayIcon=new QSystemTrayIcon(this);
// trayIcon->setIcon(QIcon(tr(":/images/music.png")));
// trayIcon->setToolTip(tr("SuperPlayer - 音乐播放器"));
// restoreAction=new QAction(tr("打开主面板"), this);
// connect(restoreAction, SIGNAL(triggered()), this, SLOT(show()));
// quitAction=new QAction(tr("退出"), this);
// connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
// trayContextMenu=new QMenu(this);
// trayContextMenu->addAction(ui->action_SongList);
// trayContextMenu->addAction(ui->action_Import);
// trayContextMenu->addSeparator();
// trayContextMenu->addAction(ui->action_Last);
// trayContextMenu->addAction(ui->action_Play);
// trayContextMenu->addAction(ui->action_Stop);
// trayContextMenu->addAction(ui->action_Next);
// trayContextMenu->addSeparator();
// trayContextMenu->addAction(ui->action_Mode1);
// trayContextMenu->addAction(ui->action_Mode2);
// trayContextMenu->addAction(ui->action_Mode3);
// trayContextMenu->addAction(ui->action_Mode4);
// trayContextMenu->addSeparator();
// trayContextMenu->addAction(ui->action_SoundPlus);
// trayContextMenu->addAction(ui->action_SoundReduce);
// trayContextMenu->addSeparator();
// trayContextMenu->addAction(ui->action_Support);
// trayContextMenu->addAction(ui->action_About);
// trayContextMenu->addSeparator();
// trayContextMenu->addAction(restoreAction);
// trayContextMenu->addAction(quitAction);
// trayIcon->setContextMenu(trayContextMenu);
// trayIcon->show();
// connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
// this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
}
void Widget::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
// switch(reason) {
// case QSystemTrayIcon::DoubleClick:
// case QSystemTrayIcon::Trigger:
// if(this->isVisible()==true) {
// ;
// } else {
// this->show();
// this->activateWindow();
// }
// break;
// default:
// break;
// }
}
void Widget::createTaskbar()
{
taskbarButton = new QWinTaskbarButton(this);
taskbarButton->setWindow(windowHandle());
taskbarProgress = taskbarButton->progress();
connect(m_bottomWidget, SIGNAL(progressMoved(int)), taskbarProgress, SLOT(setValue(int)));
connect(m_bottomWidget, SIGNAL(progressRangeChanged(int,int)), taskbarProgress, SLOT(setRange(int,int)));
connect(player, &QMediaPlayer::stateChanged, this, &Widget::updateTaskbar);
}
void Widget::createThumbnailToolBar()
{
thumbnailToolBar = new QWinThumbnailToolBar(this);
thumbnailToolBar->setWindow(windowHandle());
playToolButton = new QWinThumbnailToolButton(thumbnailToolBar);
playToolButton->setEnabled(false);
playToolButton->setToolTip(tr("Play"));
playToolButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
//connect(playToolButton, &QWinThumbnailToolButton::clicked, this, &Widget::playOrPause);
forwardToolButton = new QWinThumbnailToolButton(thumbnailToolBar);
forwardToolButton->setEnabled(false);
forwardToolButton->setToolTip(tr("Fast forward"));
forwardToolButton->setIcon(style()->standardIcon(QStyle::SP_MediaSeekForward));
connect(forwardToolButton, &QWinThumbnailToolButton::clicked, this, &Widget::playNext);
backwardToolButton = new QWinThumbnailToolButton(thumbnailToolBar);
backwardToolButton->setEnabled(false);
backwardToolButton->setToolTip(tr("Rewind"));
backwardToolButton->setIcon(style()->standardIcon(QStyle::SP_MediaSeekBackward));
connect(backwardToolButton, &QWinThumbnailToolButton: