LibreOffice Module svx (master)  1
ShadowPropertyPanel.cxx
Go to the documentation of this file.
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 "ShadowPropertyPanel.hxx"
11 #include <vcl/settings.hxx>
12 #include <vcl/svapp.hxx>
13 #include <svx/colorbox.hxx>
14 #include <svx/svxids.hrc>
15 #include <sfx2/bindings.hxx>
16 #include <sfx2/dispatch.hxx>
18 #include <svx/sdooitm.hxx>
19 #include <svx/sdshitm.hxx>
20 #include <svx/sdshtitm.hxx>
21 #include <svx/sdprcitm.hxx>
22 #include <svx/sdsxyitm.hxx>
23 #include <svx/sdshcitm.hxx>
24 #include <comphelper/lok.hxx>
25 
26 using namespace css;
27 using namespace css::uno;
28 
29 namespace svx::sidebar {
30 
31 ShadowPropertyPanel::ShadowPropertyPanel(
32  weld::Widget* pParent,
33  SfxBindings* pBindings)
34 : PanelLayout(pParent, "ShadowPropertyPanel", "svx/ui/sidebarshadow.ui"),
35  maShadowController(SID_ATTR_FILL_SHADOW, *pBindings, *this),
36  maShadowTransController(SID_ATTR_SHADOW_TRANSPARENCE, *pBindings, *this),
37  maShadowBlurController(SID_ATTR_SHADOW_BLUR, *pBindings, *this),
38  maShadowColorController(SID_ATTR_SHADOW_COLOR, *pBindings, *this),
39  maShadowXDistanceController(SID_ATTR_SHADOW_XDISTANCE, *pBindings, *this),
40  maShadowYDistanceController(SID_ATTR_SHADOW_YDISTANCE, *pBindings, *this),
41  mpBindings(pBindings),
42  nX(0),
43  nY(0),
44  nXY(0),
45  mxShowShadow(m_xBuilder->weld_check_button("SHOW_SHADOW")),
46  mxShadowDistance(m_xBuilder->weld_metric_spin_button("LB_DISTANCE", FieldUnit::POINT)),
47  mxLBShadowColor(new ColorListBox(m_xBuilder->weld_menu_button("LB_SHADOW_COLOR"), [this]{ return GetFrameWeld(); })),
48  mxShadowAngle(m_xBuilder->weld_combo_box("LB_ANGLE")),
49  mxFTAngle(m_xBuilder->weld_label("angle")),
50  mxFTDistance(m_xBuilder->weld_label("distance")),
51  mxFTTransparency(m_xBuilder->weld_label("transparency_label")),
52  mxFTBlur(m_xBuilder->weld_label("blur_label")),
53  mxFTColor(m_xBuilder->weld_label("color")),
54  mxShadowTransSlider(m_xBuilder->weld_scale("transparency_slider")),
55  mxShadowTransMetric(m_xBuilder->weld_metric_spin_button("FIELD_TRANSPARENCY", FieldUnit::PERCENT)),
56  mxShadowBlurMetric(m_xBuilder->weld_metric_spin_button("LB_SHADOW_BLUR", FieldUnit::POINT))
57 {
58  Initialize();
59 }
60 
62 {
63  mxShowShadow.reset();
64  mxFTAngle.reset();
65  mxShadowAngle.reset();
66  mxFTDistance.reset();
67  mxShadowDistance.reset();
68  mxFTTransparency.reset();
69  mxShadowTransSlider.reset();
70  mxShadowTransMetric.reset();
71  mxShadowBlurMetric.reset();
72  mxFTBlur.reset();
73  mxFTColor.reset();
74  mxLBShadowColor.reset();
75 
82 }
83 
85 {
86  mxShowShadow->set_state( TRISTATE_FALSE );
87  mxShowShadow->connect_toggled( LINK(this, ShadowPropertyPanel, ClickShadowHdl ) );
88  mxShadowTransMetric->connect_value_changed( LINK(this, ShadowPropertyPanel, ModifyShadowTransMetricHdl) );
89  mxLBShadowColor->SetSelectHdl( LINK( this, ShadowPropertyPanel, ModifyShadowColorHdl ) );
90  mxShadowAngle->connect_changed( LINK(this, ShadowPropertyPanel, ModifyShadowAngleHdl) );
91  mxShadowDistance->connect_value_changed( LINK(this, ShadowPropertyPanel, ModifyShadowDistanceHdl) );
92  mxShadowTransSlider->set_range(0, 100);
93  mxShadowTransSlider->connect_value_changed( LINK(this, ShadowPropertyPanel, ModifyShadowTransSliderHdl) );
94  mxShadowBlurMetric->set_range(0, 150, FieldUnit::POINT);
95  mxShadowBlurMetric->connect_value_changed(LINK(this, ShadowPropertyPanel, ModifyShadowBlurMetricHdl));
97 }
98 
100 {
101  if( mxShowShadow->get_state() == TRISTATE_FALSE )
102  {
103  SdrOnOffItem aItem(makeSdrShadowItem(false));
104  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_FILL_SHADOW,
105  SfxCallMode::RECORD, { &aItem });
106 
108  {
109  mxShowShadow->set_state( TRISTATE_FALSE );
110  UpdateControls();
111  }
112  }
113  else
114  {
115  SdrOnOffItem aItem(makeSdrShadowItem(true));
116  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_FILL_SHADOW,
117  SfxCallMode::RECORD, { &aItem });
118 
119  if (mxShadowDistance->get_value(FieldUnit::POINT) == 0)
120  mxShadowDistance->set_value( 8, FieldUnit::POINT );
121 
123  {
124  mxShowShadow->set_state( TRISTATE_TRUE );
125  UpdateControls();
126  }
127  }
128 }
129 
130 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowColorHdl, ColorListBox&, void)
131 {
132  XColorItem aItem(makeSdrShadowColorItem(mxLBShadowColor->GetSelectEntryColor()));
133  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_COLOR,
134  SfxCallMode::RECORD, { &aItem });
135 }
136 
137 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowTransMetricHdl, weld::MetricSpinButton&, void)
138 {
139  sal_uInt16 nVal = mxShadowTransMetric->get_value(FieldUnit::PERCENT);
140  SetTransparencyValue(nVal);
142  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_TRANSPARENCE,
143  SfxCallMode::RECORD, { &aItem });
144 }
145 
146 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowBlurMetricHdl, weld::MetricSpinButton&, void)
147 {
148  SdrMetricItem aItem(SDRATTR_SHADOWBLUR, mxShadowBlurMetric->get_value(FieldUnit::MM_100TH));
149 
150  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_BLUR, SfxCallMode::RECORD, { &aItem });
151 }
152 
153 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowTransSliderHdl, weld::Scale&, void)
154 {
155  sal_uInt16 nVal = mxShadowTransSlider->get_value();
156  SetTransparencyValue(nVal);
158  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_TRANSPARENCE,
159  SfxCallMode::RECORD, { &aItem });
160 }
161 
162 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowAngleHdl, weld::ComboBox&, void)
163 {
164  ModifyShadowDistance();
165 }
166 
168 {
169  ModifyShadowDistance();
170 }
171 
173 {
174  auto nAngle = mxShadowAngle->get_active_id().toInt32();
175  nXY = mxShadowDistance->get_value(FieldUnit::MM_100TH);
176  switch (nAngle)
177  {
178  case 0: nX = nXY; nY = 0; break;
179  case 45: nX = nXY; nY = -nXY; break;
180  case 90: nX = 0; nY = - nXY; break;
181  case 135: nX = nY = -nXY; break;
182  case 180: nX = -nXY; nY = 0; break;
183  case 225: nX = -nXY; nY = nXY; break;
184  case 270: nX = 0; nY = nXY; break;
185  case 315: nX = nY = nXY; break;
186  }
189  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_XDISTANCE,
190  SfxCallMode::RECORD, { &aXItem });
191  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_YDISTANCE,
192  SfxCallMode::RECORD, { &aYItem });
193 }
194 
196 {
197  if (mxShowShadow->get_state() == TRISTATE_FALSE)
198  {
199  mxShadowDistance->set_sensitive(false);
200  mxLBShadowColor->set_sensitive(false);
201  mxShadowAngle->set_sensitive(false);
202  mxFTAngle->set_sensitive(false);
203  mxFTDistance->set_sensitive(false);
204  mxFTTransparency->set_sensitive(false);
205  mxFTBlur->set_sensitive(false);
206  mxFTColor->set_sensitive(false);
207  mxShadowTransSlider->set_sensitive(false);
208  mxShadowTransMetric->set_sensitive(false);
209  mxShadowBlurMetric->set_sensitive(false);
210 
211  return;
212  }
213  else
214  {
215  mxShadowDistance->set_sensitive(true);
216  mxLBShadowColor->set_sensitive(true);
217  mxShadowAngle->set_sensitive(true);
218  mxFTAngle->set_sensitive(true);
219  mxFTDistance->set_sensitive(true);
220  mxFTTransparency->set_sensitive(true);
221  mxFTBlur->set_sensitive(true);
222  mxFTColor->set_sensitive(true);
223  mxShadowTransSlider->set_sensitive(true);
224  mxShadowTransMetric->set_sensitive(true);
225  mxShadowBlurMetric->set_sensitive(true);
226  }
227 
228  if(nX > 0 && nY == 0) { mxShadowAngle->set_active(0); nXY = nX; }
229  else if( nX > 0 && nY < 0 ) { mxShadowAngle->set_active(1); nXY = nX; }
230  else if( nX == 0 && nY < 0 ) { mxShadowAngle->set_active(2); nXY = -nY; }
231  else if( nX < 0 && nY < 0 ) { mxShadowAngle->set_active(3); nXY = -nY; }
232  else if( nX < 0 && nY == 0 ) { mxShadowAngle->set_active(4); nXY = -nX; }
233  else if( nX < 0 && nY > 0 ) { mxShadowAngle->set_active(5); nXY = nY; }
234  else if( nX == 0 && nY > 0 ) { mxShadowAngle->set_active(6); nXY = nY; }
235  else if( nX > 0 && nY > 0 ) { mxShadowAngle->set_active(7); nXY = nX; }
236  else { nXY = 0; }
237  mxShadowDistance->set_value(nXY, FieldUnit::MM_100TH);
238 }
239 
241 {
242  mxShadowTransSlider->set_value(nVal);
243  mxShadowTransMetric->set_value(nVal, FieldUnit::PERCENT);
244 }
245 
247 {
248  OUString sSuffix = weld::MetricSpinButton::MetricToString(FieldUnit::DEGREE);
249 
251 
252  mxShadowAngle->append(OUString::number(0), rLocaleData.getNum(0, 0, true, true) + sSuffix);
253  mxShadowAngle->append(OUString::number(45), rLocaleData.getNum(45, 0, true, true) + sSuffix);
254  mxShadowAngle->append(OUString::number(90), rLocaleData.getNum(90, 0, true, true) + sSuffix);
255  mxShadowAngle->append(OUString::number(135), rLocaleData.getNum(135, 0, true, true) + sSuffix);
256  mxShadowAngle->append(OUString::number(180), rLocaleData.getNum(180, 0, true, true) + sSuffix);
257  mxShadowAngle->append(OUString::number(225), rLocaleData.getNum(225, 0, true, true) + sSuffix);
258  mxShadowAngle->append(OUString::number(270), rLocaleData.getNum(270, 0, true, true) + sSuffix);
259  mxShadowAngle->append(OUString::number(315), rLocaleData.getNum(315, 0, true, true) + sSuffix);
260 }
261 
263  sal_uInt16 nSID,
264  SfxItemState eState,
265  const SfxPoolItem* pState)
266 {
267  switch(nSID)
268  {
269  case SID_ATTR_FILL_SHADOW:
270  {
271  if(eState >= SfxItemState::DEFAULT)
272  {
273  const SdrOnOffItem* pItem = dynamic_cast< const SdrOnOffItem* >(pState);
274  if(pItem)
275  {
276  if (pItem->GetValue())
277  mxShowShadow->set_state(TRISTATE_TRUE);
278  else
279  mxShowShadow->set_state(TRISTATE_FALSE);
280  }
281  else
282  mxShowShadow.reset();
283  }
284  }
285  break;
286 
287  case SID_ATTR_SHADOW_TRANSPARENCE:
288  {
289  if(eState >= SfxItemState::DEFAULT)
290  {
291  const SdrPercentItem* pTransparencyItem = dynamic_cast< const SdrPercentItem* >(pState);
292  if(pTransparencyItem)
293  {
294  const sal_uInt16 nVal = pTransparencyItem->GetValue();
295  SetTransparencyValue(nVal);
296  }
297  else
299  }
300  }
301  break;
302  case SID_ATTR_SHADOW_BLUR:
303  {
304  if (eState >= SfxItemState::DEFAULT)
305  {
306  const SdrMetricItem* pRadiusItem = dynamic_cast<const SdrMetricItem*>(pState);
307  if (pRadiusItem)
308  {
309  mxShadowBlurMetric->set_value(pRadiusItem->GetValue(), FieldUnit::MM_100TH);
310  }
311  }
312  }
313  break;
314  case SID_ATTR_SHADOW_COLOR:
315  {
316  if(eState >= SfxItemState::DEFAULT)
317  {
318  const XColorItem* pColorItem = dynamic_cast< const XColorItem* >(pState);
319  if(pColorItem)
320  {
321  mxLBShadowColor->SelectEntry(pColorItem->GetColorValue());
322  }
323  }
324  }
325  break;
326  case SID_ATTR_SHADOW_XDISTANCE:
327  {
328  if(eState >= SfxItemState::DEFAULT)
329  {
330  const SdrMetricItem* pXDistItem = dynamic_cast< const SdrMetricItem* >(pState);
331  if(pXDistItem)
332  {
333  nX = pXDistItem->GetValue();
334  }
335  }
336  }
337  break;
338  case SID_ATTR_SHADOW_YDISTANCE:
339  {
340  if(eState >= SfxItemState::DEFAULT)
341  {
342  const SdrMetricItem* pYDistItem = dynamic_cast< const SdrMetricItem* >(pState);
343  if(pYDistItem)
344  {
345  nY = pYDistItem->GetValue();
346  }
347  }
348  }
349  break;
350  }
351  UpdateControls();
352 }
353 
354 std::unique_ptr<PanelLayout> ShadowPropertyPanel::Create (
355  weld::Widget* pParent,
356  SfxBindings* pBindings)
357 {
358  if(pParent == nullptr)
359  throw lang::IllegalArgumentException("no parent Window given to ShadowPropertyPanel::Create", nullptr, 0);
360  if(pBindings == nullptr)
361  throw lang::IllegalArgumentException("no SfxBindings given to ShadowPropertyPanel::Create", nullptr, 2);
362 
363  return std::make_unique<ShadowPropertyPanel>(pParent, pBindings);
364 }
365 }
366 
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Label > mxFTDistance
bool GetValue() const
std::unique_ptr< weld::CheckButton > mxShowShadow
std::unique_ptr< ColorListBox > mxLBShadowColor
sal_Int32 GetValue() const
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
FieldUnit
const LocaleDataWrapper & GetLocaleDataWrapper() const
SdrMetricItem makeSdrShadowYDistItem(tools::Long nDist)
Definition: sdsxyitm.hxx:30
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
::sfx2::sidebar::ControllerItem maShadowColorController
std::unique_ptr< weld::MetricSpinButton > mxShadowBlurMetric
::sfx2::sidebar::ControllerItem maShadowTransController
std::unique_ptr< weld::Label > mxFTColor
long Long
static const AllSettings & GetSettings()
sal_uInt16 GetValue() const
TRISTATE_TRUE
static OUString MetricToString(FieldUnit rUnit)
std::unique_ptr< weld::Label > mxFTTransparency
OUString sSuffix
std::unique_ptr< weld::Label > mxFTAngle
::sfx2::sidebar::ControllerItem maShadowBlurController
const Color & GetColorValue() const
Definition: xattr.cxx:295
constexpr TypedWhichId< SdrMetricItem > SDRATTR_SHADOWBLUR(SDRATTR_SHADOW_FIRST+9)
std::unique_ptr< weld::Scale > mxShadowTransSlider
std::unique_ptr< weld::MetricSpinButton > mxShadowDistance
XColorItem makeSdrShadowColorItem(const Color &rTheColor)
Definition: sdshcitm.hxx:25
std::unique_ptr< weld::MetricSpinButton > mxShadowTransMetric
::sfx2::sidebar::ControllerItem maShadowXDistanceController
virtual void dispose()
SdrPercentItem makeSdrShadowTransparenceItem(sal_uInt16 nTransp)
Definition: sdshtitm.hxx:25
TRISTATE_FALSE
::sfx2::sidebar::ControllerItem maShadowController
std::unique_ptr< weld::Label > mxFTBlur
std::unique_ptr< weld::ComboBox > mxShadowAngle
SfxItemState
::sfx2::sidebar::ControllerItem maShadowYDistanceController
SdrMetricItem makeSdrShadowXDistItem(tools::Long nDist)
Definition: sdsxyitm.hxx:25
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
SdrOnOffItem makeSdrShadowItem(bool bShadow)
Definition: sdshitm.hxx:25
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
SfxDispatcher * GetDispatcher() const
virtual weld::Window * GetFrameWeld() const
OUString getNum(sal_Int64 nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const