mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
Major Directory Refactoring (#5118)
* refactored cardzone.cpp, added doc and changed if to switch case * started moving every files into different folders * remove undercase to match with other files naming convention * refactored dialog files * ran format.sh * refactored client/tabs folder * refactored client/tabs folder * refactored client/tabs folder * refactored client folder * refactored carddbparser * refactored dialogs * Create sonar-project.properties temporary file for lint * Create build.yml temporary file for lint * removed all files from root directory * removed all files from root directory * added current branch to workflow * fixed most broken import * fixed issues while renaming files * fixed oracle importer * fixed dbconverter * updated translations * made sub-folders for client * removed linter * removed linter folder * fixed oracle import * revert card_zone documentation * renamed db parser files name and deck_view imports * fixed dlg file issue * ran format file and fixed test file * fixed carddb test files * moved player folder in game * updated translations and format files * fixed peglib import * format cmake files * removing vcpkg to try to add it back later * tried fixing vcpkg file * renamed filter to filters and moved database parser to cards folder * reverted translation files * reverted oracle translated * Update cockatrice/src/dialogs/dlg_register.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * Update cockatrice/src/client/ui/window_main.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * removed empty line at file start * removed useless include from tab_supervisor.cpp * refactored cardzone.cpp, added doc and changed if to switch case * started moving every files into different folders * remove undercase to match with other files naming convention * refactored dialog files * ran format.sh * refactored client/tabs folder * refactored client folder * refactored carddbparser * refactored dialogs * removed all files from root directory * Create sonar-project.properties temporary file for lint * Create build.yml temporary file for lint * added current branch to workflow * fixed most broken import * fixed issues while renaming files * fixed oracle importer * fixed dbconverter * updated translations * made sub-folders for client * removed linter * removed linter folder * fixed oracle import * revert card_zone documentation * renamed db parser files name and deck_view imports * fixed dlg file issue * ran format file and fixed test file * fixed carddb test files * moved player folder in game * updated translations and format files * fixed peglib import * reverted translation files * format cmake files * removing vcpkg to try to add it back later * tried fixing vcpkg file * pre-updating of cockatrice changes * removed empty line at file start * reverted oracle translated * Update cockatrice/src/dialogs/dlg_register.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * Update cockatrice/src/client/ui/window_main.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * removed useless include from tab_supervisor.cpp --------- Co-authored-by: tooomm <tooomm@users.noreply.github.com>
This commit is contained in:
parent
d1e0f9dfc5
commit
fa999880ee
261 changed files with 735 additions and 729 deletions
|
|
@ -1,180 +0,0 @@
|
|||
#include "shortcutssettings.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
#include <QStringList>
|
||||
#include <utility>
|
||||
|
||||
ShortcutKey::ShortcutKey(const QString &_name, QList<QKeySequence> _sequence, ShortcutGroup::Groups _group)
|
||||
: QList<QKeySequence>(_sequence), name(_name), group(_group)
|
||||
{
|
||||
}
|
||||
|
||||
ShortcutsSettings::ShortcutsSettings(const QString &settingsPath, QObject *parent) : QObject(parent)
|
||||
{
|
||||
shortCuts = defaultShortCuts;
|
||||
settingsFilePath = settingsPath;
|
||||
settingsFilePath.append("shortcuts.ini");
|
||||
|
||||
bool exists = QFile(settingsFilePath).exists();
|
||||
|
||||
QSettings shortCutsFile(settingsFilePath, QSettings::IniFormat);
|
||||
|
||||
if (exists) {
|
||||
shortCutsFile.beginGroup(custom);
|
||||
const QStringList customKeys = shortCutsFile.allKeys();
|
||||
|
||||
QMap<QString, QString> invalidItems;
|
||||
for (QStringList::const_iterator it = customKeys.constBegin(); it != customKeys.constEnd(); ++it) {
|
||||
QString stringSequence = shortCutsFile.value(*it).toString();
|
||||
// check whether shortcut is forbidden
|
||||
if (isKeyAllowed(*it, stringSequence)) {
|
||||
auto shortcut = getShortcut(*it);
|
||||
shortcut.setSequence(parseSequenceString(stringSequence));
|
||||
shortCuts.insert(*it, shortcut);
|
||||
} else {
|
||||
invalidItems.insert(*it, stringSequence);
|
||||
}
|
||||
}
|
||||
|
||||
shortCutsFile.endGroup();
|
||||
|
||||
if (!invalidItems.isEmpty()) {
|
||||
// warning message in case of invalid items
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Warning);
|
||||
msgBox.setText(tr("Your configuration file contained invalid shortcuts.\n"
|
||||
"Please check your shortcut settings!"));
|
||||
QString detailedMessage = tr("The following shortcuts have been set to default:\n");
|
||||
for (QMap<QString, QString>::const_iterator item = invalidItems.constBegin();
|
||||
item != invalidItems.constEnd(); ++item) {
|
||||
detailedMessage += item.key() + " - \"" + item.value() + "\"\n";
|
||||
}
|
||||
msgBox.setDetailedText(detailedMessage);
|
||||
msgBox.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ShortcutKey ShortcutsSettings::getDefaultShortcut(const QString &name) const
|
||||
{
|
||||
return defaultShortCuts.value(name, ShortcutKey());
|
||||
}
|
||||
|
||||
ShortcutKey ShortcutsSettings::getShortcut(const QString &name) const
|
||||
{
|
||||
if (shortCuts.contains(name)) {
|
||||
return shortCuts.value(name);
|
||||
}
|
||||
|
||||
return getDefaultShortcut(name);
|
||||
}
|
||||
|
||||
QKeySequence ShortcutsSettings::getSingleShortcut(const QString &name) const
|
||||
{
|
||||
return getShortcut(name).at(0);
|
||||
}
|
||||
|
||||
QString ShortcutsSettings::getDefaultShortcutString(const QString &name) const
|
||||
{
|
||||
return stringifySequence(getDefaultShortcut(name));
|
||||
}
|
||||
|
||||
QString ShortcutsSettings::getShortcutString(const QString &name) const
|
||||
{
|
||||
return stringifySequence(getShortcut(name));
|
||||
}
|
||||
|
||||
QString ShortcutsSettings::stringifySequence(const QList<QKeySequence> &Sequence) const
|
||||
{
|
||||
QStringList stringSequence;
|
||||
for (const auto &i : Sequence) {
|
||||
stringSequence.append(i.toString(QKeySequence::PortableText));
|
||||
}
|
||||
|
||||
return stringSequence.join(sep);
|
||||
}
|
||||
|
||||
QList<QKeySequence> ShortcutsSettings::parseSequenceString(const QString &stringSequence) const
|
||||
{
|
||||
QList<QKeySequence> SequenceList;
|
||||
for (const QString &shortcut : stringSequence.split(sep)) {
|
||||
SequenceList.append(QKeySequence(shortcut, QKeySequence::PortableText));
|
||||
}
|
||||
|
||||
return SequenceList;
|
||||
}
|
||||
|
||||
void ShortcutsSettings::setShortcuts(const QString &name, const QList<QKeySequence> &Sequence)
|
||||
{
|
||||
shortCuts[name].setSequence(Sequence);
|
||||
|
||||
QSettings shortCutsFile(settingsFilePath, QSettings::IniFormat);
|
||||
shortCutsFile.beginGroup(custom);
|
||||
shortCutsFile.setValue(name, stringifySequence(Sequence));
|
||||
shortCutsFile.endGroup();
|
||||
emit shortCutChanged();
|
||||
}
|
||||
|
||||
void ShortcutsSettings::setShortcuts(const QString &name, const QKeySequence &Sequence)
|
||||
{
|
||||
setShortcuts(name, QList<QKeySequence>{Sequence});
|
||||
}
|
||||
|
||||
void ShortcutsSettings::setShortcuts(const QString &name, const QString &Sequences)
|
||||
{
|
||||
setShortcuts(name, parseSequenceString(Sequences));
|
||||
}
|
||||
|
||||
void ShortcutsSettings::resetAllShortcuts()
|
||||
{
|
||||
shortCuts = defaultShortCuts;
|
||||
QSettings shortCutsFile(settingsFilePath, QSettings::IniFormat);
|
||||
shortCutsFile.beginGroup(custom);
|
||||
shortCutsFile.remove("");
|
||||
shortCutsFile.endGroup();
|
||||
emit shortCutChanged();
|
||||
}
|
||||
|
||||
void ShortcutsSettings::clearAllShortcuts()
|
||||
{
|
||||
QSettings shortCutsFile(settingsFilePath, QSettings::IniFormat);
|
||||
shortCutsFile.beginGroup(custom);
|
||||
for (auto it = shortCuts.begin(); it != shortCuts.end(); ++it) {
|
||||
it.value().setSequence(parseSequenceString(""));
|
||||
shortCutsFile.setValue(it.key(), "");
|
||||
}
|
||||
shortCutsFile.endGroup();
|
||||
emit shortCutChanged();
|
||||
}
|
||||
|
||||
bool ShortcutsSettings::isKeyAllowed(const QString &name, const QString &Sequences) const
|
||||
{
|
||||
// if the shortcut is not to be used in deck-editor then it doesn't matter
|
||||
if (name.startsWith("Player")) {
|
||||
return true;
|
||||
}
|
||||
QString checkSequence = Sequences.split(sep).last();
|
||||
QStringList forbiddenKeys{"Del", "Backspace", "Down", "Up", "Left", "Right",
|
||||
"Return", "Enter", "Menu", "Ctrl+Alt+-", "Ctrl+Alt+=", "Ctrl+Alt+[",
|
||||
"Ctrl+Alt+]", "Tab", "Space", "Shift+S", "Shift+Left", "Shift+Right"};
|
||||
return !forbiddenKeys.contains(checkSequence);
|
||||
}
|
||||
|
||||
bool ShortcutsSettings::isValid(const QString &name, const QString &Sequences) const
|
||||
{
|
||||
QString checkSequence = Sequences.split(sep).last();
|
||||
QString checkKey = name.left(name.indexOf("/"));
|
||||
|
||||
QList<QString> allKeys = shortCuts.keys();
|
||||
for (const auto &key : allKeys) {
|
||||
if (key.startsWith(checkKey) || key.startsWith("MainWindow") || checkKey.startsWith("MainWindow")) {
|
||||
QString storedSequence = stringifySequence(shortCuts.value(key));
|
||||
QStringList stringSequences = storedSequence.split(sep);
|
||||
if (stringSequences.contains(checkSequence)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue