Refactored IWidgetAdditionWatcher, now it's called IWidgetWatcher and it also reports widget moves.

This commit is contained in:
dfighter1985 2014-09-24 23:32:24 +02:00
parent f7825fc8b3
commit e6f4801129
5 changed files with 70 additions and 67 deletions

View file

@ -1,32 +0,0 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// 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 <http://www.gnu.org/licenses/>.
#ifndef WIDGET_ADD_WATCHER
#define WIDGET_ADD_WATCHER
#include <string>
namespace NLGUI
{
class IWidgetAdditionWatcher
{
public:
virtual void widgetAdded( const std::string &name ) = 0;
};
}
#endif

View file

@ -75,6 +75,16 @@ namespace NLGUI
virtual void process() = 0;
};
// Interface for event handlers that can be called when widgets are added or moved
class IWidgetWatcher
{
public:
IWidgetWatcher(){}
virtual ~IWidgetWatcher(){}
virtual void onWidgetAdded( const std::string &name ) = 0;
virtual void onWidgetMoved( const std::string &oldid, const std::string &newid ) = 0;
};
/// Frame render times
struct SInterfaceTimes
{
@ -498,10 +508,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 );
void onWidgetAdded( const std::string &id );
void onWidgetMoved( const std::string &oldid, const std::string &newid );
void registerWidgetWatcher( IWidgetWatcher *watcher );
void unregisterWidgetWatcher( IWidgetWatcher *watcher );
CInterfaceElement* addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName );
@ -594,7 +606,7 @@ namespace NLGUI
std::vector< INewScreenSizeHandler* > newScreenSizeHandlers;
std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers;
std::vector< IEditorSelectionWatcher* > selectionWatchers;
std::vector< IWidgetAdditionWatcher* > additionWatchers;
std::vector< IWidgetWatcher* > widgetWatchers;
std::string currentEditorSelection;

View file

@ -34,7 +34,6 @@
#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
@ -2669,6 +2668,8 @@ namespace NLGUI
if( g == NULL )
g = tw;
std::string oldid = e->getId();
e->setParent( g );
e->setIdRecurse( e->getShortId() );
@ -2677,6 +2678,8 @@ namespace NLGUI
g->addElement( e );
draggedElement = NULL;
onWidgetMoved( oldid, e->getId() );
}
}
@ -3364,36 +3367,46 @@ namespace NLGUI
selectionWatchers.erase( itr );
}
void CWidgetManager::notifyAdditionWatchers( const std::string &widgetName )
void CWidgetManager::onWidgetAdded( const std::string &id )
{
std::vector< IWidgetAdditionWatcher* >::const_iterator itr = additionWatchers.begin();
while( itr != additionWatchers.end() )
std::vector< IWidgetWatcher* >::const_iterator itr = widgetWatchers.begin();
while( itr != widgetWatchers.end() )
{
(*itr)->widgetAdded( widgetName );
(*itr)->onWidgetAdded( id );
++itr;
}
}
void CWidgetManager::registerAdditionWatcher( IWidgetAdditionWatcher *watcher )
void CWidgetManager::onWidgetMoved( const std::string &oldid, const std::string &newid )
{
std::vector< IWidgetAdditionWatcher* >::const_iterator itr
= std::find( additionWatchers.begin(), additionWatchers.end(), watcher );
// already exists
if( itr != additionWatchers.end() )
return;
additionWatchers.push_back( watcher );
std::vector< IWidgetWatcher* >::const_iterator itr = widgetWatchers.begin();
while( itr != widgetWatchers.end() )
{
(*itr)->onWidgetMoved( oldid, newid );
++itr;
}
}
void CWidgetManager::unregisterAdditionWatcher( IWidgetAdditionWatcher *watcher )
void CWidgetManager::registerWidgetWatcher( IWidgetWatcher *watcher )
{
std::vector< IWidgetAdditionWatcher* >::iterator itr
= std::find( additionWatchers.begin(), additionWatchers.end(), watcher );
// doesn't exist
if( itr == additionWatchers.end() )
std::vector< IWidgetWatcher* >::const_iterator itr
= std::find( widgetWatchers.begin(), widgetWatchers.end(), watcher );
// already exists
if( itr != widgetWatchers.end() )
return;
additionWatchers.erase( itr );
widgetWatchers.push_back( watcher );
}
void CWidgetManager::unregisterWidgetWatcher( IWidgetWatcher *watcher )
{
std::vector< IWidgetWatcher* >::iterator itr
= std::find( widgetWatchers.begin(), widgetWatchers.end(), watcher );
// doesn't exist
if( itr == widgetWatchers.end() )
return;
widgetWatchers.erase( itr );
}
CInterfaceElement* CWidgetManager::addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName )
@ -3426,7 +3439,7 @@ namespace NLGUI
else
g->addView( v );
notifyAdditionWatchers( v->getId() );
onWidgetAdded( v->getId() );
return v;
}

View file

@ -18,7 +18,6 @@
#include "widget_hierarchy.h"
#include "nel/gui/interface_group.h"
#include "nel/gui/widget_manager.h"
#include "nel/gui/widget_addition_watcher.h"
namespace
{
@ -76,18 +75,24 @@ namespace
GUIEditor::WidgetHierarchy *h;
};
class CWidgetAdditionWatcher : public IWidgetAdditionWatcher
class CWidgetWatcher : public CWidgetManager::IWidgetWatcher
{
public:
CWidgetAdditionWatcher(){ h = NULL; }
~CWidgetAdditionWatcher(){}
CWidgetWatcher(){ h = NULL; }
~CWidgetWatcher(){}
void widgetAdded( const std::string &name )
void onWidgetAdded( const std::string &name )
{
if( h != NULL )
h->onWidgetAdded( name );
}
void onWidgetMoved( const std::string &oldid, const std::string &newid )
{
if( h != NULL )
h->onWidgetMoved( oldid, newid );
}
void setWidgetHierarchy( GUIEditor::WidgetHierarchy *h ){ this->h = h; }
private:
@ -95,7 +100,7 @@ namespace
};
CWidgetDeletionWatcher deletionWatcher;
CWidgetAdditionWatcher additionWatcher;
CWidgetWatcher widgetwatcher;
}
namespace GUIEditor
@ -107,7 +112,7 @@ namespace GUIEditor
connect( widgetHT, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ),
this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) );
deletionWatcher.setWidgetHierarchy( this );
additionWatcher.setWidgetHierarchy( this );
widgetwatcher.setWidgetHierarchy( this );
}
WidgetHierarchy::~WidgetHierarchy()
@ -117,7 +122,7 @@ namespace GUIEditor
void WidgetHierarchy::clearHierarchy()
{
CInterfaceElement::unregisterDeletionWatcher( &deletionWatcher );
CWidgetManager::getInstance()->unregisterAdditionWatcher( &additionWatcher );
CWidgetManager::getInstance()->unregisterWidgetWatcher( &widgetwatcher );
widgetHT->clear();
widgetHierarchyMap.clear();
}
@ -126,7 +131,7 @@ namespace GUIEditor
{
clearHierarchy();
CInterfaceElement::registerDeletionWatcher( &deletionWatcher );
CWidgetManager::getInstance()->registerAdditionWatcher( &additionWatcher );
CWidgetManager::getInstance()->registerWidgetWatcher( &widgetwatcher );
CInterfaceGroup *mg = CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup );
if( mg != NULL )
@ -231,6 +236,10 @@ namespace GUIEditor
widgetHierarchyMap[ id ] = item;
}
void WidgetHierarchy::onWidgetMoved( const std::string &oldid, const std::string &newid )
{
}
void WidgetHierarchy::getCurrentGroup( QString &g )
{
std::string s = CWidgetManager::getInstance()->getCurrentEditorSelection();

View file

@ -44,6 +44,7 @@ namespace GUIEditor
void onWidgetDeleted( const std::string &id );
void onWidgetAdded( const std::string &id );
void onWidgetMoved( const std::string &oldid, const std::string &newid );
void getCurrentGroup( QString &g );