LibreOffice Module svx (master)  1
AreaTransparencyGradientPopup.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 
22 #include <svx/xflftrit.hxx>
23 #include <svx/xgrad.hxx>
24 #include <vcl/svapp.hxx>
25 
26 namespace svx::sidebar {
27 
29  : mrAreaPropertyPanel(rPanel)
30  , mxBuilder(Application::CreateBuilder(pParent, "svx/ui/floatingareastyle.ui"))
31  , mxTopLevel(mxBuilder->weld_container("FloatingAreaStyle"))
32  , mxCenterGrid(mxBuilder->weld_widget("centergrid"))
33  , mxAngleGrid(mxBuilder->weld_widget("anglegrid"))
34  , mxMtrTrgrCenterX(mxBuilder->weld_metric_spin_button("centerx", FieldUnit::PERCENT))
35  , mxMtrTrgrCenterY(mxBuilder->weld_metric_spin_button("centery", FieldUnit::PERCENT))
36  , mxMtrTrgrAngle(mxBuilder->weld_metric_spin_button("angle", FieldUnit::DEGREE))
37  , mxBtnLeft45(mxBuilder->weld_toolbar("lefttoolbox"))
38  , mxBtnRight45(mxBuilder->weld_toolbar("righttoolbox"))
39  , mxMtrTrgrStartValue(mxBuilder->weld_metric_spin_button("start", FieldUnit::PERCENT))
40  , mxMtrTrgrEndValue(mxBuilder->weld_metric_spin_button("end", FieldUnit::PERCENT))
41  , mxMtrTrgrBorder(mxBuilder->weld_metric_spin_button("border", FieldUnit::PERCENT))
42 {
43  Link<weld::MetricSpinButton&,void> aLink = LINK(this, AreaTransparencyGradientPopup, ModifiedTrgrHdl_Impl);
44  mxMtrTrgrCenterX->connect_value_changed(aLink);
45  mxMtrTrgrCenterY->connect_value_changed(aLink);
46  mxMtrTrgrAngle->connect_value_changed(aLink);
47  mxMtrTrgrBorder->connect_value_changed(aLink);
48  mxMtrTrgrStartValue->connect_value_changed(aLink);
49  mxMtrTrgrEndValue->connect_value_changed(aLink);
50  mxBtnLeft45->connect_clicked(LINK(this, AreaTransparencyGradientPopup, Left_Click45_Impl));
51  mxBtnRight45->connect_clicked(LINK(this, AreaTransparencyGradientPopup, Right_Click45_Impl));
52  mxTopLevel->connect_focus_in(LINK(this, AreaTransparencyGradientPopup, FocusHdl));
53 }
54 
56 {
57 }
58 
60 {
61  const XGradient& rGradient = pGradientItem->GetGradientValue();
62 
63  XGradient aGradient;
64 
67  && (rGradient.GetAngle() / 10) == AreaPropertyPanelBase::DEFAULT_ANGLE
68  && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(rGradient.GetStartColor().GetRed()) + 1) * 100) / 255)
70  && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(rGradient.GetEndColor().GetRed()) + 1) * 100) / 255)
73  {
74  aGradient = mrAreaPropertyPanel.GetGradient(rGradient.GetGradientStyle());
75  }
76  else
77  {
78  aGradient = rGradient;
79  }
80  mxMtrTrgrCenterX->set_value(aGradient.GetXOffset(), FieldUnit::PERCENT);
81  mxMtrTrgrCenterY->set_value(aGradient.GetYOffset(), FieldUnit::PERCENT);
82  mxMtrTrgrAngle->set_value(aGradient.GetAngle() / 10, FieldUnit::DEGREE);
83  mxMtrTrgrStartValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aGradient.GetStartColor().GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
84  mxMtrTrgrEndValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aGradient.GetEndColor().GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
85  mxMtrTrgrBorder->set_value(aGradient.GetBorder(), FieldUnit::PERCENT);
86 }
87 
89 {
90  InitStatus(pGradientItem);
91  const XGradient& rGradient = pGradientItem->GetGradientValue();
92  css::awt::GradientStyle eXGS(rGradient.GetGradientStyle());
93 
94  switch(eXGS)
95  {
96  case css::awt::GradientStyle_LINEAR:
97  case css::awt::GradientStyle_AXIAL:
98  mxCenterGrid->hide();
99  mxAngleGrid->show();
100  break;
101  case css::awt::GradientStyle_RADIAL:
102  mxCenterGrid->show();
103  mxAngleGrid->hide();
104  break;
105  case css::awt::GradientStyle_ELLIPTICAL:
106  case css::awt::GradientStyle_SQUARE:
107  case css::awt::GradientStyle_RECT:
108  mxCenterGrid->show();
109  mxAngleGrid->show();
110  break;
111  default:
112  break;
113  }
114 }
115 
117 {
118  //Added
119  sal_Int16 aMtrValue = static_cast<sal_Int16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
120  while(aMtrValue<0)
121  aMtrValue += 360;
122  sal_uInt16 nVal = aMtrValue/360;
123  nVal = aMtrValue - nVal*360;
124  mxMtrTrgrAngle->set_value(nVal, FieldUnit::DEGREE);
125  //End of new code
126  XGradient aTmpGradient(
127  Color(nStartCol, nStartCol, nStartCol),
128  Color(nEndCol, nEndCol, nEndCol),
129  static_cast<css::awt::GradientStyle>(mrAreaPropertyPanel.GetSelectedTransparencyTypeIndex()-2),
130  static_cast<sal_uInt16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE)) * 10,
131  static_cast<sal_uInt16>(mxMtrTrgrCenterX->get_value(FieldUnit::PERCENT)),
132  static_cast<sal_uInt16>(mxMtrTrgrCenterY->get_value(FieldUnit::PERCENT)),
133  static_cast<sal_uInt16>(mxMtrTrgrBorder->get_value(FieldUnit::PERCENT)),
134  100, 100);
135 
136  mrAreaPropertyPanel.SetGradient(aTmpGradient);
137 
138  XFillFloatTransparenceItem aGradientItem(aTmpGradient, true );
139 
141 }
142 
144 {
145  sal_uInt8 nStartCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrStartValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
146  sal_uInt8 nEndCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrEndValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
147  ExecuteValueModify( nStartCol, nEndCol );
148 }
149 
150 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, Left_Click45_Impl, const OString&, void)
151 {
152  sal_uInt8 nStartCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrStartValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
153  sal_uInt8 nEndCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrEndValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
154  sal_uInt16 nTemp = static_cast<sal_uInt16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
155  if (nTemp>=315)
156  nTemp -= 360;
157  nTemp += 45;
158  mxMtrTrgrAngle->set_value(nTemp, FieldUnit::DEGREE);
159  ExecuteValueModify(nStartCol, nEndCol);
160 }
161 
162 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, Right_Click45_Impl, const OString&, void)
163 {
164  sal_uInt8 nStartCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrStartValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
165  sal_uInt8 nEndCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrEndValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
166  sal_uInt16 nTemp = static_cast<sal_uInt16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
167  if (nTemp<45)
168  nTemp += 360;
169  nTemp -= 45;
170  mxMtrTrgrAngle->set_value(nTemp, FieldUnit::DEGREE);
171  ExecuteValueModify(nStartCol, nEndCol);
172 }
173 
175 {
176  mxMtrTrgrCenterX->grab_focus();
177 }
178 
179 } // end of namespace svx::sidebar
180 
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FieldUnit
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
sal_uInt8 GetRed() const
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrStartValue
const Color & GetStartColor() const
Definition: xgrad.hxx:67
sal_uInt16 GetYOffset() const
Definition: xgrad.hxx:72
const XGradient & GetGradient(const css::awt::GradientStyle eStyle) const
sal_uInt16 GetXOffset() const
Definition: xgrad.hxx:71
virtual void setFillFloatTransparence(const XFillFloatTransparenceItem &rItem)=0
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrCenterY
sal_uInt16 GetBorder() const
Definition: xgrad.hxx:70
const XGradient & GetGradientValue() const
Definition: xattr.cxx:2142
void InitStatus(XFillFloatTransparenceItem const *pGradientItem)
long GetAngle() const
Definition: xgrad.hxx:69
void ExecuteValueModify(sal_uInt8 nStartCol, sal_uInt8 nEndCol)
AreaTransparencyGradientPopup(AreaPropertyPanelBase &rPanel, weld::Widget *pParent)
void Rearrange(XFillFloatTransparenceItem const *pItem)
css::awt::GradientStyle GetGradientStyle() const
Definition: xgrad.hxx:66
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrBorder
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrAngle
unsigned char sal_uInt8
const OUString PERCENT("Percent")
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrCenterX
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrEndValue
void SetGradient(const XGradient &rGradient)
const Color & GetEndColor() const
Definition: xgrad.hxx:68