Skip to content

Commit

Permalink
Fix: Reset shortcuts to default
Browse files Browse the repository at this point in the history
Improve: Better shortcuts ordering in dialog
  • Loading branch information
Delwing committed Nov 30, 2021
1 parent b8b785d commit eac4758
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/XMLimport.cpp
Expand Up @@ -1878,10 +1878,13 @@ void XMLimport::readProfileShortcuts() {
if (isStartElement()) {
if (name() == "profileShortcut") {
auto key = attributes().value(QStringLiteral("key"));
auto sequenceString = readElementText();
QKeySequence* sequence = !sequenceString.isEmpty() ? new QKeySequence(sequenceString) : new QKeySequence();
mpHost->profileShortcuts.value(key.toString())->swap(*sequence);
delete sequence;
if (mpHost->profileShortcuts.value(key.toString())) {
auto sequenceString = readElementText();
QKeySequence *sequence = !sequenceString.isEmpty() ? new QKeySequence(sequenceString)
: new QKeySequence();
mpHost->profileShortcuts.value(key.toString())->swap(*sequence);
delete sequence;
}
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/dlgProfilePreferences.cpp
Expand Up @@ -1158,15 +1158,15 @@ void dlgProfilePreferences::initWithHost(Host* pHost)
connect(doubleSpinBox_networkPacketTimeout, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &dlgProfilePreferences::slot_setPostingTimeout);

//Shortcuts tab
QMapIterator<QString, QKeySequence*> i(pHost->profileShortcuts);
auto shortcutKeys = mudlet::self()->mShortcutsManager->iterator();
int shortcutsRow = 0;
while (i.hasNext()) {
i.next();
QKeySequence* sequence = new QKeySequence(*i.value());
currentShortcuts.insert(i.key(), sequence);
while (shortcutKeys.hasNext()) {
auto key = shortcutKeys.next();
QKeySequence* sequence = new QKeySequence(*pHost->profileShortcuts.value(key));
currentShortcuts.insert(key, sequence);
auto sequenceEdit = new QKeySequenceEdit(*sequence);

gridLayout_groupBox_shortcuts->addWidget(new QLabel(i.key()), floor(shortcutsRow / 2), (shortcutsRow % 2) * 2 + 1);
gridLayout_groupBox_shortcuts->addWidget(new QLabel(key), floor(shortcutsRow / 2), (shortcutsRow % 2) * 2 + 1);
gridLayout_groupBox_shortcuts->addWidget(sequenceEdit, floor(shortcutsRow / 2), (shortcutsRow % 2) * 2 + 2);
shortcutsRow++;
connect(sequenceEdit, &QKeySequenceEdit::editingFinished, this, [=]() {
Expand All @@ -1184,7 +1184,9 @@ void dlgProfilePreferences::initWithHost(Host* pHost)
sequence->swap(newSequence);
});
connect(this, &dlgProfilePreferences::signal_resetMainWindowShortcutsToDefaults, sequenceEdit, [=]() {
sequenceEdit->setKeySequence(*mudlet::self()->mShortcutsManager->getDefault(i.key()));
sequenceEdit->setKeySequence(*mudlet::self()->mShortcutsManager->getDefault(key));
QKeySequence newSequence = QKeySequence(*mudlet::self()->mShortcutsManager->getDefault(key));
sequence->swap(newSequence);
});
}

Expand Down

0 comments on commit eac4758

Please sign in to comment.