TTKMusicPlayer  4.3.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  painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
42 
43  painter.fillRect(0, 0, width(), 25, QColor(200, 200, 200, 70));
44 
45  if(m_currentValue != 0)
46  {
47  painter.fillRect(0, 0, m_currentValue * 1.0 / m_maxValue * width(), 20, QColor(100, 100, 100, 70));
48  }
49 
50  painter.setPen(QColor(50, 50, 50));
51  painter.drawText(QRect(10, 0, width() / 2, 20), Qt::AlignVCenter | Qt::AlignLeft, m_frontText);
52 
53  painter.setPen(QColor(50, 50, 50));
54  painter.drawText(QRect(width() / 2, 0, width() / 2 - 10, 20), Qt::AlignVCenter | Qt::AlignRight, m_backText);
55 }
virtual void paintEvent(QPaintEvent *event) overridefinal
MusicTextSliderWidget(QWidget *parent=nullptr)
void setBackText(const QString &text)
constexpr const _Tp & max(const _Tp &a, const _Tp &b) noexcept
Definition: ttkcompat.h:33
void setFrontText(const QString &text)