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
24namespace svx::sidebar {
25
26AreaTransparencyGradientPopup::AreaTransparencyGradientPopup(const css::uno::Reference<css::frame::XFrame>& rFrame,
27 AreaPropertyPanelBase& rPanel, weld::Widget* pParent)
28 : WeldToolbarPopup(rFrame, pParent, "svx/ui/floatingareastyle.ui", "FloatingAreaStyle")
29 , mrAreaPropertyPanel(rPanel)
30 , mxCenterGrid(m_xBuilder->weld_widget("centergrid"))
31 , mxAngleGrid(m_xBuilder->weld_widget("anglegrid"))
32 , mxMtrTrgrCenterX(m_xBuilder->weld_metric_spin_button("centerx", FieldUnit::PERCENT))
33 , mxMtrTrgrCenterY(m_xBuilder->weld_metric_spin_button("centery", FieldUnit::PERCENT))
34 , mxMtrTrgrAngle(m_xBuilder->weld_metric_spin_button("angle", FieldUnit::DEGREE))
35 , mxBtnLeft45(m_xBuilder->weld_toolbar("lefttoolbox"))
36 , mxBtnRight45(m_xBuilder->weld_toolbar("righttoolbox"))
37 , mxMtrTrgrStartValue(m_xBuilder->weld_metric_spin_button("start", FieldUnit::PERCENT))
38 , mxMtrTrgrEndValue(m_xBuilder->weld_metric_spin_button("end", FieldUnit::PERCENT))
39 , mxMtrTrgrBorder(m_xBuilder->weld_metric_spin_button("border", FieldUnit::PERCENT))
40{
42 mxMtrTrgrCenterX->connect_value_changed(aLink);
43 mxMtrTrgrCenterY->connect_value_changed(aLink);
44 mxMtrTrgrAngle->connect_value_changed(aLink);
45 mxMtrTrgrBorder->connect_value_changed(aLink);
46 mxMtrTrgrStartValue->connect_value_changed(aLink);
47 mxMtrTrgrEndValue->connect_value_changed(aLink);
48 mxBtnLeft45->connect_clicked(LINK(this, AreaTransparencyGradientPopup, Left_Click45_Impl));
49 mxBtnRight45->connect_clicked(LINK(this, AreaTransparencyGradientPopup, Right_Click45_Impl));
50}
51
53{
54}
55
57{
58 const basegfx::BGradient& rGradient = pGradientItem->GetGradientValue();
59
60 basegfx::BGradient aGradient;
61 Color aStart(rGradient.GetColorStops().front().getStopColor());
62 Color aEnd(rGradient.GetColorStops().back().getStopColor());
63
66 && static_cast<sal_Int32>(toDegrees(rGradient.GetAngle())) == AreaPropertyPanelBase::DEFAULT_ANGLE
67 && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aStart.GetRed()) + 1) * 100) / 255)
69 && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aEnd.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(toDegrees(aGradient.GetAngle()), FieldUnit::DEGREE);
82 aStart = Color(aGradient.GetColorStops().front().getStopColor());
83 aEnd = Color(aGradient.GetColorStops().back().getStopColor());
84 mxMtrTrgrStartValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aStart.GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
85 mxMtrTrgrEndValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aEnd.GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
86
87 // MCGR: preserve ColorStops if given
88 // tdf#155901 We need offset of first and last stop, so include them.
89 if (aGradient.GetColorStops().size() >= 2)
90 maColorStops = aGradient.GetColorStops();
91 else
92 maColorStops.clear();
93
94 mxMtrTrgrBorder->set_value(aGradient.GetBorder(), FieldUnit::PERCENT);
95}
96
98{
99 InitStatus(pGradientItem);
100 const basegfx::BGradient& rGradient = pGradientItem->GetGradientValue();
101 css::awt::GradientStyle eXGS(rGradient.GetGradientStyle());
102
103 switch(eXGS)
104 {
105 case css::awt::GradientStyle_LINEAR:
106 case css::awt::GradientStyle_AXIAL:
107 mxCenterGrid->hide();
108 mxAngleGrid->show();
109 break;
110 case css::awt::GradientStyle_RADIAL:
111 mxCenterGrid->show();
112 mxAngleGrid->hide();
113 break;
114 case css::awt::GradientStyle_ELLIPTICAL:
115 case css::awt::GradientStyle_SQUARE:
116 case css::awt::GradientStyle_RECT:
117 mxCenterGrid->show();
118 mxAngleGrid->show();
119 break;
120 default:
121 break;
122 }
123}
124
126{
127 //Added
128 sal_Int16 aMtrValue = static_cast<sal_Int16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
129 while(aMtrValue<0)
130 aMtrValue += 360;
131 sal_uInt16 nVal = aMtrValue/360;
132 nVal = aMtrValue - nVal*360;
133 mxMtrTrgrAngle->set_value(nVal, FieldUnit::DEGREE);
134 //End of new code
135
136 basegfx::BColorStops aColorStops;
137 basegfx::BColor aStartBColor(mxMtrTrgrStartValue->get_value(FieldUnit::PERCENT) / 100.0);
138 aStartBColor.clamp();
139 basegfx::BColor aEndBColor(mxMtrTrgrEndValue->get_value(FieldUnit::PERCENT) / 100.0);
140 aEndBColor.clamp();
141
142 if (maColorStops.size() >= 2)
143 {
144 aColorStops = maColorStops;
145 aColorStops.front() = basegfx::BColorStop(maColorStops.front().getStopOffset(), aStartBColor);
146 aColorStops.back() = basegfx::BColorStop(maColorStops.back().getStopOffset(), aEndBColor);
147 }
148 else
149 {
150 aColorStops.emplace_back(0.0, aStartBColor);
151 aColorStops.emplace_back(1.0, aEndBColor);
152 }
153
154 basegfx::BGradient aTmpGradient(
155 aColorStops,
156 static_cast<css::awt::GradientStyle>(mrAreaPropertyPanel.GetSelectedTransparencyTypeIndex()-2),
157 Degree10(static_cast<sal_Int16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE)) * 10),
158 static_cast<sal_uInt16>(mxMtrTrgrCenterX->get_value(FieldUnit::PERCENT)),
159 static_cast<sal_uInt16>(mxMtrTrgrCenterY->get_value(FieldUnit::PERCENT)),
160 static_cast<sal_uInt16>(mxMtrTrgrBorder->get_value(FieldUnit::PERCENT)),
161 100, 100);
162
163 mrAreaPropertyPanel.SetGradient(aTmpGradient);
164
165 XFillFloatTransparenceItem aGradientItem(aTmpGradient, true );
166
168}
169
171{
172 ExecuteValueModify();
173}
174
175IMPL_LINK_NOARG(AreaTransparencyGradientPopup, Left_Click45_Impl, const OUString&, void)
176{
177 sal_uInt16 nTemp = static_cast<sal_uInt16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
178 if (nTemp>=315)
179 nTemp -= 360;
180 nTemp += 45;
181 mxMtrTrgrAngle->set_value(nTemp, FieldUnit::DEGREE);
182 ExecuteValueModify();
183}
184
185IMPL_LINK_NOARG(AreaTransparencyGradientPopup, Right_Click45_Impl, const OUString&, void)
186{
187 sal_uInt16 nTemp = static_cast<sal_uInt16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
188 if (nTemp<45)
189 nTemp += 360;
190 nTemp -= 45;
191 mxMtrTrgrAngle->set_value(nTemp, FieldUnit::DEGREE);
192 ExecuteValueModify();
193}
194
196{
197 mxMtrTrgrCenterX->grab_focus();
198}
199
200} // end of namespace svx::sidebar
201
202/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 GetRed() const
const basegfx::BGradient & GetGradientValue() const
Definition: xattr.cxx:2226
BColor & clamp()
sal_uInt16 GetBorder() const
sal_uInt16 GetXOffset() const
const basegfx::BColorStops & GetColorStops() const
Degree10 GetAngle() const
css::awt::GradientStyle GetGradientStyle() const
sal_uInt16 GetYOffset() const
const basegfx::BGradient & GetGradient(const css::awt::GradientStyle eStyle) const
virtual void setFillFloatTransparence(const XFillFloatTransparenceItem &rItem)=0
void SetGradient(const basegfx::BGradient &rGradient)
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrCenterX
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrStartValue
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrEndValue
AreaTransparencyGradientPopup(const css::uno::Reference< css::frame::XFrame > &rFrame, AreaPropertyPanelBase &rPanel, weld::Widget *pParent)
void InitStatus(XFillFloatTransparenceItem const *pGradientItem)
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrAngle
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrCenterY
void Rearrange(XFillFloatTransparenceItem const *pItem)
std::unique_ptr< weld::MetricSpinButton > mxMtrTrgrBorder
double toDegrees(D x)
FieldUnit
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OUString &, void)
constexpr OUStringLiteral PERCENT(u"Percent")