Introduce new ColorIconView class as a new subclass
of the abstract IColorSet class/interface introduced in
earlier commit
Change-Id: I20dd12f00effac7d510c092513cd457f1ea0bcb0
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Fri Apr 17 09:25:36 2026 +0200
svx: Introduce new abstract IColorSet base for SvxColorValueSet
, as a new implementation that uses weld::IconView instead
of SvxColorValueSet to implement the logic.
Port the "Color" section in the "Area" tab page to use
that new implementation instead of SvxColorValueSet.
Similar to earlier commit
commit 7d1647bdb7
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Thu Apr 16 11:46:45 2026 +0200
Port "Area" tab page's Gradient/Image/Pattern/Hatch sections to IconView
that was porting other sections in the "Area" tab page
from using ValueSet to using weld::IconView, this helps
to be more consistent with other platform/toolkit
widgets, reduces custom logic and e.g. also fixes the issue
of triggering the following assert when using the gtk3 vcl
plugin, the Orca screen reader is enabled and the color value set
receives focus:
soffice.bin: /home/michi/development/git/libreoffice/vcl/unx/gtk3/gtkinst.cxx:18237: virtual rtl::Reference<comphelper::OAccessible> (anonymous namespace)::GtkInstanceDrawingArea::get_accessible_parent(): Assertion `false && "get_accessible_parent should only be called on a vcl impl"' failed.
This also prepares for supporting that tab page
with native Qt widgets as it prevents another issue
(continual resizing) seen when experimenting with the
earlier implementation.
The relevant UI using this can e.g. be triggered like
this:
* start Writer
* "Format" -> "Page Style"
* go to the "Area" tab page
* switch to the "Color" tab page
As described in more detail in the commit message
of the above-mentioned 7d1647bdb7,
spacing also changes for the color selector(s)
with this change due to the switch to weld::IconView.
(See the commit message of that commit for ideas on how
spacing could be adjusted, if necessary.)
Set the column count for the icon views to 14 in
the UI file, which matches the previous default
behavior.
Tweak some properties in the .ui file to make the
icon views use a proper size.
Adjust the existing UI tests using the widget
to use the IconView/SvTreeListBox UI test
logic instead of the one for the previously
used SvxColorValueSet.
Change-Id: I70b9a62101c17bc3c392f7d395aca4eac0dcfc4b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/203809
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
87 lines
2.9 KiB
C++
87 lines
2.9 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
/*
|
|
* 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/ColorIconView.hxx>
|
|
#include <vcl/settings.hxx>
|
|
#include <vcl/svapp.hxx>
|
|
#include <vcl/virdev.hxx>
|
|
#include <vcl/weld/IconView.hxx>
|
|
|
|
ColorIconView::ColorIconView(std::unique_ptr<weld::IconView> pIconView)
|
|
: m_pIconView(std::move(pIconView))
|
|
{
|
|
m_pIconView->connect_item_activated(LINK(this, ColorIconView, ItemActivatedHdl));
|
|
}
|
|
|
|
void ColorIconView::insert(int nIndex, const Color& rColor, const OUString& rColorName)
|
|
{
|
|
assert(nIndex >= 0 && nIndex <= m_pIconView->n_children() && "Invalid index");
|
|
|
|
const OUString* pNullIconName = nullptr;
|
|
m_pIconView->insert(nIndex, nullptr, nullptr, pNullIconName, nullptr);
|
|
ScopedVclPtr<VirtualDevice> pIcon = createIcon(rColor);
|
|
m_pIconView->set_image(nIndex, *pIcon);
|
|
m_pIconView->set_item_tooltip_text(nIndex, rColorName);
|
|
m_pIconView->set_item_accessible_name(nIndex, rColorName);
|
|
m_pIconView->set_id(nIndex, rColor.AsRGBHEXString());
|
|
}
|
|
|
|
int ColorIconView::getItemCount() const { return m_pIconView->n_children(); }
|
|
|
|
Color ColorIconView::getColor(int nIndex)
|
|
{
|
|
if (nIndex < 0 || nIndex >= m_pIconView->n_children())
|
|
return Color();
|
|
|
|
Color aColor;
|
|
color::createFromString("#" + m_pIconView->get_id(nIndex).toUtf8(), aColor);
|
|
return aColor;
|
|
}
|
|
|
|
OUString ColorIconView::getColorName(int nIndex) const
|
|
{
|
|
return m_pIconView->get_item_tooltip_text(nIndex);
|
|
}
|
|
|
|
int ColorIconView::get_selected_index() const { return m_pIconView->get_selected_index(); }
|
|
|
|
void ColorIconView::select(int nIndex) { m_pIconView->select(nIndex); };
|
|
|
|
void ColorIconView::unselect_all() { m_pIconView->unselect_all(); }
|
|
|
|
void ColorIconView::remove(int nIndex) { m_pIconView->remove(nIndex); }
|
|
|
|
void ColorIconView::clear() { m_pIconView->clear(); }
|
|
|
|
IMPL_LINK(ColorIconView, ItemActivatedHdl, const weld::TreeIter&, rIter, bool)
|
|
{
|
|
Color aColor = getColor(m_pIconView->get_iter_index_in_parent(rIter));
|
|
m_aColorActivatedHdl.Call(aColor);
|
|
return true;
|
|
}
|
|
|
|
ScopedVclPtr<VirtualDevice> ColorIconView::createIcon(const Color& rColor)
|
|
{
|
|
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
|
|
|
|
const tools::Long nEdgeLength = rStyleSettings.GetListBoxPreviewDefaultPixelSize().Height() + 1;
|
|
const Size aSize(nEdgeLength, nEdgeLength);
|
|
|
|
ScopedVclPtr<VirtualDevice> pDev = m_pIconView->create_virtual_device();
|
|
pDev->SetOutputSizePixel(aSize);
|
|
|
|
pDev->SetFillColor(rColor);
|
|
pDev->SetLineColor(rStyleSettings.GetFieldTextColor());
|
|
pDev->DrawRect(pDev->GetOutputRectPixel());
|
|
|
|
return pDev;
|
|
}
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|