Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user editable key maps #5

Merged
merged 34 commits into from
Dec 16, 2023
Merged

Conversation

franklin654
Copy link
Contributor

  • changed the Cmakelist to remove unnecessary space.
  • added the functions to load and save key maps.
  • created and installed event filters to pick up user input for custom key maps

changed all static hard coded values to variables and included them in a separate folder
removed extra spaces
icons for preference buttons
added image files for button icons
added the functions and maps required to dynamically change key maps as defined by the user
@franklin654 franklin654 changed the title User preferences Add user editable key maps Aug 26, 2023
franklin654 and others added 3 commits August 30, 2023 15:11
fixing the bug that occurs when mapping to numbers, adding the icon files qt resource
adding the mouse press filter to map the keys to mouse buttons
src/preferences.cpp Outdated Show resolved Hide resolved
src/mainwindow.cpp Outdated Show resolved Hide resolved
src/mainwindow.ui Outdated Show resolved Hide resolved
src/main.cpp Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
src/settings_key_variables.h Outdated Show resolved Hide resolved
src/settings.h Show resolved Hide resolved
src/settings_key_variables.cpp Outdated Show resolved Hide resolved
src/settings.cpp Outdated Show resolved Hide resolved
src/settings.cpp Outdated Show resolved Hide resolved
@kitswas
Copy link
Owner

kitswas commented Aug 30, 2023

There's not a single line of documentation accompanying the code changes.
This pull request won't be merged unless the new code is documented.

kitswas and others added 4 commits August 30, 2023 19:03
Co-authored-by: kitswas <90329875+kitswas@users.noreply.github.com>
Co-authored-by: kitswas <90329875+kitswas@users.noreply.github.com>
fixing the broken include guard, removed the redundant functions, removed the qt::endl, fixed the typo in config file name
@franklin654
Copy link
Contributor Author

image does this type of documentation suffices

kitswas and others added 4 commits August 31, 2023 00:09
@kitswas
Copy link
Owner

kitswas commented Sep 1, 2023

@franklin654
Not a fan of commit 9a29227.

Before:

UI before commit

After:

UI after commit

Everything seems to be squished. And the UI no longer scales properly with the window.
You can decrease the default window size if the old UI looks too sparse to you. But revert that commit first.

Also, kindly read what the QSizePolicies mean.

@kitswas
Copy link
Owner

kitswas commented Sep 1, 2023

And a bit of clarification about the documentation comments.

Something like

/**
 * @brief load_setting
 * get the value of a setting.
 * @param key
 * the fullname including the groups of the setting in string format
 * @return
 * returns the value as QVariant can be converted into almost all data types.
 */
QVariant load_setting(QString key)

ends up as:

image

So:

  1. The function name should not be repeated after @brief.
  2. Every sentence should begin with a Capital Letter.
  3. Returns should not be written after @return.

Here's what I would write for this function:

/**
 * Get the value of a setting.
 * @param key
 * The full name including the groups of the setting as a string.
 * @return
 * The value as QVariant. It can be converted into almost all data types.
 */
QVariant load_setting(QString key)

image

See. Looks nicer already.

@franklin654
Copy link
Contributor Author

franklin654 commented Sep 1, 2023

image

preview of the new interface

@kitswas
Copy link
Owner

kitswas commented Sep 2, 2023

Currently, there is no option to map a button to mouse input.
We need to make it happen.

@kitswas
Copy link
Owner

kitswas commented Sep 2, 2023

We should support:

  1. Left click
  2. Right click

Here's what we could have in place of the QLineEdits we are currently using:

image

The current QLineEdit could be moved to the keyboard tab.

image

The mouse input type could be presented in a QComboBox.

Edit: A button cannot be mapped to mouse move.

@kitswas
Copy link
Owner

kitswas commented Sep 3, 2023

The Analogue Thumbsticks are missing.

For each thumbstick, we should be able to

  1. Map a key/mouse click to each of the 4 directions, or
  2. Use the whole thumbstick for mouse movement.

Comment on lines 168 to 509
QKeyEvent* key_press = static_cast<QKeyEvent*>(event);
this->DDOWN = key_press->nativeVirtualKey();
char buffer[256];
get_scan_code(key_press->nativeVirtualKey(), buffer, 256);
ui->ddownmap->setText(QString(buffer));
}
else if(event->type() == QEvent::MouseButtonRelease) {
QMouseEvent* mouse_press = static_cast<QMouseEvent*>(event);
char buffer[256];
bool valid = true;
UINT button = mouse_press->button();
switch(button) {
case Qt::MouseButton::LeftButton:
this->DDOWN = VK_LBUTTON;
get_scan_code(VK_LBUTTON, buffer, 256);
break;
case Qt::MouseButton::RightButton:
this->DDOWN = VK_RBUTTON;
get_scan_code(VK_RBUTTON, buffer, 256);
break;
case Qt::MouseButton::MiddleButton:
this->DDOWN = VK_MBUTTON;
get_scan_code(VK_MBUTTON, buffer, 256);
break;
default:
qDebug() << "Some Error Occured No Legal Mouse Button found";
valid = false;
}
if(valid)
ui->ddownmap->setText(QString(buffer));
}
}
else if(sender == ui->drightmap) {
if(event->type() == QEvent::KeyRelease) {
QKeyEvent* key_press = static_cast<QKeyEvent*>(event);
this->DRIGHT = key_press->nativeVirtualKey();
char buffer[256];
get_scan_code(key_press->nativeVirtualKey(), buffer, 256);
ui->drightmap->setText(QString(buffer));
}
else if(event->type() == QEvent::MouseButtonRelease) {
QMouseEvent* mouse_press = static_cast<QMouseEvent*>(event);
char buffer[256];
bool valid = true;
UINT button = mouse_press->button();
switch(button) {
case Qt::MouseButton::LeftButton:
this->DRIGHT = VK_LBUTTON;
get_scan_code(VK_LBUTTON, buffer, 256);
break;
case Qt::MouseButton::RightButton:
this->DRIGHT = VK_RBUTTON;
get_scan_code(VK_RBUTTON, buffer, 256);
break;
case Qt::MouseButton::MiddleButton:
this->DRIGHT = VK_MBUTTON;
get_scan_code(VK_MBUTTON, buffer, 256);
break;
default:
qDebug() << "Some Error Occured No Legal Mouse Button found";
valid = false;
}
if(valid)
ui->drightmap->setText(QString(buffer));
}
}
else if(sender == ui->dleftmap) {
if(event->type() == QEvent::KeyRelease) {
QKeyEvent* key_press = static_cast<QKeyEvent*>(event);
this->DLEFT = key_press->nativeVirtualKey();
char buffer[256];
get_scan_code(key_press->nativeVirtualKey(), buffer, 256);
ui->dleftmap->setText(QString(buffer));
}
else if(event->type() == QEvent::MouseButtonRelease) {
QMouseEvent* mouse_press = static_cast<QMouseEvent*>(event);
char buffer[256];
bool valid = true;
UINT button = mouse_press->button();
switch(button) {
case Qt::MouseButton::LeftButton:
this->DLEFT = VK_LBUTTON;
get_scan_code(VK_LBUTTON, buffer, 256);
break;
case Qt::MouseButton::RightButton:
this->DLEFT = VK_RBUTTON;
get_scan_code(VK_RBUTTON, buffer, 256);
break;
case Qt::MouseButton::MiddleButton:
this->DLEFT = VK_MBUTTON;
get_scan_code(VK_MBUTTON, buffer, 256);
break;
default:
qDebug() << "Some Error Occured No Legal Mouse Button found";
valid = false;
}
if(valid)
ui->dleftmap->setText(QString(buffer));
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much of this code is simply duplicated with different variables.

This must change.

Copy link
Owner

@kitswas kitswas Sep 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend creating a new component for keyinput (like the one discussed) and moving this logic there.

decreasing the length of code using for loops and iterators. and removing excess if statements and variables, changing the order of key maps.
Repository owner deleted a comment from sonarcloud bot Sep 9, 2023
@kitswas
Copy link
Owner

kitswas commented Oct 10, 2023

@franklin654 Are you still working on this?

@franklin654
Copy link
Contributor Author

@franklin654 Are you still working on this?

Yes Just started today again.

Comment on lines 95 to 105
void Preferences::get_scan_code(WORD vk, char* a, int size)
{
char sc = MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_CHAR);
if(sc >= '0' && sc <= 'Z') {
strncpy(a, "", size);
strncpy(a, &sc, 1);
}
else {
strncpy(a, vk_maps[vk], size);
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franklin654
There was a bug in the code using strncpy that was causing the application to crash.
Did you fix that?
Please debug and verify.

See Preferences::get_scan_code() in the file src/preferences.cpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I replaced the strncpy with strncpy_s with buffer size checks just haven't commited yet there are other changes that need to be done in preferences.cpp

1. Changed the format of saving and loading button maps.
2. Fixed the lines where memory leakage.
3. Made sure server can differentiate between mouse mapping and keyboard mapping.
4. Added some extra checks to make sure users can't put invalid inputs or perform overloading while setting the button maps.
Fixing some of the code smells Sound Cloud suggested that are fixable.
Changing the Documentation according to your suggestions.
kitswas#5 (comment)
@kitswas
Copy link
Owner

kitswas commented Dec 15, 2023

@franklin654
Please merge changes from main into your branch and run the code linter.

./code-lint.ps1

Copy link

sonarcloud bot commented Dec 16, 2023

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

33 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@kitswas kitswas merged commit 860a475 into kitswas:main Dec 16, 2023
2 checks passed
@kitswas kitswas mentioned this pull request Dec 16, 2023
3 tasks
@franklin654 franklin654 deleted the User_Preferences branch December 17, 2023 21:33
@franklin654 franklin654 restored the User_Preferences branch December 17, 2023 21:34
@franklin654 franklin654 deleted the User_Preferences branch December 17, 2023 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants