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