1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include "EffectPropertyPanel.hxx"
14 #include <sfx2/dispatch.hxx>
15 #include <svx/colorbox.hxx>
16 #include <svx/sdmetitm.hxx>
17 #include <svx/sdprcitm.hxx>
18 #include <svx/svddef.hxx>
19 #include <svx/svxids.hrc>
20 #include <svx/xcolit.hxx>
21 #include <svl/itemset.hxx>
23 namespace svx::sidebar
25 EffectPropertyPanel::EffectPropertyPanel(weld::Widget
* pParent
, SfxBindings
* pBindings
)
26 : PanelLayout(pParent
, u
"EffectPropertyPanel"_ustr
, u
"svx/ui/sidebareffect.ui"_ustr
)
27 , maGlowColorController(SID_ATTR_GLOW_COLOR
, *pBindings
, *this)
28 , maGlowRadiusController(SID_ATTR_GLOW_RADIUS
, *pBindings
, *this)
29 , maGlowTransparencyController(SID_ATTR_GLOW_TRANSPARENCY
, *pBindings
, *this)
30 , mxFTTransparency(m_xBuilder
->weld_label(u
"transparency"_ustr
))
31 , maSoftEdgeRadiusController(SID_ATTR_SOFTEDGE_RADIUS
, *pBindings
, *this)
32 , mpBindings(pBindings
)
33 , mxGlowRadius(m_xBuilder
->weld_metric_spin_button(u
"LB_GLOW_RADIUS"_ustr
, FieldUnit::POINT
))
34 , mxLBGlowColor(new ColorListBox(m_xBuilder
->weld_menu_button(u
"LB_GLOW_COLOR"_ustr
),
35 [this] { return GetFrameWeld(); }))
37 m_xBuilder
->weld_metric_spin_button(u
"LB_GLOW_TRANSPARENCY"_ustr
, FieldUnit::PERCENT
))
38 , mxFTColor(m_xBuilder
->weld_label(u
"glowcolorlabel"_ustr
))
40 m_xBuilder
->weld_metric_spin_button(u
"SB_SOFTEDGE_RADIUS"_ustr
, FieldUnit::POINT
))
45 EffectPropertyPanel::~EffectPropertyPanel()
48 mxLBGlowColor
.reset();
49 mxGlowTransparency
.reset();
51 mxFTTransparency
.reset();
52 mxSoftEdgeRadius
.reset();
54 maGlowColorController
.dispose();
55 maGlowRadiusController
.dispose();
56 maGlowTransparencyController
.dispose();
57 maSoftEdgeRadiusController
.dispose();
60 void EffectPropertyPanel::Initialize()
62 mxGlowRadius
->connect_value_changed(LINK(this, EffectPropertyPanel
, ModifyGlowRadiusHdl
));
63 mxLBGlowColor
->SetSelectHdl(LINK(this, EffectPropertyPanel
, ModifyGlowColorHdl
));
64 mxGlowTransparency
->connect_value_changed(
65 LINK(this, EffectPropertyPanel
, ModifyGlowTransparencyHdl
));
66 mxSoftEdgeRadius
->connect_value_changed(
67 LINK(this, EffectPropertyPanel
, ModifySoftEdgeRadiusHdl
));
70 IMPL_LINK_NOARG(EffectPropertyPanel
, ModifySoftEdgeRadiusHdl
, weld::MetricSpinButton
&, void)
72 SdrMetricItem
aItem(SDRATTR_SOFTEDGE_RADIUS
, mxSoftEdgeRadius
->get_value(FieldUnit::MM_100TH
));
73 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_SOFTEDGE_RADIUS
, SfxCallMode::RECORD
,
77 IMPL_LINK_NOARG(EffectPropertyPanel
, ModifyGlowColorHdl
, ColorListBox
&, void)
79 XColorItem
aItem(SDRATTR_GLOW_COLOR
, mxLBGlowColor
->GetSelectEntryColor());
80 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_COLOR
, SfxCallMode::RECORD
, { &aItem
});
83 IMPL_LINK_NOARG(EffectPropertyPanel
, ModifyGlowRadiusHdl
, weld::MetricSpinButton
&, void)
85 SdrMetricItem
aItem(SDRATTR_GLOW_RADIUS
, mxGlowRadius
->get_value(FieldUnit::MM_100TH
));
86 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_RADIUS
, SfxCallMode::RECORD
, { &aItem
});
89 IMPL_LINK_NOARG(EffectPropertyPanel
, ModifyGlowTransparencyHdl
, weld::MetricSpinButton
&, void)
91 SdrPercentItem
aItem(SDRATTR_GLOW_TRANSPARENCY
,
92 mxGlowTransparency
->get_value(FieldUnit::PERCENT
));
93 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_TRANSPARENCY
, SfxCallMode::RECORD
,
97 void EffectPropertyPanel::UpdateControls()
99 const bool bEnabled
= mxGlowRadius
->get_value(FieldUnit::MM_100TH
) != 0;
100 mxLBGlowColor
->set_sensitive(bEnabled
);
101 mxGlowTransparency
->set_sensitive(bEnabled
);
102 mxFTColor
->set_sensitive(bEnabled
);
103 mxFTTransparency
->set_sensitive(bEnabled
);
106 void EffectPropertyPanel::NotifyItemUpdate(sal_uInt16 nSID
, SfxItemState eState
,
107 const SfxPoolItem
* pState
)
111 case SID_ATTR_SOFTEDGE_RADIUS
:
113 if (eState
>= SfxItemState::DEFAULT
)
115 const SdrMetricItem
* pRadiusItem
= dynamic_cast<const SdrMetricItem
*>(pState
);
118 mxSoftEdgeRadius
->set_value(pRadiusItem
->GetValue(), FieldUnit::MM_100TH
);
123 case SID_ATTR_GLOW_COLOR
:
125 if (eState
>= SfxItemState::DEFAULT
)
127 const XColorItem
* pColorItem
= dynamic_cast<const XColorItem
*>(pState
);
130 mxLBGlowColor
->SelectEntry(pColorItem
->GetColorValue());
135 case SID_ATTR_GLOW_RADIUS
:
137 if (eState
>= SfxItemState::DEFAULT
)
139 const SdrMetricItem
* pRadiusItem
= dynamic_cast<const SdrMetricItem
*>(pState
);
142 mxGlowRadius
->set_value(pRadiusItem
->GetValue(), FieldUnit::MM_100TH
);
147 case SID_ATTR_GLOW_TRANSPARENCY
:
149 if (eState
>= SfxItemState::DEFAULT
)
151 if (auto pItem
= dynamic_cast<const SdrPercentItem
*>(pState
))
153 mxGlowTransparency
->set_value(pItem
->GetValue(), FieldUnit::PERCENT
);
162 std::unique_ptr
<PanelLayout
> EffectPropertyPanel::Create(weld::Widget
* pParent
,
163 SfxBindings
* pBindings
)
165 if (pParent
== nullptr)
166 throw css::lang::IllegalArgumentException(
167 u
"no parent Window given to EffectPropertyPanel::Create"_ustr
, nullptr, 0);
168 if (pBindings
== nullptr)
169 throw css::lang::IllegalArgumentException(
170 u
"no SfxBindings given to EffectPropertyPanel::Create"_ustr
, nullptr, 2);
172 return std::make_unique
<EffectPropertyPanel
>(pParent
, pBindings
);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */