Posref can now be set as an enum, instead of a string in the property editor.

--HG--
branch : gsoc2014-dfighter
This commit is contained in:
dfighter1985 2014-06-21 18:25:14 +02:00
parent 1afe2d4a17
commit 250cd6efc1
3 changed files with 145 additions and 7 deletions

View file

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

View file

@ -26,6 +26,83 @@
#include "widget_info_tree.h"
#include <QList>
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() );

View file

@ -36,12 +36,17 @@
<name>h</name>
<type>int</type>
<default>0</default>
</property>
</property>
<property>
<name>posref</name>
<type>string</type>
<default>BL BL</default>
</property>
<type>posref</type>
<default>BL</default>
</property>
<property>
<name>parentposref</name>
<type>posref</type>
<default>BL</default>
</property>
<property>
<name>sizeref</name>
<type>string</type>