Skip to content

Commit

Permalink
系统托盘增加菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperMan0x007 committed Jul 1, 2018
1 parent 1cf035e commit 902e9b0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
7 changes: 0 additions & 7 deletions BottomBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@
#include <QMediaPlayer>
#include <QTime>

#define ICON_PALY_PATH "://Data/Image/play.png"
#define ICON_PAUSE_PATH "://Data/Image/pause.png"
#define ICON_STOP_PATH "://Data/Image/stop.png"
#define ICON_NEXT_PATH "://Data/Image/next.png"
#define ICON_PRE_PATH "://Data/Image/pre.png"
#define ICON_PRE_PATH "://Data/Image/pre.png"
#define ICON_SOUND_PATH "://Data/Image/sound.png"
#define ICON_LIST_PATH "://Data/Image/list-view.png"
#define ICON_RANDOM_PATH "://Data/Image/random.png"
#define ICON_REPEAT_PATH "://Data/Image/repeat.png"
#define ICON_REPEAT_ONE_PATH "://Data/Image/repeat_one.png"
#define ONE_HOUR_SCOND 1000 * 60 * 60


extern CcMusic* g_pMusic;
BottomBar::BottomBar(QWidget *parent)
: QWidget(parent), m_ucPlayMode(EM_LIST_RECYCLE)
Expand Down
6 changes: 6 additions & 0 deletions BottomBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
#include <QSlider>
#include "MusicPlaylist.h"

#define ICON_PALY_PATH "://Data/Image/play.png"
#define ICON_PAUSE_PATH "://Data/Image/pause.png"
#define ICON_STOP_PATH "://Data/Image/stop.png"
#define ICON_NEXT_PATH "://Data/Image/next.png"
#define ICON_PRE_PATH "://Data/Image/pre.png"

enum { EM_LIST_RECYCLE, EM_ONE_RECYCLE, EM_RANDOM, EM_MODE_COUNT};

class ProcessSlider;
Expand Down
46 changes: 33 additions & 13 deletions CcMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,48 @@ void CcMusic::initUi()
setWindowIcon(QIcon(WND_ICON_PATH));
// 系统托盘
m_pSysTray = new QSystemTrayIcon(QIcon(WND_ICON_PATH), this);

m_pSysTray->setToolTip("CcMusic");
QMenu* trayMenu = new QMenu();
m_pSysTray->setContextMenu(trayMenu);
QAction* showHideAction = new QAction("显示&&隐藏", trayMenu);
QAction* quitAction = new QAction("退出", trayMenu);
trayMenu->addAction(showHideAction);
// action
QAction* playAction = new QAction(QIcon(ICON_PALY_PATH), "播放", trayMenu);
QAction* pauseAction = new QAction(QIcon(ICON_PAUSE_PATH), "暂停", trayMenu);
QAction* stopAction = new QAction(QIcon(ICON_STOP_PATH), "停止", trayMenu);
QAction* preAction = new QAction(QIcon(ICON_PRE_PATH), "上一首", trayMenu);
QAction* nextAction = new QAction(QIcon(ICON_NEXT_PATH), "下一首", trayMenu);
QAction* hideAction = new QAction(QIcon(""), "隐藏", trayMenu);
QAction* quitAction = new QAction(QIcon(ICON_SHHUT_DOWN_PATH), "退出", trayMenu);
//
trayMenu->addAction(playAction);
trayMenu->addAction(pauseAction);
trayMenu->addAction(stopAction);
trayMenu->addAction(preAction);
trayMenu->addAction(nextAction);
trayMenu->addSeparator();
trayMenu->addAction(hideAction);
trayMenu->addAction(quitAction);
m_pSysTray->show();
connect(showHideAction, &QAction::triggered, [&](){
if(this->isHidden())
//
connect(playAction, &QAction::triggered, this, &CcMusic::Play);
connect(pauseAction, &QAction::triggered, this, &CcMusic::Pause);
connect(stopAction, &QAction::triggered, this, &CcMusic::Stop);
connect(preAction, &QAction::triggered, this, &CcMusic::playPreSong);
connect(nextAction, &QAction::triggered, this, &CcMusic::playNextSong);
connect(hideAction, &QAction::triggered, [&](){
this->hide();
GetPlayList()->hide();
});
connect(quitAction, &QAction::triggered, [](){
exit(0);
});

connect(m_pSysTray, &QSystemTrayIcon::activated, [&](QSystemTrayIcon::ActivationReason reason)
{
if(reason == QSystemTrayIcon::Trigger && this->isHidden())
{
this->show();
}
else
{
this->hide();
GetPlayList()->hide();
}
});
connect(quitAction, &QAction::triggered, [&](){
exit(0);
});
//
connect(m_pTitleBar, &TitleBar::showWndMax, m_pBottomBar, &BottomBar::HidePlayList);
Expand Down
6 changes: 3 additions & 3 deletions CcMusic.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class CcMusic : public QWidget

public:
void SetCurrentMusic(int index);
bool Play();
void Pause();
void Stop();
void OnClose();
QMediaPlayer* GetPlayer();
MusicPlaylist* GetPlayList();
Expand All @@ -51,6 +48,9 @@ class CcMusic : public QWidget

public slots:
void setVolume(int v);
bool Play();
void Pause();
void Stop();
void playPreSong();
void playNextSong();

Expand Down
2 changes: 1 addition & 1 deletion TitleBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QSpacerItem>
#include <QApplication>

#define ICON_SHHUT_DOWN_PATH "://Data/Image/shut-down.png"

#define ICON_MIN_BTN_PATH "://Data/Image/min-btn.png"
#define ICON_MAX_BTN_PATH "://Data/Image/max-btn.png"
#define ICON_NORMAL_PATH "://Data/Image/normal.png"
Expand Down
2 changes: 2 additions & 0 deletions TitleBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <QPoint>
#include <QMouseEvent>

#define ICON_SHHUT_DOWN_PATH "://Data/Image/shut-down.png"

class TitleBar : public QWidget
{
Q_OBJECT
Expand Down

0 comments on commit 902e9b0

Please sign in to comment.