From 536dbd95b845181336b94928d26e92b2f5da47fc Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Wed, 15 Jul 2015 13:55:39 +0100 Subject: [PATCH] Text Selection Popup to use Style sheet for Properties Change-Id: I983afd9e02d90e3b325fc1c9876d52fd50aa557a Signed-off-by: Agnelo Vaz --- .../text-controls/text-selection-popup.cpp | 5 + .../controls/text-controls/text-selection-popup.h | 8 ++ ...tion-popup-bg#.png => selection-popup-bg.9.png} | Bin .../controls/text-controls/text-field-impl.cpp | 2 +- .../text-controls/text-selection-popup-impl.cpp | 104 ++++++--------------- .../text-controls/text-selection-popup-impl.h | 9 +- .../text-controls/text-selection-toolbar-impl.cpp | 9 +- .../internal/text/decorator/text-decorator.cpp | 1 + .../styles/dali-toolkit-default-theme.json | 8 +- .../styles/mobile/dali-toolkit-default-theme.json | 9 +- 10 files changed, 72 insertions(+), 83 deletions(-) rename dali-toolkit/images/{selection-popup-bg#.png => selection-popup-bg.9.png} (100%) diff --git a/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.cpp b/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.cpp index ec3ad65..4b9f548 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.cpp @@ -68,6 +68,11 @@ void TextSelectionPopup::RaiseAbove( Layer target ) GetImpl(*this).RaiseAbove( target ); } +void TextSelectionPopup::ShowPopup() +{ + GetImpl(*this).ShowPopup(); +} + TextSelectionPopup::TextSelectionPopup( Internal::TextSelectionPopup& implementation ) : Control(implementation) { diff --git a/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h b/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h index 8608891..67a7966 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h @@ -86,6 +86,9 @@ public: POPUP_PASTE_BUTTON_ICON_IMAGE, ///< name "popup-paste-button-image", The image to use as the popup paste icon, type STRING POPUP_SELECT_BUTTON_ICON_IMAGE, ///< name "popup-select-button-image", The image to use as the popup select icon, type STRING POPUP_SELECT_ALL_BUTTON_ICON_IMAGE, ///< name "popup-select-all-button-image", The image to use as the popup select all icon, type STRING + DIVIDER_COLOR, ///< name "popup-divider-color", VECTOR4, The color of the divider between options, type VECTOR4 + ICON_COLOR, ///< name "popup-icon-color", VECTOR4, The color of the icons (if supplied), type VECTOR4 + PRESSED_COLOR ///< name "popup-pressed-color", VECTOR4, The color of the option when pressed, type VECTOR4 }; }; @@ -143,6 +146,11 @@ public: */ void RaiseAbove( Layer target ); + /** + * @brief Show the Popup + */ + void ShowPopup(); + public: // Not intended for application developers /** diff --git a/dali-toolkit/images/selection-popup-bg#.png b/dali-toolkit/images/selection-popup-bg.9.png similarity index 100% rename from dali-toolkit/images/selection-popup-bg#.png rename to dali-toolkit/images/selection-popup-bg.9.png diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 558d831..8fda39b 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -115,7 +115,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left", DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right", STRING, SELECTION_HANDLE_IMAGE_RIGHT ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left", STRING, SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", STRING, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color", STRING, SELECTION_HIGHLIGHT_COLOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color", VECTOR4, SELECTION_HIGHLIGHT_COLOR ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "input-method-settings", MAP, INPUT_METHOD_SETTINGS ) diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp index 1b61bbb..3ff907b 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp @@ -49,20 +49,6 @@ namespace const std::string TEXT_SELECTION_POPUP_LABEL = "textselectionpopuplabel"; -const Dali::Vector4 DEFAULT_POPUP_DIVIDER_COLOR( Dali::Vector4( 0.23f, 0.72f, 0.8f, 0.11f ) ); -const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); -const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 0.11f ) ); - -const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "selection-popup-bg#.png" ); -const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" ); -const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" ); -const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" ); -const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" ); -const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" ); -const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" ); - -const float OPTION_MARGIN_WIDTH( 10.f ); ///< The margin between the right or lefts edge and the text or icon. - #ifdef DGETTEXT_ENABLED #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT") @@ -110,6 +96,9 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-copy-button-imag DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE ) DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE ) DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-divider-color", VECTOR4, DIVIDER_COLOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-icon-color", VECTOR4, ICON_COLOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-pressed-color", VECTOR4, PRESSED_COLOR ) DALI_TYPE_REGISTRATION_END() @@ -148,11 +137,6 @@ void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() ); break; } - case Toolkit::TextSelectionPopup::Property::POPUP_MIN_SIZE: - { - impl.SetDimensionToCustomise( POPUP_MINIMUM_SIZE, value.Get< Vector2 >() ); - break; - } case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE: { impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() ); @@ -204,6 +188,21 @@ void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image ); break; } + case Toolkit::TextSelectionPopup::Property::DIVIDER_COLOR: + { + impl.mDividerColor = value.Get< Vector4 >(); + break; + } + case Toolkit::TextSelectionPopup::Property::ICON_COLOR: + { + impl.mIconColor = value.Get< Vector4 >(); + break; + } + case Toolkit::TextSelectionPopup::Property::PRESSED_COLOR: + { + impl.mPressedColor = value.Get< Vector4 >(); + break; + } } // switch } // TextSelectionPopup } @@ -307,6 +306,11 @@ void TextSelectionPopup::RaiseAbove( Layer target ) } } +void TextSelectionPopup::ShowPopup() +{ + AddPopupOptionsToToolbar( mShowIcons, mShowCaptions ); +} + void TextSelectionPopup::OnInitialize() { CreatePopup(); @@ -386,26 +390,16 @@ void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& set { case POPUP_MAXIMUM_SIZE : { - Actor self = Self(); - mMaxSize = dimension; if ( mToolbar ) { - mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize ); + mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension ); } break; } - case POPUP_MINIMUM_SIZE : - { - Actor self = Self(); - mMinSize = dimension; - // Option can not be smaller than this if only one. - break; - } case OPTION_MAXIMUM_SIZE : { mOptionMaxSize = dimension; // Option max size not currently currently supported - break; } case OPTION_MINIMUM_SIZE : @@ -432,11 +426,7 @@ Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& set { case POPUP_MAXIMUM_SIZE : { - return mMaxSize; - } - case POPUP_MINIMUM_SIZE : - { - return mMinSize; + return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >(); } case OPTION_MAXIMUM_SIZE : { @@ -546,38 +536,11 @@ Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::But mOrderListOfButtons.reserve( 8u ); // Create button for each possible option using Option priority - if ( !mCutIconImage ) - { - mCutIconImage = ResourceImage::New( OPTION_ICON_CUT ); - } mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) ); - - if ( !mCopyIconImage ) - { - mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY ); - } mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) ); - - if ( !mPasteIconImage ) - { - mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE ); - } mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) ); - - if ( !mSelectIconImage ) - mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT ); mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) ); - - if ( !mSelectAllIconImage ) - { - mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL ); - } mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) ); - - if ( !mClipboardIconImage ) - { - mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD ); - } mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) ); // Sort the buttons according their priorities. @@ -634,7 +597,7 @@ Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::But int depth = Self().GetHierarchyDepth(); // 3. Create the icons - if ( showIcons ) + if ( showIcons && iconImage ) { ImageActor pressedIcon = ImageActor::New( iconImage ); ImageActor icon = ImageActor::New( iconImage ); @@ -765,31 +728,26 @@ Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::But void TextSelectionPopup::CreatePopup() { Actor self = Self(); - CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown + CreateOrderedListOfPopupOptions(); self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); - SetBackgroundImage( NinePatchImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE ) ); if( !mToolbar ) { mToolbar = Toolkit::TextSelectionToolbar::New(); mToolbar.SetParentOrigin( ParentOrigin::CENTER ); - mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize ); self.Add( mToolbar ); - AddPopupOptionsToToolbar( mShowIcons, mShowCaptions ); } } TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface ) : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ), mToolbar(), - mMaxSize(), - mMinSize(), - mOptionDividerSize( Size( 2.0f, 0.0f) ), + mOptionDividerSize(), mEnabledButtons( Toolkit::TextSelectionPopup::NONE ), mCallbackInterface( callbackInterface ), - mDividerColor( DEFAULT_POPUP_DIVIDER_COLOR ), - mIconColor( DEFAULT_OPTION_ICON ), - mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ), + mDividerColor( Color::WHITE ), + mIconColor( Color::WHITE ), + mPressedColor( Color::WHITE ), mSelectOptionPriority( 1 ), mSelectAllOptionPriority ( 2 ), mCutOptionPriority ( 4 ), diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h index 3bb8b71..619dc37 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h @@ -44,7 +44,6 @@ namespace enum PopupCustomisations { POPUP_MAXIMUM_SIZE, - POPUP_MINIMUM_SIZE, OPTION_MAXIMUM_SIZE, OPTION_MINIMUM_SIZE, OPTION_DIVIDER_SIZE @@ -129,6 +128,11 @@ public: */ void RaiseAbove( Layer target ); + /** + * @copydoc Toolkit::TextSelectionPopup::ShowPopup() + */ + void ShowPopup(); + private: // From Control /** @@ -257,9 +261,6 @@ private: // Data Image mSelectIconImage; Image mSelectAllIconImage; - Size mMaxSize; // Maximum size of the Popup - Size mMinSize; // Minimum size of the Popup - Size mOptionMaxSize; // Maximum size of an Option button Size mOptionMinSize; // Minimum size of an Option button Size mOptionDividerSize; // Size of divider line diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp index 756c44d..78d8f5f 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp @@ -154,6 +154,11 @@ void TextSelectionToolbar::OnStageConnection( int depth ) void TextSelectionToolbar::SetPopupMaxSize( const Size& maxSize ) { mMaxSize = maxSize; + if (mScrollView && mStencilLayer ) + { + mScrollView.SetMaximumSize( mMaxSize ); + mStencilLayer.SetMaximumSize( mMaxSize ); + } } const Dali::Vector2& TextSelectionToolbar::GetPopupMaxSize() const @@ -166,7 +171,6 @@ void TextSelectionToolbar::SetUpScrollView( Toolkit::ScrollView& scrollView ) scrollView.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); scrollView.SetParentOrigin( ParentOrigin::CENTER_LEFT ); scrollView.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - scrollView.SetMaximumSize( mMaxSize ); scrollView.SetScrollingDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 40.0f ) ); scrollView.SetAxisAutoLock( true ); @@ -189,7 +193,6 @@ void TextSelectionToolbar::SetUp() mStencilLayer = Layer::New(); mStencilLayer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); mStencilLayer.SetParentOrigin( ParentOrigin::CENTER ); - mStencilLayer.SetMaximumSize( mMaxSize ); ImageActor stencil = CreateSolidColorActor( Color::RED ); stencil.SetDrawMode( DrawMode::STENCIL ); @@ -253,7 +256,7 @@ void TextSelectionToolbar::RaiseAbove( Layer target ) TextSelectionToolbar::TextSelectionToolbar() : Control( ControlBehaviour( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ) ), - mMaxSize ( DEFAULT_MAX_SIZE ), + mMaxSize (), mIndexInTable( 0 ), mDividerIndexes() { diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index 49fe080..494805b 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -1527,6 +1527,7 @@ void Decorator::SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButt if( mImpl->mActiveLayer ) { mImpl->mActiveLayer.Add( mImpl->mCopyPastePopup.actor ); + mImpl->mCopyPastePopup.actor.ShowPopup(); } } diff --git a/dali-toolkit/styles/dali-toolkit-default-theme.json b/dali-toolkit/styles/dali-toolkit-default-theme.json index c47661f..014efd4 100644 --- a/dali-toolkit/styles/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/dali-toolkit-default-theme.json @@ -44,7 +44,13 @@ distributing this software or its derivatives. "textselectionpopup": { "popup-max-size":[400,100], - "popup-min-size":[100,65] + "option-divider-size":[2,0], + "popup-divider-color":[0.23,0.72,0.8,0.11], + "popup-icon-color":[1.0,1.0,1.0,1.0], + "popup-pressed-color":[0.24,0.72,0.8,0.11], + "background-image": { + "filename": "{DALI_IMAGE_DIR}selection-popup-bg.9.png" + } }, "textfield": { diff --git a/dali-toolkit/styles/mobile/dali-toolkit-default-theme.json b/dali-toolkit/styles/mobile/dali-toolkit-default-theme.json index b4536b8..8eeec51 100644 --- a/dali-toolkit/styles/mobile/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/mobile/dali-toolkit-default-theme.json @@ -58,6 +58,7 @@ distributing this software or its derivatives. "point-size":25 }, + "textfield": { "font-family":"SamsungSans", @@ -97,7 +98,13 @@ distributing this software or its derivatives. "textselectionpopup": { "popup-max-size":[400,100], - "popup-min-size":[100,65] + "option-divider-size":[2,0], + "popup-divider-color":[0.23,0.72,0.8,0.11], + "popup-icon-color":[1.0,1.0,1.0,1.0], + "popup-pressed-color":[0.24,0.72,0.8,0.11], + "background-image": { + "filename": "{DALI_IMAGE_DIR}selection-popup-bg.9.png" + } }, "scrollview": { -- 2.7.4