tdf#130857 sc: Port tab color dialog to ColorIconView

Similar to

    commit a4d5983b4e
    Author: Michael Weghorn <m.weghorn@posteo.de>
    Date:   Fri Jun 5 11:48:54 2026 +0200

        tdf#130857 Port ColorWindow from SvxColorValueSet to ColorIconView

, also port ScTabBgColorDlg from using SvxColorValueSet
to use ColorIconView instead.

This helps to be more consistent with other platform/toolkit
widgets, reduces custom logic and prepares for enabling
support for that dialog with native Qt widgets
(SAL_VCL_QT_USE_WELDED_WIDGETS=1) in an upcoming commit.

Extend ColorIconView to also allow setting a handler that
gets called when the selection changes and make use of that
in ScTabBgColorDlg.

The custom ScTabBgColorValueSet::ScTabBgColorValueSet
subclass for SvxColorValueSet was used to allow automatically
closing the dialog when the space or Return keys were pressed
while the widget to select the color had focus.
This is now covered by the handler for item activation,
ScTabBgColorValueSet::TabBgColorActivatedHdl, so no
separate class is needed for that any more.

The dialog can be triggered like this:

* start Calc
* "Sheet" -> "Sheet Tab Color"

Change-Id: Ia997dfa48f4239046a1b821f40ed402128111b23
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/206285
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
This commit is contained in:
Michael Weghorn
2026-06-11 21:41:36 +02:00
parent 3fa1bda90b
commit dc3b6ec185
5 changed files with 54 additions and 89 deletions
+8
View File
@@ -19,6 +19,7 @@ class VirtualDevice;
namespace weld
{
class IconView;
class ItemView;
class TreeIter;
}
@@ -27,8 +28,10 @@ class SVXCORE_DLLPUBLIC ColorIconView : public IColorSet
std::unique_ptr<weld::IconView> m_pIconView;
Link<const Color&, void> m_aColorActivatedHdl;
Link<const ColorIconView&, void> m_aSelectionChangedHdl;
DECL_LINK(ItemActivatedHdl, const weld::TreeIter&, bool);
DECL_LINK(SelectionChangedHdl, weld::ItemView&, void);
public:
ColorIconView(std::unique_ptr<weld::IconView> pIconView);
@@ -58,6 +61,11 @@ public:
m_aColorActivatedHdl = rLink;
}
void setSelectionChangedHdl(const Link<const ColorIconView&, void>& rLink)
{
m_aSelectionChangedHdl = rLink;
}
private:
ScopedVclPtr<VirtualDevice> createIcon(const Color& rColor);
};
+5 -22
View File
@@ -19,12 +19,12 @@
#pragma once
#include <svx/ColorIconView.hxx>
#include <svx/PaletteManager.hxx>
#include <vcl/weld/Button.hxx>
#include <vcl/weld/ComboBox.hxx>
#include <vcl/weld/DialogController.hxx>
#include <vcl/weld/ToggleButton.hxx>
#include <svx/SvxColorValueSet.hxx>
#include <svx/PaletteManager.hxx>
class ScTabBgColorDlg : public weld::GenericDialogController
{
@@ -34,37 +34,20 @@ public:
Color GetSelectedColor() const;
class ScTabBgColorValueSet : public SvxColorValueSet
{
public:
ScTabBgColorValueSet(std::unique_ptr<weld::ScrolledWindow> pWindow);
virtual ~ScTabBgColorValueSet() override;
void SetDialog(ScTabBgColorDlg* pTabBgColorDlg)
{
m_pTabBgColorDlg = pTabBgColorDlg;
}
virtual bool KeyInput( const KeyEvent& rKEvt ) override;
private:
ScTabBgColorDlg* m_pTabBgColorDlg;
};
private:
PaletteManager m_aPaletteManager;
std::unique_ptr<weld::ComboBox> m_xSelectPalette;
std::unique_ptr<weld::ToggleButton> m_xDefaultButton;
std::unique_ptr<ScTabBgColorValueSet> m_xTabBgColorSet;
std::unique_ptr<weld::CustomWeld> m_xTabBgColorSetWin;
ColorIconView m_aTabBgColorIconView;
std::unique_ptr<weld::Button> m_xBtnOk;
void FillPaletteLB();
DECL_LINK(SelectPaletteLBHdl, weld::ComboBox&, void);
DECL_LINK(DefaultButtonToggled, weld::Toggleable&, void);
DECL_LINK(TabBgColorSelectHdl, ValueSet*, void);
DECL_LINK(TabBgColorDblClickHdl_Impl, ValueSet*, void);
DECL_LINK(TabBgColorSelectHdl, const ColorIconView&, void);
DECL_LINK(TabBgColorActivatedHdl, const Color&, void);
DECL_LINK(TabBgColorOKHdl_Impl, weld::Button&, void);
};
+12 -52
View File
@@ -28,6 +28,7 @@
#include <vcl/weld/Builder.hxx>
#include <vcl/weld/ScrolledWindow.hxx>
#include <vcl/weld/Dialog.hxx>
#include <vcl/weld/IconView.hxx>
#include <officecfg/Office/Common.hxx>
@@ -36,30 +37,17 @@ ScTabBgColorDlg::ScTabBgColorDlg(weld::Window* pParent, const OUString& rTitle)
u"TabColorDialog"_ustr)
, m_xSelectPalette(m_xBuilder->weld_combo_box(u"paletteselector"_ustr))
, m_xDefaultButton(m_xBuilder->weld_toggle_button(u"defaultbutton"_ustr))
, m_xTabBgColorSet(new ScTabBgColorValueSet(m_xBuilder->weld_scrolled_window(u"colorsetwin"_ustr, true)))
, m_xTabBgColorSetWin(new weld::CustomWeld(*m_xBuilder, u"colorset"_ustr, *m_xTabBgColorSet))
, m_aTabBgColorIconView(m_xBuilder->weld_icon_view(u"coloriconview"_ustr))
, m_xBtnOk(m_xBuilder->weld_button(u"ok"_ustr))
{
m_xTabBgColorSet->SetDialog(this);
m_xTabBgColorSet->SetColCount(SvxColorValueSet::getColumnCount());
m_xDialog->set_title(rTitle);
const WinBits nBits(m_xTabBgColorSet->GetStyle() | WB_NAMEFIELD | WB_ITEMBORDER | WB_3DLOOK);
m_xTabBgColorSet->SetStyle(nBits);
const sal_uInt32 nColCount = SvxColorValueSet::getColumnCount();
const sal_uInt32 nRowCount(10);
const sal_uInt32 nLength = SvxColorValueSet::getEntryEdgeLength();
Size aSize(m_xTabBgColorSet->CalcWindowSizePixel(Size(nLength, nLength), nColCount, nRowCount));
m_xTabBgColorSetWin->set_size_request(aSize.Width() + 8, aSize.Height() + 8);
FillPaletteLB();
m_xSelectPalette->connect_changed(LINK(this, ScTabBgColorDlg, SelectPaletteLBHdl));
m_xDefaultButton->connect_toggled(LINK(this, ScTabBgColorDlg, DefaultButtonToggled));
m_xTabBgColorSet->SetSelectHdl(LINK(this, ScTabBgColorDlg, TabBgColorSelectHdl));
m_xTabBgColorSet->SetDoubleClickHdl(LINK(this, ScTabBgColorDlg, TabBgColorDblClickHdl_Impl));
m_aTabBgColorIconView.setSelectionChangedHdl(LINK(this, ScTabBgColorDlg, TabBgColorSelectHdl));
m_aTabBgColorIconView.setColorActivatedHdl(LINK(this, ScTabBgColorDlg, TabBgColorActivatedHdl));
m_xBtnOk->connect_clicked(LINK(this, ScTabBgColorDlg, TabBgColorOKHdl_Impl));
}
@@ -72,8 +60,8 @@ Color ScTabBgColorDlg::GetSelectedColor() const
if (m_xDefaultButton->get_active())
return COL_AUTO;
sal_uInt16 nItemId = m_xTabBgColorSet->GetSelectedItemId();
Color aColor = nItemId ? (m_xTabBgColorSet->GetItemColor(nItemId)) : COL_AUTO;
const int nIndex = m_aTabBgColorIconView.get_selected_index();
Color aColor = nIndex >= 0 ? (m_aTabBgColorIconView.getColor(nIndex)) : COL_AUTO;
return aColor;
}
@@ -95,14 +83,12 @@ void ScTabBgColorDlg::FillPaletteLB()
IMPL_LINK_NOARG(ScTabBgColorDlg, SelectPaletteLBHdl, weld::ComboBox&, void)
{
m_xTabBgColorSet->Clear();
m_aTabBgColorIconView.clear();
sal_Int32 nPos = m_xSelectPalette->get_active();
m_aPaletteManager.SetPalette( nPos );
m_aPaletteManager.ReloadColorSet(*m_xTabBgColorSet);
m_xTabBgColorSet->Resize();
m_aPaletteManager.ReloadColorSet(m_aTabBgColorIconView);
m_xDefaultButton->set_active(true);
m_xTabBgColorSet->SetNoSelection();
m_xTabBgColorSet->SetCursor(nullptr);
m_aTabBgColorIconView.unselect_all();
}
IMPL_LINK_NOARG(ScTabBgColorDlg, DefaultButtonToggled, weld::Toggleable&, void)
@@ -115,17 +101,16 @@ IMPL_LINK_NOARG(ScTabBgColorDlg, DefaultButtonToggled, weld::Toggleable&, void)
return;
}
m_xTabBgColorSet->SetNoSelection();
m_xTabBgColorSet->SetCursor(nullptr);
m_aTabBgColorIconView.unselect_all();
}
// Handler, called when color selection is changed
IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorSelectHdl, ValueSet*, void)
IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorSelectHdl, const ColorIconView&, void)
{
m_xDefaultButton->set_active(false);
}
IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorDblClickHdl_Impl, ValueSet*, void)
IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorActivatedHdl, const Color&, void)
{
m_xDialog->response(RET_OK);
}
@@ -136,29 +121,4 @@ IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorOKHdl_Impl, weld::Button&, void)
m_xDialog->response(RET_OK);
}
ScTabBgColorDlg::ScTabBgColorValueSet::ScTabBgColorValueSet(std::unique_ptr<weld::ScrolledWindow> pWindow)
: SvxColorValueSet(std::move(pWindow))
, m_pTabBgColorDlg(nullptr)
{
}
ScTabBgColorDlg::ScTabBgColorValueSet::~ScTabBgColorValueSet()
{
}
bool ScTabBgColorDlg::ScTabBgColorValueSet::KeyInput( const KeyEvent& rKEvt )
{
switch ( rKEvt.GetKeyCode().GetCode() )
{
case KEY_SPACE:
case KEY_RETURN:
{
m_pTabBgColorDlg->response(RET_OK);
return true;
}
break;
}
return SvxColorValueSet::KeyInput(rKEvt);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+23 -15
View File
@@ -7,16 +7,25 @@
<property name="can-focus">False</property>
<property name="icon-name">cmd/sc_square_unfilled.png</property>
</object>
<object class="GtkTreeStore" id="coloriconview_model">
<columns>
<!-- column-name pixbuf -->
<column type="GdkPixbuf"/>
<!-- column-name id -->
<column type="gchararray"/>
<!-- column-name tooltip -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="TabColorDialog">
<property name="can-focus">False</property>
<property name="border-width">6</property>
<property name="modal">True</property>
<property name="default-width">0</property>
<property name="default-height">0</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can-focus">False</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child internal-child="action_area">
@@ -125,26 +134,25 @@
<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>
<property name="propagate-natural-width">True</property>
<property name="propagate-natural-height">True</property>
<child>
<object class="GtkViewport">
<object class="GtkIconView" id="coloriconview">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkDrawingArea" id="colorset">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="events">GDK_BUTTON_MOTION_MASK | 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>
<property name="can-focus">True</property>
<property name="margin">6</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="model">coloriconview_model</property>
<property name="columns">12</property>
<property name="pixbuf-column">0</property>
<property name="tooltip-column">2</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
+6
View File
@@ -17,6 +17,7 @@ ColorIconView::ColorIconView(std::unique_ptr<weld::IconView> pIconView)
: m_pIconView(std::move(pIconView))
{
m_pIconView->connect_item_activated(LINK(this, ColorIconView, ItemActivatedHdl));
m_pIconView->connect_selection_changed(LINK(this, ColorIconView, SelectionChangedHdl));
}
void ColorIconView::insert(int nIndex, const Color& rColor, const OUString& rColorName)
@@ -72,6 +73,11 @@ IMPL_LINK(ColorIconView, ItemActivatedHdl, const weld::TreeIter&, rIter, bool)
return true;
}
IMPL_LINK_NOARG(ColorIconView, SelectionChangedHdl, weld::ItemView&, void)
{
m_aSelectionChangedHdl.Call(*this);
}
ScopedVclPtr<VirtualDevice> ColorIconView::createIcon(const Color& rColor)
{
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();