LibreOffice Module svx (master)  1
LinePropertyPanelBase.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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <memory>
22 #include <sfx2/weldutils.hxx>
23 #include <svx/linectrl.hxx>
24 #include <svx/xlnwtit.hxx>
25 #include <svx/xlntrit.hxx>
26 #include <svx/xlncapit.hxx>
27 #include <svx/xlinjoit.hxx>
28 #include <bitmaps.hlst>
29 
30 using namespace css;
31 using namespace css::uno;
32 
33 constexpr OStringLiteral SELECTWIDTH = "SelectWidth";
34 
35 namespace svx::sidebar {
36 
37 // trigger disabling the arrows if the none line style is selected
39 {
40 private:
42 
43 public:
45  : m_rPanel(rPanel)
46  {
47  }
48 
49  void operator()(bool bLineStyleNone)
50  {
51  m_rPanel.SetNoneLineStyle(bLineStyleNone);
52  }
53 };
54 
55 namespace
56 {
57  SvxLineStyleToolBoxControl* getLineStyleToolBoxControl(const ToolbarUnoDispatcher& rToolBoxColor)
58  {
59  css::uno::Reference<css::frame::XToolbarController> xController = rToolBoxColor.GetControllerForCommand(".uno:XLineStyle");
60  SvxLineStyleToolBoxControl* pToolBoxLineStyleControl = dynamic_cast<SvxLineStyleToolBoxControl*>(xController.get());
61  return pToolBoxLineStyleControl;
62  }
63 }
64 
65 
66 LinePropertyPanelBase::LinePropertyPanelBase(
67  weld::Widget* pParent,
68  const uno::Reference<css::frame::XFrame>& rxFrame)
69 : PanelLayout(pParent, "LinePropertyPanel", "svx/ui/sidebarline.ui"),
70  mxTBColor(m_xBuilder->weld_toolbar("color")),
71  mxColorDispatch(new ToolbarUnoDispatcher(*mxTBColor, *m_xBuilder, rxFrame)),
72  mxLineStyleTB(m_xBuilder->weld_toolbar("linestyle")),
73  mxLineStyleDispatch(new ToolbarUnoDispatcher(*mxLineStyleTB, *m_xBuilder, rxFrame)),
74  mnWidthCoreValue(0),
75  mxFTWidth(m_xBuilder->weld_label("widthlabel")),
76  mxTBWidth(m_xBuilder->weld_toolbar("width")),
77  mxFTTransparency(m_xBuilder->weld_label("translabel")),
78  mxMFTransparent(m_xBuilder->weld_metric_spin_button("linetransparency", FieldUnit::PERCENT)),
79  mxFTEdgeStyle(m_xBuilder->weld_label("cornerlabel")),
80  mxLBEdgeStyle(m_xBuilder->weld_combo_box("edgestyle")),
81  mxFTCapStyle(m_xBuilder->weld_label("caplabel")),
82  mxLBCapStyle(m_xBuilder->weld_combo_box("linecapstyle")),
83  mxGridLineProps(m_xBuilder->weld_widget("lineproperties")),
84  mxBoxArrowProps(m_xBuilder->weld_widget("arrowproperties")),
85  mxLineWidthPopup(new LineWidthPopup(mxTBWidth.get(), *this)),
86  mxLineStyleNoneChange(new LineStyleNoneChange(*this)),
87  mnTrans(0),
88  meMapUnit(MapUnit::MapMM),
89  maIMGNone(BMP_NONE_ICON),
90  mbWidthValuable(true),
91  mbArrowSupported(true),
92  mbNoneLineStyle(false)
93 {
94  Initialize();
95 }
96 
98 {
99  mxLineWidthPopup.reset();
100  mxFTWidth.reset();
101  mxTBWidth.reset();
102  mxColorDispatch.reset();
103  mxTBColor.reset();
104  mxFTTransparency.reset();
105  mxMFTransparent.reset();
106  mxLineStyleDispatch.reset();
107  mxLineStyleTB.reset();
108  mxFTEdgeStyle.reset();
109  mxLBEdgeStyle.reset();
110  mxFTCapStyle.reset();
111  mxLBCapStyle.reset();
112  mxGridLineProps.reset();
113  mxBoxArrowProps.reset();
114 }
115 
117 {
118  mxTBWidth->set_item_popover(SELECTWIDTH, mxLineWidthPopup->getTopLevel());
119 
120  maIMGWidthIcon[0] = BMP_WIDTH1_ICON;
121  maIMGWidthIcon[1] = BMP_WIDTH2_ICON;
122  maIMGWidthIcon[2] = BMP_WIDTH3_ICON;
123  maIMGWidthIcon[3] = BMP_WIDTH4_ICON;
124  maIMGWidthIcon[4] = BMP_WIDTH5_ICON;
125  maIMGWidthIcon[5] = BMP_WIDTH6_ICON;
126  maIMGWidthIcon[6] = BMP_WIDTH7_ICON;
127  maIMGWidthIcon[7] = BMP_WIDTH8_ICON;
128 
129  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[0]);
130  mxTBWidth->connect_clicked(LINK(this, LinePropertyPanelBase, ToolboxWidthSelectHdl));
131 
132  mxMFTransparent->connect_value_changed(LINK(this, LinePropertyPanelBase, ChangeTransparentHdl));
133 
134  mxLBEdgeStyle->connect_changed( LINK( this, LinePropertyPanelBase, ChangeEdgeStyleHdl ) );
135 
136  mxLBCapStyle->connect_changed( LINK( this, LinePropertyPanelBase, ChangeCapStyleHdl ) );
137 
138  SvxLineStyleToolBoxControl* pLineStyleControl = getLineStyleToolBoxControl(*mxLineStyleDispatch);
140 }
141 
142 void LinePropertyPanelBase::updateLineTransparence(bool bDisabled, bool bSetOrDefault,
143  const SfxPoolItem* pState)
144 {
145  if(bDisabled)
146  {
147  mxFTTransparency->set_sensitive(false);
148  mxMFTransparent->set_sensitive(false);
149  }
150  else
151  {
152  mxFTTransparency->set_sensitive(true);
153  mxMFTransparent->set_sensitive(true);
154  }
155 
156  if(bSetOrDefault)
157  {
158  if (const XLineTransparenceItem* pItem = dynamic_cast<const XLineTransparenceItem*>(pState))
159  {
160  mnTrans = pItem->GetValue();
161  mxMFTransparent->set_value(mnTrans, FieldUnit::PERCENT);
162  return;
163  }
164  }
165 
166  mxMFTransparent->set_value(0, FieldUnit::PERCENT);//add
167  mxMFTransparent->set_text(OUString());
168 }
169 
170 void LinePropertyPanelBase::updateLineWidth(bool bDisabled, bool bSetOrDefault,
171  const SfxPoolItem* pState)
172 {
173  if(bDisabled)
174  {
175  mxTBWidth->set_sensitive(false);
176  mxFTWidth->set_sensitive(false);
177  }
178  else
179  {
180  mxTBWidth->set_sensitive(true);
181  mxFTWidth->set_sensitive(true);
182  }
183 
184  if(bSetOrDefault)
185  {
186  if (const XLineWidthItem* pItem = dynamic_cast<const XLineWidthItem*>(pState))
187  {
188  mnWidthCoreValue = pItem->GetValue();
189  mbWidthValuable = true;
190  SetWidthIcon();
191  return;
192  }
193  }
194 
195  mbWidthValuable = false;
196  SetWidthIcon();
197 }
198 
199 void LinePropertyPanelBase::updateLineJoint(bool bDisabled, bool bSetOrDefault,
200  const SfxPoolItem* pState)
201 {
202  if(bDisabled)
203  {
204  mxLBEdgeStyle->set_sensitive(false);
205  mxFTEdgeStyle->set_sensitive(false);
206  }
207  else
208  {
209  mxLBEdgeStyle->set_sensitive(true);
210  mxFTEdgeStyle->set_sensitive(true);
211  }
212 
213  if(bSetOrDefault)
214  {
215  if (const XLineJointItem* pItem = dynamic_cast<const XLineJointItem*>(pState))
216  {
217  sal_Int32 nEntryPos(0);
218 
219  switch(pItem->GetValue())
220  {
221  case drawing::LineJoint_ROUND:
222  {
223  nEntryPos = 1;
224  break;
225  }
226  case drawing::LineJoint_NONE:
227  {
228  nEntryPos = 2;
229  break;
230  }
231  case drawing::LineJoint_MIDDLE:
232  case drawing::LineJoint_MITER:
233  {
234  nEntryPos = 3;
235  break;
236  }
237  case drawing::LineJoint_BEVEL:
238  {
239  nEntryPos = 4;
240  break;
241  }
242 
243  default:
244  break;
245  }
246 
247  if(nEntryPos)
248  {
249  mxLBEdgeStyle->set_active(nEntryPos - 1);
250  return;
251  }
252  }
253  }
254 
255  mxLBEdgeStyle->set_active(-1);
256 }
257 
258 void LinePropertyPanelBase::updateLineCap(bool bDisabled, bool bSetOrDefault,
259  const SfxPoolItem* pState)
260 {
261  if(bDisabled)
262  {
263  mxLBCapStyle->set_sensitive(false);
264  mxFTCapStyle->set_sensitive(false);
265  }
266  else
267  {
268  mxLBCapStyle->set_sensitive(true);
269  mxLBCapStyle->set_sensitive(true);
270  }
271 
272  if(bSetOrDefault)
273  {
274  if (const XLineCapItem* pItem = dynamic_cast<const XLineCapItem*>(pState))
275  {
276  sal_Int32 nEntryPos(0);
277 
278  switch(pItem->GetValue())
279  {
280  case drawing::LineCap_BUTT:
281  {
282  nEntryPos = 1;
283  break;
284  }
285  case drawing::LineCap_ROUND:
286  {
287  nEntryPos = 2;
288  break;
289  }
290  case drawing::LineCap_SQUARE:
291  {
292  nEntryPos = 3;
293  break;
294  }
295 
296  default:
297  break;
298  }
299 
300  if(nEntryPos)
301  {
302  mxLBCapStyle->set_active(nEntryPos - 1);
303  return;
304  }
305  }
306  }
307 
308  mxLBCapStyle->set_active(-1);
309 }
310 
312 {
313  const sal_Int32 nPos(mxLBEdgeStyle->get_active());
314 
315  if (nPos == -1 || !mxLBEdgeStyle->get_value_changed_from_saved())
316  return;
317 
318  std::unique_ptr<XLineJointItem> pItem;
319 
320  switch(nPos)
321  {
322  case 0: // rounded
323  {
324  pItem.reset(new XLineJointItem(drawing::LineJoint_ROUND));
325  break;
326  }
327  case 1: // none
328  {
329  pItem.reset(new XLineJointItem(drawing::LineJoint_NONE));
330  break;
331  }
332  case 2: // mitered
333  {
334  pItem.reset(new XLineJointItem(drawing::LineJoint_MITER));
335  break;
336  }
337  case 3: // beveled
338  {
339  pItem.reset(new XLineJointItem(drawing::LineJoint_BEVEL));
340  break;
341  }
342  }
343 
344  setLineJoint(pItem.get());
345 }
346 
348 {
349  const sal_Int32 nPos(mxLBCapStyle->get_active());
350 
351  if (!(nPos != -1 && mxLBCapStyle->get_value_changed_from_saved()))
352  return;
353 
354  std::unique_ptr<XLineCapItem> pItem;
355 
356  switch(nPos)
357  {
358  case 0: // flat
359  {
360  pItem.reset(new XLineCapItem(drawing::LineCap_BUTT));
361  break;
362  }
363  case 1: // round
364  {
365  pItem.reset(new XLineCapItem(drawing::LineCap_ROUND));
366  break;
367  }
368  case 2: // square
369  {
370  pItem.reset(new XLineCapItem(drawing::LineCap_SQUARE));
371  break;
372  }
373  }
374 
375  setLineCap(pItem.get());
376 }
377 
378 IMPL_LINK_NOARG(LinePropertyPanelBase, ToolboxWidthSelectHdl, const OString&, void)
379 {
380  mxTBWidth->set_menu_item_active(SELECTWIDTH, !mxTBWidth->get_menu_item_active(SELECTWIDTH));
381 }
382 
384 {
385  mxTBWidth->set_menu_item_active(SELECTWIDTH, false);
386 }
387 
389 {
390  sal_uInt16 nVal = static_cast<sal_uInt16>(mxMFTransparent->get_value(FieldUnit::PERCENT));
391  XLineTransparenceItem aItem( nVal );
392 
393  setLineTransparency(aItem);
394 }
395 
397 {
398  if (n == 0)
399  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGNone);
400  else
401  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[n-1]);
402 }
403 
405 {
406  if(!mbWidthValuable)
407  {
408  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGNone);
409  return;
410  }
411 
412  tools::Long nVal = OutputDevice::LogicToLogic(mnWidthCoreValue * 10, meMapUnit, MapUnit::MapPoint);
413 
414  if(nVal <= 6)
415  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[0]);
416  else if (nVal <= 9)
417  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[1]);
418  else if (nVal <= 12)
419  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[2]);
420  else if (nVal <= 19)
421  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[3]);
422  else if (nVal <= 26)
423  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[4]);
424  else if (nVal <= 37)
425  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[5]);
426  else if (nVal <= 52)
427  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[6]);
428  else
429  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[7]);
430 
431 }
432 
434 {
435  mnWidthCoreValue = nWidth;
436  mbWidthValuable = true;
438 }
439 
441 {
442  mxGridLineProps->set_sensitive(!mbNoneLineStyle);
443  mxBoxArrowProps->set_sensitive(!mbNoneLineStyle);
444  mxLineStyleTB->set_item_sensitive(".uno:LineEndStyle", !mbNoneLineStyle);
445 
446  mxBoxArrowProps->set_visible(mbArrowSupported);
447  mxLineStyleTB->set_item_visible(".uno:LineEndStyle", mbArrowSupported);
448 }
449 
451 {
452  meMapUnit = eMapUnit;
454 }
455 
457 {
458  mbArrowSupported = false;
460 }
461 
463 {
464  mbArrowSupported = true;
466 }
467 
468 } // end of namespace svx::sidebar
469 
470 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
std::unique_ptr< weld::Label > mxFTTransparency
FieldUnit
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
virtual void updateLineWidth(bool bDisabled, bool bSetOrDefault, const SfxPoolItem *pItem)
std::unique_ptr< weld::ComboBox > mxLBCapStyle
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
long Long
std::unique_ptr< weld::Toolbar > mxTBColor
constexpr OUStringLiteral PERCENT(u"Percent")
std::unique_ptr< weld::Widget > mxGridLineProps
std::unique_ptr< ToolbarUnoDispatcher > mxColorDispatch
std::unique_ptr< weld::Label > mxFTEdgeStyle
std::unique_ptr< weld::Label > mxFTCapStyle
void setLineStyleIsNoneFunction(const LineStyleIsNoneFunction &aLineStyleIsNoneFunction)
Definition: linectrl.cxx:182
Reference< XController > xController
std::unique_ptr< ToolbarUnoDispatcher > mxLineStyleDispatch
void SetNoneLineStyle(bool bNoneLineStyle)
std::unique_ptr< weld::Widget > mxBoxArrowProps
void updateLineTransparence(bool bDisabled, bool bSetOrDefault, const SfxPoolItem *pItem)
std::unique_ptr< LineStyleNoneChange > mxLineStyleNoneChange
std::unique_ptr< weld::Toolbar > mxLineStyleTB
css::uno::Reference< css::frame::XToolbarController > GetControllerForCommand(const OUString &rCommand) const
void updateLineCap(bool bDisabled, bool bSetOrDefault, const SfxPoolItem *pItem)
void updateLineJoint(bool bDisabled, bool bSetOrDefault, const SfxPoolItem *pItem)
std::unique_ptr< weld::ComboBox > mxLBEdgeStyle
MapUnit
std::unique_ptr< weld::Toolbar > mxTBWidth
std::unique_ptr< LineWidthPopup > mxLineWidthPopup
std::unique_ptr< weld::Label > mxFTWidth
std::unique_ptr< weld::MetricSpinButton > mxMFTransparent
LineStyleNoneChange(LinePropertyPanelBase &rPanel)
constexpr OStringLiteral SELECTWIDTH
sal_uInt16 nPos
bool m_bDetectedRangeSegmentation false