From 7396eef0672cbbeda31e8cd663bf860e9a7a76e7 Mon Sep 17 00:00:00 2001 From: Garux Date: Mon, 3 Jul 2023 12:26:20 +0600 Subject: [PATCH] * fix QComboBox popup leaking shortcuts --- contrib/bobtoolz/dialogs/dialogs-gtk.cpp | 6 +++--- contrib/prtview/ConfigDialog.cpp | 4 ++-- libs/gtkutil/combobox.h | 22 +++++++++++++++++++++- radiant/entityinspector.cpp | 4 ++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp index 6497646b..39e9434f 100644 --- a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp +++ b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp @@ -41,8 +41,8 @@ #include #include #include -#include #include "gtkutil/spinbox.h" +#include "gtkutil/combobox.h" /*-------------------------------- @@ -258,7 +258,7 @@ bool DoDoorsBox( DoorRS* rs ){ auto form = new QFormLayout( &dialog ); form->setSizeConstraint( QLayout::SizeConstraint::SetFixedSize ); { - form->addRow( "Door Front/Back Texture", comboMain = new QComboBox ); + form->addRow( "Door Front/Back Texture", comboMain = new ComboBox ); char buffer[256]; comboMain->addItems( LoadListStore( GetFilename( buffer, "bt/door-tex.txt" ) ) ); comboMain->setEditable( true ); @@ -272,7 +272,7 @@ bool DoDoorsBox( DoorRS* rs ){ checkScaleMainV->setChecked( true ); } { - form->addRow( "Door Trim Texture", comboTrim = new QComboBox ); + form->addRow( "Door Trim Texture", comboTrim = new ComboBox ); char buffer[256]; comboTrim->addItems( LoadListStore( GetFilename( buffer, "bt/door-tex-trim.txt" ) ) ); comboTrim->setEditable( true ); diff --git a/contrib/prtview/ConfigDialog.cpp b/contrib/prtview/ConfigDialog.cpp index 9394662c..a5c2a242 100644 --- a/contrib/prtview/ConfigDialog.cpp +++ b/contrib/prtview/ConfigDialog.cpp @@ -33,8 +33,8 @@ #include #include #include -#include #include +#include "gtkutil/combobox.h" static void OnColor( PackedColour& clr ){ @@ -132,7 +132,7 @@ void DoConfigDialog(){ form_add_slider( form, portals.clip_range, 64, 8192, "Clip range = ", "", false ); } { - auto combo = new QComboBox; + auto combo = new ComboBox; vbox->addWidget( combo ); combo->addItem( "Z-Buffer Test and Write (recommended for solid or no polygons)" ); combo->addItem( "Z-Buffer Test Only (recommended for transparent polygons)" ); diff --git a/libs/gtkutil/combobox.h b/libs/gtkutil/combobox.h index 28bc13f3..f177a5dd 100644 --- a/libs/gtkutil/combobox.h +++ b/libs/gtkutil/combobox.h @@ -23,12 +23,17 @@ #include #include +#include /// @brief Subclassed QComboBox not comsuming Enter key (why does it do it? works as expected for editable ComboBox) /// purpose is to have working confirmation by Enter in dialogs -/// fixme unsolved crude problem here is triggering arrows, page, home, end global shortcuts when pressed in popup; even if modal dialog 😱 +/// +fixes crude problem: triggering arrows, page, home, end global shortcuts when pressed in popup; even if modal dialog 😱 class ComboBox : public QComboBox { +public: + ComboBox( QWidget *parent = nullptr ) : QComboBox( parent ){ + this->view()->installEventFilter( this ); + } protected: void keyPressEvent( QKeyEvent *event ) override { if( event->key() == Qt::Key_Enter @@ -38,4 +43,19 @@ protected: } QComboBox::keyPressEvent( event ); } + bool eventFilter( QObject *obj, QEvent *event ) override { + // the popup leaks ALL shortcuts 😱 to global space 😱😱😱 besides ones handled in QComboBoxPrivateContainer::eventFilter + // it very bad, can interact with the editor while in modal dialog and crash it + // filter them all besides ones, taken by the other filter + if( event->type() == QEvent::ShortcutOverride ) { + QKeyEvent *keyEvent = static_cast( event ); + if( keyEvent->key() != Qt::Key_Return + && keyEvent->key() != Qt::Key_Enter + && !keyEvent->matches( QKeySequence::Cancel ) ){ + event->accept(); + return true; + } + } + return QObject::eventFilter( obj, event ); // standard event processing + } }; diff --git a/radiant/entityinspector.cpp b/radiant/entityinspector.cpp index a06f61f1..4d3fd257 100644 --- a/radiant/entityinspector.cpp +++ b/radiant/entityinspector.cpp @@ -51,7 +51,7 @@ #include #include #include -#include +#include "gtkutil/combobox.h" #include "os/path.h" #include "eclasslib.h" @@ -651,7 +651,7 @@ class ListAttribute final : public EntityAttribute public: ListAttribute( const char* key, const ListAttributeType& type ) : m_key( key ), - m_combo( new QComboBox ), + m_combo( new ComboBox ), m_type( type ){ for ( const auto&[ name, value ] : type ) {