Added color picking support to the GUI Editor. TODO: change all the widget definitions.

This commit is contained in:
dfighter1985 2014-06-18 16:48:33 +02:00
parent 8fb7c1c5f0
commit 03e4c5ccd4
3 changed files with 66 additions and 25 deletions

View file

@ -22,6 +22,7 @@
#include "nel/gui/widget_manager.h" #include "nel/gui/widget_manager.h"
#include <typeinfo> #include <typeinfo>
#include "widget_info_tree.h" #include "widget_info_tree.h"
#include <QList>
namespace GUIEditor namespace GUIEditor
{ {
@ -62,8 +63,8 @@ namespace GUIEditor
void CPropBrowserCtrl::clear() void CPropBrowserCtrl::clear()
{ {
browser->clear(); browser->clear();
disconnect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ), disconnect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ),
this, SLOT( onPropertyChanged( QtProperty* ) ) ); this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
} }
void CPropBrowserCtrl::onSelectionChanged( std::string &id ) void CPropBrowserCtrl::onSelectionChanged( std::string &id )
@ -71,16 +72,16 @@ namespace GUIEditor
if( browser == NULL ) if( browser == NULL )
return; return;
disconnect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ), disconnect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ),
this, SLOT( onPropertyChanged( QtProperty* ) ) ); this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
browser->clear(); browser->clear();
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id ); CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id );
if( e == NULL ) if( e == NULL )
{ {
connect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ), connect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ),
this, SLOT( onPropertyChanged( QtProperty* ) ) ); this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
return; return;
} }
@ -90,11 +91,11 @@ namespace GUIEditor
std::string n = e->getClassName(); std::string n = e->getClassName();
setupProperties( n, e ); setupProperties( n, e );
connect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ), connect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ),
this, SLOT( onPropertyChanged( QtProperty* ) ) ); this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
} }
void CPropBrowserCtrl::onPropertyChanged( QtProperty *prop ) void CPropBrowserCtrl::onPropertyChanged( QtProperty *prop, const QVariant &v )
{ {
QString propName = prop->propertyName(); QString propName = prop->propertyName();
QString propValue = prop->valueText(); QString propValue = prop->valueText();
@ -107,6 +108,14 @@ namespace GUIEditor
propValue = p->value().toString(); propValue = p->value().toString();
} }
if( v.type() == QVariant::Color )
{
QColor c = v.value< QColor >();
QString val = "%1 %2 %3 %4";
val = val.arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
propValue = val;
}
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( currentElement ); CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( currentElement );
if( e == NULL ) if( e == NULL )
return; return;
@ -163,6 +172,38 @@ namespace GUIEditor
NLMISC::fromString( element->getProperty( prop.propName ), value ); NLMISC::fromString( element->getProperty( prop.propName ), value );
v = value; v = value;
} }
else
if( prop.propType == "color" )
{
p = propertyMgr->addProperty( QVariant::Color, prop.propName.c_str() );
std::string s = element->getProperty( prop.propName );
// Parse string into a QColor
QString qs = s.c_str();
QStringList l = qs.split( " " );
int r = l[ 0 ].toInt();
int g = l[ 1 ].toInt();
int b = l[ 2 ].toInt();
int a = l[ 3 ].toInt();
QColor value;
value.setRed( r );
value.setGreen( g );
value.setBlue( b );
value.setAlpha( a );
v = value;
// Remove the subproperties
QList< QtProperty* > pl = p->subProperties();
QListIterator< QtProperty* > itr( pl );
while( itr.hasNext() )
{
delete itr.next();
}
pl.clear();
}
if( p == NULL ) if( p == NULL )
return; return;

View file

@ -26,6 +26,7 @@
class QtTreePropertyBrowser; class QtTreePropertyBrowser;
class QtVariantPropertyManager; class QtVariantPropertyManager;
class QtProperty; class QtProperty;
class QVariant;
namespace NLGUI namespace NLGUI
{ {
@ -53,7 +54,7 @@ namespace GUIEditor
void onSelectionChanged( std::string &id ); void onSelectionChanged( std::string &id );
private Q_SLOTS: private Q_SLOTS:
void onPropertyChanged( QtProperty *prop ); void onPropertyChanged( QtProperty *prop, const QVariant &v );
private: private:
void setupProperties( const std::string &type, const NLGUI::CInterfaceElement *element ); void setupProperties( const std::string &type, const NLGUI::CInterfaceElement *element );

View file

@ -2,7 +2,6 @@
<header> <header>
<name>CtrlTextButton</name> <name>CtrlTextButton</name>
<guiname>CCtrlTextButton</guiname> <guiname>CCtrlTextButton</guiname>
<classname>text_button</classname>
<ancestor>CtrlBaseButton</ancestor> <ancestor>CtrlBaseButton</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>
@ -12,27 +11,27 @@
<property> <property>
<name>tx_normal</name> <name>tx_normal</name>
<type>string</type> <type>string</type>
<default>but</default> <default></default>
</property> </property>
<property> <property>
<name>tx_pushed</name> <name>tx_pushed</name>
<type>string</type> <type>string</type>
<default>but</default> <default></default>
</property> </property>
<property> <property>
<name>tx_over</name> <name>tx_over</name>
<type>string</type> <type>string</type>
<default>but_over</default> <default></default>
</property> </property>
<property> <property>
<name>hardtext</name> <name>hardtext</name>
<type>string</type> <type>string</type>
<default>text</default> <default></default>
</property> </property>
<property> <property>
<name>wmargin</name> <name>wmargin</name>
<type>int</type> <type>int</type>
<default>20</default> <default>0</default>
</property> </property>
<property> <property>
<name>wmin</name> <name>wmin</name>
@ -61,32 +60,32 @@
</property> </property>
<property> <property>
<name>text_color_normal</name> <name>text_color_normal</name>
<type>string</type> <type>color</type>
<default>255 255 255 255</default> <default>255 255 255 255</default>
</property> </property>
<property> <property>
<name>text_color_pushed</name> <name>text_color_pushed</name>
<type>string</type> <type>color</type>
<default>255 255 255 255</default> <default>255 255 255 255</default>
</property> </property>
<property> <property>
<name>text_color_over</name> <name>text_color_over</name>
<type>string</type> <type>color</type>
<default>255 255 255 255</default> <default>255 255 255 255</default>
</property> </property>
<property> <property>
<name>text_shadow_color_normal</name> <name>text_shadow_color_normal</name>
<type>string</type> <type>color</type>
<default>0 0 0 255</default> <default>0 0 0 255</default>
</property> </property>
<property> <property>
<name>text_shadow_color_pushed</name> <name>text_shadow_color_pushed</name>
<type>string</type> <type>color</type>
<default>0 0 0 255</default> <default>0 0 0 255</default>
</property> </property>
<property> <property>
<name>text_shadow_color_over</name> <name>text_shadow_color_over</name>
<type>string</type> <type>color</type>
<default>0 0 0 255</default> <default>0 0 0 255</default>
</property> </property>
<property> <property>
@ -116,7 +115,7 @@
</property> </property>
<property> <property>
<name>color</name> <name>color</name>
<type>string</type> <type>color</type>
<default>255 255 255 255</default> <default>255 255 255 255</default>
</property> </property>
<property> <property>
@ -136,7 +135,7 @@
</property> </property>
<property> <property>
<name>shadow_color</name> <name>shadow_color</name>
<type>string</type> <type>color</type>
<default>0 0 0 255</default> <default>0 0 0 255</default>
</property> </property>
<property> <property>
@ -152,7 +151,7 @@
<property> <property>
<name>line_maxw</name> <name>line_maxw</name>
<type>int</type> <type>int</type>
<default>200</default> <default>0</default>
</property> </property>
<property> <property>
<name>multi_line_space</name> <name>multi_line_space</name>