-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
74 lines (57 loc) · 2.15 KB
/
Copy pathMainWindow.cpp
File metadata and controls
74 lines (57 loc) · 2.15 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
#include "MainWindow.h"
#include "backend.h"
#include <QWidget>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("GPU Switcher");
setFixedSize(320, 270);
QWidget *central = new QWidget(this);
setCentralWidget(central);
auto *layout = new QVBoxLayout(central);
QLabel *title = new QLabel("<b>Current Mode</b>");
layout->addWidget(title);
modeLabel = new QLabel("🟢 Integrated");
layout->addWidget(modeLabel);
integrated = new QRadioButton("Integrated");
hybrid = new QRadioButton("Hybrid");
ultimate = new QRadioButton("Ultimate");
integrated->setChecked(true);
layout->addWidget(integrated);
layout->addWidget(hybrid);
layout->addWidget(ultimate);
applyButton = new QPushButton("Apply");
layout->addWidget(applyButton);
statusLabel = new QLabel("✓ dGPU Powered Off");
layout->addWidget(statusLabel);
connect(applyButton,
&QPushButton::clicked,
this,
&MainWindow::applyClicked);
refreshStatus();
}
void MainWindow::refreshStatus()
{
QString mode = Backend::currentMode();
if(mode=="Integrated"){integrated->setChecked(true);modeLabel->setText("🟢 Integrated");statusLabel->setText("✓ dGPU Powered Off");}
else if(mode=="Hybrid"){hybrid->setChecked(true);modeLabel->setText("🟡 Hybrid");statusLabel->setText("✓ dGPU Available");}
else if(mode=="Ultimate"){ultimate->setChecked(true);modeLabel->setText("🔴 Ultimate");statusLabel->setText("✓ dGPU Active");}
else {modeLabel->setText("⚪ Unknown");statusLabel->setText("Unable to detect GPU mode");}
}
void MainWindow::applyClicked()
{
QString mode;
if(integrated->isChecked()) mode="Integrated";
else if(hybrid->isChecked()) mode="Hybrid";
else mode="AsusMuxDgpu";
if(Backend::switchMode(mode))
QMessageBox::information(this,"GPU Switcher","GPU mode changed successfully.\n\nPlease reboot.");
else
QMessageBox::critical(this,"GPU Switcher","Failed to change GPU mode.");
refreshStatus();
}