From f8505429ee44e5ee189d66f2d5fc4631c65cc1b8 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 15 Jun 2014 19:16:52 +0200 Subject: [PATCH] Moved the event listener from the 3d widget to the gui control class. --HG-- branch : gsoc2014-dfighter --- .../src/plugins/gui_editor/nel3d_widget.cpp | 7 +------ code/studio/src/plugins/gui_editor/nel3d_widget.h | 6 ------ .../studio/src/plugins/gui_editor/nelgui_ctrl.cpp | 15 +++++++++++++++ code/studio/src/plugins/gui_editor/nelgui_ctrl.h | 10 +++++++++- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/nel3d_widget.cpp b/code/studio/src/plugins/gui_editor/nel3d_widget.cpp index 3fd7abb7b..5be8bacb8 100644 --- a/code/studio/src/plugins/gui_editor/nel3d_widget.cpp +++ b/code/studio/src/plugins/gui_editor/nel3d_widget.cpp @@ -21,8 +21,7 @@ #include "nel/3d/driver_user.h" #include "nel/misc/rgba.h" #include "nel/misc/path.h" -#include "nel/misc/event_listener.h" -#include "nel/gui/event_listener.h" +//#include "nel/misc/event_listener.h" #ifdef NL_OS_WINDOWS #include @@ -42,7 +41,6 @@ namespace GUIEditor // so that we can render the widget normally ourselves, without the image // disappearing when a widget is resized or shown on top of us setAttribute( Qt::WA_PaintOnScreen, true ); - eventListener = NULL; } Nel3DWidget::~Nel3DWidget() @@ -59,7 +57,6 @@ namespace GUIEditor delete driver; driver = NULL; } - delete eventListener; } void Nel3DWidget::init() @@ -69,8 +66,6 @@ namespace GUIEditor driver = NL3D::UDriver::createDriver( 0, false, 0 ); driver->setMatrixMode2D11(); driver->setDisplay( winId(), NL3D::UDriver::CMode( width(), height(), 32, true ) ); - eventListener = new NLGUI::CEventListener(); - eventListener->addToServer( &driver->EventServer ); } void Nel3DWidget::createTextContext( std::string fontFile ) diff --git a/code/studio/src/plugins/gui_editor/nel3d_widget.h b/code/studio/src/plugins/gui_editor/nel3d_widget.h index fb4321d49..07a74b8c3 100644 --- a/code/studio/src/plugins/gui_editor/nel3d_widget.h +++ b/code/studio/src/plugins/gui_editor/nel3d_widget.h @@ -22,11 +22,6 @@ #include "nel/misc/types_nl.h" #include -namespace NLGUI -{ - class CEventListener; -} - namespace NL3D { class UDriver; @@ -71,7 +66,6 @@ namespace GUIEditor private: NL3D::UDriver *driver; NL3D::UTextContext *textContext; - NLGUI::CEventListener *eventListener; }; } diff --git a/code/studio/src/plugins/gui_editor/nelgui_ctrl.cpp b/code/studio/src/plugins/gui_editor/nelgui_ctrl.cpp index 2a9a433ee..4e72ba614 100644 --- a/code/studio/src/plugins/gui_editor/nelgui_ctrl.cpp +++ b/code/studio/src/plugins/gui_editor/nelgui_ctrl.cpp @@ -22,6 +22,7 @@ #include "nel/gui/widget_manager.h" #include "nel/gui/action_handler.h" #include "nel/gui/lua_manager.h" +#include "nel/gui/event_listener.h" #include "nel/misc/path.h" #include "nel/misc/i18n.h" #include @@ -42,6 +43,8 @@ namespace GUIEditor guiLoaded = false; watcher = NULL; w = new Nel3DWidget(); + eventListener = new NLGUI::CEventListener(); + listening = false; } NelGUICtrl::~NelGUICtrl() @@ -157,6 +160,12 @@ namespace GUIEditor { if( timerID == 0 ) timerID = startTimer( 200 ); + + if( !listening ) + { + eventListener->addToServer( &w->getDriver()->EventServer ); + listening = true; + } } void NelGUICtrl::hide() @@ -166,6 +175,12 @@ namespace GUIEditor killTimer( timerID ); timerID = 0; } + + if( listening ) + { + eventListener->removeFromServer(); + listening = false; + } } QWidget* NelGUICtrl::getViewPort() diff --git a/code/studio/src/plugins/gui_editor/nelgui_ctrl.h b/code/studio/src/plugins/gui_editor/nelgui_ctrl.h index 38da599e4..f13a57b9b 100644 --- a/code/studio/src/plugins/gui_editor/nelgui_ctrl.h +++ b/code/studio/src/plugins/gui_editor/nelgui_ctrl.h @@ -23,6 +23,11 @@ class QWidget; +namespace NLGUI +{ + class CEventListener; +} + namespace GUIEditor { class CEditorSelectionWatcher; @@ -58,8 +63,11 @@ Q_SIGNALS: bool guiLoaded; CEditorSelectionWatcher *watcher; + NLGUI::CEventListener *eventListener; + + Nel3DWidget *w; - Nel3DWidget *w; + bool listening; }; }