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 
25 using namespace css;
26 using namespace css::uno;
27 
28 namespace svx::sidebar {
29 
30 ShadowPropertyPanel::ShadowPropertyPanel(
31  vcl::Window* pParent,
32  const uno::Reference<css::frame::XFrame>& rxFrame,
33  SfxBindings* pBindings)
34 : PanelLayout(pParent, "ShadowPropertyPanel", "svx/ui/sidebarshadow.ui", rxFrame, true),
35  maShadowController(SID_ATTR_FILL_SHADOW, *pBindings, *this),
36  maShadowTransController(SID_ATTR_SHADOW_TRANSPARENCE, *pBindings, *this),
37  maShadowColorController(SID_ATTR_SHADOW_COLOR, *pBindings, *this),
38  maShadowXDistanceController(SID_ATTR_SHADOW_XDISTANCE, *pBindings, *this),
39  maShadowYDistanceController(SID_ATTR_SHADOW_YDISTANCE, *pBindings, *this),
40  mpBindings(pBindings),
41  nX(0),
42  nY(0),
43  nXY(0),
44  mxShowShadow(m_xBuilder->weld_check_button("SHOW_SHADOW")),
45  mxShadowDistance(m_xBuilder->weld_metric_spin_button("LB_DISTANCE", FieldUnit::POINT)),
46  mxLBShadowColor(new ColorListBox(m_xBuilder->weld_menu_button("LB_SHADOW_COLOR"), GetFrameWeld())),
47  mxShadowAngle(m_xBuilder->weld_combo_box("LB_ANGLE")),
48  mxFTAngle(m_xBuilder->weld_label("angle")),
49  mxFTDistance(m_xBuilder->weld_label("distance")),
50  mxFTTransparency(m_xBuilder->weld_label("transparency_label")),
51  mxFTColor(m_xBuilder->weld_label("color")),
52  mxShadowTransSlider(m_xBuilder->weld_scale("transparency_slider")),
53  mxShadowTransMetric(m_xBuilder->weld_metric_spin_button("FIELD_TRANSPARENCY", FieldUnit::PERCENT))
54 {
55  Initialize();
56 }
57 
59 {
60  disposeOnce();
61 }
62 
64 {
65  mxShowShadow.reset();
66  mxFTAngle.reset();
67  mxShadowAngle.reset();
68  mxFTDistance.reset();
69  mxShadowDistance.reset();
70  mxFTTransparency.reset();
71  mxShadowTransSlider.reset();
72  mxShadowTransMetric.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) );
95 }
96 
98 {
99  if( mxShowShadow->get_state() == TRISTATE_FALSE )
100  {
101  SdrOnOffItem aItem(makeSdrShadowItem(false));
102  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_FILL_SHADOW,
103  SfxCallMode::RECORD, { &aItem });
104  }
105  else
106  {
107  SdrOnOffItem aItem(makeSdrShadowItem(true));
108  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_FILL_SHADOW,
109  SfxCallMode::RECORD, { &aItem });
110  }
111 }
112 
113 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowColorHdl, ColorListBox&, void)
114 {
115  XColorItem aItem(makeSdrShadowColorItem(mxLBShadowColor->GetSelectEntryColor()));
116  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_COLOR,
117  SfxCallMode::RECORD, { &aItem });
118 }
119 
120 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowTransMetricHdl, weld::MetricSpinButton&, void)
121 {
122  sal_uInt16 nVal = mxShadowTransMetric->get_value(FieldUnit::PERCENT);
123  SetTransparencyValue(nVal);
125  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_TRANSPARENCE,
126  SfxCallMode::RECORD, { &aItem });
127 }
128 
129 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowTransSliderHdl, weld::Scale&, void)
130 {
131  sal_uInt16 nVal = mxShadowTransSlider->get_value();
132  SetTransparencyValue(nVal);
134  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_TRANSPARENCE,
135  SfxCallMode::RECORD, { &aItem });
136 }
137 
138 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowAngleHdl, weld::ComboBox&, void)
139 {
140  ModifyShadowDistance();
141 }
142 
144 {
145  ModifyShadowDistance();
146 }
147 
149 {
150  auto nAngle = mxShadowAngle->get_active_id().toInt32();
151  nXY = mxShadowDistance->get_value(FieldUnit::MM_100TH);
152  switch (nAngle)
153  {
154  case 0: nX = nXY; nY = 0; break;
155  case 45: nX = nXY; nY = -nXY; break;
156  case 90: nX = 0; nY = - nXY; break;
157  case 135: nX = nY = -nXY; break;
158  case 180: nX = -nXY; nY = 0; break;
159  case 225: nX = -nXY; nY = nXY; break;
160  case 270: nX = 0; nY = nXY; break;
161  case 315: nX = nY = nXY; break;
162  }
165  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_XDISTANCE,
166  SfxCallMode::RECORD, { &aXItem });
167  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_YDISTANCE,
168  SfxCallMode::RECORD, { &aYItem });
169 }
170 
172 {
173  if (mxShowShadow->get_state() == TRISTATE_FALSE)
174  {
175  mxShadowDistance->set_sensitive(false);
176  mxLBShadowColor->set_sensitive(false);
177  mxShadowAngle->set_sensitive(false);
178  mxFTAngle->set_sensitive(false);
179  mxFTDistance->set_sensitive(false);
180  mxFTTransparency->set_sensitive(false);
181  mxFTColor->set_sensitive(false);
182  mxShadowTransSlider->set_sensitive(false);
183  mxShadowTransMetric->set_sensitive(false);
184  return;
185  }
186  else
187  {
188  mxShadowDistance->set_sensitive(true);
189  mxLBShadowColor->set_sensitive(true);
190  mxShadowAngle->set_sensitive(true);
191  mxFTAngle->set_sensitive(true);
192  mxFTDistance->set_sensitive(true);
193  mxFTTransparency->set_sensitive(true);
194  mxFTColor->set_sensitive(true);
195  mxShadowTransSlider->set_sensitive(true);
196  mxShadowTransMetric->set_sensitive(true);
197  }
198 
199  if(nX > 0 && nY == 0) { mxShadowAngle->set_active(0); nXY = nX; }
200  else if( nX > 0 && nY < 0 ) { mxShadowAngle->set_active(1); nXY = nX; }
201  else if( nX == 0 && nY < 0 ) { mxShadowAngle->set_active(2); nXY = -nY; }
202  else if( nX < 0 && nY < 0 ) { mxShadowAngle->set_active(3); nXY = -nY; }
203  else if( nX < 0 && nY == 0 ) { mxShadowAngle->set_active(4); nXY = -nX; }
204  else if( nX < 0 && nY > 0 ) { mxShadowAngle->set_active(5); nXY = nY; }
205  else if( nX == 0 && nY > 0 ) { mxShadowAngle->set_active(6); nXY = nY; }
206  else if( nX > 0 && nY > 0 ) { mxShadowAngle->set_active(7); nXY = nX; }
207  else { nXY = 0; }
208  mxShadowDistance->set_value(nXY, FieldUnit::MM_100TH);
209 }
210 
212 {
213  mxShadowTransSlider->set_value(nVal);
214  mxShadowTransMetric->set_value(nVal, FieldUnit::PERCENT);
215 }
216 
218 {
219 }
220 
222 {
223  OUString sSuffix = weld::MetricSpinButton::MetricToString(FieldUnit::DEGREE);
224 
226 
227  mxShadowAngle->append(OUString::number(0), rLocaleData.getNum(0, 0, true, true) + sSuffix);
228  mxShadowAngle->append(OUString::number(45), rLocaleData.getNum(45, 0, true, true) + sSuffix);
229  mxShadowAngle->append(OUString::number(90), rLocaleData.getNum(90, 0, true, true) + sSuffix);
230  mxShadowAngle->append(OUString::number(135), rLocaleData.getNum(135, 0, true, true) + sSuffix);
231  mxShadowAngle->append(OUString::number(180), rLocaleData.getNum(180, 0, true, true) + sSuffix);
232  mxShadowAngle->append(OUString::number(225), rLocaleData.getNum(225, 0, true, true) + sSuffix);
233  mxShadowAngle->append(OUString::number(270), rLocaleData.getNum(270, 0, true, true) + sSuffix);
234  mxShadowAngle->append(OUString::number(315), rLocaleData.getNum(315, 0, true, true) + sSuffix);
235 }
236 
238  sal_uInt16 nSID,
239  SfxItemState eState,
240  const SfxPoolItem* pState)
241 {
242  switch(nSID)
243  {
244  case SID_ATTR_FILL_SHADOW:
245  {
246  if(eState >= SfxItemState::DEFAULT)
247  {
248  const SdrOnOffItem* pItem = dynamic_cast< const SdrOnOffItem* >(pState);
249  if(pItem)
250  {
251  if (pItem->GetValue())
252  mxShowShadow->set_state(TRISTATE_TRUE);
253  else
254  mxShowShadow->set_state(TRISTATE_FALSE);
255  }
256  else
257  mxShowShadow.reset();
258  }
259  }
260  break;
261 
262  case SID_ATTR_SHADOW_TRANSPARENCE:
263  {
264  if(eState >= SfxItemState::DEFAULT)
265  {
266  const SdrPercentItem* pTransparencyItem = dynamic_cast< const SdrPercentItem* >(pState);
267  if(pTransparencyItem)
268  {
269  const sal_uInt16 nVal = pTransparencyItem->GetValue();
270  SetTransparencyValue(nVal);
271  }
272  else
274  }
275  }
276  break;
277 
278  case SID_ATTR_SHADOW_COLOR:
279  {
280  if(eState >= SfxItemState::DEFAULT)
281  {
282  const XColorItem* pColorItem = dynamic_cast< const XColorItem* >(pState);
283  if(pColorItem)
284  {
285  mxLBShadowColor->SelectEntry(pColorItem->GetColorValue());
286  }
287  }
288  }
289  break;
290  case SID_ATTR_SHADOW_XDISTANCE:
291  {
292  if(eState >= SfxItemState::DEFAULT)
293  {
294  const SdrMetricItem* pXDistItem = dynamic_cast< const SdrMetricItem* >(pState);
295  if(pXDistItem)
296  {
297  nX = pXDistItem->GetValue();
298  }
299  }
300  }
301  break;
302  case SID_ATTR_SHADOW_YDISTANCE:
303  {
304  if(eState >= SfxItemState::DEFAULT)
305  {
306  const SdrMetricItem* pYDistItem = dynamic_cast< const SdrMetricItem* >(pState);
307  if(pYDistItem)
308  {
309  nY = pYDistItem->GetValue();
310  }
311  }
312  }
313  break;
314  }
315  UpdateControls();
316 }
317 
319  vcl::Window* pParent,
320  const uno::Reference<css::frame::XFrame>& rxFrame,
321  SfxBindings* pBindings)
322 {
323  if(pParent == nullptr)
324  throw lang::IllegalArgumentException("no parent Window given to ShadowPropertyPanel::Create", nullptr, 0);
325  if( !rxFrame.is() )
326  throw lang::IllegalArgumentException("no XFrame given to ShadowPropertyPanel::Create", nullptr, 1);
327  if(pBindings == nullptr)
328  throw lang::IllegalArgumentException("no SfxBindings given to ShadowPropertyPanel::Create", nullptr, 2);
329 
330  return VclPtr<ShadowPropertyPanel>::Create(pParent, rxFrame, pBindings);
331 }
332 }
333 
334 /* 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)
This class is the base for the Widget Layout-based sidebar panels.
Definition: PanelLayout.hxx:24
::sfx2::sidebar::ControllerItem maShadowColorController
::sfx2::sidebar::ControllerItem maShadowTransController
std::unique_ptr< weld::Label > mxFTColor
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
const Color & GetColorValue() const
Definition: xattr.cxx:309
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
virtual void DataChanged(const DataChangedEvent &rEvent) override
SdrMetricItem makeSdrShadowYDistItem(long nDist)
Definition: sdsxyitm.hxx:29
virtual void dispose() override
Definition: PanelLayout.cxx:50
std::unique_ptr< weld::ComboBox > mxShadowAngle
SfxItemState
::sfx2::sidebar::ControllerItem maShadowYDistanceController
static VclPtr< reference_type > Create(Arg &&...arg)
const OUString PERCENT("Percent")
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