-
Notifications
You must be signed in to change notification settings - Fork 17
/
lyricwidget.cpp
94 lines (79 loc) · 2.5 KB
/
lyricwidget.cpp
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
#include "lyricwidget.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QDir>
#include <QSettings>
#include <QApplication>
LyricWidget::LyricWidget(QWidget *parent) : QWidget(parent),
settings(QApplication::organizationName(), QApplication::applicationName())
{
resize(800,120);
setAttribute(Qt::WA_TranslucentBackground, true);
setWindowFlags(Qt::WindowStaysOnTopHint);
setWindowFlags(Qt::FramelessWindowHint);
setWindowFlags(Qt::X11BypassWindowManagerHint);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->setSpacing(0);
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addStretch();
pushButton_set = new QPushButton;
pushButton_set->setFixedSize(24,24);
pushButton_set->setIcon(QIcon(":/icon/set.svg"));
pushButton_set->setFocusPolicy(Qt::NoFocus);
pushButton_set->setFlat(true);
pushButton_set->setCursor(Qt::PointingHandCursor);
hbox->addWidget(pushButton_set);
pushButton_close = new QPushButton;
pushButton_close->setFixedSize(24,24);
pushButton_close->setIcon(QIcon(":/icon/close.svg"));
pushButton_close->setFocusPolicy(Qt::NoFocus);
pushButton_close->setFlat(true);
pushButton_close->setCursor(Qt::PointingHandCursor);
hbox->addWidget(pushButton_close);
vbox->addLayout(hbox);
label_lyric = new QLabel("Hello,酷狗!");
label_lyric->setAlignment(Qt::AlignCenter);
QFont font;
font.setPointSize(30);
label_lyric->setFont(font);
vbox->addWidget(label_lyric);
setLayout(vbox);
pushButton_set->hide();
pushButton_close->hide();
}
void LyricWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
isMouseLeftButtonPressed = true;
m_point = event->pos();
}
}
void LyricWidget::mouseMoveEvent(QMouseEvent *event)
{
if(isMouseLeftButtonPressed){
setCursor(Qt::ClosedHandCursor);
move(event->pos() - m_point + pos());
}
}
void LyricWidget::mouseReleaseEvent(QMouseEvent *event)
{
Q_UNUSED(event);
isMouseLeftButtonPressed = false;
setCursor(Qt::ArrowCursor);
settings.setValue("LyricX", x());
settings.setValue("LyricY", y());
}
void LyricWidget::enterEvent(QEvent *event)
{
Q_UNUSED(event);
setStyleSheet("background-color: rgba(255,255,255,30);");
pushButton_close->setVisible(true);
pushButton_set->setVisible(true);
}
void LyricWidget::leaveEvent(QEvent *event)
{
Q_UNUSED(event);
setStyleSheet("");
pushButton_close->setVisible(false);
pushButton_set->setVisible(false);
}