diff --git a/Modules/QtWidgetsExt/src/QmitkHotkeyLineEdit.cpp b/Modules/QtWidgetsExt/src/QmitkHotkeyLineEdit.cpp index f15f2c3b18..110228df8b 100644 --- a/Modules/QtWidgetsExt/src/QmitkHotkeyLineEdit.cpp +++ b/Modules/QtWidgetsExt/src/QmitkHotkeyLineEdit.cpp @@ -1,97 +1,97 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkHotkeyLineEdit.h" #include #include #include #include const std::string QmitkHotkeyLineEdit::TOOLTIP = "Press any key (combination)"; QmitkHotkeyLineEdit::QmitkHotkeyLineEdit(QWidget* parent /*= nullptr*/) : QLineEdit(parent) { Init(); } QmitkHotkeyLineEdit::QmitkHotkeyLineEdit(const QKeySequence& qKeySequence, QWidget* parent /*= nullptr*/) : QLineEdit(parent) { Init(); SetKeySequence(qKeySequence); } QmitkHotkeyLineEdit::QmitkHotkeyLineEdit(const QString& qKeySequenceAsString, QWidget* parent /*= nullptr*/) : QLineEdit(parent) { Init(); SetKeySequence(qKeySequenceAsString); } void QmitkHotkeyLineEdit::Init() { setToolTip(QString::fromStdString(QmitkHotkeyLineEdit::TOOLTIP)); setReadOnly(true); connect(this, &QLineEdit::textChanged, this, &QmitkHotkeyLineEdit::LineEditTextChanged); } void QmitkHotkeyLineEdit::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_unknown) { return; } else if (event->key() == Qt::Key_Escape) { m_KeySequence = QKeySequence(); } else { - m_KeySequence = QKeySequence(event->modifiers() + event->key()); + m_KeySequence = QKeySequence(event->modifiers() | event->key()); } SetKeySequence(m_KeySequence); } void QmitkHotkeyLineEdit::SetKeySequence(const QKeySequence& qKeySequence) { setText(qKeySequence.toString()); } void QmitkHotkeyLineEdit::SetKeySequence(const QString& qKeySequenceAsString) { SetKeySequence(QKeySequence(qKeySequenceAsString)); } QKeySequence QmitkHotkeyLineEdit::GetKeySequence() { return m_KeySequence; } QString QmitkHotkeyLineEdit::GetKeySequenceAsString() { return m_KeySequence.toString(); } bool QmitkHotkeyLineEdit::Matches(QKeyEvent* event) { - QKeySequence keySequence = QKeySequence(event->modifiers() + event->key()); + QKeySequence keySequence = QKeySequence(event->modifiers() | event->key()); return keySequence == m_KeySequence; } void QmitkHotkeyLineEdit::LineEditTextChanged(const QString& text) { m_KeySequence = QKeySequence(text.toUpper()); } diff --git a/Plugins/org.mitk.gui.qt.datamanager/src/internal/QmitkNodeTableViewKeyFilter.cpp b/Plugins/org.mitk.gui.qt.datamanager/src/internal/QmitkNodeTableViewKeyFilter.cpp index 23e017ba55..f32ab1c17d 100644 --- a/Plugins/org.mitk.gui.qt.datamanager/src/internal/QmitkNodeTableViewKeyFilter.cpp +++ b/Plugins/org.mitk.gui.qt.datamanager/src/internal/QmitkNodeTableViewKeyFilter.cpp @@ -1,124 +1,124 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkNodeTableViewKeyFilter.h" #include "../QmitkDataManagerView.h" // mitk gui qt application plugin #include #include #include #include #include #include #include #include #include // qt #include #include namespace { mitk::IPreferences* GetPreferences() { auto* preferencesService = mitk::CoreServices::GetPreferencesService(); return preferencesService->GetSystemPreferences()->Node("DataManager/Hotkeys"); } } QmitkNodeTableViewKeyFilter::QmitkNodeTableViewKeyFilter(QObject *dataManagerView, mitk::DataStorage *dataStorage) : QObject(dataManagerView), m_DataStorage(dataStorage) { } bool QmitkNodeTableViewKeyFilter::eventFilter(QObject *obj, QEvent *event) { auto dataStorage = m_DataStorage.Lock(); if (dataStorage.IsNull()) { // standard event processing return QObject::eventFilter(obj, event); } QmitkDataManagerView *dataManagerView = qobject_cast(this->parent()); if (event->type() == QEvent::KeyPress && dataManagerView) { auto* prefs = GetPreferences(); QKeySequence makeAllInvisible = QKeySequence(QString::fromStdString(prefs->Get("Make all nodes invisible", "Ctrl+V"))); QKeySequence toggleVisibility = QKeySequence(QString::fromStdString(prefs->Get("Toggle visibility of selected nodes", "V"))); QKeySequence deleteSelectedNodes = QKeySequence(QString::fromStdString(prefs->Get("Delete selected nodes", "Del"))); QKeySequence reinit = QKeySequence(QString::fromStdString(prefs->Get("Reinit selected nodes", "R"))); QKeySequence globalReinit = QKeySequence(QString::fromStdString(prefs->Get("Global reinit", "Ctrl+R"))); QKeySequence showInfo = QKeySequence(QString::fromStdString(prefs->Get("Show node information", "Ctrl+I"))); QKeyEvent *keyEvent = static_cast(event); - QKeySequence keySequence = QKeySequence(keyEvent->modifiers() + keyEvent->key()); + QKeySequence keySequence = QKeySequence(keyEvent->modifiers() | keyEvent->key()); // if no modifier was pressed the sequence is now empty if (keySequence.isEmpty()) { keySequence = QKeySequence(keyEvent->key()); } auto selectedNodes = AbstractDataNodeAction::GetSelectedNodes(dataManagerView->GetSite()); if (keySequence == makeAllInvisible) { if (selectedNodes.empty()) { // if no nodes are selected, hide all nodes of the data storage auto nodeset = dataStorage->GetAll(); for (auto it = nodeset->Begin(); it != nodeset->End(); ++it) { mitk::DataNode* node = it->Value(); if (nullptr != node) { selectedNodes.push_back(node); } } } HideAllAction::Run(selectedNodes); return true; } if (keySequence == deleteSelectedNodes) { RemoveAction::Run(dataManagerView->GetSite(), dataStorage, selectedNodes); return true; } if (keySequence == toggleVisibility) { ToggleVisibilityAction::Run(dataManagerView->GetSite(), dataStorage, selectedNodes); return true; } if (keySequence == reinit) { ReinitAction::Run(dataManagerView->GetSite(), dataStorage, selectedNodes); return true; } if (keySequence == globalReinit) { GlobalReinitAction::Run(dataManagerView->GetSite(), dataStorage); return true; } if (keySequence == showInfo) { ShowDetailsAction::Run(selectedNodes); return true; } } // standard event processing return QObject::eventFilter(obj, event); }