From 3ffe56b862850eafe088f5abee6df32486943cd3 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 8 Oct 2014 20:36:16 +0200 Subject: [PATCH] Added support for ungrouping. --HG-- branch : dfighter-tools --- code/nel/include/nel/gui/interface_group.h | 3 ++ code/nel/include/nel/gui/widget_manager.h | 1 + code/nel/src/gui/interface_group.cpp | 40 +++++++++++++++++++ code/nel/src/gui/widget_manager.cpp | 34 ++++++++++++++++ .../gui_editor/editor_message_processor.cpp | 12 ++++++ .../gui_editor/editor_message_processor.h | 1 + .../plugins/gui_editor/gui_editor_window.cpp | 4 ++ 7 files changed, 95 insertions(+) diff --git a/code/nel/include/nel/gui/interface_group.h b/code/nel/include/nel/gui/interface_group.h index 62e61373e..cdfd182e7 100644 --- a/code/nel/include/nel/gui/interface_group.h +++ b/code/nel/include/nel/gui/interface_group.h @@ -330,6 +330,9 @@ namespace NLGUI void moveBy( sint32 x, sint32 y ); + // Blows up the group, moves it's children to it's parent + bool explode(); + protected: void makeNewClip (sint32 &oldClipX, sint32 &oldClipY, sint32 &oldClipW, sint32 &oldClipH); diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index 8790fc272..917a0e9ba 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -518,6 +518,7 @@ namespace NLGUI CInterfaceElement* addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName ); void setGroupSelection( bool b ){ groupSelection = b; } + bool unGroupSelection(); private: CWidgetManager(); diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index ac6b57fb0..35b493ecb 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -2555,5 +2555,45 @@ namespace NLGUI v->updateCoords(); } } + + bool CInterfaceGroup::explode() + { + CInterfaceGroup *p = getParent(); + if( p == NULL ) + return false; + + std::string oldId; + + // Reparent children + for( sint32 i = 0; i < _EltOrder.size(); i++ ) + { + CInterfaceElement *e = _EltOrder[ i ]; + + oldId = e->getId(); + + e->setParent( p ); + + if( e->getParentPos() == this ) + e->setParentPos( p ); + + if( e->getParentSize() == this ) + e->setParentSize( p ); + + if( e->getParentPos() == p ) + e->alignTo( p ); + + p->addElement( e ); + e->setIdRecurse( e->getShortId() ); + + CWidgetManager::getInstance()->onWidgetMoved( oldId, e->getId() ); + } + + _EltOrder.clear(); + _Views.clear(); + _Controls.clear(); + _ChildrenGroups.clear(); + + return true; + } } diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index c6068b363..21c9bd53d 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -3477,6 +3477,40 @@ namespace NLGUI return v; } + bool CWidgetManager::unGroupSelection() + { + if( currentEditorSelection.empty() ) + return false; + + // Does the element exist? + CInterfaceElement *e = getElementFromId( currentEditorSelection ); + if( e == NULL ) + return false; + + // Is the element a group? + CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( e ); + if( g == NULL ) + return false; + + // Can't blow up a root group :( + CInterfaceGroup *p = g->getParent(); + if( p == NULL ) + return false; + + // KABOOM! + bool ok = g->explode(); + if( !ok ) + return false; + + p->delElement( g ); + + setCurrentEditorSelection( "" ); + + p->updateCoords(); + + return true; + } + CWidgetManager::CWidgetManager() { diff --git a/code/studio/src/plugins/gui_editor/editor_message_processor.cpp b/code/studio/src/plugins/gui_editor/editor_message_processor.cpp index e834aa21f..4c48a4fa4 100644 --- a/code/studio/src/plugins/gui_editor/editor_message_processor.cpp +++ b/code/studio/src/plugins/gui_editor/editor_message_processor.cpp @@ -135,5 +135,17 @@ namespace GUIEditor { CWidgetManager::getInstance()->setGroupSelection( b ); } + + void CEditorMessageProcessor::onUngroup() + { + bool ok = CWidgetManager::getInstance()->unGroupSelection(); + + if( !ok ) + { + QMessageBox::critical( NULL, + tr( "Ungrouping widgets" ), + tr( "Couldn't ungroup widgets." ) ); + } + } } diff --git a/code/studio/src/plugins/gui_editor/editor_message_processor.h b/code/studio/src/plugins/gui_editor/editor_message_processor.h index 5d4098272..9e6d3cf89 100644 --- a/code/studio/src/plugins/gui_editor/editor_message_processor.h +++ b/code/studio/src/plugins/gui_editor/editor_message_processor.h @@ -39,6 +39,7 @@ namespace GUIEditor void onDelete(); void onAdd( const QString &parentGroup, const QString &widgetType, const QString &name ); void onSetGroupSelection( bool b ); + void onUngroup(); private: CWidgetInfoTree *tree; diff --git a/code/studio/src/plugins/gui_editor/gui_editor_window.cpp b/code/studio/src/plugins/gui_editor/gui_editor_window.cpp index 3a4f982aa..01433bf9e 100644 --- a/code/studio/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/studio/src/plugins/gui_editor/gui_editor_window.cpp @@ -399,6 +399,10 @@ namespace GUIEditor connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onAddWidgetClicked() ) ); m->addAction( a ); + a = new QAction( "Ungroup", this ); + connect( a, SIGNAL( triggered() ), messageProcessor, SLOT( onUngroup() ) ); + m->addAction( a ); + // ---------------------------------------------------------------------------------- m->addSeparator();