Tooltip posrefs are now enums in the GUI Editor.

This commit is contained in:
dfighter1985 2014-06-29 01:44:06 +02:00
parent 9690392ec6
commit 5deea1a13b
5 changed files with 280 additions and 29 deletions

View file

@ -171,7 +171,9 @@ namespace NLGUI
THotSpot _ToolTipPosRefAlt : 6; THotSpot _ToolTipPosRefAlt : 6;
protected: protected:
void convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS); void convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS);
void convertTooltipHotSpot(const char *prop, THotSpot &HS );
static std::string TooltipHotSpotToString( THotSpot parent, THotSpot child ); static std::string TooltipHotSpotToString( THotSpot parent, THotSpot child );
static std::string TooltipHotSpotToString( THotSpot HS );
void mapAHString( const std::string &key, const std::string &value ); void mapAHString( const std::string &key, const std::string &value );
std::string getAHString( const std::string &key ) const; std::string getAHString( const std::string &key ) const;

View file

@ -220,28 +220,22 @@ namespace NLGUI
else else
if( name == "tooltip_posref" ) if( name == "tooltip_posref" )
{ {
std::string s; return TooltipHotSpotToString( _ToolTipPosRef );
if( ( _ToolTipParentPosRef == Hotspot_TTAuto ) && ( _ToolTipPosRef == Hotspot_TTAuto ) )
return "auto";
else{
s = CInterfaceElement::HotSpotToString( _ToolTipParentPosRef );
s += " ";
s += CInterfaceElement::HotSpotToString( _ToolTipPosRef );
return s;
} }
else
if( name == "tooltip_parent_posref" )
{
return TooltipHotSpotToString( _ToolTipParentPosRef );
} }
else else
if( name == "tooltip_posref_alt" ) if( name == "tooltip_posref_alt" )
{ {
std::string s; return TooltipHotSpotToString( _ToolTipPosRefAlt );
if( ( _ToolTipParentPosRefAlt == Hotspot_TTAuto ) && ( _ToolTipPosRefAlt == Hotspot_TTAuto ) )
return "auto";
else{
s = CInterfaceElement::HotSpotToString( _ToolTipParentPosRefAlt );
s += " ";
s += CInterfaceElement::HotSpotToString( _ToolTipPosRefAlt );
return s;
} }
else
if( name == "tooltip_parent_posref_alt" )
{
return TooltipHotSpotToString( _ToolTipParentPosRefAlt );
} }
else else
if( name == "instant_help" ) if( name == "instant_help" )
@ -293,21 +287,65 @@ namespace NLGUI
else else
if( name == "tooltip_posref" ) if( name == "tooltip_posref" )
{ {
THotSpot parentHS;
THotSpot HS; THotSpot HS;
convertTooltipHotSpot( value.c_str(), parentHS, HS ); convertTooltipHotSpot( value.c_str(), HS );
_ToolTipParentPosRef = parentHS;
_ToolTipPosRef = HS; _ToolTipPosRef = HS;
// When auto is set, both of them need to be auto
if( _ToolTipPosRef == Hotspot_TTAuto )
_ToolTipParentPosRef = Hotspot_TTAuto;
else
if( _ToolTipParentPosRef == Hotspot_TTAuto )
_ToolTipParentPosRef = _ToolTipPosRef;
return;
}
else
if( name == "tooltip_parent_posref" )
{
THotSpot HS;
convertTooltipHotSpot( value.c_str(), HS );
_ToolTipParentPosRef = HS;
// When auto is set, both of them need to be auto
if( _ToolTipParentPosRef == Hotspot_TTAuto )
_ToolTipPosRef = Hotspot_TTAuto;
else
if( _ToolTipPosRef == Hotspot_TTAuto )
_ToolTipPosRef = _ToolTipParentPosRef;
return; return;
} }
else else
if( name == "tooltip_posref_alt" ) if( name == "tooltip_posref_alt" )
{ {
THotSpot parentHS;
THotSpot HS; THotSpot HS;
convertTooltipHotSpot( value.c_str(), parentHS, HS ); convertTooltipHotSpot( value.c_str(), HS );
_ToolTipParentPosRefAlt = parentHS;
_ToolTipPosRefAlt = HS; _ToolTipPosRefAlt = HS;
// When auto is set, both of them need to be auto
if( _ToolTipPosRefAlt == Hotspot_TTAuto )
_ToolTipParentPosRefAlt = Hotspot_TTAuto;
else
if( _ToolTipParentPosRefAlt == Hotspot_TTAuto )
_ToolTipPosRefAlt = _ToolTipParentPosRefAlt;
return;
}
else
if( name == "tooltip_parent_posref_alt" )
{
THotSpot HS;
convertTooltipHotSpot( value.c_str(), HS );
_ToolTipParentPosRefAlt = HS;
// When auto is set, both of them need to be auto
if( _ToolTipParentPosRefAlt == Hotspot_TTAuto )
_ToolTipPosRefAlt = Hotspot_TTAuto;
else
if( _ToolTipPosRefAlt == Hotspot_TTAuto )
_ToolTipPosRefAlt = _ToolTipParentPosRefAlt;
return; return;
} }
else else
@ -374,6 +412,21 @@ namespace NLGUI
} }
} }
void CCtrlBase::convertTooltipHotSpot(const char *prop, THotSpot &HS )
{
if(prop)
{
const char *ptr = (const char*)prop;
if(stricmp(ptr, "auto")==0)
{
HS = Hotspot_TTAuto;
}
else if(strlen(ptr)==2)
{
HS = convertHotSpot(ptr);
}
}
}
std::string CCtrlBase::TooltipHotSpotToString( THotSpot parent, THotSpot child ) std::string CCtrlBase::TooltipHotSpotToString( THotSpot parent, THotSpot child )
{ {
@ -393,6 +446,20 @@ namespace NLGUI
return s; return s;
} }
std::string CCtrlBase::TooltipHotSpotToString( THotSpot HS )
{
std::string s;
if( HS == Hotspot_TTAuto )
{
s = "auto";
}
else
{
s = HotSpotToString( HS );
}
return s;
}
// *************************************************************************** // ***************************************************************************
bool CCtrlBase::emptyContextHelp() const bool CCtrlBase::emptyContextHelp() const
{ {

View file

@ -102,6 +102,83 @@ namespace
}; };
class NelPosRefTT
{
public:
enum NELPosRef
{
TTPOSREF_BL = 0,
TTPOSREF_BM = 1,
TTPOSREF_BR = 2,
TTPOSREF_ML = 3,
TTPOSREF_MM = 4,
TTPOSREF_MR = 5,
TTPOSREF_TL = 6,
TTPOSREF_TM = 7,
TTPOSREF_TR = 8,
TTPOSREF_AUTO = 9
};
static int fromString( const std::string &s )
{
int r = -1;
if( s == "BL" )
r = TTPOSREF_BL;
else
if( s == "BM" )
r = TTPOSREF_BM;
else
if( s == "BR" )
r = TTPOSREF_BR;
else
if( s == "ML" )
r = TTPOSREF_ML;
else
if( s == "MM" )
r = TTPOSREF_MM;
else
if( s == "MR" )
r = TTPOSREF_MR;
else
if( s == "TL" )
r = TTPOSREF_TL;
else
if( s == "TM" )
r = TTPOSREF_TM;
else
if( s == "TR" )
r = TTPOSREF_TR;
else
r = TTPOSREF_AUTO;
return r;
}
static std::string toString( int value )
{
std::string v;
switch( value )
{
case TTPOSREF_BL: v = "BL"; break;
case TTPOSREF_BM: v = "BM"; break;
case TTPOSREF_BR: v = "BR"; break;
case TTPOSREF_ML: v = "ML"; break;
case TTPOSREF_MM: v = "MM"; break;
case TTPOSREF_MR: v = "MR"; break;
case TTPOSREF_TL: v = "TL"; break;
case TTPOSREF_TM: v = "TM"; break;
case TTPOSREF_TR: v = "TR"; break;
case TTPOSREF_AUTO: v = "auto"; break;
}
return v;
}
};
class NelButtonType class NelButtonType
{ {
public: public:
@ -201,6 +278,12 @@ namespace GUIEditor
variantFactory = new QtVariantEditorFactory; variantFactory = new QtVariantEditorFactory;
enumFactory = new QtEnumEditorFactory; enumFactory = new QtEnumEditorFactory;
ttPairs[ "tooltip_posref" ] = "tooltip_parent_posref";
ttPairs[ "tooltip_parent_posref" ] = "tooltip_posref";
ttPairs[ "tooltip_posref_alt" ] = "tooltip_parent_posref_alt";
ttPairs[ "tooltip_parent_posref_alt" ] = "tooltip_posref_alt";
} }
CPropBrowserCtrl::~CPropBrowserCtrl() CPropBrowserCtrl::~CPropBrowserCtrl()
@ -363,6 +446,56 @@ namespace GUIEditor
e->setProperty( propName.toUtf8().constData(), v ); e->setProperty( propName.toUtf8().constData(), v );
} }
else
if( type == "posreftt" )
{
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( currentElement );
if( e == NULL )
return;
std::string v = NelPosRefTT::toString( value );
if( v.empty() )
return;
e->setProperty( propName.toUtf8().constData(), v );
// When auto is set as posref for a tooltip, it's pair MUST be auto as well
// When we set anything other than auto, the pair MUST not be auto either
// Only need to set the widget here, since the actual property is changed in the GUI library automatically
{
// Find the pair
std::map< std::string, std::string >::const_iterator ttItr =
ttPairs.find( n );
// Found!
if( ttItr != ttPairs.end() )
{
// Find the QtProperty that belongs to the pair
std::map< std::string, QtProperty* >::const_iterator pItr =
ttPosRefProps.find( ttItr->second );
// Found!
if( pItr != ttPosRefProps.end() )
{
disablePropertyWatchers();
if( value == NelPosRefTT::TTPOSREF_AUTO )
enumMgr->setValue( pItr->second, NelPosRefTT::TTPOSREF_AUTO );
else
{
int v = NelPosRefTT::fromString( pItr->second->valueText().toUtf8().constData() );
if( v == NelPosRefTT::TTPOSREF_AUTO )
{
enumMgr->setValue( pItr->second, value );
}
}
enablePropertyWatchers();
}
}
}
}
} }
void CPropBrowserCtrl::enablePropertyWatchers() void CPropBrowserCtrl::enablePropertyWatchers()
@ -389,6 +522,7 @@ namespace GUIEditor
SWidgetInfo &w = itr->second; SWidgetInfo &w = itr->second;
nameToType.clear(); nameToType.clear();
ttPosRefProps.clear();
std::vector< SPropEntry >::const_iterator pItr; std::vector< SPropEntry >::const_iterator pItr;
for( pItr = w.props.begin(); pItr != w.props.end(); ++pItr ) for( pItr = w.props.begin(); pItr != w.props.end(); ++pItr )
@ -490,6 +624,42 @@ namespace GUIEditor
return; return;
} }
else else
if( prop.propType == "posreftt" )
{
std::string j = element->getProperty( prop.propName );
if( j.empty() )
return;
int e = -1;
e = NelPosRefTT::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" );
enums.push_back( "auto" );
enumMgr->setEnumNames( pp, enums );
enumMgr->setValue( pp, e );
browser->addProperty( pp );
ttPosRefProps[ prop.propName ] = pp;
return;
}
else
if( prop.propType == "string" ) if( prop.propType == "string" )
{ {
p = propertyMgr->addProperty( QVariant::String, prop.propName.c_str() ); p = propertyMgr->addProperty( QVariant::String, prop.propName.c_str() );

View file

@ -77,6 +77,8 @@ namespace GUIEditor
std::string currentElement; std::string currentElement;
std::map< std::string, SWidgetInfo > widgetInfo; std::map< std::string, SWidgetInfo > widgetInfo;
std::map< std::string, std::string > nameToType; std::map< std::string, std::string > nameToType;
std::map< std::string, QtProperty * > ttPosRefProps; // Tooltip posref properties
std::map< std::string, std::string > ttPairs;
}; };
} }

View file

@ -40,12 +40,22 @@
</property> </property>
<property> <property>
<name>tooltip_posref</name> <name>tooltip_posref</name>
<type>string</type> <type>posreftt</type>
<default>auto</default>
</property>
<property>
<name>tooltip_parent_posref</name>
<type>posreftt</type>
<default>auto</default> <default>auto</default>
</property> </property>
<property> <property>
<name>tooltip_posref_alt</name> <name>tooltip_posref_alt</name>
<type>string</type> <type>posreftt</type>
<default>auto</default>
</property>
<property>
<name>tooltip_parent_posref_alt</name>
<type>posreftt</type>
<default>auto</default> <default>auto</default>
</property> </property>
<property> <property>