-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvolumntool.cpp
More file actions
105 lines (98 loc) · 3 KB
/
Copy pathvolumntool.cpp
File metadata and controls
105 lines (98 loc) · 3 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
#include "volumntool.h"
#include "ui_volumntool.h"
#include<QGraphicsDropShadowEffect>
VolumnTool::VolumnTool(QWidget *parent)
: QWidget(parent)
, ui(new Ui::VolumnTool)
,_ismuted(false)
,_volumerantio(20)
{
ui->setupUi(this);
//设置窗口属性
setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
//透明窗口
setAttribute(Qt::WA_TranslucentBackground);
//自定义阴影效果
QGraphicsDropShadowEffect* effect=new QGraphicsDropShadowEffect(this);
effect->setOffset(0,0);
effect->setColor("#646464");
effect->setBlurRadius(10);
setGraphicsEffect(effect);
//改变图片
ui->Silencebtn->setIcon(QIcon(":/images/volumn.png"));
//对默认音量进行设置
QRect rec=ui->OutLine->geometry();
ui->OutLine->setGeometry(rec.x(),rec.height()-36+25,rec.width(),36);
ui->Controll->move(ui->Controll->x(),ui->OutLine->y()-ui->Controll->height()/2);
ui->Ration->setText("20%");
connect(ui->Silencebtn,&QPushButton::clicked,this,&VolumnTool::OnSilenceClick);
ui->SliderBox->installEventFilter(this);
}
VolumnTool::~VolumnTool()
{
delete ui;
}
void VolumnTool::paintEvent(QPaintEvent *event)
{
(void)event;
//创建painter对象
QPainter painter(this);
//设置抗锯齿
painter.setRenderHint(QPainter::Antialiasing,true);
//设置画笔
//没有画笔画出来就没有边框和轮廓
painter.setPen(Qt::NoPen);
//画刷颜色
painter.setBrush(Qt::white);
//创建三角形
QPolygon polygon;
polygon.append(QPoint(30,300));
polygon.append(QPoint(70,300));
polygon.append(QPoint(50,320));
//绘制三角形
painter.drawPolygon(polygon);
}
void VolumnTool::OnSilenceClick()
{
_ismuted=!_ismuted;
if(_ismuted)
{
ui->Silencebtn->setIcon(QIcon(":/images/silent.png"));
}else
{
ui->Silencebtn->setIcon(QIcon(":/images/volumn.png"));
}
emit setsilence(_ismuted);
}
bool VolumnTool::eventFilter(QObject *object, QEvent *event)
{
if(object==ui->SliderBox)
{
if(event->type()==QEvent::MouseButtonPress)
{
SetVolume();
}else if(event->type()==QEvent::MouseMove)
{
SetVolume();
emit setvolumeratio(_volumerantio);
}else if(event->type()==QEvent::MouseButtonRelease)
{
emit setvolumeratio(_volumerantio);
}
return true;
}
return QObject::eventFilter(object,event);
}
void VolumnTool::SetVolume()
{
int height=ui->SliderBox->mapFromGlobal(QCursor().pos()).y();
height=height<25?25:height;
height=height>205?205:height;
ui->Controll->move(ui->Controll->x(),height-ui->Controll->height()/2);
ui->OutLine->setGeometry(ui->OutLine->x(),height,ui->OutLine->width(),205-height);
float maxheigtht=180.0f;
float ration=(float)ui->OutLine->height()/maxheigtht;
ration=qBound(0.0f,ration,1.0f);
_volumerantio=ration;
ui->Ration->setText(QString("%1%").arg(_volumerantio*100,0,'f',1));
}