LibreOffice Module svx (master)  1
GraphicPropertyPanel.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  */
20 #include "GraphicPropertyPanel.hxx"
21 #include <svx/strings.hrc>
22 #include <svx/svxids.hrc>
23 #include <svx/dialmgr.hxx>
24 #include <svl/intitem.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 
29 using namespace css;
30 using namespace css::uno;
31 
32 
33 // namespace open
34 
35 namespace svx::sidebar {
36 
37 
38 GraphicPropertyPanel::GraphicPropertyPanel(
39  vcl::Window* pParent,
40  const css::uno::Reference<css::frame::XFrame>& rxFrame,
41  SfxBindings* pBindings)
42 : PanelLayout(pParent, "GraphicPropertyPanel", "svx/ui/sidebargraphic.ui", rxFrame, true),
43  maBrightControl(SID_ATTR_GRAF_LUMINANCE, *pBindings, *this),
44  maContrastControl(SID_ATTR_GRAF_CONTRAST, *pBindings, *this),
45  maTransparenceControl(SID_ATTR_GRAF_TRANSPARENCE, *pBindings, *this),
46  maRedControl(SID_ATTR_GRAF_RED, *pBindings, *this),
47  maGreenControl(SID_ATTR_GRAF_GREEN, *pBindings, *this),
48  maBlueControl(SID_ATTR_GRAF_BLUE, *pBindings, *this),
49  maGammaControl(SID_ATTR_GRAF_GAMMA, *pBindings, *this),
50  maModeControl(SID_ATTR_GRAF_MODE, *pBindings, *this),
51  mpBindings(pBindings),
52  mxMtrBrightness(m_xBuilder->weld_metric_spin_button("setbrightness", FieldUnit::PERCENT)),
53  mxMtrContrast(m_xBuilder->weld_metric_spin_button("setcontrast", FieldUnit::PERCENT)),
54  mxLBColorMode(m_xBuilder->weld_combo_box("setcolormode")),
55  mxMtrTrans(m_xBuilder->weld_metric_spin_button("setgraphtransparency", FieldUnit::PERCENT)),
56  mxMtrRed(m_xBuilder->weld_metric_spin_button("setred", FieldUnit::PERCENT)),
57  mxMtrGreen(m_xBuilder->weld_metric_spin_button("setgreen", FieldUnit::PERCENT)),
58  mxMtrBlue(m_xBuilder->weld_metric_spin_button("setblue", FieldUnit::PERCENT)),
59  mxMtrGamma(m_xBuilder->weld_spin_button("setgamma"))
60 {
61  mxLBColorMode->set_size_request(mxLBColorMode->get_preferred_size().Width(), -1);
62  Initialize();
63 }
64 
66 {
67  disposeOnce();
68 }
69 
71 {
72  mxMtrBrightness.reset();
73  mxMtrContrast.reset();
74  mxLBColorMode.reset();
75  mxMtrTrans.reset();
76  mxMtrRed.reset();
77  mxMtrGreen.reset();
78  mxMtrBlue.reset();
79  mxMtrGamma.reset();
80 
89 
91 }
92 
94 {
95  mxMtrBrightness->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyBrightnessHdl ) );
96  mxMtrContrast->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyContrastHdl ) );
97  mxMtrTrans->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyTransHdl ) );
98 
99  mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_STANDARD));
100  mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_GREYS));
101  mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_MONO));
102  mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_WATERMARK));
103  mxLBColorMode->connect_changed( LINK( this, GraphicPropertyPanel, ClickColorModeHdl ));
104 
105  mxMtrRed->connect_value_changed( LINK( this, GraphicPropertyPanel, RedHdl ) );
106  mxMtrGreen->connect_value_changed( LINK( this, GraphicPropertyPanel, GreenHdl ) );
107  mxMtrBlue->connect_value_changed( LINK( this, GraphicPropertyPanel, BlueHdl ) );
108  mxMtrGamma->connect_value_changed( LINK( this, GraphicPropertyPanel, GammaHdl ) );
109 }
110 
112 {
113  const sal_Int16 nBright = mxMtrBrightness->get_value(FieldUnit::PERCENT);
114  const SfxInt16Item aBrightItem( SID_ATTR_GRAF_LUMINANCE, nBright );
115  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_LUMINANCE,
116  SfxCallMode::RECORD, { &aBrightItem });
117 }
118 
119 
121 {
122  const sal_Int16 nContrast = mxMtrContrast->get_value(FieldUnit::PERCENT);
123  const SfxInt16Item aContrastItem( SID_ATTR_GRAF_CONTRAST, nContrast );
124  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_CONTRAST,
125  SfxCallMode::RECORD, { &aContrastItem });
126 }
127 
128 
130 {
131  const sal_Int16 nTrans = mxMtrTrans->get_value(FieldUnit::PERCENT);
132  const SfxInt16Item aTransItem( SID_ATTR_GRAF_TRANSPARENCE, nTrans );
133  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_TRANSPARENCE,
134  SfxCallMode::RECORD, { &aTransItem });
135 }
136 
137 
139 {
140  const sal_Int16 nTrans = mxLBColorMode->get_active();
141  const SfxInt16Item aTransItem( SID_ATTR_GRAF_MODE, nTrans );
142  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_MODE,
143  SfxCallMode::RECORD, { &aTransItem });
144 }
145 
146 
148 {
149  const sal_Int16 nRed = mxMtrRed->get_value(FieldUnit::PERCENT);
150  const SfxInt16Item aRedItem( SID_ATTR_GRAF_RED, nRed );
151  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_RED,
152  SfxCallMode::RECORD, { &aRedItem });
153 }
154 
155 
157 {
158  const sal_Int16 nGreen = mxMtrGreen->get_value(FieldUnit::PERCENT);
159  const SfxInt16Item aGreenItem( SID_ATTR_GRAF_GREEN, nGreen );
160  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_GREEN,
161  SfxCallMode::RECORD, { &aGreenItem });
162 }
163 
164 
166 {
167  const sal_Int16 nBlue = mxMtrBlue->get_value(FieldUnit::PERCENT);
168  const SfxInt16Item aBlueItem( SID_ATTR_GRAF_BLUE, nBlue );
169  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_BLUE,
170  SfxCallMode::RECORD, { &aBlueItem });
171 }
172 
173 
175 {
176  const sal_Int32 nGamma = mxMtrGamma->get_value();
177  const SfxInt32Item nGammaItem( SID_ATTR_GRAF_GAMMA, nGamma );
178  GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_GAMMA,
179  SfxCallMode::RECORD, { &nGammaItem });
180 }
181 
182 
184  vcl::Window* pParent,
185  const css::uno::Reference<css::frame::XFrame>& rxFrame,
186  SfxBindings* pBindings)
187 {
188  if (pParent == nullptr)
189  throw lang::IllegalArgumentException("no parent Window given to GraphicPropertyPanel::Create", nullptr, 0);
190  if ( ! rxFrame.is())
191  throw lang::IllegalArgumentException("no XFrame given to GraphicPropertyPanel::Create", nullptr, 1);
192  if (pBindings == nullptr)
193  throw lang::IllegalArgumentException("no SfxBindings given to GraphicPropertyPanel::Create", nullptr, 2);
194 
196  pParent,
197  rxFrame,
198  pBindings);
199 }
200 
201 
203  const DataChangedEvent& /*rEvent*/)
204 {
205 }
206 
207 
209  sal_uInt16 nSID,
210  SfxItemState eState,
211  const SfxPoolItem* pState)
212 {
213  switch( nSID )
214  {
215  case SID_ATTR_GRAF_LUMINANCE:
216  {
217  if(eState >= SfxItemState::DEFAULT)
218  {
219  mxMtrBrightness->set_sensitive(true);
220  const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
221 
222  if(pItem)
223  {
224  const sal_Int64 nBright = pItem->GetValue();
225  mxMtrBrightness->set_value(nBright, FieldUnit::PERCENT);
226  }
227  }
228  else if(SfxItemState::DISABLED == eState)
229  {
230  mxMtrBrightness->set_sensitive(false);
231  }
232  else
233  {
234  mxMtrBrightness->set_sensitive(true);
235  mxMtrBrightness->set_text(OUString());
236  }
237  break;
238  }
239  case SID_ATTR_GRAF_CONTRAST:
240  {
241  if(eState >= SfxItemState::DEFAULT)
242  {
243  mxMtrContrast->set_sensitive(true);
244  const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
245 
246  if(pItem)
247  {
248  const sal_Int64 nContrast = pItem->GetValue();
249  mxMtrContrast->set_value(nContrast, FieldUnit::PERCENT);
250  }
251  }
252  else if(SfxItemState::DISABLED == eState)
253  {
254  mxMtrContrast->set_sensitive(false);
255  }
256  else
257  {
258  mxMtrContrast->set_sensitive(true);
259  mxMtrContrast->set_text(OUString());
260  }
261  break;
262  }
263  case SID_ATTR_GRAF_TRANSPARENCE:
264  {
265  if(eState >= SfxItemState::DEFAULT)
266  {
267  mxMtrTrans->set_sensitive(true);
268  const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
269 
270  if(pItem)
271  {
272  const sal_Int64 nTrans = pItem->GetValue();
273  mxMtrTrans->set_value(nTrans, FieldUnit::PERCENT);
274  }
275  }
276  else if(SfxItemState::DISABLED == eState)
277  {
278  mxMtrTrans->set_sensitive(false);
279  }
280  else
281  {
282  mxMtrTrans->set_sensitive(true);
283  mxMtrTrans->set_text(OUString());
284  }
285  break;
286  }
287  case SID_ATTR_GRAF_MODE:
288  {
289  if(eState >= SfxItemState::DEFAULT)
290  {
291  mxLBColorMode->set_sensitive(true);
292  const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
293 
294  if(pItem)
295  {
296  const sal_Int64 nTrans = pItem->GetValue();
297  mxLBColorMode->set_active(nTrans);
298  }
299  }
300  else if(SfxItemState::DISABLED == eState)
301  {
302  mxLBColorMode->set_sensitive(false);
303  }
304  else
305  {
306  mxLBColorMode->set_sensitive(true);
307  mxLBColorMode->set_active(-1);
308  }
309  break;
310  }
311  case SID_ATTR_GRAF_RED:
312  {
313  if(eState >= SfxItemState::DEFAULT)
314  {
315  mxMtrRed->set_sensitive(true);
316  const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
317 
318  if(pItem)
319  {
320  const sal_Int64 nRed = pItem->GetValue();
321  mxMtrRed->set_value(nRed, FieldUnit::PERCENT);
322  }
323  }
324  else if(SfxItemState::DISABLED == eState)
325  {
326  mxMtrRed->set_sensitive(false);
327  }
328  else
329  {
330  mxMtrRed->set_sensitive(true);
331  mxMtrRed->set_text(OUString());
332  }
333  break;
334  }
335  case SID_ATTR_GRAF_GREEN:
336  {
337  if(eState >= SfxItemState::DEFAULT)
338  {
339  mxMtrGreen->set_sensitive(true);
340  const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
341 
342  if(pItem)
343  {
344  const sal_Int64 nGreen = pItem->GetValue();
345  mxMtrGreen->set_value(nGreen, FieldUnit::PERCENT);
346  }
347  }
348  else if(SfxItemState::DISABLED == eState)
349  {
350  mxMtrGreen->set_sensitive(false);
351  }
352  else
353  {
354  mxMtrGreen->set_sensitive(true);
355  mxMtrGreen->set_text(OUString());
356  }
357  break;
358  }
359  case SID_ATTR_GRAF_BLUE:
360  {
361  if(eState >= SfxItemState::DEFAULT)
362  {
363  mxMtrBlue->set_sensitive(true);
364  const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
365 
366  if(pItem)
367  {
368  const sal_Int64 nBlue = pItem->GetValue();
369  mxMtrBlue->set_value(nBlue, FieldUnit::PERCENT);
370  }
371  }
372  else if(SfxItemState::DISABLED == eState)
373  {
374  mxMtrBlue->set_sensitive(false);
375  }
376  else
377  {
378  mxMtrBlue->set_sensitive(true);
379  mxMtrBlue->set_text(OUString());
380  }
381  break;
382  }
383  case SID_ATTR_GRAF_GAMMA:
384  {
385  if(eState >= SfxItemState::DEFAULT)
386  {
387  mxMtrGamma->set_sensitive(true);
388  const SfxUInt32Item* pItem = dynamic_cast< const SfxUInt32Item* >(pState);
389 
390  if(pItem)
391  {
392  const sal_Int64 nGamma = pItem->GetValue();
393  mxMtrGamma->set_value( nGamma );
394  }
395  }
396  else if(SfxItemState::DISABLED == eState)
397  {
398  mxMtrGamma->set_sensitive(false);
399  }
400  else
401  {
402  mxMtrGamma->set_sensitive(true);
403  mxMtrGamma->set_text(OUString());
404  }
405  break;
406  }
407  }
408 }
409 
410 
411 // namespace close
412 
413 } // end of namespace svx::sidebar
414 
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FieldUnit
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 maRedControl
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
std::unique_ptr< weld::MetricSpinButton > mxMtrContrast
::sfx2::sidebar::ControllerItem maContrastControl
::sfx2::sidebar::ControllerItem maModeControl
sal_uInt16 GetValue() const
::sfx2::sidebar::ControllerItem maTransparenceControl
std::unique_ptr< weld::MetricSpinButton > mxMtrBrightness
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
::sfx2::sidebar::ControllerItem maGreenControl
std::unique_ptr< weld::MetricSpinButton > mxMtrTrans
sal_Int16 GetValue() const
::sfx2::sidebar::ControllerItem maBrightControl
virtual void dispose()
std::unique_ptr< weld::ComboBox > mxLBColorMode
std::unique_ptr< weld::SpinButton > mxMtrGamma
static VclPtr< vcl::Window > Create(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
virtual void dispose() override
Definition: PanelLayout.cxx:52
std::unique_ptr< weld::MetricSpinButton > mxMtrGreen
SfxItemState
std::unique_ptr< weld::MetricSpinButton > mxMtrRed
::sfx2::sidebar::ControllerItem maGammaControl
static VclPtr< reference_type > Create(Arg &&...arg)
const OUString PERCENT("Percent")
sal_uInt32 GetValue() const
::sfx2::sidebar::ControllerItem maBlueControl
std::unique_ptr< weld::MetricSpinButton > mxMtrBlue
virtual void DataChanged(const DataChangedEvent &rEvent) override