diff --git a/include/svx/dialog/ThemeColorValueSet.hxx b/include/svx/dialog/ThemeColorValueSet.hxx deleted file mode 100644 index ee73275c4d41..000000000000 --- a/include/svx/dialog/ThemeColorValueSet.hxx +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- 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/. - */ - -#pragma once - -#include -#include -#include -#include - -namespace svx -{ -class SVX_DLLPUBLIC ThemeColorValueSet final : public ValueSet -{ - std::vector> maColorSets; - -public: - ThemeColorValueSet() - : ValueSet(nullptr) - { - } - - void SetDrawingArea(weld::DrawingArea* pDrawingArea) override; - void UserDraw(const UserDrawEvent& rUserDrawEvent) override; - void StyleUpdated() override; - - void insert(model::ColorSet const& rColorSet); -}; - -} // end svx namespace - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk index e0fe649db132..677522593a25 100644 --- a/svx/Library_svx.mk +++ b/svx/Library_svx.mk @@ -176,7 +176,6 @@ $(eval $(call gb_Library_add_exception_objects,svx,\ svx/source/dialog/svxruler \ svx/source/dialog/swframeexample \ svx/source/dialog/swframeposstrings \ - svx/source/dialog/ThemeColorValueSet \ svx/source/dialog/ThemeDialog \ svx/source/dialog/ThemeColorEditDialog \ svx/source/dialog/txencbox \ diff --git a/svx/source/dialog/ThemeColorValueSet.cxx b/svx/source/dialog/ThemeColorValueSet.cxx deleted file mode 100644 index b63703e27c10..000000000000 --- a/svx/source/dialog/ThemeColorValueSet.cxx +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- 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 -#include - -namespace svx -{ -constexpr tools::Long BORDER = 4; -constexpr tools::Long SIZE = 16; -constexpr tools::Long LABEL_HEIGHT = 16; -constexpr tools::Long LABEL_TEXT_HEIGHT = 14; -constexpr tools::Long constElementNumber = 8; - -void ThemeColorValueSet::insert(model::ColorSet const& rColorSet) -{ - maColorSets.push_back(std::cref(rColorSet)); - InsertItem(maColorSets.size()); -} - -void ThemeColorValueSet::SetDrawingArea(weld::DrawingArea* pDrawingArea) -{ - ValueSet::SetDrawingArea(pDrawingArea); - SetStyle(WB_TABSTOP | WB_ITEMBORDER | WB_DOUBLEBORDER); - Size aSize(BORDER * 7 + SIZE * 6 + BORDER * 2, BORDER * 3 + SIZE * 2 + LABEL_HEIGHT); - SetItemWidth(aSize.Width()); - SetItemHeight(aSize.Height()); -} - -void ThemeColorValueSet::UserDraw(const UserDrawEvent& rUserDrawEvent) -{ - vcl::RenderContext* pDev = rUserDrawEvent.GetRenderContext(); - tools::Rectangle aRect = rUserDrawEvent.GetRect(); - const Point aPosition = aRect.GetPos(); - const sal_uInt16 nItemId = rUserDrawEvent.GetItemId(); - model::ColorSet const& rColorSet = maColorSets[nItemId - 1]; - - Size aSize = aRect.GetSize(); - Size aMin(BORDER * 7 + SIZE * constElementNumber / 2 + BORDER * 2, - BORDER * 3 + SIZE * 2 + LABEL_HEIGHT); - tools::Long startX = (aSize.Width() / 2.0) - (aMin.Width() / 2.0); - tools::Long x = BORDER; - tools::Long y1 = BORDER + LABEL_HEIGHT; - tools::Long y2 = y1 + SIZE + BORDER; - - pDev->SetLineColor(COL_LIGHTGRAY); - pDev->SetFillColor(COL_LIGHTGRAY); - tools::Rectangle aNameRect(aPosition, Size(aSize.Width(), LABEL_HEIGHT)); - pDev->DrawRect(aNameRect); - - vcl::Font aFont; - OUString aName = rColorSet.getName(); - aFont.SetFontHeight(LABEL_TEXT_HEIGHT); - pDev->SetFont(aFont); - - Size aTextSize(pDev->GetTextWidth(aName), pDev->GetTextHeight()); - - Point aPoint(aPosition.X() + (aNameRect.GetWidth() / 2.0) - (aTextSize.Width() / 2.0), - aPosition.Y() + (aNameRect.GetHeight() / 2.0) - (aTextSize.Height() / 2.0)); - - pDev->DrawText(aPoint, aName); - - pDev->SetLineColor(COL_LIGHTGRAY); - pDev->SetFillColor(); - - for (sal_uInt32 i = 2; i < 10; i += 2) - { - pDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i))); - pDev->DrawRect(tools::Rectangle(Point(aPosition.X() + x + startX, aPosition.Y() + y1), - Size(SIZE, SIZE))); - - pDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i + 1))); - pDev->DrawRect(tools::Rectangle(Point(aPosition.X() + x + startX, aPosition.Y() + y2), - Size(SIZE, SIZE))); - - x += SIZE + BORDER; - if (i == 2 || i == 8) - x += BORDER; - } -} - -void ThemeColorValueSet::StyleUpdated() -{ - SetFormat(); - Invalidate(); - ValueSet::StyleUpdated(); -} - -} // end svx namespace - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx b/sw/source/uibase/sidebar/ThemePanel.cxx index 690906b1893c..0a7170a447d1 100644 --- a/sw/source/uibase/sidebar/ThemePanel.cxx +++ b/sw/source/uibase/sidebar/ThemePanel.cxx @@ -18,9 +18,9 @@ #include #include #include +#include #include #include -#include #include namespace sw::sidebar @@ -36,33 +36,28 @@ std::unique_ptr ThemePanel::Create(weld::Widget* pParent) ThemePanel::ThemePanel(weld::Widget* pParent) : PanelLayout(pParent, u"ThemePanel"_ustr, u"modules/swriter/ui/sidebartheme.ui"_ustr) - , mxValueSetColors(new svx::ThemeColorValueSet) - , mxValueSetColorsWin(new weld::CustomWeld(*m_xBuilder, u"valueset_colors"_ustr, *mxValueSetColors)) + , mxIconViewColors(m_xBuilder->weld_icon_view(u"iconview_colors"_ustr)) , mxApplyButton(m_xBuilder->weld_button(u"apply"_ustr)) { - mxValueSetColors->SetColCount(2); - mxValueSetColors->SetLineCount(3); - mxValueSetColors->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor()); - mxApplyButton->connect_clicked(LINK(this, ThemePanel, ClickHdl)); - mxValueSetColors->SetDoubleClickHdl(LINK(this, ThemePanel, DoubleClickValueSetHdl)); + mxIconViewColors->connect_item_activated(LINK(this, ThemePanel, ItemActivatedHdl)); auto const& rColorSets = svx::ColorSets::get(); for (model::ColorSet const& rColorSet : rColorSets.getColorSetVector()) { - mxValueSetColors->insert(rColorSet); + ScopedVclPtr pDev = CreateImage(rColorSet); + const Bitmap aBitmap = pDev->GetBitmap(Point(0, 0), pDev->GetOutputSize()); + const int nIndex = mxIconViewColors->n_children(); + const OUString sId = OUString::number(nIndex); + mxIconViewColors->insert(nIndex, nullptr, &sId, &aBitmap, nullptr); } - mxValueSetColors->SetOptimalSize(); - if (!rColorSets.getColorSetVector().empty()) - mxValueSetColors->SelectItem(1); // ItemId 1, position 0 + mxIconViewColors->select(0); } ThemePanel::~ThemePanel() { - mxValueSetColorsWin.reset(); - mxValueSetColors.reset(); mxApplyButton.reset(); } @@ -71,9 +66,66 @@ IMPL_LINK_NOARG(ThemePanel, ClickHdl, weld::Button&, void) DoubleClickHdl(); } -IMPL_LINK_NOARG(ThemePanel, DoubleClickValueSetHdl, ValueSet*, void) +IMPL_LINK_NOARG(ThemePanel, ItemActivatedHdl, weld::IconView&, bool) { DoubleClickHdl(); + return true; +} + +VclPtr ThemePanel::CreateImage(const model::ColorSet& rColorSet) +{ + constexpr tools::Long BORDER = 4; + constexpr tools::Long SIZE = 16; + constexpr tools::Long LABEL_HEIGHT = 16; + constexpr tools::Long LABEL_TEXT_HEIGHT = 14; + constexpr tools::Long constElementNumber = 8; + + const Size aMin(BORDER * 7 + SIZE * constElementNumber / 2 + BORDER * 2, + BORDER * 3 + SIZE * 2 + LABEL_HEIGHT); + + const Size aSize(aMin.Width() + 40, aMin.Height()); + VclPtr pDev = mxIconViewColors->create_virtual_device(); + pDev->SetOutputSizePixel(aSize); + + tools::Long startX = (aSize.Width() / 2.0) - (aMin.Width() / 2.0); + tools::Long x = BORDER; + tools::Long y1 = BORDER + LABEL_HEIGHT; + tools::Long y2 = y1 + SIZE + BORDER; + + pDev->SetLineColor(COL_LIGHTGRAY); + pDev->SetFillColor(COL_LIGHTGRAY); + tools::Rectangle aNameRect(Point(0, 0), Size(aSize.Width(), LABEL_HEIGHT)); + pDev->DrawRect(aNameRect); + + vcl::Font aFont; + OUString aName = rColorSet.getName(); + aFont.SetFontHeight(LABEL_TEXT_HEIGHT); + pDev->SetFont(aFont); + + Size aTextSize(pDev->GetTextWidth(aName), pDev->GetTextHeight()); + + Point aPoint((aNameRect.GetWidth() / 2.0) - (aTextSize.Width() / 2.0), + (aNameRect.GetHeight() / 2.0) - (aTextSize.Height() / 2.0)); + + pDev->DrawText(aPoint, aName); + + pDev->SetLineColor(COL_LIGHTGRAY); + pDev->SetFillColor(); + + for (sal_uInt32 i = 2; i < 10; i += 2) + { + pDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i))); + pDev->DrawRect(tools::Rectangle(Point(x + startX, y1), Size(SIZE, SIZE))); + + pDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i + 1))); + pDev->DrawRect(tools::Rectangle(Point(x + startX, y2), Size(SIZE, SIZE))); + + x += SIZE + BORDER; + if (i == 2 || i == 8) + x += BORDER; + } + + return pDev; } void ThemePanel::DoubleClickHdl() @@ -82,10 +134,10 @@ void ThemePanel::DoubleClickHdl() if (!pDocSh) return; - sal_uInt32 nItemId = mxValueSetColors->GetSelectedItemId(); - if (!nItemId) + const OUString sId = mxIconViewColors->get_selected_id(); + if (sId.isEmpty()) return; - sal_uInt32 nIndex = nItemId - 1; + const sal_uInt32 nIndex = sId.toUInt32(); auto const& rColorSets = svx::ColorSets::get(); model::ColorSet const& rColorSet = rColorSets.getColorSet(nIndex); diff --git a/sw/source/uibase/sidebar/ThemePanel.hxx b/sw/source/uibase/sidebar/ThemePanel.hxx index e536faaf3858..513778525f67 100644 --- a/sw/source/uibase/sidebar/ThemePanel.hxx +++ b/sw/source/uibase/sidebar/ThemePanel.hxx @@ -15,8 +15,6 @@ #include #include -namespace svx { class ThemeColorValueSet; } - namespace sw::sidebar { @@ -38,14 +36,14 @@ public: boost::property_tree::ptree& /*rState*/) override {}; private: - std::unique_ptr mxValueSetColors; - std::unique_ptr mxValueSetColorsWin; + std::unique_ptr mxIconViewColors; std::unique_ptr mxApplyButton; DECL_LINK(ClickHdl, weld::Button&, void); + DECL_LINK(ItemActivatedHdl, weld::IconView&, bool); DECL_LINK(DoubleClickValueSetHdl, ValueSet*, void); void DoubleClickHdl(); - + VclPtr CreateImage(const model::ColorSet& rColorSet); }; } // end of namespace sw::sidebar diff --git a/sw/uiconfig/swriter/ui/sidebartheme.ui b/sw/uiconfig/swriter/ui/sidebartheme.ui index dd464e0c259e..ed0cc6603d83 100644 --- a/sw/uiconfig/swriter/ui/sidebartheme.ui +++ b/sw/uiconfig/swriter/ui/sidebartheme.ui @@ -2,6 +2,14 @@ + + + + + + + + True @@ -14,7 +22,7 @@ False Colors True - valueset_colors + iconview_colors 0 @@ -36,29 +44,13 @@ - + True True - True - True - never - never - in - - - True - False - - - True - True - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_STRUCTURE_MASK - True - True - - - - + 6 + colorsliststore + 0 + 2 0