From 250cd6efc159c0d8f79c7ffbfc96d1036b2b87c8 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 21 Jun 2014 18:25:14 +0200 Subject: [PATCH] Posref can now be set as an enum, instead of a string in the property editor. --HG-- branch : gsoc2014-dfighter --- code/nel/src/gui/interface_element.cpp | 16 ++- .../gui_editor/property_browser_ctrl.cpp | 123 ++++++++++++++++++ .../gui_editor/widgets/InterfaceElement.xml | 13 +- 3 files changed, 145 insertions(+), 7 deletions(-) diff --git a/code/nel/src/gui/interface_element.cpp b/code/nel/src/gui/interface_element.cpp index 15f9cf812..0225d2797 100644 --- a/code/nel/src/gui/interface_element.cpp +++ b/code/nel/src/gui/interface_element.cpp @@ -130,12 +130,17 @@ namespace NLGUI if( name == "posref" ) { std::string posref; - posref = HotSpotToString( getParentPosRef() ); - posref += " "; posref += HotSpotToString( getPosRef() ); return posref; } else + if( name == "parentposref" ) + { + std::string parentPosRef; + parentPosRef = HotSpotToString( getParentPosRef() ); + return parentPosRef; + } + else if( name == "sizeref" ) { return getSizeRefAsString( _SizeRef, _SizeDivW, _SizeDivH ); @@ -221,10 +226,15 @@ namespace NLGUI else if( name == "posref" ) { - convertHotSpotCouple( value.c_str(), _ParentPosRef, _PosRef ); + convertHotSpot( value.c_str() ); return; } else + if( name == "parentposref" ) + { + convertHotSpot( value.c_str() ); + } + else if( name == "sizeref" ) { parseSizeRef( value.c_str() ); diff --git a/code/studio/src/plugins/gui_editor/property_browser_ctrl.cpp b/code/studio/src/plugins/gui_editor/property_browser_ctrl.cpp index 6408703f4..d5feba8f7 100644 --- a/code/studio/src/plugins/gui_editor/property_browser_ctrl.cpp +++ b/code/studio/src/plugins/gui_editor/property_browser_ctrl.cpp @@ -26,6 +26,83 @@ #include "widget_info_tree.h" #include +namespace +{ + + class NelPosRef + { + public: + + enum NELPosRef + { + POSREF_BL = 0, + POSREF_BM = 1, + POSREF_BR = 2, + POSREF_ML = 3, + POSREF_MM = 4, + POSREF_MR = 5, + POSREF_TL = 6, + POSREF_TM = 7, + POSREF_TR = 8 + }; + + static int fromString( const std::string &s ) + { + int r = -1; + + if( s == "BL" ) + r = POSREF_BL; + else + if( s == "BM" ) + r = POSREF_BM; + else + if( s == "BR" ) + r = POSREF_BR; + else + if( s == "ML" ) + r = POSREF_ML; + else + if( s == "MM" ) + r = POSREF_MM; + else + if( s == "MR" ) + r = POSREF_MR; + else + if( s == "TL" ) + r = POSREF_TL; + else + if( s == "TM" ) + r = POSREF_TM; + else + if( s == "TR" ) + r = POSREF_TR; + + return r; + } + + static std::string toString( int value ) + { + std::string v; + + switch( value ) + { + case POSREF_BL: v = "BL"; break; + case POSREF_BM: v = "BM"; break; + case POSREF_BR: v = "BR"; break; + case POSREF_ML: v = "ML"; break; + case POSREF_MM: v = "MM"; break; + case POSREF_MR: v = "MR"; break; + case POSREF_TL: v = "TL"; break; + case POSREF_TM: v = "TM"; break; + case POSREF_TR: v = "TR"; break; + } + + return v; + } + }; + +} + namespace GUIEditor { enum NELButtonTypes @@ -184,6 +261,19 @@ namespace GUIEditor case TEXT_JUSTIFIED: v = "justified"; break; } + e->setProperty( propName.toUtf8().constData(), v ); + } + else + if( ( propName == "posref" ) || ( propName == "parentposref" ) ) + { + CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( currentElement ); + if( e == NULL ) + return; + + std::string v = NelPosRef::toString( value ); + if( v.empty() ) + return; + e->setProperty( propName.toUtf8().constData(), v ); } } @@ -299,6 +389,39 @@ namespace GUIEditor return; } else + if( prop.propType == "posref" ) + { + std::string j = element->getProperty( prop.propName ); + if( j.empty() ) + return; + + int e = -1; + e = NelPosRef::fromString( j ); + if( e == -1 ) + return; + + QtProperty *pp = enumMgr->addProperty( prop.propName.c_str() ); + if( pp == NULL ) + return; + + QStringList enums; + enums.push_back( "BL" ); + enums.push_back( "BM" ); + enums.push_back( "BR" ); + enums.push_back( "ML" ); + enums.push_back( "MM" ); + enums.push_back( "MR" ); + enums.push_back( "TL" ); + enums.push_back( "TM" ); + enums.push_back( "TR" ); + + enumMgr->setEnumNames( pp, enums ); + enumMgr->setValue( pp, e ); + browser->addProperty( pp ); + + return; + } + else if( prop.propType == "string" ) { p = propertyMgr->addProperty( QVariant::String, prop.propName.c_str() ); diff --git a/code/studio/src/plugins/gui_editor/widgets/InterfaceElement.xml b/code/studio/src/plugins/gui_editor/widgets/InterfaceElement.xml index 856480dc7..b16de9ed0 100644 --- a/code/studio/src/plugins/gui_editor/widgets/InterfaceElement.xml +++ b/code/studio/src/plugins/gui_editor/widgets/InterfaceElement.xml @@ -36,12 +36,17 @@ h int 0 - + posref - string - BL BL - + posref + BL + + + parentposref + posref + BL + sizeref string