TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicremotewidget.cpp
Go to the documentation of this file.
1 #include "musicremotewidget.h"
8 #include "musictinyuiobject.h"
9 #include "musicsettingmanager.h"
10 #include "musicapplication.h"
11 #include "ttkclickedslider.h"
12 
14  : TTKAbstractMoveWidget(parent)
15 {
16  setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::Tool);
17  setAttribute(Qt::WA_DeleteOnClose);
18 
19  drawWindowShadow(false);
20  setMouseTracking(true);
21 
22  m_showMainWindowButton = new QPushButton(this);
23  m_preSongButton = new QPushButton(this);
24  m_nextSongButton = new QPushButton(this);
25  m_playButton = new QPushButton(this);
26  m_settingButton = new QPushButton(this);
27 #ifdef Q_OS_UNIX
28  m_showMainWindowButton->setFocusPolicy(Qt::NoFocus);
29  m_preSongButton->setFocusPolicy(Qt::NoFocus);
30  m_nextSongButton->setFocusPolicy(Qt::NoFocus);
31  m_playButton->setFocusPolicy(Qt::NoFocus);
32  m_settingButton->setFocusPolicy(Qt::NoFocus);
33 #endif
34 
35  m_mainWidget = new QWidget(this);
36  m_mainWidget->setObjectName("MainWidget");
37 
39  m_showMainWindowButton->setIcon(QIcon(":/image/lb_app_logo"));
40 
41  m_showMainWindowButton->setToolTip(tr("Show MainWindow"));
42  m_preSongButton->setToolTip(tr("Previous"));
43  m_nextSongButton->setToolTip(tr("Next"));
44  m_playButton->setToolTip(tr("Play"));
45  m_settingButton->setToolTip(tr("Settings"));
46 
47  m_preSongButton->setFixedSize(28, 28);
48  m_nextSongButton->setFixedSize(28, 28);
49  m_playButton->setFixedSize(28, 28);
50  m_settingButton->setFixedSize(20, 20);
51  m_showMainWindowButton->setFixedSize(22, 22);
52 
54  m_nextSongButton->setStyleSheet(TTK::UI::TinyBtnNext);
55  m_playButton->setStyleSheet(TTK::UI::TinyBtnPlay);
57  m_mainWidget->setStyleSheet(QString("#MainWidget{%1}").arg(TTK::UI::BackgroundStyle04));
58 
59  m_showMainWindowButton->setCursor(QCursor(Qt::PointingHandCursor));
60  m_preSongButton->setCursor(QCursor(Qt::PointingHandCursor));
61  m_nextSongButton->setCursor(QCursor(Qt::PointingHandCursor));
62  m_playButton->setCursor(QCursor(Qt::PointingHandCursor));
63  m_settingButton->setCursor(QCursor(Qt::PointingHandCursor));
64 
65  connect(m_showMainWindowButton, SIGNAL(clicked()), SIGNAL(showMainWindow()));
66  connect(m_playButton, SIGNAL(clicked()), SIGNAL(playStateChanged()));
67  connect(m_preSongButton, SIGNAL(clicked()), SIGNAL(playPreviousChanged()));
68  connect(m_nextSongButton, SIGNAL(clicked()), SIGNAL(playNextChanged()));
69  connect(m_settingButton, SIGNAL(clicked()), SIGNAL(settingChanged()));
70 
71  m_volumeWidget = new QWidget(m_mainWidget);
72  QHBoxLayout *volumeLayout = new QHBoxLayout(m_volumeWidget);
73  volumeLayout->setContentsMargins(0, 0, 0, 0);
74  volumeLayout->setSpacing(1);
75 
76  m_volumeButton = new QToolButton(m_volumeWidget);
77  m_volumeButton->setFixedSize(QSize(16, 16));
78 
79  m_volumeSlider = new TTKClickedSlider(Qt::Horizontal, m_volumeWidget);
80  m_volumeSlider->setRange(0, 100);
81  m_volumeSlider->setStyleSheet(TTK::UI::SliderStyle01);
82  m_volumeSlider->setFixedWidth(42);
83 
84  volumeLayout->addWidget(m_volumeButton);
85  volumeLayout->addWidget(m_volumeSlider);
86  m_volumeButton->setCursor(QCursor(Qt::PointingHandCursor));
87  m_volumeSlider->setCursor(QCursor(Qt::PointingHandCursor));
88 
89  connect(m_volumeButton, SIGNAL(clicked()), MusicApplication::instance(), SLOT(volumeMute()));
90  connect(m_volumeSlider, SIGNAL(valueChanged(int)), SLOT(volumeSliderChanged(int)));
91 }
92 
94 {
95  delete m_volumeButton;
96  delete m_volumeSlider;
97  delete m_volumeWidget;
99  delete m_preSongButton;
100  delete m_nextSongButton;
101  delete m_playButton;
102  delete m_settingButton;
103  delete m_mainWidget;
104 }
105 
107 {
108  m_playButton->setStyleSheet(state ? TTK::UI::TinyBtnPause : TTK::UI::TinyBtnPlay);
109 }
110 
112 {
113  blockSignals(true);
114  m_volumeSlider->setValue(index);
115  volumeChanged(index);
116  blockSignals(false);
117 }
118 
120 {
122  {
123  return Square;
124  }
126  {
127  return Rectangle;
128  }
130  {
131  return SimpleStyle;
132  }
134  {
135  return ComplexStyle;
136  }
138  {
139  return Ripple;
140  }
141  else
142  {
143  return Null;
144  }
145 }
146 
147 void MusicRemoteWidget::setLabelText(const QString &text)
148 {
149  Q_UNUSED(text);
150 }
151 
153 {
154  QString style = TTK::UI::TinyBtnSoundWhite;
155  if(66 < value && value <=100)
156  {
157  style += "QToolButton{ margin-left:-48px; }";
158  }
159  else if(33 < value && value <=66)
160  {
161  style += "QToolButton{ margin-left:-32px; }";
162  }
163  else if(0 < value && value <=33)
164  {
165  style += "QToolButton{ margin-left:-16px; }";
166  }
167  else
168  {
169  style += "QToolButton{ margin-left:-64px; }";
170  }
171 
172  m_volumeButton->setStyleSheet(style);
173  Q_EMIT volumeChanged(value);
174 }
175 
177 {
178  TTKAbstractMoveWidget::show();
180 }
181 
183 {
185  return TTKAbstractMoveWidget::close();
186 }
187 
188 void MusicRemoteWidget::contextMenuEvent(QContextMenuEvent *event)
189 {
190  TTKAbstractMoveWidget::contextMenuEvent(event);
191  QMenu menu(this);
192  menu.setWindowFlags(menu.windowFlags() | Qt::FramelessWindowHint);
193  menu.setAttribute(Qt::WA_TranslucentBackground);
194  menu.setStyleSheet(TTK::UI::MenuStyle03);
195  menu.addAction(QIcon(":/contextMenu/btn_selected"), tr("WindowTop"))->setEnabled(false);
196  menu.addAction(tr("Show MainWindow"), this, SIGNAL(showMainWindow()));
197  menu.addSeparator();
198 
199  QAction * action = menu.addAction(tr("Square Remote"));
200  action->setEnabled(!TTKObjectCast(MusicRemoteWidgetForSquare*, this));
201  action->setData(Square);
202  action = menu.addAction(tr("Rectangle Remote"));
203  action->setEnabled(!TTKObjectCast(MusicRemoteWidgetForRectangle*, this));
204  action->setData(Rectangle);
205  action = menu.addAction(tr("Simple Style Remote"));
206  action->setEnabled(!TTKObjectCast(MusicRemoteWidgetForSimpleStyle*, this));
207  action->setData(SimpleStyle);
208  action = menu.addAction(tr("Complex Style Remote"));
209  action->setEnabled(!TTKObjectCast(MusicRemoteWidgetForComplexStyle*, this));
210  action->setData(ComplexStyle);
211  action = menu.addAction(tr("Ripple Remote"));
212  action->setEnabled(!TTKObjectCast(MusicRemoteWidgetForRipple*, this));
213  action->setData(Ripple);
214  menu.addAction(tr("Quit"), this, SLOT(close()));
215  connect(&menu, SIGNAL(triggered(QAction*)), SIGNAL(remoteTypeChanged(QAction*)));
216 
217  menu.exec(QCursor::pos());
218 }
219 
221 {
222  const QSize &windowSize = G_SETTING_PTR->value(MusicSettingManager::ScreenSize).toSize();
223  w->move(windowSize.width() - w->width() - 150, w->height() + 70);
224 }
The class of the desktop complex remote widget.
static MusicApplication * instance()
void drawWindowShadow(bool show)
QPushButton * m_nextSongButton
QPushButton * m_showMainWindowButton
void remoteTypeChanged(QAction *type)
static constexpr const char * TinyBtnPrevious
static constexpr const char * TinyBtnSetting
void adjustPosition(QWidget *w)
void playPreviousChanged()
static const QString BackgroundStyle04
Definition: musicuiobject.h:90
The class of the desktop square remote widget.
static const QString PushButtonStyle02
QToolButton * m_volumeButton
The class of the slider that can clicked any position.
static constexpr const char * TinyBtnPause
The class of the desktop simple remote widget.
The class of the desktop ripple remote widget.
QPushButton * m_settingButton
void setCurrentPlayState(bool state) const
static constexpr const char * TinyBtnSoundWhite
static const QString MenuStyle03
The class of the ttk moving widget base.
The class of the desktop rectangle remote widget.
TTKClickedSlider * m_volumeSlider
void volumeChanged(int value)
static constexpr const char * TinyBtnPlay
static const QString SliderStyle01
Slider.
QPushButton * m_playButton
static constexpr const char * TinyBtnNext
void volumeSliderChanged(int value)
QPushButton * m_preSongButton
virtual void contextMenuEvent(QContextMenuEvent *event) override
void setVolumeValue(int index)
MusicRemoteWidget(QWidget *parent=nullptr)
virtual void setLabelText(const QString &text)
state
Definition: http_parser.c:279
#define G_SETTING_PTR
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:60