-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathform.cpp
89 lines (78 loc) · 1.98 KB
/
form.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
#include "form.h"
#include "ui_form.h"
#include <QMouseEvent>
#include <QDebug>
#include <QDir>
#include <QSettings>
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
ui->pushButton_close->hide();
ui->pushButton_set->hide();
setAttribute(Qt::WA_TranslucentBackground,true);
setWindowFlags(Qt::WindowStaysOnTopHint);
setWindowFlags(Qt::FramelessWindowHint);
setWindowFlags(Qt::X11BypassWindowManagerHint);
}
Form::~Form()
{
delete ui;
}
void Form::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
m_bPressed = true;
m_point = event->pos();
}
}
void Form::mouseMoveEvent(QMouseEvent *event)
{
if(m_bPressed)
move(event->pos() - m_point + pos());
}
void Form::mouseReleaseEvent(QMouseEvent *event)
{
Q_UNUSED(event);
m_bPressed = false;
writeSettings(QDir::currentPath() + "/config.ini", "LyricX", QString::number(x()));
writeSettings(QDir::currentPath() + "/config.ini", "LyricY", QString::number(y()));
}
void Form::enterEvent(QEvent *event)
{
Q_UNUSED(event);
setStyleSheet("background-color: rgba(255,255,255,30);");
ui->pushButton_close->show();
ui->pushButton_set->show();
}
void Form::leaveEvent(QEvent *event)
{
Q_UNUSED(event);
setStyleSheet("");
ui->pushButton_close->hide();
ui->pushButton_set->hide();
}
QString Form::readSettings(QString path, QString key)
{
QSettings setting(path, QSettings::IniFormat);
setting.beginGroup("config");
QString value = setting.value(key).toString();
return value;
}
void Form::writeSettings(QString path, QString key, QString value)
{
QSettings *config = new QSettings(path, QSettings::IniFormat);
config->beginGroup("config");
config->setValue(key, value);
config->endGroup();
}
void Form::on_pushButton_close_clicked()
{
hide();
emit pushButton_lyric_toggle();
}
//void Form::on_pushButton_set_clicked()
//{
// emit pull_settings();
//}