tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / svx / source / sidebar / shadow / ShadowPropertyPanel.cxx
blobd106133a9dd8a6bdc309589ede9a6515fdb0dcfc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
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>
17 #include <unotools/localedatawrapper.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 #include <svl/itemset.hxx>
27 using namespace css;
28 using namespace css::uno;
30 namespace svx::sidebar {
32 ShadowPropertyPanel::ShadowPropertyPanel(
33 weld::Widget* pParent,
34 SfxBindings* pBindings)
35 : PanelLayout(pParent, u"ShadowPropertyPanel"_ustr, u"svx/ui/sidebarshadow.ui"_ustr),
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(u"SHOW_SHADOW"_ustr)),
47 mxShadowDistance(m_xBuilder->weld_metric_spin_button(u"LB_DISTANCE"_ustr, FieldUnit::POINT)),
48 mxLBShadowColor(new ColorListBox(m_xBuilder->weld_menu_button(u"LB_SHADOW_COLOR"_ustr), [this]{ return GetFrameWeld(); })),
49 mxShadowAngle(m_xBuilder->weld_combo_box(u"LB_ANGLE"_ustr)),
50 mxFTAngle(m_xBuilder->weld_label(u"angle"_ustr)),
51 mxFTDistance(m_xBuilder->weld_label(u"distance"_ustr)),
52 mxFTTransparency(m_xBuilder->weld_label(u"transparency_label"_ustr)),
53 mxFTBlur(m_xBuilder->weld_label(u"blur_label"_ustr)),
54 mxFTColor(m_xBuilder->weld_label(u"shadowcolorlabel"_ustr)),
55 mxShadowTransSlider(m_xBuilder->weld_scale(u"transparency_slider"_ustr)),
56 mxShadowTransMetric(m_xBuilder->weld_metric_spin_button(u"FIELD_TRANSPARENCY"_ustr, FieldUnit::PERCENT)),
57 mxShadowBlurMetric(m_xBuilder->weld_metric_spin_button(u"LB_SHADOW_BLUR"_ustr, FieldUnit::POINT))
59 Initialize();
62 ShadowPropertyPanel::~ShadowPropertyPanel()
64 mxShowShadow.reset();
65 mxFTAngle.reset();
66 mxShadowAngle.reset();
67 mxFTDistance.reset();
68 mxShadowDistance.reset();
69 mxFTTransparency.reset();
70 mxShadowTransSlider.reset();
71 mxShadowTransMetric.reset();
72 mxShadowBlurMetric.reset();
73 mxFTBlur.reset();
74 mxFTColor.reset();
75 mxLBShadowColor.reset();
77 maShadowController.dispose();
78 maShadowTransController.dispose();
79 maShadowBlurController.dispose();
80 maShadowColorController.dispose();
81 maShadowXDistanceController.dispose();
82 maShadowYDistanceController.dispose();
85 void ShadowPropertyPanel::Initialize()
87 mxShowShadow->set_state( TRISTATE_FALSE );
88 mxShowShadow->connect_toggled( LINK(this, ShadowPropertyPanel, ClickShadowHdl ) );
89 mxShadowTransMetric->connect_value_changed( LINK(this, ShadowPropertyPanel, ModifyShadowTransMetricHdl) );
90 mxLBShadowColor->SetSelectHdl( LINK( this, ShadowPropertyPanel, ModifyShadowColorHdl ) );
91 mxShadowAngle->connect_changed( LINK(this, ShadowPropertyPanel, ModifyShadowAngleHdl) );
92 mxShadowDistance->connect_value_changed( LINK(this, ShadowPropertyPanel, ModifyShadowDistanceHdl) );
93 mxShadowTransSlider->set_range(0, 100);
94 mxShadowTransSlider->connect_value_changed( LINK(this, ShadowPropertyPanel, ModifyShadowTransSliderHdl) );
95 mxShadowBlurMetric->set_range(0, 150, FieldUnit::POINT);
96 mxShadowBlurMetric->connect_value_changed(LINK(this, ShadowPropertyPanel, ModifyShadowBlurMetricHdl));
97 InsertAngleValues();
100 IMPL_LINK_NOARG(ShadowPropertyPanel, ClickShadowHdl, weld::Toggleable&, void)
102 if( mxShowShadow->get_state() == TRISTATE_FALSE )
104 SdrOnOffItem aItem(makeSdrShadowItem(false));
105 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_FILL_SHADOW,
106 SfxCallMode::RECORD, { &aItem });
108 if (comphelper::LibreOfficeKit::isActive())
110 mxShowShadow->set_state( TRISTATE_FALSE );
111 UpdateControls();
114 else
116 SdrOnOffItem aItem(makeSdrShadowItem(true));
117 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_FILL_SHADOW,
118 SfxCallMode::RECORD, { &aItem });
120 if (mxShadowDistance->get_value(FieldUnit::POINT) == 0)
121 mxShadowDistance->set_value( 8, FieldUnit::POINT );
123 if (comphelper::LibreOfficeKit::isActive())
125 mxShowShadow->set_state( TRISTATE_TRUE );
126 UpdateControls();
131 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowColorHdl, ColorListBox&, void)
133 XColorItem aItem(makeSdrShadowColorItem(mxLBShadowColor->GetSelectEntryColor()));
134 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_COLOR,
135 SfxCallMode::RECORD, { &aItem });
138 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowTransMetricHdl, weld::MetricSpinButton&, void)
140 sal_uInt16 nVal = mxShadowTransMetric->get_value(FieldUnit::PERCENT);
141 SetTransparencyValue(nVal);
142 SdrPercentItem aItem( makeSdrShadowTransparenceItem(nVal) );
143 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_TRANSPARENCE,
144 SfxCallMode::RECORD, { &aItem });
147 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowBlurMetricHdl, weld::MetricSpinButton&, void)
149 SdrMetricItem aItem(SDRATTR_SHADOWBLUR, mxShadowBlurMetric->get_value(FieldUnit::MM_100TH));
151 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_BLUR, SfxCallMode::RECORD, { &aItem });
154 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowTransSliderHdl, weld::Scale&, void)
156 sal_uInt16 nVal = mxShadowTransSlider->get_value();
157 SetTransparencyValue(nVal);
158 SdrPercentItem aItem( makeSdrShadowTransparenceItem(nVal) );
159 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_TRANSPARENCE,
160 SfxCallMode::RECORD, { &aItem });
163 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowAngleHdl, weld::ComboBox&, void)
165 ModifyShadowDistance();
168 IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowDistanceHdl, weld::MetricSpinButton&, void)
170 ModifyShadowDistance();
173 void ShadowPropertyPanel::ModifyShadowDistance()
175 auto nAngle = mxShadowAngle->get_active_id().toInt32();
176 nXY = mxShadowDistance->get_value(FieldUnit::MM_100TH);
177 switch (nAngle)
179 case 0: nX = nXY; nY = 0; break;
180 case 45: nX = nXY; nY = -nXY; break;
181 case 90: nX = 0; nY = - nXY; break;
182 case 135: nX = nY = -nXY; break;
183 case 180: nX = -nXY; nY = 0; break;
184 case 225: nX = -nXY; nY = nXY; break;
185 case 270: nX = 0; nY = nXY; break;
186 case 315: nX = nY = nXY; break;
188 SdrMetricItem aXItem(makeSdrShadowXDistItem(nX));
189 SdrMetricItem aYItem(makeSdrShadowYDistItem(nY));
190 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_XDISTANCE,
191 SfxCallMode::RECORD, { &aXItem });
192 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_YDISTANCE,
193 SfxCallMode::RECORD, { &aYItem });
196 void ShadowPropertyPanel::UpdateControls()
198 if (mxShowShadow->get_state() == TRISTATE_FALSE)
200 mxShadowDistance->set_sensitive(false);
201 mxLBShadowColor->set_sensitive(false);
202 mxShadowAngle->set_sensitive(false);
203 mxFTAngle->set_sensitive(false);
204 mxFTDistance->set_sensitive(false);
205 mxFTTransparency->set_sensitive(false);
206 mxFTBlur->set_sensitive(false);
207 mxFTColor->set_sensitive(false);
208 mxShadowTransSlider->set_sensitive(false);
209 mxShadowTransMetric->set_sensitive(false);
210 mxShadowBlurMetric->set_sensitive(false);
212 return;
214 else
216 mxShadowDistance->set_sensitive(true);
217 mxLBShadowColor->set_sensitive(true);
218 mxShadowAngle->set_sensitive(true);
219 mxFTAngle->set_sensitive(true);
220 mxFTDistance->set_sensitive(true);
221 mxFTTransparency->set_sensitive(true);
222 mxFTBlur->set_sensitive(true);
223 mxFTColor->set_sensitive(true);
224 mxShadowTransSlider->set_sensitive(true);
225 mxShadowTransMetric->set_sensitive(true);
226 mxShadowBlurMetric->set_sensitive(true);
229 if(nX > 0 && nY == 0) { mxShadowAngle->set_active(0); nXY = nX; }
230 else if( nX > 0 && nY < 0 ) { mxShadowAngle->set_active(1); nXY = nX; }
231 else if( nX == 0 && nY < 0 ) { mxShadowAngle->set_active(2); nXY = -nY; }
232 else if( nX < 0 && nY < 0 ) { mxShadowAngle->set_active(3); nXY = -nY; }
233 else if( nX < 0 && nY == 0 ) { mxShadowAngle->set_active(4); nXY = -nX; }
234 else if( nX < 0 && nY > 0 ) { mxShadowAngle->set_active(5); nXY = nY; }
235 else if( nX == 0 && nY > 0 ) { mxShadowAngle->set_active(6); nXY = nY; }
236 else if( nX > 0 && nY > 0 ) { mxShadowAngle->set_active(7); nXY = nX; }
237 else { nXY = 0; }
238 mxShadowDistance->set_value(nXY, FieldUnit::MM_100TH);
241 void ShadowPropertyPanel::SetTransparencyValue(tools::Long nVal)
243 mxShadowTransSlider->set_value(nVal);
244 mxShadowTransMetric->set_value(nVal, FieldUnit::PERCENT);
247 void ShadowPropertyPanel::InsertAngleValues()
249 OUString sSuffix = weld::MetricSpinButton::MetricToString(FieldUnit::DEGREE);
251 const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetLocaleDataWrapper();
253 mxShadowAngle->append(OUString::number(0), rLocaleData.getNum(0, 0, true, true) + sSuffix);
254 mxShadowAngle->append(OUString::number(45), rLocaleData.getNum(45, 0, true, true) + sSuffix);
255 mxShadowAngle->append(OUString::number(90), rLocaleData.getNum(90, 0, true, true) + sSuffix);
256 mxShadowAngle->append(OUString::number(135), rLocaleData.getNum(135, 0, true, true) + sSuffix);
257 mxShadowAngle->append(OUString::number(180), rLocaleData.getNum(180, 0, true, true) + sSuffix);
258 mxShadowAngle->append(OUString::number(225), rLocaleData.getNum(225, 0, true, true) + sSuffix);
259 mxShadowAngle->append(OUString::number(270), rLocaleData.getNum(270, 0, true, true) + sSuffix);
260 mxShadowAngle->append(OUString::number(315), rLocaleData.getNum(315, 0, true, true) + sSuffix);
263 void ShadowPropertyPanel::NotifyItemUpdate(
264 sal_uInt16 nSID,
265 SfxItemState eState,
266 const SfxPoolItem* pState)
268 switch(nSID)
270 case SID_ATTR_FILL_SHADOW:
272 if(eState >= SfxItemState::DEFAULT)
274 const SdrOnOffItem* pItem = dynamic_cast< const SdrOnOffItem* >(pState);
275 if (pItem && pItem->GetValue())
276 mxShowShadow->set_state(TRISTATE_TRUE);
277 else
278 mxShowShadow->set_state(TRISTATE_FALSE);
281 break;
283 case SID_ATTR_SHADOW_TRANSPARENCE:
285 if(eState >= SfxItemState::DEFAULT)
287 const SdrPercentItem* pTransparencyItem = dynamic_cast< const SdrPercentItem* >(pState);
288 if(pTransparencyItem)
290 const sal_uInt16 nVal = pTransparencyItem->GetValue();
291 SetTransparencyValue(nVal);
293 else
294 SetTransparencyValue(0);
297 break;
298 case SID_ATTR_SHADOW_BLUR:
300 if (eState >= SfxItemState::DEFAULT)
302 const SdrMetricItem* pRadiusItem = dynamic_cast<const SdrMetricItem*>(pState);
303 if (pRadiusItem)
305 mxShadowBlurMetric->set_value(pRadiusItem->GetValue(), FieldUnit::MM_100TH);
309 break;
310 case SID_ATTR_SHADOW_COLOR:
312 if(eState >= SfxItemState::DEFAULT)
314 const XColorItem* pColorItem = dynamic_cast< const XColorItem* >(pState);
315 if(pColorItem)
317 mxLBShadowColor->SelectEntry(pColorItem->GetColorValue());
321 break;
322 case SID_ATTR_SHADOW_XDISTANCE:
324 if(eState >= SfxItemState::DEFAULT)
326 const SdrMetricItem* pXDistItem = dynamic_cast< const SdrMetricItem* >(pState);
327 if(pXDistItem)
329 nX = pXDistItem->GetValue();
333 break;
334 case SID_ATTR_SHADOW_YDISTANCE:
336 if(eState >= SfxItemState::DEFAULT)
338 const SdrMetricItem* pYDistItem = dynamic_cast< const SdrMetricItem* >(pState);
339 if(pYDistItem)
341 nY = pYDistItem->GetValue();
345 break;
347 UpdateControls();
350 std::unique_ptr<PanelLayout> ShadowPropertyPanel::Create (
351 weld::Widget* pParent,
352 SfxBindings* pBindings)
354 if(pParent == nullptr)
355 throw lang::IllegalArgumentException(u"no parent Window given to ShadowPropertyPanel::Create"_ustr, nullptr, 0);
356 if(pBindings == nullptr)
357 throw lang::IllegalArgumentException(u"no SfxBindings given to ShadowPropertyPanel::Create"_ustr, nullptr, 2);
359 return std::make_unique<ShadowPropertyPanel>(pParent, pBindings);
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */