TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicvideoplaywidget.cpp
Go to the documentation of this file.
1 #include "musicvideoplaywidget.h"
2 #include "musicvideoview.h"
3 #include "musicitemsearchedit.h"
7 #include "musictinyuiobject.h"
8 #include "musicapplication.h"
9 #include "ttkdesktopwrapper.h"
10 
11 #include <QParallelAnimationGroup>
12 
13 static constexpr int WINDOW_HEIGHT = 508;
14 static constexpr int WINDOW_WIDTH = 678;
15 
17  : TTKAbstractMoveWidget(false, parent),
18  m_backButton(nullptr)
19 {
20  setWindowTitle(tr("TTKMovie"));
21 
22  m_leaverTimer = new QTimer(this);
23  m_leaverTimer->setInterval(4 * TTK_DN_S2MS);
24  m_leaverTimer->setSingleShot(true);
25  connect(m_leaverTimer, SIGNAL(timeout()), SLOT(leaveTimeout()));
26 
27  QVBoxLayout *layout = new QVBoxLayout(this);
28  layout->setContentsMargins(0, 0, 0, 0);
29  layout->setSpacing(0);
30 
31  m_topWidget = new QWidget(this);
33 
34  QHBoxLayout *topLayout = new QHBoxLayout(m_topWidget);
35  topLayout->setContentsMargins(9, 4, 9, 4);
36 
37  m_textLabel = new QLabel(m_topWidget);
38  m_textLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
39  m_textLabel->setStyleSheet(TTK::UI::ColorStyle06);
40 
42  m_searchEdit->setFixedHeight(25);
43 
44  topLayout->addWidget(m_textLabel);
45  topLayout->addStretch();
46  topLayout->addWidget(m_searchEdit);
47 
48  m_closeButton = new QPushButton(this);
49  m_closeButton->setToolTip(tr("Close"));
50  m_closeButton->setFixedSize(14, 14);
51  m_closeButton->setStyleSheet(TTK::UI::BtnPClose);
52  m_closeButton->setCursor(QCursor(Qt::PointingHandCursor));
53  connect(m_closeButton, SIGNAL(clicked()), parent, SLOT(videoNeedToClose()));
54  topLayout->addWidget(m_closeButton);
55  m_topWidget->setLayout(topLayout);
56 
57 #ifdef Q_OS_UNIX
58  m_closeButton->setFocusPolicy(Qt::NoFocus);
59 #endif
60 
61  m_stackedWidget = new QStackedWidget(this);
63 
64  QWidget *topMaskWidget = new QWidget(this);
65  topMaskWidget->setFixedHeight(35);
66  topMaskWidget->setStyleSheet(TTK::UI::BackgroundStyle02);
67 
68  layout->addWidget(topMaskWidget);
69  layout->addWidget(m_stackedWidget);
70  setLayout(layout);
71 
72  m_searchEdit->hide();
73  m_topWidget->raise();
74 
77  m_videoView = new MusicVideoView(this);
78 
79  m_stackedWidget->addWidget(m_videoView);
80 #if TTK_QT_VERSION_CHECK(5,0,0)
81  m_stackedWidget->addWidget(m_tableWidget);
82 #else
83  QWidget *videoMaskWidget = new QWidget(this);
84  videoMaskWidget->setObjectName("videoMaskWidget");
85  videoMaskWidget->setStyleSheet(QString("#%1{%2}").arg(videoMaskWidget->objectName(), TTK::UI::BackgroundStyle10));
86  QHBoxLayout *videoMaskWidgetLayout = new QHBoxLayout(videoMaskWidget);
87  videoMaskWidgetLayout->setContentsMargins(0, 0, 0, 0);
88  videoMaskWidgetLayout->addWidget(m_tableWidget);
89  m_stackedWidget->addWidget(videoMaskWidget);
90 #endif
91  m_stackedWidget->setCurrentIndex(0);
92 
93  m_leaverAnimation = new QParallelAnimationGroup(this);
94  QPropertyAnimation *topAnimation = new QPropertyAnimation(m_topWidget, "pos", m_leaverAnimation);
95  topAnimation->setDuration(TTK_DN_S2MS / 2);
96  QPropertyAnimation *ctrlAnimation = new QPropertyAnimation(m_videoView->controlBarWidget(), "pos", m_leaverAnimation);
97  ctrlAnimation->setDuration(TTK_DN_S2MS / 2);
98  m_leaverAnimation->addAnimation(topAnimation);
99  m_leaverAnimation->addAnimation(ctrlAnimation);
100 
102  connect(m_tableWidget, SIGNAL(restartToSearchQuery(QString)), SLOT(videoResearchButtonSearched(QString)));
103  connect(m_searchEdit, SIGNAL(trigger(QString)), SLOT(videoResearchButtonSearched(QString)));
104 
105  connect(m_videoFloatWidget, SIGNAL(searchButtonClicked()), SLOT(switchToSearchTable()));
106  connect(m_videoFloatWidget, SIGNAL(popupButtonClicked()), SLOT(popupButtonClicked()));
109  connect(m_videoFloatWidget, SIGNAL(shareButtonClicked()), SLOT(shareButtonClicked()));
110 
111  connect(m_videoView, SIGNAL(searchButtonClicked()), SLOT(switchToSearchTable()));
112  connect(m_videoView, SIGNAL(popupButtonClicked()), SLOT(popupButtonClicked()));
113  connect(m_videoView, SIGNAL(fullscreenButtonClicked()), SLOT(fullscreenButtonClicked()));
114  connect(m_videoView, SIGNAL(downloadButtonClicked()), SLOT(downloadButtonClicked()));
115  connect(m_videoView, SIGNAL(shareButtonClicked()), SLOT(shareButtonClicked()));
116 }
117 
119 {
120  delete m_leaverTimer;
121  delete m_leaverAnimation;
122  delete m_closeButton;
123  delete m_textLabel;
124  delete m_searchEdit;
125  delete m_backButton;
126  delete m_videoView;
127  delete m_stackedWidget;
128 }
129 
131 {
133  blockMoveOption(!popup);
134 
135  if(popup)
136  {
137  const QSize &size = G_SETTING_PTR->value(MusicSettingManager::ScreenSize).toSize();
138  setGeometry((size.width() - WINDOW_WIDTH) / 2, (size.height() - WINDOW_HEIGHT) / 2, WINDOW_WIDTH, WINDOW_HEIGHT);
139  resizeGeometry(0, 0);
140  setParent(nullptr);
141  show();
142  }
143  else
144  {
145 #ifdef Q_OS_UNIX
146  if(isFullScreen())
147  {
148  showNormal();
149  }
150 #endif
152  }
153 }
154 
156 {
157  return !m_moveOption;
158 }
159 
161 {
162  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width();
163  const int height = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().height();
164 
165  if(!isFullScreen())
166  {
167 #ifdef Q_OS_UNIX
168  const bool v = isPopupMode();
169  resizeGeometry(v ? (this->width() - 680) : (width - WINDOW_WIDTH_MIN), v ? (this->height() - 508) : (height - WINDOW_HEIGHT_MIN));
170 #else
172 #endif
173  }
174 }
175 
177 {
178  if(resize)
179  {
180  showFullScreen();
181  }
182  else
183  {
184  showNormal();
185  setGeometry(250, 150, WINDOW_WIDTH, WINDOW_HEIGHT);
186  }
187 
188  QSize s = size();
189 #ifdef Q_OS_UNIX
190  const QRect &rect = TTKDesktopWrapper::screenGeometry();
191  if(isFullScreen() && !rect.isNull())
192  {
193  s = rect.size();
194  }
195  else
196  {
197  s = QSize(WINDOW_WIDTH, WINDOW_HEIGHT);
198  showNormal();
199  }
200 #endif
201  resizeGeometry(s.width() - WINDOW_WIDTH, s.height() - WINDOW_HEIGHT);
202 }
203 
204 void MusicVideoPlayWidget::resizeGeometry(int width, int height)
205 {
206  m_topWidget->setGeometry(0, 0, 680 + width, 35);
208  m_videoView->resizeGeometry(width, height);
209  m_videoFloatWidget->resizeGeometry(width, height);
210 }
211 
213 {
214  QHBoxLayout *topLayout = TTKObjectCast(QHBoxLayout*, m_topWidget->layout());
215  delete m_backButton;
216  m_backButton = new QToolButton(m_topWidget);
217  m_backButton->setFixedSize(20, 20);
218  m_backButton->setToolTip(tr("Back"));
219  m_backButton->setCursor(QCursor(Qt::PointingHandCursor));
220  m_backButton->setStyleSheet(TTK::UI::BtnBackBack);
221  connect(m_backButton, SIGNAL(clicked()), SLOT(switchToPlayView()));
222  topLayout->insertWidget(0, m_backButton);
223 
224  m_textLabel->clear();
225  m_searchEdit->show();
226  m_stackedWidget->setCurrentIndex(1);
227 }
228 
230 {
231  delete m_backButton;
232  m_backButton = nullptr;
233 
235  m_searchEdit->hide();
236  m_stackedWidget->setCurrentIndex(0);
237 }
238 
240 {
242  m_searchEdit->editor()->setText(name);
244 }
245 
247 {
249 
250  const TTK::MusicSongInformation info(data.value<TTK::MusicSongInformation>());
251  const TTK::MusicSongPropertyList &props = info.m_songProps;
252  if(!props.isEmpty())
253  {
254  const TTK::MusicSongProperty &prop = props.front();
255  MusicVideoItem data;
257  data.m_url = prop.m_url;
258  data.m_id = info.m_songId;
259  data.m_cover = info.m_coverUrl;
261  mediaUrlPathChanged(data);
262  }
263 }
264 
266 {
269 }
270 
272 {
273  if(url.isEmpty())
274  {
275  return;
276  }
277 
279  if(w->isPlaying())
280  {
281  w->switchToPlayState();
282  }
283 
285  m_videoView->setMedia(url);
286  m_videoView->play();
287 
289 }
290 
292 {
293  m_videoItem = item;
294  setTitleText(item.m_name);
295  mediaUrlChanged(item.m_url);
296  //
297  m_videoView->setBarrage(item.m_name, item.m_id);
298 }
299 
301 {
303 }
304 
306 {
308  {
309  return;
310  }
311 
312  const bool full = !m_videoFloatWidget->isFullscreenMode();
314  Q_EMIT fullscreenButtonClicked(full);
315 }
316 
318 {
320 }
321 
323 {
324  const QString &name = m_videoItem.m_name.trimmed();
325  const QString &id = m_videoItem.m_id.trimmed();
326 
327  if(name.isEmpty() || id.isEmpty())
328  {
329  return;
330  }
331 
333  item.m_id = id;
334  item.m_name = name;
335  item.m_cover = m_videoItem.m_cover;
337 
338  MusicSongSharingWidget widget(this);
340  widget.exec();
341 }
342 
344 {
345  QWidget *w(m_videoView->controlBarWidget());
346  if(w->y() != height())
347  {
348  const int topHeight = (m_stackedWidget->currentIndex() == 1) ? 0 : -m_topWidget->height();
349  start(0, topHeight, height() - w->height() - m_topWidget->height(), height());
350  }
351 }
352 
353 void MusicVideoPlayWidget::resizeEvent(QResizeEvent *event)
354 {
355  TTKAbstractMoveWidget::resizeEvent(event);
356  resizeWindow();
357 
358  m_leaverTimer->stop();
359  m_leaverAnimation->stop();
360 }
361 
363 {
364  TTKAbstractMoveWidget::enterEvent(event);
365  m_leaverTimer->stop();
366 
367  QWidget *w(m_videoView->controlBarWidget());
368  if(w->y() >= height())
369  {
370  const int topHeight = (m_stackedWidget->currentIndex() == 1) ? 0 : -m_topWidget->height();
371  start(topHeight, 0, height(), height() - w->height() - m_topWidget->height());
372  }
373 }
374 
376 {
377  TTKAbstractMoveWidget::leaveEvent(event);
378  m_leaverTimer->start();
379 }
380 
381 void MusicVideoPlayWidget::setTitleText(const QString &text)
382 {
383  m_textLabel->setText(TTK::Widget::elidedText(font(), text, Qt::ElideRight, width() - 50));
384 }
385 
386 void MusicVideoPlayWidget::start(int st, int end, int ctrlst, int ctrlend)
387 {
388  m_leaverAnimation->stop();
389  QPropertyAnimation *animation = TTKObjectCast(QPropertyAnimation*, m_leaverAnimation->animationAt(0));
390  animation->setStartValue(QPoint(0, st));
391  animation->setEndValue(QPoint(0, end));
392  animation = TTKObjectCast(QPropertyAnimation*, m_leaverAnimation->animationAt(1));
393  animation->setStartValue(QPoint(0, ctrlst));
394  animation->setEndValue(QPoint(0, ctrlend));
395  m_leaverAnimation->start();
396 }
QParallelAnimationGroup * m_leaverAnimation
static const QString ColorStyle06
Definition: musicuiobject.h:52
#define QtEnterEvent
Event enter.
Definition: ttkqtcompat.h:160
TTK_MODULE_EXPORT QString generateSongName(const QString &title, const QString &artist)
Definition: musicsong.cpp:112
static constexpr int WINDOW_HEIGHT
static MusicApplication * instance()
QStackedWidget * m_stackedWidget
static constexpr int WINDOW_WIDTH
void setMedia(const QString &data)
static const QString BorderStyle01
border
void setTitleText(const QString &text)
MusicVideoFloatWidget * m_videoFloatWidget
void mediaUrlChanged(const QString &url)
The class of the song share widget.
The class of the music song property.
Definition: musicobject.h:223
MusicVideoPlayWidget(QWidget *parent=nullptr)
void initialize(Module type, const MusicSongSharingWidget::Item &data)
static const QString BackgroundStyle08
voidpf void uLong size
Definition: ioapi.h:136
static constexpr const char * BtnPClose
The class of the app main widget.
void start(int topst, int topend, int ctrlst, int ctrlend)
MusicSongPropertyList m_songProps
Definition: musicobject.h:295
MusicVideoSearchTableWidget * m_tableWidget
void startToSearchByID(const QString &name)
virtual void leaveEvent(QEvent *event) overridefinal
void videoResearchButtonSearched(const QString &name)
virtual void enterEvent(QtEnterEvent *event) overridefinal
MusicSearchEdit * editor() const
virtual void resizeEvent(QResizeEvent *event) overridefinal
const char * name
Definition: http_parser.c:458
#define MUSIC_MOVIE_RADIO
static const QString BackgroundStyle02
Definition: musicuiobject.h:84
void resizeGeometry(bool resize)
static QRect screenGeometry(int index=0)
The class of the ttk moving widget base.
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
The class of the video float widget.
void mediaUrlPathChanged(const MusicVideoItem &item)
static const QString BackgroundStyle10
void resizeGeometry(int width, int height)
MusicVideoControlWidget * controlBarWidget() const
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
void blockMoveOption(bool block)
The class of the video view widget.
void startToSearchByID(const QString &text)
MusicItemQueryEdit * m_searchEdit
bool isPlaying() const
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:153
The class of the video item play data item.
void setBarrage(const QString &name, const QString &id)
void resizeGeometry(int width, int height)
MusicVideoView * m_videoView
The class of the query line edit widget.
static constexpr const char * BtnBackBack
The class of the video search table widget.
The class of the music song information.
Definition: musicobject.h:281
#define WINDOW_HEIGHT_MIN
Definition: musicobject.h:154
virtual void startToSearchByText(const QString &text) overridefinal
#define G_SETTING_PTR
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:60