include/sfx2/StylePreviewRenderer.hxx | 14 + include/svx/ColorSets.hxx | 70 +++++++++ include/svx/CommonStylePreviewRenderer.hxx | 2 include/tools/color.hxx | 10 + svx/Library_svxcore.mk | 1 svx/source/styles/ColorSets.cxx | 126 +++++++++++++++++ svx/source/styles/CommonStylePreviewRenderer.cxx | 18 +- svx/source/xoutdev/xtable.cxx | 33 ++-- sw/source/uibase/sidebar/StylePresetsPanel.cxx | 120 +++++++++++++++- sw/source/uibase/sidebar/StylePresetsPanel.hxx | 10 + sw/source/uibase/sidebar/ThemePanel.cxx | 167 +++++++++-------------- sw/source/uibase/sidebar/ThemePanel.hxx | 13 + sw/uiconfig/swriter/ui/sidebarstylepresets.ui | 11 + sw/uiconfig/swriter/ui/sidebartheme.ui | 26 +-- tools/qa/cppunit/test_color.cxx | 60 ++++++++ tools/source/generic/color.cxx | 26 +++ 16 files changed, 566 insertions(+), 141 deletions(-)
New commits: commit c9df840d207c8d965b2df993e0a90be89f52c254 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Wed Aug 26 11:32:13 2015 +0900 ColorSets: add preview to ThemePanel, move impl. to own file Change-Id: I1b05edc954125e5bdeed05b5fdce1430f8eaba26 diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx new file mode 100644 index 0000000..009ee40 --- /dev/null +++ b/include/svx/ColorSets.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#ifndef INCLUDED_SVX_COLORSETS_HXX +#define INCLUDED_SVX_COLORSETS_HXX + +#include <svx/svxdllapi.h> +#include <vector> +#include <rtl/ustring.hxx> +#include <tools/color.hxx> + +namespace svx +{ + +class SVX_DLLPUBLIC ColorSet +{ + OUString maName; + std::vector<Color> maColors; +public: + ColorSet(OUString aName); + ~ColorSet(); + + void add(sal_uInt32 nIndex, sal_uInt32 aColorData) + { + maColors[nIndex] = Color(aColorData); + } + + const OUString& getName() const + { + return maName; + } + const Color& getColor(sal_uInt32 nIndex) const + { + return maColors[nIndex]; + } +}; + +class SVX_DLLPUBLIC ColorSets +{ + std::vector<ColorSet> maColorSets; +public: + ColorSets(); + ~ColorSets(); + + void init(); + const std::vector<ColorSet>& getColorSets() + { + return maColorSets; + } + + const ColorSet& getColorSet(sal_uInt32 nIndex) + { + return maColorSets[nIndex]; + } + + const ColorSet& getColorSet(const OUString& rName); +}; + +} // end of namespace svx + +#endif // INCLUDED_SVX_COLORSETS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index 6ba013a..89b1eb0 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -341,6 +341,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/svdraw/svdxcgv \ svx/source/styles/CommonStylePreviewRenderer \ svx/source/styles/CommonStyleManager \ + svx/source/styles/ColorSets \ svx/source/table/cell \ svx/source/table/cellcursor \ svx/source/table/cellrange \ diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx new file mode 100644 index 0000000..43ac4a7 --- /dev/null +++ b/svx/source/styles/ColorSets.cxx @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <svx/ColorSets.hxx> + +namespace svx +{ + +ColorSet::ColorSet(OUString aName) + : maName(aName) + , maColors(12) +{} + +ColorSet::~ColorSet() +{} + +ColorSets::ColorSets() +{} + +ColorSets::~ColorSets() +{} + +void ColorSets::init() +{ + { + ColorSet aColorSet("Breeze"); + aColorSet.add(0, 0x232629); + aColorSet.add(1, 0xFCFCFC); + aColorSet.add(2, 0x31363B); + aColorSet.add(3, 0xEFF0F1); + aColorSet.add(4, 0xDA4453); + aColorSet.add(5, 0xF47750); + aColorSet.add(6, 0xFDBC4B); + aColorSet.add(7, 0xC9CE3B); + aColorSet.add(8, 0x1CDC9A); + aColorSet.add(9, 0x2ECC71); + aColorSet.add(10, 0x1D99F3); + aColorSet.add(11, 0x3DAEE9); + maColorSets.push_back(aColorSet); + } + { + ColorSet aColorSet("Tango"); + aColorSet.add(0, 0x000000); + aColorSet.add(1, 0xFFFFFF); + aColorSet.add(2, 0x2E3436); + aColorSet.add(3, 0xBABDB6); + aColorSet.add(4, 0x3465A4); + aColorSet.add(5, 0x73D216); + aColorSet.add(6, 0xF57900); + aColorSet.add(7, 0x888A85); + aColorSet.add(8, 0xEDD400); + aColorSet.add(9, 0xEF2929); + aColorSet.add(10, 0x75507B); + aColorSet.add(11, 0x555753); + maColorSets.push_back(aColorSet); + } + { + ColorSet aColorSet("Material Blue"); + aColorSet.add(0, 0x212121); + aColorSet.add(1, 0xFFFFFF); + aColorSet.add(2, 0x37474F); + aColorSet.add(3, 0xECEFF1); + aColorSet.add(4, 0x7986CB); + aColorSet.add(5, 0x303F9F); + aColorSet.add(6, 0x64B5F6); + aColorSet.add(7, 0x1976D2); + aColorSet.add(8, 0x4FC3F7); + aColorSet.add(9, 0x0277BD); + aColorSet.add(10, 0x4DD0E1); + aColorSet.add(11, 0x0097A7); + maColorSets.push_back(aColorSet); + } + { + ColorSet aColorSet("Material Red"); + aColorSet.add(0, 0x212121); + aColorSet.add(1, 0xFFFFFF); + aColorSet.add(2, 0x424242); + aColorSet.add(3, 0xF5F5F5); + aColorSet.add(4, 0xFF9800); + aColorSet.add(5, 0xFF6D00); + aColorSet.add(6, 0xFF5722); + aColorSet.add(7, 0xDD2C00); + aColorSet.add(8, 0xF44336); + aColorSet.add(9, 0xD50000); + aColorSet.add(10, 0xE91E63); + aColorSet.add(11, 0xC51162); + maColorSets.push_back(aColorSet); + } + { + ColorSet aColorSet("Material Green"); + aColorSet.add(0, 0x212121); + aColorSet.add(1, 0xFFFFFF); + aColorSet.add(2, 0x424242); + aColorSet.add(3, 0xF5F5F5); + aColorSet.add(4, 0x009688); + aColorSet.add(5, 0x00bfa5); + aColorSet.add(6, 0x4caf50); + aColorSet.add(7, 0x00c853); + aColorSet.add(8, 0x8bc34a); + aColorSet.add(9, 0x64dd17); + aColorSet.add(10, 0xcddc39); + aColorSet.add(11, 0xaeea00); + maColorSets.push_back(aColorSet); + } +} + +const ColorSet& ColorSets::getColorSet(const OUString& rName) +{ + for (size_t i = 0; i < maColorSets.size(); ++i) + { + if (maColorSets[i].getName() == rName) + return maColorSets[i]; + } + return maColorSets[0]; +} + +} // end of namespace svx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx b/sw/source/uibase/sidebar/ThemePanel.cxx index c0457bb..93b0f1c 100644 --- a/sw/source/uibase/sidebar/ThemePanel.cxx +++ b/sw/source/uibase/sidebar/ThemePanel.cxx @@ -15,8 +15,6 @@ #include <swtypes.hxx> #include <cmdid.h> -#include <tools/helpers.hxx> - #include <svl/intitem.hxx> #include <svx/svxids.hrc> #include <svx/dlgutil.hxx> @@ -55,13 +53,6 @@ public: OUString msBaseFont; }; -class ColorSet -{ -public: - OUString maName; - Color maColors[10]; -}; - class ColorVariable { public: @@ -99,26 +90,13 @@ public: maVariable = aVariable; } - Color getColor(ColorSet& rColorSet) + Color getColor(svx::ColorSet& rColorSet) { Color aColor; if (maVariable.mnIndex > -1) { - aColor.SetColor(rColorSet.maColors[maVariable.mnIndex].GetColor()); - if (maVariable.mnTintShade < 0) - { - double fFactor = std::abs(maVariable.mnTintShade) / 10000.0; - aColor.SetRed(MinMax(aColor.GetRed() + (fFactor * (255.0 - aColor.GetRed())), 0, 255)); - aColor.SetGreen(MinMax(aColor.GetGreen() + (fFactor * (255.0 - aColor.GetGreen())), 0, 255)); - aColor.SetBlue(MinMax(aColor.GetBlue() + (fFactor * (255.0 - aColor.GetBlue())), 0, 255)); - } - else if (maVariable.mnTintShade > 0) - { - double fFactor = 1.0 - std::abs(maVariable.mnTintShade) / 10000.0; - aColor.SetRed(MinMax(aColor.GetRed() * fFactor, 0, 255)); - aColor.SetGreen(MinMax(aColor.GetGreen() * fFactor, 0, 255)); - aColor.SetBlue(MinMax(aColor.GetBlue() * fFactor, 0, 255)); - } + aColor = rColorSet.getColor(maVariable.mnIndex); + aColor.ApplyTintOrShade(maVariable.mnTintShade); } else { @@ -163,61 +141,61 @@ StyleSet setupThemes() { StyleRedefinition aRedefinition("Heading 1"); - aRedefinition.setColorVariable(ColorVariable(0, 4000)); + aRedefinition.setColorVariable(ColorVariable(10, -1000)); aSet.add(aRedefinition); } { StyleRedefinition aRedefinition("Heading 2"); - aRedefinition.setColorVariable(ColorVariable(0, 2500)); + aRedefinition.setColorVariable(ColorVariable(7, -500)); aSet.add(aRedefinition); } { StyleRedefinition aRedefinition("Heading 3"); - aRedefinition.setColorVariable(ColorVariable(0, 1000)); + aRedefinition.setColorVariable(ColorVariable(5, 0)); aSet.add(aRedefinition); } { StyleRedefinition aRedefinition("Heading 4"); - aRedefinition.setColorVariable(ColorVariable(0)); + aRedefinition.setColorVariable(ColorVariable(6, -1000)); aSet.add(aRedefinition); } { StyleRedefinition aRedefinition("Heading 5"); - aRedefinition.setColorVariable(ColorVariable(0, -500)); + aRedefinition.setColorVariable(ColorVariable(4, -1500)); aSet.add(aRedefinition); } { StyleRedefinition aRedefinition("Heading 6"); - aRedefinition.setColorVariable(ColorVariable(0, -1000)); + aRedefinition.setColorVariable(ColorVariable(3, -2500)); aSet.add(aRedefinition); } { StyleRedefinition aRedefinition("Heading 7"); - aRedefinition.setColorVariable(ColorVariable(0, -1500)); + aRedefinition.setColorVariable(ColorVariable(3, -2500)); aSet.add(aRedefinition); } { StyleRedefinition aRedefinition("Heading 8"); - aRedefinition.setColorVariable(ColorVariable(0, -2000)); + aRedefinition.setColorVariable(ColorVariable(2, 0)); aSet.add(aRedefinition); } { StyleRedefinition aRedefinition("Heading 9"); - aRedefinition.setColorVariable(ColorVariable(0, -2500)); + aRedefinition.setColorVariable(ColorVariable(2, 0)); aSet.add(aRedefinition); } { StyleRedefinition aRedefinition("Heading 10"); - aRedefinition.setColorVariable(ColorVariable(0, -3000)); + aRedefinition.setColorVariable(ColorVariable(0, 0)); aSet.add(aRedefinition); } @@ -276,7 +254,7 @@ void changeFont(SwFormat* pFormat, SwDocStyleSheet* pStyle, FontSet& rFontSet) } }*/ -void changeColor(SwTextFormatColl* pCollection, ColorSet& rColorSet, StyleRedefinition* pRedefinition) +void changeColor(SwTextFormatColl* pCollection, svx::ColorSet& rColorSet, StyleRedefinition* pRedefinition) { Color aColor = pRedefinition->getColor(rColorSet); @@ -373,62 +351,15 @@ FontSet getFontSet(const OUString& rFontVariant, std::vector<FontSet>& aFontSets return aFontSets[0]; } -std::vector<ColorSet> initColorSets() -{ - std::vector<ColorSet> aColorSets; - { - ColorSet aColorSet; - aColorSet.maName = "Default"; - aColorSet.maColors[0] = Color(0x00, 0x00, 0x00); - aColorSets.push_back(aColorSet); - } - { - ColorSet aColorSet; - aColorSet.maName = "Red"; - aColorSet.maColors[0] = Color(0xa4, 0x00, 0x00); - aColorSets.push_back(aColorSet); - } - { - ColorSet aColorSet; - aColorSet.maName = "Green"; - aColorSet.maColors[0] = Color(0x00, 0xa4, 0x00); - aColorSets.push_back(aColorSet); - } - { - ColorSet aColorSet; - aColorSet.maName = "Blue"; - aColorSet.maColors[0] = Color(0x00, 0x00, 0xa4); - aColorSets.push_back(aColorSet); - } - { - ColorSet aColorSet; - aColorSet.maName = "Sky"; - aColorSet.maColors[0] = Color(0x72, 0x9f, 0xcf); - aColorSets.push_back(aColorSet); - } - - return aColorSets; -} - -ColorSet getColorSet(const OUString& rColorVariant, std::vector<ColorSet>& aColorSets) -{ - for (size_t i = 0; i < aColorSets.size(); ++i) - { - if (aColorSets[i].maName == rColorVariant) - return aColorSets[i]; - } - return aColorSets[0]; -} - -void applyTheme(SfxStyleSheetBasePool* pPool, const OUString& sFontSetName, const OUString& sColorSetName, StyleSet& rStyleSet) +void applyTheme(SfxStyleSheetBasePool* pPool, const OUString& sFontSetName, const OUString& sColorSetName, + StyleSet& rStyleSet, svx::ColorSets& rColorSets) { SwDocStyleSheet* pStyle; std::vector<FontSet> aFontSets = initFontSets(); FontSet aFontSet = getFontSet(sFontSetName, aFontSets); - std::vector<ColorSet> aColorSets = initColorSets(); - ColorSet aColorSet = getColorSet(sColorSetName, aColorSets); + svx::ColorSet aColorSet = rColorSets.getColorSet(sColorSetName); pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA); pStyle = static_cast<SwDocStyleSheet*>(pPool->First()); @@ -480,19 +411,53 @@ VclPtr<vcl::Window> ThemePanel::Create (vcl::Window* pParent, return VclPtr<ThemePanel>::Create(pParent, rxFrame, pBindings); } +BitmapEx ThemePanel::GenerateColorPreview(const svx::ColorSet& rColorSet) +{ + ScopedVclPtrInstance<VirtualDevice> pVirtualDev(*Application::GetDefaultDevice()); + sal_Int32 nScaleFactor = pVirtualDev->GetDPIScaleFactor(); + long BORDER = 2 * nScaleFactor; + long SIZE = 12 * nScaleFactor; + + Size aSize(BORDER * 7 + SIZE * 6, BORDER * 3 + SIZE * 2); + pVirtualDev->SetOutputSizePixel(aSize); + + long x = BORDER; + long y1 = BORDER; + long y2 = y1 + SIZE + BORDER; + + pVirtualDev->SetLineColor(COL_LIGHTGRAY); + + for (sal_uInt32 i = 0; i < 12; i += 2) + { + pVirtualDev->SetFillColor(rColorSet.getColor(i)); + pVirtualDev->DrawRect(Rectangle(x, y1, x + SIZE, y1 + SIZE)); + + pVirtualDev->SetFillColor(rColorSet.getColor(i + 1)); + pVirtualDev->DrawRect(Rectangle(x, y2, x + SIZE, y2 + SIZE)); + + x += SIZE + BORDER; + } + + return pVirtualDev->GetBitmapEx(Point(), aSize); +} + ThemePanel::ThemePanel(vcl::Window* pParent, - const css::uno::Reference<css::frame::XFrame>& rxFrame, - SfxBindings* pBindings) + const css::uno::Reference<css::frame::XFrame>& rxFrame, + SfxBindings* pBindings) : PanelLayout(pParent, "ThemePanel", "modules/swriter/ui/sidebartheme.ui", rxFrame) , mpBindings(pBindings) + , maColorSets() { - get(mpListBoxFonts, "listbox_fonts"); - get(mpListBoxColors, "listbox_colors"); - get(mpApplyButton, "apply"); + get(mpListBoxFonts, "listbox_fonts"); + get(mpValueSetColors, "valueset_colors"); + get(mpApplyButton, "apply"); + + mpValueSetColors->SetColCount(2); + mpValueSetColors->SetLineCount(4); mpApplyButton->SetClickHdl(LINK(this, ThemePanel, ClickHdl)); mpListBoxFonts->SetDoubleClickHdl(LINK(this, ThemePanel, DoubleClickHdl)); - mpListBoxColors->SetDoubleClickHdl(LINK(this, ThemePanel, DoubleClickHdl)); + mpValueSetColors->SetDoubleClickHdl(LINK(this, ThemePanel, DoubleClickHdl)); std::vector<FontSet> aFontSets = initFontSets(); for (size_t i = 0; i < aFontSets.size(); ++i) @@ -500,10 +465,16 @@ ThemePanel::ThemePanel(vcl::Window* pParent, mpListBoxFonts->InsertEntry(aFontSets[i].maName); } - std::vector<ColorSet> aColorSets = initColorSets(); + maColorSets.init(); + + const std::vector<svx::ColorSet>& aColorSets = maColorSets.getColorSets(); for (size_t i = 0; i < aColorSets.size(); ++i) { - mpListBoxColors->InsertEntry(aColorSets[i].maName); + const svx::ColorSet& rColorSet = aColorSets[i]; + + OUString aName = rColorSet.getName(); + BitmapEx aPreview = GenerateColorPreview(rColorSet); + mpValueSetColors->InsertItem(i, Image(aPreview), aName); } } @@ -515,7 +486,7 @@ ThemePanel::~ThemePanel() void ThemePanel::dispose() { mpListBoxFonts.clear(); - mpListBoxColors.clear(); + mpValueSetColors.clear(); mpApplyButton.clear(); PanelLayout::dispose(); @@ -525,17 +496,19 @@ IMPL_LINK_NOARG_TYPED(ThemePanel, ClickHdl, Button*, void) { DoubleClickHdl(NULL); } + IMPL_LINK_NOARG(ThemePanel, DoubleClickHdl) { SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current()); if (pDocSh) { OUString sEntryFonts = mpListBoxFonts->GetSelectEntry(); - OUString sEntryColors = mpListBoxColors->GetSelectEntry(); + sal_uInt32 nItemId = mpValueSetColors->GetSelectItemId(); + OUString sEntryColors = maColorSets.getColorSet(nItemId).getName(); StyleSet aStyleSet = setupThemes(); - applyTheme(pDocSh->GetStyleSheetPool(), sEntryFonts, sEntryColors, aStyleSet); + applyTheme(pDocSh->GetStyleSheetPool(), sEntryFonts, sEntryColors, aStyleSet, maColorSets); } return 1; } diff --git a/sw/source/uibase/sidebar/ThemePanel.hxx b/sw/source/uibase/sidebar/ThemePanel.hxx index 0e95c5e..a2af076 100644 --- a/sw/source/uibase/sidebar/ThemePanel.hxx +++ b/sw/source/uibase/sidebar/ThemePanel.hxx @@ -32,8 +32,12 @@ #include <svl/intitem.hxx> #include <svl/lstner.hxx> +#include <svtools/valueset.hxx> + #include <svx/fntctrl.hxx> +#include <svx/ColorSets.hxx> + #include "docsh.hxx" namespace sw { namespace sidebar { @@ -56,18 +60,23 @@ private: ThemePanel(vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& rxFrame, SfxBindings* pBindings); - virtual ~ThemePanel(); + virtual void dispose() SAL_OVERRIDE; + BitmapEx GenerateColorPreview(const svx::ColorSet& rColorSet); + SfxBindings* mpBindings; VclPtr<ListBox> mpListBoxFonts; - VclPtr<ListBox> mpListBoxColors; + VclPtr<ValueSet> mpValueSetColors; VclPtr<PushButton> mpApplyButton; + svx::ColorSets maColorSets; + DECL_LINK_TYPED(ClickHdl, Button*, void); DECL_LINK(DoubleClickHdl, void*); + }; }} // end of namespace sw::sidebar diff --git a/sw/uiconfig/swriter/ui/sidebartheme.ui b/sw/uiconfig/swriter/ui/sidebartheme.ui index b422773..ec0d850 100644 --- a/sw/uiconfig/swriter/ui/sidebartheme.ui +++ b/sw/uiconfig/swriter/ui/sidebartheme.ui @@ -2,6 +2,8 @@ <!-- Generated with glade 3.18.3 --> <interface> <requires lib="gtk+" version="3.0"/> + <requires lib="LibreOffice" version="1.0"/> + <object class="GtkGrid" id="ThemePanel"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -44,20 +46,6 @@ </packing> </child> <child> - <object class="GtkTreeView" id="listbox_colors"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="hexpand">True</property> - <child internal-child="selection"> - <object class="GtkTreeSelection" id="treeview-selection2"/> - </child> - </object> - <packing> - <property name="left_attach">0</property> - <property name="top_attach">3</property> - </packing> - </child> - <child> <object class="GtkLabel" id="label2"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -82,6 +70,16 @@ <property name="top_attach">4</property> </packing> </child> + <child> + <object class="svtlo-ValueSet" id="valueset_colors"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">3</property> + </packing> + </child> </object> </child> </object> commit 48d2dca48d75fef67e3caa61d80f074fdbeb9984 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue May 26 18:49:29 2015 +0900 Show previews of style presets in sidebar Change-Id: I0e3d6f00a79bc33e1db1329df217e7e867dfd511 diff --git a/include/sfx2/StylePreviewRenderer.hxx b/include/sfx2/StylePreviewRenderer.hxx index bc77e20..1fc9804 100644 --- a/include/sfx2/StylePreviewRenderer.hxx +++ b/include/sfx2/StylePreviewRenderer.hxx @@ -26,8 +26,14 @@ protected: OutputDevice& mrOutputDev; SfxStyleSheetBase* mpStyle; long mnMaxHeight; + OUString msRenderText; public: + enum class RenderAlign + { + TOP, CENTER, BOTTOM + }; + StylePreviewRenderer(const SfxObjectShell& rShell, OutputDevice& rOutputDev, SfxStyleSheetBase* pStyle, @@ -36,14 +42,20 @@ public: , mrOutputDev(rOutputDev) , mpStyle(pStyle) , mnMaxHeight(nMaxHeight) + , msRenderText() {} virtual ~StylePreviewRenderer() {} + void setRenderText(OUString& rRenderText) + { + msRenderText = rRenderText; + } + virtual bool recalculate() = 0; virtual Size getRenderSize() = 0; - virtual bool render(const Rectangle& aRectangle) = 0; + virtual bool render(const Rectangle& aRectangle, RenderAlign eRenderAlign = RenderAlign::CENTER) = 0; }; } // end namespace sfx2 diff --git a/include/svx/CommonStylePreviewRenderer.hxx b/include/svx/CommonStylePreviewRenderer.hxx index 1e7d54e..49717b5 100644 --- a/include/svx/CommonStylePreviewRenderer.hxx +++ b/include/svx/CommonStylePreviewRenderer.hxx @@ -35,7 +35,7 @@ public: virtual bool recalculate() SAL_OVERRIDE; virtual Size getRenderSize() SAL_OVERRIDE; - virtual bool render(const Rectangle& aRectangle) SAL_OVERRIDE; + virtual bool render(const Rectangle& aRectangle, RenderAlign eRenderAlign = RenderAlign::CENTER) SAL_OVERRIDE; }; } // end namespace svx diff --git a/svx/source/styles/CommonStylePreviewRenderer.cxx b/svx/source/styles/CommonStylePreviewRenderer.cxx index ab1271a..2d9ac3f 100644 --- a/svx/source/styles/CommonStylePreviewRenderer.cxx +++ b/svx/source/styles/CommonStylePreviewRenderer.cxx @@ -174,8 +174,10 @@ Size CommonStylePreviewRenderer::getRenderSize() return maPixelSize; } -bool CommonStylePreviewRenderer::render(const Rectangle& aRectangle) +bool CommonStylePreviewRenderer::render(const Rectangle& aRectangle, RenderAlign eRenderAlign) { + const OUString& rText = msRenderText.isEmpty() ? maStyleName : msRenderText; + // setup the device & draw vcl::Font aOldFont(mrOutputDev.GetFont()); Color aOldColor(mrOutputDev.GetTextColor()); @@ -192,10 +194,18 @@ bool CommonStylePreviewRenderer::render(const Rectangle& aRectangle) mrOutputDev.SetTextColor(maFontColor); Point aFontDrawPosition = aRectangle.TopLeft(); - if (aRectangle.GetHeight() > maPixelSize.Height()) - aFontDrawPosition.Y() += ( aRectangle.GetHeight() - maPixelSize.Height() ) / 2; + if (eRenderAlign == RenderAlign::CENTER) + { + if (aRectangle.GetHeight() > maPixelSize.Height()) + aFontDrawPosition.Y() += (aRectangle.GetHeight() - maPixelSize.Height()) / 2; + } + else if (eRenderAlign == RenderAlign::BOTTOM) + { + if (aRectangle.GetHeight() > maPixelSize.Height()) + aFontDrawPosition.Y() += aRectangle.GetHeight() - maPixelSize.Height(); + } - mrOutputDev.DrawText(aFontDrawPosition, maStyleName); + mrOutputDev.DrawText(aFontDrawPosition, rText); mrOutputDev.SetFillColor(aOldFillColor); mrOutputDev.SetTextColor(aOldColor); diff --git a/sw/source/uibase/sidebar/StylePresetsPanel.cxx b/sw/source/uibase/sidebar/StylePresetsPanel.cxx index 7a4dbfc..957f050 100644 --- a/sw/source/uibase/sidebar/StylePresetsPanel.cxx +++ b/sw/source/uibase/sidebar/StylePresetsPanel.cxx @@ -63,14 +63,18 @@ StylePresetsPanel::StylePresetsPanel(vcl::Window* pParent, : PanelLayout(pParent, "StylePresetsPanel", "modules/swriter/ui/sidebarstylepresets.ui", rxFrame) , mpBindings(pBindings) { + get(mpValueSet, "valueset"); - get(mpListBox, "listbox"); + mpValueSet->SetColCount(2); - mpListBox->SetDoubleClickHdl(LINK(this, StylePresetsPanel, DoubleClickHdl)); + mpValueSet->SetDoubleClickHdl(LINK(this, StylePresetsPanel, DoubleClickHdl)); + RefreshList(); +} +void StylePresetsPanel::RefreshList() +{ SfxDocumentTemplates aTemplates; - sal_uInt16 nCount = aTemplates.GetRegionCount(); for (sal_uInt16 i = 0; i < nCount; ++i) { @@ -81,14 +85,112 @@ StylePresetsPanel::StylePresetsPanel(vcl::Window* pParent, { OUString aName = aTemplates.GetName(i,j); OUString aURL = aTemplates.GetPath(i,j); - sal_Int32 nIndex = mpListBox->InsertEntry(aName); + BitmapEx aPreview = CreatePreview(aURL, aName); + mpValueSet->InsertItem(j, Image(aPreview), aName); maTemplateEntries.push_back(std::unique_ptr<TemplateEntry>(new TemplateEntry(aName, aURL))); - mpListBox->SetEntryData(nIndex, maTemplateEntries.back().get()); + mpValueSet->SetItemData(j, maTemplateEntries.back().get()); } } } } +BitmapEx StylePresetsPanel::CreatePreview(OUString& aUrl, OUString& aName) +{ + SfxMedium aMedium(aUrl, STREAM_STD_READWRITE); + SfxObjectShell* pObjectShell = SfxObjectShell::Current(); + SfxObjectShellLock xTemplDoc = pObjectShell->CreateObjectByFactoryName(pObjectShell->GetFactory().GetFactoryName(), SfxObjectCreateMode::ORGANIZER); + xTemplDoc->DoInitNew(0); + if (xTemplDoc->LoadFrom(aMedium)) + { + return GenerateStylePreview(*xTemplDoc, aName); + } + return BitmapEx(); +} + +void renderPreview(sfx2::StyleManager* pStyleManager, OutputDevice& aOutputDevice, + OUString sName, sal_Int32 nHeight, Rectangle& aRect) +{ + sfx2::StylePreviewRenderer* pStylePreviewRenderer; + + SfxStyleSheetBase* pStyleSheet = pStyleManager->Search(sName, SFX_STYLE_FAMILY_PARA); + + if (pStyleSheet) + { + pStylePreviewRenderer = pStyleManager->CreateStylePreviewRenderer(aOutputDevice, pStyleSheet, nHeight); + pStylePreviewRenderer->recalculate(); + pStylePreviewRenderer->render(aRect, sfx2::StylePreviewRenderer::RenderAlign::TOP); + } +} + +BitmapEx StylePresetsPanel::GenerateStylePreview(SfxObjectShell& rSource, OUString& aName) +{ + sfx2::StyleManager* pStyleManager = rSource.GetStyleManager(); + + ScopedVclPtrInstance<VirtualDevice> pVirtualDev(*Application::GetDefaultDevice()); + + sal_Int32 nScalingFactor = pVirtualDev->GetDPIScaleFactor(); + + sal_Int32 nMargin = 6 * nScalingFactor; + + sal_Int32 nPreviewWidth = 144 * nScalingFactor; + + sal_Int32 nNameHeight = 16 * nScalingFactor; + sal_Int32 nTitleHeight = 32 * nScalingFactor; + sal_Int32 nHeadingHeight = 24 * nScalingFactor; + sal_Int32 nTextBodyHeight = 16 * nScalingFactor; + sal_Int32 nBottomMargin = 2 * nScalingFactor; + + sal_Int32 nNameFontSize = 12 * nScalingFactor; + + sal_Int32 nPreviewHeight = nNameHeight + nTitleHeight + nHeadingHeight + nTextBodyHeight + nBottomMargin; + + Size aSize(nPreviewWidth, nPreviewHeight); + + pVirtualDev->SetOutputSizePixel(aSize); + + pVirtualDev->SetLineColor(COL_LIGHTGRAY); + pVirtualDev->SetFillColor(); + + long y = 0; + { + pVirtualDev->SetFillColor(COL_LIGHTGRAY); + Rectangle aNameRect(0, y, nPreviewWidth, nNameHeight); + pVirtualDev->DrawRect(aNameRect); + + vcl::Font aFont; + aFont.SetSize(Size(0, nNameFontSize)); + + pVirtualDev->SetFont(aFont); + + Size aTextSize(pVirtualDev->GetTextWidth(aName), pVirtualDev->GetTextHeight()); + + Point aPoint((aNameRect.GetWidth() / 2.0) - (aTextSize.Width() / 2.0), + y + (aNameRect.GetHeight() / 2.0) - (aTextSize.Height() / 2.0)); + + pVirtualDev->DrawText(aPoint, aName); + + y += nNameHeight; + } + + { + Rectangle aRenderRect(Point(nMargin, y), aSize); + renderPreview(pStyleManager, *pVirtualDev.get(), "Title", nTitleHeight, aRenderRect); + y += nTitleHeight; + } + + { + Rectangle aRenderRect(Point(nMargin, y), aSize); + renderPreview(pStyleManager, *pVirtualDev.get(), "Heading 1", nHeadingHeight, aRenderRect); + y += nHeadingHeight; + } + { + Rectangle aRenderRect(Point(nMargin, y), aSize); + renderPreview(pStyleManager, *pVirtualDev.get(), "Text Body", nTextBodyHeight, aRenderRect); + } + + return pVirtualDev->GetBitmapEx(Point(), aSize); +} + StylePresetsPanel::~StylePresetsPanel() { disposeOnce(); @@ -96,15 +198,15 @@ StylePresetsPanel::~StylePresetsPanel() void StylePresetsPanel::dispose() { - mpListBox.disposeAndClear(); + mpValueSet.disposeAndClear(); PanelLayout::dispose(); } IMPL_LINK_NOARG(StylePresetsPanel, DoubleClickHdl) { - sal_Int32 nIndex = mpListBox->GetSelectEntryPos(); - TemplateEntry* pEntry = static_cast<TemplateEntry*>(mpListBox->GetEntryData(nIndex)); + sal_Int32 nItemId = mpValueSet->GetSelectItemId(); + TemplateEntry* pEntry = static_cast<TemplateEntry*>(mpValueSet->GetItemData(nItemId)); SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current()); if (pDocSh) @@ -115,7 +217,7 @@ IMPL_LINK_NOARG(StylePresetsPanel, DoubleClickHdl) pDocSh->LoadStylesFromFile(pEntry->maURL, aOption, false); } - return 1; + return 0; } void StylePresetsPanel::NotifyItemUpdate(const sal_uInt16 /*nSId*/, diff --git a/sw/source/uibase/sidebar/StylePresetsPanel.hxx b/sw/source/uibase/sidebar/StylePresetsPanel.hxx index dd2a7c7..fd51cf41 100644 --- a/sw/source/uibase/sidebar/StylePresetsPanel.hxx +++ b/sw/source/uibase/sidebar/StylePresetsPanel.hxx @@ -19,6 +19,8 @@ #include <sfx2/sidebar/ControllerItem.hxx> +#include <sfx2/objsh.hxx> + #include <svx/pageitem.hxx> #include <svx/rulritem.hxx> #include <editeng/sizeitem.hxx> @@ -32,6 +34,8 @@ #include <svl/intitem.hxx> #include <svl/lstner.hxx> +#include <svtools/valueset.hxx> + #include <svx/fntctrl.hxx> #include "docstyle.hxx" @@ -64,6 +68,10 @@ private: OUString maURL; }; + void RefreshList(); + BitmapEx CreatePreview(OUString& aUrl, OUString& aName); + BitmapEx GenerateStylePreview(SfxObjectShell& rSource, OUString& aName); + StylePresetsPanel(vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& rxFrame, SfxBindings* pBindings); @@ -73,7 +81,7 @@ private: SfxBindings* mpBindings; - VclPtr<ListBox> mpListBox; + VclPtr<ValueSet> mpValueSet; std::vector<std::unique_ptr<TemplateEntry>> maTemplateEntries; diff --git a/sw/uiconfig/swriter/ui/sidebarstylepresets.ui b/sw/uiconfig/swriter/ui/sidebarstylepresets.ui index 071e9e5..fc64564 100644 --- a/sw/uiconfig/swriter/ui/sidebarstylepresets.ui +++ b/sw/uiconfig/swriter/ui/sidebarstylepresets.ui @@ -2,6 +2,7 @@ <!-- Generated with glade 3.18.3 --> <interface> <requires lib="gtk+" version="3.0"/> + <requires lib="LibreOffice" version="1.0"/> <object class="GtkGrid" id="StylePresetsPanel"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -31,6 +32,16 @@ <property name="top_attach">0</property> </packing> </child> + <child> + <object class="svtlo-ValueSet" id="valueset"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + </packing> + </child> </object> </child> </object> commit a0ab7c31a254285856f6520d069570647c56af22 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Wed May 27 12:20:49 2015 +0900 Again add ability to change tint/shade of a color + unit test Change-Id: I4c06290f09e5bfecd2c1de896e19cb5036a3a0e9 diff --git a/include/tools/color.hxx b/include/tools/color.hxx index f940dbc..00c89e2 100644 --- a/include/tools/color.hxx +++ b/include/tools/color.hxx @@ -163,6 +163,16 @@ public: void DecreaseContrast(sal_uInt8 cContDec); + /** + * Apply tint or shade to a color. + * + * The input value is the percentage (in 100th of percent) of how much the + * color changes towards the black (shade) or white (tint). If the value + * is positive, the color is tinted, if the value is negative, the color is + * shaded. + **/ + void ApplyTintOrShade(sal_Int16 n100thPercent); + void Invert(); void Merge(const Color& rMergeColor, sal_uInt8 cTransparency); diff --git a/tools/qa/cppunit/test_color.cxx b/tools/qa/cppunit/test_color.cxx index 99f311f..aeab12a 100644 --- a/tools/qa/cppunit/test_color.cxx +++ b/tools/qa/cppunit/test_color.cxx @@ -23,10 +23,12 @@ class Test: public CppUnit::TestFixture public: void test_asRGBColor(); void test_readAndWriteStream(); + void test_ApplyTintOrShade(); CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(test_asRGBColor); CPPUNIT_TEST(test_readAndWriteStream); + CPPUNIT_TEST(test_ApplyTintOrShade); CPPUNIT_TEST_SUITE_END(); }; @@ -76,6 +78,64 @@ void Test::test_readAndWriteStream() } } +bool checkTintShade(sal_uInt8 nR, sal_uInt8 nG, sal_uInt8 nB, OUString sReference, sal_Int16 nTintShade, OUString sExpected) +{ + Color aColor(nR, nG, nB); + if (sReference != aColor.AsRGBHexString()) + return false; + aColor.ApplyTintOrShade(nTintShade); + return sExpected == aColor.AsRGBHexString(); +} + +void Test::test_ApplyTintOrShade() +{ + // BLACK reference + + // 5% tint + CPPUNIT_ASSERT(checkTintShade(0x00, 0x00, 0x00, "000000", 500, "0d0d0d")); + // 15% tint + CPPUNIT_ASSERT(checkTintShade(0x00, 0x00, 0x00, "000000", 1500, "262626")); + // 25% tint + CPPUNIT_ASSERT(checkTintShade(0x00, 0x00, 0x00, "000000", 2500, "404040")); + // 50% tint + CPPUNIT_ASSERT(checkTintShade(0x00, 0x00, 0x00, "000000", 5000, "808080")); + // 100% tint + CPPUNIT_ASSERT(checkTintShade(0x00, 0x00, 0x00, "000000", 10000, "ffffff")); + + // WHITE reference + + // 5% shade + CPPUNIT_ASSERT(checkTintShade(0xff, 0xff, 0xff, "ffffff", -500, "f2f2f2")); + // 15% shade + CPPUNIT_ASSERT(checkTintShade(0xff, 0xff, 0xff, "ffffff", -1500, "d9d9d9")); + // 25% shade + CPPUNIT_ASSERT(checkTintShade(0xff, 0xff, 0xff, "ffffff", -2500, "bfbfbf")); + // 50% shade + CPPUNIT_ASSERT(checkTintShade(0xff, 0xff, 0xff, "ffffff", -5000, "808080")); + // 100% shade + CPPUNIT_ASSERT(checkTintShade(0xff, 0xff, 0xff, "ffffff", -10000, "000000")); + + // GREY reference + + // 0% - no change + CPPUNIT_ASSERT(checkTintShade(0x80, 0x80, 0x80, "808080", 0, "808080")); + + // 25% tint + CPPUNIT_ASSERT(checkTintShade(0x80, 0x80, 0x80, "808080", 2500, "a0a0a0")); + // 50% tint + CPPUNIT_ASSERT(checkTintShade(0x80, 0x80, 0x80, "808080", 5000, "c0c0c0")); + // 100% tint + CPPUNIT_ASSERT(checkTintShade(0x80, 0x80, 0x80, "808080", 10000, "ffffff")); + + // 25% shade + CPPUNIT_ASSERT(checkTintShade(0x80, 0x80, 0x80, "808080", -2500, "606060")); + // 50% shade + CPPUNIT_ASSERT(checkTintShade(0x80, 0x80, 0x80, "808080", -5000, "404040")); + // 100% shade + CPPUNIT_ASSERT(checkTintShade(0x80, 0x80, 0x80, "808080", -10000, "000000")); + +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); } diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx index 07fdd00..4ab32d4 100644 --- a/tools/source/generic/color.cxx +++ b/tools/source/generic/color.cxx @@ -312,6 +312,32 @@ SvStream& ReadColor( SvStream& rIStream, Color& rColor ) return rIStream; } +void Color::ApplyTintOrShade(sal_Int16 n100thPercent) +{ + if (n100thPercent == 0) + return; + + basegfx::BColor aBColor = basegfx::tools::rgb2hsl(getBColor()); + double fFactor = 1.0 - (std::abs(double(n100thPercent)) / 10000.0); + double fResult; + + if (n100thPercent > 0) // tint + { + fResult = aBColor.getBlue() * fFactor + (1.0 - fFactor); + } + else if (n100thPercent < 0) // shade + { + fResult = aBColor.getBlue() * fFactor; + } + + aBColor.setBlue(fResult); + aBColor = basegfx::tools::hsl2rgb(aBColor); + + SetRed(sal_uInt8(( aBColor.getRed() * 255.0) + 0.5)); + SetGreen(sal_uInt8((aBColor.getGreen() * 255.0) + 0.5)); + SetBlue(sal_uInt8(( aBColor.getBlue() * 255.0) + 0.5)); +} + SvStream& WriteColor( SvStream& rOStream, const Color& rColor ) { DBG_ASSERTWARNING( rOStream.GetVersion(), "Color::<< - Solar-Version not set on rOStream" ); commit bba73f9e0f286f48fe02f7e232c53de79fc5f12c Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Fri Jul 31 19:59:20 2015 +0900 get rid of the macro here Change-Id: I1ba5583d9121b541b6b76588f1334980abe3836e diff --git a/svx/source/xoutdev/xtable.cxx b/svx/source/xoutdev/xtable.cxx index b3f1416d..02ad986 100644 --- a/svx/source/xoutdev/xtable.cxx +++ b/svx/source/xoutdev/xtable.cxx @@ -308,27 +308,36 @@ bool XPropertyList::SaveTo( const uno::Reference< embed::XStorage > &xStorage, return SvxXMLXTableExportComponent::save( rURL, createInstance(), xStorage, pOptName ); } -XPropertyListRef XPropertyList::CreatePropertyList( XPropertyListType t, +XPropertyListRef XPropertyList::CreatePropertyList( XPropertyListType aType, const OUString& rPath, const OUString& rReferer ) { XPropertyListRef pRet; -#define MAP(e,c) \ - case e: pRet = XPropertyListRef (new c( rPath, rReferer ) ); break - switch (t) { - MAP( XCOLOR_LIST, XColorList ); - MAP( XLINE_END_LIST, XLineEndList ); - MAP( XDASH_LIST, XDashList ); - MAP( XHATCH_LIST, XHatchList ); - MAP( XGRADIENT_LIST, XGradientList ); - MAP( XBITMAP_LIST, XBitmapList ); + switch (aType) { + case XCOLOR_LIST: + pRet = XPropertyListRef(new XColorList(rPath, rReferer)); + break; + case XLINE_END_LIST: + pRet = XPropertyListRef(new XLineEndList(rPath, rReferer)); + break; + case XDASH_LIST: + pRet = XPropertyListRef(new XDashList(rPath, rReferer)); + break; + case XHATCH_LIST: + pRet = XPropertyListRef(new XHatchList(rPath, rReferer)); + break; + case XGRADIENT_LIST: + pRet = XPropertyListRef(new XGradientList(rPath, rReferer)); + break; + case XBITMAP_LIST: + pRet = XPropertyListRef(new XBitmapList(rPath, rReferer)); + break; default: OSL_FAIL("unknown xproperty type"); break; } -#undef MAP - OSL_ASSERT( !pRet.is() || pRet->meType == t ); + OSL_ASSERT( !pRet.is() || pRet->meType == aType ); return pRet; }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits