svx: Port ExtrusionLightingWindow from ValueSet to weld::IconView

Port the widget to select the lighting from using
a ValueSet widget to using weld::IconView.

This helps to be more consistent with other platform/toolkit
widgets and reduces custom widget logic.

Adjust indices used to account for the fact that
weld::IconView indices are 0-based while the ValueSet ones
are 1-based.

The popup can be triggered like this:

* open attachment 175894 from tdf#145296
* make sure the "3D-Settings" toolbar is enabled
  in "View" -> "Toolbars" -> "3D-Settings"
* select the extruded shape
* press the "Lighting" button in the "3D-Settings"
  toolbar

Change-Id: I28d86251b70149574535dc7b583660dbe42e9a0d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211903
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2026-10-07 17:50:48 +02:00
parent 1050ed2e56
commit 0bf31b7f4c
3 changed files with 61 additions and 69 deletions
+34 -42
View File
@@ -22,6 +22,7 @@
#include <comphelper/propertyvalue.hxx>
#include <svtools/toolbarmenu.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/virdev.hxx>
#include <vcl/weld/Builder.hxx>
#include <vcl/weld/ScrolledWindow.hxx>
#include <vcl/weld/Toolbar.hxx>
@@ -594,44 +595,38 @@ ExtrusionLightingWindow::ExtrusionLightingWindow(svt::PopupWindowController* pCo
weld::Widget* pParent)
: WeldToolbarPopup(pControl->getFrameInterface(), pParent, u"svx/ui/lightingwindow.ui"_ustr, u"LightingWindow"_ustr)
, mxControl(pControl)
, mxLightingSet(new ValueSet(nullptr))
, mxLightingSetWin(new weld::CustomWeld(*m_xBuilder, u"valueset"_ustr, *mxLightingSet))
, mxLightingIconView(m_xBuilder->weld_icon_view(u"iconview"_ustr))
, mxBright(m_xBuilder->weld_radio_button(u"bright"_ustr))
, mxNormal(m_xBuilder->weld_radio_button(u"normal"_ustr))
, mxDim(m_xBuilder->weld_radio_button(u"dim"_ustr))
{
mxLightingSet->SetStyle(WB_TABSTOP | WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NOBORDER | WB_NO_DIRECTSELECT);
for (sal_uInt16 i = FROM_TOP_LEFT; i <= FROM_BOTTOM_RIGHT; ++i)
{
if( i != FROM_FRONT )
{
maImgLightingOff[i] = Image(StockImage::Yes, aLightOffBmps[i]);
maImgLightingOn[i] = Image(StockImage::Yes, aLightOnBmps[i]);
maImgLightingOff[i] = Image(StockImage::Yes, aLightOffBmps[i]).GetBitmap();
maImgLightingOn[i] = Image(StockImage::Yes, aLightOnBmps[i]).GetBitmap();
}
maImgLightingPreview[i] = Image(StockImage::Yes, aLightPreviewBmps[i]);
maImgLightingPreview[i] = Image(StockImage::Yes, aLightPreviewBmps[i]).GetBitmap();
}
mxLightingSet->SetHelpId( HID_VALUESET_EXTRUSION_LIGHTING );
mxLightingIconView->set_help_id(HID_VALUESET_EXTRUSION_LIGHTING);
mxLightingSet->SetSelectHdl( LINK( this, ExtrusionLightingWindow, SelectValueSetHdl ) );
mxLightingSet->SetColCount( 3 );
mxLightingSet->EnableFullItemMode( false );
mxLightingIconView->connect_item_activated(
LINK(this, ExtrusionLightingWindow, IconViewItemActivatedHdl));
for (sal_uInt16 i = FROM_TOP_LEFT; i <= FROM_BOTTOM_RIGHT; ++i)
for (int i = FROM_TOP_LEFT; i <= FROM_BOTTOM_RIGHT; ++i)
{
if( i != FROM_FRONT )
{
mxLightingSet->InsertItem( i+1, maImgLightingOff[i] );
mxLightingIconView->insert(i, nullptr, nullptr, &maImgLightingOff[i], nullptr);
}
else
{
mxLightingSet->InsertItem( 5, maImgLightingPreview[FROM_FRONT] );
mxLightingIconView->insert(4, nullptr, nullptr, &maImgLightingPreview[FROM_FRONT],
nullptr);
}
}
Size aSize(72, 72);
mxLightingSet->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
mxLightingSet->SetOutputSizePixel(aSize);
mxBright->connect_toggled(LINK(this, ExtrusionLightingWindow, SelectToolbarMenuHdl));
mxNormal->connect_toggled(LINK(this, ExtrusionLightingWindow, SelectToolbarMenuHdl));
@@ -641,10 +636,7 @@ ExtrusionLightingWindow::ExtrusionLightingWindow(svt::PopupWindowController* pCo
AddStatusListener( g_sExtrusionLightingIntensity );
}
void ExtrusionLightingWindow::GrabFocus()
{
mxLightingSet->GrabFocus();
}
void ExtrusionLightingWindow::GrabFocus() { mxLightingIconView->grab_focus(); }
ExtrusionLightingWindow::~ExtrusionLightingWindow()
{
@@ -665,26 +657,28 @@ void ExtrusionLightingWindow::implSetDirection( int nDirection, bool bEnabled )
if( !bEnabled )
nDirection = FROM_FRONT;
sal_uInt16 nItemId;
for( nItemId = FROM_TOP_LEFT; nItemId <= FROM_BOTTOM_RIGHT; nItemId++ )
for (int nItemIndex = FROM_TOP_LEFT; nItemIndex <= FROM_BOTTOM_RIGHT; nItemIndex++)
{
if( nItemId == FROM_FRONT )
ScopedVclPtr<VirtualDevice> pDev = VclPtr<VirtualDevice>::Create();
if (nItemIndex == FROM_FRONT)
{
mxLightingSet->SetItemImage( nItemId + 1, maImgLightingPreview[ nDirection ] );
pDev->SetOutputSizePixel(maImgLightingPreview[nDirection].GetSizePixel());
pDev->DrawBitmap(Point(), maImgLightingPreview[nDirection]);
}
else
{
mxLightingSet->SetItemImage(
nItemId + 1,
static_cast<sal_uInt16>(nDirection) == nItemId ? maImgLightingOn[nItemId] : maImgLightingOff[nItemId]
);
const Bitmap& rBitmap = nDirection == nItemIndex ? maImgLightingOn[nItemIndex]
: maImgLightingOff[nItemIndex];
pDev->SetOutputSizePixel(rBitmap.GetSizePixel());
pDev->DrawBitmap(Point(), rBitmap);
}
mxLightingIconView->set_image(nItemIndex, *pDev);
}
if (bEnabled)
mxLightingSet->Enable();
mxLightingIconView->set_sensitive(true);
else
mxLightingSet->Disable();
mxLightingIconView->set_sensitive(false);
}
void ExtrusionLightingWindow::statusChanged(
@@ -719,23 +713,21 @@ void ExtrusionLightingWindow::statusChanged(
}
}
IMPL_LINK_NOARG(ExtrusionLightingWindow, SelectValueSetHdl, ValueSet*, void)
IMPL_LINK(ExtrusionLightingWindow, IconViewItemActivatedHdl, const weld::TreeIter&, rIter, bool)
{
sal_Int32 nDirection = mxLightingSet->GetSelectedItemId();
sal_Int32 nDirection = mxLightingIconView->get_iter_index_in_parent(rIter);
assert(nDirection >= 0 && nDirection < 9 && "Invalid index");
if( (nDirection > 0) && (nDirection < 10) )
{
nDirection--;
Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue(
g_sExtrusionLightingDirection.copy(5), nDirection) };
Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(
g_sExtrusionLightingDirection.copy(5), nDirection) };
mxControl->dispatchCommand(g_sExtrusionLightingDirection, aArgs);
mxControl->dispatchCommand( g_sExtrusionLightingDirection, aArgs );
implSetDirection( nDirection, true );
}
implSetDirection(nDirection, true);
mxControl->EndPopupMode();
return true;
}
IMPL_LINK(ExtrusionLightingWindow, SelectToolbarMenuHdl, weld::Toggleable&, rButton, void)
+7 -6
View File
@@ -23,6 +23,7 @@
#include <svtools/popupwindowcontroller.hxx>
#include <svtools/valueset.hxx>
#include <vcl/image.hxx>
#include <vcl/weld/IconView.hxx>
#include <vcl/weld/RadioButton.hxx>
#include <vcl/weld/customweld.hxx>
@@ -143,21 +144,21 @@ class ExtrusionLightingWindow final : public WeldToolbarPopup
{
private:
rtl::Reference<svt::PopupWindowController> mxControl;
std::unique_ptr<ValueSet> mxLightingSet;
std::unique_ptr<weld::CustomWeld> mxLightingSetWin;
std::unique_ptr<weld::IconView> mxLightingIconView;
std::unique_ptr<weld::RadioButton> mxBright;
std::unique_ptr<weld::RadioButton> mxNormal;
std::unique_ptr<weld::RadioButton> mxDim;
Image maImgLightingOff[9];
Image maImgLightingOn[9];
Image maImgLightingPreview[9];
Bitmap maImgLightingOff[9];
Bitmap maImgLightingOn[9];
Bitmap maImgLightingPreview[9];
void implSetIntensity( int nLevel, bool bEnabled );
void implSetDirection( int nDirection, bool bEnabled );
DECL_LINK( SelectToolbarMenuHdl, weld::Toggleable&, void );
DECL_LINK( SelectValueSetHdl, ValueSet*, void );
DECL_LINK(IconViewItemActivatedHdl, const weld::TreeIter&, bool);
public:
ExtrusionLightingWindow(svt::PopupWindowController* pControl, weld::Widget* pParentWindow);
virtual void GrabFocus() override;
+20 -21
View File
@@ -2,6 +2,16 @@
<!-- Generated with glade 3.40.0 -->
<interface domain="svx">
<requires lib="gtk+" version="3.24"/>
<object class="GtkTreeStore" id="iconview_model">
<columns>
<!-- column-name pixbuf -->
<column type="GdkPixbuf"/>
<!-- column-name id -->
<column type="gchararray"/>
<!-- column-name tooltip -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can-focus">False</property>
@@ -29,29 +39,18 @@
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkScrolledWindow" id="valuesetwin">
<object class="GtkIconView" id="iconview">
<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">
<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">iconview_model</property>
<property name="columns">3</property>
<property name="row-spacing">0</property>
<property name="column-spacing">0</property>
<property name="pixbuf-column">0</property>
<property name="tooltip-column">2</property>
<property name="item-padding">3</property>
<property name="activate-on-single-click">True</property>
</object>
<packing>
<property name="expand">False</property>