1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  */
9 
10 #include <sal/config.h>
11 
12 #include "EffectPropertyPanel.hxx"
13 
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 
22 namespace svx::sidebar
23 {
EffectPropertyPanel(weld::Widget * pParent,SfxBindings * pBindings)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(); }))
35     , mxGlowTransparency(
36           m_xBuilder->weld_metric_spin_button("LB_GLOW_TRANSPARENCY", FieldUnit::PERCENT))
37     , mxFTRadiusSoftEdge(m_xBuilder->weld_label("radiussoftedge"))
38     , mxFTRadiusGlow(m_xBuilder->weld_label("radiusglow"))
39     , mxFTColor(m_xBuilder->weld_label("color"))
40     , mxSoftEdgeRadius(m_xBuilder->weld_metric_spin_button("SB_SOFTEDGE_RADIUS", FieldUnit::POINT))
41 {
42     Initialize();
43 }
44 
~EffectPropertyPanel()45 EffectPropertyPanel::~EffectPropertyPanel()
46 {
47     mxGlowRadius.reset();
48     mxLBGlowColor.reset();
49     mxGlowTransparency.reset();
50     mxFTRadiusSoftEdge.reset();
51     mxFTColor.reset();
52     mxFTTransparency.reset();
53     mxSoftEdgeRadius.reset();
54     mxFTRadiusGlow.reset();
55 
56     maGlowColorController.dispose();
57     maGlowRadiusController.dispose();
58     maGlowTransparencyController.dispose();
59     maSoftEdgeRadiusController.dispose();
60 }
61 
Initialize()62 void EffectPropertyPanel::Initialize()
63 {
64     mxGlowRadius->connect_value_changed(LINK(this, EffectPropertyPanel, ModifyGlowRadiusHdl));
65     mxLBGlowColor->SetSelectHdl(LINK(this, EffectPropertyPanel, ModifyGlowColorHdl));
66     mxGlowTransparency->connect_value_changed(
67         LINK(this, EffectPropertyPanel, ModifyGlowTransparencyHdl));
68     mxSoftEdgeRadius->connect_value_changed(
69         LINK(this, EffectPropertyPanel, ModifySoftEdgeRadiusHdl));
70 }
71 
IMPL_LINK_NOARG(EffectPropertyPanel,ModifySoftEdgeRadiusHdl,weld::MetricSpinButton &,void)72 IMPL_LINK_NOARG(EffectPropertyPanel, ModifySoftEdgeRadiusHdl, weld::MetricSpinButton&, void)
73 {
74     SdrMetricItem aItem(SDRATTR_SOFTEDGE_RADIUS, mxSoftEdgeRadius->get_value(FieldUnit::MM_100TH));
75     mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_SOFTEDGE_RADIUS, SfxCallMode::RECORD,
76                                              { &aItem });
77 }
78 
IMPL_LINK_NOARG(EffectPropertyPanel,ModifyGlowColorHdl,ColorListBox &,void)79 IMPL_LINK_NOARG(EffectPropertyPanel, ModifyGlowColorHdl, ColorListBox&, void)
80 {
81     XColorItem aItem(SDRATTR_GLOW_COLOR, mxLBGlowColor->GetSelectEntryColor());
82     mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_COLOR, SfxCallMode::RECORD, { &aItem });
83 }
84 
IMPL_LINK_NOARG(EffectPropertyPanel,ModifyGlowRadiusHdl,weld::MetricSpinButton &,void)85 IMPL_LINK_NOARG(EffectPropertyPanel, ModifyGlowRadiusHdl, weld::MetricSpinButton&, void)
86 {
87     SdrMetricItem aItem(SDRATTR_GLOW_RADIUS, mxGlowRadius->get_value(FieldUnit::MM_100TH));
88     mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_RADIUS, SfxCallMode::RECORD, { &aItem });
89 }
90 
IMPL_LINK_NOARG(EffectPropertyPanel,ModifyGlowTransparencyHdl,weld::MetricSpinButton &,void)91 IMPL_LINK_NOARG(EffectPropertyPanel, ModifyGlowTransparencyHdl, weld::MetricSpinButton&, void)
92 {
93     SdrPercentItem aItem(SDRATTR_GLOW_TRANSPARENCY,
94                          mxGlowTransparency->get_value(FieldUnit::PERCENT));
95     mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_TRANSPARENCY, SfxCallMode::RECORD,
96                                              { &aItem });
97 }
98 
UpdateControls()99 void EffectPropertyPanel::UpdateControls()
100 {
101     const bool bEnabled = mxGlowRadius->get_value(FieldUnit::MM_100TH) != 0;
102     mxLBGlowColor->set_sensitive(bEnabled);
103     mxGlowTransparency->set_sensitive(bEnabled);
104     mxFTColor->set_sensitive(bEnabled);
105     mxFTTransparency->set_sensitive(bEnabled);
106 }
107 
NotifyItemUpdate(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pState)108 void EffectPropertyPanel::NotifyItemUpdate(sal_uInt16 nSID, SfxItemState eState,
109                                            const SfxPoolItem* pState)
110 {
111     switch (nSID)
112     {
113         case SID_ATTR_SOFTEDGE_RADIUS:
114         {
115             if (eState >= SfxItemState::DEFAULT)
116             {
117                 const SdrMetricItem* pRadiusItem = dynamic_cast<const SdrMetricItem*>(pState);
118                 if (pRadiusItem)
119                 {
120                     mxSoftEdgeRadius->set_value(pRadiusItem->GetValue(), FieldUnit::MM_100TH);
121                 }
122             }
123         }
124         break;
125         case SID_ATTR_GLOW_COLOR:
126         {
127             if (eState >= SfxItemState::DEFAULT)
128             {
129                 const XColorItem* pColorItem = dynamic_cast<const XColorItem*>(pState);
130                 if (pColorItem)
131                 {
132                     mxLBGlowColor->SelectEntry(pColorItem->GetColorValue());
133                 }
134             }
135         }
136         break;
137         case SID_ATTR_GLOW_RADIUS:
138         {
139             if (eState >= SfxItemState::DEFAULT)
140             {
141                 const SdrMetricItem* pRadiusItem = dynamic_cast<const SdrMetricItem*>(pState);
142                 if (pRadiusItem)
143                 {
144                     mxGlowRadius->set_value(pRadiusItem->GetValue(), FieldUnit::MM_100TH);
145                 }
146             }
147         }
148         break;
149         case SID_ATTR_GLOW_TRANSPARENCY:
150         {
151             if (eState >= SfxItemState::DEFAULT)
152             {
153                 if (auto pItem = dynamic_cast<const SdrPercentItem*>(pState))
154                 {
155                     mxGlowTransparency->set_value(pItem->GetValue(), FieldUnit::PERCENT);
156                 }
157             }
158         }
159         break;
160     }
161     UpdateControls();
162 }
163 
Create(weld::Widget * pParent,SfxBindings * pBindings)164 std::unique_ptr<PanelLayout> EffectPropertyPanel::Create(weld::Widget* pParent,
165                                                          SfxBindings* pBindings)
166 {
167     if (pParent == nullptr)
168         throw css::lang::IllegalArgumentException(
169             "no parent Window given to EffectPropertyPanel::Create", nullptr, 0);
170     if (pBindings == nullptr)
171         throw css::lang::IllegalArgumentException(
172             "no SfxBindings given to EffectPropertyPanel::Create", nullptr, 2);
173 
174     return std::make_unique<EffectPropertyPanel>(pParent, pBindings);
175 }
176 }
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
179