From 3a7f25bc79b88db857ead6e7deecdbebfe419d93 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 23 Feb 2013 00:13:44 +0100 Subject: [PATCH 01/25] MODIFIED: Views can now be selected too from the central widget. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/ctrl_base.h | 4 +-- code/nel/include/nel/gui/interface_element.h | 1 + code/nel/include/nel/gui/view_base.h | 4 +++ code/nel/include/nel/gui/view_text.h | 2 ++ code/nel/include/nel/gui/widget_manager.h | 3 ++ code/nel/src/gui/ctrl_base.cpp | 3 ++ code/nel/src/gui/ctrl_base_button.cpp | 6 ---- code/nel/src/gui/view_base.cpp | 18 ++++++++++ code/nel/src/gui/view_text.cpp | 5 +++ code/nel/src/gui/widget_manager.cpp | 37 ++++++++++++++++++-- 10 files changed, 72 insertions(+), 11 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_base.h b/code/nel/include/nel/gui/ctrl_base.h index fe8d5ea60..28eeb2cd0 100644 --- a/code/nel/include/nel/gui/ctrl_base.h +++ b/code/nel/include/nel/gui/ctrl_base.h @@ -68,9 +68,7 @@ namespace NLGUI // special parse virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup); - - /// Handle all events (implemented by derived classes) (return true to signal event handled) - virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + bool handleEvent (const NLGUI::CEventDescriptor &event); virtual CCtrlBase *getSubCtrl (sint32 /* x */, sint32 /* y */) { return this; } diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 210c24b2e..570dbf689 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -473,6 +473,7 @@ namespace NLGUI bool isInGroup( CInterfaceGroup *group ); static void setEditorMode( bool b ){ editorMode = b; } + static bool getEditorMode(){ return editorMode; } void setEditorSelected( bool b ){ editorSelected = b; } bool isEditorSelected() const{ return editorSelected; } diff --git a/code/nel/include/nel/gui/view_base.h b/code/nel/include/nel/gui/view_base.h index b7d2aceab..f64803720 100644 --- a/code/nel/include/nel/gui/view_base.h +++ b/code/nel/include/nel/gui/view_base.h @@ -25,6 +25,7 @@ namespace NLGUI { + class CEventDescriptor; class CViewBase : public CInterfaceElement { @@ -76,6 +77,9 @@ namespace NLGUI // special for mouse over : return true and fill the name of the cursor to display virtual bool getMouseOverShape(std::string &/* texName */, uint8 &/* rot */, NLMISC::CRGBA &/* col */) { return false; } + + /// Handle all events (implemented by derived classes) (return true to signal event handled) + virtual bool handleEvent (const NLGUI::CEventDescriptor &evnt); }; diff --git a/code/nel/include/nel/gui/view_text.h b/code/nel/include/nel/gui/view_text.h index df3cf27e3..fa9e184b7 100644 --- a/code/nel/include/nel/gui/view_text.h +++ b/code/nel/include/nel/gui/view_text.h @@ -188,6 +188,8 @@ namespace NLGUI int luaSetLineMaxW(CLuaState &ls); + bool handleEvent( const NLGUI::CEventDescriptor &evnt ); + REFLECT_EXPORT_START(CViewText, CViewBase) REFLECT_STRING("hardtext", getHardText, setHardText); REFLECT_UCSTRING("uc_hardtext", getText, setText); diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index 7fedc6240..5700a52e6 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -341,6 +341,7 @@ namespace NLGUI /** * Capture */ + CViewBase *getCapturedView(){ return _CapturedView; } CCtrlBase *getCapturePointerLeft() { return _CapturePointerLeft; } CCtrlBase *getCapturePointerRight() { return _CapturePointerRight; } CCtrlBase *getCaptureKeyboard() { return _CaptureKeyboard; } @@ -510,6 +511,8 @@ namespace NLGUI NLMISC::CRefPtr _CapturePointerLeft; NLMISC::CRefPtr _CapturePointerRight; + NLMISC::CRefPtr< CViewBase > _CapturedView; + // What is under pointer std::vector< CViewBase* > _ViewsUnderPointer; std::vector< CCtrlBase* > _CtrlsUnderPointer; diff --git a/code/nel/src/gui/ctrl_base.cpp b/code/nel/src/gui/ctrl_base.cpp index 8cd51f026..c2f467736 100644 --- a/code/nel/src/gui/ctrl_base.cpp +++ b/code/nel/src/gui/ctrl_base.cpp @@ -37,6 +37,9 @@ namespace NLGUI // *************************************************************************** bool CCtrlBase::handleEvent(const NLGUI::CEventDescriptor &event) { + if( CViewBase::handleEvent( event ) ) + return true; + if (event.getType() == NLGUI::CEventDescriptor::system) { NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event; diff --git a/code/nel/src/gui/ctrl_base_button.cpp b/code/nel/src/gui/ctrl_base_button.cpp index 4c892ecc7..16b2a3ad4 100644 --- a/code/nel/src/gui/ctrl_base_button.cpp +++ b/code/nel/src/gui/ctrl_base_button.cpp @@ -668,12 +668,6 @@ namespace NLGUI if (CWidgetManager::getInstance()->getCapturePointerLeft() != this) return false; - if( editorMode ) - { - CWidgetManager::getInstance()->setCurrentEditorSelection( getId() ); - return true; - } - if (_LeftDblClickHandled) // no effect on mouse up after double click has been handled { _LeftDblClickHandled = false; diff --git a/code/nel/src/gui/view_base.cpp b/code/nel/src/gui/view_base.cpp index cf1e01ede..ebe18b979 100644 --- a/code/nel/src/gui/view_base.cpp +++ b/code/nel/src/gui/view_base.cpp @@ -45,5 +45,23 @@ namespace NLGUI CInterfaceElement::visit(visitor); } + + bool CViewBase::handleEvent( const NLGUI::CEventDescriptor &evnt ) + { + if( evnt.getType() == NLGUI::CEventDescriptor::mouse ) + { + const NLGUI::CEventDescriptorMouse &eventDesc = ( const NLGUI::CEventDescriptorMouse& )evnt; + if( eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown ) + { + if( editorMode ) + { + CWidgetManager::getInstance()->setCurrentEditorSelection( getId() ); + return true; + } + } + } + return false; + } + } diff --git a/code/nel/src/gui/view_text.cpp b/code/nel/src/gui/view_text.cpp index 85e76a09c..b9d58ae45 100644 --- a/code/nel/src/gui/view_text.cpp +++ b/code/nel/src/gui/view_text.cpp @@ -2945,6 +2945,11 @@ namespace NLGUI } } + bool CViewText::handleEvent( const NLGUI::CEventDescriptor &evnt ) + { + return false; + } + // *************************************************************************** void CViewText::serial(NLMISC::IStream &f) { diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index b12ddff3c..c923c40fe 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -1031,6 +1031,7 @@ namespace NLGUI _OldCaptureKeyboard = NULL; setCapturePointerLeft(NULL); setCapturePointerRight(NULL); + _CapturedView = NULL; resetColorProps(); @@ -2086,6 +2087,12 @@ namespace NLGUI getCapturePointerRight()->handleEvent( evnt ); setCapturePointerRight( NULL ); } + + if( _CapturedView != NULL ) + { + _CapturedView->handleEvent( evnt ); + _CapturedView = NULL; + } } } @@ -2249,6 +2256,9 @@ namespace NLGUI getCapturePointerLeft() != getCapturePointerRight() ) handled|= getCapturePointerRight()->handleEvent(evnt); + if( _CapturedView != NULL ) + _CapturedView->handleEvent( evnt ); + CInterfaceGroup *ptr = getWindowUnder (eventDesc.getX(), eventDesc.getY()); setCurrentWindowUnder( ptr ); @@ -2326,6 +2336,8 @@ namespace NLGUI } } + bool captured = false; + // must not capture a new element if a sheet is currentlty being dragged. // This may happen when alt-tab has been used => the sheet is dragged but the left button is up if (!CCtrlDraggable::getDraggedSheet()) @@ -2343,9 +2355,25 @@ namespace NLGUI { nMaxDepth = d; setCapturePointerLeft( ctrl ); + captured = true; } } } + + if( CInterfaceElement::getEditorMode() && !captured ) + { + for( sint32 i = _ViewsUnderPointer.size()-1; i >= 0; i-- ) + { + CViewBase *v = _ViewsUnderPointer[i]; + if( ( v != NULL ) && v->isInGroup( pNewCurrentWnd ) ) + { + _CapturedView = v; + captured = true; + break; + } + } + } + notifyElementCaptured( getCapturePointerLeft() ); if (clickedOutModalWindow && !clickedOutModalWindow->OnPostClickOut.empty()) { @@ -2353,13 +2381,16 @@ namespace NLGUI } } //if found - if ( getCapturePointerLeft() != NULL) + if ( captured ) { // consider clicking on a control implies handling of the event. handled= true; // handle the capture - getCapturePointerLeft()->handleEvent(evnt); + if( getCapturePointerLeft() != NULL ) + getCapturePointerLeft()->handleEvent(evnt); + else + _CapturedView->handleEvent( evnt ); } } @@ -2588,6 +2619,8 @@ namespace NLGUI // *************************************************************************** void CWidgetManager::setCapturePointerLeft(CCtrlBase *c) { + _CapturedView = NULL; + // additionally, abort any dragging if( CCtrlDraggable::getDraggedSheet() != NULL ) CCtrlDraggable::getDraggedSheet()->abortDragging(); From 365ef61ec94faec0ad388672ffaadd29b0b6f476 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 23 Feb 2013 06:55:19 +0100 Subject: [PATCH 02/25] MODIFIED: Update property browser when selecting in the central widget. --HG-- branch : gsoc2012-gui-editor --- .../nel/gui/editor_selection_watcher.h | 30 ++++++++++++++++ code/nel/include/nel/gui/widget_manager.h | 6 ++++ code/nel/src/gui/widget_manager.cpp | 36 +++++++++++++++++++ .../src/plugins/gui_editor/CMakeLists.txt | 1 + .../gui_editor/editor_selection_watcher.cpp | 26 ++++++++++++++ .../gui_editor/editor_selection_watcher.h | 36 +++++++++++++++++++ .../plugins/gui_editor/gui_editor_window.cpp | 22 +++++++++--- .../plugins/gui_editor/gui_editor_window.h | 1 + .../src/plugins/gui_editor/nelgui_widget.cpp | 7 ++++ .../src/plugins/gui_editor/nelgui_widget.h | 4 +++ .../plugins/gui_editor/widget_hierarchy.cpp | 16 ++++++--- .../src/plugins/gui_editor/widget_hierarchy.h | 4 +-- 12 files changed, 177 insertions(+), 12 deletions(-) create mode 100644 code/nel/include/nel/gui/editor_selection_watcher.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.h diff --git a/code/nel/include/nel/gui/editor_selection_watcher.h b/code/nel/include/nel/gui/editor_selection_watcher.h new file mode 100644 index 000000000..415f4f9db --- /dev/null +++ b/code/nel/include/nel/gui/editor_selection_watcher.h @@ -0,0 +1,30 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include + +namespace NLGUI +{ + /// Watches the currently selected GUI widget + class IEditorSelectionWatcher + { + public: + + /// Notifies the watcher about the change + virtual void selectionChanged( std::string &newSelection ) = 0; + }; +} + diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index 5700a52e6..12f4a065b 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -47,6 +47,7 @@ namespace NLGUI class CInterfaceOptions; class CInterfaceAnim; class CProcedure; + class IEditorSelectionWatcher; /** GUI Widget Manager @@ -485,6 +486,9 @@ namespace NLGUI IParser* getParser() const{ return parser; } void setCurrentEditorSelection( const std::string &name ); + void notifySelectionWatchers(); + void registerSelectionWatcher( IEditorSelectionWatcher *watcher ); + void unregisterSelectionWatcher( IEditorSelectionWatcher *watcher ); private: CWidgetManager(); @@ -564,6 +568,8 @@ namespace NLGUI std::vector< INewScreenSizeHandler* > newScreenSizeHandlers; std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers; + std::vector< IEditorSelectionWatcher* > selectionWatchers; + std::string currentEditorSelection; }; diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index c923c40fe..4640931f5 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -31,6 +31,7 @@ #include "nel/gui/proc.h" #include "nel/gui/interface_expr.h" #include "nel/gui/reflect_register.h" +#include "nel/gui/editor_selection_watcher.h" #include "nel/misc/events.h" namespace NLGUI @@ -3181,9 +3182,44 @@ namespace NLGUI } e->setEditorSelected( true ); currentEditorSelection = name; + notifySelectionWatchers(); } } + void CWidgetManager::notifySelectionWatchers() + { + std::vector< IEditorSelectionWatcher* >::iterator itr = selectionWatchers.begin(); + while( itr != selectionWatchers.end() ) + { + (*itr)->selectionChanged( currentEditorSelection ); + ++itr; + } + } + + void CWidgetManager::registerSelectionWatcher( IEditorSelectionWatcher *watcher ) + { + std::vector< IEditorSelectionWatcher* >::iterator itr = + std::find( selectionWatchers.begin(), selectionWatchers.end(), watcher ); + + // We already have this watcher + if( itr != selectionWatchers.end() ) + return; + + selectionWatchers.push_back( watcher ); + } + + void CWidgetManager::unregisterSelectionWatcher( IEditorSelectionWatcher *watcher ) + { + std::vector< IEditorSelectionWatcher* >::iterator itr = + std::find( selectionWatchers.begin(), selectionWatchers.end(), watcher ); + + // We don't have this watcher + if( itr == selectionWatchers.end() ) + return; + + selectionWatchers.erase( itr ); + } + CWidgetManager::CWidgetManager() { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt index 0a5d8533d..c08157373 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt @@ -60,6 +60,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR nelgui_widget.h new_property_widget.h new_widget_widget.h + editor_selection_watcher.h ) SET(OVQT_PLUGIN_GUI_EDITOR_UIS diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.cpp new file mode 100644 index 000000000..ee3a079ad --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.cpp @@ -0,0 +1,26 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "editor_selection_watcher.h" + +namespace GUIEditor +{ + void CEditorSelectionWatcher::selectionChanged( std::string &newSelection ) + { + Q_EMIT sgnSelectionChanged( newSelection ); + } +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.h new file mode 100644 index 000000000..61218c0cd --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.h @@ -0,0 +1,36 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "nel/gui/editor_selection_watcher.h" +#include + +namespace GUIEditor +{ + /// Watches the Editor selection, and emits a signal when it changes + class CEditorSelectionWatcher : public QObject, public NLGUI::IEditorSelectionWatcher + { + Q_OBJECT + + public: + CEditorSelectionWatcher() : QObject( NULL ){} + + void selectionChanged( std::string &newSelection ); + + Q_SIGNALS: + void sgnSelectionChanged( std::string &id ); + }; +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp index 5a0aff4de..66945b562 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp @@ -41,6 +41,7 @@ #include "project_file_serializer.h" #include "project_window.h" #include "nelgui_widget.h" +#include "editor_selection_watcher.h" namespace GUIEditor { @@ -91,11 +92,7 @@ namespace GUIEditor viewPort->init(); - connect( viewPort, SIGNAL( guiLoadComplete() ), hierarchyView, SLOT( onGUILoaded() ) ); - connect( viewPort, SIGNAL( guiLoadComplete() ), procList, SLOT( onGUILoaded() ) ); - connect( viewPort, SIGNAL( guiLoadComplete() ), linkList, SLOT( onGUILoaded() ) ); - connect( hierarchyView, SIGNAL( selectionChanged( std::string& ) ), - &browserCtrl, SLOT( onSelectionChanged( std::string& ) ) ); + connect( viewPort, SIGNAL( guiLoadComplete() ), this, SLOT( onGUILoaded() ) ); } GUIEditorWindow::~GUIEditorWindow() @@ -262,6 +259,11 @@ namespace GUIEditor if( reply != QMessageBox::Yes ) return false; + + CEditorSelectionWatcher *w = viewPort->getWatcher(); + disconnect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), hierarchyView, SLOT( onSelectionChanged( std::string& ) ) ); + disconnect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), &browserCtrl, SLOT( onSelectionChanged( std::string& ) ) ); + projectFiles.clearAll(); projectWindow->clear(); hierarchyView->clearHierarchy(); @@ -291,6 +293,16 @@ namespace GUIEditor setCursor( Qt::ArrowCursor ); } + void GUIEditorWindow::onGUILoaded() + { + hierarchyView->onGUILoaded(); + procList->onGUILoaded(); + linkList->onGUILoaded(); + + CEditorSelectionWatcher *w = viewPort->getWatcher(); + connect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), hierarchyView, SLOT( onSelectionChanged( std::string& ) ) ); + connect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), &browserCtrl, SLOT( onSelectionChanged( std::string& ) ) ); + } void GUIEditorWindow::createMenus() { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h index d4327d3d9..41cd30e9a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h @@ -58,6 +58,7 @@ public Q_SLOTS: private Q_SLOTS: void onProjectFilesChanged(); + void onGUILoaded(); private: void createMenus(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp index 85525e428..d86d31269 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp @@ -27,6 +27,7 @@ #include #include #include +#include "editor_selection_watcher.h" namespace GUIEditor { @@ -37,6 +38,7 @@ namespace GUIEditor { timerID = 0; guiLoaded = false; + watcher = NULL; } NelGUIWidget::~NelGUIWidget() @@ -70,6 +72,8 @@ namespace GUIEditor NLGUI::CViewRenderer::getInstance()->init(); CWidgetManager::getInstance()->getParser()->setEditorMode( true ); + + watcher = new CEditorSelectionWatcher(); } bool NelGUIWidget::parse( SProjectFiles &files ) @@ -106,6 +110,8 @@ namespace GUIEditor guiLoaded = true; Q_EMIT guiLoadComplete(); + CWidgetManager::getInstance()->registerSelectionWatcher( watcher ); + return true; } @@ -115,6 +121,7 @@ namespace GUIEditor if( timerID != 0 ) killTimer( timerID ); timerID = 0; + CWidgetManager::getInstance()->unregisterSelectionWatcher( watcher ); CWidgetManager::getInstance()->reset(); CWidgetManager::getInstance()->getParser()->removeAll(); CViewRenderer::getInstance()->reset(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h index 5a45cc351..34c510507 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h @@ -23,6 +23,8 @@ namespace GUIEditor { + class CEditorSelectionWatcher; + /// Qt viewport for the Nel GUI library class NelGUIWidget : public Nel3DWidget { @@ -35,6 +37,7 @@ namespace GUIEditor bool parse( SProjectFiles &files ); void draw(); void reset(); + CEditorSelectionWatcher* getWatcher(){ return watcher; } Q_SIGNALS: void guiLoadComplete(); @@ -49,6 +52,7 @@ Q_SIGNALS: private: int timerID; bool guiLoaded; + CEditorSelectionWatcher *watcher; }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp index f510d6fb1..a238c1f03 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp @@ -130,6 +130,16 @@ namespace GUIEditor if( masterGroup.empty() ) return; buildHierarchy( masterGroup ); + currentSelection.clear(); + } + + void WidgetHierarchy::onSelectionChanged( std::string &newSelection ) + { + if( newSelection == currentSelection ) + return; + + + // Update the tree } void WidgetHierarchy::onItemDblClicked( QTreeWidgetItem *item ) @@ -138,9 +148,7 @@ namespace GUIEditor return; std::string n = item->text( 0 ).toUtf8().constData(); - std::string selection = makeFullName( item, n ); - CWidgetManager::getInstance()->setCurrentEditorSelection( selection ); - - Q_EMIT selectionChanged( selection ); + currentSelection = makeFullName( item, n ); + CWidgetManager::getInstance()->setCurrentEditorSelection( currentSelection ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h index 493fd2a08..4c138d226 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h @@ -45,6 +45,7 @@ namespace GUIEditor public Q_SLOTS: void onGUILoaded(); + void onSelectionChanged( std::string &newSelection ); private Q_SLOTS: void onItemDblClicked( QTreeWidgetItem *item ); @@ -52,9 +53,6 @@ namespace GUIEditor private: std::string currentSelection; std::string masterGroup; - - Q_SIGNALS: - void selectionChanged( std::string &id ); }; } From 29ef7af61af0e306dcec99c1895e475d48c192aa Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 2 Mar 2013 03:24:22 +0100 Subject: [PATCH 03/25] MODIFIED: When selecting a widget in the central widget, the hierarchy tree should now be updated as well. --HG-- branch : gsoc2012-gui-editor --- .../plugins/gui_editor/widget_hierarchy.cpp | 24 ++++++++++++++++++- .../src/plugins/gui_editor/widget_hierarchy.h | 3 +++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp index a238c1f03..b7485baa4 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp @@ -75,6 +75,7 @@ namespace GUIEditor void WidgetHierarchy::clearHierarchy() { widgetHT->clear(); + widgetHierarchyMap.clear(); } void WidgetHierarchy::buildHierarchy( std::string &masterGroup ) @@ -87,6 +88,7 @@ namespace GUIEditor QTreeWidgetItem *item = new QTreeWidgetItem( NULL ); item->setText( 0, "ui" ); widgetHT->addTopLevelItem( item ); + widgetHierarchyMap[ "ui" ] = item; buildHierarchy( item, mg ); } @@ -96,7 +98,9 @@ namespace GUIEditor { // First add ourselves QTreeWidgetItem *item = new QTreeWidgetItem( parent ); + item->setText( 0, makeNodeName( group->getId() ).c_str() ); + widgetHierarchyMap[ group->getId() ] = item; // Then add recursively our subgroups const std::vector< CInterfaceGroup* > &groups = group->getGroups(); @@ -113,6 +117,7 @@ namespace GUIEditor { QTreeWidgetItem *subItem = new QTreeWidgetItem( item ); subItem->setText( 0, makeNodeName( (*citr)->getId() ).c_str() ); + widgetHierarchyMap[ (*citr)->getId() ] = subItem; } // Add our views @@ -122,6 +127,7 @@ namespace GUIEditor { QTreeWidgetItem *subItem = new QTreeWidgetItem( item ); subItem->setText( 0, makeNodeName( (*vitr)->getId() ).c_str() ); + widgetHierarchyMap[ (*vitr)->getId() ] = subItem; } } @@ -138,8 +144,24 @@ namespace GUIEditor if( newSelection == currentSelection ) return; + std::map< std::string, QTreeWidgetItem* >::iterator itr = + widgetHierarchyMap.find( newSelection ); + if( itr == widgetHierarchyMap.end() ) + return; - // Update the tree + if( widgetHT->currentItem() != NULL ) + widgetHT->currentItem()->setSelected( false ); + + QTreeWidgetItem *item = itr->second; + QTreeWidgetItem *currItem = item; + while( currItem != NULL ) + { + currItem->setExpanded( true ); + currItem = currItem->parent(); + } + + item->setSelected( true ); + widgetHT->setCurrentItem( item ); } void WidgetHierarchy::onItemDblClicked( QTreeWidgetItem *item ) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h index 4c138d226..58e66212e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h @@ -18,6 +18,8 @@ #define WIDGET_HA_H #include "ui_widget_hierarchy.h" +#include +#include namespace NLGUI { @@ -53,6 +55,7 @@ namespace GUIEditor private: std::string currentSelection; std::string masterGroup; + std::map< std::string, QTreeWidgetItem* > widgetHierarchyMap; }; } From 026ccfcd1307ccc252b131687067a16981fc92cb Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 2 Mar 2013 06:57:40 +0100 Subject: [PATCH 04/25] MODIFIED: GUI Editor can now delete widgets. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/widget_manager.h | 1 + .../src/plugins/gui_editor/CMakeLists.txt | 1 + .../gui_editor/editor_message_processor.cpp | 56 +++++++++++++++++++ .../gui_editor/editor_message_processor.h | 33 +++++++++++ .../plugins/gui_editor/gui_editor_window.cpp | 11 ++++ .../plugins/gui_editor/gui_editor_window.h | 3 +- 6 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index 12f4a065b..498139ecf 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -485,6 +485,7 @@ namespace NLGUI IParser* getParser() const{ return parser; } + std::string& getCurrentEditorSelection(){ return currentEditorSelection; } void setCurrentEditorSelection( const std::string &name ); void notifySelectionWatchers(); void registerSelectionWatcher( IEditorSelectionWatcher *watcher ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt index c08157373..63a7d00cc 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt @@ -61,6 +61,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR new_property_widget.h new_widget_widget.h editor_selection_watcher.h + editor_message_processor.h ) SET(OVQT_PLUGIN_GUI_EDITOR_UIS diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp new file mode 100644 index 000000000..944ce945a --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp @@ -0,0 +1,56 @@ +// Object Viewer Qt GUI Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include +#include "editor_message_processor.h" + +#include "nel/gui/interface_group.h" +#include "nel/gui/widget_manager.h" + +namespace GUIEditor +{ + void CEditorMessageProcessor::onDelete() + { + std::string selection = CWidgetManager::getInstance()->getCurrentEditorSelection(); + if( selection.empty() ) + return; + + QMessageBox::StandardButton r = + QMessageBox::question( NULL, + tr( "Deleting widget" ), + tr( "Are you sure you want to delete %1?" ).arg( selection.c_str() ), + QMessageBox::Yes | QMessageBox::No ); + if( r != QMessageBox::Yes ) + return; + + CInterfaceElement *e = + CWidgetManager::getInstance()->getElementFromId( selection ); + if( e == NULL ) + return; + + CInterfaceElement *p = e; + while( ( p != NULL ) && !p->isGroup() ) + p = p->getParent(); + + CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( p ); + if( g == NULL ) + return; + + if( g->delElement( e ) ) + CWidgetManager::getInstance()->setCurrentEditorSelection( "" ); + } +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h new file mode 100644 index 000000000..17cac7683 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h @@ -0,0 +1,33 @@ +// Object Viewer Qt GUI Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include + +namespace GUIEditor +{ + /// Processes the GUI Editor's editor messages like delete, new, etc... + class CEditorMessageProcessor : public QObject + { + Q_OBJECT + public: + CEditorMessageProcessor( QObject *parent = NULL ) : QObject( parent ){} + ~CEditorMessageProcessor(){} + + public Q_SLOTS: + void onDelete(); + }; +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp index 66945b562..f84b555d1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp @@ -42,6 +42,7 @@ #include "project_window.h" #include "nelgui_widget.h" #include "editor_selection_watcher.h" +#include "editor_message_processor.h" namespace GUIEditor { @@ -54,6 +55,7 @@ namespace GUIEditor QMainWindow(parent) { m_ui.setupUi(this); + messageProcessor = new CEditorMessageProcessor; m_undoStack = new QUndoStack(this); widgetProps = new CWidgetProperties; linkList = new LinkList; @@ -99,6 +101,9 @@ namespace GUIEditor { writeSettings(); + delete messageProcessor; + messageProcessor = NULL; + delete widgetProps; widgetProps = NULL; @@ -311,6 +316,7 @@ namespace GUIEditor QAction *saveAction = mm->action( Core::Constants::SAVE ); QAction *saveAsAction = mm->action( Core::Constants::SAVE_AS ); QAction *closeAction = mm->action( Core::Constants::CLOSE ); + QAction *delAction = mm->action( Core::Constants::DEL ); //if( newAction != NULL ) // newAction->setEnabled( true ); @@ -320,6 +326,11 @@ namespace GUIEditor saveAsAction->setEnabled( true ); if( closeAction != NULL ) closeAction->setEnabled( true ); + if( delAction != NULL ) + { + delAction->setEnabled( true ); + connect( delAction, SIGNAL( triggered( bool ) ), messageProcessor, SLOT( onDelete() ) ); + } QMenu *menu = mm->menu( Core::Constants::M_TOOLS ); if( menu != NULL ) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h index 41cd30e9a..37f33e91c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h @@ -36,6 +36,7 @@ namespace GUIEditor class ProjectWindow; class NelGUIWidget; class CWidgetInfoTree; + class CEditorMessageProcessor; class GUIEditorWindow: public QMainWindow { @@ -77,8 +78,8 @@ private: ProcList *procList; ProjectWindow *projectWindow; NelGUIWidget *viewPort; - CWidgetInfoTree *widgetInfoTree; + CEditorMessageProcessor *messageProcessor; CPropBrowserCtrl browserCtrl; QString currentProject; From 48d50cb4091f84342b021de7a1889c285bddfa9c Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 2 Mar 2013 23:27:17 +0100 Subject: [PATCH 05/25] MODIFIED: Text buttons will now delete their text too when being deleted. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/ctrl_text_button.h | 1 + code/nel/src/gui/ctrl_text_button.cpp | 10 ++++++++++ code/nel/src/gui/interface_group.cpp | 6 +++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_text_button.h b/code/nel/include/nel/gui/ctrl_text_button.h index 2df1dee5d..5837a0fbf 100644 --- a/code/nel/include/nel/gui/ctrl_text_button.h +++ b/code/nel/include/nel/gui/ctrl_text_button.h @@ -42,6 +42,7 @@ namespace NLGUI /// Constructor CCtrlTextButton(const TCtorParam ¶m); + ~CCtrlTextButton(); std::string getProperty( const std::string &name ) const; void setProperty( const std::string &name, const std::string &value ); diff --git a/code/nel/src/gui/ctrl_text_button.cpp b/code/nel/src/gui/ctrl_text_button.cpp index fd118cfcb..332358b15 100644 --- a/code/nel/src/gui/ctrl_text_button.cpp +++ b/code/nel/src/gui/ctrl_text_button.cpp @@ -60,6 +60,16 @@ namespace NLGUI _ForceTextOver = false; } + CCtrlTextButton::~CCtrlTextButton() + { + if( _ViewText != NULL ) + { + if( getParent() != NULL ) + getParent()->delElement( _ViewText ); + _ViewText = NULL; + } + } + std::string CCtrlTextButton::getProperty( const std::string &name ) const { std::string prop; diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index c4ba1e950..bb643769a 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -141,12 +141,12 @@ namespace NLGUI // initStart = ryzomGetLocalTime (); clearGroups(); // nlinfo ("%d seconds for clearGroups '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); - // initStart = ryzomGetLocalTime (); - clearViews(); - // nlinfo ("%d seconds for clearViews '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); // initStart = ryzomGetLocalTime (); clearControls(); // nlinfo ("%d seconds for clearControls '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); + // initStart = ryzomGetLocalTime (); + clearViews(); + // nlinfo ("%d seconds for clearViews '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); CWidgetManager::getInstance()->removeRefOnGroup (this); #ifdef AJM_DEBUG_TRACK_INTERFACE_GROUPS From b80c47cc106308f8ac006fcb501f7f7f54e6b6ef Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 3 Mar 2013 00:54:22 +0100 Subject: [PATCH 06/25] MODIFIED: Somehow I left this here, and it prevented viewtexts from being selected. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/view_text.h | 2 -- code/nel/src/gui/view_text.cpp | 5 ----- 2 files changed, 7 deletions(-) diff --git a/code/nel/include/nel/gui/view_text.h b/code/nel/include/nel/gui/view_text.h index fa9e184b7..df3cf27e3 100644 --- a/code/nel/include/nel/gui/view_text.h +++ b/code/nel/include/nel/gui/view_text.h @@ -188,8 +188,6 @@ namespace NLGUI int luaSetLineMaxW(CLuaState &ls); - bool handleEvent( const NLGUI::CEventDescriptor &evnt ); - REFLECT_EXPORT_START(CViewText, CViewBase) REFLECT_STRING("hardtext", getHardText, setHardText); REFLECT_UCSTRING("uc_hardtext", getText, setText); diff --git a/code/nel/src/gui/view_text.cpp b/code/nel/src/gui/view_text.cpp index b9d58ae45..85e76a09c 100644 --- a/code/nel/src/gui/view_text.cpp +++ b/code/nel/src/gui/view_text.cpp @@ -2945,11 +2945,6 @@ namespace NLGUI } } - bool CViewText::handleEvent( const NLGUI::CEventDescriptor &evnt ) - { - return false; - } - // *************************************************************************** void CViewText::serial(NLMISC::IStream &f) { From 532a3ef7d3ca7e36405e4d9e7ec470d7c71f7703 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 3 Mar 2013 03:49:56 +0100 Subject: [PATCH 07/25] MODIFIED: collapse the widget hierarchy tree and remove the widget from it when it's deleted. Also clear the widget properties panel. --HG-- branch : gsoc2012-gui-editor --- code/nel/src/gui/widget_manager.cpp | 8 +++-- .../gui_editor/editor_message_processor.cpp | 2 ++ .../gui_editor/property_browser_ctrl.cpp | 5 +++ .../plugins/gui_editor/widget_hierarchy.cpp | 35 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index 4640931f5..8cc43cc9d 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -3181,9 +3181,13 @@ namespace NLGUI prev->setEditorSelected( false ); } e->setEditorSelected( true ); - currentEditorSelection = name; - notifySelectionWatchers(); } + else + if( !name.empty() ) + return; + + currentEditorSelection = name; + notifySelectionWatchers(); } void CWidgetManager::notifySelectionWatchers() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp index 944ce945a..36e3481e0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp @@ -50,7 +50,9 @@ namespace GUIEditor return; if( g->delElement( e ) ) + { CWidgetManager::getInstance()->setCurrentEditorSelection( "" ); + } } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp index 1612ea803..3c5fa9177 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp @@ -78,7 +78,12 @@ namespace GUIEditor CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id ); if( e == NULL ) + { + connect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ), + this, SLOT( onPropertyChanged( QtProperty* ) ) ); + return; + } currentElement = id; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp index b7485baa4..96ae10aa3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp @@ -144,14 +144,47 @@ namespace GUIEditor if( newSelection == currentSelection ) return; + if( newSelection.empty() ) + { + if( widgetHT->currentItem() != NULL ) + { + QTreeWidgetItem *item = widgetHT->currentItem(); + QTreeWidgetItem *p = item; + + // Deselect item + item->setSelected( false ); + widgetHT->setCurrentItem( NULL ); + + // Collapse the tree + while( p != NULL ) + { + p->setExpanded( false ); + p = p->parent(); + } + + // Finally remove the item! + delete item; + item = NULL; + + std::map< std::string, QTreeWidgetItem* >::iterator itr = + widgetHierarchyMap.find( currentSelection ); + if( itr != widgetHierarchyMap.end() ) + widgetHierarchyMap.erase( itr ); + currentSelection = ""; + } + return; + } + std::map< std::string, QTreeWidgetItem* >::iterator itr = widgetHierarchyMap.find( newSelection ); if( itr == widgetHierarchyMap.end() ) return; + // deselect current item if( widgetHT->currentItem() != NULL ) widgetHT->currentItem()->setSelected( false ); + // expand the tree items, so that we can see the selected item QTreeWidgetItem *item = itr->second; QTreeWidgetItem *currItem = item; while( currItem != NULL ) @@ -160,8 +193,10 @@ namespace GUIEditor currItem = currItem->parent(); } + // select the current item item->setSelected( true ); widgetHT->setCurrentItem( item ); + currentSelection = newSelection; } void WidgetHierarchy::onItemDblClicked( QTreeWidgetItem *item ) From aa2affa158f27bcbc84adfd2290b1e69b52f519d Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 7 Mar 2013 06:01:33 +0100 Subject: [PATCH 08/25] MODIFIED: Draw the highlight of the currently selected widget in editor mode. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/interface_element.h | 2 ++ code/nel/src/gui/ctrl_button.cpp | 2 +- code/nel/src/gui/ctrl_text_button.cpp | 3 +-- code/nel/src/gui/interface_element.cpp | 5 +++++ code/nel/src/gui/widget_manager.cpp | 10 ++++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 570dbf689..2b1fa32c0 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -424,6 +424,8 @@ namespace NLGUI void drawHotSpot(THotSpot hs, NLMISC::CRGBA col); + void drawHighlight(); + // Returns 'true' if that element can be downcasted to a view virtual bool isView() const { return false; } diff --git a/code/nel/src/gui/ctrl_button.cpp b/code/nel/src/gui/ctrl_button.cpp index e4ad08074..c680ee973 100644 --- a/code/nel/src/gui/ctrl_button.cpp +++ b/code/nel/src/gui/ctrl_button.cpp @@ -357,7 +357,7 @@ namespace NLGUI - if ( ( _Over && !editorMode ) || editorSelected ) + if ( ( _Over && !editorMode ) ) { if( !editorMode && (lastOver == false) && (_AHOnOver != NULL)) diff --git a/code/nel/src/gui/ctrl_text_button.cpp b/code/nel/src/gui/ctrl_text_button.cpp index 332358b15..a527bb06f 100644 --- a/code/nel/src/gui/ctrl_text_button.cpp +++ b/code/nel/src/gui/ctrl_text_button.cpp @@ -774,8 +774,7 @@ namespace NLGUI CCtrlBase *capturePointerLeft = CWidgetManager::getInstance()->getCapturePointerLeft(); // *** Draw Over - if( editorSelected || - ( !editorMode && _Over && (_OverWhenPushed || !(_Pushed || capturePointerLeft == this ) ) ) + if( ( !editorMode && _Over && (_OverWhenPushed || !(_Pushed || capturePointerLeft == this ) ) ) ) { if( !editorMode && (lastOver == false) && (_AHOnOver != NULL) ) diff --git a/code/nel/src/gui/interface_element.cpp b/code/nel/src/gui/interface_element.cpp index b369b96d1..dc51735ff 100644 --- a/code/nel/src/gui/interface_element.cpp +++ b/code/nel/src/gui/interface_element.cpp @@ -1300,6 +1300,11 @@ namespace NLGUI } + void CInterfaceElement::drawHighlight() + { + CViewRenderer::getInstance()->drawWiredQuad( _XReal, _YReal, _WReal, _HReal ); + } + // *************************************************************************** void CInterfaceElement::invalidateContent() { diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index 8cc43cc9d..90103840c 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -2056,6 +2056,16 @@ namespace NLGUI getPointer()->draw (); } + if( CInterfaceElement::getEditorMode() ) + { + if( !currentEditorSelection.empty() ) + { + CInterfaceElement *e = getElementFromId( currentEditorSelection ); + if( e != NULL ) + e->drawHighlight(); + } + } + // flush layers CViewRenderer::getInstance()->flush(); From 660fb008953e75c70ae25d53a1dcf9771e006dc9 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 8 Mar 2013 06:07:21 +0100 Subject: [PATCH 09/25] MODIFIED: Widgets derived from CInterfaceGroup should now be deleted too properly. --HG-- branch : gsoc2012-gui-editor --- .../src/plugins/gui_editor/editor_message_processor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp index 36e3481e0..28cc7d75b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp @@ -41,9 +41,9 @@ namespace GUIEditor if( e == NULL ) return; - CInterfaceElement *p = e; - while( ( p != NULL ) && !p->isGroup() ) - p = p->getParent(); + CInterfaceElement *p = e->getParent(); + if( p == NULL ) + return; CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( p ); if( g == NULL ) From 363154e24156bbc7625a7dd662054db8b2d8452b Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 8 Mar 2013 06:28:52 +0100 Subject: [PATCH 10/25] MODIFIED: Preliminary support for a little cleanup when removing a widget from it's parent group ( for example when moving the widget ). --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/ctrl_text_button.h | 2 ++ code/nel/include/nel/gui/interface_element.h | 3 +++ code/nel/src/gui/ctrl_text_button.cpp | 13 ++++++++++--- code/nel/src/gui/interface_group.cpp | 15 ++++++++++++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_text_button.h b/code/nel/include/nel/gui/ctrl_text_button.h index 5837a0fbf..eb9968505 100644 --- a/code/nel/include/nel/gui/ctrl_text_button.h +++ b/code/nel/include/nel/gui/ctrl_text_button.h @@ -124,6 +124,8 @@ namespace NLGUI REFLECT_LUA_METHOD("getViewText", luaGetViewText) REFLECT_EXPORT_END + void onRemoved(); + protected: enum {NumTexture= 3}; diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 2b1fa32c0..739f1b95e 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -486,6 +486,9 @@ namespace NLGUI void setSerializable( bool b ){ serializable = b; } bool IsSerializable() const{ return serializable; } + /// Called when the widget is removed from it's parent group + virtual void onRemoved(){} + protected: bool editorSelected; diff --git a/code/nel/src/gui/ctrl_text_button.cpp b/code/nel/src/gui/ctrl_text_button.cpp index a527bb06f..744086c38 100644 --- a/code/nel/src/gui/ctrl_text_button.cpp +++ b/code/nel/src/gui/ctrl_text_button.cpp @@ -64,8 +64,8 @@ namespace NLGUI { if( _ViewText != NULL ) { - if( getParent() != NULL ) - getParent()->delElement( _ViewText ); + if( _Parent != NULL ) + _Parent->delView( _ViewText ); _ViewText = NULL; } } @@ -967,6 +967,13 @@ namespace NLGUI } // *************************************************************************** - + void CCtrlTextButton::onRemoved() + { + if( _ViewText != NULL ) + { + if( _Parent != NULL ) + _Parent->delView( _ViewText, true ); + } + } } diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index bb643769a..6804df955 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -1084,9 +1084,12 @@ namespace NLGUI { if (_Views[i] == child) { - if (!dontDelete) delete _Views[i]; + CViewBase *v = _Views[i]; _Views.erase(_Views.begin()+i); delEltOrder (child); + child->onRemoved(); + child->setParent( NULL ); + if (!dontDelete) delete v; return true; } } @@ -1100,9 +1103,12 @@ namespace NLGUI { if (_Controls[i] == child) { - if (!dontDelete) delete _Controls[i]; + CCtrlBase *c = _Controls[i]; _Controls.erase(_Controls.begin()+i); delEltOrder (child); + child->onRemoved(); + child->setParent( NULL ); + if (!dontDelete) delete c; return true; } } @@ -1116,9 +1122,12 @@ namespace NLGUI { if (_ChildrenGroups[i] == child) { - if (!dontDelete) delete _ChildrenGroups[i]; + CInterfaceGroup *g = _ChildrenGroups[i]; _ChildrenGroups.erase(_ChildrenGroups.begin()+i); delEltOrder (child); + child->onRemoved(); + child->setParent( NULL ); + if (!dontDelete) delete g; return true; } } From 20820697a3f6702cd6243698013b09a82220691b Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 9 Mar 2013 20:58:53 +0100 Subject: [PATCH 11/25] FIXED: It's not nice to leak memory. --HG-- branch : gsoc2012-gui-editor --- code/nel/src/gui/ctrl_text_button.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/nel/src/gui/ctrl_text_button.cpp b/code/nel/src/gui/ctrl_text_button.cpp index 744086c38..76fa3e02d 100644 --- a/code/nel/src/gui/ctrl_text_button.cpp +++ b/code/nel/src/gui/ctrl_text_button.cpp @@ -66,6 +66,9 @@ namespace NLGUI { if( _Parent != NULL ) _Parent->delView( _ViewText ); + else + delete _ViewText; + _ViewText = NULL; } } From df834e058424bde80b00618c19320f94fe33ba45 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 9 Mar 2013 22:02:31 +0100 Subject: [PATCH 12/25] FIXED: Widgets will no longer get stuck in the widget hierarchy tree, when deleting their parent. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/interface_element.h | 19 +++++ code/nel/src/gui/interface_element.cpp | 32 +++++++ .../plugins/gui_editor/widget_hierarchy.cpp | 84 ++++++++++++------- .../src/plugins/gui_editor/widget_hierarchy.h | 2 + 4 files changed, 109 insertions(+), 28 deletions(-) diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 739f1b95e..83bda2c84 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -70,6 +70,14 @@ namespace NLGUI { public: + /// Watches CInterfaceElement deletions + class IDeletionWatcher + { + public: + IDeletionWatcher(){} + virtual ~IDeletionWatcher(){} + virtual void onDeleted( const std::string &name ){} + }; enum EStrech { @@ -489,6 +497,12 @@ namespace NLGUI /// Called when the widget is removed from it's parent group virtual void onRemoved(){} + /// Registers a deletion watcher + static void registerDeletionWatcher( IDeletionWatcher *watcher ); + + /// Unregisters a deletion watcher + static void unregisterDeletionWatcher( IDeletionWatcher *watcher ); + protected: bool editorSelected; @@ -549,6 +563,11 @@ namespace NLGUI void parseSizeRef(const char *sizeRefStr, sint32 &sizeref, sint32 &sizeDivW, sint32 &sizeDivH); private: + /// Notifies the deletion watchers that this interface element is being deleted + void notifyDeletionWatchers(); + + static std::vector< IDeletionWatcher* > deletionWatchers; + //void snapSize(); bool serializable; diff --git a/code/nel/src/gui/interface_element.cpp b/code/nel/src/gui/interface_element.cpp index dc51735ff..9385887a4 100644 --- a/code/nel/src/gui/interface_element.cpp +++ b/code/nel/src/gui/interface_element.cpp @@ -32,6 +32,7 @@ using namespace NLMISC; namespace NLGUI { bool CInterfaceElement::editorMode = false; + std::vector< CInterfaceElement::IDeletionWatcher* > CInterfaceElement::deletionWatchers; // ------------------------------------------------------------------------------------------------ CInterfaceElement::~CInterfaceElement() @@ -44,6 +45,7 @@ namespace NLGUI } delete _Links; } + notifyDeletionWatchers(); } // ------------------------------------------------------------------------------------------------ @@ -1551,6 +1553,36 @@ namespace NLGUI } } + void CInterfaceElement::registerDeletionWatcher( IDeletionWatcher *watcher ) + { + std::vector< IDeletionWatcher* >::iterator itr + = std::find( deletionWatchers.begin(), deletionWatchers.end(), watcher ); + // Already registered + if( itr != deletionWatchers.end() ) + return; + deletionWatchers.push_back( watcher ); + } + + void CInterfaceElement::unregisterDeletionWatcher( IDeletionWatcher *watcher ) + { + std::vector< IDeletionWatcher* >::iterator itr + = std::find( deletionWatchers.begin(), deletionWatchers.end(), watcher ); + // Not registered + if( itr == deletionWatchers.end() ) + return; + deletionWatchers.erase( itr ); + } + + void CInterfaceElement::notifyDeletionWatchers() + { + std::vector< IDeletionWatcher* >::iterator itr = deletionWatchers.begin(); + while( itr != deletionWatchers.end() ) + { + (*itr)->onDeleted( _Id ); + ++itr; + } + } + CStringMapper* CStringShared::_UIStringMapper = NULL; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp index 96ae10aa3..2bab73c1e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp @@ -56,6 +56,26 @@ namespace name = s.toUtf8().constData(); return name; } + + class CWidgetDeletionWatcher : public CInterfaceElement::IDeletionWatcher + { + public: + CWidgetDeletionWatcher(){ h = NULL; } + + ~CWidgetDeletionWatcher(){} + + void onDeleted( const std::string &id ){ + if( h != NULL ) + h->onWidgetDeleted( id ); + } + + void setWidgetHierarchy( GUIEditor::WidgetHierarchy *h ){ this->h = h; } + + private: + GUIEditor::WidgetHierarchy *h; + }; + + CWidgetDeletionWatcher deletionWatcher; } namespace GUIEditor @@ -66,6 +86,7 @@ namespace GUIEditor setupUi( this ); connect( widgetHT, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) ); + deletionWatcher.setWidgetHierarchy( this ); } WidgetHierarchy::~WidgetHierarchy() @@ -74,6 +95,7 @@ namespace GUIEditor void WidgetHierarchy::clearHierarchy() { + CInterfaceElement::unregisterDeletionWatcher( &deletionWatcher ); widgetHT->clear(); widgetHierarchyMap.clear(); } @@ -81,6 +103,7 @@ namespace GUIEditor void WidgetHierarchy::buildHierarchy( std::string &masterGroup ) { clearHierarchy(); + CInterfaceElement::registerDeletionWatcher( &deletionWatcher ); CInterfaceGroup *mg = CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup ); if( mg != NULL ) @@ -131,6 +154,39 @@ namespace GUIEditor } } + void WidgetHierarchy::onWidgetDeleted( const std::string &id ) + { + std::map< std::string, QTreeWidgetItem* >::iterator itr + = widgetHierarchyMap.find( id ); + if( itr == widgetHierarchyMap.end() ) + return; + + if( widgetHT->currentItem() == itr->second ) + { + QTreeWidgetItem *item = itr->second; + QTreeWidgetItem *p = item; + + // Deselect item + item->setSelected( false ); + widgetHT->setCurrentItem( NULL ); + + // Collapse the tree + while( p != NULL ) + { + p->setExpanded( false ); + p = p->parent(); + } + + currentSelection = ""; + } + + itr->second->setSelected( false ); + + delete itr->second; + itr->second = NULL; + widgetHierarchyMap.erase( itr ); + } + void WidgetHierarchy::onGUILoaded() { if( masterGroup.empty() ) @@ -145,35 +201,7 @@ namespace GUIEditor return; if( newSelection.empty() ) - { - if( widgetHT->currentItem() != NULL ) - { - QTreeWidgetItem *item = widgetHT->currentItem(); - QTreeWidgetItem *p = item; - - // Deselect item - item->setSelected( false ); - widgetHT->setCurrentItem( NULL ); - - // Collapse the tree - while( p != NULL ) - { - p->setExpanded( false ); - p = p->parent(); - } - - // Finally remove the item! - delete item; - item = NULL; - - std::map< std::string, QTreeWidgetItem* >::iterator itr = - widgetHierarchyMap.find( currentSelection ); - if( itr != widgetHierarchyMap.end() ) - widgetHierarchyMap.erase( itr ); - currentSelection = ""; - } return; - } std::map< std::string, QTreeWidgetItem* >::iterator itr = widgetHierarchyMap.find( newSelection ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h index 58e66212e..6de6b1366 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h @@ -42,6 +42,8 @@ namespace GUIEditor void clearHierarchy(); void buildHierarchy( std::string &masterGroup ); + void onWidgetDeleted( const std::string &id ); + private: void buildHierarchy( QTreeWidgetItem *parent, NLGUI::CInterfaceGroup *group ); From b6970c54aec902c28b7ed35138a3fea81e8f4515 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 9 Mar 2013 22:31:51 +0100 Subject: [PATCH 13/25] MODIFIED: Ups, missed this. --HG-- branch : gsoc2012-gui-editor --- code/nel/src/gui/interface_element.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/nel/src/gui/interface_element.cpp b/code/nel/src/gui/interface_element.cpp index 9385887a4..acc3197d7 100644 --- a/code/nel/src/gui/interface_element.cpp +++ b/code/nel/src/gui/interface_element.cpp @@ -45,7 +45,9 @@ namespace NLGUI } delete _Links; } - notifyDeletionWatchers(); + + if( editorMode ) + notifyDeletionWatchers(); } // ------------------------------------------------------------------------------------------------ From 7aee088634f57be5efbffd413fe8006049f36ee5 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 10 Mar 2013 00:56:27 +0100 Subject: [PATCH 14/25] FIXED: Deleting the CViewText of CCtrlTextButton should no longer lead to crashes. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/ctrl_text_button.h | 1 + code/nel/include/nel/gui/interface_element.h | 4 + code/nel/include/nel/gui/interface_group.h | 2 + code/nel/src/gui/ctrl_text_button.cpp | 82 ++++++++++++-------- code/nel/src/gui/interface_element.cpp | 4 + code/nel/src/gui/interface_group.cpp | 17 +++- 6 files changed, 73 insertions(+), 37 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_text_button.h b/code/nel/include/nel/gui/ctrl_text_button.h index eb9968505..183b6a65e 100644 --- a/code/nel/include/nel/gui/ctrl_text_button.h +++ b/code/nel/include/nel/gui/ctrl_text_button.h @@ -125,6 +125,7 @@ namespace NLGUI REFLECT_EXPORT_END void onRemoved(); + void onWidgetDeleted( CInterfaceElement *e ); protected: diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 83bda2c84..764d165ef 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -503,6 +503,10 @@ namespace NLGUI /// Unregisters a deletion watcher static void unregisterDeletionWatcher( IDeletionWatcher *watcher ); + /// Called when the widget is deleted, + /// so other widgets in the group can check if it belongs to them + virtual void onWidgetDeleted( CInterfaceElement *e ){} + protected: bool editorSelected; diff --git a/code/nel/include/nel/gui/interface_group.h b/code/nel/include/nel/gui/interface_group.h index 61cdc2c9b..f72bc6f1f 100644 --- a/code/nel/include/nel/gui/interface_group.h +++ b/code/nel/include/nel/gui/interface_group.h @@ -322,6 +322,8 @@ namespace NLGUI // Return the current Depth, with no ZBias applied. float getDepthForZSort() const { return _DepthForZSort; } + void onWidgetDeleted( CInterfaceElement *e ); + protected: void makeNewClip (sint32 &oldClipX, sint32 &oldClipY, sint32 &oldClipW, sint32 &oldClipH); diff --git a/code/nel/src/gui/ctrl_text_button.cpp b/code/nel/src/gui/ctrl_text_button.cpp index 76fa3e02d..c878ee82a 100644 --- a/code/nel/src/gui/ctrl_text_button.cpp +++ b/code/nel/src/gui/ctrl_text_button.cpp @@ -65,10 +65,8 @@ namespace NLGUI if( _ViewText != NULL ) { if( _Parent != NULL ) - _Parent->delView( _ViewText ); - else - delete _ViewText; - + _Parent->delView( _ViewText, true ); + delete _ViewText; _ViewText = NULL; } } @@ -124,7 +122,10 @@ namespace NLGUI else if( name == "hardtext" ) { - return _ViewText->getText().toString(); + if( _ViewText != NULL ) + return _ViewText->getText().toString(); + else + return std::string( "" ); } else if( name == "text_y" ) @@ -139,7 +140,10 @@ namespace NLGUI else if( name == "text_underlined" ) { - return toString( _ViewText->getUnderlined() ); + if( _ViewText != NULL ) + return toString( _ViewText->getUnderlined() ); + else + return std::string( "" ); } else if( name == "text_posref" ) @@ -280,7 +284,8 @@ namespace NLGUI else if( name == "hardtext" ) { - _ViewText->setText( value ); + if( _ViewText != NULL ) + _ViewText->setText( value ); return; } else @@ -303,8 +308,10 @@ namespace NLGUI if( name == "text_underlined" ) { bool b; - if( fromString( value, b ) ) - _ViewText->setUnderlined( b ); + if( _ViewText != NULL ) + if( fromString( value, b ) ) + _ViewText->setUnderlined( b ); + return; } else @@ -813,32 +820,35 @@ namespace NLGUI } } // Setup ViewText color - if ( pTxId==_TextureIdNormal || editorMode ) + if( _ViewText != NULL ) { - if(_TextHeaderColor) viewTextColor.A= _TextColorNormal.A; - else viewTextColor= _TextColorNormal; - _ViewText->setColor(viewTextColor); - _ViewText->setShadowColor(_TextShadowColorNormal); - _ViewText->setModulateGlobalColor(_TextModulateGlobalColorNormal); + if ( pTxId==_TextureIdNormal || editorMode ) + { + if(_TextHeaderColor) viewTextColor.A= _TextColorNormal.A; + else viewTextColor= _TextColorNormal; + _ViewText->setColor(viewTextColor); + _ViewText->setShadowColor(_TextShadowColorNormal); + _ViewText->setModulateGlobalColor(_TextModulateGlobalColorNormal); + } + else if ( pTxId==_TextureIdPushed ) + { + if(_TextHeaderColor) viewTextColor.A= _TextColorPushed.A; + else viewTextColor= _TextColorPushed; + _ViewText->setColor(viewTextColor); + _ViewText->setShadowColor(_TextShadowColorPushed); + _ViewText->setModulateGlobalColor(_TextModulateGlobalColorPushed); + } + else if ( pTxId==_TextureIdOver ) + { + if(_TextHeaderColor) viewTextColor.A= _TextColorOver.A; + else viewTextColor= _TextColorOver; + _ViewText->setColor(viewTextColor); + _ViewText->setShadowColor(_TextShadowColorOver); + _ViewText->setModulateGlobalColor(_TextModulateGlobalColorOver); + } + if(getFrozen() && getFrozenHalfTone()) + _ViewText->setAlpha(_ViewText->getAlpha()>>2); } - else if ( pTxId==_TextureIdPushed ) - { - if(_TextHeaderColor) viewTextColor.A= _TextColorPushed.A; - else viewTextColor= _TextColorPushed; - _ViewText->setColor(viewTextColor); - _ViewText->setShadowColor(_TextShadowColorPushed); - _ViewText->setModulateGlobalColor(_TextModulateGlobalColorPushed); - } - else if ( pTxId==_TextureIdOver ) - { - if(_TextHeaderColor) viewTextColor.A= _TextColorOver.A; - else viewTextColor= _TextColorOver; - _ViewText->setColor(viewTextColor); - _ViewText->setShadowColor(_TextShadowColorOver); - _ViewText->setModulateGlobalColor(_TextModulateGlobalColorOver); - } - if(getFrozen() && getFrozenHalfTone()) - _ViewText->setAlpha(_ViewText->getAlpha()>>2); } @@ -978,5 +988,11 @@ namespace NLGUI _Parent->delView( _ViewText, true ); } } + + void CCtrlTextButton::onWidgetDeleted( CInterfaceElement *e ) + { + if( e == _ViewText ) + _ViewText = NULL; + } } diff --git a/code/nel/src/gui/interface_element.cpp b/code/nel/src/gui/interface_element.cpp index acc3197d7..786ac7967 100644 --- a/code/nel/src/gui/interface_element.cpp +++ b/code/nel/src/gui/interface_element.cpp @@ -47,7 +47,11 @@ namespace NLGUI } if( editorMode ) + { notifyDeletionWatchers(); + if( _Parent != NULL ) + _Parent->onWidgetDeleted( this ); + } } // ------------------------------------------------------------------------------------------------ diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index 6804df955..a39a901c7 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -1088,7 +1088,6 @@ namespace NLGUI _Views.erase(_Views.begin()+i); delEltOrder (child); child->onRemoved(); - child->setParent( NULL ); if (!dontDelete) delete v; return true; } @@ -1107,7 +1106,6 @@ namespace NLGUI _Controls.erase(_Controls.begin()+i); delEltOrder (child); child->onRemoved(); - child->setParent( NULL ); if (!dontDelete) delete c; return true; } @@ -1126,7 +1124,6 @@ namespace NLGUI _ChildrenGroups.erase(_ChildrenGroups.begin()+i); delEltOrder (child); child->onRemoved(); - child->setParent( NULL ); if (!dontDelete) delete g; return true; } @@ -2477,4 +2474,16 @@ namespace NLGUI return "IMPLEMENT ME!"; } -} \ No newline at end of file + void CInterfaceGroup::onWidgetDeleted( CInterfaceElement *e ) + { + for( std::vector< CViewBase* >::iterator itr = _Views.begin(); itr != _Views.end(); ++itr ) + (*itr)->onWidgetDeleted( e ); + + for( std::vector< CCtrlBase* >::iterator itr = _Controls.begin(); itr != _Controls.end(); ++itr ) + (*itr)->onWidgetDeleted( e ); + + for( std::vector< CInterfaceGroup* >::iterator itr = _ChildrenGroups.begin(); itr != _ChildrenGroups.end(); ++itr ) + (*itr)->onWidgetDeleted( e ); + } +} + From c91e7492bba9a23698b6b7736f3301726789df9e Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 5 May 2013 04:58:15 +0200 Subject: [PATCH 15/25] Added GUI for widget adding. --HG-- branch : gsoc2012-gui-editor --- .../src/plugins/gui_editor/CMakeLists.txt | 2 + .../plugins/gui_editor/add_widget_widget.cpp | 64 ++++++++++++++++ .../plugins/gui_editor/add_widget_widget.h | 29 +++++++ .../plugins/gui_editor/add_widget_widget.ui | 76 +++++++++++++++++++ .../plugins/gui_editor/gui_editor_window.cpp | 25 ++++++ .../plugins/gui_editor/gui_editor_window.h | 4 + .../plugins/gui_editor/widget_hierarchy.cpp | 32 ++++++++ .../src/plugins/gui_editor/widget_hierarchy.h | 2 + .../src/plugins/gui_editor/widget_info_tree.h | 4 +- .../gui_editor/widget_info_tree_node.h | 8 +- .../plugins/gui_editor/widget_properties.cpp | 2 + .../plugins/gui_editor/widget_properties.h | 3 + 12 files changed, 246 insertions(+), 5 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.ui diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt index 63a7d00cc..893ec263e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt @@ -60,6 +60,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR nelgui_widget.h new_property_widget.h new_widget_widget.h + add_widget_widget.h editor_selection_watcher.h editor_message_processor.h ) @@ -76,6 +77,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_UIS project_window.ui new_property_widget.ui new_widget_widget.ui + add_widget_widget.ui ) SET(QT_USE_QTGUI TRUE) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.cpp new file mode 100644 index 000000000..24bd70f63 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.cpp @@ -0,0 +1,64 @@ +#include "add_widget_widget.h" +#include "widget_info_tree.h" +#include +#include +#include + +namespace GUIEditor +{ + + AddWidgetWidget::AddWidgetWidget( QWidget *parent ) : + QWidget( parent ) + { + setupUi( this ); + setupConnections(); + } + + AddWidgetWidget::~AddWidgetWidget() + { + } + + void AddWidgetWidget::setCurrentGroup( const QString &g ) + { + groupEdit->setText( g ); + } + + void AddWidgetWidget::setupWidgetInfo( const CWidgetInfoTree *tree ) + { + std::vector< std::string > names; + tree->getNames( names, false ); + + widgetCB->clear(); + + std::sort( names.begin(), names.end() ); + + std::vector< std::string >::const_iterator itr = names.begin(); + while( itr != names.end() ) + { + widgetCB->addItem( QString( itr->c_str() ) ); + ++itr; + } + + } + + void AddWidgetWidget::setupConnections() + { + connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( close() ) ); + connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); + } + + void AddWidgetWidget::onAddClicked() + { + if( nameEdit->text().isEmpty() ) + { + QMessageBox::warning( NULL, + tr( "WARNING" ), + tr( "You need to specify a name for your new widget!" ), + QMessageBox::Ok ); + + return; + } + + close(); + } +} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.h new file mode 100644 index 000000000..fa5045ac2 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.h @@ -0,0 +1,29 @@ +#ifndef ADD_WIDGET_WIDGET_H +#define ADD_WIDGET_WIDGET_H + +#include "ui_add_widget_widget.h" + +namespace GUIEditor +{ + class CWidgetInfoTree; + + class AddWidgetWidget : public QWidget, public Ui::AddWidgetWidget + { + Q_OBJECT + public: + AddWidgetWidget( QWidget *parent = NULL ); + ~AddWidgetWidget(); + + void setCurrentGroup( const QString &g ); + void setupWidgetInfo( const CWidgetInfoTree *tree ); + + private: + void setupConnections(); + + private Q_SLOTS: + void onAddClicked(); + }; + +} + +#endif diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.ui new file mode 100644 index 000000000..dd7e14e48 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.ui @@ -0,0 +1,76 @@ + + + AddWidgetWidget + + + Qt::ApplicationModal + + + + 0 + 0 + 318 + 132 + + + + Add new widget + + + + + + + + Group + + + + + + + + + + + + + + Widget + + + + + + + + + + Name + + + + + + + + + + + + Add + + + + + + + Cancel + + + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp index f84b555d1..33cb5e647 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp @@ -43,6 +43,7 @@ #include "nelgui_widget.h" #include "editor_selection_watcher.h" #include "editor_message_processor.h" +#include "add_widget_widget.h" namespace GUIEditor { @@ -61,6 +62,7 @@ namespace GUIEditor linkList = new LinkList; procList = new ProcList; projectWindow = new ProjectWindow; + addWidgetWidget = new AddWidgetWidget; connect( projectWindow, SIGNAL( projectFilesChanged() ), this, SLOT( onProjectFilesChanged() ) ); viewPort = new NelGUIWidget; setCentralWidget( viewPort ); @@ -76,6 +78,7 @@ namespace GUIEditor parser.setWidgetInfoTree( widgetInfoTree ); parser.parseGUIWidgets(); widgetProps->setupWidgetInfo( widgetInfoTree ); + addWidgetWidget->setupWidgetInfo( widgetInfoTree ); QDockWidget *dock = new QDockWidget( "Widget Hierarchy", this ); dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); @@ -95,6 +98,7 @@ namespace GUIEditor viewPort->init(); connect( viewPort, SIGNAL( guiLoadComplete() ), this, SLOT( onGUILoaded() ) ); + connect( widgetProps, SIGNAL( treeChanged() ), this, SLOT( onTreeChanged() ) ); } GUIEditorWindow::~GUIEditorWindow() @@ -119,6 +123,9 @@ namespace GUIEditor delete viewPort; viewPort = NULL; + delete addWidgetWidget; + addWidgetWidget = NULL; + // no deletion needed for these, since dockwidget owns them hierarchyView = NULL; propBrowser = NULL; @@ -309,6 +316,20 @@ namespace GUIEditor connect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), &browserCtrl, SLOT( onSelectionChanged( std::string& ) ) ); } + void GUIEditorWindow::onAddWidgetClicked() + { + QString g; + hierarchyView->getCurrentGroup( g ); + + addWidgetWidget->setCurrentGroup( g ); + addWidgetWidget->show(); + } + + void GUIEditorWindow::onTreeChanged() + { + addWidgetWidget->setupWidgetInfo( widgetInfoTree ); + } + void GUIEditorWindow::createMenus() { Core::MenuManager *mm = Core::ICore::instance()->menuManager(); @@ -352,6 +373,10 @@ namespace GUIEditor a = new QAction( "Project Window", this ); connect( a, SIGNAL( triggered( bool ) ), projectWindow, SLOT( show() ) ); m->addAction( a ); + + a = new QAction( "Add Widget", this ); + connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onAddWidgetClicked() ) ); + m->addAction( a ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h index 37f33e91c..e1a8b8b2d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h @@ -37,6 +37,7 @@ namespace GUIEditor class NelGUIWidget; class CWidgetInfoTree; class CEditorMessageProcessor; + class AddWidgetWidget; class GUIEditorWindow: public QMainWindow { @@ -60,6 +61,8 @@ public Q_SLOTS: private Q_SLOTS: void onProjectFilesChanged(); void onGUILoaded(); + void onAddWidgetClicked(); + void onTreeChanged(); private: void createMenus(); @@ -80,6 +83,7 @@ private: NelGUIWidget *viewPort; CWidgetInfoTree *widgetInfoTree; CEditorMessageProcessor *messageProcessor; + AddWidgetWidget *addWidgetWidget; CPropBrowserCtrl browserCtrl; QString currentProject; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp index 85b662628..f48c35e93 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp @@ -187,6 +187,38 @@ namespace GUIEditor widgetHierarchyMap.erase( itr ); } + void WidgetHierarchy::getCurrentGroup( QString &g ) + { + std::string s = CWidgetManager::getInstance()->getCurrentEditorSelection(); + if( s.empty() ) + { + g = ""; + return; + } + + NLGUI::CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( s ); + if( e == NULL ) + { + g = ""; + return; + } + + if( e->isGroup() ) + { + g = e->getId().c_str(); + return; + } + + NLGUI::CInterfaceGroup *p = e->getParent(); + if( p == NULL ) + { + g = ""; + return; + } + + g = p->getId().c_str(); + } + void WidgetHierarchy::onGUILoaded() { if( masterGroup.empty() ) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h index 6de6b1366..bfc68ea4f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h @@ -44,6 +44,8 @@ namespace GUIEditor void onWidgetDeleted( const std::string &id ); + void getCurrentGroup( QString &g ); + private: void buildHierarchy( QTreeWidgetItem *parent, NLGUI::CInterfaceGroup *group ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree.h index 25ad7bb40..5e717923c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree.h @@ -93,11 +93,11 @@ namespace GUIEditor } /// Get the node names and put them into the vector - void getNames( std::vector< std::string > &v ) const + void getNames( std::vector< std::string > &v, bool includeAbstract = true ) const { if( root == NULL ) return; - root->getNames( v ); + root->getNames( v, includeAbstract ); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_node.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_node.h index 81adfe06c..0de9e6977 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_node.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_node.h @@ -215,11 +215,13 @@ namespace GUIEditor } /// Get the node names and put them into the vector - void getNames( std::vector< std::string > &v ) const + void getNames( std::vector< std::string > &v, bool includeAbstract = true ) const { - v.push_back( info.name ); + if( !info.isAbstract || ( info.isAbstract && includeAbstract ) ) + v.push_back( info.name ); + for( std::vector< CWidgetInfoTreeNode* >::const_iterator itr = children.begin(); itr != children.end(); ++itr ) - ( *itr )->getNames( v ); + ( *itr )->getNames( v, includeAbstract ); } /// Accepts a visitor to itself and to the children nodes diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.cpp index 0a9337e6c..69d556975 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.cpp @@ -84,6 +84,7 @@ namespace GUIEditor{ return; tree->removeNode( widgetName.toUtf8().constData() ); + Q_EMIT treeChanged(); widgetPropTree->clear(); buildWidgetList(); } @@ -156,6 +157,7 @@ namespace GUIEditor{ void CWidgetProperties::onWidgetAdded() { buildWidgetList(); + Q_EMIT treeChanged(); } void CWidgetProperties::buildWidgetList() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.h index b14bf2f72..44e535b0f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.h @@ -74,6 +74,9 @@ namespace GUIEditor CWidgetInfoTree *tree; NewPropertyWidget *newPropertyWidget; NewWidgetWidget *newWidgetWidget; + + Q_SIGNALS: + void treeChanged(); }; } From 45f5d6cc0d4e225a2b5c9c54d5994c7abb6be531 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 5 May 2013 05:49:35 +0200 Subject: [PATCH 16/25] Added some more checks, signal and slots related to widget adding. --HG-- branch : gsoc2012-gui-editor --- .../plugins/gui_editor/add_widget_widget.cpp | 15 ++++++++++++++- .../plugins/gui_editor/add_widget_widget.h | 3 +++ .../plugins/gui_editor/add_widget_widget.ui | 3 +++ .../gui_editor/editor_message_processor.cpp | 19 +++++++++++++++++++ .../gui_editor/editor_message_processor.h | 1 + .../plugins/gui_editor/gui_editor_window.cpp | 6 ++++++ 6 files changed, 46 insertions(+), 1 deletion(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.cpp index 24bd70f63..3f32586b6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.cpp @@ -49,6 +49,16 @@ namespace GUIEditor void AddWidgetWidget::onAddClicked() { + if( groupEdit->text().isEmpty() ) + { + QMessageBox::warning( NULL, + tr( "WARNING" ), + tr( "You need to be adding the new widget into a group!" ), + QMessageBox::Ok ); + + return; + } + if( nameEdit->text().isEmpty() ) { QMessageBox::warning( NULL, @@ -60,5 +70,8 @@ namespace GUIEditor } close(); + + Q_EMIT adding( groupEdit->text(), widgetCB->currentText(), nameEdit->text() ); } -} \ No newline at end of file +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.h index fa5045ac2..8f9f6a0be 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.h @@ -22,6 +22,9 @@ namespace GUIEditor private Q_SLOTS: void onAddClicked(); + + Q_SIGNALS: + void adding( const QString &parentGroup, const QString &widgetType, const QString &name ); }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.ui index dd7e14e48..58a1890f4 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/add_widget_widget.ui @@ -31,6 +31,9 @@ + + true + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp index 28cc7d75b..25924a804 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp @@ -54,5 +54,24 @@ namespace GUIEditor CWidgetManager::getInstance()->setCurrentEditorSelection( "" ); } } + + void CEditorMessageProcessor::onAdd( const QString &parentGroup, const QString &widgetType, const QString &name ) + { + // Check if this group exists + CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( std::string( parentGroup.toAscii() ) ); + if( e == NULL ) + return; + CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( e ); + if( g == NULL ) + return; + + // Check if an element already exists with that name + if( g->getElement( std::string( name.toAscii() ) ) != NULL ) + return; + + // Create and add the new widget + //CViewBase *v = NULL; + //g->addView( v ); + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h index 17cac7683..1d41e87a6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h @@ -28,6 +28,7 @@ namespace GUIEditor public Q_SLOTS: void onDelete(); + void onAdd( const QString &parentGroup, const QString &widgetType, const QString &name ); }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp index 33cb5e647..8ccd510ef 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp @@ -99,6 +99,12 @@ namespace GUIEditor connect( viewPort, SIGNAL( guiLoadComplete() ), this, SLOT( onGUILoaded() ) ); connect( widgetProps, SIGNAL( treeChanged() ), this, SLOT( onTreeChanged() ) ); + connect( + addWidgetWidget, + SIGNAL( adding( const QString&, const QString&, const QString& ) ), + messageProcessor, + SLOT( onAdd( const QString&, const QString&, const QString& ) ) + ); } GUIEditorWindow::~GUIEditorWindow() From 142bc623c9067ea089f6c263678e519baae49101 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 9 May 2013 05:53:14 +0200 Subject: [PATCH 17/25] Some more work for widget adding support. Basically the system works, just need to make sure the proper widget is instantiated, and the defaults are loaded ( so it shows up ). --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/interface_parser.h | 1 + code/nel/include/nel/gui/parser.h | 2 + .../include/nel/gui/widget_addition_watcher.h | 16 ++++ code/nel/include/nel/gui/widget_manager.h | 8 ++ code/nel/src/gui/interface_parser.cpp | 5 ++ code/nel/src/gui/widget_manager.cpp | 73 +++++++++++++++++++ .../gui_editor/editor_message_processor.cpp | 29 ++++---- .../plugins/gui_editor/widget_hierarchy.cpp | 44 +++++++++++ .../src/plugins/gui_editor/widget_hierarchy.h | 1 + 9 files changed, 165 insertions(+), 14 deletions(-) create mode 100644 code/nel/include/nel/gui/widget_addition_watcher.h diff --git a/code/nel/include/nel/gui/interface_parser.h b/code/nel/include/nel/gui/interface_parser.h index eb602b8ca..2bf1df9a8 100644 --- a/code/nel/include/nel/gui/interface_parser.h +++ b/code/nel/include/nel/gui/interface_parser.h @@ -382,6 +382,7 @@ namespace NLGUI bool serializeProcs( xmlNodePtr parentNode ) const; bool serializePointerSettings( xmlNodePtr parentNode ) const; bool serializeKeySettings( xmlNodePtr parentNode ) const; + CViewBase* createClass( const std::string &name ); }; } diff --git a/code/nel/include/nel/gui/parser.h b/code/nel/include/nel/gui/parser.h index dc6d00767..db868f70d 100644 --- a/code/nel/include/nel/gui/parser.h +++ b/code/nel/include/nel/gui/parser.h @@ -27,6 +27,7 @@ namespace NLGUI { class CInterfaceElement; + class CViewBase; class CInterfaceGroup; class CInterfaceAnim; class CCtrlSheetSelection; @@ -86,6 +87,7 @@ namespace NLGUI virtual bool serializeProcs( xmlNodePtr parentNode ) const = 0; virtual bool serializePointerSettings( xmlNodePtr parentNode ) const = 0; virtual bool serializeKeySettings( xmlNodePtr parentNode ) const = 0; + virtual CViewBase* createClass( const std::string &name ) = 0; }; } diff --git a/code/nel/include/nel/gui/widget_addition_watcher.h b/code/nel/include/nel/gui/widget_addition_watcher.h new file mode 100644 index 000000000..555c1ff3c --- /dev/null +++ b/code/nel/include/nel/gui/widget_addition_watcher.h @@ -0,0 +1,16 @@ +#ifndef WIDGET_ADD_WATCHER +#define WIDGET_ADD_WATCHER + +#include + +namespace NLGUI +{ + class IWidgetAdditionWatcher + { + public: + virtual void widgetAdded( const std::string &name ) = 0; + }; +} + +#endif + diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index 498139ecf..7ec4908a0 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -48,6 +48,7 @@ namespace NLGUI class CInterfaceAnim; class CProcedure; class IEditorSelectionWatcher; + class IWidgetAdditionWatcher; /** GUI Widget Manager @@ -490,6 +491,12 @@ namespace NLGUI void notifySelectionWatchers(); void registerSelectionWatcher( IEditorSelectionWatcher *watcher ); void unregisterSelectionWatcher( IEditorSelectionWatcher *watcher ); + + void notifyAdditionWatchers( const std::string &widgetName ); + void registerAdditionWatcher( IWidgetAdditionWatcher *watcher ); + void unregisterAdditionWatcher( IWidgetAdditionWatcher *watcher ); + + CInterfaceElement* addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName ); private: CWidgetManager(); @@ -570,6 +577,7 @@ namespace NLGUI std::vector< INewScreenSizeHandler* > newScreenSizeHandlers; std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers; std::vector< IEditorSelectionWatcher* > selectionWatchers; + std::vector< IWidgetAdditionWatcher* > additionWatchers; std::string currentEditorSelection; diff --git a/code/nel/src/gui/interface_parser.cpp b/code/nel/src/gui/interface_parser.cpp index 76f5df1ed..03cce1449 100644 --- a/code/nel/src/gui/interface_parser.cpp +++ b/code/nel/src/gui/interface_parser.cpp @@ -3148,5 +3148,10 @@ namespace NLGUI return true; } + + CViewBase* CInterfaceParser::createClass( const std::string &name ) + { + return NLMISC_GET_FACTORY( CViewBase, std::string ).createObject( std::string( name ) , CViewBase::TCtorParam() ); + } } diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index 0612d54b1..ecac9335c 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -34,6 +34,7 @@ #include "nel/gui/interface_expr.h" #include "nel/gui/reflect_register.h" #include "nel/gui/editor_selection_watcher.h" +#include "nel/gui/widget_addition_watcher.h" #include "nel/misc/events.h" namespace NLGUI @@ -3236,6 +3237,78 @@ namespace NLGUI selectionWatchers.erase( itr ); } + void CWidgetManager::notifyAdditionWatchers( const std::string &widgetName ) + { + std::vector< IWidgetAdditionWatcher* >::const_iterator itr = additionWatchers.begin(); + while( itr != additionWatchers.end() ) + { + (*itr)->widgetAdded( widgetName ); + ++itr; + } + } + + void CWidgetManager::registerAdditionWatcher( IWidgetAdditionWatcher *watcher ) + { + std::vector< IWidgetAdditionWatcher* >::const_iterator itr + = std::find( additionWatchers.begin(), additionWatchers.end(), watcher ); + // already exists + if( itr != additionWatchers.end() ) + return; + + additionWatchers.push_back( watcher ); + } + + void CWidgetManager::unregisterAdditionWatcher( IWidgetAdditionWatcher *watcher ) + { + std::vector< IWidgetAdditionWatcher* >::iterator itr + = std::find( additionWatchers.begin(), additionWatchers.end(), watcher ); + // doesn't exist + if( itr == additionWatchers.end() ) + return; + + additionWatchers.erase( itr ); + } + + CInterfaceElement* CWidgetManager::addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName ) + { + // Check if this group exists + CInterfaceElement *e = getElementFromId( group ); + if( e == NULL ) + return NULL; + CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( e ); + if( g == NULL ) + return NULL; + + // Check if an element already exists with that name + if( g->getElement( widgetName ) != NULL ) + return NULL; + + // Create and add the new widget + CViewBase *v = getParser()->createClass( "button" ); + if( v == NULL ) + return NULL; + + v->setId( std::string( g->getId() + ":" + widgetName ) ); + + v->setParentPosRef( Hotspot_TL ); + v->setPosRef( Hotspot_TL ); + + if( v->isGroup() ) + g->addGroup( dynamic_cast< CInterfaceGroup* >( v ) ); + else + if( v->isCtrl() ) + g->addCtrl( dynamic_cast< CCtrlBase* >( v ) ); + else + g->addView( v ); + + // Invalidate so it shows up! + v->invalidateCoords(); + + notifyAdditionWatchers( v->getId() ); + + return v; + } + CWidgetManager::CWidgetManager() { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp index 25924a804..c91381fb7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp @@ -57,21 +57,22 @@ namespace GUIEditor void CEditorMessageProcessor::onAdd( const QString &parentGroup, const QString &widgetType, const QString &name ) { - // Check if this group exists - CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( std::string( parentGroup.toAscii() ) ); + CInterfaceElement *e = + CWidgetManager::getInstance()->addWidgetToGroup( + std::string( parentGroup.toUtf8() ), + std::string( widgetType.toUtf8() ), + std::string( name.toUtf8() ) + ); + if( e == NULL ) - return; - CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( e ); - if( g == NULL ) - return; - - // Check if an element already exists with that name - if( g->getElement( std::string( name.toAscii() ) ) != NULL ) - return; - - // Create and add the new widget - //CViewBase *v = NULL; - //g->addView( v ); + { + QMessageBox::critical( + NULL, + tr( "Error" ), + tr( "Error adding the new widget!" ), + QMessageBox::Ok + ); + } } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp index f48c35e93..24208f4a3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp @@ -18,6 +18,7 @@ #include "widget_hierarchy.h" #include "nel/gui/interface_group.h" #include "nel/gui/widget_manager.h" +#include "nel/gui/widget_addition_watcher.h" namespace { @@ -75,7 +76,26 @@ namespace GUIEditor::WidgetHierarchy *h; }; + class CWidgetAdditionWatcher : public IWidgetAdditionWatcher + { + public: + CWidgetAdditionWatcher(){ h = NULL; } + ~CWidgetAdditionWatcher(){} + + void widgetAdded( const std::string &name ) + { + if( h != NULL ) + h->onWidgetAdded( name ); + } + + void setWidgetHierarchy( GUIEditor::WidgetHierarchy *h ){ this->h = h; } + + private: + GUIEditor::WidgetHierarchy *h; + }; + CWidgetDeletionWatcher deletionWatcher; + CWidgetAdditionWatcher additionWatcher; } namespace GUIEditor @@ -87,6 +107,7 @@ namespace GUIEditor connect( widgetHT, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) ); deletionWatcher.setWidgetHierarchy( this ); + additionWatcher.setWidgetHierarchy( this ); } WidgetHierarchy::~WidgetHierarchy() @@ -96,6 +117,7 @@ namespace GUIEditor void WidgetHierarchy::clearHierarchy() { CInterfaceElement::unregisterDeletionWatcher( &deletionWatcher ); + CWidgetManager::getInstance()->unregisterAdditionWatcher( &additionWatcher ); widgetHT->clear(); widgetHierarchyMap.clear(); } @@ -104,6 +126,7 @@ namespace GUIEditor { clearHierarchy(); CInterfaceElement::registerDeletionWatcher( &deletionWatcher ); + CWidgetManager::getInstance()->registerAdditionWatcher( &additionWatcher ); CInterfaceGroup *mg = CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup ); if( mg != NULL ) @@ -187,6 +210,27 @@ namespace GUIEditor widgetHierarchyMap.erase( itr ); } + void WidgetHierarchy::onWidgetAdded( const std::string &id ) + { + // Get the parent's name + std::string::size_type p = id.find_last_of( ':' ); + if( p == std::string::npos ) + return; + std::string parentId = id.substr( 0, p ); + + // Do we have the parent in the hierarchy? + std::map< std::string, QTreeWidgetItem* >::iterator itr + = widgetHierarchyMap.find( parentId ); + if( itr == widgetHierarchyMap.end() ) + return; + + // Add the new widget to the hierarchy + QTreeWidgetItem *parent = itr->second; + QTreeWidgetItem *item = new QTreeWidgetItem( parent ); + item->setText( 0, makeNodeName( id ).c_str() ); + widgetHierarchyMap[ id ] = item; + } + void WidgetHierarchy::getCurrentGroup( QString &g ) { std::string s = CWidgetManager::getInstance()->getCurrentEditorSelection(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h index bfc68ea4f..4641c8ce8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h @@ -43,6 +43,7 @@ namespace GUIEditor void buildHierarchy( std::string &masterGroup ); void onWidgetDeleted( const std::string &id ); + void onWidgetAdded( const std::string &id ); void getCurrentGroup( QString &g ); From 337f93a233a88dfe7a660512aa7dd4a9e040acfa Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 9 May 2013 23:57:48 +0200 Subject: [PATCH 18/25] When adding a new widget, the correct widget is now instantiated. Also added some checks. --HG-- branch : gsoc2012-gui-editor --- .../include/nel/gui/widget_addition_watcher.h | 16 +++++ code/nel/src/gui/widget_manager.cpp | 59 +++++++++---------- .../gui_editor/editor_message_processor.cpp | 54 ++++++++++++++++- .../gui_editor/editor_message_processor.h | 14 ++++- .../plugins/gui_editor/gui_editor_window.cpp | 1 + .../src/plugins/gui_editor/widget_info.h | 1 + .../gui_editor/widget_info_serializer.cpp | 1 + .../gui_editor/widget_properties_parser.cpp | 3 + .../plugins/gui_editor/widgets/CtrlButton.xml | 1 + .../gui_editor/widgets/CtrlColPick.xml | 1 + .../plugins/gui_editor/widgets/CtrlScroll.xml | 1 + .../gui_editor/widgets/CtrlTextButton.xml | 1 + .../widgets/DBGroupSelectNumber.xml | 1 + .../plugins/gui_editor/widgets/DBViewBar.xml | 1 + .../plugins/gui_editor/widgets/DBViewBar3.xml | 1 + .../gui_editor/widgets/DBViewDigit.xml | 3 +- .../gui_editor/widgets/DBViewNumber.xml | 3 +- .../gui_editor/widgets/DBViewQuantity.xml | 7 ++- .../gui_editor/widgets/GroupContainer.xml | 1 + .../gui_editor/widgets/GroupEditBox.xml | 1 + .../plugins/gui_editor/widgets/GroupHTML.xml | 1 + .../gui_editor/widgets/GroupHeader.xml | 1 + .../plugins/gui_editor/widgets/GroupList.xml | 1 + .../plugins/gui_editor/widgets/GroupMenu.xml | 1 + .../plugins/gui_editor/widgets/GroupModal.xml | 1 + .../gui_editor/widgets/GroupScrollText.xml | 1 + .../plugins/gui_editor/widgets/GroupTab.xml | 1 + .../plugins/gui_editor/widgets/GroupTable.xml | 1 + .../plugins/gui_editor/widgets/GroupTree.xml | 1 + .../gui_editor/widgets/InterfaceGroup.xml | 1 + .../widgets/InterfaceGroupWheel.xml | 1 + .../plugins/gui_editor/widgets/ViewBitmap.xml | 1 + .../gui_editor/widgets/ViewBitmapCombo.xml | 1 + .../plugins/gui_editor/widgets/ViewText.xml | 3 +- .../gui_editor/widgets/ViewTextFormated.xml | 1 + .../plugins/gui_editor/widgets/ViewTextID.xml | 1 + .../gui_editor/widgets/ViewTextIDFormated.xml | 1 + 37 files changed, 151 insertions(+), 39 deletions(-) diff --git a/code/nel/include/nel/gui/widget_addition_watcher.h b/code/nel/include/nel/gui/widget_addition_watcher.h index 555c1ff3c..f4371ed5b 100644 --- a/code/nel/include/nel/gui/widget_addition_watcher.h +++ b/code/nel/include/nel/gui/widget_addition_watcher.h @@ -1,3 +1,19 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #ifndef WIDGET_ADD_WATCHER #define WIDGET_ADD_WATCHER diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index ecac9335c..9ed12988e 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -3271,37 +3271,34 @@ namespace NLGUI CInterfaceElement* CWidgetManager::addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName ) { - // Check if this group exists - CInterfaceElement *e = getElementFromId( group ); - if( e == NULL ) - return NULL; - CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( e ); - if( g == NULL ) - return NULL; - - // Check if an element already exists with that name - if( g->getElement( widgetName ) != NULL ) - return NULL; - - // Create and add the new widget - CViewBase *v = getParser()->createClass( "button" ); - if( v == NULL ) - return NULL; - - v->setId( std::string( g->getId() + ":" + widgetName ) ); - - v->setParentPosRef( Hotspot_TL ); - v->setPosRef( Hotspot_TL ); - - if( v->isGroup() ) - g->addGroup( dynamic_cast< CInterfaceGroup* >( v ) ); - else - if( v->isCtrl() ) - g->addCtrl( dynamic_cast< CCtrlBase* >( v ) ); - else - g->addView( v ); - - // Invalidate so it shows up! + // Check if this group exists + CInterfaceElement *e = getElementFromId( group ); + if( e == NULL ) + return NULL; + CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( e ); + if( g == NULL ) + return NULL; + + // Check if an element already exists with that name + if( g->getElement( widgetName ) != NULL ) + return NULL; + + // Create and add the new widget + CViewBase *v = getParser()->createClass( widgetClass ); + if( v == NULL ) + return NULL; + + v->setId( std::string( g->getId() + ":" + widgetName ) ); + + if( v->isGroup() ) + g->addGroup( dynamic_cast< CInterfaceGroup* >( v ) ); + else + if( v->isCtrl() ) + g->addCtrl( dynamic_cast< CCtrlBase* >( v ) ); + else + g->addView( v ); + + // Invalidate so it shows up! v->invalidateCoords(); notifyAdditionWatchers( v->getId() ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp index c91381fb7..44d0ad562 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp @@ -19,6 +19,7 @@ #include "nel/gui/interface_group.h" #include "nel/gui/widget_manager.h" +#include "widget_info_tree.h" namespace GUIEditor { @@ -57,13 +58,42 @@ namespace GUIEditor void CEditorMessageProcessor::onAdd( const QString &parentGroup, const QString &widgetType, const QString &name ) { + CWidgetInfoTreeNode *node = tree->findNodeByName( std::string( widgetType.toUtf8() ) ); + // No such widget + if( node == NULL ) + { + QMessageBox::critical( + NULL, + tr( "Error" ), + tr( "Error adding the new widget! No such widget type!" ), + QMessageBox::Ok + ); + + return; + } + + // No class name defined + std::string className = node->getInfo().className; + if( className.empty() ) + { + QMessageBox::critical( + NULL, + tr( "Error" ), + tr( "Error adding the new widget! Missing classname!" ), + QMessageBox::Ok + ); + + return; + } + CInterfaceElement *e = CWidgetManager::getInstance()->addWidgetToGroup( std::string( parentGroup.toUtf8() ), - std::string( widgetType.toUtf8() ), + className, std::string( name.toUtf8() ) ); + // Failed to add widget if( e == NULL ) { QMessageBox::critical( @@ -72,7 +102,29 @@ namespace GUIEditor tr( "Error adding the new widget!" ), QMessageBox::Ok ); + + return; } + + // Setting the defaults will override the Id too + std::string id = e->getId(); + + // Set up the defaults + std::vector< SPropEntry >::const_iterator itr = node->getInfo().props.begin(); + while( itr != node->getInfo().props.end() ) + { + e->setProperty( itr->propName, itr->propDefault ); + ++itr; + } + + // Restore the Id + e->setId( id ); + // Make the widget aligned to the top left corner + e->setParentPosRef( Hotspot_TL ); + e->setPosRef( Hotspot_TL ); + + // Apply the new settings + e->invalidateCoords(); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h index 1d41e87a6..ffeedd7f1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.h @@ -18,17 +18,29 @@ namespace GUIEditor { + class CWidgetInfoTree; + /// Processes the GUI Editor's editor messages like delete, new, etc... class CEditorMessageProcessor : public QObject { Q_OBJECT public: - CEditorMessageProcessor( QObject *parent = NULL ) : QObject( parent ){} + CEditorMessageProcessor( QObject *parent = NULL ) : + QObject( parent ) + { + tree = NULL; + } + ~CEditorMessageProcessor(){} + + void setTree( CWidgetInfoTree *tree ){ this->tree = tree; } public Q_SLOTS: void onDelete(); void onAdd( const QString &parentGroup, const QString &widgetType, const QString &name ); + + private: + CWidgetInfoTree *tree; }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp index 8ccd510ef..341338d8d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp @@ -79,6 +79,7 @@ namespace GUIEditor parser.parseGUIWidgets(); widgetProps->setupWidgetInfo( widgetInfoTree ); addWidgetWidget->setupWidgetInfo( widgetInfoTree ); + messageProcessor->setTree( widgetInfoTree ); QDockWidget *dock = new QDockWidget( "Widget Hierarchy", this ); dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info.h index 7a33ef056..2f7396071 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info.h @@ -53,6 +53,7 @@ namespace GUIEditor { std::string name; std::string GUIName; + std::string className; std::string ancestor; std::string description; bool isAbstract; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.cpp index 4c2339c40..cf7acca1a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.cpp @@ -63,6 +63,7 @@ namespace GUIEditor f << "\t
" << std::endl; f << "\t\t" << info.name << "" << std::endl; f << "\t\t" << info.GUIName << "" << std::endl; + f << "\t\t" << info.className << "" << std::endl; f << "\t\t" << info.ancestor << "" << std::endl; f << "\t\t" << info.description << "" << std::endl; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.cpp index fe7ee6d54..d4d708db4 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.cpp @@ -131,6 +131,9 @@ namespace GUIEditor if( key == "guiname" ) info.GUIName = value.toUtf8().constData(); else + if( key == "classname" ) + info.className = value.toUtf8().constData(); + else if( key == "ancestor" ) info.ancestor = value.toUtf8().constData(); else diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlButton.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlButton.xml index 12b82e7f6..cb6f6c099 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlButton.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlButton.xml @@ -2,6 +2,7 @@
CtrlButton CCtrlButton + button CtrlBaseButton false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlColPick.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlColPick.xml index ea2ba6171..6ac05fbcc 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlColPick.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlColPick.xml @@ -2,6 +2,7 @@
CtrlColPick CCtrlColPick + colpick CtrlBase false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlScroll.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlScroll.xml index 1ad970f31..a5c8dae1e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlScroll.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlScroll.xml @@ -2,6 +2,7 @@
CtrlScroll CCtrlScroll + scroll CtrlBase false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlTextButton.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlTextButton.xml index 1195432d1..8826cd5db 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlTextButton.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlTextButton.xml @@ -2,6 +2,7 @@
CtrlTextButton CCtrlTextButton + text_button CtrlBaseButton false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBGroupSelectNumber.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBGroupSelectNumber.xml index 624ded887..63be51b5e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBGroupSelectNumber.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBGroupSelectNumber.xml @@ -2,6 +2,7 @@
DBGroupSelectNumber CDBGroupSelectNumber + select_number InterfaceGroup false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewBar.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewBar.xml index 33250a27c..c7f2e488c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewBar.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewBar.xml @@ -2,6 +2,7 @@
DBViewBar CDBViewBar + bar ViewBitmap false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewBar3.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewBar3.xml index fbb74ad3b..9b12a637a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewBar3.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewBar3.xml @@ -2,6 +2,7 @@
DBViewBar3 CDBViewBar3 + bar3 ViewBitmap false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewDigit.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewDigit.xml index 0d9aca44a..8a2a28831 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewDigit.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewDigit.xml @@ -2,6 +2,7 @@
DBViewDigit CDBViewDigit + digit CtrlBase false @@ -11,7 +12,7 @@ value string - + 0 numdigit diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewNumber.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewNumber.xml index c1861df61..95a43025e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewNumber.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewNumber.xml @@ -2,6 +2,7 @@
DBViewNumber CDBViewNumber + text_number ViewText false @@ -11,7 +12,7 @@ value string - + 0 positive diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewQuantity.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewQuantity.xml index c24379c96..1b812bccf 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewQuantity.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/DBViewQuantity.xml @@ -2,6 +2,7 @@
DBViewQuantity CDBViewQuantity + text_quantity ViewText false @@ -11,17 +12,17 @@ value string - + 0 valuemax string - + 100 emptytext string - + empty text diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupContainer.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupContainer.xml index ad167520d..bdbf9931a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupContainer.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupContainer.xml @@ -2,6 +2,7 @@
GroupContainer CGroupContainer + container InterfaceGroup false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupEditBox.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupEditBox.xml index 31ca205c7..603af6c04 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupEditBox.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupEditBox.xml @@ -2,6 +2,7 @@
GroupEditBox CGroupEditBox + edit_box InterfaceGroup false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupHTML.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupHTML.xml index fe2235c04..b76fe4cd4 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupHTML.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupHTML.xml @@ -2,6 +2,7 @@
GroupHTML CGroupHTML + html GroupScrollText false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupHeader.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupHeader.xml index cc96fd742..bcb517c66 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupHeader.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupHeader.xml @@ -2,6 +2,7 @@
GroupHeader CGroupHeader + header GroupList false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupList.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupList.xml index e7db36de6..1858cd5b3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupList.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupList.xml @@ -2,6 +2,7 @@
GroupList CGroupList + list InterfaceGroup false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupMenu.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupMenu.xml index ac57b5c4d..4739f0352 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupMenu.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupMenu.xml @@ -2,6 +2,7 @@
GroupMenu CGroupMenu + menu GroupModal false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupModal.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupModal.xml index 034e3025e..afc5005c8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupModal.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupModal.xml @@ -2,6 +2,7 @@
GroupModal CGroupModal + modal GroupFrame false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupScrollText.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupScrollText.xml index 95719398d..8cefb8df2 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupScrollText.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupScrollText.xml @@ -2,6 +2,7 @@
GroupScrollText CGroupScrollText + scroll_text InterfaceGroup false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTab.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTab.xml index df148a0a3..69db79466 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTab.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTab.xml @@ -2,6 +2,7 @@
GroupTab CGroupTab + tab InterfaceGroup false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTable.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTable.xml index 8e9b8cffe..9c2240adc 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTable.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTable.xml @@ -2,6 +2,7 @@
GroupTable CGroupTable + table InterfaceGroup false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTree.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTree.xml index 8e075ac53..6bd10ad9f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTree.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/GroupTree.xml @@ -2,6 +2,7 @@
GroupTree CGroupTree + tree InterfaceGroup false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroup.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroup.xml index b9e99d336..c9a8c1546 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroup.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroup.xml @@ -2,6 +2,7 @@
InterfaceGroup CInterfaceGroup + interface_group CtrlBase false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroupWheel.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroupWheel.xml index 62d67cc0a..51590ee33 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroupWheel.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroupWheel.xml @@ -2,6 +2,7 @@
InterfaceGroupWheel CInterfaceGroupWheel + group_wheel InterfaceGroup false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewBitmap.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewBitmap.xml index 9da967b5a..8b931f78b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewBitmap.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewBitmap.xml @@ -2,6 +2,7 @@
ViewBitmap CViewBitmap + bitmap CtrlBase false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewBitmapCombo.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewBitmapCombo.xml index 0b55f6932..190143be5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewBitmapCombo.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewBitmapCombo.xml @@ -2,6 +2,7 @@
ViewBitmapCombo CViewBitmapCombo + bitmap_combo CtrlBase false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewText.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewText.xml index 378854df5..f2a0b28df 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewText.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewText.xml @@ -2,6 +2,7 @@
ViewText CViewText + text InterfaceElement false @@ -101,7 +102,7 @@ hardtext string - + some text hardtext_format diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextFormated.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextFormated.xml index cabd081f0..c5749ca9c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextFormated.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextFormated.xml @@ -2,6 +2,7 @@
ViewTextFormated CViewTextFormated + text_formated ViewText false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextID.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextID.xml index 52e010ec6..b3edc86ab 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextID.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextID.xml @@ -2,6 +2,7 @@
ViewTextID CViewTextID + text_id ViewText false diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextIDFormated.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextIDFormated.xml index af8dd54eb..3ac6c7962 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextIDFormated.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewTextIDFormated.xml @@ -2,6 +2,7 @@
ViewTextIDFormated CViewTextIDFormated + text_id_formated ViewTextID false From 057960d0567bf288c927e1961f9c7804dcaac001 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 10 May 2013 00:28:29 +0200 Subject: [PATCH 19/25] Forgot to set the parent. --HG-- branch : gsoc2012-gui-editor --- code/nel/src/gui/widget_manager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index 9ed12988e..f718f63a7 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -3298,6 +3298,8 @@ namespace NLGUI else g->addView( v ); + v->setParent( g ); + // Invalidate so it shows up! v->invalidateCoords(); From 9042de4ab2eee826d8c19f724a26834a8a3bdb31 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 10 May 2013 00:55:23 +0200 Subject: [PATCH 20/25] Make sure to apply the changes, when changing properties. --HG-- branch : gsoc2012-gui-editor --- code/nel/src/gui/widget_manager.cpp | 3 --- .../src/plugins/gui_editor/editor_message_processor.cpp | 5 +++-- .../src/plugins/gui_editor/property_browser_ctrl.cpp | 6 ++++++ .../src/plugins/gui_editor/widgets/ViewText.xml | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index f718f63a7..bad93687b 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -3300,9 +3300,6 @@ namespace NLGUI v->setParent( g ); - // Invalidate so it shows up! - v->invalidateCoords(); - notifyAdditionWatchers( v->getId() ); return v; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp index 44d0ad562..c784fa527 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp @@ -123,8 +123,9 @@ namespace GUIEditor e->setParentPosRef( Hotspot_TL ); e->setPosRef( Hotspot_TL ); - // Apply the new settings - e->invalidateCoords(); + // Apply the new settings + e->setActive( false ); + e->setActive( true ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp index 3c5fa9177..82330bfaf 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp @@ -111,6 +111,12 @@ namespace GUIEditor if( e == NULL ) return; e->setProperty( propName.toUtf8().constData(), propValue.toUtf8().constData() ); + + + // Make sure the changes are applied + bool active = e->getActive(); + e->setActive( !active ); + e->setActive( active ); } void CPropBrowserCtrl::setupProperties( const std::string &type, const CInterfaceElement *element ) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewText.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewText.xml index f2a0b28df..9490a1eee 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewText.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ViewText.xml @@ -47,7 +47,7 @@ line_maxw int - 0 + 100 multi_line_space From 25195fce4ca75da989408ddeac93f31776d46ad7 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 10 May 2013 02:10:18 +0200 Subject: [PATCH 21/25] The editor probably shouldn't crash when adding textbutton widget. --HG-- branch : gsoc2012-gui-editor --- code/nel/src/gui/ctrl_text_button.cpp | 8 ++++++++ code/nel/src/gui/widget_manager.cpp | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/code/nel/src/gui/ctrl_text_button.cpp b/code/nel/src/gui/ctrl_text_button.cpp index a977902b7..8dbe9b912 100644 --- a/code/nel/src/gui/ctrl_text_button.cpp +++ b/code/nel/src/gui/ctrl_text_button.cpp @@ -886,6 +886,14 @@ namespace NLGUI { _Setuped= true; + if( _ViewText == NULL ) + { + CViewBase *v = CWidgetManager::getInstance()->getParser()->createClass( "text" ); + nlassert( v != NULL ); + _ViewText = dynamic_cast< CViewText* >( v ); + _ViewText->setText( ucstring( "text" ) ); + } + // setup the viewText and add to parent _ViewText->setParent (getParent()); _ViewText->setParentPos (this); diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index bad93687b..6e7431b70 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -3289,6 +3289,7 @@ namespace NLGUI return NULL; v->setId( std::string( g->getId() + ":" + widgetName ) ); + v->setParent( g ); if( v->isGroup() ) g->addGroup( dynamic_cast< CInterfaceGroup* >( v ) ); @@ -3298,8 +3299,6 @@ namespace NLGUI else g->addView( v ); - v->setParent( g ); - notifyAdditionWatchers( v->getId() ); return v; From b49a6ca04da264f96e17f357f072c482f2c47063 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 10 May 2013 22:29:47 +0200 Subject: [PATCH 22/25] Added some defaults. --HG-- branch : gsoc2012-gui-editor --- code/nel/src/gui/ctrl_text_button.cpp | 7 +++++++ .../plugins/gui_editor/widgets/CtrlBaseButton.xml | 2 +- .../src/plugins/gui_editor/widgets/CtrlButton.xml | 6 +++--- .../plugins/gui_editor/widgets/CtrlTextButton.xml | 12 ++++++------ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/code/nel/src/gui/ctrl_text_button.cpp b/code/nel/src/gui/ctrl_text_button.cpp index 8dbe9b912..cdf006a51 100644 --- a/code/nel/src/gui/ctrl_text_button.cpp +++ b/code/nel/src/gui/ctrl_text_button.cpp @@ -237,6 +237,11 @@ namespace NLGUI _TextureIdNormal[ 0 ].setTexture( std::string( value + "_l.tga" ).c_str() ); _TextureIdNormal[ 1 ].setTexture( std::string( value + "_m.tga" ).c_str() ); _TextureIdNormal[ 2 ].setTexture( std::string( value + "_r.tga" ).c_str() ); + + CViewRenderer &rVR = *CViewRenderer::getInstance(); + rVR.getTextureSizeFromId(_TextureIdNormal[0], _BmpLeftW, _BmpH); + rVR.getTextureSizeFromId(_TextureIdNormal[1], _BmpMiddleW, _BmpH); + rVR.getTextureSizeFromId(_TextureIdNormal[2], _BmpRightW, _BmpH); return; } else @@ -891,7 +896,9 @@ namespace NLGUI CViewBase *v = CWidgetManager::getInstance()->getParser()->createClass( "text" ); nlassert( v != NULL ); _ViewText = dynamic_cast< CViewText* >( v ); + _ViewText->setId( _Id + "_text" ); _ViewText->setText( ucstring( "text" ) ); + _ViewText->setSerializable( false ); } // setup the viewText and add to parent diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlBaseButton.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlBaseButton.xml index 722d1b241..42e2bdef1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlBaseButton.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlBaseButton.xml @@ -11,7 +11,7 @@ button_type string - toggle_button + push_button pushed diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlButton.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlButton.xml index cb6f6c099..fb2514e7c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlButton.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlButton.xml @@ -12,17 +12,17 @@ tx_normal string - + log_but_r.tga tx_pushed string - + log_but_r.tga tx_over string - + log_but_over_r.tga scale diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlTextButton.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlTextButton.xml index 8826cd5db..cacc45ccb 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlTextButton.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/CtrlTextButton.xml @@ -12,27 +12,27 @@ tx_normal string - + but tx_pushed string - + but tx_over string - + but_over hardtext string - + text wmargin int - 0 + 20 wmin @@ -152,7 +152,7 @@ line_maxw int - 0 + 200 multi_line_space From 2faff4dfaafcd03ad8ef907919a2db5f290fd870 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 10 May 2013 22:35:04 +0200 Subject: [PATCH 23/25] Inconsistent line ending style, according to VS. How it managed to do this is a mystery tho. --HG-- branch : gsoc2012-gui-editor --- .../gui_editor/editor_message_processor.cpp | 260 +++++++++--------- 1 file changed, 130 insertions(+), 130 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp index c784fa527..2a9810f24 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp @@ -1,131 +1,131 @@ -// Object Viewer Qt GUI Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#include -#include "editor_message_processor.h" - -#include "nel/gui/interface_group.h" -#include "nel/gui/widget_manager.h" -#include "widget_info_tree.h" - -namespace GUIEditor -{ - void CEditorMessageProcessor::onDelete() - { - std::string selection = CWidgetManager::getInstance()->getCurrentEditorSelection(); - if( selection.empty() ) - return; - - QMessageBox::StandardButton r = - QMessageBox::question( NULL, - tr( "Deleting widget" ), - tr( "Are you sure you want to delete %1?" ).arg( selection.c_str() ), - QMessageBox::Yes | QMessageBox::No ); - if( r != QMessageBox::Yes ) - return; - - CInterfaceElement *e = - CWidgetManager::getInstance()->getElementFromId( selection ); - if( e == NULL ) - return; - - CInterfaceElement *p = e->getParent(); - if( p == NULL ) - return; - - CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( p ); - if( g == NULL ) - return; - - if( g->delElement( e ) ) - { - CWidgetManager::getInstance()->setCurrentEditorSelection( "" ); - } - } - - void CEditorMessageProcessor::onAdd( const QString &parentGroup, const QString &widgetType, const QString &name ) - { - CWidgetInfoTreeNode *node = tree->findNodeByName( std::string( widgetType.toUtf8() ) ); - // No such widget - if( node == NULL ) - { - QMessageBox::critical( - NULL, - tr( "Error" ), - tr( "Error adding the new widget! No such widget type!" ), - QMessageBox::Ok - ); - - return; - } - - // No class name defined - std::string className = node->getInfo().className; - if( className.empty() ) - { - QMessageBox::critical( - NULL, - tr( "Error" ), - tr( "Error adding the new widget! Missing classname!" ), - QMessageBox::Ok - ); - - return; - } - - CInterfaceElement *e = - CWidgetManager::getInstance()->addWidgetToGroup( - std::string( parentGroup.toUtf8() ), - className, - std::string( name.toUtf8() ) - ); - - // Failed to add widget - if( e == NULL ) - { - QMessageBox::critical( - NULL, - tr( "Error" ), - tr( "Error adding the new widget!" ), - QMessageBox::Ok - ); - - return; - } - - // Setting the defaults will override the Id too - std::string id = e->getId(); - - // Set up the defaults - std::vector< SPropEntry >::const_iterator itr = node->getInfo().props.begin(); - while( itr != node->getInfo().props.end() ) - { - e->setProperty( itr->propName, itr->propDefault ); - ++itr; - } - - // Restore the Id - e->setId( id ); - // Make the widget aligned to the top left corner - e->setParentPosRef( Hotspot_TL ); - e->setPosRef( Hotspot_TL ); - +// Object Viewer Qt GUI Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include +#include "editor_message_processor.h" + +#include "nel/gui/interface_group.h" +#include "nel/gui/widget_manager.h" +#include "widget_info_tree.h" + +namespace GUIEditor +{ + void CEditorMessageProcessor::onDelete() + { + std::string selection = CWidgetManager::getInstance()->getCurrentEditorSelection(); + if( selection.empty() ) + return; + + QMessageBox::StandardButton r = + QMessageBox::question( NULL, + tr( "Deleting widget" ), + tr( "Are you sure you want to delete %1?" ).arg( selection.c_str() ), + QMessageBox::Yes | QMessageBox::No ); + if( r != QMessageBox::Yes ) + return; + + CInterfaceElement *e = + CWidgetManager::getInstance()->getElementFromId( selection ); + if( e == NULL ) + return; + + CInterfaceElement *p = e->getParent(); + if( p == NULL ) + return; + + CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( p ); + if( g == NULL ) + return; + + if( g->delElement( e ) ) + { + CWidgetManager::getInstance()->setCurrentEditorSelection( "" ); + } + } + + void CEditorMessageProcessor::onAdd( const QString &parentGroup, const QString &widgetType, const QString &name ) + { + CWidgetInfoTreeNode *node = tree->findNodeByName( std::string( widgetType.toUtf8() ) ); + // No such widget + if( node == NULL ) + { + QMessageBox::critical( + NULL, + tr( "Error" ), + tr( "Error adding the new widget! No such widget type!" ), + QMessageBox::Ok + ); + + return; + } + + // No class name defined + std::string className = node->getInfo().className; + if( className.empty() ) + { + QMessageBox::critical( + NULL, + tr( "Error" ), + tr( "Error adding the new widget! Missing classname!" ), + QMessageBox::Ok + ); + + return; + } + + CInterfaceElement *e = + CWidgetManager::getInstance()->addWidgetToGroup( + std::string( parentGroup.toUtf8() ), + className, + std::string( name.toUtf8() ) + ); + + // Failed to add widget + if( e == NULL ) + { + QMessageBox::critical( + NULL, + tr( "Error" ), + tr( "Error adding the new widget!" ), + QMessageBox::Ok + ); + + return; + } + + // Setting the defaults will override the Id too + std::string id = e->getId(); + + // Set up the defaults + std::vector< SPropEntry >::const_iterator itr = node->getInfo().props.begin(); + while( itr != node->getInfo().props.end() ) + { + e->setProperty( itr->propName, itr->propDefault ); + ++itr; + } + + // Restore the Id + e->setId( id ); + // Make the widget aligned to the top left corner + e->setParentPosRef( Hotspot_TL ); + e->setPosRef( Hotspot_TL ); + // Apply the new settings - e->setActive( false ); - e->setActive( true ); - } -} - + e->setActive( false ); + e->setActive( true ); + } +} + From b29fd5ca1130f95260d1cc0eb23da70e7f75ebf0 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 11 May 2013 02:40:55 +0200 Subject: [PATCH 24/25] Editbox should now create it's text when added. --HG-- branch : gsoc2012-gui-editor --- code/nel/src/gui/group_editbox.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/code/nel/src/gui/group_editbox.cpp b/code/nel/src/gui/group_editbox.cpp index 4e8eb3e36..26feff20c 100644 --- a/code/nel/src/gui/group_editbox.cpp +++ b/code/nel/src/gui/group_editbox.cpp @@ -1411,7 +1411,8 @@ namespace NLGUI // ---------------------------------------------------------------------------- void CGroupEditBox::checkCoords() { - setupDisplayText(); + if( !editorMode ) + setupDisplayText(); CInterfaceGroup::checkCoords(); } @@ -1530,7 +1531,29 @@ namespace NLGUI _ViewText = dynamic_cast(CInterfaceGroup::getView("edit_text")); if(_ViewText == NULL) + { nlwarning("Interface: CGroupEditBox: text 'edit_text' missing or bad type"); + if( editorMode ) + { + nlwarning( "Trying to create a new 'edit_text' for %s", getId().c_str() ); + _ViewText = dynamic_cast< CViewText* >( CWidgetManager::getInstance()->getParser()->createClass( "text" ) ); + if( _ViewText != NULL ) + { + _ViewText->setParent( this ); + _ViewText->setIdRecurse( "edit_text" ); + _ViewText->setHardText( "sometext" ); + _ViewText->setPosRef( Hotspot_TL ); + _ViewText->setParentPosRef( Hotspot_TL ); + addView( _ViewText ); + + setH( _ViewText->getFontHeight() ); + setW( _ViewText->getFontWidth() * _ViewText->getText().size() ); + + } + else + nlwarning( "Failed to create new 'edit_text' for %s", getId().c_str() ); + } + } // For MultiLine editbox, clip the end space, else weird when edit space at end of line (nothing happens) if(_ViewText) From f382b97f74f26ebc93115848aaccf5223c9b6cd5 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 15 May 2013 01:54:35 +0200 Subject: [PATCH 25/25] Making GCC happy. --HG-- branch : gsoc2012-gui-editor --- .../src/plugins/gui_editor/editor_message_processor.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp index 2a9810f24..691dbdead 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_message_processor.cpp @@ -86,11 +86,14 @@ namespace GUIEditor return; } + std::string pgName = std::string( parentGroup.toUtf8() ); + std::string wName = std::string( name.toUtf8() ); + CInterfaceElement *e = CWidgetManager::getInstance()->addWidgetToGroup( - std::string( parentGroup.toUtf8() ), + pgName, className, - std::string( name.toUtf8() ) + wName ); // Failed to add widget