Text style to return properties as string 35/128635/5
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Wed, 10 May 2017 17:45:25 +0000 (18:45 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Fri, 12 May 2017 17:42:39 +0000 (18:42 +0100)
API previously broken when Map used

Change-Id: I439a995cb1177c5b7ea6c81e45eba81d61759d68

automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
dali-toolkit/internal/text/text-controller-impl.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h
dali-toolkit/internal/text/text-effects-style.cpp

index 6455402..ff32ccf 100644 (file)
@@ -1847,3 +1847,69 @@ int utcDaliTextEditorHandles(void)
   END_TEST;
 }
 
+
+int utcDaliTextEditorUnderPropertyStringP(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextEditorUnderPropertyStringP");
+  TextEditor editor = TextEditor::New();
+  DALI_TEST_CHECK( editor );
+
+  std::string underlineSettings1( "{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}" );
+
+  Stage::GetCurrent().Add( editor );
+
+  editor.SetProperty( TextEditor::Property::UNDERLINE, underlineSettings1 );
+  DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::UNDERLINE ), underlineSettings1, TEST_LOCATION );
+
+  tet_infoline("Set underline settings with a map");
+  // Check the input underline property
+  Property::Map underlineMapSet;
+  Property::Map underlineMapGet;
+  underlineMapSet.Insert( "enable", "true" );
+  underlineMapSet.Insert( "color", "blue" );
+  underlineMapSet.Insert( "height", "2" );
+
+  editor.SetProperty( TextEditor::Property::UNDERLINE, underlineMapSet );
+  underlineMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::UNDERLINE );
+  DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
+  DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapSet, underlineMapGet ), true,  TEST_LOCATION );
+
+  tet_infoline("Set underline settings with a string");
+  editor.SetProperty( TextEditor::Property::UNDERLINE, underlineSettings1 );
+  Property::Value value = editor.GetProperty( TextEditor::Property::UNDERLINE );
+  std::string result;
+  value.Get(result);
+  DALI_TEST_EQUALS( result , underlineSettings1, TEST_LOCATION  );
+
+  tet_infoline("Trying to set invalid underline settings, should not update and stay at previous settings");
+  std::string underlineSettingsVoid( "{\"enable\":\"true\",\"coooolor\":\"blue\",\"heeeight\":\"4\"}" );
+  editor.SetProperty( TextEditor::Property::UNDERLINE, underlineSettingsVoid );
+  value = editor.GetProperty( TextEditor::Property::UNDERLINE );
+  value.Get(result);
+  DALI_TEST_EQUALS( result , underlineSettings1, TEST_LOCATION  );
+
+  END_TEST;
+}
+
+int utcDaliTextEditorShadowPropertyStringP(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextEditorUnderPropertyStringP Setting Shadow propeties by string");
+
+  TextEditor editor = TextEditor::New();
+
+  std::string shadowSettings( "{\"color\":\"green\",\"offset\":\"2 2\"}" );
+
+  Stage::GetCurrent().Add( editor );
+
+  editor.SetProperty( TextEditor::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" );
+
+  Property::Value value = editor.GetProperty<std::string>( TextEditor::Property::SHADOW );
+  std::string result;
+  value.Get(result);
+
+  DALI_TEST_EQUALS( result, shadowSettings, TEST_LOCATION );
+
+  END_TEST;
+}
index f317fb3..43a7cf3 100644 (file)
@@ -314,7 +314,9 @@ struct Controller::Impl
     mMarkupProcessorEnabled( false ),
     mClipboardHideEnabled( true ),
     mIsAutoScrollEnabled( false ),
-    mAutoScrollDirectionRTL( false )
+    mAutoScrollDirectionRTL( false ),
+    mUnderlineSetByString( false ),
+    mShadowSetByString( false )
   {
     mModel = Model::New();
 
@@ -721,6 +723,8 @@ public:
   bool mIsAutoScrollEnabled:1;             ///< Whether auto text scrolling is enabled.
   CharacterDirection mAutoScrollDirectionRTL:1;  ///< Direction of auto scrolling, true if rtl
 
+  bool mUnderlineSetByString:1;            ///< Set when underline is set by string (legacy) instead of map
+  bool mShadowSetByString:1;               ///< Set when shadow is set by string (legacy) instead of map
 };
 
 } // namespace Text
index 2811804..7545481 100644 (file)
@@ -1418,6 +1418,26 @@ Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
   return action;
 }
 
+bool Controller::IsUnderlineSetByString()
+{
+  return mImpl->mUnderlineSetByString;
+}
+
+void Controller::UnderlineSetByString( bool setByString )
+{
+  mImpl->mUnderlineSetByString = setByString;
+}
+
+bool Controller::IsShadowSetByString()
+{
+  return mImpl->mShadowSetByString;
+}
+
+void Controller::ShadowSetByString( bool setByString )
+{
+  mImpl->mShadowSetByString = setByString;
+}
+
 // public : Queries & retrieves.
 
 Layout::Engine& Controller::GetLayoutEngine()
index 7301e70..b9cbb2c 100644 (file)
@@ -398,6 +398,30 @@ public: // Configure the text controller.
    */
   NoTextTap::Action GetNoTextLongPressAction() const;
 
+  /**
+   * @brief Query if Underline settings were provided by string or map
+   * @return bool true if set by string
+   */
+  bool IsUnderlineSetByString();
+
+  /**
+   * Set method underline setting were set by
+   * @param[in] bool, true if set by string
+   */
+  void UnderlineSetByString( bool setByString );
+
+  /**
+   * @brief Query if shadow settings were provided by string or map
+   * @return bool true if set by string
+   */
+  bool IsShadowSetByString();
+
+  /**
+   * Set method shadow setting were set by
+   * @param[in] bool, true if set by string
+   */
+  void ShadowSetByString( bool setByString );
+
 public: // Update.
 
   /**
index 44302d7..75fabd7 100644 (file)
@@ -138,12 +138,39 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va
         bool heightDefined = false;
         float height = 0.f;
 
-        const bool empty = ParseUnderlineProperties( propertiesMap,
-                                                     enabled,
-                                                     colorDefined,
-                                                     color,
-                                                     heightDefined,
-                                                     height );
+        bool empty = true;
+
+        if ( propertiesMap.Empty() )
+        {
+          // Map empty so check if a string provided
+          const std::string propertyString = value.Get<std::string>();
+
+          if ( !propertyString.empty() )
+          {
+            Property::Map parsedStringMap;
+            Text::ParsePropertyString( propertyString, parsedStringMap );
+
+            empty = ParseUnderlineProperties( parsedStringMap,
+                                              enabled,
+                                              colorDefined,
+                                              color,
+                                              heightDefined,
+                                              height );
+
+            controller->UnderlineSetByString( !empty);
+          }
+        }
+        else
+        {
+           empty = ParseUnderlineProperties( propertiesMap,
+                                             enabled,
+                                             colorDefined,
+                                             color,
+                                             heightDefined,
+                                             height );
+
+           controller->UnderlineSetByString( false );
+        }
 
         if( !empty )
         {
@@ -202,20 +229,40 @@ void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, E
         const Vector4& color = controller->GetUnderlineColor();
         const float height = controller->GetUnderlineHeight();
 
-        Property::Map map;
+        if ( controller->IsUnderlineSetByString() )
+        {
+          std::string underlineProperties = "{\"enable\":";
+          const std::string enabledStr = enabled ? "true" : "false";
+          underlineProperties += "\"" + enabledStr + "\",";
+
+          std::string colorStr;
+          Vector4ToColorString( color, colorStr );
+          underlineProperties += "\"color\":\"" + colorStr + "\",";
+
+          std::string heightStr;
+          FloatToString( height, heightStr );
+          underlineProperties += "\"height\":\"" + heightStr + "\"}";
+
+          value = underlineProperties;
+        }
+        else
+        {
+          Property::Map map;
 
-        const std::string enabledStr = enabled ? TRUE_TOKEN : FALSE_TOKEN;
-        map.Insert( ENABLE_KEY, enabledStr );
+          const std::string enabledStr = enabled ? TRUE_TOKEN : FALSE_TOKEN;
+          map.Insert( ENABLE_KEY, enabledStr );
 
-        std::string colorStr;
-        Vector4ToColorString( color, colorStr );
-        map.Insert( COLOR_KEY, colorStr );
+          std::string colorStr;
+          Vector4ToColorString( color, colorStr );
+          map.Insert( COLOR_KEY, colorStr );
 
-        std::string heightStr;
-        FloatToString( height, heightStr );
-        map.Insert( HEIGHT_KEY, heightStr );
+          std::string heightStr;
+          FloatToString( height, heightStr );
+          map.Insert( HEIGHT_KEY, heightStr );
+
+          value = map;
+        }
 
-        value = map;
         break;
       }
       case EffectStyle::INPUT:
@@ -244,11 +291,35 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value
         bool offsetDefined = false;
         Vector2 offset;
 
-        const bool empty = ParseShadowProperties( propertiesMap,
-                                                  colorDefined,
-                                                  color,
-                                                  offsetDefined,
-                                                  offset );
+        bool empty = true;
+
+        if ( propertiesMap.Empty() )
+        {
+           // Map empty so check if a string provided
+           const std::string propertyString = value.Get<std::string>();
+
+           Property::Map parsedStringMap;
+           Text::ParsePropertyString( propertyString, parsedStringMap );
+
+           empty = ParseShadowProperties( parsedStringMap,
+                                          colorDefined,
+                                          color,
+                                          offsetDefined,
+                                          offset );
+
+           controller->ShadowSetByString( !empty );
+
+        }
+        else
+        {
+          empty = ParseShadowProperties( propertiesMap,
+                                         colorDefined,
+                                         color,
+                                         offsetDefined,
+                                         offset );
+
+          controller->ShadowSetByString( false );
+        }
 
         if( !empty )
         {
@@ -299,17 +370,34 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe
         const Vector4& color = controller->GetShadowColor();
         const Vector2& offset = controller->GetShadowOffset();
 
-        Property::Map map;
+        if ( controller->IsShadowSetByString() )
+        {
+          std::string shadowProperties = "{";
 
-        std::string colorStr;
-        Vector4ToColorString( color, colorStr );
-        map.Insert( COLOR_KEY, colorStr );
+          std::string colorStr;
+          Vector4ToColorString( color, colorStr );
+          shadowProperties += "\"color\":\"" + colorStr + "\",";
 
-        std::string offsetStr;
-        Vector2ToString( offset, offsetStr );
-        map.Insert( OFFSET_KEY, offsetStr );
+          std::string offsetStr;
+          Vector2ToString( offset, offsetStr );
+          shadowProperties += "\"offset\":\"" + offsetStr + "\"}";
 
-        value = map;
+          value = shadowProperties;
+        }
+        else
+        {
+          Property::Map map;
+
+          std::string colorStr;
+          Vector4ToColorString( color, colorStr );
+          map.Insert( COLOR_KEY, colorStr );
+
+          std::string offsetStr;
+          Vector2ToString( offset, offsetStr );
+          map.Insert( OFFSET_KEY, offsetStr );
+
+          value = map;
+        }
         break;
       }
       case EffectStyle::INPUT: