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>
22 namespace svx::sidebar
24 EffectPropertyPanel::EffectPropertyPanel(weld::Widget
* pParent
, SfxBindings
* pBindings
)
25 : PanelLayout(pParent
, "EffectPropertyPanel", "svx/ui/sidebareffect.ui")
26 , maGlowColorController(SID_ATTR_GLOW_COLOR
, *pBindings
, *this)
27 , maGlowRadiusController(SID_ATTR_GLOW_RADIUS
, *pBindings
, *this)
28 , maGlowTransparencyController(SID_ATTR_GLOW_TRANSPARENCY
, *pBindings
, *this)
29 , mxFTTransparency(m_xBuilder
->weld_label("transparency"))
30 , maSoftEdgeRadiusController(SID_ATTR_SOFTEDGE_RADIUS
, *pBindings
, *this)
31 , mpBindings(pBindings
)
32 , mxGlowRadius(m_xBuilder
->weld_metric_spin_button("LB_GLOW_RADIUS", FieldUnit::POINT
))
33 , mxLBGlowColor(new ColorListBox(m_xBuilder
->weld_menu_button("LB_GLOW_COLOR"),
34 [this] { return GetFrameWeld(); }))
36 m_xBuilder
->weld_metric_spin_button("LB_GLOW_TRANSPARENCY", FieldUnit::PERCENT
))
37 , mxFTColor(m_xBuilder
->weld_label("glowcolorlabel"))
38 , mxSoftEdgeRadius(m_xBuilder
->weld_metric_spin_button("SB_SOFTEDGE_RADIUS", FieldUnit::POINT
))
43 EffectPropertyPanel::~EffectPropertyPanel()
46 mxLBGlowColor
.reset();
47 mxGlowTransparency
.reset();
49 mxFTTransparency
.reset();
50 mxSoftEdgeRadius
.reset();
52 maGlowColorController
.dispose();
53 maGlowRadiusController
.dispose();
54 maGlowTransparencyController
.dispose();
55 maSoftEdgeRadiusController
.dispose();
58 void EffectPropertyPanel::Initialize()
60 mxGlowRadius
->connect_value_changed(LINK(this, EffectPropertyPanel
, ModifyGlowRadiusHdl
));
61 mxLBGlowColor
->SetSelectHdl(LINK(this, EffectPropertyPanel
, ModifyGlowColorHdl
));
62 mxGlowTransparency
->connect_value_changed(
63 LINK(this, EffectPropertyPanel
, ModifyGlowTransparencyHdl
));
64 mxSoftEdgeRadius
->connect_value_changed(
65 LINK(this, EffectPropertyPanel
, ModifySoftEdgeRadiusHdl
));
68 IMPL_LINK_NOARG(EffectPropertyPanel
, ModifySoftEdgeRadiusHdl
, weld::MetricSpinButton
&, void)
70 SdrMetricItem
aItem(SDRATTR_SOFTEDGE_RADIUS
, mxSoftEdgeRadius
->get_value(FieldUnit::MM_100TH
));
71 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_SOFTEDGE_RADIUS
, SfxCallMode::RECORD
,
75 IMPL_LINK_NOARG(EffectPropertyPanel
, ModifyGlowColorHdl
, ColorListBox
&, void)
77 XColorItem
aItem(SDRATTR_GLOW_COLOR
, mxLBGlowColor
->GetSelectEntryColor());
78 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_COLOR
, SfxCallMode::RECORD
, { &aItem
});
81 IMPL_LINK_NOARG(EffectPropertyPanel
, ModifyGlowRadiusHdl
, weld::MetricSpinButton
&, void)
83 SdrMetricItem
aItem(SDRATTR_GLOW_RADIUS
, mxGlowRadius
->get_value(FieldUnit::MM_100TH
));
84 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_RADIUS
, SfxCallMode::RECORD
, { &aItem
});
87 IMPL_LINK_NOARG(EffectPropertyPanel
, ModifyGlowTransparencyHdl
, weld::MetricSpinButton
&, void)
89 SdrPercentItem
aItem(SDRATTR_GLOW_TRANSPARENCY
,
90 mxGlowTransparency
->get_value(FieldUnit::PERCENT
));
91 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_TRANSPARENCY
, SfxCallMode::RECORD
,
95 void EffectPropertyPanel::UpdateControls()
97 const bool bEnabled
= mxGlowRadius
->get_value(FieldUnit::MM_100TH
) != 0;
98 mxLBGlowColor
->set_sensitive(bEnabled
);
99 mxGlowTransparency
->set_sensitive(bEnabled
);
100 mxFTColor
->set_sensitive(bEnabled
);
101 mxFTTransparency
->set_sensitive(bEnabled
);
104 void EffectPropertyPanel::NotifyItemUpdate(sal_uInt16 nSID
, SfxItemState eState
,
105 const SfxPoolItem
* pState
)
109 case SID_ATTR_SOFTEDGE_RADIUS
:
111 if (eState
>= SfxItemState::DEFAULT
)
113 const SdrMetricItem
* pRadiusItem
= dynamic_cast<const SdrMetricItem
*>(pState
);
116 mxSoftEdgeRadius
->set_value(pRadiusItem
->GetValue(), FieldUnit::MM_100TH
);
121 case SID_ATTR_GLOW_COLOR
:
123 if (eState
>= SfxItemState::DEFAULT
)
125 const XColorItem
* pColorItem
= dynamic_cast<const XColorItem
*>(pState
);
128 mxLBGlowColor
->SelectEntry(pColorItem
->GetColorValue());
133 case SID_ATTR_GLOW_RADIUS
:
135 if (eState
>= SfxItemState::DEFAULT
)
137 const SdrMetricItem
* pRadiusItem
= dynamic_cast<const SdrMetricItem
*>(pState
);
140 mxGlowRadius
->set_value(pRadiusItem
->GetValue(), FieldUnit::MM_100TH
);
145 case SID_ATTR_GLOW_TRANSPARENCY
:
147 if (eState
>= SfxItemState::DEFAULT
)
149 if (auto pItem
= dynamic_cast<const SdrPercentItem
*>(pState
))
151 mxGlowTransparency
->set_value(pItem
->GetValue(), FieldUnit::PERCENT
);
160 std::unique_ptr
<PanelLayout
> EffectPropertyPanel::Create(weld::Widget
* pParent
,
161 SfxBindings
* pBindings
)
163 if (pParent
== nullptr)
164 throw css::lang::IllegalArgumentException(
165 "no parent Window given to EffectPropertyPanel::Create", nullptr, 0);
166 if (pBindings
== nullptr)
167 throw css::lang::IllegalArgumentException(
168 "no SfxBindings given to EffectPropertyPanel::Create", nullptr, 2);
170 return std::make_unique
<EffectPropertyPanel
>(pParent
, pBindings
);
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */