1
1
Fork 0
forked from suyu/suyu

Merge pull request #2517 from lioncash/hotkey

configure_hotkeys: Minor cleanup
This commit is contained in:
bunnei 2019-05-25 22:58:46 -04:00 committed by GitHub
commit 91300bdfb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 35 deletions

View file

@ -25,9 +25,6 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry)
adjustSize(); adjustSize();
ui->selectorList->setCurrentRow(0); ui->selectorList->setCurrentRow(0);
// Synchronise lists upon initialisation
ui->hotkeysTab->EmitHotkeysChanged();
} }
ConfigureDialog::~ConfigureDialog() = default; ConfigureDialog::~ConfigureDialog() = default;

View file

@ -31,22 +31,6 @@ ConfigureHotkeys::ConfigureHotkeys(QWidget* parent)
ConfigureHotkeys::~ConfigureHotkeys() = default; ConfigureHotkeys::~ConfigureHotkeys() = default;
void ConfigureHotkeys::EmitHotkeysChanged() {
emit HotkeysChanged(GetUsedKeyList());
}
QList<QKeySequence> ConfigureHotkeys::GetUsedKeyList() const {
QList<QKeySequence> list;
for (int r = 0; r < model->rowCount(); r++) {
const QStandardItem* parent = model->item(r, 0);
for (int r2 = 0; r2 < parent->rowCount(); r2++) {
const QStandardItem* keyseq = parent->child(r2, 1);
list << QKeySequence::fromString(keyseq->text(), QKeySequence::NativeText);
}
}
return list;
}
void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) { void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) {
for (const auto& group : registry.hotkey_groups) { for (const auto& group : registry.hotkey_groups) {
auto* parent_item = new QStandardItem(group.first); auto* parent_item = new QStandardItem(group.first);
@ -83,16 +67,29 @@ void ConfigureHotkeys::Configure(QModelIndex index) {
} }
if (IsUsedKey(key_sequence) && key_sequence != QKeySequence(previous_key.toString())) { if (IsUsedKey(key_sequence) && key_sequence != QKeySequence(previous_key.toString())) {
QMessageBox::critical(this, tr("Error in inputted key"), QMessageBox::warning(this, tr("Conflicting Key Sequence"),
tr("You're using a key that's already bound.")); tr("The entered key sequence is already assigned to another hotkey."));
} else { } else {
model->setData(index, key_sequence.toString(QKeySequence::NativeText)); model->setData(index, key_sequence.toString(QKeySequence::NativeText));
EmitHotkeysChanged();
} }
} }
bool ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const { bool ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const {
return GetUsedKeyList().contains(key_sequence); for (int r = 0; r < model->rowCount(); r++) {
const QStandardItem* const parent = model->item(r, 0);
for (int r2 = 0; r2 < parent->rowCount(); r2++) {
const QStandardItem* const key_seq_item = parent->child(r2, 1);
const auto key_seq_str = key_seq_item->text();
const auto key_seq = QKeySequence::fromString(key_seq_str, QKeySequence::NativeText);
if (key_sequence == key_seq) {
return true;
}
}
}
return false;
} }
void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) { void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) {
@ -114,7 +111,6 @@ void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) {
} }
registry.SaveHotkeys(); registry.SaveHotkeys();
Settings::Apply();
} }
void ConfigureHotkeys::retranslateUi() { void ConfigureHotkeys::retranslateUi() {

View file

@ -24,8 +24,6 @@ public:
void applyConfiguration(HotkeyRegistry& registry); void applyConfiguration(HotkeyRegistry& registry);
void retranslateUi(); void retranslateUi();
void EmitHotkeysChanged();
/** /**
* Populates the hotkey list widget using data from the provided registry. * Populates the hotkey list widget using data from the provided registry.
* Called everytime the Configure dialog is opened. * Called everytime the Configure dialog is opened.
@ -33,13 +31,9 @@ public:
*/ */
void Populate(const HotkeyRegistry& registry); void Populate(const HotkeyRegistry& registry);
signals:
void HotkeysChanged(QList<QKeySequence> new_key_list);
private: private:
void Configure(QModelIndex index); void Configure(QModelIndex index);
bool IsUsedKey(QKeySequence key_sequence) const; bool IsUsedKey(QKeySequence key_sequence) const;
QList<QKeySequence> GetUsedKeyList() const;
std::unique_ptr<Ui::ConfigureHotkeys> ui; std::unique_ptr<Ui::ConfigureHotkeys> ui;

View file

@ -9,16 +9,19 @@
SequenceDialog::SequenceDialog(QWidget* parent) : QDialog(parent) { SequenceDialog::SequenceDialog(QWidget* parent) : QDialog(parent) {
setWindowTitle(tr("Enter a hotkey")); setWindowTitle(tr("Enter a hotkey"));
auto* layout = new QVBoxLayout(this); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
key_sequence = new QKeySequenceEdit; key_sequence = new QKeySequenceEdit;
layout->addWidget(key_sequence);
auto* buttons = auto* const buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
buttons->setCenterButtons(true); buttons->setCenterButtons(true);
auto* const layout = new QVBoxLayout(this);
layout->addWidget(key_sequence);
layout->addWidget(buttons); layout->addWidget(buttons);
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
} }
SequenceDialog::~SequenceDialog() = default; SequenceDialog::~SequenceDialog() = default;