sw: Use weld::IconView in ThemePanel
Replace the use of a custom ValueSet subclass
ThemeColorValueSet to display the themes to choose
with a more standard weld::IconView.
Besides reducing custom logic, it also ensures
that theming/styling adheres better to the rest
of the application, e.g. the way that the currently
selected theme in the sidebar is highlighted.
In this case, it also makes sure that actually
all themes are shown: Previously, only 6 of them
instead of all 7 were displayed, due to hard-coding
the number of rows and columns in the ThemePanel ctor
mxValueSetColors->SetColCount(2);
mxValueSetColors->SetLineCount(3);
Now, all 7 themes are shown and can be selected.
The newly introduced helper method ThemePanel::CreateImage
mostly takes over the existing logic from the (now dropped)
ThemeColorValueSet::UserDraw.
Drop the now no longer used ThemeColorValueSet.
An upcoming commit will also set accessible
names for the themes, which wasn't previously
done either.
The theme panel can be reached as follows:
* start Writer
* in "Tools" -> "Options" -> "Advanced", enable
"Enable experimental features (may be unstable)",
press "OK" button, restart LO to apply those changes
* open the "Design" sidebar panel in Writer
The list of theme colors in the "Themes" section
is the one that was switched to weld::IconView
by this commit.
The "Format" -> "Themes" dialog shows the same
set of color themes and can also be used while testing
that a change to the color theme in the sidebar
was actually applied as expected.
Change-Id: I77b7b12d0087eac8afeb88d4847a95ed268bfc5f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195324
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
This commit is contained in:
@@ -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 <svx/svxdllapi.h>
|
||||
#include <sal/config.h>
|
||||
#include <svtools/valueset.hxx>
|
||||
#include <docmodel/theme/ColorSet.hxx>
|
||||
|
||||
namespace svx
|
||||
{
|
||||
class SVX_DLLPUBLIC ThemeColorValueSet final : public ValueSet
|
||||
{
|
||||
std::vector<std::reference_wrapper<const model::ColorSet>> 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: */
|
||||
@@ -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 \
|
||||
|
||||
@@ -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 <svx/dialog/ThemeColorValueSet.hxx>
|
||||
#include <vcl/event.hxx>
|
||||
|
||||
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: */
|
||||
@@ -18,9 +18,9 @@
|
||||
#include <ThemeColorChanger.hxx>
|
||||
#include <vcl/settings.hxx>
|
||||
#include <vcl/svapp.hxx>
|
||||
#include <vcl/virdev.hxx>
|
||||
#include <docmodel/theme/Theme.hxx>
|
||||
#include <svx/svdpage.hxx>
|
||||
#include <svx/dialog/ThemeColorValueSet.hxx>
|
||||
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
||||
|
||||
namespace sw::sidebar
|
||||
@@ -36,33 +36,28 @@ std::unique_ptr<PanelLayout> 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<VirtualDevice> 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<VirtualDevice> 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<VirtualDevice> 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);
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#include <svtools/valueset.hxx>
|
||||
#include <svx/ColorSets.hxx>
|
||||
|
||||
namespace svx { class ThemeColorValueSet; }
|
||||
|
||||
namespace sw::sidebar
|
||||
{
|
||||
|
||||
@@ -38,14 +36,14 @@ public:
|
||||
boost::property_tree::ptree& /*rState*/) override {};
|
||||
|
||||
private:
|
||||
std::unique_ptr<svx::ThemeColorValueSet> mxValueSetColors;
|
||||
std::unique_ptr<weld::CustomWeld> mxValueSetColorsWin;
|
||||
std::unique_ptr<weld::IconView> mxIconViewColors;
|
||||
std::unique_ptr<weld::Button> mxApplyButton;
|
||||
|
||||
DECL_LINK(ClickHdl, weld::Button&, void);
|
||||
DECL_LINK(ItemActivatedHdl, weld::IconView&, bool);
|
||||
DECL_LINK(DoubleClickValueSetHdl, ValueSet*, void);
|
||||
void DoubleClickHdl();
|
||||
|
||||
VclPtr<VirtualDevice> CreateImage(const model::ColorSet& rColorSet);
|
||||
};
|
||||
|
||||
} // end of namespace sw::sidebar
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
<!-- Generated with glade 3.40.0 -->
|
||||
<interface domain="sw">
|
||||
<requires lib="gtk+" version="3.24"/>
|
||||
<object class="GtkTreeStore" id="colorsliststore">
|
||||
<columns>
|
||||
<!-- column-name pixbuf -->
|
||||
<column type="GdkPixbuf"/>
|
||||
<!-- column-name id -->
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
<!-- n-columns=1 n-rows=3 -->
|
||||
<object class="GtkGrid" id="ThemePanel">
|
||||
<property name="visible">True</property>
|
||||
@@ -14,7 +22,7 @@
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes" context="sidebartheme|label2">Colors</property>
|
||||
<property name="use-underline">True</property>
|
||||
<property name="mnemonic-widget">valueset_colors</property>
|
||||
<property name="mnemonic-widget">iconview_colors</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
@@ -36,29 +44,13 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="valuesetwin">
|
||||
<object class="GtkIconView" id="iconview_colors">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="hscrollbar-policy">never</property>
|
||||
<property name="vscrollbar-policy">never</property>
|
||||
<property name="shadow-type">in</property>
|
||||
<child>
|
||||
<object class="GtkViewport">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkDrawingArea" id="valueset_colors">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_STRUCTURE_MASK</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<property name="margin">6</property>
|
||||
<property name="model">colorsliststore</property>
|
||||
<property name="pixbuf-column">0</property>
|
||||
<property name="columns">2</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
|
||||
Reference in New Issue
Block a user