TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicenhancedpopwidget.cpp
Go to the documentation of this file.
2 #include "musicsettingmanager.h"
6 #include "musicrightareawidget.h"
7 #include "musicqmmputils.h"
8 
9 #include <QLabel>
10 #include <QButtonGroup>
11 
12 static constexpr int LABEL_ANIMAT_WIDGET = 156;
13 static constexpr int LABEL_BUTTON_WIDGET = 116;
14 static constexpr int LABEL_BUTTON_HEIGHT = 111;
15 
17  : QToolButton(parent),
18  m_state(false)
19 {
20  m_animationLabel = new QLabel(this);
22  m_animationLabel->setAttribute(Qt::WA_TransparentForMouseEvents, true);
23 
24  m_foreLabel = new QLabel(this);
25  m_foreLabel->setObjectName("ForeLabel");
27 
28  m_animation = new QPropertyAnimation(m_animationLabel, "pos", this);
29  m_animation->setDuration(500);
30  m_animation->setStartValue(QPoint(-LABEL_ANIMAT_WIDGET, 0));
31  m_animation->setEndValue(QPoint(LABEL_ANIMAT_WIDGET, 0));
32  connect(m_animation, SIGNAL(finished()), SLOT(finished()));
33 }
34 
36 {
37  delete m_foreLabel;
38  delete m_animationLabel;
39  delete m_animation;
40 }
41 
42 void MusicEnhancedToolButton::setStyleSheet(const QString &styleSheet, bool state)
43 {
44  m_state = state;
45  if(m_state)
46  {
47  m_animation->setDuration(2000);
48  m_foreLabel->setStyleSheet(QString("#ForeLabel{%1}").arg(styleSheet));
49  m_animationLabel->setStyleSheet("background-image:url(':/enhance/lb_selected')");
50  QToolButton::setStyleSheet(QString("QToolButton{background-image:url(':/enhance/lb_blue'); }"));
51  }
52  else
53  {
54  m_animation->setDuration(500);
55  m_foreLabel->setStyleSheet({});
56  m_animationLabel->setStyleSheet("background-image:url(':/enhance/lb_enter')");
57  QToolButton::setStyleSheet(QString("QToolButton{%1}").arg(styleSheet));
58  }
59 }
60 
62 {
63  m_animation->start();
64 }
65 
67 {
68  m_animation->stop();
69 }
70 
72 {
73  if(m_state)
74  {
75  start();
76  }
77 }
78 
80 {
81  QToolButton::enterEvent(event);
82  if(!m_state)
83  {
84  start();
85  }
86 }
87 
88 
90  : MusicToolMenuWidget(parent)
91 {
92  setToolTip(tr("Magic Music"));
93 
94  initialize();
95 
97  connect(m_menu, SIGNAL(windowStateChanged(bool)), SLOT(buttonAnimationChanged(bool)));
98 }
99 
101 {
102  delete m_caseButton;
103  qDeleteAll(m_buttons);
104 }
105 
107 {
108  setObjectName(className());
109  QString style = TTK::UI::BtnMagic;
110  switch(type)
111  {
112  case 0: style += "#%1{ margin-left: 0px; }"; break;
113  case 1: style += "#%1{ margin-left: -48px; }"; break;
114  case 2: style += "#%1{ margin-left: -192px; }"; break;
115  case 3: style += "#%1{ margin-left: -96px; }"; break;
116  case 4: style += "#%1{ margin-left: -144px; }"; break;
117  default: break;
118  }
119  setStyleSheet(style.arg(className()));
120 
121  const QString &prfix = QString("background-image:url(':/enhance/lb_%1')");
122  m_caseButton->setStyleSheet(type ? TTK::UI::EnhanceOn : TTK::UI::EnhanceOff);
123  m_buttons[0]->setStyleSheet(prfix.arg(type == 1 ? "3d_on" : "3d_off"), type == 1);
124  m_buttons[1]->setStyleSheet(prfix.arg(type == 2 ? "nicam_on" : "nicam_off"), type == 2);
125  m_buttons[2]->setStyleSheet(prfix.arg(type == 3 ? "subwoofer_on" : "subwoofer_off"), type == 3);
126  m_buttons[3]->setStyleSheet(prfix.arg(type == 4 ? "vocal_on" : "vocal_off"), type == 4);
127 
128  m_lastSelectedIndex = (type == 0) ? m_lastSelectedIndex : type;
130 
131  if(type != 0)
132  {
134  }
135 
137  Q_EMIT enhancedMusicChanged(type);
138  m_menu->close();
139 }
140 
142 {
143  setEnhancedMusicConfig(m_caseButton->styleSheet().contains(":/enhance/btn_magic_off_normal") ? m_lastSelectedIndex : 0);
144 }
145 
147 {
148  const int index = G_SETTING_PTR->value(MusicSettingManager::EnhancedMusicIndex).toInt();
149  if(index < 1 || index > m_buttons.count())
150  {
151  return;
152  }
153 
154  state ? m_buttons[index - 1]->start() : m_buttons[index - 1]->stop();
155 }
156 
158 {
160  m_menu->close();
161 }
162 
164 {
166  m_menu->setStyleSheet(TTK::UI::MenuStyle04);
167 
168  m_containWidget->setFixedSize(272, 370);
169  m_containWidget->setObjectName("ContainWidget");
170  m_containWidget->setStyleSheet(QString("#ContainWidget{%1%2}").arg(TTK::UI::BorderStyle01, "background:url(':/enhance/lb_background')"));
171 
172  QToolButton *labelButton = new QToolButton(m_containWidget);
173  labelButton->setGeometry(80, 20, 126, 40);
174  labelButton->setStyleSheet(TTK::UI::EnhanceTitle);
175  labelButton->setCursor(Qt::PointingHandCursor);
176 
177  QToolButton *helpButton = new QToolButton(m_containWidget);
178  helpButton->setGeometry(205, 3, 24, 24);
179  helpButton->setStyleSheet(TTK::UI::EnhanceHelp);
180  helpButton->setCursor(Qt::PointingHandCursor);
181  connect(helpButton, SIGNAL(clicked()), SLOT(helpButtonClicked()));
182 
183  QToolButton *shareButton = new QToolButton(m_containWidget);
184  shareButton->setGeometry(230, 3, 24, 24);
185  shareButton->setStyleSheet(TTK::UI::EnhanceShare);
186  shareButton->setCursor(Qt::PointingHandCursor);
187 
188  QToolButton *closeButton = new QToolButton(m_containWidget);
189  closeButton->setGeometry(255, 8, 16, 16);
190  closeButton->setStyleSheet(TTK::UI::EnhanceClose);
191  closeButton->setCursor(Qt::PointingHandCursor);
192  connect(closeButton, SIGNAL(clicked()), m_menu, SLOT(close()));
193 
194  m_caseButton = new QToolButton(m_containWidget);
195  m_caseButton->setGeometry(200, 70, 62, 38);
196  m_caseButton->setStyleSheet(TTK::UI::EnhanceOn);
197  m_caseButton->setCursor(Qt::PointingHandCursor);
198 
200  button1->setGeometry(15, 115, LABEL_BUTTON_WIDGET, LABEL_BUTTON_HEIGHT);
201  button1->setStyleSheet("background-image:url(':/enhance/lb_3d_off')");
202  button1->setCursor(Qt::PointingHandCursor);
203 
205  button2->setGeometry(145, 115, LABEL_BUTTON_WIDGET, LABEL_BUTTON_HEIGHT);
206  button2->setStyleSheet("background-image:url(':/enhance/lb_nicam_off')");
207  button2->setCursor(Qt::PointingHandCursor);
208 
210  button3->setGeometry(15, 240, LABEL_BUTTON_WIDGET, LABEL_BUTTON_HEIGHT);
211  button3->setStyleSheet("background-image:url(':/enhance/lb_subwoofer_off')");
212  button3->setCursor(Qt::PointingHandCursor);
213 
215  button4->setGeometry(145, 240, LABEL_BUTTON_WIDGET, LABEL_BUTTON_HEIGHT);
216  button4->setStyleSheet("background-image:url(':/enhance/lb_vocal_off')");
217  button4->setCursor(Qt::PointingHandCursor);
218 
219  QButtonGroup *buttonGroup = new QButtonGroup(this);
220  buttonGroup->addButton(button1, 1);
221  buttonGroup->addButton(button2, 2);
222  buttonGroup->addButton(button3, 3);
223  buttonGroup->addButton(button4, 4);
225  m_buttons << button1 << button2 << button3 << button4;
226 
228  connect(m_caseButton, SIGNAL(clicked()), SLOT(switchButtonState()));
229 }
static MusicRightAreaWidget * instance()
#define QtEnterEvent
Event enter.
Definition: ttkqtcompat.h:160
The class of the tool menu base widget.
MusicEnhancedToolButton(QWidget *parent=nullptr)
static const QString MenuStyle04
static const QString BorderStyle01
border
MusicEnhancedPopWidget(QWidget *parent=nullptr)
static constexpr const char * BtnMagic
MusicToolMenu * m_menu
QPropertyAnimation * m_animation
static constexpr const char * EnhanceClose
void enhancedMusicChanged(int type)
static constexpr const char * EnhanceShare
static constexpr int LABEL_BUTTON_WIDGET
static constexpr int LABEL_ANIMAT_WIDGET
static constexpr const char * EnhanceOff
virtual void enterEvent(QtEnterEvent *event) overridefinal
#define TTK_SLOT
Definition: ttkqtglobal.h:165
#define QtButtonGroupConnect(p, q, f, s)
Button group connect.
Definition: ttkqtcompat.h:101
void setStyleSheet(const QString &styleSheet, bool state=false)
static MusicApplicationModule * instance()
static constexpr const char * EnhanceOn
QList< MusicEnhancedToolButton * > m_buttons
void buttonAnimationChanged(bool state)
static constexpr int LABEL_BUTTON_HEIGHT
The class of the enhanced tool button.
static constexpr const char * EnhanceTitle
static constexpr const char * EnhanceHelp
TTK_MODULE_EXPORT void enabledEffectPlugin(bool enabled, const QString &name={})
state
Definition: http_parser.c:279
void functionClicked(int index, QWidget *widget=nullptr)
#define G_SETTING_PTR