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