-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqshowlrc.cpp
More file actions
133 lines (120 loc) · 3.28 KB
/
qshowlrc.cpp
File metadata and controls
133 lines (120 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "qshowlrc.h"
#include "ui_qshowlrc.h"
QShowLrc::QShowLrc(QWidget *parent) :
QWidget(parent),
ui(new Ui::QShowLrc)
{
ui->setupUi(this);
initWinAttribute();
initWinInterface();
initTextEdit();
}
QShowLrc::~QShowLrc()
{
delete ui;
}
void QShowLrc::mousePressEvent(QMouseEvent *event)
{
//只能是鼠标左键移动和改变大小
if(event->button() == Qt::LeftButton)
{
mouse_press = true;
}
//窗口移动距离
move_point = event->globalPos() - pos();
}
void QShowLrc::mouseReleaseEvent(QMouseEvent *)
{
mouse_press = false;
}
void QShowLrc::mouseMoveEvent(QMouseEvent *event)
{
//移动窗口
if(mouse_press)
{
QPoint move_pos = event->globalPos();
move(move_pos - move_point);
}
}
void QShowLrc::initWinAttribute()
{
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(QSize(width(), height()));
}
void QShowLrc::initWinInterface()
{
QPixmap pixmap = QPixmap(":/share/2.png").scaled(ui->textEdit->size());
QPalette palette(ui->textEdit->palette());
palette.setBrush(QPalette::Base, QBrush(pixmap));
palette.setColor(QPalette::Text, QColor(255, 255, 255));
ui->textEdit->setPalette(palette);
ui->pb_close->setIconSize(QSize(28, 28));
ui->pb_close->setIcon(QIcon(":/share/close_hover.png"));
}
void QShowLrc::initTextEdit()
{
ui->textEdit->setReadOnly(true);
ui->textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QPixmap pixmap = QPixmap(":/share/2.png").scaled(this->size());
QPalette palette(this->palette());
palette.setBrush(QPalette::Background, QBrush(pixmap));
this->setPalette(palette);
}
void QShowLrc::setLrc(QString lrc)
{
lrc_map.clear();
ui->textEdit->clear();
if(!lrc.contains("\n"))
{
ui->textEdit->setText(lrc);
ui->textEdit->setAlignment(Qt::AlignCenter);
return;
}
regExgLrc(lrc);
showLrcOnText();
}
void QShowLrc::regExgLrc(QString lrc)
{
QStringList lines = lrc.split("\n");
QRegExp regExp("\\[\\d{2}:\\d{2}\\.\\d{2}\\]");
foreach(QString oneLine, lines)
{
QString temp = oneLine; //取出一行
temp.replace(regExp, ""); //替换掉时间
int pos = regExp.indexIn(oneLine, 0);
while(pos > -1)
{
QString cap = regExp.cap(0);
QRegExp rx;
rx.setPattern("\\d{2}(?=:)");
rx.indexIn(cap);
int minute = rx.cap(0).toInt();
rx.setPattern("\\d{2}(?=\\.)");
rx.indexIn(cap);
int second = rx.cap(0).toInt();
rx.setPattern("\\d{2}(?=\\])");
rx.indexIn(cap);
int millisecond = rx.cap(0).toInt();
qint64 totalTime = minute * 60000
+ second * 1000
+ millisecond * 10;
// 插入到lrc_map中
lrc_map.insert(totalTime, temp);
pos += regExp.matchedLength();
pos = regExp.indexIn(oneLine, pos);
}
}
}
void QShowLrc::showLrcOnText()
{
ui->textEdit->setAlignment(Qt::AlignCenter);
foreach(QString oneLine, lrc_map.values())
{
ui->textEdit->append(oneLine);
}
ui->textEdit->scrollToAnchor("\n");
}
void QShowLrc::on_pb_close_clicked()
{
hide();
}