Add read-only property for getting text line count 32/128932/12
authorJinho, Lee <jeano.lee@samsung.com>
Thu, 11 May 2017 14:24:53 +0000 (23:24 +0900)
committerJinho, Lee <jeano.lee@samsung.com>
Thu, 1 Jun 2017 07:32:16 +0000 (16:32 +0900)
Change-Id: I316752b0a8b77187d2995b7c8a2ad4be7650b371

automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h
dali-toolkit/devel-api/controls/text-controls/text-label-devel.h
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

index 5cacd19..b1ffcff 100644 (file)
@@ -93,6 +93,7 @@ const char* const PROPERTY_NAME_ENABLE_SCROLL_BAR                    = "enableSc
 const char* const PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION             = "scrollBarShowDuration";
 const char* const PROPERTY_NAME_SCROLL_BAR_FADE_DURATION             = "scrollBarFadeDuration";
 const char* const PROPERTY_NAME_PIXEL_SIZE                           = "pixelSize";
+const char* const PROPERTY_NAME_LINE_COUNT                           = "lineCount";
 
 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
 
@@ -433,6 +434,7 @@ int UtcDaliTextEditorGetPropertyP(void)
   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION );
   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION );
   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == DevelTextEditor::Property::PIXEL_SIZE );
+  DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_COUNT) == DevelTextEditor::Property::LINE_COUNT );
 
   END_TEST;
 }
@@ -1935,3 +1937,28 @@ int utcDaliTextEditorFontStylePropertyStringP(void)
 
   END_TEST;
 }
+int utcDaliTextEditorGetPropertyLinecountP(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline(" utcDaliTextEditorGetPropertyLinecount getting line count property");
+
+  int lineCount =0 ;
+
+  TextEditor editor = TextEditor::New();
+  editor.SetProperty( TextEditor::Property::POINT_SIZE, 10) ;
+  editor.SetProperty( TextEditor::Property::TEXT,
+                       "TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST ");
+
+  Stage::GetCurrent().Add( editor );
+
+  editor.SetSize( 100.0f, 100.0f );
+  lineCount =  editor.GetProperty<int>( DevelTextEditor::Property::LINE_COUNT );
+  DALI_TEST_EQUALS( lineCount, 14, TEST_LOCATION );
+
+  editor.SetSize( 50.0f, 100.0f );
+  lineCount =  editor.GetProperty<int>( DevelTextEditor::Property::LINE_COUNT );
+  DALI_TEST_EQUALS( lineCount, 28, TEST_LOCATION );
+
+  END_TEST;
+}
index cff3a39..5bc2654 100644 (file)
@@ -109,7 +109,14 @@ namespace Property
        * @brief The size of font in pixels.
        * @details name "pixelSize", type float
        */
-      PIXEL_SIZE
+      PIXEL_SIZE,
+
+      /**
+       * @brief The line count of text.
+       * @details name "lineCount", type int
+       * @note this property is read-only.
+       */
+      LINE_COUNT
   };
 } // namespace Property
 
index 40c6c70..12e9c75 100644 (file)
@@ -83,6 +83,13 @@ namespace Property
        *          values FINISH_LOOP, IMMEDIATE, defualt FINISH_LOOP
        */
       AUTO_SCROLL_STOP_MODE = OUTLINE + 4,
+
+      /*
+       * @brief The line count of text.
+       * @details name "lineCount", type int
+       * @node this property is read-only.
+       */
+      LINE_COUNT = OUTLINE + 5
   };
 } // namespace Property
 
index 5be99a6..47ee359 100644 (file)
@@ -134,6 +134,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableScrollBar",
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarShowDuration",          FLOAT,     SCROLL_BAR_SHOW_DURATION             )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarFadeDuration",          FLOAT,     SCROLL_BAR_FADE_DURATION             )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pixelSize",                      FLOAT,     PIXEL_SIZE                           )
+DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "lineCount",            INTEGER,   LINE_COUNT                           )
 
 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged",        SIGNAL_TEXT_CHANGED )
 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged",  SIGNAL_INPUT_STYLE_CHANGED )
@@ -994,6 +995,15 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind
         }
         break;
       }
+      case Toolkit::DevelTextEditor::Property::LINE_COUNT:
+      {
+        if( impl.mController )
+        {
+          float width = textEditor.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
+          value = impl.mController->GetLineCount( width );
+        }
+        break;
+      }
     } //switch
   }
 
index b1c031c..5187b25 100644 (file)
@@ -117,7 +117,8 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline",                   MAP
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize",           FLOAT,   PIXEL_SIZE             )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis",            BOOLEAN, ELLIPSIS               )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT,   AUTO_SCROLL_LOOP_DELAY )
-DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode",  STRING,  AUTO_SCROLL_STOP_MODE )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode",  STRING,  AUTO_SCROLL_STOP_MODE  )
+DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT             )
 
 DALI_TYPE_REGISTRATION_END()
 
@@ -736,6 +737,15 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde
         }
         break;
       }
+      case Toolkit::DevelTextLabel::Property::LINE_COUNT:
+      {
+        if( impl.mController )
+        {
+          float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
+          value = impl.mController->GetLineCount( width );
+        }
+        break;
+      }
     }
   }
 
index a502200..7596b51 100644 (file)
@@ -1599,6 +1599,13 @@ float Controller::GetHeightForWidth( float width )
   return layoutSize.height;
 }
 
+int Controller::GetLineCount( float width )
+{
+  GetHeightForWidth( width );
+  int numberofLines = mImpl->mModel->GetNumberOfLines();
+  return numberofLines;
+}
+
 const ModelInterface* const Controller::GetTextModel() const
 {
   return mImpl->mModel.Get();
index 7562394..e3a7427 100644 (file)
@@ -910,6 +910,13 @@ public: // Queries & retrieves.
   float GetHeightForWidth( float width );
 
   /**
+   * @brief Retrieves the text's number of lines for a given width.
+   * @param[in] width The width of the text's area.
+   * @ return The number of lines.
+   */
+  int GetLineCount( float width );
+
+  /**
    * @brief Retrieves the text's model.
    *
    * @return A pointer to the text's model.