mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-23 15:26:16 +00:00
CHANGED: #1471 The property browser widget can now actually change properties.
This commit is contained in:
parent
607a3f188a
commit
d562a50ceb
4 changed files with 72 additions and 1 deletions
|
@ -237,7 +237,33 @@ inline bool fromString(const std::string &str, uint64 &val) { bool ret = sscanf(
|
|||
inline bool fromString(const std::string &str, sint64 &val) { bool ret = sscanf(str.c_str(), "%"NL_I64"d", &val) == 1; if (!ret) val = 0; return ret; }
|
||||
inline bool fromString(const std::string &str, float &val) { bool ret = sscanf(str.c_str(), "%f", &val) == 1; if (!ret) val = 0.0f; return ret; }
|
||||
inline bool fromString(const std::string &str, double &val) { bool ret = sscanf(str.c_str(), "%lf", &val) == 1; if (!ret) val = 0.0; return ret; }
|
||||
inline bool fromString(const std::string &str, bool &val) { val = (str.length() == 1) && str[0] != '0'; return (str.length() == 1) && (str[0] == '0' || str[0] == '1'); }
|
||||
|
||||
inline bool fromString(const std::string &str, bool &val)
|
||||
{
|
||||
if( str.length() == 1 )
|
||||
{
|
||||
if( str[ 0 ] == '1' )
|
||||
val = true;
|
||||
else
|
||||
if( str[ 0 ] == '0' )
|
||||
val = false;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( str == "true" )
|
||||
val = true;
|
||||
else
|
||||
if( str == "false" )
|
||||
val = false;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool fromString(const std::string &str, std::string &val) { val = str; return true; }
|
||||
|
||||
// stl vectors of bool use bit reference and not real bools, so define the operator for bit reference
|
||||
|
|
|
@ -166,6 +166,7 @@ namespace NLGUI
|
|||
if( name == "id" )
|
||||
{
|
||||
setIdRecurse( stripId( value ) );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "active" )
|
||||
|
@ -173,6 +174,7 @@ namespace NLGUI
|
|||
bool b;
|
||||
if( fromString( value, b ) )
|
||||
setActive( b );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "x" )
|
||||
|
@ -180,6 +182,7 @@ namespace NLGUI
|
|||
sint32 x;
|
||||
if( fromString( value, x ) )
|
||||
setX( x );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "y" )
|
||||
|
@ -187,6 +190,7 @@ namespace NLGUI
|
|||
sint32 y;
|
||||
if( fromString( value, y ) )
|
||||
setY( y );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "w" )
|
||||
|
@ -194,6 +198,7 @@ namespace NLGUI
|
|||
sint32 w;
|
||||
if( fromString( value, w ) )
|
||||
setW( w );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "h" )
|
||||
|
@ -201,25 +206,30 @@ namespace NLGUI
|
|||
sint32 h;
|
||||
if( fromString( value, h ) )
|
||||
setH( h );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "posref" )
|
||||
{
|
||||
convertHotSpotCouple( value.c_str(), _ParentPosRef, _PosRef );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "sizeref" )
|
||||
{
|
||||
parseSizeRef( value.c_str() );
|
||||
return;
|
||||
}
|
||||
if( name == "posparent" )
|
||||
{
|
||||
setPosParent( value );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "sizeparent" )
|
||||
{
|
||||
setSizeParent( value );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "global_color" )
|
||||
|
@ -227,6 +237,7 @@ namespace NLGUI
|
|||
bool b;
|
||||
if( fromString( value, b ) )
|
||||
setModulateGlobalColor( b );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "render_layer" )
|
||||
|
@ -234,6 +245,7 @@ namespace NLGUI
|
|||
sint8 l;
|
||||
if( fromString( value, l ) )
|
||||
setRenderLayer( l );
|
||||
return;
|
||||
}
|
||||
else
|
||||
if( name == "avoid_resize_parent" )
|
||||
|
@ -241,6 +253,7 @@ namespace NLGUI
|
|||
bool b;
|
||||
if( fromString( value, b ) )
|
||||
setAvoidResizeParent( b );
|
||||
return;
|
||||
}
|
||||
else
|
||||
nlwarning( "Tried to set invalid property '%s' for widget '%s'", name.c_str(), _Id.c_str() );
|
||||
|
|
|
@ -58,12 +58,17 @@ namespace GUIEditor
|
|||
{
|
||||
if( browser == NULL )
|
||||
return;
|
||||
disconnect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ),
|
||||
this, SLOT( onPropertyChanged( QtProperty* ) ) );
|
||||
|
||||
browser->clear();
|
||||
|
||||
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id );
|
||||
if( e == NULL )
|
||||
return;
|
||||
|
||||
currentElement = id;
|
||||
|
||||
std::string n;
|
||||
n = typeid( *e ).name();
|
||||
std::string::size_type i = n.find_last_of( ':' );
|
||||
|
@ -71,6 +76,27 @@ namespace GUIEditor
|
|||
n = n.substr( i + 1, n.size() - 1 );
|
||||
|
||||
setupProperties( n, e );
|
||||
connect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ),
|
||||
this, SLOT( onPropertyChanged( QtProperty* ) ) );
|
||||
}
|
||||
|
||||
void CPropBrowserCtrl::onPropertyChanged( QtProperty *prop )
|
||||
{
|
||||
QString propName = prop->propertyName();
|
||||
QString propValue = prop->valueText();
|
||||
|
||||
// for some reason booleans cannot be extracted from a QtProperty :(
|
||||
if( propValue.isEmpty() )
|
||||
{
|
||||
QtVariantProperty *p = propertyMgr->variantProperty( prop );
|
||||
if( p != NULL )
|
||||
propValue = p->value().toString();
|
||||
}
|
||||
|
||||
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( currentElement );
|
||||
if( e == NULL )
|
||||
return;
|
||||
e->setProperty( propName.toStdString(), propValue.toStdString() );
|
||||
}
|
||||
|
||||
void CPropBrowserCtrl::setupProperties( const std::string &type, const CInterfaceElement *element )
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
class QtTreePropertyBrowser;
|
||||
class QtVariantPropertyManager;
|
||||
class QtProperty;
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
|
@ -49,6 +50,9 @@ namespace GUIEditor
|
|||
public Q_SLOTS:
|
||||
void onSelectionChanged( std::string &id );
|
||||
|
||||
private Q_SLOTS:
|
||||
void onPropertyChanged( QtProperty *prop );
|
||||
|
||||
private:
|
||||
void setupProperties( const std::string &type, const NLGUI::CInterfaceElement *element );
|
||||
void setupProperty( const SPropEntry &prop, const NLGUI::CInterfaceElement *element );
|
||||
|
@ -56,6 +60,8 @@ namespace GUIEditor
|
|||
QtTreePropertyBrowser *browser;
|
||||
QtVariantPropertyManager *propertyMgr;
|
||||
std::map< std::string, SWidgetInfo > widgetInfo;
|
||||
|
||||
std::string currentElement;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue