From 82a4b1f919a80fe81aed7e968806a61a004f706d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Tue, 22 Mar 2016 18:46:05 +0000 Subject: [PATCH] [GB.QT5] * BUG: Leave events are now correctly sent after a popup menu has been closed. Workaround a QT5 bug. git-svn-id: svn://localhost/gambas/trunk@7657 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.qt4/src/CMenu.cpp | 4 ++++ gb.qt4/src/CWidget.cpp | 43 +++++++++++++++++++++++++++++++++++++++--- gb.qt4/src/CWidget.h | 5 +++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/gb.qt4/src/CMenu.cpp b/gb.qt4/src/CMenu.cpp index 6078dc26b..8a45f60c2 100644 --- a/gb.qt4/src/CMenu.cpp +++ b/gb.qt4/src/CMenu.cpp @@ -327,7 +327,11 @@ BEGIN_METHOD(Menu_new, GB_OBJECT parent; GB_BOOLEAN hidden) if (!menu->menu) { +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) && QT_VERSION < QT_VERSION_CHECK(5,5,0) menu->menu = new MyMenu(); +#else + menu->menu = new QMenu(); +#endif menu->menu->setSeparatorsCollapsible(true); ((QAction *)(menu->widget.widget))->setMenu(menu->menu); diff --git a/gb.qt4/src/CWidget.cpp b/gb.qt4/src/CWidget.cpp index a5a73e30f..9d4a8746d 100644 --- a/gb.qt4/src/CWidget.cpp +++ b/gb.qt4/src/CWidget.cpp @@ -74,14 +74,19 @@ static QMap _x11_to_qt_keycode; CWIDGET *CWIDGET_active_control = 0; CWIDGET *CWIDGET_previous_control = 0; -static bool _focus_change = false; -static CWIDGET *_old_active_control = 0; + int CCONTROL_last_event_type = 0; +static bool _focus_change = false; +static CWIDGET *_old_active_control = 0; static CWIDGET *_hovered = 0; static CWIDGET *_official_hovered = 0; -QSet *_enter_leave_set = NULL; +#ifdef QT5 +static CWIDGET *_last_entered = NULL; +#else +static QSet *_enter_leave_set = NULL; +#endif static QT_COLOR_FUNC _after_set_color = NULL; @@ -346,6 +351,9 @@ static void CWIDGET_enter(void *_object) //qDebug("CWIDGET_enter: %p %s", THIS, THIS->name); if (!THIS->flag.inside) { +#ifdef QT5 + _last_entered = THIS; +#endif THIS->flag.inside = true; GB.Raise(THIS, EVENT_Enter, 0); } @@ -356,6 +364,10 @@ static void CWIDGET_leave(void *_object) //qDebug("CWIDGET_leave: %p %s", THIS, THIS->name); if (THIS->flag.inside) { +#ifdef QT5 + if (_last_entered == THIS) + _last_entered = (CWIDGET *)CWIDGET_get_parent((void *)_last_entered); +#endif THIS->flag.inside = false; GB.Raise(THIS, EVENT_Leave, 0); } @@ -421,6 +433,13 @@ QString CWIDGET_Utf8ToQString(GB_STRING *str) return QString::fromUtf8((const char *)(str->value.addr + str->value.start), str->value.len); } +#ifdef QT5 +void CWIDGET_leave_popup(void *) +{ + while (_last_entered) + CWIDGET_leave(_last_entered); +} +#else void *CWIDGET_enter_popup() { void *save = _enter_leave_set; @@ -464,6 +483,7 @@ static void insert_enter_leave_event(CWIDGET *control, bool in) _enter_leave_set->insert(control); GB.Ref(control); } +#endif static bool _post_check_hovered = false; static CWIDGET *_post_check_hovered_window = NULL; @@ -499,6 +519,11 @@ void CWIDGET_destroy(CWIDGET *_object) return; } +#ifdef QT5 + if (_last_entered == THIS) + _last_entered = NULL; +#endif + //qDebug("CWIDGET_destroy: %s %p", GB.GetClassName(THIS), THIS); CWIDGET_set_visible(THIS, false); @@ -2490,16 +2515,22 @@ bool CWidget::eventFilter(QObject *widget, QEvent *event) __ENTER: { +#ifndef QT5 QWidget *popup = qApp->activePopupWidget(); +#endif //qDebug("enter %s real = %d popup = %p inside = %d", control->name, real, popup, control->flag.inside); if (real) { +#ifdef QT5 + CWIDGET_enter(control); +#else if (!popup || CWidget::getReal(popup)) CWIDGET_enter(control); else if (_enter_leave_set) insert_enter_leave_event(control, true); +#endif } goto __NEXT; @@ -2507,16 +2538,22 @@ bool CWidget::eventFilter(QObject *widget, QEvent *event) __LEAVE: { +#ifndef QT5 QWidget *popup = qApp->activePopupWidget(); +#endif //qDebug("leave %s real = %d popup = %p inside = %d", control->name, real, popup, control->flag.inside); if (real) { +#ifdef QT5 + CWIDGET_leave(control); +#else if (!popup || CWidget::getReal(popup)) CWIDGET_leave(control); else if (_enter_leave_set) insert_enter_leave_event(control, false); +#endif } goto __NEXT; diff --git a/gb.qt4/src/CWidget.h b/gb.qt4/src/CWidget.h index 4d7b6cdb9..72a9c97ff 100644 --- a/gb.qt4/src/CWidget.h +++ b/gb.qt4/src/CWidget.h @@ -216,8 +216,13 @@ void CWIDGET_handle_focus(CWIDGET *control, bool on); void CWIDGET_finish_focus(void); void CWIDGET_register_proxy(void *_object, void *proxy); bool CWIDGET_container_for(void *_object, void *container_for); +#ifdef QT5 +#define CWIDGET_enter_popup() (0) +void CWIDGET_leave_popup(void *); +#else void *CWIDGET_enter_popup(); void CWIDGET_leave_popup(void *save); +#endif void CACTION_register(void *control, const char *old, const char *key); void CACTION_raise(void *control); bool CWIDGET_get_allow_focus(void *_object);