Added support for ungrouping.

This commit is contained in:
dfighter1985 2014-10-08 20:36:16 +02:00
parent 6737dfb1b6
commit f48c247e2b
7 changed files with 95 additions and 0 deletions

View file

@ -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);

View file

@ -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();

View file

@ -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;
}
}

View file

@ -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()
{

View file

@ -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." ) );
}
}
}

View file

@ -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;

View file

@ -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();