MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / onValidateShortcutButtonClicked

Method onValidateShortcutButtonClicked

Gui/PreferencesPanel.cpp:1510–1580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1508}
1509
1510void
1511PreferencesPanel::onValidateShortcutButtonClicked()
1512{
1513 QString text = _imp->shortcutEditor->text();
1514 QString altText = _imp->altShortcutEditor->text();
1515
1516 QList<QTreeWidgetItem*> items = _imp->shortcutsTree->selectedItems();
1517 if ( (items.size() > 1) || items.empty() ) {
1518 return;
1519 }
1520
1521 QTreeWidgetItem* selection = items.front();
1522 QKeySequence seq(text, QKeySequence::NativeText);
1523 QKeySequence altseq(altText, QKeySequence::NativeText);
1524 BoundAction* action = _imp->getActionForTreeItem(selection);
1525 QTreeWidgetItem* parent = selection->parent();
1526 while (parent) {
1527 QTreeWidgetItem* parentUp = parent->parent();
1528 if (!parentUp) {
1529 break;
1530 }
1531 parent = parentUp;
1532 }
1533 assert(parent);
1534
1535 //only keybinds can be edited...
1536 KeyBoundAction* ka = dynamic_cast<KeyBoundAction*>(action);
1537 assert(ka);
1538 if (!ka) {
1539 return;
1540 }
1541 Qt::KeyboardModifiers modifiers, altmodifiers;
1542 Qt::Key symbol, altsymbmol;
1543 extractKeySequence(seq, modifiers, symbol);
1544 extractKeySequence(altseq, altmodifiers, altsymbmol);
1545
1546 for (GuiAppShorcuts::iterator it = _imp->appShortcuts.begin(); it != _imp->appShortcuts.end(); ++it) {
1547 for (std::list<GuiBoundAction>::iterator it2 = it->actions.begin(); it2 != it->actions.end(); ++it2) {
1548 if ( (it2->action != action) && ( it->item->text(0) == parent->text(0) ) ) {
1549 KeyBoundAction* keyAction = dynamic_cast<KeyBoundAction*>(it2->action);
1550 if (keyAction) {
1551 assert( keyAction->modifiers.size() == keyAction->currentShortcut.size() );
1552 std::list<Qt::KeyboardModifiers>::const_iterator mit = keyAction->modifiers.begin();
1553 for (std::list<Qt::Key>::const_iterator it3 = keyAction->currentShortcut.begin(); it3 != keyAction->currentShortcut.end(); ++it3, ++mit) {
1554 if ( (*mit == modifiers) && (*it3 == symbol) ) {
1555 QString err = QString::fromUtf8("Cannot bind this shortcut because the following action is already using it: %1")
1556 .arg( it2->item->text(0) );
1557 _imp->shortcutEditor->clear();
1558 Dialogs::errorDialog( tr("Shortcuts Editor").toStdString(), tr( err.toStdString().c_str() ).toStdString() );
1559
1560 return;
1561 }
1562 }
1563 }
1564 }
1565 }
1566 }
1567

Callers

nothing calls this directly

Calls 13

extractKeySequenceFunction · 0.85
emptyMethod · 0.80
getActionForTreeItemMethod · 0.80
parentMethod · 0.80
toStdStringMethod · 0.80
notifyShortcutChangedMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
clearMethod · 0.45
setTextMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected