LibreOffice Module sd (master) 1
SlsPageObjectLayouter.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
21
23#include <view/SlsTheme.hxx>
24#include <tools/IconCache.hxx>
25#include <Window.hxx>
26
27#include <bitmaps.hlst>
28#include <osl/diagnose.h>
29
30namespace sd::slidesorter::view {
31
32namespace {
33const sal_Int32 gnLeftPageNumberOffset = 2;
34const sal_Int32 gnRightPageNumberOffset = 5;
35const sal_Int32 gnOuterBorderWidth = 5;
36const sal_Int32 gnInfoAreaMinWidth = 26;
37}
38
40 const Size& rPageObjectWindowSize,
41 const Size& rPageSize,
42 sd::Window *pWindow,
43 const sal_Int32 nPageCount)
44 : mpWindow(pWindow),
45 maTransitionEffectIcon(IconCache::Instance().GetIcon(BMP_FADE_EFFECT_INDICATOR)),
46 maCustomAnimationEffectIcon(IconCache::Instance().GetIcon(BMP_CUSTOM_ANIMATION_INDICATOR)),
47 mpPageNumberFont(Theme::GetFont(Theme::Font_PageNumber, *pWindow->GetOutDev()))
48{
49 const Size aPageNumberAreaSize (GetPageNumberAreaSize(nPageCount));
50
51 const int nMaximumBorderWidth (gnOuterBorderWidth);
52 const int nFocusIndicatorWidth (Theme_FocusIndicatorWidth);
53
54 Size aPageObjectSize(rPageObjectWindowSize.Width(), rPageObjectWindowSize.Height());
56 aPageObjectSize,
57 Size(rPageSize.Width(), rPageSize.Height()),
58 aPageNumberAreaSize.Width(),
59 nFocusIndicatorWidth);
62 Point(
63 nFocusIndicatorWidth,
64 nFocusIndicatorWidth),
65 Size(
66 aPageObjectSize.Width()-2*nFocusIndicatorWidth,
67 aPageObjectSize.Height()-2*nFocusIndicatorWidth));
68
70 Point(
71 std::max(gnLeftPageNumberOffset,
72 sal_Int32(maPreviewBoundingBox.Left()
73 - gnRightPageNumberOffset
74 - aPageNumberAreaSize.Width())),
75 nMaximumBorderWidth),
76 aPageNumberAreaSize);
77
78 const Size aIconSize (maTransitionEffectIcon.GetSizePixel());
80 Point(
81 (maPreviewBoundingBox.Left() - 2*aIconSize.Width()) / 2,
82 maPreviewBoundingBox.Bottom() - aIconSize.Height()),
83 aIconSize);
85 Point(
86 (maPreviewBoundingBox.Left() - 2*aIconSize.Width()) / 2,
87 maPreviewBoundingBox.Bottom() - 2*aIconSize.Height()),
88 aIconSize);
89}
90
92{
93}
94
96 Size& rPageObjectSize,
97 const Size& rPageSize,
98 const sal_Int32 nPageNumberAreaWidth,
99 const sal_Int32 nFocusIndicatorWidth)
100{
101 const sal_Int32 nIconWidth (maTransitionEffectIcon.GetSizePixel().Width());
102 const sal_Int32 nLeftAreaWidth (
103 ::std::max(
104 gnInfoAreaMinWidth,
105 gnRightPageNumberOffset
106 + ::std::max(
107 nPageNumberAreaWidth,
108 nIconWidth)));
109 sal_Int32 nPreviewWidth;
110 sal_Int32 nPreviewHeight;
111 const double nPageAspectRatio (double(rPageSize.Width()) / double(rPageSize.Height()));
112 if (rPageObjectSize.Height() == 0)
113 {
114 // Calculate height so that the preview fills the available
115 // horizontal space completely while observing the aspect ratio of
116 // the preview.
117 nPreviewWidth = rPageObjectSize.Width()
118 - nLeftAreaWidth - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
119 nPreviewHeight = ::basegfx::fround(nPreviewWidth / nPageAspectRatio);
120 rPageObjectSize.setHeight(nPreviewHeight + 2*gnOuterBorderWidth + 2*nFocusIndicatorWidth + 1);
121 }
122 else if (rPageObjectSize.Width() == 0)
123 {
124 // Calculate the width of the page object so that the preview fills
125 // the available vertical space completely while observing the
126 // aspect ratio of the preview.
127 nPreviewHeight = rPageObjectSize.Height() - 2*gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
128 nPreviewWidth = ::basegfx::fround(nPreviewHeight * nPageAspectRatio);
129 rPageObjectSize.setWidth(nPreviewWidth
130 + nLeftAreaWidth + gnOuterBorderWidth + 2*nFocusIndicatorWidth + 1);
131
132 }
133 else
134 {
135 // The size of the page object is given. Calculate the size of the
136 // preview.
137 nPreviewWidth = rPageObjectSize.Width()
138 - nLeftAreaWidth - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
139 nPreviewHeight = rPageObjectSize.Height()
140 - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
141 if (double(nPreviewWidth)/double(nPreviewHeight) > nPageAspectRatio)
142 nPreviewWidth = ::basegfx::fround(nPreviewHeight * nPageAspectRatio);
143 else
144 nPreviewHeight = ::basegfx::fround(nPreviewWidth / nPageAspectRatio);
145 }
146 // When the preview does not fill the available space completely then
147 // place it flush right and vertically centered.
148 const int nLeft (rPageObjectSize.Width()
149 - gnOuterBorderWidth - nPreviewWidth - nFocusIndicatorWidth - 1);
150 const int nTop ((rPageObjectSize.Height() - nPreviewHeight)/2);
151 return ::tools::Rectangle(
152 nLeft,
153 nTop,
154 nLeft + nPreviewWidth,
155 nTop + nPreviewHeight);
156}
157
159 const model::SharedPageDescriptor& rpPageDescriptor,
160 const Part ePart,
161 const CoordinateSystem eCoordinateSystem,
162 bool bIgnoreLocation)
163{
164 OSL_ASSERT(rpPageDescriptor);
165 Point aLocation(0,0);
166 if (rpPageDescriptor)
167 aLocation = rpPageDescriptor->GetLocation( bIgnoreLocation );
168 return GetBoundingBox(aLocation, ePart, eCoordinateSystem);
169}
170
172 const Point& rPageObjectLocation,
173 const Part ePart,
174 const CoordinateSystem eCoordinateSystem)
175{
176 ::tools::Rectangle aBoundingBox;
177 switch (ePart)
178 {
180 aBoundingBox = maFocusIndicatorBoundingBox;
181 break;
182
183 case Part::PageObject:
184 aBoundingBox = maPageObjectBoundingBox;
185 break;
186
187 case Part::Preview:
188 aBoundingBox = maPreviewBoundingBox;
189 break;
190
191 case Part::PageNumber:
192 aBoundingBox = maPageNumberAreaBoundingBox;
193 break;
194
196 aBoundingBox = maTransitionEffectBoundingBox;
197 break;
200 break;
201 }
202
203 // Adapt coordinates to the requested coordinate system.
204 Point aLocation (rPageObjectLocation);
205 if (eCoordinateSystem == WindowCoordinateSystem)
206 aLocation += mpWindow->GetMapMode().GetOrigin();
207
208 return ::tools::Rectangle(
209 aBoundingBox.TopLeft() + aLocation,
210 aBoundingBox.BottomRight() + aLocation);
211}
212
214{
217}
218
220{
223}
224
226{
227 OSL_ASSERT(mpWindow);
228
229 // Set the correct font.
230 vcl::Font aOriginalFont (mpWindow->GetFont());
232 mpWindow->SetFont(*mpPageNumberFont);
233
234 OUString sPageNumberTemplate;
235 if (nPageCount < 10)
236 sPageNumberTemplate = "9";
237 else if (nPageCount < 100)
238 sPageNumberTemplate = "99";
239 else if (nPageCount < 200)
240 // Just for the case that 1 is narrower than 9.
241 sPageNumberTemplate = "199";
242 else if (nPageCount < 1000)
243 sPageNumberTemplate = "999";
244 else
245 sPageNumberTemplate = "9999";
246 // More than 9999 pages are not handled.
247
248 const Size aSize (
249 mpWindow->GetTextWidth(sPageNumberTemplate),
250 mpWindow->GetTextHeight());
251
252 mpWindow->SetFont(aOriginalFont);
253
254 return aSize;
255}
256
257} // end of namespace ::sd::slidesorter::view
258
259/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Size GetSizePixel() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
This simple class stores frequently used icons so that the classes that use the icons do not have to ...
Definition: IconCache.hxx:38
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
Size GetPreviewSize()
the size of the embedded preview: position independent, in window coordinate system
PageObjectLayouter(const Size &rPageObjectWindowSize, const Size &rPreviewModelSize, sd::Window *pWindow, const sal_Int32 nPageCount)
Create a new PageObjectLayouter object.
::tools::Rectangle CalculatePreviewBoundingBox(Size &rPageObjectSize, const Size &rPreviewModelSize, const sal_Int32 nPageNumberAreaWidth, const sal_Int32 nFocusIndicatorWidth)
::tools::Rectangle GetBoundingBox(const model::SharedPageDescriptor &rpPageDescriptor, const Part ePart, const CoordinateSystem eCoordinateSystem, bool bIgnoreLocation=false)
Return the bounding box of the page object or one of its graphical parts.
CoordinateSystem
Two coordinate systems are supported.
const std::shared_ptr< vcl::Font > mpPageNumberFont
Size GetGridMaxSize()
the maximum size of each tile, also position independent, in window coordinate system
Collection of colors and styles that are used to paint the slide sorter view.
Definition: SlsTheme.hxx:39
constexpr Point TopLeft() const
constexpr Size GetSize() const
constexpr Point BottomRight() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
std::shared_ptr< PageDescriptor > SharedPageDescriptor
const int Theme_FocusIndicatorWidth
Definition: SlsTheme.hxx:33
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
VclPtr< vcl::Window > mpWindow