TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsongdailywidget.cpp
Go to the documentation of this file.
1 #include "musicsongdailywidget.h"
2 #include "musiccibarequest.h"
3 #include "musicwidgetheaders.h"
4 #include "musicwidgetutils.h"
5 #include "musicimageutils.h"
6 
8  : QFrame(parent)
9 {
10  setObjectName(className());
11  setStyleSheet(QString("#%1{ %2 }").arg(objectName(), TTK::UI::BackgroundStyle10));
12 
13  m_container = new QLabel(this);
14 
15  QVBoxLayout *layout = new QVBoxLayout(this);
16  layout->addWidget(m_container);
17  setLayout(layout);
18 
19  m_note = new QLabel(m_container);
20  m_content = new QLabel(m_container);
21 
23  connect(m_networkRequest, SIGNAL(downLoadRawDataChanged(QByteArray)), this, SLOT(downLoadImageFinished(QByteArray)));
24 
26 }
27 
29 {
30  delete m_note;
31  delete m_content;
32  delete m_container;
33  delete m_networkRequest;
34 }
35 
37 {
38  const double scale = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width() * 1.0 / WINDOW_WIDTH_MIN;
39 
40  QFont font = m_note->font();
41  font.setPixelSize(20.0 * scale);
42  const int noteHeight = TTK::Widget::fontTextHeight(font);
43 
44  m_note->setFont(font);
45  m_note->setGeometry(50, 50, TTK::Widget::fontTextWidth(font, m_note->text()), noteHeight);
46 
47  font = m_content->font();
48  font.setPixelSize(18.0 * scale);
49  const int contentHeight = TTK::Widget::fontTextHeight(font);
50 
51  m_content->setFont(font);
52  m_content->setGeometry(50, 50 + noteHeight, TTK::Widget::fontTextWidth(font, m_content->text()), contentHeight);
53 
54  m_container->setPixmap(QPixmap::fromImage(m_image).scaled(m_container->size(), Qt::KeepAspectRatioByExpanding));
55 }
56 
57 void MusicSongDailyWidget::downLoadImageFinished(const QByteArray &bytes)
58 {
59  if(bytes.isEmpty())
60  {
61  TTK_ERROR_STREAM("Input byte data is empty");
62  return;
63  }
64 
65  m_image.loadFromData(bytes);
66  if(m_image.isNull())
67  {
68  return;
69  }
70 
71  QRgb r = 0, g = 0, b = 0;
72  for(int w = 0; w < m_image.width(); ++w)
73  {
74  for(int h = 0; h < m_image.height(); ++h)
75  {
76  const QRgb rgb = m_image.pixel(w, h);
77  r += qRed(rgb);
78  g += qGreen(rgb);
79  b += qBlue(rgb);
80  }
81  }
82 
83  const int size = m_image.width() * m_image.height();
84  r /= size;
85  g /= size;
86  b /= size;
87 
88  const QRgb rgb = TTK::Image::colorContrast(qRgb(r, g, b));
89  const QString &style = QString("color:rgb(%1, %2, %3)").arg(qRed(rgb)).arg(qGreen(rgb)).arg(qBlue(rgb));
90 
91  m_note->setStyleSheet(style);
92  m_content->setStyleSheet(style);
93 
94  m_note->setText(m_networkRequest->note());
95  m_content->setText(m_networkRequest->content());
96 
97  resizeWidget();
98 }
99 
100 void MusicSongDailyWidget::resizeEvent(QResizeEvent *event)
101 {
102  QWidget::resizeEvent(event);
103  resizeWidget();
104 }
virtual void resizeEvent(QResizeEvent *event) overridefinal
voidpf void uLong size
Definition: ioapi.h:136
virtual void resizeWidget() overridefinal
QString content() const
The class of the ciba request.
QString note() const
static const QString BackgroundStyle10
void downLoadImageFinished(const QByteArray &bytes)
TTK_MODULE_EXPORT int fontTextWidth(const QFont &font, const QString &text)
TTK_MODULE_EXPORT unsigned int colorContrast(const unsigned int color)
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:155
TTK_MODULE_EXPORT int fontTextHeight(const QFont &font)
MusicSongDailyWidget(QWidget *parent=nullptr)
MusicCiBaRequest * m_networkRequest
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:70
#define G_SETTING_PTR