bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / sidebar / area / AreaTransparencyGradientPopup.cxx
blob7c4a8dc599621ec49b66bef505c692311c455053
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/sidebar/AreaTransparencyGradientPopup.hxx>
21 #include <svx/sidebar/AreaPropertyPanelBase.hxx>
22 #include <svx/xflftrit.hxx>
23 #include <svx/xgrad.hxx>
24 #include <vcl/svapp.hxx>
26 namespace svx::sidebar {
28 AreaTransparencyGradientPopup::AreaTransparencyGradientPopup(AreaPropertyPanelBase& rPanel, weld::Widget* pParent)
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))
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));
55 AreaTransparencyGradientPopup::~AreaTransparencyGradientPopup()
59 void AreaTransparencyGradientPopup::InitStatus(XFillFloatTransparenceItem const * pGradientItem)
61 const XGradient& rGradient = pGradientItem->GetGradientValue();
63 XGradient aGradient;
65 if (rGradient.GetXOffset() == AreaPropertyPanelBase::DEFAULT_CENTERX
66 && rGradient.GetYOffset() == AreaPropertyPanelBase::DEFAULT_CENTERY
67 && (rGradient.GetAngle().get() / 10) == AreaPropertyPanelBase::DEFAULT_ANGLE
68 && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(rGradient.GetStartColor().GetRed()) + 1) * 100) / 255)
69 == AreaPropertyPanelBase::DEFAULT_STARTVALUE
70 && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(rGradient.GetEndColor().GetRed()) + 1) * 100) / 255)
71 == AreaPropertyPanelBase::DEFAULT_ENDVALUE
72 && rGradient.GetBorder() == AreaPropertyPanelBase::DEFAULT_BORDER)
74 aGradient = mrAreaPropertyPanel.GetGradient(rGradient.GetGradientStyle());
76 else
78 aGradient = rGradient;
80 mxMtrTrgrCenterX->set_value(aGradient.GetXOffset(), FieldUnit::PERCENT);
81 mxMtrTrgrCenterY->set_value(aGradient.GetYOffset(), FieldUnit::PERCENT);
82 mxMtrTrgrAngle->set_value(aGradient.GetAngle().get() / 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);
88 void AreaTransparencyGradientPopup::Rearrange(XFillFloatTransparenceItem const * pGradientItem)
90 InitStatus(pGradientItem);
91 const XGradient& rGradient = pGradientItem->GetGradientValue();
92 css::awt::GradientStyle eXGS(rGradient.GetGradientStyle());
94 switch(eXGS)
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;
116 void AreaTransparencyGradientPopup::ExecuteValueModify(sal_uInt8 nStartCol, sal_uInt8 nEndCol)
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 Degree10(static_cast<sal_Int16>(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);
136 mrAreaPropertyPanel.SetGradient(aTmpGradient);
138 XFillFloatTransparenceItem aGradientItem(aTmpGradient, true );
140 mrAreaPropertyPanel.setFillFloatTransparence(aGradientItem);
143 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, ModifiedTrgrHdl_Impl, weld::MetricSpinButton&, void)
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 );
150 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, Left_Click45_Impl, const OString&, void)
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);
162 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, Right_Click45_Impl, const OString&, void)
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);
174 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, FocusHdl, weld::Widget&, void)
176 mxMtrTrgrCenterX->grab_focus();
179 } // end of namespace svx::sidebar
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */