TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicpreviewlabel.cpp
Go to the documentation of this file.
1 #include "musicpreviewlabel.h"
2 #include "musicwidgetutils.h"
3 
5  : TTKClickedLabel(parent)
6 {
7  m_linearGradient.setStart(0, 0);
8 }
9 
10 void MusicColorPreviewLabel::setColors(const QList<QColor> &colors)
11 {
12  QLinearGradient linearGradient;
13  for(int i = 0; i < colors.count(); ++i)
14  {
15  linearGradient.setColorAt((i + 1) * 1.0 / colors.count(), colors[i]);
16  }
17 
19  m_linearGradient = linearGradient;
20  update();
21 }
22 
23 QList<QColor> MusicColorPreviewLabel::colors() const
24 {
25  return m_gradientColors;
26 }
27 
29 {
30  return !m_gradientColors.empty() ? m_gradientColors.front() : QColor();
31 }
32 
34 {
35  QPainter painter(this);
36 
37  const int h = height() - 4 * 2;
38  m_linearGradient.setFinalStop(0, height());
39 
40  painter.setFont(font());
41  painter.setBrush(Qt::white);
42  painter.drawRect(0, 0, width(), height());
43 
44  painter.setPen(QPen(Qt::black, 0));
45  painter.drawRect(0, 0, width() - 1, height() - 1);
46 
47  painter.setBrush(m_linearGradient);
48  painter.drawRect(4, 4, h, h);
49 
50  painter.setPen(QPen(Qt::black, 0));
51  painter.drawText(h + 2 * 4, 4, width() - h - 3 * 4, h, Qt::AlignCenter, text());
52 }
53 
54 
55 
57  : QLabel(parent),
58  m_transparent(255)
59 {
60  m_linearGradient.setStart(0, 0);
61  m_maskLinearGradient.setStart(0, 0);
62 }
63 
65 {
66  m_font.setFamily(item.m_family);
67  m_font.setPointSize(item.m_size);
68  m_font.setBold((item.m_type == 1 || item.m_type == 3));
69  m_font.setItalic((item.m_type == 2 || item.m_type == 3));
70 
72 }
73 
74 void MusicPreviewLabel::setLinearGradient(const QList<QColor> &front, const QList<QColor> &back)
75 {
76  QLinearGradient linearGradient, maskLinearGradient;
77  for(int i = 0; i < back.count(); ++i)
78  {
79  QColor rgb = back[i];
80  rgb.setAlpha(m_transparent);
81  linearGradient.setColorAt((i + 1) * 1.0 / back.count(), rgb);
82  }
83 
84  for(int i = 0; i < front.count(); ++i)
85  {
86  QColor rgb = front[i];
87  rgb.setAlpha(m_transparent);
88  maskLinearGradient.setColorAt((i + 1) * 1.0 / front.count(), rgb);
89  }
90 
91  m_linearGradient = linearGradient;
92  m_maskLinearGradient = maskLinearGradient;
93 }
94 
95 void MusicPreviewLabel::paintEvent(QPaintEvent *)
96 {
97  QPainter painter(this);
98 
99  const int h = TTK::Widget::fontTextHeight(m_font);
100  const int begin = (rect().height() - h) / 2;
101  m_linearGradient.setFinalStop(0, h + begin);
102  m_maskLinearGradient.setFinalStop(0, h + begin);
103 
104  painter.setFont(m_font);
105  painter.drawText(rect(), Qt::AlignLeft | Qt::AlignVCenter, "This is TTKMusicPlayer");
106 
107  painter.setPen(QColor(0, 0, 0, 200));
108  painter.drawText(rect(), Qt::AlignLeft | Qt::AlignVCenter, "This is TTKMusicPlayer");
109 
110  painter.setPen(QPen(m_linearGradient, 0));
111  painter.drawText(1, 1, rect().width(), rect().height(), Qt::AlignLeft | Qt::AlignVCenter, "This is TTKMusicPlayer");
112 
113  painter.setPen(QPen(m_maskLinearGradient, 0));
114  painter.drawText(1, 1, 60, rect().height(), Qt::AlignLeft | Qt::AlignVCenter, "This is TTKMusicPlayer");
115 }
QList< QColor > m_background
The class of the label previewed.
QLinearGradient m_maskLinearGradient
virtual void paintEvent(QPaintEvent *event) overridefinal
The class of the label widget that can click.
QList< QColor > m_frontground
QLinearGradient m_linearGradient
void setColors(const QList< QColor > &colors)
virtual void paintEvent(QPaintEvent *event) overridefinal
QList< QColor > m_gradientColors
QLinearGradient m_linearGradient
QList< QColor > colors() const
void setLinearGradient(const MusicPreviewLabelItem &item)
TTK_MODULE_EXPORT int fontTextHeight(const QFont &font)
MusicPreviewLabel(QWidget *parent=nullptr)
MusicColorPreviewLabel(QWidget *parent=nullptr)