diff options
| author | 2019-05-25 22:58:46 -0400 | |
|---|---|---|
| committer | 2019-05-25 22:58:46 -0400 | |
| commit | 91300bdfb2c243dddea4f23fab752d47c9ad66a3 (patch) | |
| tree | c7080e0146a804680477354b58779ab934138118 /src | |
| parent | Merge pull request #2513 from lioncash/string (diff) | |
| parent | configure_hotkeys: Remove unnecessary Settings::Apply() call (diff) | |
| download | yuzu-91300bdfb2c243dddea4f23fab752d47c9ad66a3.tar.gz yuzu-91300bdfb2c243dddea4f23fab752d47c9ad66a3.tar.xz yuzu-91300bdfb2c243dddea4f23fab752d47c9ad66a3.zip | |
Merge pull request #2517 from lioncash/hotkey
configure_hotkeys: Minor cleanup
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_dialog.cpp | 3 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.cpp | 38 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.h | 6 | ||||
| -rw-r--r-- | src/yuzu/util/sequence_dialog/sequence_dialog.cpp | 13 |
4 files changed, 25 insertions, 35 deletions
diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 32c05b797..8086f9d6b 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp | |||
| @@ -25,9 +25,6 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry) | |||
| 25 | 25 | ||
| 26 | adjustSize(); | 26 | adjustSize(); |
| 27 | ui->selectorList->setCurrentRow(0); | 27 | ui->selectorList->setCurrentRow(0); |
| 28 | |||
| 29 | // Synchronise lists upon initialisation | ||
| 30 | ui->hotkeysTab->EmitHotkeysChanged(); | ||
| 31 | } | 28 | } |
| 32 | 29 | ||
| 33 | ConfigureDialog::~ConfigureDialog() = default; | 30 | ConfigureDialog::~ConfigureDialog() = default; |
diff --git a/src/yuzu/configuration/configure_hotkeys.cpp b/src/yuzu/configuration/configure_hotkeys.cpp index a7a8752e5..9fb970c21 100644 --- a/src/yuzu/configuration/configure_hotkeys.cpp +++ b/src/yuzu/configuration/configure_hotkeys.cpp | |||
| @@ -31,22 +31,6 @@ ConfigureHotkeys::ConfigureHotkeys(QWidget* parent) | |||
| 31 | 31 | ||
| 32 | ConfigureHotkeys::~ConfigureHotkeys() = default; | 32 | ConfigureHotkeys::~ConfigureHotkeys() = default; |
| 33 | 33 | ||
| 34 | void ConfigureHotkeys::EmitHotkeysChanged() { | ||
| 35 | emit HotkeysChanged(GetUsedKeyList()); | ||
| 36 | } | ||
| 37 | |||
| 38 | QList<QKeySequence> ConfigureHotkeys::GetUsedKeyList() const { | ||
| 39 | QList<QKeySequence> list; | ||
| 40 | for (int r = 0; r < model->rowCount(); r++) { | ||
| 41 | const QStandardItem* parent = model->item(r, 0); | ||
| 42 | for (int r2 = 0; r2 < parent->rowCount(); r2++) { | ||
| 43 | const QStandardItem* keyseq = parent->child(r2, 1); | ||
| 44 | list << QKeySequence::fromString(keyseq->text(), QKeySequence::NativeText); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | return list; | ||
| 48 | } | ||
| 49 | |||
| 50 | void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) { | 34 | void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) { |
| 51 | for (const auto& group : registry.hotkey_groups) { | 35 | for (const auto& group : registry.hotkey_groups) { |
| 52 | auto* parent_item = new QStandardItem(group.first); | 36 | auto* parent_item = new QStandardItem(group.first); |
| @@ -83,16 +67,29 @@ void ConfigureHotkeys::Configure(QModelIndex index) { | |||
| 83 | } | 67 | } |
| 84 | 68 | ||
| 85 | if (IsUsedKey(key_sequence) && key_sequence != QKeySequence(previous_key.toString())) { | 69 | if (IsUsedKey(key_sequence) && key_sequence != QKeySequence(previous_key.toString())) { |
| 86 | QMessageBox::critical(this, tr("Error in inputted key"), | 70 | QMessageBox::warning(this, tr("Conflicting Key Sequence"), |
| 87 | tr("You're using a key that's already bound.")); | 71 | tr("The entered key sequence is already assigned to another hotkey.")); |
| 88 | } else { | 72 | } else { |
| 89 | model->setData(index, key_sequence.toString(QKeySequence::NativeText)); | 73 | model->setData(index, key_sequence.toString(QKeySequence::NativeText)); |
| 90 | EmitHotkeysChanged(); | ||
| 91 | } | 74 | } |
| 92 | } | 75 | } |
| 93 | 76 | ||
| 94 | bool ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const { | 77 | bool ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const { |
| 95 | return GetUsedKeyList().contains(key_sequence); | 78 | for (int r = 0; r < model->rowCount(); r++) { |
| 79 | const QStandardItem* const parent = model->item(r, 0); | ||
| 80 | |||
| 81 | for (int r2 = 0; r2 < parent->rowCount(); r2++) { | ||
| 82 | const QStandardItem* const key_seq_item = parent->child(r2, 1); | ||
| 83 | const auto key_seq_str = key_seq_item->text(); | ||
| 84 | const auto key_seq = QKeySequence::fromString(key_seq_str, QKeySequence::NativeText); | ||
| 85 | |||
| 86 | if (key_sequence == key_seq) { | ||
| 87 | return true; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | return false; | ||
| 96 | } | 93 | } |
| 97 | 94 | ||
| 98 | void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) { | 95 | void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) { |
| @@ -114,7 +111,6 @@ void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) { | |||
| 114 | } | 111 | } |
| 115 | 112 | ||
| 116 | registry.SaveHotkeys(); | 113 | registry.SaveHotkeys(); |
| 117 | Settings::Apply(); | ||
| 118 | } | 114 | } |
| 119 | 115 | ||
| 120 | void ConfigureHotkeys::retranslateUi() { | 116 | void ConfigureHotkeys::retranslateUi() { |
diff --git a/src/yuzu/configuration/configure_hotkeys.h b/src/yuzu/configuration/configure_hotkeys.h index 73fb8a175..e77d73c35 100644 --- a/src/yuzu/configuration/configure_hotkeys.h +++ b/src/yuzu/configuration/configure_hotkeys.h | |||
| @@ -24,8 +24,6 @@ public: | |||
| 24 | void applyConfiguration(HotkeyRegistry& registry); | 24 | void applyConfiguration(HotkeyRegistry& registry); |
| 25 | void retranslateUi(); | 25 | void retranslateUi(); |
| 26 | 26 | ||
| 27 | void EmitHotkeysChanged(); | ||
| 28 | |||
| 29 | /** | 27 | /** |
| 30 | * Populates the hotkey list widget using data from the provided registry. | 28 | * Populates the hotkey list widget using data from the provided registry. |
| 31 | * Called everytime the Configure dialog is opened. | 29 | * Called everytime the Configure dialog is opened. |
| @@ -33,13 +31,9 @@ public: | |||
| 33 | */ | 31 | */ |
| 34 | void Populate(const HotkeyRegistry& registry); | 32 | void Populate(const HotkeyRegistry& registry); |
| 35 | 33 | ||
| 36 | signals: | ||
| 37 | void HotkeysChanged(QList<QKeySequence> new_key_list); | ||
| 38 | |||
| 39 | private: | 34 | private: |
| 40 | void Configure(QModelIndex index); | 35 | void Configure(QModelIndex index); |
| 41 | bool IsUsedKey(QKeySequence key_sequence) const; | 36 | bool IsUsedKey(QKeySequence key_sequence) const; |
| 42 | QList<QKeySequence> GetUsedKeyList() const; | ||
| 43 | 37 | ||
| 44 | std::unique_ptr<Ui::ConfigureHotkeys> ui; | 38 | std::unique_ptr<Ui::ConfigureHotkeys> ui; |
| 45 | 39 | ||
diff --git a/src/yuzu/util/sequence_dialog/sequence_dialog.cpp b/src/yuzu/util/sequence_dialog/sequence_dialog.cpp index d3edf6ec3..bb5f74ec4 100644 --- a/src/yuzu/util/sequence_dialog/sequence_dialog.cpp +++ b/src/yuzu/util/sequence_dialog/sequence_dialog.cpp | |||
| @@ -9,16 +9,19 @@ | |||
| 9 | 9 | ||
| 10 | SequenceDialog::SequenceDialog(QWidget* parent) : QDialog(parent) { | 10 | SequenceDialog::SequenceDialog(QWidget* parent) : QDialog(parent) { |
| 11 | setWindowTitle(tr("Enter a hotkey")); | 11 | setWindowTitle(tr("Enter a hotkey")); |
| 12 | auto* layout = new QVBoxLayout(this); | 12 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); |
| 13 | |||
| 13 | key_sequence = new QKeySequenceEdit; | 14 | key_sequence = new QKeySequenceEdit; |
| 14 | layout->addWidget(key_sequence); | 15 | |
| 15 | auto* buttons = | 16 | auto* const buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
| 16 | new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal); | ||
| 17 | buttons->setCenterButtons(true); | 17 | buttons->setCenterButtons(true); |
| 18 | |||
| 19 | auto* const layout = new QVBoxLayout(this); | ||
| 20 | layout->addWidget(key_sequence); | ||
| 18 | layout->addWidget(buttons); | 21 | layout->addWidget(buttons); |
| 22 | |||
| 19 | connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); | 23 | connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); |
| 20 | connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); | 24 | connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); |
| 21 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); | ||
| 22 | } | 25 | } |
| 23 | 26 | ||
| 24 | SequenceDialog::~SequenceDialog() = default; | 27 | SequenceDialog::~SequenceDialog() = default; |