diff --git a/ui/src/CMakeLists.txt b/ui/src/CMakeLists.txt index acb69d739b..5f09c7bf82 100644 --- a/ui/src/CMakeLists.txt +++ b/ui/src/CMakeLists.txt @@ -141,6 +141,7 @@ add_library(${module_name} virtualconsole/vcmatrixproperties.cpp virtualconsole/vcmatrixproperties.h virtualconsole/vcmatrixproperties.ui virtualconsole/vcproperties.cpp virtualconsole/vcproperties.h virtualconsole/vcproperties.ui virtualconsole/vcpropertieseditor.cpp virtualconsole/vcpropertieseditor.h + virtualconsole/vcscrollarea.cpp virtualconsole/vcscrollarea.h virtualconsole/vcslider.cpp virtualconsole/vcslider.h virtualconsole/vcsliderproperties.cpp virtualconsole/vcsliderproperties.h virtualconsole/vcsliderproperties.ui virtualconsole/vcsoloframe.cpp virtualconsole/vcsoloframe.h diff --git a/ui/src/src.pro b/ui/src/src.pro index 8f80738cca..8f6a5f6caf 100644 --- a/ui/src/src.pro +++ b/ui/src/src.pro @@ -155,6 +155,7 @@ HEADERS += virtualconsole/addvcbuttonmatrix.h \ virtualconsole/vcmatrixproperties.h \ virtualconsole/vcproperties.h \ virtualconsole/vcpropertieseditor.h \ + virtualconsole/vcscrollarea.h \ virtualconsole/vcslider.h \ virtualconsole/vcsliderproperties.h \ virtualconsole/vcsoloframe.h \ @@ -337,6 +338,7 @@ SOURCES += virtualconsole/addvcbuttonmatrix.cpp \ virtualconsole/vcmatrixproperties.cpp \ virtualconsole/vcproperties.cpp \ virtualconsole/vcpropertieseditor.cpp \ + virtualconsole/vcscrollarea.cpp \ virtualconsole/vcslider.cpp \ virtualconsole/vcsliderproperties.cpp \ virtualconsole/vcsoloframe.cpp \ diff --git a/ui/src/virtualconsole/vcscrollarea.cpp b/ui/src/virtualconsole/vcscrollarea.cpp new file mode 100644 index 0000000000..e58cd0047a --- /dev/null +++ b/ui/src/virtualconsole/vcscrollarea.cpp @@ -0,0 +1,48 @@ +#include "vcscrollarea.h" +#include "qevent.h" + +#include + +VCScrollArea::VCScrollArea(QWidget *parent) : QScrollArea(parent) { + // nothing more right now +} + +void VCScrollArea::keyPressEvent(QKeyEvent *ev) { + unsigned int keyCode = ev->key() | ev->modifiers(); + QList::const_iterator it = std::find(m_overriddenKeyCodes.constBegin(), m_overriddenKeyCodes.constEnd(), keyCode); + if (it != m_overriddenKeyCodes.constEnd()) + { + ev->ignore(); + } + else + { + QScrollArea::keyPressEvent(ev); + } +} + +bool VCScrollArea::needsOverride(const QKeySequence& ks) { + return ks == QKeySequence::MoveToPreviousPage + || ks == QKeySequence::MoveToNextPage + || ks == QKeySequence(Qt::Key_Up) + || ks == QKeySequence(Qt::Key_Down) + || ks == QKeySequence(Qt::Key_Left) + || ks == QKeySequence(Qt::Key_Right); +} + +void VCScrollArea::setKeyOverrides(const QList &keyOverrides) { + m_overriddenKeyCodes.clear(); + for (QList::const_iterator it = keyOverrides.constBegin(); + it != keyOverrides.constEnd(); ++it) + { + if (needsOverride(*it)) + { + // all our key sequences have only one key + unsigned int keyCode = (*it)[0]; + m_overriddenKeyCodes.append(keyCode); + } + } +} + +void VCScrollArea::clearKeyOverrides() { + m_overriddenKeyCodes.clear(); +} diff --git a/ui/src/virtualconsole/vcscrollarea.h b/ui/src/virtualconsole/vcscrollarea.h new file mode 100644 index 0000000000..261ecc3530 --- /dev/null +++ b/ui/src/virtualconsole/vcscrollarea.h @@ -0,0 +1,26 @@ +#ifndef VCSCROLLAREA_H +#define VCSCROLLAREA_H + +#include +#include +#include + +class VCScrollArea : public QScrollArea +{ + Q_OBJECT +public: + explicit VCScrollArea(QWidget *parent = nullptr); + + static bool needsOverride(const QKeySequence& keySequence); + + void setKeyOverrides(const QList &keyOverrides); + void clearKeyOverrides(); + +protected: + void keyPressEvent(QKeyEvent *) override; + +private: + QList m_overriddenKeyCodes; +}; + +#endif // VCSCROLLAREA_H diff --git a/ui/src/virtualconsole/virtualconsole.cpp b/ui/src/virtualconsole/virtualconsole.cpp index 44aeda860a..fcfd5db09d 100644 --- a/ui/src/virtualconsole/virtualconsole.cpp +++ b/ui/src/virtualconsole/virtualconsole.cpp @@ -1583,7 +1583,7 @@ void VirtualConsole::initContents() { Q_ASSERT(layout() != NULL); - m_scrollArea = new QScrollArea(this); + m_scrollArea = new VCScrollArea(this); m_contentsLayout->addWidget(m_scrollArea); m_scrollArea->setAlignment(Qt::AlignCenter); m_scrollArea->setWidgetResizable(false); @@ -1661,6 +1661,8 @@ bool VirtualConsole::liveEdit() const void VirtualConsole::enableEdit() { + disableKeyOverrides(); + // Allow editing and adding in design mode m_toolsSettingsAction->setEnabled(true); m_editActionGroup->setEnabled(true); @@ -1759,6 +1761,8 @@ void VirtualConsole::disableEdit() m_stackingRaiseAction->setShortcut(QKeySequence()); m_stackingLowerAction->setShortcut(QKeySequence()); + enableKeyOverrides(); + // Hide toolbar; there's nothing usable there in operate mode m_toolbar->hide(); @@ -1768,6 +1772,25 @@ void VirtualConsole::disableEdit() m_contents->setFocus(); } +void VirtualConsole::enableKeyOverrides() { + QList keySequencesToOverride; + + for (QHash::const_iterator it = m_widgetsMap.constBegin(); + it != m_widgetsMap.constEnd(); ++it) + { + VCButton *btn = qobject_cast(*it); + if (btn) + { + keySequencesToOverride.append(btn->keySequence()); + } + } + m_scrollArea->setKeyOverrides(keySequencesToOverride); +} + +void VirtualConsole::disableKeyOverrides() { + m_scrollArea->clearKeyOverrides(); +} + void VirtualConsole::slotModeChanged(Doc::Mode mode) { if (mode == Doc::Operate) diff --git a/ui/src/virtualconsole/virtualconsole.h b/ui/src/virtualconsole/virtualconsole.h index 9b3d642626..5aa517fabb 100644 --- a/ui/src/virtualconsole/virtualconsole.h +++ b/ui/src/virtualconsole/virtualconsole.h @@ -26,6 +26,7 @@ #include #include +#include "vcscrollarea.h" #include "vcproperties.h" #include "doc.h" @@ -34,7 +35,7 @@ class QXmlStreamWriter; class VirtualConsole; class QActionGroup; class QVBoxLayout; -class QScrollArea; +class VCScrollArea; class VCDockArea; class QKeyEvent; class QToolBar; @@ -336,13 +337,16 @@ public slots: protected: QVBoxLayout* m_contentsLayout; - QScrollArea* m_scrollArea; + VCScrollArea* m_scrollArea; VCFrame* m_contents; QHash m_widgetsMap; /********************************************************************* * Key press handler *********************************************************************/ +private: + void enableKeyOverrides(); + void disableKeyOverrides(); protected: /** Handler for keyboard key presse events */