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 */
19
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
29using namespace css;
30using namespace css::uno;
31
32
33// namespace open
34
35namespace svx::sidebar {
36
37
39 weld::Widget* pParent,
40 SfxBindings* pBindings)
41: PanelLayout(pParent, "GraphicPropertyPanel", "svx/ui/sidebargraphic.ui"),
42 maBrightControl(SID_ATTR_GRAF_LUMINANCE, *pBindings, *this),
43 maContrastControl(SID_ATTR_GRAF_CONTRAST, *pBindings, *this),
44 maTransparenceControl(SID_ATTR_GRAF_TRANSPARENCE, *pBindings, *this),
45 maRedControl(SID_ATTR_GRAF_RED, *pBindings, *this),
46 maGreenControl(SID_ATTR_GRAF_GREEN, *pBindings, *this),
47 maBlueControl(SID_ATTR_GRAF_BLUE, *pBindings, *this),
48 maGammaControl(SID_ATTR_GRAF_GAMMA, *pBindings, *this),
49 maModeControl(SID_ATTR_GRAF_MODE, *pBindings, *this),
50 mpBindings(pBindings),
51 mxMtrBrightness(m_xBuilder->weld_metric_spin_button("setbrightness", FieldUnit::PERCENT)),
52 mxMtrContrast(m_xBuilder->weld_metric_spin_button("setcontrast", FieldUnit::PERCENT)),
53 mxLBColorMode(m_xBuilder->weld_combo_box("setcolormode")),
54 mxMtrTrans(m_xBuilder->weld_metric_spin_button("setgraphtransparency", FieldUnit::PERCENT))
55{
56 mxLBColorMode->set_size_request(mxLBColorMode->get_preferred_size().Width(), -1);
57 Initialize();
58}
59
61{
62 mxMtrBrightness.reset();
63 mxMtrContrast.reset();
64 mxLBColorMode.reset();
65 mxMtrTrans.reset();
66
75}
76
78{
79 mxMtrBrightness->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyBrightnessHdl ) );
80 mxMtrContrast->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyContrastHdl ) );
81 mxMtrTrans->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyTransHdl ) );
82
83 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_STANDARD));
84 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_GREYS));
85 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_MONO));
86 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_WATERMARK));
87 mxLBColorMode->connect_changed( LINK( this, GraphicPropertyPanel, ClickColorModeHdl ));
88}
89
91{
92 const sal_Int16 nBright = mxMtrBrightness->get_value(FieldUnit::PERCENT);
93 const SfxInt16Item aBrightItem( SID_ATTR_GRAF_LUMINANCE, nBright );
94 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_LUMINANCE,
95 SfxCallMode::RECORD, { &aBrightItem });
96}
97
98
100{
101 const sal_Int16 nContrast = mxMtrContrast->get_value(FieldUnit::PERCENT);
102 const SfxInt16Item aContrastItem( SID_ATTR_GRAF_CONTRAST, nContrast );
103 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_CONTRAST,
104 SfxCallMode::RECORD, { &aContrastItem });
105}
106
107
109{
110 const sal_Int16 nTrans = mxMtrTrans->get_value(FieldUnit::PERCENT);
111 const SfxUInt16Item aTransItem( SID_ATTR_GRAF_TRANSPARENCE, nTrans );
112 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_TRANSPARENCE,
113 SfxCallMode::RECORD, { &aTransItem });
114}
115
116
118{
119 const sal_Int16 nTrans = mxLBColorMode->get_active();
120 const SfxUInt16Item aTransItem( SID_ATTR_GRAF_MODE, nTrans );
121 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_MODE,
122 SfxCallMode::RECORD, { &aTransItem });
123}
124
125std::unique_ptr<PanelLayout> GraphicPropertyPanel::Create (
126 weld::Widget* pParent,
127 SfxBindings* pBindings)
128{
129 if (pParent == nullptr)
130 throw lang::IllegalArgumentException("no parent Window given to GraphicPropertyPanel::Create", nullptr, 0);
131 if (pBindings == nullptr)
132 throw lang::IllegalArgumentException("no SfxBindings given to GraphicPropertyPanel::Create", nullptr, 2);
133
134 return std::make_unique<GraphicPropertyPanel>(pParent, pBindings);
135}
136
138 sal_uInt16 nSID,
139 SfxItemState eState,
140 const SfxPoolItem* pState)
141{
142 switch( nSID )
143 {
144 case SID_ATTR_GRAF_LUMINANCE:
145 {
146 if(eState >= SfxItemState::DEFAULT)
147 {
148 mxMtrBrightness->set_sensitive(true);
149 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
150
151 if(pItem)
152 {
153 const sal_Int64 nBright = pItem->GetValue();
154 mxMtrBrightness->set_value(nBright, FieldUnit::PERCENT);
155 }
156 }
157 else if(SfxItemState::DISABLED == eState)
158 {
159 mxMtrBrightness->set_sensitive(false);
160 }
161 else
162 {
163 mxMtrBrightness->set_sensitive(true);
164 mxMtrBrightness->set_text(OUString());
165 }
166 break;
167 }
168 case SID_ATTR_GRAF_CONTRAST:
169 {
170 if(eState >= SfxItemState::DEFAULT)
171 {
172 mxMtrContrast->set_sensitive(true);
173 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
174
175 if(pItem)
176 {
177 const sal_Int64 nContrast = pItem->GetValue();
178 mxMtrContrast->set_value(nContrast, FieldUnit::PERCENT);
179 }
180 }
181 else if(SfxItemState::DISABLED == eState)
182 {
183 mxMtrContrast->set_sensitive(false);
184 }
185 else
186 {
187 mxMtrContrast->set_sensitive(true);
188 mxMtrContrast->set_text(OUString());
189 }
190 break;
191 }
192 case SID_ATTR_GRAF_TRANSPARENCE:
193 {
194 if(eState >= SfxItemState::DEFAULT)
195 {
196 mxMtrTrans->set_sensitive(true);
197 const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
198
199 if(pItem)
200 {
201 const sal_Int64 nTrans = pItem->GetValue();
202 mxMtrTrans->set_value(nTrans, FieldUnit::PERCENT);
203 }
204 }
205 else if(SfxItemState::DISABLED == eState)
206 {
207 mxMtrTrans->set_sensitive(false);
208 }
209 else
210 {
211 mxMtrTrans->set_sensitive(true);
212 mxMtrTrans->set_text(OUString());
213 }
214 break;
215 }
216 case SID_ATTR_GRAF_MODE:
217 {
218 if(eState >= SfxItemState::DEFAULT)
219 {
220 mxLBColorMode->set_sensitive(true);
221
222 if(pState)
223 {
224 const sal_uInt16 nTrans = static_cast< const SfxUInt16Item* >(pState)->GetValue();
225 mxLBColorMode->set_active(nTrans);
226 }
227 }
228 else if(SfxItemState::DISABLED == eState)
229 {
230 mxLBColorMode->set_sensitive(false);
231 }
232 else
233 {
234 mxLBColorMode->set_sensitive(true);
235 mxLBColorMode->set_active(-1);
236 }
237 break;
238 }
239 }
240}
241
242// namespace close
243
244} // end of namespace svx::sidebar
245
246/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetValue() const
SfxDispatcher * GetDispatcher() 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 * >())
sal_Int16 GetValue() const
GraphicPropertyPanel(weld::Widget *pParent, SfxBindings *pBindings)
::sfx2::sidebar::ControllerItem maModeControl
std::unique_ptr< weld::MetricSpinButton > mxMtrBrightness
std::unique_ptr< weld::MetricSpinButton > mxMtrContrast
::sfx2::sidebar::ControllerItem maGammaControl
::sfx2::sidebar::ControllerItem maContrastControl
std::unique_ptr< weld::MetricSpinButton > mxMtrTrans
::sfx2::sidebar::ControllerItem maGreenControl
::sfx2::sidebar::ControllerItem maBrightControl
::sfx2::sidebar::ControllerItem maRedControl
std::unique_ptr< weld::ComboBox > mxLBColorMode
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
::sfx2::sidebar::ControllerItem maBlueControl
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
::sfx2::sidebar::ControllerItem maTransparenceControl
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
virtual SfxBindings & GetBindings() override
FieldUnit
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
std::string GetValue
SfxItemState
constexpr OUStringLiteral PERCENT(u"Percent")