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 
28 AreaTransparencyGradientPopup::AreaTransparencyGradientPopup(const css::uno::Reference<css::frame::XFrame>& rFrame,
29  AreaPropertyPanelBase& rPanel, weld::Widget* pParent)
30  : WeldToolbarPopup(rFrame, pParent, "svx/ui/floatingareastyle.ui", "FloatingAreaStyle")
31  , mrAreaPropertyPanel(rPanel)
32  , mxCenterGrid(m_xBuilder->weld_widget("centergrid"))
33  , mxAngleGrid(m_xBuilder->weld_widget("anglegrid"))
34  , mxMtrTrgrCenterX(m_xBuilder->weld_metric_spin_button("centerx", FieldUnit::PERCENT))
35  , mxMtrTrgrCenterY(m_xBuilder->weld_metric_spin_button("centery", FieldUnit::PERCENT))
36  , mxMtrTrgrAngle(m_xBuilder->weld_metric_spin_button("angle", FieldUnit::DEGREE))
37  , mxBtnLeft45(m_xBuilder->weld_toolbar("lefttoolbox"))
38  , mxBtnRight45(m_xBuilder->weld_toolbar("righttoolbox"))
39  , mxMtrTrgrStartValue(m_xBuilder->weld_metric_spin_button("start", FieldUnit::PERCENT))
40  , mxMtrTrgrEndValue(m_xBuilder->weld_metric_spin_button("end", FieldUnit::PERCENT))
41  , mxMtrTrgrBorder(m_xBuilder->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 }
53 
55 {
56 }
57 
59 {
60  const XGradient& rGradient = pGradientItem->GetGradientValue();
61 
62  XGradient aGradient;
63 
66  && (rGradient.GetAngle().get() / 10) == AreaPropertyPanelBase::DEFAULT_ANGLE
67  && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(rGradient.GetStartColor().GetRed()) + 1) * 100) / 255)
69  && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(rGradient.GetEndColor().GetRed()) + 1) * 100) / 255)
72  {
73  aGradient = mrAreaPropertyPanel.GetGradient(rGradient.GetGradientStyle());
74  }
75  else
76  {
77  aGradient = rGradient;
78  }
79  mxMtrTrgrCenterX->set_value(aGradient.GetXOffset(), FieldUnit::PERCENT);
80  mxMtrTrgrCenterY->set_value(aGradient.GetYOffset(), FieldUnit::PERCENT);
81  mxMtrTrgrAngle->set_value(aGradient.GetAngle().get() / 10, FieldUnit::DEGREE);
82  mxMtrTrgrStartValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aGradient.GetStartColor().GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
83  mxMtrTrgrEndValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aGradient.GetEndColor().GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
84  mxMtrTrgrBorder->set_value(aGradient.GetBorder(), FieldUnit::PERCENT);
85 }
86 
88 {
89  InitStatus(pGradientItem);
90  const XGradient& rGradient = pGradientItem->GetGradientValue();
91  css::awt::GradientStyle eXGS(rGradient.GetGradientStyle());
92 
93  switch(eXGS)
94  {
95  case css::awt::GradientStyle_LINEAR:
96  case css::awt::GradientStyle_AXIAL:
97  mxCenterGrid->hide();
98  mxAngleGrid->show();
99  break;
100  case css::awt::GradientStyle_RADIAL:
101  mxCenterGrid->show();
102  mxAngleGrid->hide();
103  break;
104  case css::awt::GradientStyle_ELLIPTICAL:
105  case css::awt::GradientStyle_SQUARE:
106  case css::awt::GradientStyle_RECT:
107  mxCenterGrid->show();
108  mxAngleGrid->show();
109  break;
110  default:
111  break;
112  }
113 }
114 
116 {
117  //Added
118  sal_Int16 aMtrValue = static_cast<sal_Int16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
119  while(aMtrValue<0)
120  aMtrValue += 360;
121  sal_uInt16 nVal = aMtrValue/360;
122  nVal = aMtrValue - nVal*360;
123  mxMtrTrgrAngle->set_value(nVal, FieldUnit::DEGREE);
124  //End of new code
125  XGradient aTmpGradient(
126  Color(nStartCol, nStartCol, nStartCol),
127  Color(nEndCol, nEndCol, nEndCol),
128  static_cast<css::awt::GradientStyle>(mrAreaPropertyPanel.GetSelectedTransparencyTypeIndex()-2),
129  Degree10(static_cast<sal_Int16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE)) * 10),
130  static_cast<sal_uInt16>(mxMtrTrgrCenterX->get_value(FieldUnit::PERCENT)),
131  static_cast<sal_uInt16>(mxMtrTrgrCenterY->get_value(FieldUnit::PERCENT)),
132  static_cast<sal_uInt16>(mxMtrTrgrBorder->get_value(FieldUnit::PERCENT)),
133  100, 100);
134 
135  mrAreaPropertyPanel.SetGradient(aTmpGradient);
136 
137  XFillFloatTransparenceItem aGradientItem(aTmpGradient, true );
138 
140 }
141 
143 {
144  sal_uInt8 nStartCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrStartValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
145  sal_uInt8 nEndCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrEndValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
146  ExecuteValueModify( nStartCol, nEndCol );
147 }
148 
149 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, Left_Click45_Impl, const OString&, void)
150 {
151  sal_uInt8 nStartCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrStartValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
152  sal_uInt8 nEndCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrEndValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
153  sal_uInt16 nTemp = static_cast<sal_uInt16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
154  if (nTemp>=315)
155  nTemp -= 360;
156  nTemp += 45;
157  mxMtrTrgrAngle->set_value(nTemp, FieldUnit::DEGREE);
158  ExecuteValueModify(nStartCol, nEndCol);
159 }
160 
161 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, Right_Click45_Impl, const OString&, void)
162 {
163  sal_uInt8 nStartCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrStartValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
164  sal_uInt8 nEndCol = static_cast<sal_uInt8>((static_cast<sal_uInt16>(mxMtrTrgrEndValue->get_value(FieldUnit::PERCENT)) * 255) / 100);
165  sal_uInt16 nTemp = static_cast<sal_uInt16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
166  if (nTemp<45)
167  nTemp += 360;
168  nTemp -= 45;
169  mxMtrTrgrAngle->set_value(nTemp, FieldUnit::DEGREE);
170  ExecuteValueModify(nStartCol, nEndCol);
171 }
172 
174 {
175  mxMtrTrgrCenterX->grab_focus();
176 }
177 
178 } // end of namespace svx::sidebar
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FieldUnit
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
sal_uInt8 GetRed() const
Degree10 GetAngle() const
Definition: xgrad.hxx:71
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrStartValue
constexpr OUStringLiteral PERCENT(u"Percent")
const Color & GetStartColor() const
Definition: xgrad.hxx:69
sal_uInt16 GetYOffset() const
Definition: xgrad.hxx:74
const XGradient & GetGradient(const css::awt::GradientStyle eStyle) const
sal_uInt16 GetXOffset() const
Definition: xgrad.hxx:73
virtual void setFillFloatTransparence(const XFillFloatTransparenceItem &rItem)=0
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrCenterY
UNDERLYING_TYPE get() const
sal_uInt16 GetBorder() const
Definition: xgrad.hxx:72
const XGradient & GetGradientValue() const
Definition: xattr.cxx:2160
AreaTransparencyGradientPopup(const css::uno::Reference< css::frame::XFrame > &rFrame, AreaPropertyPanelBase &rPanel, weld::Widget *pParent)
void InitStatus(XFillFloatTransparenceItem const *pGradientItem)
void ExecuteValueModify(sal_uInt8 nStartCol, sal_uInt8 nEndCol)
void Rearrange(XFillFloatTransparenceItem const *pItem)
css::awt::GradientStyle GetGradientStyle() const
Definition: xgrad.hxx:68
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrBorder
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrAngle
unsigned char sal_uInt8
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrCenterX
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrEndValue
void SetGradient(const XGradient &rGradient)
const Color & GetEndColor() const
Definition: xgrad.hxx:70