Repository navigation
Expand file tree
/
Copy pathsettingpage.cpp
More file actions
245 lines (201 loc) · 7.98 KB
/
Copy pathsettingpage.cpp
File metadata and controls
245 lines (201 loc) · 7.98 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include"CGammaRamp.h"
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#include <audioclient.h>
#include "settingpage.h"
#include "ui_settingpage.h"
#include<qpixmap.h>
#include<qfile.h>
#include <QTemporaryDir>
#include<qdesktopservices.h>
#include<qurl.h>
#include<qpainter.h>
#include<stdio.h>
settingpage::settingpage(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::settingpage)
{
//index=0;
ui->setupUi(this);
QPixmap pixmap = QPixmap(":/picture/Settingpage/dialogbox.png").scaled(this->size());
QPalette palette(this->palette());
palette.setBrush(QPalette::Background, QBrush(pixmap));
this->setPalette(palette);
//去窗口边框
this->setWindowFlags(Qt::FramelessWindowHint | this->windowFlags());
//把窗口背景设置为透明
this->setAttribute(Qt::WA_TranslucentBackground);
//以下属性默认为false,即mouseMoveEvent只有在按键按下时移动才能触发
//设置标签对鼠标事件穿透
ui->label_help->setAttribute(Qt::WA_TransparentForMouseEvents);
ui->label_done->setAttribute(Qt::WA_TransparentForMouseEvents);
ui->label_web->setAttribute(Qt::WA_TransparentForMouseEvents);
ui->LangL->setAttribute(Qt::WA_TransparentForMouseEvents);
ui->Help->setCursor(QCursor(Qt::PointingHandCursor));
ui->Web->setCursor(QCursor(Qt::PointingHandCursor));
ui->Done->setCursor(QCursor(Qt::PointingHandCursor));
ui->LangB->setCursor(QCursor(Qt::PointingHandCursor));
ui->Help->setGeometry(140, 260, 131, 51);
ui->Help->setStyleSheet("border-image:url(:/picture/Settingpage/dialogbutton.png)");
connect(ui->Help, &QPushButton::pressed, [=](){
ui->Help->setStyleSheet("border-image:url(:/picture/Settingpage/DialogButtonGlow.png)");}
);
connect(ui->Help, &QPushButton::released, [=](){
ui->Help->setStyleSheet("border-image:url(:/picture/Settingpage/dialogbutton.png)"); }
);
ui->Web->setGeometry(460, 260, 131, 51);
ui->Web->setStyleSheet("border-image:url(:/picture/Settingpage/dialogbutton.png)");
connect(ui->Web, &QPushButton::pressed, [=](){
ui->Web->setStyleSheet("border-image:url(:/picture/Settingpage/DialogButtonGlow.png)");}
);
connect(ui->Web, &QPushButton::released, [=](){
ui->Web->setStyleSheet("border-image:url(:/picture/Settingpage/dialogbutton.png)"); }
);
ui->Done->setGeometry(300, 320, 131, 51);
ui->Done->setStyleSheet("border-image:url(:/picture/Settingpage/dialogbutton.png)");
connect(ui->Done, &QPushButton::pressed, [=](){
ui->Done->setStyleSheet("border-image:url(:/picture/Settingpage/DialogButtonGlow.png)");}
);
connect(ui->Done, &QPushButton::released, [=](){
ui->Done->setStyleSheet("border-image:url(:/picture/Settingpage/dialogbutton.png)"); }
);
slider1=new PixmapSlider();
slider1->setParent(this);
slider1->setGeometry(291,140,40,40);
slider1->SetChannelImage(":/picture/Settingpage/slider-track-1.png","");
slider1->SetThumbImage(":/picture/Settingpage/thumb.png",":/picture/Settingpage/thumb.png");
slider1->SetRange(0, 99);
slider1->SetPos(40,false);
QObject::connect(slider1, SIGNAL(valueChanged(int)), this, SLOT(onVolumeValueChanged(int)));
slider2=new PixmapSlider();
slider2->setParent(this);
slider2->setGeometry(291,200,40,40);
slider2->SetChannelImage(":/picture/Settingpage/slider-track-1.png","");
slider2->SetThumbImage(":/picture/Settingpage/thumb.png",":/picture/Settingpage/thumb.png");
slider2->SetRange(0, 99);
slider2->SetPos(40,false);
QObject::connect(slider2, SIGNAL(valueChanged(int)), this, SLOT(onSpinValueChanged(int)));
}
void settingpage::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.drawPixmap(0, 0, QPixmap(":/picture/Settingpage/dialogbox.png"));
}
//打开文档
void settingpage::on_Help_clicked()
{
QFile file(":/doc/Exp.doc");
QTemporaryDir tempDir;
tempDir.setAutoRemove(false);
if (tempDir.isValid()) {
QString tempFile = tempDir.path() + "/Exp.doc";
if (QFile::copy(":/doc/Exp.doc", tempFile)) {
//now extracted to the filesystem
QDesktopServices::openUrl(QUrl::fromLocalFile(tempDir.path() + "/Exp.doc"));
}
}
}
//获取spinbox的值
void settingpage::onSpinValueChanged(int i)
{
int gamma = i;
CGammaRamp GammaRamp;
GammaRamp.SetBrightness(NULL, gamma);
}
//打开网页
void settingpage::on_Web_clicked()
{
QDesktopServices::openUrl(QUrl(QLatin1String("https://gitee.com/guyi2020/bejeweled-2021")));
}
//关闭设置界面
void settingpage::on_Done_clicked()
{
this->setVisible(false);
}
void settingpage::onVolumeValueChanged(int i)
{
SetVolumeLevel(i/2);
}
bool settingpage::SetVolumeLevel(int level)
{
HRESULT hr;
IMMDeviceEnumerator* pDeviceEnumerator = 0;
IMMDevice* pDevice = 0;
IAudioEndpointVolume* pAudioEndpointVolume = 0;
IAudioClient* pAudioClient = 0;
try {
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pDeviceEnumerator);
if (FAILED(hr)) throw "CoCreateInstance";
hr = pDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &pDevice);
if (FAILED(hr)) throw "GetDefaultAudioEndpoint";
hr = pDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL, (void**)&pAudioEndpointVolume);
if (FAILED(hr)) throw "pDevice->Active";
hr = pDevice->Activate(__uuidof(IAudioClient), CLSCTX_ALL, NULL, (void**)&pAudioClient);
if (FAILED(hr)) throw "pDevice->Active";
if (level == -2) {
hr = pAudioEndpointVolume->SetMute(FALSE, NULL);
if (FAILED(hr)) throw "SetMute";
}
else if (level == -1) {
hr = pAudioEndpointVolume->SetMute(TRUE, NULL);
if (FAILED(hr)) throw "SetMute";
}
else {
if (level<0 || level>100) {
hr = E_INVALIDARG;
throw "Invalid Arg";
}
float fVolume;
fVolume = level / 100.0f;
hr = pAudioEndpointVolume->SetMasterVolumeLevelScalar(fVolume, &GUID_NULL);
if (FAILED(hr)) throw "SetMasterVolumeLevelScalar";
pAudioClient->Release();
pAudioEndpointVolume->Release();
pDevice->Release();
pDeviceEnumerator->Release();
return true;
}
}
catch (...) {
if (pAudioClient) pAudioClient->Release();
if (pAudioEndpointVolume) pAudioEndpointVolume->Release();
if (pDevice) pDevice->Release();
if (pDeviceEnumerator) pDeviceEnumerator->Release();
throw;
}
return false;
}
settingpage::~settingpage()
{
delete ui;
}
void settingpage::on_LangB_clicked()
{
if(index==0){
ui->LangB->setStyleSheet("border-image:url(:/picture/Settingpage/Toggle_2.png)");
ui->LangL->setText("简体中文");
ui->label_Bright->setText("亮度");
ui->label_Bright->setGeometry(190,200,101,31);
ui->label_volume->setText("音量");
ui->label_settings->setText("设置");
ui->label_settings->setGeometry(320,30,121,51);
ui->label_help->setText("帮助");
ui->label_done->setText("退出");
ui->label_web->setText("网页");
selectLan(index);
index=1;
return;
}else{
ui->LangB->setStyleSheet("border-image:url(:/picture/Settingpage/Toggle_1.png)");
ui->LangL->setText("English");
ui->label_Bright->setText("Brightness");
ui->label_volume->setText("Volume");
ui->label_settings->setText("Settings");
ui->label_help->setText("Help");
ui->label_done->setText("Done");
ui->label_web->setText("Web");
selectLan(index);
index=0;
return;
}
}