Merged upstream changes.

This commit is contained in:
dfighter1985 2013-03-12 06:11:50 +01:00
commit 9cf63bf950
27 changed files with 627 additions and 64 deletions

View file

@ -68,9 +68,7 @@ namespace NLGUI
// special parse // special parse
virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup); virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup);
bool handleEvent (const NLGUI::CEventDescriptor &event);
/// Handle all events (implemented by derived classes) (return true to signal event handled)
virtual bool handleEvent (const NLGUI::CEventDescriptor &event);
virtual CCtrlBase *getSubCtrl (sint32 /* x */, sint32 /* y */) { return this; } virtual CCtrlBase *getSubCtrl (sint32 /* x */, sint32 /* y */) { return this; }

View file

@ -42,6 +42,7 @@ namespace NLGUI
/// Constructor /// Constructor
CCtrlTextButton(const TCtorParam &param); CCtrlTextButton(const TCtorParam &param);
~CCtrlTextButton();
std::string getProperty( const std::string &name ) const; std::string getProperty( const std::string &name ) const;
void setProperty( const std::string &name, const std::string &value ); void setProperty( const std::string &name, const std::string &value );
@ -123,6 +124,9 @@ namespace NLGUI
REFLECT_LUA_METHOD("getViewText", luaGetViewText) REFLECT_LUA_METHOD("getViewText", luaGetViewText)
REFLECT_EXPORT_END REFLECT_EXPORT_END
void onRemoved();
void onWidgetDeleted( CInterfaceElement *e );
protected: protected:
enum {NumTexture= 3}; enum {NumTexture= 3};

View file

@ -0,0 +1,30 @@
// 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/>.
#include <string>
namespace NLGUI
{
/// Watches the currently selected GUI widget
class IEditorSelectionWatcher
{
public:
/// Notifies the watcher about the change
virtual void selectionChanged( std::string &newSelection ) = 0;
};
}

View file

@ -70,6 +70,14 @@ namespace NLGUI
{ {
public: public:
/// Watches CInterfaceElement deletions
class IDeletionWatcher
{
public:
IDeletionWatcher(){}
virtual ~IDeletionWatcher(){}
virtual void onDeleted( const std::string &name ){}
};
enum EStrech enum EStrech
{ {
@ -424,6 +432,8 @@ namespace NLGUI
void drawHotSpot(THotSpot hs, NLMISC::CRGBA col); void drawHotSpot(THotSpot hs, NLMISC::CRGBA col);
void drawHighlight();
// Returns 'true' if that element can be downcasted to a view // Returns 'true' if that element can be downcasted to a view
virtual bool isView() const { return false; } virtual bool isView() const { return false; }
@ -473,6 +483,7 @@ namespace NLGUI
bool isInGroup( CInterfaceGroup *group ); bool isInGroup( CInterfaceGroup *group );
static void setEditorMode( bool b ){ editorMode = b; } static void setEditorMode( bool b ){ editorMode = b; }
static bool getEditorMode(){ return editorMode; }
void setEditorSelected( bool b ){ editorSelected = b; } void setEditorSelected( bool b ){ editorSelected = b; }
bool isEditorSelected() const{ return editorSelected; } bool isEditorSelected() const{ return editorSelected; }
@ -483,6 +494,19 @@ namespace NLGUI
void setSerializable( bool b ){ serializable = b; } void setSerializable( bool b ){ serializable = b; }
bool IsSerializable() const{ return serializable; } bool IsSerializable() const{ return serializable; }
/// 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 );
/// 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: protected:
bool editorSelected; bool editorSelected;
@ -543,6 +567,11 @@ namespace NLGUI
void parseSizeRef(const char *sizeRefStr, sint32 &sizeref, sint32 &sizeDivW, sint32 &sizeDivH); void parseSizeRef(const char *sizeRefStr, sint32 &sizeref, sint32 &sizeDivW, sint32 &sizeDivH);
private: private:
/// Notifies the deletion watchers that this interface element is being deleted
void notifyDeletionWatchers();
static std::vector< IDeletionWatcher* > deletionWatchers;
//void snapSize(); //void snapSize();
bool serializable; bool serializable;

View file

@ -322,6 +322,8 @@ namespace NLGUI
// Return the current Depth, with no ZBias applied. // Return the current Depth, with no ZBias applied.
float getDepthForZSort() const { return _DepthForZSort; } float getDepthForZSort() const { return _DepthForZSort; }
void onWidgetDeleted( CInterfaceElement *e );
protected: protected:
void makeNewClip (sint32 &oldClipX, sint32 &oldClipY, sint32 &oldClipW, sint32 &oldClipH); void makeNewClip (sint32 &oldClipX, sint32 &oldClipY, sint32 &oldClipW, sint32 &oldClipH);

View file

@ -25,6 +25,7 @@
namespace NLGUI namespace NLGUI
{ {
class CEventDescriptor;
class CViewBase : public CInterfaceElement class CViewBase : public CInterfaceElement
{ {
@ -77,6 +78,9 @@ namespace NLGUI
// special for mouse over : return true and fill the name of the cursor to display // 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; } 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);
}; };
} }

View file

@ -47,6 +47,7 @@ namespace NLGUI
class CInterfaceOptions; class CInterfaceOptions;
class CInterfaceAnim; class CInterfaceAnim;
class CProcedure; class CProcedure;
class IEditorSelectionWatcher;
/** /**
GUI Widget Manager GUI Widget Manager
@ -341,6 +342,7 @@ namespace NLGUI
/** /**
* Capture * Capture
*/ */
CViewBase *getCapturedView(){ return _CapturedView; }
CCtrlBase *getCapturePointerLeft() { return _CapturePointerLeft; } CCtrlBase *getCapturePointerLeft() { return _CapturePointerLeft; }
CCtrlBase *getCapturePointerRight() { return _CapturePointerRight; } CCtrlBase *getCapturePointerRight() { return _CapturePointerRight; }
CCtrlBase *getCaptureKeyboard() { return _CaptureKeyboard; } CCtrlBase *getCaptureKeyboard() { return _CaptureKeyboard; }
@ -483,7 +485,11 @@ namespace NLGUI
IParser* getParser() const{ return parser; } IParser* getParser() const{ return parser; }
std::string& getCurrentEditorSelection(){ return currentEditorSelection; }
void setCurrentEditorSelection( const std::string &name ); void setCurrentEditorSelection( const std::string &name );
void notifySelectionWatchers();
void registerSelectionWatcher( IEditorSelectionWatcher *watcher );
void unregisterSelectionWatcher( IEditorSelectionWatcher *watcher );
private: private:
CWidgetManager(); CWidgetManager();
@ -510,6 +516,8 @@ namespace NLGUI
NLMISC::CRefPtr<CCtrlBase> _CapturePointerLeft; NLMISC::CRefPtr<CCtrlBase> _CapturePointerLeft;
NLMISC::CRefPtr<CCtrlBase> _CapturePointerRight; NLMISC::CRefPtr<CCtrlBase> _CapturePointerRight;
NLMISC::CRefPtr< CViewBase > _CapturedView;
// What is under pointer // What is under pointer
std::vector< CViewBase* > _ViewsUnderPointer; std::vector< CViewBase* > _ViewsUnderPointer;
std::vector< CCtrlBase* > _CtrlsUnderPointer; std::vector< CCtrlBase* > _CtrlsUnderPointer;
@ -561,6 +569,8 @@ namespace NLGUI
std::vector< INewScreenSizeHandler* > newScreenSizeHandlers; std::vector< INewScreenSizeHandler* > newScreenSizeHandlers;
std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers; std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers;
std::vector< IEditorSelectionWatcher* > selectionWatchers;
std::string currentEditorSelection; std::string currentEditorSelection;
}; };

View file

@ -37,6 +37,9 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
bool CCtrlBase::handleEvent(const NLGUI::CEventDescriptor &event) bool CCtrlBase::handleEvent(const NLGUI::CEventDescriptor &event)
{ {
if( CViewBase::handleEvent( event ) )
return true;
if (event.getType() == NLGUI::CEventDescriptor::system) if (event.getType() == NLGUI::CEventDescriptor::system)
{ {
NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event; NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event;

View file

@ -668,12 +668,6 @@ namespace NLGUI
if (CWidgetManager::getInstance()->getCapturePointerLeft() != this) if (CWidgetManager::getInstance()->getCapturePointerLeft() != this)
return false; return false;
if( editorMode )
{
CWidgetManager::getInstance()->setCurrentEditorSelection( getId() );
return true;
}
if (_LeftDblClickHandled) // no effect on mouse up after double click has been handled if (_LeftDblClickHandled) // no effect on mouse up after double click has been handled
{ {
_LeftDblClickHandled = false; _LeftDblClickHandled = false;

View file

@ -357,7 +357,7 @@ namespace NLGUI
if ( ( _Over && !editorMode ) || editorSelected ) if ( ( _Over && !editorMode ) )
{ {
if( !editorMode && (lastOver == false) && (_AHOnOver != NULL)) if( !editorMode && (lastOver == false) && (_AHOnOver != NULL))

View file

@ -60,6 +60,17 @@ namespace NLGUI
_ForceTextOver = false; _ForceTextOver = false;
} }
CCtrlTextButton::~CCtrlTextButton()
{
if( _ViewText != NULL )
{
if( _Parent != NULL )
_Parent->delView( _ViewText, true );
delete _ViewText;
_ViewText = NULL;
}
}
std::string CCtrlTextButton::getProperty( const std::string &name ) const std::string CCtrlTextButton::getProperty( const std::string &name ) const
{ {
std::string prop; std::string prop;
@ -111,7 +122,10 @@ namespace NLGUI
else else
if( name == "hardtext" ) if( name == "hardtext" )
{ {
return _ViewText->getText().toString(); if( _ViewText != NULL )
return _ViewText->getText().toString();
else
return std::string( "" );
} }
else else
if( name == "text_y" ) if( name == "text_y" )
@ -126,7 +140,10 @@ namespace NLGUI
else else
if( name == "text_underlined" ) if( name == "text_underlined" )
{ {
return toString( _ViewText->getUnderlined() ); if( _ViewText != NULL )
return toString( _ViewText->getUnderlined() );
else
return std::string( "" );
} }
else else
if( name == "text_posref" ) if( name == "text_posref" )
@ -267,7 +284,8 @@ namespace NLGUI
else else
if( name == "hardtext" ) if( name == "hardtext" )
{ {
_ViewText->setText( value ); if( _ViewText != NULL )
_ViewText->setText( value );
return; return;
} }
else else
@ -290,8 +308,10 @@ namespace NLGUI
if( name == "text_underlined" ) if( name == "text_underlined" )
{ {
bool b; bool b;
if( fromString( value, b ) ) if( _ViewText != NULL )
_ViewText->setUnderlined( b ); if( fromString( value, b ) )
_ViewText->setUnderlined( b );
return; return;
} }
else else
@ -764,8 +784,7 @@ namespace NLGUI
CCtrlBase *capturePointerLeft = CWidgetManager::getInstance()->getCapturePointerLeft(); CCtrlBase *capturePointerLeft = CWidgetManager::getInstance()->getCapturePointerLeft();
// *** Draw Over // *** Draw Over
if( editorSelected || if( ( !editorMode && _Over && (_OverWhenPushed || !(_Pushed || capturePointerLeft == this ) ) )
( !editorMode && _Over && (_OverWhenPushed || !(_Pushed || capturePointerLeft == this ) ) )
) )
{ {
if( !editorMode && (lastOver == false) && (_AHOnOver != NULL) ) if( !editorMode && (lastOver == false) && (_AHOnOver != NULL) )
@ -801,32 +820,35 @@ namespace NLGUI
} }
} }
// Setup ViewText color // Setup ViewText color
if ( pTxId==_TextureIdNormal || editorMode ) if( _ViewText != NULL )
{ {
if(_TextHeaderColor) viewTextColor.A= _TextColorNormal.A; if ( pTxId==_TextureIdNormal || editorMode )
else viewTextColor= _TextColorNormal; {
_ViewText->setColor(viewTextColor); if(_TextHeaderColor) viewTextColor.A= _TextColorNormal.A;
_ViewText->setShadowColor(_TextShadowColorNormal); else viewTextColor= _TextColorNormal;
_ViewText->setModulateGlobalColor(_TextModulateGlobalColorNormal); _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);
} }
@ -958,6 +980,19 @@ namespace NLGUI
} }
// *************************************************************************** // ***************************************************************************
void CCtrlTextButton::onRemoved()
{
if( _ViewText != NULL )
{
if( _Parent != NULL )
_Parent->delView( _ViewText, true );
}
}
void CCtrlTextButton::onWidgetDeleted( CInterfaceElement *e )
{
if( e == _ViewText )
_ViewText = NULL;
}
} }

View file

@ -32,6 +32,7 @@ using namespace NLMISC;
namespace NLGUI namespace NLGUI
{ {
bool CInterfaceElement::editorMode = false; bool CInterfaceElement::editorMode = false;
std::vector< CInterfaceElement::IDeletionWatcher* > CInterfaceElement::deletionWatchers;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
CInterfaceElement::~CInterfaceElement() CInterfaceElement::~CInterfaceElement()
@ -44,6 +45,13 @@ namespace NLGUI
} }
delete _Links; delete _Links;
} }
if( editorMode )
{
notifyDeletionWatchers();
if( _Parent != NULL )
_Parent->onWidgetDeleted( this );
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -1300,6 +1308,11 @@ namespace NLGUI
} }
void CInterfaceElement::drawHighlight()
{
CViewRenderer::getInstance()->drawWiredQuad( _XReal, _YReal, _WReal, _HReal );
}
// *************************************************************************** // ***************************************************************************
void CInterfaceElement::invalidateContent() void CInterfaceElement::invalidateContent()
{ {
@ -1546,6 +1559,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; CStringMapper* CStringShared::_UIStringMapper = NULL;

View file

@ -141,12 +141,12 @@ namespace NLGUI
// initStart = ryzomGetLocalTime (); // initStart = ryzomGetLocalTime ();
clearGroups(); clearGroups();
// nlinfo ("%d seconds for clearGroups '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); // 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 (); // initStart = ryzomGetLocalTime ();
clearControls(); clearControls();
// nlinfo ("%d seconds for clearControls '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); // 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); CWidgetManager::getInstance()->removeRefOnGroup (this);
#ifdef AJM_DEBUG_TRACK_INTERFACE_GROUPS #ifdef AJM_DEBUG_TRACK_INTERFACE_GROUPS
@ -1084,9 +1084,11 @@ namespace NLGUI
{ {
if (_Views[i] == child) if (_Views[i] == child)
{ {
if (!dontDelete) delete _Views[i]; CViewBase *v = _Views[i];
_Views.erase(_Views.begin()+i); _Views.erase(_Views.begin()+i);
delEltOrder (child); delEltOrder (child);
child->onRemoved();
if (!dontDelete) delete v;
return true; return true;
} }
} }
@ -1100,9 +1102,11 @@ namespace NLGUI
{ {
if (_Controls[i] == child) if (_Controls[i] == child)
{ {
if (!dontDelete) delete _Controls[i]; CCtrlBase *c = _Controls[i];
_Controls.erase(_Controls.begin()+i); _Controls.erase(_Controls.begin()+i);
delEltOrder (child); delEltOrder (child);
child->onRemoved();
if (!dontDelete) delete c;
return true; return true;
} }
} }
@ -1116,9 +1120,11 @@ namespace NLGUI
{ {
if (_ChildrenGroups[i] == child) if (_ChildrenGroups[i] == child)
{ {
if (!dontDelete) delete _ChildrenGroups[i]; CInterfaceGroup *g = _ChildrenGroups[i];
_ChildrenGroups.erase(_ChildrenGroups.begin()+i); _ChildrenGroups.erase(_ChildrenGroups.begin()+i);
delEltOrder (child); delEltOrder (child);
child->onRemoved();
if (!dontDelete) delete g;
return true; return true;
} }
} }
@ -2468,4 +2474,16 @@ namespace NLGUI
return "IMPLEMENT ME!"; return "IMPLEMENT ME!";
} }
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 );
}
} }

View file

@ -45,5 +45,23 @@ namespace NLGUI
CInterfaceElement::visit(visitor); 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;
}
} }

View file

@ -31,6 +31,7 @@
#include "nel/gui/proc.h" #include "nel/gui/proc.h"
#include "nel/gui/interface_expr.h" #include "nel/gui/interface_expr.h"
#include "nel/gui/reflect_register.h" #include "nel/gui/reflect_register.h"
#include "nel/gui/editor_selection_watcher.h"
#include "nel/misc/events.h" #include "nel/misc/events.h"
namespace NLGUI namespace NLGUI
@ -1031,6 +1032,7 @@ namespace NLGUI
_OldCaptureKeyboard = NULL; _OldCaptureKeyboard = NULL;
setCapturePointerLeft(NULL); setCapturePointerLeft(NULL);
setCapturePointerRight(NULL); setCapturePointerRight(NULL);
_CapturedView = NULL;
resetColorProps(); resetColorProps();
@ -2054,6 +2056,16 @@ namespace NLGUI
getPointer()->draw (); getPointer()->draw ();
} }
if( CInterfaceElement::getEditorMode() )
{
if( !currentEditorSelection.empty() )
{
CInterfaceElement *e = getElementFromId( currentEditorSelection );
if( e != NULL )
e->drawHighlight();
}
}
// flush layers // flush layers
CViewRenderer::getInstance()->flush(); CViewRenderer::getInstance()->flush();
@ -2086,6 +2098,12 @@ namespace NLGUI
getCapturePointerRight()->handleEvent( evnt ); getCapturePointerRight()->handleEvent( evnt );
setCapturePointerRight( NULL ); setCapturePointerRight( NULL );
} }
if( _CapturedView != NULL )
{
_CapturedView->handleEvent( evnt );
_CapturedView = NULL;
}
} }
} }
@ -2249,6 +2267,9 @@ namespace NLGUI
getCapturePointerLeft() != getCapturePointerRight() ) getCapturePointerLeft() != getCapturePointerRight() )
handled|= getCapturePointerRight()->handleEvent(evnt); handled|= getCapturePointerRight()->handleEvent(evnt);
if( _CapturedView != NULL )
_CapturedView->handleEvent( evnt );
CInterfaceGroup *ptr = getWindowUnder (eventDesc.getX(), eventDesc.getY()); CInterfaceGroup *ptr = getWindowUnder (eventDesc.getX(), eventDesc.getY());
setCurrentWindowUnder( ptr ); setCurrentWindowUnder( ptr );
@ -2326,6 +2347,8 @@ namespace NLGUI
} }
} }
bool captured = false;
// must not capture a new element if a sheet is currentlty being dragged. // 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 // This may happen when alt-tab has been used => the sheet is dragged but the left button is up
if (!CCtrlDraggable::getDraggedSheet()) if (!CCtrlDraggable::getDraggedSheet())
@ -2343,9 +2366,25 @@ namespace NLGUI
{ {
nMaxDepth = d; nMaxDepth = d;
setCapturePointerLeft( ctrl ); 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() ); notifyElementCaptured( getCapturePointerLeft() );
if (clickedOutModalWindow && !clickedOutModalWindow->OnPostClickOut.empty()) if (clickedOutModalWindow && !clickedOutModalWindow->OnPostClickOut.empty())
{ {
@ -2353,13 +2392,16 @@ namespace NLGUI
} }
} }
//if found //if found
if ( getCapturePointerLeft() != NULL) if ( captured )
{ {
// consider clicking on a control implies handling of the event. // consider clicking on a control implies handling of the event.
handled= true; handled= true;
// handle the capture // handle the capture
getCapturePointerLeft()->handleEvent(evnt); if( getCapturePointerLeft() != NULL )
getCapturePointerLeft()->handleEvent(evnt);
else
_CapturedView->handleEvent( evnt );
} }
} }
@ -2588,6 +2630,8 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CWidgetManager::setCapturePointerLeft(CCtrlBase *c) void CWidgetManager::setCapturePointerLeft(CCtrlBase *c)
{ {
_CapturedView = NULL;
// additionally, abort any dragging // additionally, abort any dragging
if( CCtrlDraggable::getDraggedSheet() != NULL ) if( CCtrlDraggable::getDraggedSheet() != NULL )
CCtrlDraggable::getDraggedSheet()->abortDragging(); CCtrlDraggable::getDraggedSheet()->abortDragging();
@ -3147,8 +3191,47 @@ namespace NLGUI
prev->setEditorSelected( false ); prev->setEditorSelected( false );
} }
e->setEditorSelected( true ); e->setEditorSelected( true );
currentEditorSelection = name;
} }
else
if( !name.empty() )
return;
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 );
} }

View file

@ -60,6 +60,8 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR
nelgui_widget.h nelgui_widget.h
new_property_widget.h new_property_widget.h
new_widget_widget.h new_widget_widget.h
editor_selection_watcher.h
editor_message_processor.h
) )
SET(OVQT_PLUGIN_GUI_EDITOR_UIS SET(OVQT_PLUGIN_GUI_EDITOR_UIS

View file

@ -0,0 +1,58 @@
// Object Viewer Qt GUI Editor plugin <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/>.
#include <QMessageBox>
#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->getParent();
if( p == NULL )
return;
CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( p );
if( g == NULL )
return;
if( g->delElement( e ) )
{
CWidgetManager::getInstance()->setCurrentEditorSelection( "" );
}
}
}

View file

@ -0,0 +1,33 @@
// Object Viewer Qt GUI Editor plugin <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/>.
#include <QObject>
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();
};
}

View file

@ -0,0 +1,26 @@
// 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/>.
#include "editor_selection_watcher.h"
namespace GUIEditor
{
void CEditorSelectionWatcher::selectionChanged( std::string &newSelection )
{
Q_EMIT sgnSelectionChanged( newSelection );
}
}

View file

@ -0,0 +1,36 @@
// 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/>.
#include "nel/gui/editor_selection_watcher.h"
#include <QObject>
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 );
};
}

View file

@ -41,6 +41,8 @@
#include "project_file_serializer.h" #include "project_file_serializer.h"
#include "project_window.h" #include "project_window.h"
#include "nelgui_widget.h" #include "nelgui_widget.h"
#include "editor_selection_watcher.h"
#include "editor_message_processor.h"
namespace GUIEditor namespace GUIEditor
{ {
@ -53,6 +55,7 @@ namespace GUIEditor
QMainWindow(parent) QMainWindow(parent)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
messageProcessor = new CEditorMessageProcessor;
m_undoStack = new QUndoStack(this); m_undoStack = new QUndoStack(this);
widgetProps = new CWidgetProperties; widgetProps = new CWidgetProperties;
linkList = new LinkList; linkList = new LinkList;
@ -91,17 +94,16 @@ namespace GUIEditor
viewPort->init(); viewPort->init();
connect( viewPort, SIGNAL( guiLoadComplete() ), hierarchyView, SLOT( onGUILoaded() ) ); connect( viewPort, SIGNAL( guiLoadComplete() ), this, 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& ) ) );
} }
GUIEditorWindow::~GUIEditorWindow() GUIEditorWindow::~GUIEditorWindow()
{ {
writeSettings(); writeSettings();
delete messageProcessor;
messageProcessor = NULL;
delete widgetProps; delete widgetProps;
widgetProps = NULL; widgetProps = NULL;
@ -262,6 +264,11 @@ namespace GUIEditor
if( reply != QMessageBox::Yes ) if( reply != QMessageBox::Yes )
return false; 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(); projectFiles.clearAll();
projectWindow->clear(); projectWindow->clear();
hierarchyView->clearHierarchy(); hierarchyView->clearHierarchy();
@ -291,6 +298,16 @@ namespace GUIEditor
setCursor( Qt::ArrowCursor ); 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() void GUIEditorWindow::createMenus()
{ {
@ -299,6 +316,7 @@ namespace GUIEditor
QAction *saveAction = mm->action( Core::Constants::SAVE ); QAction *saveAction = mm->action( Core::Constants::SAVE );
QAction *saveAsAction = mm->action( Core::Constants::SAVE_AS ); QAction *saveAsAction = mm->action( Core::Constants::SAVE_AS );
QAction *closeAction = mm->action( Core::Constants::CLOSE ); QAction *closeAction = mm->action( Core::Constants::CLOSE );
QAction *delAction = mm->action( Core::Constants::DEL );
//if( newAction != NULL ) //if( newAction != NULL )
// newAction->setEnabled( true ); // newAction->setEnabled( true );
@ -308,6 +326,11 @@ namespace GUIEditor
saveAsAction->setEnabled( true ); saveAsAction->setEnabled( true );
if( closeAction != NULL ) if( closeAction != NULL )
closeAction->setEnabled( true ); 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 ); QMenu *menu = mm->menu( Core::Constants::M_TOOLS );
if( menu != NULL ) if( menu != NULL )

View file

@ -36,6 +36,7 @@ namespace GUIEditor
class ProjectWindow; class ProjectWindow;
class NelGUIWidget; class NelGUIWidget;
class CWidgetInfoTree; class CWidgetInfoTree;
class CEditorMessageProcessor;
class GUIEditorWindow: public QMainWindow class GUIEditorWindow: public QMainWindow
{ {
@ -58,6 +59,7 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void onProjectFilesChanged(); void onProjectFilesChanged();
void onGUILoaded();
private: private:
void createMenus(); void createMenus();
@ -76,8 +78,8 @@ private:
ProcList *procList; ProcList *procList;
ProjectWindow *projectWindow; ProjectWindow *projectWindow;
NelGUIWidget *viewPort; NelGUIWidget *viewPort;
CWidgetInfoTree *widgetInfoTree; CWidgetInfoTree *widgetInfoTree;
CEditorMessageProcessor *messageProcessor;
CPropBrowserCtrl browserCtrl; CPropBrowserCtrl browserCtrl;
QString currentProject; QString currentProject;

View file

@ -27,6 +27,7 @@
#include <set> #include <set>
#include <string> #include <string>
#include <QTimerEvent> #include <QTimerEvent>
#include "editor_selection_watcher.h"
namespace GUIEditor namespace GUIEditor
{ {
@ -37,6 +38,7 @@ namespace GUIEditor
{ {
timerID = 0; timerID = 0;
guiLoaded = false; guiLoaded = false;
watcher = NULL;
} }
NelGUIWidget::~NelGUIWidget() NelGUIWidget::~NelGUIWidget()
@ -70,6 +72,8 @@ namespace GUIEditor
NLGUI::CViewRenderer::getInstance()->init(); NLGUI::CViewRenderer::getInstance()->init();
CWidgetManager::getInstance()->getParser()->setEditorMode( true ); CWidgetManager::getInstance()->getParser()->setEditorMode( true );
watcher = new CEditorSelectionWatcher();
} }
bool NelGUIWidget::parse( SProjectFiles &files ) bool NelGUIWidget::parse( SProjectFiles &files )
@ -106,6 +110,8 @@ namespace GUIEditor
guiLoaded = true; guiLoaded = true;
Q_EMIT guiLoadComplete(); Q_EMIT guiLoadComplete();
CWidgetManager::getInstance()->registerSelectionWatcher( watcher );
return true; return true;
} }
@ -115,6 +121,7 @@ namespace GUIEditor
if( timerID != 0 ) if( timerID != 0 )
killTimer( timerID ); killTimer( timerID );
timerID = 0; timerID = 0;
CWidgetManager::getInstance()->unregisterSelectionWatcher( watcher );
CWidgetManager::getInstance()->reset(); CWidgetManager::getInstance()->reset();
CWidgetManager::getInstance()->getParser()->removeAll(); CWidgetManager::getInstance()->getParser()->removeAll();
CViewRenderer::getInstance()->reset(); CViewRenderer::getInstance()->reset();

View file

@ -23,6 +23,8 @@
namespace GUIEditor namespace GUIEditor
{ {
class CEditorSelectionWatcher;
/// Qt viewport for the Nel GUI library /// Qt viewport for the Nel GUI library
class NelGUIWidget : public Nel3DWidget class NelGUIWidget : public Nel3DWidget
{ {
@ -35,6 +37,7 @@ namespace GUIEditor
bool parse( SProjectFiles &files ); bool parse( SProjectFiles &files );
void draw(); void draw();
void reset(); void reset();
CEditorSelectionWatcher* getWatcher(){ return watcher; }
Q_SIGNALS: Q_SIGNALS:
void guiLoadComplete(); void guiLoadComplete();
@ -49,6 +52,7 @@ Q_SIGNALS:
private: private:
int timerID; int timerID;
bool guiLoaded; bool guiLoaded;
CEditorSelectionWatcher *watcher;
}; };
} }

View file

@ -78,7 +78,12 @@ namespace GUIEditor
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id ); CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id );
if( e == NULL ) if( e == NULL )
{
connect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ),
this, SLOT( onPropertyChanged( QtProperty* ) ) );
return; return;
}
currentElement = id; currentElement = id;

View file

@ -56,6 +56,26 @@ namespace
name = s.toUtf8().constData(); name = s.toUtf8().constData();
return name; 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 namespace GUIEditor
@ -66,6 +86,7 @@ namespace GUIEditor
setupUi( this ); setupUi( this );
connect( widgetHT, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), connect( widgetHT, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ),
this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) ); this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) );
deletionWatcher.setWidgetHierarchy( this );
} }
WidgetHierarchy::~WidgetHierarchy() WidgetHierarchy::~WidgetHierarchy()
@ -74,12 +95,15 @@ namespace GUIEditor
void WidgetHierarchy::clearHierarchy() void WidgetHierarchy::clearHierarchy()
{ {
CInterfaceElement::unregisterDeletionWatcher( &deletionWatcher );
widgetHT->clear(); widgetHT->clear();
widgetHierarchyMap.clear();
} }
void WidgetHierarchy::buildHierarchy( std::string &masterGroup ) void WidgetHierarchy::buildHierarchy( std::string &masterGroup )
{ {
clearHierarchy(); clearHierarchy();
CInterfaceElement::registerDeletionWatcher( &deletionWatcher );
CInterfaceGroup *mg = CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup ); CInterfaceGroup *mg = CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup );
if( mg != NULL ) if( mg != NULL )
@ -87,6 +111,7 @@ namespace GUIEditor
QTreeWidgetItem *item = new QTreeWidgetItem( NULL ); QTreeWidgetItem *item = new QTreeWidgetItem( NULL );
item->setText( 0, "ui" ); item->setText( 0, "ui" );
widgetHT->addTopLevelItem( item ); widgetHT->addTopLevelItem( item );
widgetHierarchyMap[ "ui" ] = item;
buildHierarchy( item, mg ); buildHierarchy( item, mg );
} }
@ -96,7 +121,9 @@ namespace GUIEditor
{ {
// First add ourselves // First add ourselves
QTreeWidgetItem *item = new QTreeWidgetItem( parent ); QTreeWidgetItem *item = new QTreeWidgetItem( parent );
item->setText( 0, makeNodeName( group->getId() ).c_str() ); item->setText( 0, makeNodeName( group->getId() ).c_str() );
widgetHierarchyMap[ group->getId() ] = item;
// Then add recursively our subgroups // Then add recursively our subgroups
const std::vector< CInterfaceGroup* > &groups = group->getGroups(); const std::vector< CInterfaceGroup* > &groups = group->getGroups();
@ -113,6 +140,7 @@ namespace GUIEditor
{ {
QTreeWidgetItem *subItem = new QTreeWidgetItem( item ); QTreeWidgetItem *subItem = new QTreeWidgetItem( item );
subItem->setText( 0, makeNodeName( (*citr)->getId() ).c_str() ); subItem->setText( 0, makeNodeName( (*citr)->getId() ).c_str() );
widgetHierarchyMap[ (*citr)->getId() ] = subItem;
} }
// Add our views // Add our views
@ -122,14 +150,81 @@ namespace GUIEditor
{ {
QTreeWidgetItem *subItem = new QTreeWidgetItem( item ); QTreeWidgetItem *subItem = new QTreeWidgetItem( item );
subItem->setText( 0, makeNodeName( (*vitr)->getId() ).c_str() ); subItem->setText( 0, makeNodeName( (*vitr)->getId() ).c_str() );
widgetHierarchyMap[ (*vitr)->getId() ] = subItem;
} }
} }
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() void WidgetHierarchy::onGUILoaded()
{ {
if( masterGroup.empty() ) if( masterGroup.empty() )
return; return;
buildHierarchy( masterGroup ); buildHierarchy( masterGroup );
currentSelection.clear();
}
void WidgetHierarchy::onSelectionChanged( std::string &newSelection )
{
if( newSelection == currentSelection )
return;
if( newSelection.empty() )
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 )
{
currItem->setExpanded( true );
currItem = currItem->parent();
}
// select the current item
item->setSelected( true );
widgetHT->setCurrentItem( item );
currentSelection = newSelection;
} }
void WidgetHierarchy::onItemDblClicked( QTreeWidgetItem *item ) void WidgetHierarchy::onItemDblClicked( QTreeWidgetItem *item )
@ -138,9 +233,7 @@ namespace GUIEditor
return; return;
std::string n = item->text( 0 ).toUtf8().constData(); std::string n = item->text( 0 ).toUtf8().constData();
std::string selection = makeFullName( item, n ); currentSelection = makeFullName( item, n );
CWidgetManager::getInstance()->setCurrentEditorSelection( selection ); CWidgetManager::getInstance()->setCurrentEditorSelection( currentSelection );
Q_EMIT selectionChanged( selection );
} }
} }

View file

@ -18,6 +18,8 @@
#define WIDGET_HA_H #define WIDGET_HA_H
#include "ui_widget_hierarchy.h" #include "ui_widget_hierarchy.h"
#include <string>
#include <map>
namespace NLGUI namespace NLGUI
{ {
@ -40,11 +42,14 @@ namespace GUIEditor
void clearHierarchy(); void clearHierarchy();
void buildHierarchy( std::string &masterGroup ); void buildHierarchy( std::string &masterGroup );
void onWidgetDeleted( const std::string &id );
private: private:
void buildHierarchy( QTreeWidgetItem *parent, NLGUI::CInterfaceGroup *group ); void buildHierarchy( QTreeWidgetItem *parent, NLGUI::CInterfaceGroup *group );
public Q_SLOTS: public Q_SLOTS:
void onGUILoaded(); void onGUILoaded();
void onSelectionChanged( std::string &newSelection );
private Q_SLOTS: private Q_SLOTS:
void onItemDblClicked( QTreeWidgetItem *item ); void onItemDblClicked( QTreeWidgetItem *item );
@ -52,9 +57,7 @@ namespace GUIEditor
private: private:
std::string currentSelection; std::string currentSelection;
std::string masterGroup; std::string masterGroup;
std::map< std::string, QTreeWidgetItem* > widgetHierarchyMap;
Q_SIGNALS:
void selectionChanged( std::string &id );
}; };
} }