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  vcl::Window* pParent,
33  const uno::Reference<css::frame::XFrame>& rxFrame,
34  SfxBindings* pBindings)
35 : PanelLayout(pParent, "ShadowPropertyPanel", "svx/ui/sidebarshadow.ui", rxFrame),
36  maShadowController(SID_ATTR_FILL_SHADOW, *pBindings, *this),
37  maShadowTransController(SID_ATTR_SHADOW_TRANSPARENCE, *pBindings, *this),
38  maShadowBlurController(SID_ATTR_SHADOW_BLUR, *pBindings, *this),
39  maShadowColorController(SID_ATTR_SHADOW_COLOR, *pBindings, *this),
40  maShadowXDistanceController(SID_ATTR_SHADOW_XDISTANCE, *pBindings, *this),
41  maShadowYDistanceController(SID_ATTR_SHADOW_YDISTANCE, *pBindings, *this),
42  mpBindings(pBindings),
43  nX(0),
44  nY(0),
45  nXY(0),
46  mxShowShadow(m_xBuilder->weld_check_button("SHOW_SHADOW")),
47  mxShadowDistance(m_xBuilder->weld_metric_spin_button("LB_DISTANCE", FieldUnit::POINT)),
48  mxLBShadowColor(new ColorListBox(m_xBuilder->weld_menu_button("LB_SHADOW_COLOR"), GetFrameWeld())),
49  mxShadowAngle(m_xBuilder->weld_combo_box("LB_ANGLE")),
50  mxFTAngle(m_xBuilder->weld_label("angle")),
51  mxFTDistance(m_xBuilder->weld_label("distance")),
52  mxFTTransparency(m_xBuilder->weld_label("transparency_label")),
53  mxFTBlur(m_xBuilder->weld_label("blur_label")),
54  mxFTColor(m_xBuilder->weld_label("color")),
55  mxShadowTransSlider(m_xBuilder->weld_scale("transparency_slider")),
56  mxShadowTransMetric(m_xBuilder->weld_metric_spin_button("FIELD_TRANSPARENCY", FieldUnit::PERCENT)),
57  mxShadowBlurMetric(m_xBuilder->weld_metric_spin_button("LB_SHADOW_BLUR", FieldUnit::POINT))
58 {
59  Initialize();
60 }
61 
63 {
64  disposeOnce();
65 }
66 
68 {
69  mxShowShadow.reset();
70  mxFTAngle.reset();
71  mxShadowAngle.reset();
72  mxFTDistance.reset();
73  mxShadowDistance.reset();
74  mxFTTransparency.reset();
75  mxShadowTransSlider.reset();
76  mxShadowTransMetric.reset();
77  mxShadowBlurMetric.reset();
78  mxFTBlur.reset();
79  mxFTColor.reset();
80  mxLBShadowColor.reset();
81 
89 }
90 
92 {
93  mxShowShadow->set_state( TRISTATE_FALSE );
94  mxShowShadow->connect_toggled( LINK(this, ShadowPropertyPanel, ClickShadowHdl ) );
95  mxShadowTransMetric->connect_value_changed( LINK(this, ShadowPropertyPanel, ModifyShadowTransMetricHdl) );
96  mxLBShadowColor->SetSelectHdl( LINK( this, ShadowPropertyPanel, ModifyShadowColorHdl ) );
97  mxShadowAngle->connect_changed( LINK(this, ShadowPropertyPanel, ModifyShadowAngleHdl) );
98  mxShadowDistance->connect_value_changed( LINK(this, ShadowPropertyPanel, ModifyShadowDistanceHdl) );
99  mxShadowTransSlider->set_range(0, 100);
100  mxShadowTransSlider->connect_value_changed( LINK(this, ShadowPropertyPanel, ModifyShadowTransSliderHdl) );
101  mxShadowBlurMetric->set_range(0, 150, FieldUnit::POINT);
102  mxShadowBlurMetric->connect_value_changed(LINK(this, ShadowPropertyPanel, ModifyShadowBlurMetricHdl));
104 }
105 
107 {
108  if( mxShowShadow->get_state() == TRISTATE_FALSE )
109  {
110  SdrOnOffItem aItem(makeSdrShadowItem(false));
111  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_FILL_SHADOW,
112  SfxCallMode::RECORD, { &aItem });
113 
115  {
116  mxShowShadow->set_state( TRISTATE_FALSE );
117  UpdateControls();
118  }
119  }
120  else
121  {
122  SdrOnOffItem aItem(makeSdrShadowItem(true));
123  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_FILL_SHADOW,
124  SfxCallMode::RECORD, { &aItem });
125 
126  if (mxShadowDistance->get_value(FieldUnit::POINT) == 0)
127  mxShadowDistance->set_value( 8, FieldUnit::POINT );
128 
130  {
131  mxShowShadow->set_state( TRISTATE_TRUE );
132  UpdateControls();
133  }
134  }
135 }
136 
137 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowColorHdl, ColorListBox&, void)
138 {
139  XColorItem aItem(makeSdrShadowColorItem(mxLBShadowColor->GetSelectEntryColor()));
140  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_COLOR,
141  SfxCallMode::RECORD, { &aItem });
142 }
143 
144 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowTransMetricHdl, weld::MetricSpinButton&, void)
145 {
146  sal_uInt16 nVal = mxShadowTransMetric->get_value(FieldUnit::PERCENT);
147  SetTransparencyValue(nVal);
149  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_TRANSPARENCE,
150  SfxCallMode::RECORD, { &aItem });
151 }
152 
153 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowBlurMetricHdl, weld::MetricSpinButton&, void)
154 {
155  SdrMetricItem aItem(SDRATTR_SHADOWBLUR, mxShadowBlurMetric->get_value(FieldUnit::MM_100TH));
156 
157  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_BLUR, SfxCallMode::RECORD, { &aItem });
158 }
159 
160 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowTransSliderHdl, weld::Scale&, void)
161 {
162  sal_uInt16 nVal = mxShadowTransSlider->get_value();
163  SetTransparencyValue(nVal);
165  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_TRANSPARENCE,
166  SfxCallMode::RECORD, { &aItem });
167 }
168 
169 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowAngleHdl, weld::ComboBox&, void)
170 {
171  ModifyShadowDistance();
172 }
173 
175 {
176  ModifyShadowDistance();
177 }
178 
180 {
181  auto nAngle = mxShadowAngle->get_active_id().toInt32();
182  nXY = mxShadowDistance->get_value(FieldUnit::MM_100TH);
183  switch (nAngle)
184  {
185  case 0: nX = nXY; nY = 0; break;
186  case 45: nX = nXY; nY = -nXY; break;
187  case 90: nX = 0; nY = - nXY; break;
188  case 135: nX = nY = -nXY; break;
189  case 180: nX = -nXY; nY = 0; break;
190  case 225: nX = -nXY; nY = nXY; break;
191  case 270: nX = 0; nY = nXY; break;
192  case 315: nX = nY = nXY; break;
193  }
196  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_XDISTANCE,
197  SfxCallMode::RECORD, { &aXItem });
198  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_YDISTANCE,
199  SfxCallMode::RECORD, { &aYItem });
200 }
201 
203 {
204  if (mxShowShadow->get_state() == TRISTATE_FALSE)
205  {
206  mxShadowDistance->set_sensitive(false);
207  mxLBShadowColor->set_sensitive(false);
208  mxShadowAngle->set_sensitive(false);
209  mxFTAngle->set_sensitive(false);
210  mxFTDistance->set_sensitive(false);
211  mxFTTransparency->set_sensitive(false);
212  mxFTBlur->set_sensitive(false);
213  mxFTColor->set_sensitive(false);
214  mxShadowTransSlider->set_sensitive(false);
215  mxShadowTransMetric->set_sensitive(false);
216  mxShadowBlurMetric->set_sensitive(false);
217 
218  return;
219  }
220  else
221  {
222  mxShadowDistance->set_sensitive(true);
223  mxLBShadowColor->set_sensitive(true);
224  mxShadowAngle->set_sensitive(true);
225  mxFTAngle->set_sensitive(true);
226  mxFTDistance->set_sensitive(true);
227  mxFTTransparency->set_sensitive(true);
228  mxFTBlur->set_sensitive(true);
229  mxFTColor->set_sensitive(true);
230  mxShadowTransSlider->set_sensitive(true);
231  mxShadowTransMetric->set_sensitive(true);
232  mxShadowBlurMetric->set_sensitive(true);
233  }
234 
235  if(nX > 0 && nY == 0) { mxShadowAngle->set_active(0); nXY = nX; }
236  else if( nX > 0 && nY < 0 ) { mxShadowAngle->set_active(1); nXY = nX; }
237  else if( nX == 0 && nY < 0 ) { mxShadowAngle->set_active(2); nXY = -nY; }
238  else if( nX < 0 && nY < 0 ) { mxShadowAngle->set_active(3); nXY = -nY; }
239  else if( nX < 0 && nY == 0 ) { mxShadowAngle->set_active(4); nXY = -nX; }
240  else if( nX < 0 && nY > 0 ) { mxShadowAngle->set_active(5); nXY = nY; }
241  else if( nX == 0 && nY > 0 ) { mxShadowAngle->set_active(6); nXY = nY; }
242  else if( nX > 0 && nY > 0 ) { mxShadowAngle->set_active(7); nXY = nX; }
243  else { nXY = 0; }
244  mxShadowDistance->set_value(nXY, FieldUnit::MM_100TH);
245 }
246 
248 {
249  mxShadowTransSlider->set_value(nVal);
250  mxShadowTransMetric->set_value(nVal, FieldUnit::PERCENT);
251 }
252 
254 {
255 }
256 
258 {
259  OUString sSuffix = weld::MetricSpinButton::MetricToString(FieldUnit::DEGREE);
260 
262 
263  mxShadowAngle->append(OUString::number(0), rLocaleData.getNum(0, 0, true, true) + sSuffix);
264  mxShadowAngle->append(OUString::number(45), rLocaleData.getNum(45, 0, true, true) + sSuffix);
265  mxShadowAngle->append(OUString::number(90), rLocaleData.getNum(90, 0, true, true) + sSuffix);
266  mxShadowAngle->append(OUString::number(135), rLocaleData.getNum(135, 0, true, true) + sSuffix);
267  mxShadowAngle->append(OUString::number(180), rLocaleData.getNum(180, 0, true, true) + sSuffix);
268  mxShadowAngle->append(OUString::number(225), rLocaleData.getNum(225, 0, true, true) + sSuffix);
269  mxShadowAngle->append(OUString::number(270), rLocaleData.getNum(270, 0, true, true) + sSuffix);
270  mxShadowAngle->append(OUString::number(315), rLocaleData.getNum(315, 0, true, true) + sSuffix);
271 }
272 
274  sal_uInt16 nSID,
275  SfxItemState eState,
276  const SfxPoolItem* pState)
277 {
278  switch(nSID)
279  {
280  case SID_ATTR_FILL_SHADOW:
281  {
282  if(eState >= SfxItemState::DEFAULT)
283  {
284  const SdrOnOffItem* pItem = dynamic_cast< const SdrOnOffItem* >(pState);
285  if(pItem)
286  {
287  if (pItem->GetValue())
288  mxShowShadow->set_state(TRISTATE_TRUE);
289  else
290  mxShowShadow->set_state(TRISTATE_FALSE);
291  }
292  else
293  mxShowShadow.reset();
294  }
295  }
296  break;
297 
298  case SID_ATTR_SHADOW_TRANSPARENCE:
299  {
300  if(eState >= SfxItemState::DEFAULT)
301  {
302  const SdrPercentItem* pTransparencyItem = dynamic_cast< const SdrPercentItem* >(pState);
303  if(pTransparencyItem)
304  {
305  const sal_uInt16 nVal = pTransparencyItem->GetValue();
306  SetTransparencyValue(nVal);
307  }
308  else
310  }
311  }
312  break;
313  case SID_ATTR_SHADOW_BLUR:
314  {
315  if (eState >= SfxItemState::DEFAULT)
316  {
317  const SdrMetricItem* pRadiusItem = dynamic_cast<const SdrMetricItem*>(pState);
318  if (pRadiusItem)
319  {
320  mxShadowBlurMetric->set_value(pRadiusItem->GetValue(), FieldUnit::MM_100TH);
321  }
322  }
323  }
324  break;
325  case SID_ATTR_SHADOW_COLOR:
326  {
327  if(eState >= SfxItemState::DEFAULT)
328  {
329  const XColorItem* pColorItem = dynamic_cast< const XColorItem* >(pState);
330  if(pColorItem)
331  {
332  mxLBShadowColor->SelectEntry(pColorItem->GetColorValue());
333  }
334  }
335  }
336  break;
337  case SID_ATTR_SHADOW_XDISTANCE:
338  {
339  if(eState >= SfxItemState::DEFAULT)
340  {
341  const SdrMetricItem* pXDistItem = dynamic_cast< const SdrMetricItem* >(pState);
342  if(pXDistItem)
343  {
344  nX = pXDistItem->GetValue();
345  }
346  }
347  }
348  break;
349  case SID_ATTR_SHADOW_YDISTANCE:
350  {
351  if(eState >= SfxItemState::DEFAULT)
352  {
353  const SdrMetricItem* pYDistItem = dynamic_cast< const SdrMetricItem* >(pState);
354  if(pYDistItem)
355  {
356  nY = pYDistItem->GetValue();
357  }
358  }
359  }
360  break;
361  }
362  UpdateControls();
363 }
364 
366  vcl::Window* pParent,
367  const uno::Reference<css::frame::XFrame>& rxFrame,
368  SfxBindings* pBindings)
369 {
370  if(pParent == nullptr)
371  throw lang::IllegalArgumentException("no parent Window given to ShadowPropertyPanel::Create", nullptr, 0);
372  if( !rxFrame.is() )
373  throw lang::IllegalArgumentException("no XFrame given to ShadowPropertyPanel::Create", nullptr, 1);
374  if(pBindings == nullptr)
375  throw lang::IllegalArgumentException("no SfxBindings given to ShadowPropertyPanel::Create", nullptr, 2);
376 
377  return VclPtr<ShadowPropertyPanel>::Create(pParent, rxFrame, pBindings);
378 }
379 }
380 
381 /* 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
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
static const AllSettings & GetSettings()
constexpr OUStringLiteral PERCENT(u"Percent")
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:310
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
virtual void DataChanged(const DataChangedEvent &rEvent) override
SdrMetricItem makeSdrShadowYDistItem(long nDist)
Definition: sdsxyitm.hxx:29
virtual void dispose() override
std::unique_ptr< weld::ComboBox > mxShadowAngle
SfxItemState
::sfx2::sidebar::ControllerItem maShadowYDistanceController
static VclPtr< reference_type > Create(Arg &&...arg)
static VclPtr< vcl::Window > Create(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, 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
OUString getNum(sal_Int64 nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
SdrMetricItem makeSdrShadowXDistItem(long nDist)
Definition: sdsxyitm.hxx:25