Use less pointers in frontend

This commit is contained in:
SimoneN64
2024-09-24 13:05:10 +02:00
parent 60870165d5
commit bd98a3b4ee
16 changed files with 270 additions and 261 deletions

View File

@@ -1,6 +1,4 @@
#include <AudioSettings.hpp>
#include <QLabel>
#include <QVBoxLayout>
AudioSettings::AudioSettings(nlohmann::json &settings) : settings(settings), QWidget(nullptr) {
lockChannels->setChecked(JSONGetField<bool>(settings, "audio", "lock"));
@@ -9,7 +7,7 @@ AudioSettings::AudioSettings(nlohmann::json &settings) : settings(settings), QWi
volumeL->setRange(0, 100);
volumeR->setRange(0, 100);
connect(lockChannels, &QCheckBox::stateChanged, this, [&]() {
connect(lockChannels.get(), &QCheckBox::stateChanged, this, [&]() {
JSONSetField(settings, "audio", "lock", lockChannels->isChecked());
if (lockChannels->isChecked()) {
volumeR->setValue(volumeL->value());
@@ -18,7 +16,7 @@ AudioSettings::AudioSettings(nlohmann::json &settings) : settings(settings), QWi
emit modified();
});
connect(volumeL, &QSlider::valueChanged, this, [&]() {
connect(volumeL.get(), &QSlider::valueChanged, this, [&]() {
JSONSetField(settings, "audio", "volumeL", float(volumeL->value()) / 100.f);
if (lockChannels->isChecked()) {
volumeR->setValue(volumeL->value());
@@ -27,26 +25,20 @@ AudioSettings::AudioSettings(nlohmann::json &settings) : settings(settings), QWi
emit modified();
});
connect(volumeR, &QSlider::valueChanged, this, [&]() {
connect(volumeR.get(), &QSlider::valueChanged, this, [&]() {
if (!lockChannels->isChecked()) {
JSONSetField(settings, "audio", "volumeR", float(volumeR->value()) / 100.f);
}
emit modified();
});
auto labelLock = new QLabel("Lock channels:");
auto labelL = new QLabel("Volume L");
auto labelR = new QLabel("Volume R");
auto mainLayout = new QVBoxLayout;
auto volLayout = new QHBoxLayout;
mainLayout->addWidget(labelLock);
mainLayout->addWidget(lockChannels);
volLayout->addWidget(labelL);
volLayout->addWidget(volumeL);
volLayout->addWidget(labelR);
volLayout->addWidget(volumeR);
mainLayout->addLayout(volLayout);
mainLayout->addWidget(labelLock.get());
mainLayout->addWidget(lockChannels.get());
volLayout->addWidget(labelL.get());
volLayout->addWidget(volumeL.get());
volLayout->addWidget(labelR.get());
volLayout->addWidget(volumeR.get());
mainLayout->addLayout(volLayout.get());
mainLayout->addStretch();
setLayout(mainLayout);
setLayout(mainLayout.get());
}

View File

@@ -3,12 +3,20 @@
#include <QCheckBox>
#include <QSlider>
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
class AudioSettings : public QWidget {
QCheckBox *lockChannels = new QCheckBox;
std::unique_ptr<QCheckBox> lockChannels = std::make_unique<QCheckBox>();
std::unique_ptr<QLabel> labelLock = std::make_unique<QLabel>("Lock channels:");
std::unique_ptr<QLabel> labelL = std::make_unique<QLabel>("Volume L");
std::unique_ptr<QLabel> labelR = std::make_unique<QLabel>("Volume R");
std::unique_ptr<QVBoxLayout> mainLayout = std::make_unique<QVBoxLayout>();
std::unique_ptr<QHBoxLayout> volLayout = std::make_unique<QHBoxLayout>();
Q_OBJECT
public:
QSlider *volumeL = new QSlider(Qt::Horizontal), *volumeR = new QSlider(Qt::Horizontal);
std::unique_ptr<QSlider> volumeL = std::make_unique<QSlider>(Qt::Horizontal),
volumeR = std::make_unique<QSlider>(Qt::Horizontal);
AudioSettings(nlohmann::json &);
nlohmann::json &settings;
Q_SIGNALS:

View File

@@ -78,7 +78,8 @@ add_executable(kaizen-qt
InputSettings.hpp
InputSettings.cpp
Debugger.hpp
Debugger.cpp)
Debugger.cpp
CodeModel.hpp)
include(CheckCCompilerFlag)

View File

@@ -1,7 +1,5 @@
#include <CPUSettings.hpp>
#include <JSONUtils.hpp>
#include <QLabel>
#include <QVBoxLayout>
#include <log.hpp>
CPUSettings::CPUSettings(nlohmann::json &settings) : settings(settings), QWidget(nullptr) {
@@ -14,7 +12,7 @@ CPUSettings::CPUSettings(nlohmann::json &settings) : settings(settings), QWidget
cpuTypes->setCurrentIndex(0);
}
connect(cpuTypes, &QComboBox::currentIndexChanged, this, [&]() {
connect(cpuTypes.get(), &QComboBox::currentIndexChanged, this, [&]() {
if (cpuTypes->currentIndex() == 0) {
JSONSetField(settings, "cpu", "type", "interpreter");
//} else if (cpuTypes->currentIndex() == 1) {
@@ -26,11 +24,8 @@ CPUSettings::CPUSettings(nlohmann::json &settings) : settings(settings), QWidget
emit modified();
});
auto label = new QLabel("CPU type:");
auto mainLayout = new QVBoxLayout;
mainLayout->addWidget(label);
mainLayout->addWidget(cpuTypes);
mainLayout->addWidget(label.get());
mainLayout->addWidget(cpuTypes.get());
mainLayout->addStretch();
setLayout(mainLayout);
setLayout(mainLayout.get());
}

View File

@@ -2,9 +2,13 @@
#include <JSONUtils.hpp>
#include <QComboBox>
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
class CPUSettings : public QWidget {
QComboBox *cpuTypes = new QComboBox;
std::unique_ptr<QComboBox> cpuTypes = std::make_unique<QComboBox>();
std::unique_ptr<QLabel> label = std::make_unique<QLabel>("CPU type:");
std::unique_ptr<QVBoxLayout> mainLayout = std::make_unique<QVBoxLayout>();
Q_OBJECT
public:
CPUSettings(nlohmann::json &);

View File

@@ -0,0 +1,12 @@
#pragma once
#include <QAbstractTableModel>
class CodeModel final : public QAbstractTableModel {
Q_OBJECT
public:
~CodeModel() override {}
explicit CodeModel(QObject *parent = nullptr) {}
int rowCount(const QModelIndex &parent = QModelIndex()) const override { return 1; }
int columnCount(const QModelIndex &parent = QModelIndex()) const override { return 2; }
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override { return {}; }
};

View File

@@ -1,29 +1,23 @@
#include <Debugger.hpp>
#include <QGuiApplication>
Debugger::Debugger() : QWidget(nullptr) {
disassembly = new QDockWidget;
disassembly->setWindowTitle("Disassembly");
disassembly->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
codeView = new QTreeView(disassembly);
codeView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
codeView->setHeaderHidden(true);
cpuState = new QDockWidget;
codeView->setModel(codeModel.get());
cpuState->setWindowTitle("Registers");
cpuState->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
registers = new QTreeView(cpuState);
registers->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
horLayout = new QHBoxLayout;
horLayout->addWidget(disassembly);
horLayout->addWidget(cpuState);
horLayout->addWidget(disassembly.get());
horLayout->addWidget(cpuState.get());
verLayout = new QVBoxLayout;
verLayout->addLayout(horLayout);
verLayout->addLayout(horLayout.get());
setLayout(verLayout);
setLayout(verLayout.get());
connect(codeView, &QTreeView::activated, this, [&](QModelIndex index) {
connect(codeView.get(), &QTreeView::activated, this, [&](QModelIndex index) {
});
}

View File

@@ -4,12 +4,16 @@
#include <QTreeView>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <CodeModel.hpp>
class Debugger : public QWidget {
QDockWidget *disassembly{}, *cpuState{};
QTreeView *codeView{}, *registers{};
QHBoxLayout *horLayout{};
QVBoxLayout *verLayout{};
std::unique_ptr<QDockWidget> disassembly = std::make_unique<QDockWidget>(),
cpuState = std::make_unique<QDockWidget>();
std::unique_ptr<QTreeView> codeView = std::make_unique<QTreeView>(disassembly.get()),
registers = std::make_unique<QTreeView>(cpuState.get());
std::unique_ptr<QHBoxLayout> horLayout = std::make_unique<QHBoxLayout>();
std::unique_ptr<QVBoxLayout> verLayout = std::make_unique<QVBoxLayout>();
std::unique_ptr<CodeModel> codeModel = std::make_unique<CodeModel>();
public:
Debugger();

View File

@@ -16,7 +16,7 @@ public:
[[noreturn]] void run() noexcept override;
SDL_Gamepad *controller = nullptr;
SDL_Gamepad *controller{};
ParallelRDP parallel;
n64::Core core;
SettingsWindow &settings;

View File

@@ -1,68 +1,66 @@
#include <InputSettings.hpp>
#include <QKeyEvent>
#include <QVBoxLayout>
#include <log.hpp>
InputSettings::InputSettings(nlohmann::json &settings) : settings(settings), QWidget(nullptr) {
n64_button_labels[0] = new QLabel("A");
n64_button_labels[1] = new QLabel("B");
n64_button_labels[2] = new QLabel("Z");
n64_button_labels[3] = new QLabel("Start");
n64_button_labels[4] = new QLabel("L");
n64_button_labels[5] = new QLabel("R");
n64_button_labels[6] = new QLabel("Dpad Up");
n64_button_labels[7] = new QLabel("Dpad Down");
n64_button_labels[8] = new QLabel("Dpad Left");
n64_button_labels[9] = new QLabel("Dpad Right");
n64_button_labels[10] = new QLabel("C Up");
n64_button_labels[11] = new QLabel("C Down");
n64_button_labels[12] = new QLabel("C Left");
n64_button_labels[13] = new QLabel("C Right");
n64_button_labels[14] = new QLabel("Analog Up");
n64_button_labels[15] = new QLabel("Analog Down");
n64_button_labels[16] = new QLabel("Analog Left");
n64_button_labels[17] = new QLabel("Analog Right");
n64_button_labels[0] = std::make_unique<QLabel>("A");
n64_button_labels[1] = std::make_unique<QLabel>("B");
n64_button_labels[2] = std::make_unique<QLabel>("Z");
n64_button_labels[3] = std::make_unique<QLabel>("Start");
n64_button_labels[4] = std::make_unique<QLabel>("L");
n64_button_labels[5] = std::make_unique<QLabel>("R");
n64_button_labels[6] = std::make_unique<QLabel>("Dpad Up");
n64_button_labels[7] = std::make_unique<QLabel>("Dpad Down");
n64_button_labels[8] = std::make_unique<QLabel>("Dpad Left");
n64_button_labels[9] = std::make_unique<QLabel>("Dpad Right");
n64_button_labels[10] = std::make_unique<QLabel>("C Up");
n64_button_labels[11] = std::make_unique<QLabel>("C Down");
n64_button_labels[12] = std::make_unique<QLabel>("C Left");
n64_button_labels[13] = std::make_unique<QLabel>("C Right");
n64_button_labels[14] = std::make_unique<QLabel>("Analog Up");
n64_button_labels[15] = std::make_unique<QLabel>("Analog Down");
n64_button_labels[16] = std::make_unique<QLabel>("Analog Left");
n64_button_labels[17] = std::make_unique<QLabel>("Analog Right");
auto str = JSONGetField<std::string>(settings, "input", "A");
kb_buttons[0] = new QPushButton(str.c_str());
kb_buttons[0] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "B");
kb_buttons[1] = new QPushButton(str.c_str());
kb_buttons[1] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "Z");
kb_buttons[2] = new QPushButton(str.c_str());
kb_buttons[2] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "Start");
kb_buttons[3] = new QPushButton(str.c_str());
kb_buttons[3] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "L");
kb_buttons[4] = new QPushButton(str.c_str());
kb_buttons[4] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "R");
kb_buttons[5] = new QPushButton(str.c_str());
kb_buttons[5] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "Dpad Up");
kb_buttons[6] = new QPushButton(str.c_str());
kb_buttons[6] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "Dpad Down");
kb_buttons[7] = new QPushButton(str.c_str());
kb_buttons[7] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "Dpad Left");
kb_buttons[8] = new QPushButton(str.c_str());
kb_buttons[8] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "Dpad Right");
kb_buttons[9] = new QPushButton(str.c_str());
kb_buttons[9] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "C Up");
kb_buttons[10] = new QPushButton(str.c_str());
kb_buttons[10] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "C Down");
kb_buttons[11] = new QPushButton(str.c_str());
kb_buttons[11] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "C Left");
kb_buttons[12] = new QPushButton(str.c_str());
kb_buttons[12] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "C Right");
kb_buttons[13] = new QPushButton(str.c_str());
kb_buttons[13] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "Analog Up");
kb_buttons[14] = new QPushButton(str.c_str());
kb_buttons[14] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "Analog Down");
kb_buttons[15] = new QPushButton(str.c_str());
kb_buttons[15] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "Analog Left");
kb_buttons[16] = new QPushButton(str.c_str());
kb_buttons[16] = std::make_unique<QPushButton>(str.c_str());
str = JSONGetField<std::string>(settings, "input", "Analog Right");
kb_buttons[17] = new QPushButton(str.c_str());
kb_buttons[17] = std::make_unique<QPushButton>(str.c_str());
for (int i = 0; i < 18; i++) {
connect(kb_buttons[i], &QPushButton::pressed, this, [&, i]() {
for (auto kb_button : kb_buttons) {
connect(kb_buttons[i].get(), &QPushButton::pressed, this, [&, i]() {
for (auto& kb_button : kb_buttons) {
kb_button->setEnabled(false);
}
grabKeyboard();
@@ -71,64 +69,53 @@ InputSettings::InputSettings(nlohmann::json &settings) : settings(settings), QWi
});
}
auto AB = new QHBoxLayout;
auto ZStart = new QHBoxLayout;
auto LR = new QHBoxLayout;
auto DupDdown = new QHBoxLayout;
auto DleftDright = new QHBoxLayout;
auto CupCdown = new QHBoxLayout;
auto CleftCright = new QHBoxLayout;
auto AupAdown = new QHBoxLayout;
auto AleftAright = new QHBoxLayout;
auto mainLayout = new QVBoxLayout;
AB->addWidget(n64_button_labels[0]);
AB->addWidget(kb_buttons[0]);
AB->addWidget(n64_button_labels[1]);
AB->addWidget(kb_buttons[1]);
mainLayout->addLayout(AB);
ZStart->addWidget(n64_button_labels[2]);
ZStart->addWidget(kb_buttons[2]);
ZStart->addWidget(n64_button_labels[3]);
ZStart->addWidget(kb_buttons[3]);
mainLayout->addLayout(ZStart);
LR->addWidget(n64_button_labels[4]);
LR->addWidget(kb_buttons[4]);
LR->addWidget(n64_button_labels[5]);
LR->addWidget(kb_buttons[5]);
mainLayout->addLayout(LR);
DupDdown->addWidget(n64_button_labels[6]);
DupDdown->addWidget(kb_buttons[6]);
DupDdown->addWidget(n64_button_labels[7]);
DupDdown->addWidget(kb_buttons[7]);
mainLayout->addLayout(DupDdown);
DleftDright->addWidget(n64_button_labels[8]);
DleftDright->addWidget(kb_buttons[8]);
DleftDright->addWidget(n64_button_labels[9]);
DleftDright->addWidget(kb_buttons[9]);
mainLayout->addLayout(DleftDright);
CupCdown->addWidget(n64_button_labels[10]);
CupCdown->addWidget(kb_buttons[10]);
CupCdown->addWidget(n64_button_labels[11]);
CupCdown->addWidget(kb_buttons[11]);
mainLayout->addLayout(CupCdown);
CleftCright->addWidget(n64_button_labels[12]);
CleftCright->addWidget(kb_buttons[12]);
CleftCright->addWidget(n64_button_labels[13]);
CleftCright->addWidget(kb_buttons[13]);
mainLayout->addLayout(CleftCright);
AupAdown->addWidget(n64_button_labels[14]);
AupAdown->addWidget(kb_buttons[14]);
AupAdown->addWidget(n64_button_labels[15]);
AupAdown->addWidget(kb_buttons[15]);
mainLayout->addLayout(AupAdown);
AleftAright->addWidget(n64_button_labels[16]);
AleftAright->addWidget(kb_buttons[16]);
AleftAright->addWidget(n64_button_labels[17]);
AleftAright->addWidget(kb_buttons[17]);
mainLayout->addLayout(AleftAright);
AB->addWidget(n64_button_labels[0].get());
AB->addWidget(kb_buttons[0].get());
AB->addWidget(n64_button_labels[1].get());
AB->addWidget(kb_buttons[1].get());
mainLayout->addLayout(AB.get());
ZStart->addWidget(n64_button_labels[2].get());
ZStart->addWidget(kb_buttons[2].get());
ZStart->addWidget(n64_button_labels[3].get());
ZStart->addWidget(kb_buttons[3].get());
mainLayout->addLayout(ZStart.get());
LR->addWidget(n64_button_labels[4].get());
LR->addWidget(kb_buttons[4].get());
LR->addWidget(n64_button_labels[5].get());
LR->addWidget(kb_buttons[5].get());
mainLayout->addLayout(LR.get());
DupDdown->addWidget(n64_button_labels[6].get());
DupDdown->addWidget(kb_buttons[6].get());
DupDdown->addWidget(n64_button_labels[7].get());
DupDdown->addWidget(kb_buttons[7].get());
mainLayout->addLayout(DupDdown.get());
DleftDright->addWidget(n64_button_labels[8].get());
DleftDright->addWidget(kb_buttons[8].get());
DleftDright->addWidget(n64_button_labels[9].get());
DleftDright->addWidget(kb_buttons[9].get());
mainLayout->addLayout(DleftDright.get());
CupCdown->addWidget(n64_button_labels[10].get());
CupCdown->addWidget(kb_buttons[10].get());
CupCdown->addWidget(n64_button_labels[11].get());
CupCdown->addWidget(kb_buttons[11].get());
mainLayout->addLayout(CupCdown.get());
CleftCright->addWidget(n64_button_labels[12].get());
CleftCright->addWidget(kb_buttons[12].get());
CleftCright->addWidget(n64_button_labels[13].get());
CleftCright->addWidget(kb_buttons[13].get());
mainLayout->addLayout(CleftCright.get());
AupAdown->addWidget(n64_button_labels[14].get());
AupAdown->addWidget(kb_buttons[14].get());
AupAdown->addWidget(n64_button_labels[15].get());
AupAdown->addWidget(kb_buttons[15].get());
mainLayout->addLayout(AupAdown.get());
AleftAright->addWidget(n64_button_labels[16].get());
AleftAright->addWidget(kb_buttons[16].get());
AleftAright->addWidget(n64_button_labels[17].get());
AleftAright->addWidget(kb_buttons[17].get());
mainLayout->addLayout(AleftAright.get());
mainLayout->addStretch();
setLayout(mainLayout);
setLayout(mainLayout.get());
}
@@ -140,7 +127,7 @@ void InputSettings::keyPressEvent(QKeyEvent *e) {
kb_buttons[which_grabbing]->setText(k);
grabbing = false;
which_grabbing = -1;
for (auto kb_button : kb_buttons) {
for (auto& kb_button : kb_buttons) {
kb_button->setEnabled(true);
}
releaseKeyboard();

View File

@@ -3,12 +3,25 @@
#include <QLabel>
#include <QPushButton>
#include <QWidget>
#include <QKeyEvent>
#include <QVBoxLayout>
class InputSettings : public QWidget {
bool grabbing = false;
int which_grabbing = -1;
QPushButton *kb_buttons[18];
QLabel *n64_button_labels[18];
std::unique_ptr<QHBoxLayout> AB = std::make_unique<QHBoxLayout>();
std::unique_ptr<QHBoxLayout> ZStart = std::make_unique<QHBoxLayout>();
std::unique_ptr<QHBoxLayout> LR = std::make_unique<QHBoxLayout>();
std::unique_ptr<QHBoxLayout> DupDdown = std::make_unique<QHBoxLayout>();
std::unique_ptr<QHBoxLayout> DleftDright = std::make_unique<QHBoxLayout>();
std::unique_ptr<QHBoxLayout> CupCdown = std::make_unique<QHBoxLayout>();
std::unique_ptr<QHBoxLayout> CleftCright = std::make_unique<QHBoxLayout>();
std::unique_ptr<QHBoxLayout> AupAdown = std::make_unique<QHBoxLayout>();
std::unique_ptr<QHBoxLayout> AleftAright = std::make_unique<QHBoxLayout>();
std::unique_ptr<QVBoxLayout> mainLayout = std::make_unique<QVBoxLayout>();
std::array<std::unique_ptr<QPushButton>, 18> kb_buttons;
std::array<std::unique_ptr<QLabel>, 18> n64_button_labels;
Q_OBJECT
public:
InputSettings(nlohmann::json &);

View File

@@ -1,74 +1,67 @@
#include <MainWindow.hpp>
#include <QFileDialog>
#include <QKeyEvent>
#include <QMessageBox>
#include <QSlider>
#include <QMenu>
#include <QMenuBar>
#include <QStatusBar>
MainWindow::MainWindow() noexcept {
if (objectName().isEmpty())
setObjectName("MainWindow");
resize(800, 646);
actionOpenDebuggerWindow = new QAction(this);
actionOpenDebuggerWindow = std::make_unique<QAction>(this);
actionOpenDebuggerWindow->setObjectName("actionOpenDebuggerWindow");
actionAbout = new QAction(this);
actionAbout = std::make_unique<QAction>(this);
actionAbout->setObjectName("actionAbout");
actionOpen = new QAction(this);
actionOpen = std::make_unique<QAction>(this);
actionOpen->setObjectName("actionOpen");
actionExit = new QAction(this);
actionExit = std::make_unique<QAction>(this);
actionExit->setObjectName("actionExit");
actionPause = new QAction(this);
actionPause = std::make_unique<QAction>(this);
actionPause->setObjectName("actionPause");
actionReset = new QAction(this);
actionReset = std::make_unique<QAction>(this);
actionReset->setObjectName("actionReset");
actionStop = new QAction(this);
actionStop = std::make_unique<QAction>(this);
actionStop->setObjectName("actionStop");
actionSettings = new QAction(this);
actionSettings = std::make_unique<QAction>(this);
actionSettings->setObjectName("actionSettings");
centralwidget = new QWidget(this);
centralwidget = std::make_unique<QWidget>(this);
centralwidget->setObjectName("centralwidget");
verticalLayout = new QVBoxLayout;
verticalLayout = std::make_unique<QVBoxLayout>();
verticalLayout->setSpacing(0);
verticalLayout->setObjectName("verticalLayout");
verticalLayout->setContentsMargins(0, 0, 0, 0);
vulkanWidget = new RenderWidget;
vulkanWidget = std::make_unique<RenderWidget>();
vulkanWidget->setObjectName("vulkanWidget");
verticalLayout->addWidget(vulkanWidget);
verticalLayout->addWidget(vulkanWidget.get());
centralwidget->setLayout(verticalLayout);
centralwidget->setLayout(verticalLayout.get());
setCentralWidget(centralwidget);
menubar = new QMenuBar(this);
setCentralWidget(centralwidget.get());
menubar = std::make_unique<QMenuBar>(this);
menubar->setObjectName("menubar");
menubar->setGeometry(QRect(0, 0, 800, 22));
menuFile = new QMenu(menubar);
menuFile = std::make_unique<QMenu>(menubar.get());
menuFile->setObjectName("menuFile");
menuEmulation = new QMenu(menubar);
menuEmulation = std::make_unique<QMenu>(menubar.get());
menuEmulation->setObjectName("menuEmulation");
menuTools = new QMenu(menubar);
menuTools = std::make_unique<QMenu>(menubar.get());
menuTools->setObjectName("menuTools");
menuAbout = new QMenu(menubar);
menuAbout = std::make_unique<QMenu>(menubar.get());
menuAbout->setObjectName("menuAbout");
setMenuBar(menubar);
statusbar = new QStatusBar(this);
setMenuBar(menubar.get());
statusbar = std::make_unique<QStatusBar>(this);
statusbar->setObjectName("statusbar");
setStatusBar(statusbar);
setStatusBar(statusbar.get());
menubar->addAction(menuFile->menuAction());
menubar->addAction(menuEmulation->menuAction());
menubar->addAction(menuTools->menuAction());
menubar->addAction(menuAbout->menuAction());
menuFile->addAction(actionOpen);
menuFile->addAction(actionExit);
menuEmulation->addAction(actionSettings);
menuEmulation->addAction(actionPause);
menuEmulation->addAction(actionReset);
menuEmulation->addAction(actionStop);
menuTools->addAction(actionOpenDebuggerWindow);
menuAbout->addAction(actionAbout);
menuFile->addAction(actionOpen.get());
menuFile->addAction(actionExit.get());
menuEmulation->addAction(actionSettings.get());
menuEmulation->addAction(actionPause.get());
menuEmulation->addAction(actionReset.get());
menuEmulation->addAction(actionStop.get());
menuTools->addAction(actionOpenDebuggerWindow.get());
menuAbout->addAction(actionAbout.get());
Retranslate();
@@ -109,7 +102,7 @@ void MainWindow::Retranslate() {
} // retranslateUi
void MainWindow::ConnectSignalsToSlots() noexcept {
connect(actionOpen, &QAction::triggered, this, [this]() {
connect(actionOpen.get(), &QAction::triggered, this, [this]() {
QString file_name = QFileDialog::getOpenFileName(
this, "Nintendo 64 executable", QString(),
"All supported types (*.zip *.ZIP *.7z *.7Z *.rar *.RAR *.tar *.TAR *.n64 *.N64 *.v64 *.V64 *.z64 *.Z64)");
@@ -120,13 +113,13 @@ void MainWindow::ConnectSignalsToSlots() noexcept {
}
});
connect(actionExit, &QAction::triggered, this, [this]() { emit Exit(); });
connect(actionExit.get(), &QAction::triggered, this, [this]() { emit Exit(); });
connect(this, &MainWindow::destroyed, this, [this]() { emit Exit(); });
connect(actionReset, &QAction::triggered, this, [this]() { emit Reset(); });
connect(actionReset.get(), &QAction::triggered, this, [this]() { emit Reset(); });
connect(actionStop, &QAction::triggered, this, [this]() {
connect(actionStop.get(), &QAction::triggered, this, [this]() {
vulkanWidget->hide();
actionPause->setDisabled(true);
actionReset->setDisabled(true);
@@ -134,13 +127,13 @@ void MainWindow::ConnectSignalsToSlots() noexcept {
emit Stop();
});
connect(actionPause, &QAction::triggered, this, [this]() {
connect(actionPause.get(), &QAction::triggered, this, [this]() {
textPauseToggle = !textPauseToggle;
actionPause->setText(textPauseToggle ? "Resume" : "Pause");
emit Pause();
});
connect(actionAbout, &QAction::triggered, this, [this]() {
connect(actionAbout.get(), &QAction::triggered, this, [this]() {
QMessageBox::about(this, tr("About Kaizen"),
tr("Kaizen is a Nintendo 64 emulator that strives to offer a friendly user "
"experience and great compatibility.\n"
@@ -148,6 +141,6 @@ void MainWindow::ConnectSignalsToSlots() noexcept {
"Nintendo 64 is a registered trademarks of Nintendo Co., Ltd."));
});
connect(actionSettings, &QAction::triggered, this, [this]() { emit OpenSettings(); });
connect(actionOpenDebuggerWindow, &QAction::triggered, this, [this]() { emit OpenDebugger(); });
connect(actionSettings.get(), &QAction::triggered, this, [this]() { emit OpenSettings(); });
connect(actionOpenDebuggerWindow.get(), &QAction::triggered, this, [this]() { emit OpenDebugger(); });
}

View File

@@ -2,6 +2,13 @@
#include <QApplication>
#include <QMainWindow>
#include <QVBoxLayout>
#include <QFileDialog>
#include <QKeyEvent>
#include <QMessageBox>
#include <QSlider>
#include <QMenu>
#include <QMenuBar>
#include <QStatusBar>
#include <RenderWidget.hpp>
#include <Debugger.hpp>
@@ -11,23 +18,23 @@ class MainWindow : public QMainWindow {
public:
MainWindow() noexcept;
QAction *actionOpenDebuggerWindow;
QAction *actionAbout;
QAction *actionOpen;
QAction *actionExit;
QAction *actionPause;
QAction *actionReset;
QAction *actionStop;
QAction *actionSettings;
QWidget *centralwidget;
QVBoxLayout *verticalLayout;
RenderWidget *vulkanWidget;
QMenuBar *menubar;
QMenu *menuFile;
QMenu *menuEmulation;
QMenu *menuTools;
QMenu *menuAbout;
QStatusBar *statusbar;
std::unique_ptr<QAction> actionOpenDebuggerWindow{};
std::unique_ptr<QAction> actionAbout{};
std::unique_ptr<QAction> actionOpen{};
std::unique_ptr<QAction> actionExit{};
std::unique_ptr<QAction> actionPause{};
std::unique_ptr<QAction> actionReset{};
std::unique_ptr<QAction> actionStop{};
std::unique_ptr<QAction> actionSettings{};
std::unique_ptr<QWidget> centralwidget{};
std::unique_ptr<QVBoxLayout> verticalLayout{};
std::unique_ptr<RenderWidget> vulkanWidget{};
std::unique_ptr<QMenuBar> menubar{};
std::unique_ptr<QMenu> menuFile{};
std::unique_ptr<QMenu> menuEmulation{};
std::unique_ptr<QMenu> menuTools{};
std::unique_ptr<QMenu> menuAbout{};
std::unique_ptr<QStatusBar> statusbar{};
private:
void Retranslate();

View File

@@ -29,18 +29,18 @@ struct QtInstanceFactory : Vulkan::InstanceFactory {
class QtParallelRdpWindowInfo : public ParallelRDP::WindowInfo {
public:
explicit QtParallelRdpWindowInfo(QWindow *window) : window(window) {}
explicit QtParallelRdpWindowInfo(QWindow* window) : window(window) {}
CoordinatePair get_window_size() override {
return CoordinatePair{static_cast<float>(window->width()), static_cast<float>(window->height())};
}
private:
QWindow *window;
std::shared_ptr<QWindow> window{};
};
class QtWSIPlatform final : public Vulkan::WSIPlatform {
public:
explicit QtWSIPlatform(QWindow *window) : window(window) {}
explicit QtWSIPlatform(QWindow* window) : window(window) {}
std::vector<const char *> get_instance_extensions() override {
auto vec = std::vector<const char *>();
@@ -53,7 +53,7 @@ public:
}
VkSurfaceKHR create_surface(VkInstance, VkPhysicalDevice) override {
return QVulkanInstance::surfaceForWindow(window);
return QVulkanInstance::surfaceForWindow(window.get());
}
void destroy_surface(VkInstance, VkSurfaceKHR) override {}
@@ -73,7 +73,7 @@ public:
VkApplicationInfo appInfo{.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .apiVersion = VK_API_VERSION_1_3};
QWindow *window;
std::shared_ptr<QWindow> window{};
};
class RenderWidget : public QWidget {

View File

@@ -1,7 +1,3 @@
#include <QButtonGroup>
#include <QFileDialog>
#include <QGroupBox>
#include <QVBoxLayout>
#include <SettingsWindow.hpp>
#include <fmt/core.h>
@@ -18,47 +14,43 @@ SettingsWindow::SettingsWindow() : QWidget(nullptr) {
resize(500, 400);
setWindowTitle("Settings");
cpuSettings = new CPUSettings(settings);
audioSettings = new AudioSettings(settings);
inputSettings = new InputSettings(settings);
generalSettings = new QWidget;
cpuSettings = std::make_unique<CPUSettings>(settings);
audioSettings = std::make_unique<AudioSettings>(settings);
inputSettings = std::make_unique<InputSettings>(settings);
generalSettings = std::make_unique<QWidget>();
keyMap = inputSettings->GetMappedKeys();
folderLabelPrefix = new QLabel("Save files' path: ");
folderLabel = new QLabel(fmt::format("{}", savePath).c_str());
folderLabel = std::make_unique<QLabel>(fmt::format("{}", savePath).c_str());
connect(folderBtn, &QPushButton::pressed, this, [&]() {
connect(folderBtn.get(), &QPushButton::pressed, this, [&]() {
savePath = QFileDialog::getExistingDirectory(this, tr("Select directory")).toStdString();
folderLabel->setText(fmt::format("{}", savePath).c_str());
JSONSetField(settings, "general", "savePath", savePath);
apply->setEnabled(true);
});
auto generalLayout = new QHBoxLayout;
auto generalLayoutV = new QVBoxLayout;
generalLayout->addWidget(folderLabelPrefix);
generalLayout->addWidget(folderLabel);
generalLayout->addWidget(folderLabelPrefix.get());
generalLayout->addWidget(folderLabel.get());
generalLayout->addStretch();
generalLayout->addWidget(folderBtn);
generalLayoutV->addLayout(generalLayout);
generalLayout->addWidget(folderBtn.get());
generalLayoutV->addLayout(generalLayout.get());
generalLayoutV->addStretch();
generalSettings->setLayout(generalLayoutV);
generalSettings->setLayout(generalLayoutV.get());
auto *tabs = new QTabWidget;
tabs->addTab(generalSettings, tr("General"));
tabs->addTab(cpuSettings, tr("CPU"));
tabs->addTab(audioSettings, tr("Audio"));
tabs->addTab(inputSettings, tr("Input"));
tabs->addTab(generalSettings.get(), tr("General"));
tabs->addTab(cpuSettings.get(), tr("CPU"));
tabs->addTab(audioSettings.get(), tr("Audio"));
tabs->addTab(inputSettings.get(), tr("Input"));
apply->setEnabled(false);
connect(cpuSettings, &CPUSettings::modified, this, [&]() { apply->setEnabled(true); });
connect(cpuSettings.get(), &CPUSettings::modified, this, [&]() { apply->setEnabled(true); });
connect(audioSettings, &AudioSettings::modified, this, [&]() { apply->setEnabled(true); });
connect(audioSettings.get(), &AudioSettings::modified, this, [&]() { apply->setEnabled(true); });
connect(inputSettings, &InputSettings::modified, this, [&]() { apply->setEnabled(true); });
connect(inputSettings.get(), &InputSettings::modified, this, [&]() { apply->setEnabled(true); });
connect(apply, &QPushButton::pressed, this, [&]() {
connect(apply.get(), &QPushButton::pressed, this, [&]() {
auto newMap = inputSettings->GetMappedKeys();
if (!std::equal(keyMap.begin(), keyMap.end(), newMap.begin(), newMap.end())) {
keyMap = newMap;
@@ -70,13 +62,11 @@ SettingsWindow::SettingsWindow() : QWidget(nullptr) {
file.close();
});
connect(cancel, &QPushButton::pressed, this, &QWidget::hide);
connect(cancel.get(), &QPushButton::pressed, this, &QWidget::hide);
QVBoxLayout *mainLayout = new QVBoxLayout;
QHBoxLayout *buttonsLayout = new QHBoxLayout;
buttonsLayout->addWidget(apply);
buttonsLayout->addWidget(cancel);
mainLayout->addWidget(tabs);
mainLayout->addLayout(buttonsLayout);
setLayout(mainLayout);
buttonsLayout->addWidget(apply.get());
buttonsLayout->addWidget(cancel.get());
mainLayout->addWidget(tabs.get());
mainLayout->addLayout(buttonsLayout.get());
setLayout(mainLayout.get());
}

View File

@@ -6,14 +6,23 @@
#include <QPushButton>
#include <QTabWidget>
#include <QWidget>
#include <QButtonGroup>
#include <QFileDialog>
#include <QGroupBox>
#include <QVBoxLayout>
class SettingsWindow : public QWidget {
QPushButton *cancel = new QPushButton("Cancel");
QPushButton *apply = new QPushButton("Apply");
QFileIconProvider *iconProv = new QFileIconProvider;
QPushButton *folderBtn = new QPushButton(iconProv->icon(QFileIconProvider::Folder), "");
QLabel *folderLabelPrefix;
QLabel *folderLabel;
std::unique_ptr<QPushButton> cancel = std::make_unique<QPushButton>("Cancel");
std::unique_ptr<QPushButton> apply = std::make_unique<QPushButton>("Apply");
std::unique_ptr<QFileIconProvider> iconProv = std::make_unique<QFileIconProvider>();
std::unique_ptr<QPushButton> folderBtn = std::make_unique<QPushButton>(iconProv->icon(QFileIconProvider::Folder), "");
std::unique_ptr<QLabel> folderLabelPrefix = std::make_unique<QLabel>("Save files' path: ");
std::unique_ptr<QLabel> folderLabel;
std::unique_ptr<QHBoxLayout> generalLayout = std::make_unique<QHBoxLayout>();
std::unique_ptr<QVBoxLayout> generalLayoutV = std::make_unique<QVBoxLayout>();
std::unique_ptr<QTabWidget> tabs = std::make_unique<QTabWidget>();
std::unique_ptr<QVBoxLayout> mainLayout = std::make_unique<QVBoxLayout>();
std::unique_ptr<QHBoxLayout> buttonsLayout = std::make_unique<QHBoxLayout>();
Q_OBJECT
public:
float getVolumeL() { return float(audioSettings->volumeL->value()) / 100.f; }
@@ -21,10 +30,10 @@ public:
std::array<Qt::Key, 18> keyMap{};
SettingsWindow();
nlohmann::json settings;
CPUSettings *cpuSettings;
AudioSettings *audioSettings;
InputSettings *inputSettings;
QWidget *generalSettings;
std::unique_ptr<CPUSettings> cpuSettings{};
std::unique_ptr<AudioSettings> audioSettings{};
std::unique_ptr<InputSettings> inputSettings{};
std::unique_ptr<QWidget> generalSettings{};
Q_SIGNALS:
void regrabKeyboard();
};