TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsystemtraymenu.cpp
Go to the documentation of this file.
1 #include "musicsystemtraymenu.h"
2 #include "musiccontextuiobject.h"
3 #include "musictinyuiobject.h"
4 #include "musicrightareawidget.h"
5 #include "musicwidgetutils.h"
6 #include "ttkclickedslider.h"
7 
8 #include <QWidgetAction>
9 
11  : QMenu(parent)
12 {
13  setStyleSheet(TTK::UI::MenuStyle02);
14 
15  m_showLrcAction = new QAction(QIcon(":/contextMenu/btn_lrc_label"),tr("Show Desktop Lrc"), this);
16  connect(m_showLrcAction, SIGNAL(triggered()), SLOT(showDesktopLrc()));
17 
18  m_lockLrcAction = new QAction(QIcon(":/contextMenu/btn_lock"), tr("Lock Lrc"), this);
19  connect(m_lockLrcAction, SIGNAL(triggered()), SLOT(setWindowLockedChanged()));
20 #ifdef Q_OS_UNIX
21  addAction(QIcon(":/image/lb_app_logo"), tr("Show MainWindow"), parent, SLOT(showNormal()));
22  addSeparator();
23 #else
25  addSeparator();
27 #endif
28  addAction(m_showLrcAction);
29  addAction(m_lockLrcAction);
30  addSeparator();
31  addAction(QIcon(":/contextMenu/btn_setting"), tr("Settings"), parent, SLOT(showSettingWidget()));
32  addSeparator();
33  addAction(tr("Quit"), parent, SLOT(quitWindow()));
34 }
35 
37 {
38 #ifndef Q_OS_UNIX
39  delete m_showText;
40  delete m_playButton;
41  delete m_volumeButton;
42  delete m_volumeSlider;
43 #endif
44  delete m_showLrcAction;
45  delete m_lockLrcAction;
46 }
47 
48 void MusicSystemTrayMenu::setLabelText(const QString &text) const
49 {
50 #ifndef Q_OS_UNIX
51  m_showText->setText(TTK::Widget::elidedText(font(), text, Qt::ElideRight, 160));
52  m_showText->setToolTip(text);
53 #else
54  Q_UNUSED(text);
55 #endif
56 }
57 
59 {
60  m_showLrcAction->setText(show ? tr("Hide Desktop Lrc") : tr("Show Desktop Lrc"));
61  m_lockLrcAction->setEnabled(show);
62 }
63 
65 {
66  m_lockLrcAction->setText(!lock ? tr("Lock Lrc") : tr("Unlock Lrc"));
67 }
68 
70 {
72 }
73 
75 {
76 #ifndef Q_OS_UNIX
78 #else
79  Q_UNUSED(state);
80 #endif
81 }
82 
84 {
85 #ifndef Q_OS_UNIX
86  m_volumeSlider->blockSignals(true);
87  m_volumeSlider->setValue(value);
88  m_volumeSlider->blockSignals(false);
89 
90  QString style = TTK::UI::TinyBtnSound;
91  if(66 < value && value <=100)
92  {
93  style += "QToolButton{ margin-left:-48px; }";
94  }
95  else if(33 < value && value <=66)
96  {
97  style += "QToolButton{ margin-left:-32px; }";
98  }
99  else if(0 < value && value <=33)
100  {
101  style += "QToolButton{ margin-left:-16px; }";
102  }
103  else
104  {
105  style += "QToolButton{ margin-left:-64px; }";
106  }
107  m_volumeButton->setStyleSheet(style);
108 #else
109  Q_UNUSED(value);
110 #endif
111 }
112 
114 {
115  const bool show = m_showLrcAction->text().trimmed() == tr("Show Desktop Lrc").trimmed();
116  m_showLrcAction->setText(show ? tr("Hide Desktop Lrc") : tr("Show Desktop Lrc"));
117  m_lockLrcAction->setEnabled(show);
119 }
120 
122 {
123  QWidgetAction *widgetAction = new QWidgetAction(this);
124  QWidget *widgetActionContainer = new QWidget(this);
125  QVBoxLayout *vbox = new QVBoxLayout(widgetActionContainer);
126 
127  QWidget *widgetContainer = new QWidget(widgetActionContainer);
128  widgetContainer->setFixedWidth(172);
129  QHBoxLayout *box = new QHBoxLayout(widgetContainer);
130  box->setContentsMargins(9, 2, 9, 9);
131 
132  QToolButton *previousPlay = new QToolButton(widgetContainer);
133  QToolButton *nextPlay = new QToolButton(widgetContainer);
134  m_playButton = new QToolButton(widgetContainer);
135 
136  previousPlay->setFixedSize(32, 32);
137  nextPlay->setFixedSize(32, 32);
138  m_playButton->setFixedSize(32, 32);
139 
140  previousPlay->setStyleSheet(TTK::UI::ContextPrevious);
141  nextPlay->setStyleSheet(TTK::UI::ContextNext);
142  m_playButton->setStyleSheet(TTK::UI::ContextPlay);
143 
144  previousPlay->setCursor(QCursor(Qt::PointingHandCursor));
145  nextPlay->setCursor(QCursor(Qt::PointingHandCursor));
146  m_playButton->setCursor(QCursor(Qt::PointingHandCursor));
147 
148  previousPlay->setToolTip(tr("Previous"));
149  nextPlay->setToolTip(tr("Next"));
150  m_playButton->setToolTip(tr("Play"));
151 
152  box->addWidget(previousPlay);
153  box->addWidget(m_playButton);
154  box->addWidget(nextPlay);
155 
156  m_showText = new QLabel(widgetActionContainer);
157  m_showText->setAlignment(Qt::AlignCenter);
158  m_showText->setStyleSheet(TTK::UI::ColorStyle03);
159 
160  vbox->addWidget(widgetContainer);
161  vbox->addWidget(m_showText);
162  widgetActionContainer->setLayout(vbox);
163  widgetAction->setDefaultWidget(widgetActionContainer);
164  addAction(widgetAction);
165 
166  connect(previousPlay, SIGNAL(clicked()), parent(), SLOT(playPrevious()));
167  connect(nextPlay, SIGNAL(clicked()), parent(), SLOT(playNext()));
168  connect(m_playButton, SIGNAL(clicked()), parent(), SLOT(switchToPlayState()));
169 }
170 
172 {
173  QWidgetAction *widgetAction = new QWidgetAction(this);
174  QWidget *widgetActionContainer = new QWidget(this);
175  QHBoxLayout *vbox = new QHBoxLayout(widgetActionContainer);
176  vbox->setContentsMargins(9, 2, 9, 9);
177 
178  m_volumeButton = new QToolButton(widgetActionContainer);
179  m_volumeButton->setCursor(QCursor(Qt::PointingHandCursor));
180  m_volumeButton->setFixedSize(16, 16);
181 
182  m_volumeSlider = new TTKClickedSlider(Qt::Horizontal, widgetActionContainer);
183  m_volumeSlider->setRange(0, 100);
184  m_volumeSlider->setStyleSheet(TTK::UI::SliderStyle08);
185 
186  vbox->addWidget(m_volumeButton);
187  vbox->addWidget(m_volumeSlider);
188  widgetActionContainer->setLayout(vbox);
189 
190  widgetAction->setDefaultWidget(widgetActionContainer);
191  addAction(widgetAction);
192 
193  connect(m_volumeButton, SIGNAL(clicked()), parent(), SLOT(volumeMute()));
194  connect(m_volumeSlider, SIGNAL(valueChanged(int)), parent(), SLOT(volumeChanged(int)));
195 }
static MusicRightAreaWidget * instance()
void setCurrentPlayState(bool state) const
void setLabelText(const QString &text) const
static constexpr const char * ContextNext
The class of the slider that can clicked any position.
static const QString SliderStyle08
QToolButton * m_volumeButton
static constexpr const char * TinyBtnSound
static constexpr const char * ContextPause
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
void setDestopLrcVisible(bool visible) const
static const QString MenuStyle02
void lockDesktopLrc(bool lock)
static const QString ColorStyle03
Definition: musicuiobject.h:43
void setVolumeValue(int value) const
TTKClickedSlider * m_volumeSlider
static constexpr const char * ContextPrevious
MusicSystemTrayMenu(QWidget *parent=nullptr)
QToolButton * m_playButton
static constexpr const char * ContextPlay
state
Definition: http_parser.c:279