From 42abe32c4a3431a9550511c71120fbdc74d36f7b Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Mon, 25 Dec 2023 20:14:38 +0530 Subject: [PATCH 1/7] Cleanup: Removed unused headers --- src/networking/server.cpp | 1 - src/preferences.cpp | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/networking/server.cpp b/src/networking/server.cpp index 5f068b4..1b824a4 100644 --- a/src/networking/server.cpp +++ b/src/networking/server.cpp @@ -3,7 +3,6 @@ #include "ui_server.h" -#include "../../VGP_Data_Exchange/C/Colfer.h" #include "../../third-party-libs/QR-Code-generator/cpp/qrcodegen.hpp" #include "../settings_key_variables.h" diff --git a/src/preferences.cpp b/src/preferences.cpp index 6d4b015..ee2b92b 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -3,13 +3,9 @@ #include "settings_key_variables.h" #include "ui_preferences.h" #include "winuser.h" -#include #include -#include #include #include -#include -#include #include #include From c66aafeb99b5d905827945d2810e24c0249677ed Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Mon, 25 Dec 2023 20:16:53 +0530 Subject: [PATCH 2/7] Cleanup: Removed Signal-Slot autoconnect --- src/mainwindow.cpp | 3 ++- src/mainwindow.hpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 70a65e2..eaf01e5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -13,6 +13,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi this->p = new Preferences(this); ui->setupUi(this); ui->settingsButton->connect(ui->settingsButton, &QPushButton::pressed, this, [=] { this->p->show(); }); + QPushButton::connect(ui->startButton, &QPushButton::pressed, this, &MainWindow::launch_server); } MainWindow::~MainWindow() @@ -20,7 +21,7 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::on_startButton_clicked() +void MainWindow::launch_server() { Server server(this); server.exec(); diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 86eaf75..49c73ef 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -19,7 +19,7 @@ class MainWindow : public QMainWindow ~MainWindow(); private slots: - void on_startButton_clicked(); + void launch_server(); private: Ui::MainWindow *ui; From e7752c00709227c1be1e901213b7020f864add49 Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Mon, 25 Dec 2023 20:18:25 +0530 Subject: [PATCH 3/7] Cleanup: Code Quality improvements --- CMakeLists.txt | 2 +- src/mainwindow.cpp | 2 +- src/mainwindow.hpp | 6 +++--- src/networking/server.hpp | 2 +- src/preferences.h | 8 ++++---- src/settings.cpp | 8 ++++---- src/settings.h | 4 ++-- src/settings_key_variables.h | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fdd39e7..e52159d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ set(THIRD_PARTY_LIB_SOURCES add_library(QR_Code_Generator SHARED ${THIRD_PARTY_LIB_SOURCES}) set(PROJECT_SOURCES + res/icons.qrc src/main.cpp src/mainwindow.cpp src/mainwindow.hpp @@ -37,7 +38,6 @@ set(PROJECT_SOURCES src/networking/server.ui src/networking/executor.cpp src/networking/executor.hpp - res/icons.qrc src/preferences.h src/preferences.cpp src/preferences.ui diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index eaf01e5..0bfe3fa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -12,7 +12,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi load_key_maps(); this->p = new Preferences(this); ui->setupUi(this); - ui->settingsButton->connect(ui->settingsButton, &QPushButton::pressed, this, [=] { this->p->show(); }); + QPushButton::connect(ui->settingsButton, &QPushButton::pressed, this, [=] { this->p->show(); }); QPushButton::connect(ui->startButton, &QPushButton::pressed, this, &MainWindow::launch_server); } diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 49c73ef..0d44d81 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -10,13 +10,13 @@ class MainWindow; } QT_END_NAMESPACE -class MainWindow : public QMainWindow +class MainWindow final : public QMainWindow { Q_OBJECT public: - MainWindow(QWidget *parent = nullptr); - ~MainWindow(); + explicit MainWindow(QWidget *parent = nullptr); + ~MainWindow() final; private slots: void launch_server(); diff --git a/src/networking/server.hpp b/src/networking/server.hpp index db0ad15..6733704 100644 --- a/src/networking/server.hpp +++ b/src/networking/server.hpp @@ -15,7 +15,7 @@ class Server : public QDialog public: explicit Server(QWidget *parent = nullptr); - ~Server(); + ~Server() override; QTcpServer *tcpServer = nullptr; private slots: diff --git a/src/preferences.h b/src/preferences.h index 26e5549..c35e9f4 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -10,18 +10,18 @@ namespace Ui class Preferences; } -class Preferences : public QDialog +class Preferences final : public QDialog { Q_OBJECT public: explicit Preferences(QWidget *parent = nullptr); void load_keys(); - ~Preferences(); + ~Preferences() final; protected: - bool eventFilter(QObject *sender, QEvent *event); - void keyPressEvent(QKeyEvent *e); + bool eventFilter(QObject *sender, QEvent *event) final; + void keyPressEvent(QKeyEvent *e) final; private: Ui::Preferences *ui; diff --git a/src/settings.cpp b/src/settings.cpp index ea92e7e..d8090a9 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -22,7 +22,7 @@ void (*load_functions[3])(void) = { * @param value * The value of the settings can be of any data type string, int, char, float, e.t.c. */ -void save_setting(QString key, QVariant value) +void save_setting(const QString& key, const QVariant& value) { settings->setValue(key, value); settings->sync(); @@ -37,7 +37,7 @@ void save_setting(QString key, QVariant value) * The fullname including the groups of the setting in string format * @return The setting as QVariant can be converted into almost all data types. */ -QVariant load_setting(QString key) +QVariant load_setting(const QString& key) { QVariant value = settings->value(key); return value; @@ -125,9 +125,9 @@ void load_key_maps() // set the key mappings to the stored values */ void load_all_settings() { - for (int i = 0; i < 3; i++) + for (auto & load_function : load_functions) { - (*load_functions[i])(); + (*load_function)(); } } diff --git a/src/settings.h b/src/settings.h index 7abaae6..9cd78ce 100644 --- a/src/settings.h +++ b/src/settings.h @@ -54,8 +54,8 @@ inline QMap keymaps = {{setting_keys::keys::A, "key {setting_keys::keys::VIEW, "keymaps/VIEW"}, {setting_keys::keys::MENU, "keymaps/MENU"}}; -void save_setting(QString key, QVariant value); -QVariant load_setting(QString key); +void save_setting(const QString& key, const QVariant& value); +QVariant load_setting(const QString& key); void load_mouse_setting(); void set_mouse_sensivity(); void load_settings_file(QObject *parent); diff --git a/src/settings_key_variables.h b/src/settings_key_variables.h index 273879c..4c1ca37 100644 --- a/src/settings_key_variables.h +++ b/src/settings_key_variables.h @@ -13,7 +13,7 @@ */ struct TRIAL { - WORD vk; + WORD vk{}; uint is_mouse_key = 0; }; From b1ba3363443b71f19fc4460d1bae063311ee6d9f Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Mon, 25 Dec 2023 20:45:22 +0530 Subject: [PATCH 4/7] Cleanup: Renamed a struct --- src/settings.cpp | 30 +++++++++++++++--------------- src/settings.h | 4 ++-- src/settings_key_variables.cpp | 28 ++++++++++++++-------------- src/settings_key_variables.h | 5 ++--- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index d8090a9..e2c30d7 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -22,7 +22,7 @@ void (*load_functions[3])(void) = { * @param value * The value of the settings can be of any data type string, int, char, float, e.t.c. */ -void save_setting(const QString& key, const QVariant& value) +void save_setting(const QString &key, const QVariant &value) { settings->setValue(key, value); settings->sync(); @@ -37,7 +37,7 @@ void save_setting(const QString& key, const QVariant& value) * The fullname including the groups of the setting in string format * @return The setting as QVariant can be converted into almost all data types. */ -QVariant load_setting(const QString& key) +QVariant load_setting(const QString &key) { QVariant value = settings->value(key); return value; @@ -79,43 +79,43 @@ void load_port_number() // set the port number as user_defined void load_key_maps() // set the key mappings to the stored values { GAMEPAD_BUTTONS[GamepadButtons_A] = - TRIAL{(WORD)settings->value(keymaps[A], GAMEPAD_BUTTONS[GamepadButtons_A].vk).toULongLong(), + Input{(WORD)settings->value(keymaps[A], GAMEPAD_BUTTONS[GamepadButtons_A].vk).toULongLong(), is_mouse_button(settings->value(keymaps[A], GAMEPAD_BUTTONS[GamepadButtons_A].vk).toULongLong())}; GAMEPAD_BUTTONS[GamepadButtons_B] = - TRIAL{(WORD)settings->value(keymaps[B], GAMEPAD_BUTTONS[GamepadButtons_B].vk).toULongLong(), + Input{(WORD)settings->value(keymaps[B], GAMEPAD_BUTTONS[GamepadButtons_B].vk).toULongLong(), is_mouse_button(settings->value(keymaps[B], GAMEPAD_BUTTONS[GamepadButtons_B].vk).toULongLong())}; GAMEPAD_BUTTONS[GamepadButtons_X] = - TRIAL{(WORD)settings->value(keymaps[X], GAMEPAD_BUTTONS[GamepadButtons_X].vk).toULongLong(), + Input{(WORD)settings->value(keymaps[X], GAMEPAD_BUTTONS[GamepadButtons_X].vk).toULongLong(), is_mouse_button(settings->value(keymaps[X], GAMEPAD_BUTTONS[GamepadButtons_X].vk).toULongLong())}; GAMEPAD_BUTTONS[GamepadButtons_Y] = - TRIAL{(WORD)settings->value(keymaps[Y], GAMEPAD_BUTTONS[GamepadButtons_Y].vk).toULongLong(), + Input{(WORD)settings->value(keymaps[Y], GAMEPAD_BUTTONS[GamepadButtons_Y].vk).toULongLong(), is_mouse_button(settings->value(keymaps[Y], GAMEPAD_BUTTONS[GamepadButtons_Y].vk).toULongLong())}; GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder] = - TRIAL{(WORD)settings->value(keymaps[LSHDR], GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk).toULongLong(), + Input{(WORD)settings->value(keymaps[LSHDR], GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk).toULongLong(), is_mouse_button( settings->value(keymaps[LSHDR], GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk).toULongLong())}; GAMEPAD_BUTTONS[GamepadButtons_RightShoulder] = - TRIAL{(WORD)settings->value(keymaps[RSHDR], GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk).toULongLong(), + Input{(WORD)settings->value(keymaps[RSHDR], GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk).toULongLong(), is_mouse_button( settings->value(keymaps[RSHDR], GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk).toULongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_DPadDown] = TRIAL{ + GAMEPAD_BUTTONS[GamepadButtons_DPadDown] = Input{ (WORD)settings->value(keymaps[DPADDOWN], GAMEPAD_BUTTONS[GamepadButtons_DPadDown].vk).toULongLong(), is_mouse_button(settings->value(keymaps[DPADDOWN], GAMEPAD_BUTTONS[GamepadButtons_DPadDown].vk).toULongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_DPadUp] = TRIAL{ + GAMEPAD_BUTTONS[GamepadButtons_DPadUp] = Input{ (WORD)settings->value(keymaps[DPADUP], GAMEPAD_BUTTONS[GamepadButtons_DPadUp].vk).toLongLong(), is_mouse_button(settings->value(keymaps[DPADUP], GAMEPAD_BUTTONS[GamepadButtons_DPadUp].vk).toLongLong())}; GAMEPAD_BUTTONS[GamepadButtons_DPadRight] = - TRIAL{(WORD)settings->value(keymaps[DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk).toLongLong(), + Input{(WORD)settings->value(keymaps[DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk).toLongLong(), is_mouse_button( settings->value(keymaps[DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk).toLongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_DPadLeft] = TRIAL{ + GAMEPAD_BUTTONS[GamepadButtons_DPadLeft] = Input{ (WORD)settings->value(keymaps[DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk).toLongLong(), is_mouse_button(settings->value(keymaps[DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk).toLongLong())}; GAMEPAD_BUTTONS[GamepadButtons_View] = - TRIAL{(WORD)settings->value(keymaps[VIEW], GAMEPAD_BUTTONS[GamepadButtons_View].vk).toLongLong(), + Input{(WORD)settings->value(keymaps[VIEW], GAMEPAD_BUTTONS[GamepadButtons_View].vk).toLongLong(), is_mouse_button(settings->value(keymaps[VIEW], GAMEPAD_BUTTONS[GamepadButtons_View].vk).toLongLong())}; GAMEPAD_BUTTONS[GamepadButtons_Menu] = - TRIAL{(WORD)settings->value(keymaps[MENU], GAMEPAD_BUTTONS[GamepadButtons_Menu].vk).toLongLong(), + Input{(WORD)settings->value(keymaps[MENU], GAMEPAD_BUTTONS[GamepadButtons_Menu].vk).toLongLong(), is_mouse_button(settings->value(keymaps[MENU], GAMEPAD_BUTTONS[GamepadButtons_Menu].vk).toLongLong())}; } @@ -125,7 +125,7 @@ void load_key_maps() // set the key mappings to the stored values */ void load_all_settings() { - for (auto & load_function : load_functions) + for (auto &load_function : load_functions) { (*load_function)(); } diff --git a/src/settings.h b/src/settings.h index 9cd78ce..1d630a5 100644 --- a/src/settings.h +++ b/src/settings.h @@ -54,8 +54,8 @@ inline QMap keymaps = {{setting_keys::keys::A, "key {setting_keys::keys::VIEW, "keymaps/VIEW"}, {setting_keys::keys::MENU, "keymaps/MENU"}}; -void save_setting(const QString& key, const QVariant& value); -QVariant load_setting(const QString& key); +void save_setting(const QString &key, const QVariant &value); +QVariant load_setting(const QString &key); void load_mouse_setting(); void set_mouse_sensivity(); void load_settings_file(QObject *parent); diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index a70169d..4e5db6c 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -7,20 +7,20 @@ int port = 7878; // the port on which the server runs on. * @brief GAMEPAD_BUTTONS * A map for the gamepad button and the corresponding input. */ -std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButtons_Menu, TRIAL{VK_MENU, 0}}, - {GamepadButtons::GamepadButtons_View, TRIAL{VK_TAB, 0}}, - {GamepadButtons::GamepadButtons_A, TRIAL{VK_RETURN, 0}}, - {GamepadButtons::GamepadButtons_B, TRIAL{'B', 0}}, - {GamepadButtons::GamepadButtons_X, TRIAL{VK_SHIFT, 0}}, - {GamepadButtons::GamepadButtons_Y, TRIAL{VK_CONTROL, 0}}, - {GamepadButtons::GamepadButtons_DPadUp, TRIAL{VK_UP, 0}}, - {GamepadButtons::GamepadButtons_DPadDown, TRIAL{VK_DOWN, 0}}, - {GamepadButtons::GamepadButtons_DPadLeft, TRIAL{VK_LEFT, 0}}, - {GamepadButtons::GamepadButtons_DPadRight, TRIAL{VK_RIGHT, 0}}, - {GamepadButtons::GamepadButtons_LeftShoulder, TRIAL{VK_LBUTTON, 1}}, - {GamepadButtons::GamepadButtons_RightShoulder, TRIAL{VK_NEXT, 0}}}; -// {GamepadButtons::GamepadButtons_LeftThumbstick, TRIAL{VK_LBUTTON, 1}}, -// {GamepadButtons::GamepadButtons_RightThumbstick, TRIAL{VK_NEXT, 0}}}; +std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButtons_Menu, Input{VK_MENU, 0}}, + {GamepadButtons::GamepadButtons_View, Input{VK_TAB, 0}}, + {GamepadButtons::GamepadButtons_A, Input{VK_RETURN, 0}}, + {GamepadButtons::GamepadButtons_B, Input{'B', 0}}, + {GamepadButtons::GamepadButtons_X, Input{VK_SHIFT, 0}}, + {GamepadButtons::GamepadButtons_Y, Input{VK_CONTROL, 0}}, + {GamepadButtons::GamepadButtons_DPadUp, Input{VK_UP, 0}}, + {GamepadButtons::GamepadButtons_DPadDown, Input{VK_DOWN, 0}}, + {GamepadButtons::GamepadButtons_DPadLeft, Input{VK_LEFT, 0}}, + {GamepadButtons::GamepadButtons_DPadRight, Input{VK_RIGHT, 0}}, + {GamepadButtons::GamepadButtons_LeftShoulder, Input{VK_LBUTTON, 1}}, + {GamepadButtons::GamepadButtons_RightShoulder, Input{VK_NEXT, 0}}}; +// {GamepadButtons::GamepadButtons_LeftThumbstick, Input{VK_LBUTTON, 1}}, +// {GamepadButtons::GamepadButtons_RightThumbstick, Input{VK_NEXT, 0}}}; /** * @brief THUMBSTICK_KEYS diff --git a/src/settings_key_variables.h b/src/settings_key_variables.h index 4c1ca37..54ef08a 100644 --- a/src/settings_key_variables.h +++ b/src/settings_key_variables.h @@ -8,10 +8,9 @@ #include /** - * @brief The TRIAL Struct * A structure to hold the button mappings. */ -struct TRIAL +struct Input { WORD vk{}; uint is_mouse_key = 0; @@ -19,7 +18,7 @@ struct TRIAL extern int mouse_sensivity; extern int port; -extern std::map GAMEPAD_BUTTONS; +extern std::map GAMEPAD_BUTTONS; enum Thumbstick { From 3a4b8866c03d6e239c98e555bb6278a6c7f90ad0 Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Mon, 25 Dec 2023 21:08:45 +0530 Subject: [PATCH 5/7] Cleanup: Fixed typo Changed 'sensivity' to 'sensitivity' across 6 files. Someone does not use spellcheck. --- src/networking/executor.cpp | 8 ++++---- src/preferences.cpp | 24 ++++++++++++------------ src/settings.cpp | 6 +++--- src/settings.h | 4 ++-- src/settings_key_variables.cpp | 4 ++-- src/settings_key_variables.h | 2 +- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/networking/executor.cpp b/src/networking/executor.cpp index 0b97b14..1151387 100644 --- a/src/networking/executor.cpp +++ b/src/networking/executor.cpp @@ -89,10 +89,10 @@ bool inject_gamepad_state(vgp_data_exchange_gamepad_reading reading) // Use the right thumbstick to move the mouse // if (abs(reading.right_thumbstick_x) > THRESHOLD || abs(reading.right_thumbstick_y) > THRESHOLD) - int offsetX = reading.right_thumbstick_x * mouse_sensivity; - int offsetY = reading.right_thumbstick_y * mouse_sensivity; - int scaleX = abs(offsetX) < (THRESHOLD * mouse_sensivity) ? 0 : 1; - int scaleY = abs(offsetY) < (THRESHOLD * mouse_sensivity) ? 0 : 1; + int offsetX = reading.right_thumbstick_x * mouse_sensitivity; + int offsetY = reading.right_thumbstick_y * mouse_sensitivity; + int scaleX = abs(offsetX) < (THRESHOLD * mouse_sensitivity) ? 0 : 1; + int scaleY = abs(offsetY) < (THRESHOLD * mouse_sensitivity) ? 0 : 1; qDebug() << "Moving mouse by" << offsetX << ", " << offsetY; for (int count = 1; count <= std::max(abs(offsetX), abs(offsetY)); ++count) diff --git a/src/preferences.cpp b/src/preferences.cpp index ee2b92b..3023159 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -17,28 +17,28 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [=] { // running the functions to change and save the new settings if the user presses ok this->change_mouse_sensitivity(ui->horizontalSlider->value() * 100); - qDebug() << mouse_sensivity; - save_setting(setting_keys::Mouse_sensivity, - mouse_sensivity / 100); // saving the new mouse sensivity - change_key_inputs(); // changing and saving key maps + qDebug() << mouse_sensitivity; + save_setting(setting_keys::Mouse_sensitivity, + mouse_sensitivity / 100); // saving the new mouse sensitivity + change_key_inputs(); // changing and saving key maps }); ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=] { load_keys(); }); ui->formLayout->setSizeConstraint(QLayout::SetMinimumSize); ui->formLayout->setHorizontalSpacing(50); ui->formLayout->setVerticalSpacing(10); - ui->horizontalSlider->setValue(mouse_sensivity / 100); + ui->horizontalSlider->setValue(mouse_sensitivity / 100); Preferences::load_keys(); } /** * @brief Preferences::change_mouse_sensitivity - * Changes the mouse sensivity or the cursor speed + * Changes the mouse sensitivity or the cursor speed * @param value - * The amount of mouse sensivity you want to set. + * The amount of mouse sensitivity you want to set. */ void Preferences::change_mouse_sensitivity(int value) { - mouse_sensivity = value; + mouse_sensitivity = value; } /** @@ -113,7 +113,7 @@ void Preferences::change_key_inputs() /** * @brief Preferences::get_scan_code - * Copies the name of the of corrosponding key or virutal key code to the provided buffer. + * Copies the name of the of corresponding key or virtual key code to the provided buffer. * @param vk * The virtual key code of the key you want to get. * @param a @@ -196,8 +196,8 @@ void Preferences::load_keys() * @brief Preferences::eventFilter * The event filter virtual function is redefined to to filter for mouse and keyboard inputs when user tries to change * the button-key maps. Checks which object is sending the event and type of event. If event is a keyboard or - * mousebutton press than map and the object is buttonmap than get the virtual key code of the key pressed and store the - * change in a temporary variable. + * mouse button press then map and the object is button map then get the virtual key code of the key pressed + * and store the change in a temporary variable. * @param sender * To get the address of the object that is triggering the event. * @param event @@ -241,7 +241,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) valid = true; break; default: - qDebug() << "[!] Error Occured No Legal Mouse Button Found"; + qDebug() << "[!] Error Occurred. No Legal Mouse Button Found"; } if (valid) ptr->setText(QString(buffer)); diff --git a/src/settings.cpp b/src/settings.cpp index e2c30d7..42df190 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -8,7 +8,7 @@ const QString SETTINGS_FILE = QDir::toNativeSeparators( QDir::homePath() + "//VirtualGamePad.ini"); // the path of the settigs file. C:\Users\\VirtualGamePad.ini QSettings *settings; -QString setting_keys::Mouse_sensivity = "mouse_setting/mouse_sensivity"; +QString setting_keys::Mouse_sensitivity = "mouse_setting/mouse_sensitivity"; void (*load_functions[3])(void) = { load_mouse_setting, load_port_number, @@ -45,11 +45,11 @@ QVariant load_setting(const QString &key) /** * @brief load_mouse_setting - * Loads and sets the mouse sensivity. + * Loads and sets the mouse sensitivity. */ void load_mouse_setting() { - mouse_sensivity = settings->value(setting_keys::Mouse_sensivity).toInt() * 100; + mouse_sensitivity = settings->value(setting_keys::Mouse_sensitivity).toInt() * 100; } /** diff --git a/src/settings.h b/src/settings.h index 1d630a5..4caaa29 100644 --- a/src/settings.h +++ b/src/settings.h @@ -14,7 +14,7 @@ enum server_keys Port }; -extern QString Mouse_sensivity; +extern QString Mouse_sensitivity; enum keys { @@ -57,7 +57,7 @@ inline QMap keymaps = {{setting_keys::keys::A, "key void save_setting(const QString &key, const QVariant &value); QVariant load_setting(const QString &key); void load_mouse_setting(); -void set_mouse_sensivity(); +void set_mouse_sensitivity(); void load_settings_file(QObject *parent); void load_port_number(); void load_key_maps(); diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index 4e5db6c..035d303 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -1,7 +1,7 @@ #include "settings_key_variables.h" -int mouse_sensivity = 1000; // the mouse_sensivity or the cursor speed. -int port = 7878; // the port on which the server runs on. +int mouse_sensitivity = 1000; // the mouse_sensitivity or the cursor speed. +int port = 7878; // the port on which the server runs on. /** * @brief GAMEPAD_BUTTONS diff --git a/src/settings_key_variables.h b/src/settings_key_variables.h index 54ef08a..6623da9 100644 --- a/src/settings_key_variables.h +++ b/src/settings_key_variables.h @@ -16,7 +16,7 @@ struct Input uint is_mouse_key = 0; }; -extern int mouse_sensivity; +extern int mouse_sensitivity; extern int port; extern std::map GAMEPAD_BUTTONS; From 09731a40fda1c3b34c9f8e8cf8f2bdb5b1a0f0f4 Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Mon, 25 Dec 2023 21:17:24 +0530 Subject: [PATCH 6/7] Cleanup: Consistent Documentation --- src/preferences.cpp | 7 ------- src/settings.cpp | 8 -------- src/settings.h | 4 ++-- src/settings_key_variables.cpp | 4 ---- 4 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/preferences.cpp b/src/preferences.cpp index 3023159..3dae34c 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -31,7 +31,6 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen } /** - * @brief Preferences::change_mouse_sensitivity * Changes the mouse sensitivity or the cursor speed * @param value * The amount of mouse sensitivity you want to set. @@ -42,7 +41,6 @@ void Preferences::change_mouse_sensitivity(int value) } /** - * @brief Preferences::change_key_inputs * This changes the keyboard maps and saves those changes in the config file. * This function is executed if the user presses ok button. */ @@ -112,7 +110,6 @@ void Preferences::change_key_inputs() } /** - * @brief Preferences::get_scan_code * Copies the name of the of corresponding key or virtual key code to the provided buffer. * @param vk * The virtual key code of the key you want to get. @@ -136,7 +133,6 @@ void Preferences::get_scan_code(WORD vk, char *a, int size) } /** - * @brief Preferences::load_keys * Displays the key to which each button is mapped to. * Saves the initial key maps in variables that can be changed later if user wants to. */ @@ -193,7 +189,6 @@ void Preferences::load_keys() } /** - * @brief Preferences::eventFilter * The event filter virtual function is redefined to to filter for mouse and keyboard inputs when user tries to change * the button-key maps. Checks which object is sending the event and type of event. If event is a keyboard or * mouse button press then map and the object is button map then get the virtual key code of the key pressed @@ -257,7 +252,6 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) } /** - * @brief Preferences::keyPressEvent * Make the Qdialog box ignores the enter key and escape key presses when the focus is on button map * @param e * Capture the key_press event @@ -270,7 +264,6 @@ void Preferences::keyPressEvent(QKeyEvent *e) } /** - * @brief Preferences::install_event_filter * Install the above event filter on all the button maps to capture the key presses when they have the focus. */ void Preferences::install_event_filter() diff --git a/src/settings.cpp b/src/settings.cpp index 42df190..f11cf0c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -15,7 +15,6 @@ void (*load_functions[3])(void) = { load_key_maps}; // an array of pointer to functions that needs to run on startup to load settings. /** - * @brief save_setting * Save a setting to the settings file * @param key * The name of the setting in string format if you want to group settings seperate the head group using @@ -31,7 +30,6 @@ void save_setting(const QString &key, const QVariant &value) } /** - * @brief load_setting * Get the value of a setting. * @param key * The fullname including the groups of the setting in string format @@ -44,7 +42,6 @@ QVariant load_setting(const QString &key) } /** - * @brief load_mouse_setting * Loads and sets the mouse sensitivity. */ void load_mouse_setting() @@ -53,7 +50,6 @@ void load_mouse_setting() } /** - * @brief load_settings_file * Loads the settings file for the current application. * @param parent * The parent object either a widget or Qt Application e.t.c @@ -64,7 +60,6 @@ void load_settings_file(QObject *parent = nullptr) } /** - * @brief load_port_number * Load and set the port number */ void load_port_number() // set the port number as user_defined @@ -73,7 +68,6 @@ void load_port_number() // set the port number as user_defined } /** - * @brief load_key_maps * Load the key maps from the settings file. */ void load_key_maps() // set the key mappings to the stored values @@ -120,7 +114,6 @@ void load_key_maps() // set the key mappings to the stored values } /** - * @brief load_all_settings * Run the functions using the function array to load all the necessary settings. */ void load_all_settings() @@ -132,7 +125,6 @@ void load_all_settings() } /** - * @brief is_mouse_button * Function to find out if the user mapped a keyboard key or mouse button * @param vk * Virtual key code of the key or mouse button pressed diff --git a/src/settings.h b/src/settings.h index 4caaa29..30c4843 100644 --- a/src/settings.h +++ b/src/settings.h @@ -37,9 +37,9 @@ enum keys extern QSettings *settings; inline QList server_settings = {"port"}; // inline QList keymaps = {"keymaps/A", "keymaps/B", "keymaps/X", "keymaps/Y", "keymaps/RT", "keymaps/LT"}; + /** - * @brief keymaps - * a Qmap to map the keys in namespace to corresponding settings name in string format. + * A Qmap to map the keys in namespace to corresponding settings name in string format. */ inline QMap keymaps = {{setting_keys::keys::A, "keymaps/A"}, {setting_keys::keys::B, "keymaps/B"}, diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index 035d303..91f8e4c 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -4,7 +4,6 @@ int mouse_sensitivity = 1000; // the mouse_sensitivity or the cursor speed. int port = 7878; // the port on which the server runs on. /** - * @brief GAMEPAD_BUTTONS * A map for the gamepad button and the corresponding input. */ std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButtons_Menu, Input{VK_MENU, 0}}, @@ -23,7 +22,6 @@ std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButto // {GamepadButtons::GamepadButtons_RightThumbstick, Input{VK_NEXT, 0}}}; /** - * @brief THUMBSTICK_KEYS * Maps the joystick movements. */ std::map THUMBSTICK_KEYS = { @@ -33,7 +31,6 @@ std::map THUMBSTICK_KEYS = { {Thumbstick::RightThumbstickLeft, VK_LEFT}, {Thumbstick::RightThumbstickRight, VK_RIGHT}}; /** - * @brief vk_maps * A std::map to map the virtual key codes to corresponding key names */ std::map vk_maps = {{VK_LBUTTON, "LMButton"}, @@ -64,7 +61,6 @@ std::map vk_maps = {{VK_LBUTTON, "LMButton"}, {VK_MENU, "MENU"}}; /** - * @brief MOUSE_BUTTONS * A list containing the Mouse Buttons. */ const QList MOUSE_BUTTONS = {VK_LBUTTON, VK_RBUTTON, VK_MBUTTON}; From 56ba328c02850b5dfdf3ffcb68e03c3b419c15ef Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Mon, 25 Dec 2023 21:34:43 +0530 Subject: [PATCH 7/7] Cleanup: Implemented some SonarCloud suggestions --- src/mainwindow.hpp | 2 +- src/preferences.h | 6 ++-- src/settings.cpp | 2 +- src/settings.h | 24 +++++++-------- src/settings_key_variables.cpp | 54 ++++++++++++++++------------------ 5 files changed, 43 insertions(+), 45 deletions(-) diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 0d44d81..a748c61 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -16,7 +16,7 @@ class MainWindow final : public QMainWindow public: explicit MainWindow(QWidget *parent = nullptr); - ~MainWindow() final; + ~MainWindow() override; private slots: void launch_server(); diff --git a/src/preferences.h b/src/preferences.h index c35e9f4..4e13594 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -17,11 +17,11 @@ class Preferences final : public QDialog public: explicit Preferences(QWidget *parent = nullptr); void load_keys(); - ~Preferences() final; + ~Preferences() override; protected: - bool eventFilter(QObject *sender, QEvent *event) final; - void keyPressEvent(QKeyEvent *e) final; + bool eventFilter(QObject *sender, QEvent *event) override; + void keyPressEvent(QKeyEvent *e) override; private: Ui::Preferences *ui; diff --git a/src/settings.cpp b/src/settings.cpp index f11cf0c..0e7d1cd 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -10,7 +10,7 @@ QSettings *settings; QString setting_keys::Mouse_sensitivity = "mouse_setting/mouse_sensitivity"; -void (*load_functions[3])(void) = { +void (*load_functions[])(void) = { load_mouse_setting, load_port_number, load_key_maps}; // an array of pointer to functions that needs to run on startup to load settings. diff --git a/src/settings.h b/src/settings.h index 30c4843..333318a 100644 --- a/src/settings.h +++ b/src/settings.h @@ -41,18 +41,18 @@ inline QList server_settings = {"port"}; /** * A Qmap to map the keys in namespace to corresponding settings name in string format. */ -inline QMap keymaps = {{setting_keys::keys::A, "keymaps/A"}, - {setting_keys::keys::B, "keymaps/B"}, - {setting_keys::keys::X, "keymaps/X"}, - {setting_keys::keys::Y, "keymaps/Y"}, - {setting_keys::keys::RSHDR, "keymaps/RT"}, - {setting_keys::keys::LSHDR, "keymaps/LT"}, - {setting_keys::keys::DPADDOWN, "keymaps/DPADDOWN"}, - {setting_keys::keys::DPADUP, "keymaps/DPADUP"}, - {setting_keys::keys::DPADRIGHT, "keymaps/DPADRIGHT"}, - {setting_keys::keys::DPADLEFT, "keymaps/DPADLEFT"}, - {setting_keys::keys::VIEW, "keymaps/VIEW"}, - {setting_keys::keys::MENU, "keymaps/MENU"}}; +const inline QMap keymaps = {{setting_keys::keys::A, "keymaps/A"}, + {setting_keys::keys::B, "keymaps/B"}, + {setting_keys::keys::X, "keymaps/X"}, + {setting_keys::keys::Y, "keymaps/Y"}, + {setting_keys::keys::RSHDR, "keymaps/RT"}, + {setting_keys::keys::LSHDR, "keymaps/LT"}, + {setting_keys::keys::DPADDOWN, "keymaps/DPADDOWN"}, + {setting_keys::keys::DPADUP, "keymaps/DPADUP"}, + {setting_keys::keys::DPADRIGHT, "keymaps/DPADRIGHT"}, + {setting_keys::keys::DPADLEFT, "keymaps/DPADLEFT"}, + {setting_keys::keys::VIEW, "keymaps/VIEW"}, + {setting_keys::keys::MENU, "keymaps/MENU"}}; void save_setting(const QString &key, const QVariant &value); QVariant load_setting(const QString &key); diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index 91f8e4c..76722ca 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -18,8 +18,6 @@ std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButto {GamepadButtons::GamepadButtons_DPadRight, Input{VK_RIGHT, 0}}, {GamepadButtons::GamepadButtons_LeftShoulder, Input{VK_LBUTTON, 1}}, {GamepadButtons::GamepadButtons_RightShoulder, Input{VK_NEXT, 0}}}; -// {GamepadButtons::GamepadButtons_LeftThumbstick, Input{VK_LBUTTON, 1}}, -// {GamepadButtons::GamepadButtons_RightThumbstick, Input{VK_NEXT, 0}}}; /** * Maps the joystick movements. @@ -33,32 +31,32 @@ std::map THUMBSTICK_KEYS = { /** * A std::map to map the virtual key codes to corresponding key names */ -std::map vk_maps = {{VK_LBUTTON, "LMButton"}, - {VK_RBUTTON, "RMButton"}, - {VK_MBUTTON, "MMButton"}, - {VK_BACK, "BACKSPACE"}, - {VK_TAB, "TAB"}, - {VK_RETURN, "ENTER"}, - {VK_SHIFT, "SHIFT"}, - {VK_CONTROL, "CTRL"}, - {VK_CAPITAL, "CAPITAL"}, - {VK_ESCAPE, "ESCAPE"}, - {VK_SPACE, "SPACE"}, - {VK_PRIOR, "PageUP"}, - {VK_NEXT, "PageDOWN"}, - {VK_END, "END"}, - {VK_HOME, "HOME"}, - {VK_LEFT, "LEFT"}, - {VK_UP, "UP"}, - {VK_RIGHT, "RIGHT"}, - {VK_DOWN, "DOWN"}, - {VK_INSERT, "INS"}, - {VK_DELETE, "DEL"}, - {VK_OEM_PERIOD, "."}, - {VK_OEM_COMMA, ","}, - {VK_OEM_MINUS, "-"}, - {VK_OEM_PLUS, "+"}, - {VK_MENU, "MENU"}}; +const std::map vk_maps = {{VK_LBUTTON, "LMButton"}, + {VK_RBUTTON, "RMButton"}, + {VK_MBUTTON, "MMButton"}, + {VK_BACK, "BACKSPACE"}, + {VK_TAB, "TAB"}, + {VK_RETURN, "ENTER"}, + {VK_SHIFT, "SHIFT"}, + {VK_CONTROL, "CTRL"}, + {VK_CAPITAL, "CAPITAL"}, + {VK_ESCAPE, "ESCAPE"}, + {VK_SPACE, "SPACE"}, + {VK_PRIOR, "PageUP"}, + {VK_NEXT, "PageDOWN"}, + {VK_END, "END"}, + {VK_HOME, "HOME"}, + {VK_LEFT, "LEFT"}, + {VK_UP, "UP"}, + {VK_RIGHT, "RIGHT"}, + {VK_DOWN, "DOWN"}, + {VK_INSERT, "INS"}, + {VK_DELETE, "DEL"}, + {VK_OEM_PERIOD, "."}, + {VK_OEM_COMMA, ","}, + {VK_OEM_MINUS, "-"}, + {VK_OEM_PLUS, "+"}, + {VK_MENU, "MENU"}}; /** * A list containing the Mouse Buttons.