X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftoolkit-style-monitor.cpp;h=18c086f3b96a4068aa391a3d1f835564be52ee9f;hp=6b200637be3cab133e5728eac9c09b4d2167d4f5;hb=7dbe383e1d72909ceb2ef46e33b880243911df7e;hpb=30f6ca1e541089b19f2b349a8a12d8a5bcaf2f9e diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-style-monitor.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-style-monitor.cpp index 6b20063..18c086f 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-style-monitor.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-style-monitor.cpp @@ -1,29 +1,68 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +// HEADER #include "toolkit-style-monitor.h" -#include +// EXTERNAL INCLUDES +#include +#include #include -#include +#include -namespace Dali +namespace +{ +const char* DEFAULT_THEME= + "{\n" + " \"config\":\n" + " {\n" + " \"brokenImageUrl\":\"{DALI_IMAGE_DIR}broken.png\"\n" + " },\n" + " \"styles\":\n" + " {\n" + " \"textlabel\":\n" + " {\n" + " \"fontStyle\":{\"weight\":\"normal\"},\n" + " \"pointSize\":18\n" + " }\n" + " }\n" + "}\n"; + +struct NamedTheme { + NamedTheme( const std::string& name, const std::string& theme ) + : name(name), theme(theme) + { + } + + std::string name; + std::string theme; +}; +typedef std::vector< NamedTheme > NamedThemes; +NamedThemes gThemes; +std::string gTheme; +std::string gFontFamily("LucidaSans"); +std::string gFontStyle("Regular"); +int gFontSize(1); +} +namespace Dali +{ namespace Internal { namespace Adaptor @@ -40,22 +79,25 @@ public: // Creation & Destruction public: // Style Information std::string GetDefaultFontFamily() const; + std::string GetDefaultFontStyle() const; float GetDefaultFontSize() const; const std::string& GetTheme() const; void SetTheme(std::string theme); + bool LoadThemeFile( const std::string& filename, std::string& output ); public: // Signals - Dali::StyleMonitor::StyleChangeSignalV2& StyleChangeSignal(); + Dali::StyleMonitor::StyleChangeSignalType& StyleChangeSignal(); - void EmitStyleChangeSignal(StyleChange styleChange) + void EmitStyleChangeSignal(StyleChange::Type styleChange) { mStyleChangeSignal.Emit(Dali::StyleMonitor(this), styleChange); } private: - Dali::StyleMonitor::StyleChangeSignalV2 mStyleChangeSignal; + Dali::StyleMonitor::StyleChangeSignalType mStyleChangeSignal; static Dali::StyleMonitor mToolkitStyleMonitor; - std::string mTheme; + + std::string mTheme; ///<< Current theme name }; Dali::StyleMonitor StyleMonitor::mToolkitStyleMonitor; @@ -80,12 +122,17 @@ StyleMonitor::~StyleMonitor() std::string StyleMonitor::GetDefaultFontFamily() const { - return Dali::StyleMonitor::DEFAULT_FONT_FAMILY; + return gFontFamily; +} + +std::string StyleMonitor::GetDefaultFontStyle() const +{ + return gFontStyle; } float StyleMonitor::GetDefaultFontSize() const { - return Dali::StyleMonitor::DEFAULT_FONT_SIZE; + return gFontSize; } const std::string& StyleMonitor::GetTheme() const @@ -95,14 +142,34 @@ const std::string& StyleMonitor::GetTheme() const void StyleMonitor::SetTheme(std::string path) { - StyleChange styleChange; - styleChange.themeChange = true; - styleChange.themeFilePath = path; mTheme = path; - EmitStyleChangeSignal(styleChange); + EmitStyleChangeSignal( StyleChange::THEME_CHANGE ); +} + +bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output ) +{ + for( NamedThemes::iterator iter = gThemes.begin(); iter != gThemes.end(); ++iter ) + { + NamedTheme& theme = *iter; + if( theme.name == filename ) + { + output = theme.theme; + return true; + } + } + + if( !gTheme.empty() ) + { + output = gTheme; + } + else + { + output = DEFAULT_THEME; + } + return true; } -Dali::StyleMonitor::StyleChangeSignalV2& StyleMonitor::StyleChangeSignal() +Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal() { return mStyleChangeSignal; } @@ -123,9 +190,6 @@ const Internal::Adaptor::StyleMonitor& GetImplementation(const Dali::StyleMonito return static_cast(object); } -const std::string Dali::StyleMonitor::DEFAULT_FONT_FAMILY("DefaultFont"); -const float Dali::StyleMonitor::DEFAULT_FONT_SIZE(1.0f); - StyleMonitor::StyleMonitor() { } @@ -149,7 +213,12 @@ std::string StyleMonitor::GetDefaultFontFamily() const return GetImplementation(*this).GetDefaultFontFamily(); } -float StyleMonitor::GetDefaultFontSize() const +std::string StyleMonitor::GetDefaultFontStyle() const +{ + return GetImplementation(*this).GetDefaultFontStyle(); +} + +int StyleMonitor::GetDefaultFontSize() const { return GetImplementation(*this).GetDefaultFontSize(); } @@ -159,19 +228,19 @@ const std::string& StyleMonitor::GetTheme() const return GetImplementation(*this).GetTheme(); } -void StyleMonitor::SetTheme(std::string themeFilePath) +void StyleMonitor::SetTheme(const std::string& themeFilePath) { GetImplementation(*this).SetTheme(themeFilePath); } -StyleMonitor::StyleChangeSignalV2& StyleMonitor::StyleChangeSignal() +StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal() { return GetImplementation(*this).StyleChangeSignal(); } -void StyleMonitor::EmitStyleChangeSignal(StyleChange styleChange) +bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output ) { - GetImplementation(*this).EmitStyleChangeSignal(styleChange); + return GetImplementation(*this).LoadThemeFile(filename, output); } StyleMonitor& StyleMonitor::operator=(const StyleMonitor& monitor) @@ -189,3 +258,41 @@ StyleMonitor::StyleMonitor(Internal::Adaptor::StyleMonitor* internal) } } // namespace Dali + +namespace Test +{ +namespace StyleMonitor +{ + +void SetThemeFileOutput( const std::string& name, const std::string& output ) +{ + for( NamedThemes::iterator iter = gThemes.begin(); iter != gThemes.end(); ++iter ) + { + NamedTheme& theme = *iter; + if( theme.name == name ) + { + theme.theme = output; + return; + } + } + + gThemes.push_back( NamedTheme( name, output ) ); +} + +void SetDefaultFontFamily(const std::string& family) +{ + gFontFamily = family; +} + +void SetDefaultFontStyle(const std::string& style) +{ + gFontStyle = style; +} + +void SetDefaultFontSize( float size ) +{ + gFontSize = size; +} + +} // StyleMonitor +} // Test