summaryrefslogtreecommitdiff
path: root/svx/source
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2021-02-02 16:12:55 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2021-02-11 18:50:48 +0100
commitfd9b52502de6044a2249ff81407ac579a35ad3a1 (patch)
tree131722a0c23bb9eaa55e22eb5cab841429a6012e /svx/source
parentb11db88d0174fbad25f7ee04726ae27ceb1488c3 (diff)
tdf#139429 Convert Style previews widget to IconView
- this adds labels to easily identify the styles - easier to work with many styles - nice native widget in gtk3 - double click opens the style settings - added Command callback fro iconview Change-Id: I08743515cbd2a4e4bd592d1509e48bbe2a43b129 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110408 Tested-by: Jenkins Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'svx/source')
-rw-r--r--svx/source/inc/StylesPreviewWindow.hxx30
-rw-r--r--svx/source/tbxctrls/StylesPreviewWindow.cxx197
2 files changed, 74 insertions, 153 deletions
diff --git a/svx/source/inc/StylesPreviewWindow.hxx b/svx/source/inc/StylesPreviewWindow.hxx
index 9e90c4d36288..416c8a15a63f 100644
--- a/svx/source/inc/StylesPreviewWindow.hxx
+++ b/svx/source/inc/StylesPreviewWindow.hxx
@@ -40,24 +40,17 @@ public:
void StateChanged(SfxItemState eState, const SfxPoolItem* pState) override;
};
-class StyleItemController : public weld::CustomWidgetController
+class StyleItemController
{
static constexpr unsigned LEFT_MARGIN = 8;
SfxStyleFamily m_eStyleFamily;
std::pair<OUString, OUString> m_aStyleName;
- bool m_bSelected;
- css::uno::Reference<css::frame::XDispatchProvider> m_xDispatchProvider;
public:
- StyleItemController(
- const std::pair<OUString, OUString>& aStyleName,
- const css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider);
-
- void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
+ StyleItemController(const std::pair<OUString, OUString>& aStyleName);
- bool MouseButtonDown(const MouseEvent& rMEvt) override;
- bool Command(const CommandEvent& rEvent) override;
+ void Paint(vcl::RenderContext& rRenderContext);
void SetStyle(const std::pair<OUString, OUString>& sStyleName);
@@ -77,23 +70,21 @@ class StylesPreviewWindow_Base
protected:
static constexpr unsigned STYLES_COUNT = 6;
- std::unique_ptr<StyleItemController> m_xStyleControllers[STYLES_COUNT];
- std::unique_ptr<weld::CustomWeld> m_xStyleControllersWeld[STYLES_COUNT];
+ css::uno::Reference<css::frame::XDispatchProvider> m_xDispatchProvider;
+
+ std::unique_ptr<weld::IconView> m_xStylesView;
StyleStatusListener* m_pStatusListener;
css::uno::Reference<css::lang::XComponent> m_xStatusListener;
- std::unique_ptr<weld::Toolbar> m_xUp;
- std::unique_ptr<weld::Toolbar> m_xDown;
-
std::vector<std::pair<OUString, OUString>> m_aDefaultStyles;
std::vector<std::pair<OUString, OUString>> m_aAllStyles;
- unsigned m_nStyleIterator;
OUString m_sSelectedStyle;
- DECL_LINK(GoUp, const OString&, void);
- DECL_LINK(GoDown, const OString&, void);
+ DECL_LINK(Selected, weld::IconView&, void);
+ DECL_LINK(DoubleClick, weld::IconView&, bool);
+ DECL_LINK(DoCommand, const CommandEvent&, bool);
public:
StylesPreviewWindow_Base(
@@ -106,8 +97,7 @@ public:
private:
void Update();
void UpdateStylesList();
- void MakeCurrentStyleVisible();
- std::pair<OUString, OUString> GetVisibleStyle(unsigned nPosition);
+ bool Command(const CommandEvent& rEvent);
};
class StylesPreviewWindow_Impl : public InterimItemWindow, public StylesPreviewWindow_Base
diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx b/svx/source/tbxctrls/StylesPreviewWindow.cxx
index 48d12d2a67f2..141a02dfc847 100644
--- a/svx/source/tbxctrls/StylesPreviewWindow.cxx
+++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx
@@ -27,6 +27,7 @@
#include <sfx2/sfxsids.hrc>
#include <sfx2/tplpitem.hxx>
#include <sfx2/viewsh.hxx>
+#include <vcl/virdev.hxx>
#include <editeng/editids.hrc>
#include <editeng/fontitem.hxx>
@@ -71,18 +72,13 @@ void StyleStatusListener::StateChanged(SfxItemState /*eState*/, const SfxPoolIte
m_pPreviewControl->Select(pStateItem->GetStyleName());
}
-StyleItemController::StyleItemController(
- const std::pair<OUString, OUString>& aStyleName,
- const css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider)
+StyleItemController::StyleItemController(const std::pair<OUString, OUString>& aStyleName)
: m_eStyleFamily(SfxStyleFamily::Para)
, m_aStyleName(aStyleName)
- , m_bSelected(false)
- , m_xDispatchProvider(xDispatchProvider)
{
}
-void StyleItemController::Paint(vcl::RenderContext& rRenderContext,
- const tools::Rectangle& /*rRect*/)
+void StyleItemController::Paint(vcl::RenderContext& rRenderContext)
{
rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::FONT | PushFlags::TEXTCOLOR);
@@ -91,51 +87,19 @@ void StyleItemController::Paint(vcl::RenderContext& rRenderContext,
rRenderContext.Pop();
}
-void StyleItemController::SetStyle(const std::pair<OUString, OUString>& sStyleName)
-{
- m_aStyleName = sStyleName;
- Invalidate();
-}
-
-void StyleItemController::Select(bool bSelect)
-{
- m_bSelected = bSelect;
- Invalidate();
-}
-
-bool StyleItemController::MouseButtonDown(const MouseEvent& rMEvt)
-{
- if (rMEvt.IsLeft())
- {
- css::uno::Sequence<css::beans::PropertyValue> aArgs(2);
- aArgs[0].Value <<= m_aStyleName.second;
- aArgs[1].Name = "Family";
- aArgs[1].Value <<= sal_Int16(m_eStyleFamily);
-
- aArgs[0].Name = "Template";
- SfxToolBoxControl::Dispatch(m_xDispatchProvider, ".uno:StyleApply", aArgs);
- }
-
- return false;
-}
-
-bool StyleItemController::Command(const CommandEvent& rEvent)
+bool StylesPreviewWindow_Base::Command(const CommandEvent& rEvent)
{
if (rEvent.GetCommand() != CommandEventId::ContextMenu)
- return CustomWidgetController::Command(rEvent);
+ return false;
std::unique_ptr<weld::Builder> xBuilder(
- Application::CreateBuilder(GetDrawingArea(), "svx/ui/stylemenu.ui"));
+ Application::CreateBuilder(m_xStylesView.get(), "svx/ui/stylemenu.ui"));
std::unique_ptr<weld::Menu> xMenu(xBuilder->weld_menu("menu"));
std::string_view rIdent = xMenu->popup_at_rect(
- GetDrawingArea(), tools::Rectangle(rEvent.GetMousePosPixel(), Size(1, 1)));
+ m_xStylesView.get(), tools::Rectangle(rEvent.GetMousePosPixel(), Size(1, 1)));
if (rIdent == "update" || rIdent == "edit")
{
- css::uno::Sequence<css::beans::PropertyValue> aArgs(2);
- aArgs[0].Name = "Param";
- aArgs[0].Value <<= m_aStyleName.second;
- aArgs[1].Name = "Family";
- aArgs[1].Value <<= sal_Int16(m_eStyleFamily);
+ css::uno::Sequence<css::beans::PropertyValue> aArgs(0);
SfxToolBoxControl::Dispatch(m_xDispatchProvider,
rIdent == "update" ? OUString(".uno:StyleUpdateByExample")
@@ -259,24 +223,13 @@ void StyleItemController::DrawEntry(vcl::RenderContext& rRenderContext)
Size aSize(rRenderContext.GetOutputSizePixel());
tools::Rectangle aFullRect(Point(0, 0), aSize);
- aSize = Size(aSize.getWidth() - 6, aSize.getHeight() - 6);
tools::Rectangle aContentRect(aFullRect);
Color aOriginalColor = rRenderContext.GetFillColor();
Color aOriginalLineColor = rRenderContext.GetLineColor();
- vcl::Region aOriginalClipRegion(aFullRect);
-
- if (m_bSelected)
- {
- aContentRect = tools::Rectangle(Point(3, 3), aSize);
- DrawSelection(rRenderContext);
- }
DrawContentBackground(rRenderContext, aContentRect, aOriginalColor);
- vcl::Region aClipRegion(aContentRect);
- rRenderContext.SetClipRegion(aClipRegion);
-
std::unique_ptr<const SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview());
if (!pItemSet)
return;
@@ -326,7 +279,6 @@ void StyleItemController::DrawEntry(vcl::RenderContext& rRenderContext)
rRenderContext.SetFillColor(aOriginalColor);
rRenderContext.SetLineColor(aOriginalLineColor);
- rRenderContext.SetClipRegion(aOriginalClipRegion);
}
void StyleItemController::DrawContentBackground(vcl::RenderContext& rRenderContext,
@@ -386,30 +338,51 @@ void StyleItemController::DrawText(vcl::RenderContext& rRenderContext)
StylesPreviewWindow_Base::StylesPreviewWindow_Base(
weld::Builder& xBuilder, std::vector<std::pair<OUString, OUString>>& aDefaultStyles,
const css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider)
- : m_xUp(xBuilder.weld_toolbar("uptoolbar"))
- , m_xDown(xBuilder.weld_toolbar("downtoolbar"))
+ : m_xDispatchProvider(xDispatchProvider)
+ , m_xStylesView(xBuilder.weld_icon_view("stylesview"))
, m_aDefaultStyles(aDefaultStyles)
- , m_nStyleIterator(0)
{
- for (unsigned int i = 0; i < STYLES_COUNT; i++)
- {
- auto aStyle
- = i < aDefaultStyles.size() ? aDefaultStyles[i] : std::pair<OUString, OUString>("", "");
- m_xStyleControllers[i].reset(new StyleItemController(aStyle, xDispatchProvider));
+ m_xStylesView->connect_selection_changed(LINK(this, StylesPreviewWindow_Base, Selected));
+ m_xStylesView->connect_item_activated(LINK(this, StylesPreviewWindow_Base, DoubleClick));
+ m_xStylesView->connect_command(LINK(this, StylesPreviewWindow_Base, DoCommand));
- OUString sIdOUString = "style" + OUString::number(i + 1);
- OString sId = OUStringToOString(sIdOUString, RTL_TEXTENCODING_ASCII_US);
+ m_pStatusListener = new StyleStatusListener(this, xDispatchProvider);
+ m_xStatusListener.set(static_cast<cppu::OWeakObject*>(m_pStatusListener), css::uno::UNO_QUERY);
- m_xStyleControllersWeld[i].reset(
- new weld::CustomWeld(xBuilder, sId, *m_xStyleControllers[i]));
- m_xStyleControllersWeld[i]->set_size_request(128, 28);
- }
+ Update();
+}
- m_xUp->connect_clicked(LINK(this, StylesPreviewWindow_Base, GoUp));
- m_xDown->connect_clicked(LINK(this, StylesPreviewWindow_Base, GoDown));
+IMPL_LINK(StylesPreviewWindow_Base, Selected, weld::IconView&, rIconView, void)
+{
+ OUString sStyleName = rIconView.get_selected_text();
- m_pStatusListener = new StyleStatusListener(this, xDispatchProvider);
- m_xStatusListener.set(static_cast<cppu::OWeakObject*>(m_pStatusListener), css::uno::UNO_QUERY);
+ css::uno::Sequence<css::beans::PropertyValue> aArgs(2);
+ aArgs[0].Value <<= sStyleName;
+ aArgs[1].Name = "Family";
+ aArgs[1].Value <<= sal_Int16(SfxStyleFamily::Para);
+
+ aArgs[0].Name = "Template";
+ SfxToolBoxControl::Dispatch(m_xDispatchProvider, ".uno:StyleApply", aArgs);
+}
+
+IMPL_LINK(StylesPreviewWindow_Base, DoubleClick, weld::IconView&, rIconView, bool)
+{
+ OUString sStyleName = rIconView.get_selected_text();
+
+ css::uno::Sequence<css::beans::PropertyValue> aArgs(2);
+ aArgs[0].Name = "Param";
+ aArgs[0].Value <<= sStyleName;
+ aArgs[1].Name = "Family";
+ aArgs[1].Value <<= sal_Int16(SfxStyleFamily::Para);
+
+ SfxToolBoxControl::Dispatch(m_xDispatchProvider, ".uno:EditStyle", aArgs);
+
+ return true;
+}
+
+IMPL_LINK(StylesPreviewWindow_Base, DoCommand, const CommandEvent&, rPos, bool)
+{
+ return Command(rPos);
}
StylesPreviewWindow_Base::~StylesPreviewWindow_Base()
@@ -427,56 +400,25 @@ StylesPreviewWindow_Base::~StylesPreviewWindow_Base()
m_pStatusListener = nullptr;
}
-std::pair<OUString, OUString> StylesPreviewWindow_Base::GetVisibleStyle(unsigned nPosition)
-{
- if (nPosition >= STYLES_COUNT || !m_aAllStyles.size())
- return std::make_pair<OUString, OUString>("", "");
-
- return m_aAllStyles[(m_nStyleIterator + nPosition) % m_aAllStyles.size()];
-}
-
void StylesPreviewWindow_Base::Select(const OUString& rStyleName)
{
m_sSelectedStyle = rStyleName;
UpdateStylesList();
- MakeCurrentStyleVisible();
Update();
}
-void StylesPreviewWindow_Base::MakeCurrentStyleVisible()
-{
- if (!m_aAllStyles.size())
- return;
-
- unsigned nNewIterator = m_nStyleIterator;
- auto aFound = std::find_if(m_aAllStyles.begin(), m_aAllStyles.end(), [this](auto it) {
- return it.first == m_sSelectedStyle || it.second == m_sSelectedStyle;
- });
- if (aFound != m_aAllStyles.end())
- nNewIterator = aFound - m_aAllStyles.begin();
-
- bool bIsAlreadyVisible
- = nNewIterator >= m_nStyleIterator % m_aAllStyles.size()
- && nNewIterator < m_nStyleIterator % m_aAllStyles.size() + STYLES_COUNT;
- if (!bIsAlreadyVisible)
- m_nStyleIterator = nNewIterator;
-}
-
void StylesPreviewWindow_Base::Update()
{
UpdateStylesList();
- for (unsigned int i = 0; i < STYLES_COUNT; i++)
+ for (unsigned long i = 0; i < m_aAllStyles.size(); ++i)
{
- std::pair<OUString, OUString> sStyleName = GetVisibleStyle(i);
- m_xStyleControllers[i]->SetStyle(sStyleName);
- m_xStyleControllersWeld[i]->set_tooltip_text(sStyleName.second);
-
- if (sStyleName.first == m_sSelectedStyle || sStyleName.second == m_sSelectedStyle)
- m_xStyleControllers[i]->Select(true);
- else
- m_xStyleControllers[i]->Select(false);
+ if (m_aAllStyles[i].first == m_sSelectedStyle || m_aAllStyles[i].second == m_sSelectedStyle)
+ {
+ m_xStylesView->select(i);
+ break;
+ }
}
}
@@ -503,22 +445,19 @@ void StylesPreviewWindow_Base::UpdateStylesList()
pStyle = xIter->Next();
}
}
-}
-IMPL_LINK(StylesPreviewWindow_Base, GoUp, const OString&, /*rItem*/, void)
-{
- if (m_nStyleIterator == 0)
- m_nStyleIterator = m_aAllStyles.size();
- else
- m_nStyleIterator = m_nStyleIterator - 2;
+ m_xStylesView->clear();
+ for (auto& rStyle : m_aAllStyles)
+ {
+ ScopedVclPtr<VirtualDevice> pImg = VclPtr<VirtualDevice>::Create();
+ const Size aSize(100, 30);
+ pImg->SetOutputSizePixel(aSize);
- Update();
-}
+ StyleItemController aStyleController(rStyle);
+ aStyleController.Paint(*pImg);
-IMPL_LINK(StylesPreviewWindow_Base, GoDown, const OString&, /*rItem*/, void)
-{
- m_nStyleIterator = m_nStyleIterator + 2;
- Update();
+ m_xStylesView->append(rStyle.first, rStyle.second, pImg);
+ }
}
StylesPreviewWindow_Impl::StylesPreviewWindow_Impl(
@@ -528,10 +467,6 @@ StylesPreviewWindow_Impl::StylesPreviewWindow_Impl(
reinterpret_cast<sal_uInt64>(SfxViewShell::Current()))
, StylesPreviewWindow_Base(*m_xBuilder, aDefaultStyles, xDispatchProvider)
{
- m_xUp->set_stack_background();
- m_xDown->set_stack_background();
- m_xContainer->set_stack_background();
-
SetOptimalSize();
}
@@ -539,11 +474,7 @@ StylesPreviewWindow_Impl::~StylesPreviewWindow_Impl() { disposeOnce(); }
void StylesPreviewWindow_Impl::dispose()
{
- m_xUp.reset();
- m_xDown.reset();
-
- for (unsigned int i = 0; i < STYLES_COUNT; i++)
- m_xStyleControllersWeld[i].reset();
+ m_xStylesView.reset();
InterimItemWindow::dispose();
}