TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musictextsliderwidget.cpp
Go to the documentation of this file.
2 
3 #include <QPainter>
4 
6  : QWidget(parent),
7  m_maxValue(1),
8  m_currentValue(0)
9 {
10 
11 }
12 
14 {
15  m_maxValue = max;
16  update();
17 }
18 
20 {
21  m_currentValue = value;
22  update();
23 }
24 
25 void MusicTextSliderWidget::setFrontText(const QString &text)
26 {
27  m_frontText = text;
28  update();
29 }
30 
31 void MusicTextSliderWidget::setBackText(const QString &text)
32 {
33  m_backText = text;
34  update();
35 }
36 
37 void MusicTextSliderWidget::paintEvent(QPaintEvent *event)
38 {
39  QWidget::paintEvent(event);
40  QPainter painter(this);
41 
42  painter.fillRect(0, 0, width(), 25, QColor(200, 200, 200, 70));
43 
44  if(m_currentValue != 0)
45  {
46  painter.fillRect(0, 0, m_currentValue * 1.0 / m_maxValue * width(), 20, QColor(100, 100, 100, 70));
47  }
48 
49  painter.setPen(QColor(50, 50, 50));
50  painter.drawText(QRect(10, 0, width() / 2, 20), Qt::AlignVCenter | Qt::AlignLeft, m_frontText);
51 
52  painter.setPen(QColor(50, 50, 50));
53  painter.drawText(QRect(width() / 2, 0, width() / 2 - 10, 20), Qt::AlignVCenter | Qt::AlignRight, m_backText);
54 }
constexpr const _Tp & max(const _Tp &a, const _Tp &b)
Definition: ttkcompat.h:33
virtual void paintEvent(QPaintEvent *event) overridefinal
MusicTextSliderWidget(QWidget *parent=nullptr)
void setBackText(const QString &text)
void setFrontText(const QString &text)