From 4af4bb1fa49c269e684ab145aaa37efd8d01d718 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 18 Jun 2014 16:48:33 +0200 Subject: [PATCH] Added color picking support to the GUI Editor. TODO: change all the widget definitions. --- .../gui_editor/property_browser_ctrl.cpp | 59 ++++++++++++++++--- .../gui_editor/property_browser_ctrl.h | 3 +- .../gui_editor/widgets/CtrlTextButton.xml | 29 +++++---- 3 files changed, 66 insertions(+), 25 deletions(-) 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 82330bfaf..da4ff1499 100644 --- a/code/studio/src/plugins/gui_editor/property_browser_ctrl.cpp +++ b/code/studio/src/plugins/gui_editor/property_browser_ctrl.cpp @@ -22,6 +22,7 @@ #include "nel/gui/widget_manager.h" #include #include "widget_info_tree.h" +#include namespace GUIEditor { @@ -62,8 +63,8 @@ namespace GUIEditor void CPropBrowserCtrl::clear() { browser->clear(); - disconnect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ), - this, SLOT( onPropertyChanged( QtProperty* ) ) ); + disconnect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), + this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) ); } void CPropBrowserCtrl::onSelectionChanged( std::string &id ) @@ -71,16 +72,16 @@ namespace GUIEditor if( browser == NULL ) return; - disconnect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ), - this, SLOT( onPropertyChanged( QtProperty* ) ) ); + disconnect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), + this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) ); browser->clear(); CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id ); if( e == NULL ) { - connect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ), - this, SLOT( onPropertyChanged( QtProperty* ) ) ); + connect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), + this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) ); return; } @@ -90,11 +91,11 @@ namespace GUIEditor std::string n = e->getClassName(); setupProperties( n, e ); - connect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ), - this, SLOT( onPropertyChanged( QtProperty* ) ) ); + connect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), + this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) ); } - void CPropBrowserCtrl::onPropertyChanged( QtProperty *prop ) + void CPropBrowserCtrl::onPropertyChanged( QtProperty *prop, const QVariant &v ) { QString propName = prop->propertyName(); QString propValue = prop->valueText(); @@ -107,6 +108,14 @@ namespace GUIEditor 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 ); if( e == NULL ) return; @@ -163,6 +172,38 @@ namespace GUIEditor NLMISC::fromString( element->getProperty( prop.propName ), 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 ) return; diff --git a/code/studio/src/plugins/gui_editor/property_browser_ctrl.h b/code/studio/src/plugins/gui_editor/property_browser_ctrl.h index 4c5ebce63..e126b86ea 100644 --- a/code/studio/src/plugins/gui_editor/property_browser_ctrl.h +++ b/code/studio/src/plugins/gui_editor/property_browser_ctrl.h @@ -26,6 +26,7 @@ class QtTreePropertyBrowser; class QtVariantPropertyManager; class QtProperty; +class QVariant; namespace NLGUI { @@ -53,7 +54,7 @@ namespace GUIEditor void onSelectionChanged( std::string &id ); private Q_SLOTS: - void onPropertyChanged( QtProperty *prop ); + void onPropertyChanged( QtProperty *prop, const QVariant &v ); private: void setupProperties( const std::string &type, const NLGUI::CInterfaceElement *element ); diff --git a/code/studio/src/plugins/gui_editor/widgets/CtrlTextButton.xml b/code/studio/src/plugins/gui_editor/widgets/CtrlTextButton.xml index cacc45ccb..32541cc1f 100644 --- a/code/studio/src/plugins/gui_editor/widgets/CtrlTextButton.xml +++ b/code/studio/src/plugins/gui_editor/widgets/CtrlTextButton.xml @@ -2,7 +2,6 @@
CtrlTextButton CCtrlTextButton - text_button CtrlBaseButton false @@ -12,27 +11,27 @@ tx_normal string - but + tx_pushed string - but + tx_over string - but_over + hardtext string - text + wmargin int - 20 + 0 wmin @@ -61,32 +60,32 @@ text_color_normal - string + color 255 255 255 255 text_color_pushed - string + color 255 255 255 255 text_color_over - string + color 255 255 255 255 text_shadow_color_normal - string + color 0 0 0 255 text_shadow_color_pushed - string + color 0 0 0 255 text_shadow_color_over - string + color 0 0 0 255 @@ -116,7 +115,7 @@ color - string + color 255 255 255 255 @@ -136,7 +135,7 @@ shadow_color - string + color 0 0 0 255 @@ -152,7 +151,7 @@ line_maxw int - 200 + 0 multi_line_space