tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / slidesorter / view / SlsTheme.cxx
blob5172e6241eaaf7b6697ceb5f9843eef3add19fca
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 <bitmaps.hlst>
21 #include <view/SlsTheme.hxx>
22 #include <controller/SlsProperties.hxx>
23 #include <tools/color.hxx>
24 #include <vcl/outdev.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/settings.hxx>
28 #include <osl/diagnose.h>
30 namespace sd::slidesorter::view {
32 const Color Black(0x000000);
33 const Color White(0xffffff);
35 static Color ChangeLuminance (Color aColor, const int nValue)
37 if (nValue > 0)
38 aColor.IncreaseLuminance(nValue);
39 else
40 aColor.DecreaseLuminance(-nValue);
41 return aColor;
44 static Color HGBAdapt (
45 const Color aColor,
46 const sal_Int32 nNewSaturation,
47 const sal_Int32 nNewBrightness)
49 sal_uInt16 nHue (0);
50 sal_uInt16 nSaturation (0);
51 sal_uInt16 nBrightness (0);
52 aColor.RGBtoHSB(nHue, nSaturation, nBrightness);
53 return Color::HSBtoRGB(
54 nHue,
55 nNewSaturation>=0 ? nNewSaturation : nSaturation,
56 nNewBrightness>=0 ? nNewBrightness : nBrightness);
59 Theme::Theme (const std::shared_ptr<controller::Properties>& rpProperties)
60 : maBackgroundColor(rpProperties->GetBackgroundColor())
62 maColor.resize(ColorType_Size_);
63 maColor[Color_Background] = maBackgroundColor;
64 maColor[Color_PageNumberDefault] = Color(0x0808080);
65 maColor[Color_PageNumberHover] = Color(0x4c4c4c);
66 maColor[Color_PageNumberHighContrast] = White;
67 maColor[Color_PageNumberBrightBackground] = Color(0x333333);
68 maColor[Color_PageNumberDarkBackground] = Color(0xcccccc);
69 maColor[Color_PreviewBorder] = Color(0x949599);
71 Update(rpProperties);
74 void Theme::Update (const std::shared_ptr<controller::Properties>& rpProperties)
76 // Set up colors.
77 maBackgroundColor = rpProperties->GetBackgroundColor();
79 maColor[Color_Background] = maBackgroundColor;
81 maGradients.resize(GradientColorType_Size_);
83 maColor[Color_Background] = maBackgroundColor;
84 const Color aSelectionColor (rpProperties->GetSelectionColor());
85 maColor[Color_Selection] = aSelectionColor;
86 if (aSelectionColor.IsBright())
87 maColor[Color_PageCountFontColor] = Black;
88 else
89 maColor[Color_PageCountFontColor] = White;
91 // Set up gradients.
92 SetGradient(Gradient_MouseOverPage, aSelectionColor, 0, 60, +80,+100, +50,+25);
93 SetGradient(Gradient_SelectedPage, aSelectionColor, 50, 50, +80,+100, +50,+25);
94 SetGradient(Gradient_FocusedPage, aSelectionColor, -1,-1, 0,0, -50,-75);
95 SetGradient(Gradient_MouseOverSelected, aSelectionColor, 55, 60, +80,+100, +50,+25);
96 SetGradient(Gradient_SelectedAndFocusedPage, aSelectionColor, 50, 50, +80,+100, -50,-75);
97 SetGradient(Gradient_MouseOverSelectedAndFocusedPage, aSelectionColor, 55, 60, +80,+100, -50,-75);
99 SetGradient(Gradient_NormalPage, maBackgroundColor, -1,-1, 0,0, 0,0);
101 // The focused gradient needs special handling because its fill color is
102 // like that of the NormalPage gradient.
103 GetGradient(Gradient_FocusedPage).maFillColor1 = GetGradient(Gradient_NormalPage).maFillColor1;
104 GetGradient(Gradient_FocusedPage).maFillColor2 = GetGradient(Gradient_NormalPage).maFillColor2;
106 // Set up icons.
107 if (maIcons.empty())
109 maIcons.resize(IconType_Size_);
111 InitializeIcon(Icon_RawShadow, IMAGE_SHADOW);
112 InitializeIcon(Icon_RawInsertShadow, IMAGE_INSERT_SHADOW);
113 InitializeIcon(Icon_HideSlideOverlay, IMAGE_HIDE_SLIDE_OVERLAY);
114 InitializeIcon(Icon_FocusBorder, IMAGE_FOCUS_BORDER);
118 std::shared_ptr<vcl::Font> Theme::GetFont (
119 const FontType eType,
120 const OutputDevice& rDevice)
122 std::shared_ptr<vcl::Font> pFont;
124 switch (eType)
126 case Font_PageNumber:
127 pFont = std::make_shared<vcl::Font>(Application::GetSettings().GetStyleSettings().GetAppFont());
128 pFont->SetTransparent(true);
129 pFont->SetWeight(WEIGHT_BOLD);
130 break;
132 case Font_PageCount:
133 pFont = std::make_shared<vcl::Font>(Application::GetSettings().GetStyleSettings().GetAppFont());
134 pFont->SetTransparent(true);
135 pFont->SetWeight(WEIGHT_NORMAL);
137 const Size aSize (pFont->GetFontSize());
138 pFont->SetFontSize(Size(aSize.Width()*5/3, aSize.Height()*5/3));
140 break;
143 if (pFont)
145 // Transform the point size to pixel size.
146 const MapMode aFontMapMode (MapUnit::MapPoint);
147 const Size aFontSize (rDevice.LogicToPixel(pFont->GetFontSize(), aFontMapMode));
149 // Transform the font size to the logical coordinates of the device.
150 pFont->SetFontSize(rDevice.PixelToLogic(aFontSize));
153 return pFont;
156 Color Theme::GetColor (const ColorType eType)
158 if (sal_uInt32(eType)<maColor.size())
159 return maColor[eType];
160 else
161 return Color(0);
164 Color Theme::GetGradientColor (
165 const GradientColorType eType,
166 const GradientColorClass eClass)
168 GradientDescriptor& rDescriptor (GetGradient(eType));
170 switch (eClass)
172 case GradientColorClass::Border1: return rDescriptor.maBorderColor1;
173 case GradientColorClass::Border2: return rDescriptor.maBorderColor2;
174 case GradientColorClass::Fill1: return rDescriptor.maFillColor1;
175 case GradientColorClass::Fill2: return rDescriptor.maFillColor2;
177 return Color(0);
180 void Theme::SetGradient (
181 const GradientColorType eType,
182 const Color aBaseColor,
183 const sal_Int32 nSaturationOverride,
184 const sal_Int32 nBrightnessOverride,
185 const sal_Int32 nFillStartOffset,
186 const sal_Int32 nFillEndOffset,
187 const sal_Int32 nBorderStartOffset,
188 const sal_Int32 nBorderEndOffset)
190 GradientDescriptor& rGradient (GetGradient(eType));
192 const Color aColor (nSaturationOverride>=0 || nBrightnessOverride>=0
193 ? HGBAdapt(aBaseColor, nSaturationOverride, nBrightnessOverride)
194 : aBaseColor);
196 rGradient.maFillColor1 = ChangeLuminance(aColor, nFillStartOffset);
197 rGradient.maFillColor2 = ChangeLuminance(aColor, nFillEndOffset);
198 rGradient.maBorderColor1 = ChangeLuminance(aColor, nBorderStartOffset);
199 rGradient.maBorderColor2 = ChangeLuminance(aColor, nBorderEndOffset);
202 const BitmapEx& Theme::GetIcon (const IconType eType)
204 if (size_t(eType)<maIcons.size())
205 return maIcons[eType];
206 else
208 OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
209 return maIcons[0];
213 Theme::GradientDescriptor& Theme::GetGradient (const GradientColorType eType)
215 if (size_t(eType)<maGradients.size())
216 return maGradients[eType];
217 else
219 OSL_ASSERT(eType>=0 && size_t(eType)<maGradients.size());
220 return maGradients[0];
224 void Theme::InitializeIcon(const IconType eType, const OUString& rResourceId)
226 if (size_t(eType)<maIcons.size())
228 const BitmapEx aIcon(rResourceId);
229 maIcons[eType] = aIcon;
231 else
233 OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
237 } // end of namespace ::sd::slidesorter::view
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */