TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicremotewidgetforstrip.cpp
Go to the documentation of this file.
2 #include "musictinyuiobject.h"
3 #include "musicmarqueewidget.h"
4 
6  : MusicRemoteWidget(parent)
7 {
8  setGeometry(200, 200, 320, 80);
9  adjustPosition(this);
10  setAttribute(Qt::WA_DeleteOnClose, false);
11  setAttribute(Qt::WA_QuitOnClose, false);
12 
13  QHBoxLayout *hbox = new QHBoxLayout(this);
14  hbox->setContentsMargins(5, 5, 5, 5);
15  hbox->addWidget(m_mainWidget);
16  setLayout(hbox);
17 
18  QWidget *topWidget = new QWidget(m_mainWidget);
19  m_bottomWidget = new QWidget(m_mainWidget);
20 
21  QVBoxLayout *mhbox = new QVBoxLayout(m_mainWidget);
22  mhbox->addWidget(topWidget);
23  mhbox->addWidget(m_bottomWidget);
24  m_mainWidget->setLayout(mhbox);
25 
27  m_lrcButton = new QPushButton(this);
28  m_wallPaperButton = new QPushButton(this);
29  m_listButton = new QPushButton(this);
30  m_windowStateButton = new QPushButton(this);
31  m_closeButton = new QToolButton(this);
32 #ifdef Q_OS_UNIX
33  m_lrcButton->setFocusPolicy(Qt::NoFocus);
34  m_wallPaperButton->setFocusPolicy(Qt::NoFocus);
35  m_listButton->setFocusPolicy(Qt::NoFocus);
36  m_windowStateButton->setFocusPolicy(Qt::NoFocus);
37  m_closeButton->setFocusPolicy(Qt::NoFocus);
38 #endif
39 
40  m_closeButton->setIcon(QIcon(":/functions/btn_close_hover"));
43  m_lrcButton->setStyleSheet(TTK::UI::TinyBtnLrcOff);
45  m_listButton->setStyleSheet(TTK::UI::TinyBtnList);
47 
48  m_lrcButton->setToolTip(tr("Lrc"));
49  m_wallPaperButton->setToolTip(tr("WallPaper"));
50  m_listButton->setToolTip(tr("List"));
51  m_windowStateButton->setToolTip(tr("Collapse"));
52  m_closeButton->setToolTip(tr("Close"));
53 
54  m_lrcButton->setFixedSize(22, 22);
55  m_wallPaperButton->setFixedSize(22, 22);
56  m_listButton->setFixedSize(22, 22);
57  m_windowStateButton->setFixedSize(22, 22);
58  m_closeButton->setFixedSize(22, 22);
59 
60  m_lrcButton->setCursor(QCursor(Qt::PointingHandCursor));
61  m_closeButton->setCursor(QCursor(Qt::PointingHandCursor));
62  m_wallPaperButton->setCursor(QCursor(Qt::PointingHandCursor));
63  m_listButton->setCursor(QCursor(Qt::PointingHandCursor));
64  m_windowStateButton->setCursor(QCursor(Qt::PointingHandCursor));
65 
66  QHBoxLayout *topWidgetBox = new QHBoxLayout(topWidget);
67  topWidgetBox->setContentsMargins(0, 0, 0, 0);
68  topWidgetBox->addWidget(m_songNameLabel);
69  topWidgetBox->setSpacing(1);
70  topWidgetBox->addWidget(m_windowStateButton);
71  topWidgetBox->addWidget(m_settingButton);
72  topWidgetBox->addWidget(m_closeButton);
73  topWidget->setLayout(topWidgetBox);
74 
75  QHBoxLayout *bottomWidgetBox = new QHBoxLayout(m_bottomWidget);
76  bottomWidgetBox->setContentsMargins(0, 0, 0, 0);
77  bottomWidgetBox->setSpacing(1);
78  bottomWidgetBox->addWidget(m_preSongButton);
79  bottomWidgetBox->addWidget(m_playButton);
80  bottomWidgetBox->addWidget(m_nextSongButton);
81  bottomWidgetBox->addStretch(1);
82  bottomWidgetBox->addWidget(m_volumeWidget);
83  bottomWidgetBox->addWidget(m_showMainWindowButton);
84  bottomWidgetBox->addWidget(m_lrcButton);
85  bottomWidgetBox->addWidget(m_wallPaperButton);
86  bottomWidgetBox->addWidget(m_listButton);
87  m_bottomWidget->setLayout(bottomWidgetBox);
88 
89  connect(m_closeButton, SIGNAL(clicked()), SLOT(close()));
90  connect(m_windowStateButton, SIGNAL(clicked()), SLOT(windowStateChanged()));
91 }
92 
94 {
95  delete m_lrcButton;
96  delete m_wallPaperButton;
97  delete m_listButton;
98  delete m_windowStateButton;
99  delete m_closeButton;
100  delete m_songNameLabel;
101 // delete m_bottomWidget;
102 }
103 
104 void MusicRemoteWidgetForStrip::setLabelText(const QString &value)
105 {
106  m_songNameLabel->setText(TTK::Widget::elidedText(font(), value, Qt::ElideRight, width() - 20));
107 }
108 
110 {
111  const bool f = m_windowStateButton->styleSheet().contains("collapse");
112  setFixedHeight(f ? 50 : 80);
113  m_bottomWidget->setVisible(!f);
115  m_windowStateButton->setToolTip(f ? tr("Expand") : tr("Collapse"));
116 }
117 
118 void MusicRemoteWidgetForStrip::contextMenuEvent(QContextMenuEvent *event)
119 {
120  TTKAbstractMoveWidget::contextMenuEvent(event);
121  QMenu menu(this);
122  menu.setWindowFlags(menu.windowFlags() | Qt::FramelessWindowHint);
123  menu.setAttribute(Qt::WA_TranslucentBackground);
124  menu.setStyleSheet(TTK::UI::MenuStyle03);
125  menu.addAction(QIcon(":/contextMenu/btn_selected"), tr("WindowTop"))->setEnabled(false);
126  menu.addAction(tr("Show MainWindow"), this, SIGNAL(showMainWindow()));
127  menu.addAction(tr("Quit"), this, SLOT(close()));
128  menu.exec(QCursor::pos());
129 }
virtual void contextMenuEvent(QContextMenuEvent *event) overridefinal
QPushButton * m_nextSongButton
QPushButton * m_showMainWindowButton
static const QString WidgetStyle01
Widget.
virtual void setLabelText(const QString &value) overridefinal
void adjustPosition(QWidget *w)
MusicRemoteWidgetForStrip(QWidget *parent=nullptr)
static constexpr const char * TinyBtnLrcOff
QPushButton * m_settingButton
static constexpr const char * TinyBtnExpand
static constexpr const char * TinyBtnCollapse
static const QString MenuStyle03
static constexpr const char * TinyBtnWallpaperOff
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
The class of the desktop remote widget base.
The class of the marquee widget.
void setText(const QString &newText)
QPushButton * m_playButton
static const QString ToolButtonStyle04
QPushButton * m_preSongButton
static constexpr const char * TinyBtnList
MusicMarqueeWidget * m_songNameLabel