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
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
26using namespace css;
27using namespace css::uno;
28
29namespace svx::sidebar {
30
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("shadowcolorlabel")),
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
131{
132 XColorItem aItem(makeSdrShadowColorItem(mxLBShadowColor->GetSelectEntryColor()));
133 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_COLOR,
134 SfxCallMode::RECORD, { &aItem });
135}
136
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
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
153IMPL_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
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 && pItem->GetValue())
275 mxShowShadow->set_state(TRISTATE_TRUE);
276 else
277 mxShowShadow->set_state(TRISTATE_FALSE);
278 }
279 }
280 break;
281
282 case SID_ATTR_SHADOW_TRANSPARENCE:
283 {
284 if(eState >= SfxItemState::DEFAULT)
285 {
286 const SdrPercentItem* pTransparencyItem = dynamic_cast< const SdrPercentItem* >(pState);
287 if(pTransparencyItem)
288 {
289 const sal_uInt16 nVal = pTransparencyItem->GetValue();
291 }
292 else
294 }
295 }
296 break;
297 case SID_ATTR_SHADOW_BLUR:
298 {
299 if (eState >= SfxItemState::DEFAULT)
300 {
301 const SdrMetricItem* pRadiusItem = dynamic_cast<const SdrMetricItem*>(pState);
302 if (pRadiusItem)
303 {
304 mxShadowBlurMetric->set_value(pRadiusItem->GetValue(), FieldUnit::MM_100TH);
305 }
306 }
307 }
308 break;
309 case SID_ATTR_SHADOW_COLOR:
310 {
311 if(eState >= SfxItemState::DEFAULT)
312 {
313 const XColorItem* pColorItem = dynamic_cast< const XColorItem* >(pState);
314 if(pColorItem)
315 {
316 mxLBShadowColor->SelectEntry(pColorItem->GetColorValue());
317 }
318 }
319 }
320 break;
321 case SID_ATTR_SHADOW_XDISTANCE:
322 {
323 if(eState >= SfxItemState::DEFAULT)
324 {
325 const SdrMetricItem* pXDistItem = dynamic_cast< const SdrMetricItem* >(pState);
326 if(pXDistItem)
327 {
328 nX = pXDistItem->GetValue();
329 }
330 }
331 }
332 break;
333 case SID_ATTR_SHADOW_YDISTANCE:
334 {
335 if(eState >= SfxItemState::DEFAULT)
336 {
337 const SdrMetricItem* pYDistItem = dynamic_cast< const SdrMetricItem* >(pState);
338 if(pYDistItem)
339 {
340 nY = pYDistItem->GetValue();
341 }
342 }
343 }
344 break;
345 }
347}
348
349std::unique_ptr<PanelLayout> ShadowPropertyPanel::Create (
350 weld::Widget* pParent,
351 SfxBindings* pBindings)
352{
353 if(pParent == nullptr)
354 throw lang::IllegalArgumentException("no parent Window given to ShadowPropertyPanel::Create", nullptr, 0);
355 if(pBindings == nullptr)
356 throw lang::IllegalArgumentException("no SfxBindings given to ShadowPropertyPanel::Create", nullptr, 2);
357
358 return std::make_unique<ShadowPropertyPanel>(pParent, pBindings);
359}
360}
361
362/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const LocaleDataWrapper & GetLocaleDataWrapper() const
static const AllSettings & GetSettings()
sal_Int32 GetValue() const
sal_uInt16 GetValue() const
OUString getNum(sal_Int64 nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
virtual weld::Window * GetFrameWeld() const
SfxDispatcher * GetDispatcher() const
bool GetValue() const
virtual void dispose()
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 * >())
const Color & GetColorValue() const
Definition: xattr.cxx:302
std::unique_ptr< weld::Label > mxFTColor
::sfx2::sidebar::ControllerItem maShadowTransController
std::unique_ptr< weld::Label > mxFTTransparency
std::unique_ptr< weld::Label > mxFTDistance
::sfx2::sidebar::ControllerItem maShadowXDistanceController
std::unique_ptr< weld::MetricSpinButton > mxShadowDistance
std::unique_ptr< weld::MetricSpinButton > mxShadowTransMetric
std::unique_ptr< ColorListBox > mxLBShadowColor
std::unique_ptr< weld::Scale > mxShadowTransSlider
std::unique_ptr< weld::MetricSpinButton > mxShadowBlurMetric
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
::sfx2::sidebar::ControllerItem maShadowYDistanceController
ShadowPropertyPanel(weld::Widget *pParent, SfxBindings *pBindings)
std::unique_ptr< weld::Label > mxFTBlur
std::unique_ptr< weld::Label > mxFTAngle
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
std::unique_ptr< weld::CheckButton > mxShowShadow
::sfx2::sidebar::ControllerItem maShadowBlurController
::sfx2::sidebar::ControllerItem maShadowColorController
::sfx2::sidebar::ControllerItem maShadowController
std::unique_ptr< weld::ComboBox > mxShadowAngle
static OUString MetricToString(FieldUnit rUnit)
virtual SfxBindings & GetBindings() override
FieldUnit
TRISTATE_FALSE
TRISTATE_TRUE
OUString sSuffix
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OUString &, void)
long Long
SfxItemState
XColorItem makeSdrShadowColorItem(const Color &rTheColor)
Definition: sdshcitm.hxx:25
SdrOnOffItem makeSdrShadowItem(bool bShadow)
Definition: sdshitm.hxx:25
SdrPercentItem makeSdrShadowTransparenceItem(sal_uInt16 nTransp)
Definition: sdshtitm.hxx:25
SdrMetricItem makeSdrShadowXDistItem(tools::Long nDist)
Definition: sdsxyitm.hxx:25
SdrMetricItem makeSdrShadowYDistItem(tools::Long nDist)
Definition: sdsxyitm.hxx:30
constexpr TypedWhichId< SdrMetricItem > SDRATTR_SHADOWBLUR(SDRATTR_SHADOW_FIRST+9)