From 1afe2d4a17cd7b3b36dd70c2bee072c6252f5fe5 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 20 Jun 2014 17:07:27 +0200 Subject: [PATCH] Text justification can now be set using an enum property editor. --HG-- branch : gsoc2014-dfighter --- .../gui_editor/property_browser_ctrl.cpp | 74 +++++++++++++++++-- .../gui_editor/widgets/CtrlTextButton.xml | 2 +- .../plugins/gui_editor/widgets/ViewText.xml | 2 +- 3 files changed, 70 insertions(+), 8 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 c27d3ca6c..6408703f4 100644 --- a/code/studio/src/plugins/gui_editor/property_browser_ctrl.cpp +++ b/code/studio/src/plugins/gui_editor/property_browser_ctrl.cpp @@ -35,6 +35,13 @@ namespace GUIEditor BUTTON_TYPE_RADIO = 2 }; + enum NELTxtJustification + { + TEXT_CLIPWORD, + TEXT_DONTCLIPWORD, + TEXT_JUSTIFIED + }; + CPropBrowserCtrl::CPropBrowserCtrl() { browser = NULL; @@ -145,7 +152,7 @@ namespace GUIEditor if( e == NULL ) return; - if( ( value < 0 ) || ( value > 2 ) ) + if( ( value < BUTTON_TYPE_PUSH ) || ( value > BUTTON_TYPE_RADIO ) ) return; std::string v; @@ -157,6 +164,26 @@ namespace GUIEditor case BUTTON_TYPE_RADIO: v = "radio_button"; break; } + e->setProperty( propName.toUtf8().constData(), v ); + } + else + if( propName == "justification" ) + { + CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( currentElement ); + if( e == NULL ) + return; + + if( ( value < TEXT_CLIPWORD ) || ( value > TEXT_JUSTIFIED ) ) + return; + + std::string v; + switch( value ) + { + case TEXT_CLIPWORD: v = "clip_word"; break; + case TEXT_DONTCLIPWORD: v = "dont_clip_word"; break; + case TEXT_JUSTIFIED: v = "justified"; break; + } + e->setProperty( propName.toUtf8().constData(), v ); } } @@ -209,11 +236,6 @@ namespace GUIEditor if( btype.empty() ) return; - QStringList enums; - enums.push_back( "push_button" ); - enums.push_back( "toggle_button" ); - enums.push_back( "radio_button" ); - int e = -1; if( btype == "push_button" ) e = BUTTON_TYPE_PUSH; @@ -231,12 +253,52 @@ namespace GUIEditor if( pp == NULL ) return; + QStringList enums; + enums.push_back( "push_button" ); + enums.push_back( "toggle_button" ); + enums.push_back( "radio_button" ); + enumMgr->setEnumNames( pp, enums ); enumMgr->setValue( pp, e ); browser->addProperty( pp ); return; } else + if( prop.propType == "text_justification" ) + { + std::string j = element->getProperty( prop.propName ); + if( j.empty() ) + return; + + int e = -1; + if( j == "clip_word" ) + e = TEXT_CLIPWORD; + else + if( j == "dont_clip_word" ) + e = TEXT_DONTCLIPWORD; + else + if( j == "justified" ) + e = TEXT_JUSTIFIED; + + if( e == -1 ) + return; + + QtProperty *pp = enumMgr->addProperty( prop.propName.c_str() ); + if( pp == NULL ) + return; + + QStringList enums; + enums.push_back( "clip_word" ); + enums.push_back( "dont_clip_word" ); + enums.push_back( "justified" ); + + 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() ); diff --git a/code/studio/src/plugins/gui_editor/widgets/CtrlTextButton.xml b/code/studio/src/plugins/gui_editor/widgets/CtrlTextButton.xml index 32541cc1f..4553af272 100644 --- a/code/studio/src/plugins/gui_editor/widgets/CtrlTextButton.xml +++ b/code/studio/src/plugins/gui_editor/widgets/CtrlTextButton.xml @@ -145,7 +145,7 @@ justification - string + text_justification dont_clip_word diff --git a/code/studio/src/plugins/gui_editor/widgets/ViewText.xml b/code/studio/src/plugins/gui_editor/widgets/ViewText.xml index fc4d30688..415c3167e 100644 --- a/code/studio/src/plugins/gui_editor/widgets/ViewText.xml +++ b/code/studio/src/plugins/gui_editor/widgets/ViewText.xml @@ -40,7 +40,7 @@ justification - string + text_justification dont_clip_word