tdf#37654 - Add custom slide names to slide/page name

Change-Id: I5eace83ae8a81d456190dfd721f3d5dc03d0d8e6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205753
Tested-by: Jenkins
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
This commit is contained in:
Andreas Heinisch
2026-05-29 14:23:27 +02:00
parent 07b1781475
commit 671c60f628
4 changed files with 95 additions and 37 deletions
@@ -67,7 +67,9 @@ public:
TransitionEffectIndicator,
// Indicator whether or not there is a custom animation associated
// with this slide.
CustomAnimationEffectIndicator
CustomAnimationEffectIndicator,
// Bounding box of the slide name when the slide was renamed
PageName
};
/** Two coordinate systems are supported. They differ only in
translation not in scale. Both relate to pixel values in the window.
@@ -128,6 +130,8 @@ private:
::tools::Rectangle maPreviewBoundingBox;
::tools::Rectangle maTransitionEffectBoundingBox;
::tools::Rectangle maCustomAnimationEffectBoundingBox;
::tools::Rectangle maPageNameAreaBoundingBox;
::tools::Rectangle maPreviewWithNameBoundingBox;
const Image maTransitionEffectIcon;
const Image maCustomAnimationEffectIcon;
const std::shared_ptr<vcl::Font> mpPageNumberFont;
@@ -96,6 +96,12 @@ private:
OutputDevice& rDevice,
const Theme::GradientColorType eColorType,
const ::tools::Rectangle& rBox) const;
void PaintPageName (
PageObjectLayouter *pPageObjectLayouter,
OutputDevice& rDevice,
const model::SharedPageDescriptor& rpDescriptor) const;
Color GetPageTextColor (
const model::SharedPageDescriptor& rpDescriptor) const;
void PaintBackgroundDetail(
PageObjectLayouter *pPageObjectLayouter,
OutputDevice& rDevice,
@@ -24,6 +24,7 @@
#include <tools/IconCache.hxx>
#include <Window.hxx>
#include <sdpage.hxx>
#include <bitmaps.hlst>
#include <osl/diagnose.h>
@@ -75,6 +76,18 @@ PageObjectLayouter::PageObjectLayouter (
nMaximumBorderWidth),
aPageNumberAreaSize);
// Position the page name right of the page number, extending to the page edge
maPageNameAreaBoundingBox = ::tools::Rectangle(
Point(maPageNumberAreaBoundingBox.Right() + gnRightPageNumberOffset,
maPageNumberAreaBoundingBox.Top()),
Point(maPageObjectBoundingBox.Right(), maPageNumberAreaBoundingBox.Bottom()));
// Move the page preview below the custom page name to avoid any overlapping
const tools::Long nNameBottom = maPageNumberAreaBoundingBox.Bottom() + 1;
const tools::Long nNewTop = std::max<tools::Long>(nNameBottom, maPreviewBoundingBox.Top());
maPreviewWithNameBoundingBox = ::tools::Rectangle(Point(maPreviewBoundingBox.Left(), nNewTop),
maPreviewBoundingBox.BottomRight());
const Size aIconSize (maTransitionEffectIcon.GetSizePixel());
maTransitionEffectBoundingBox = ::tools::Rectangle(
Point(
@@ -165,6 +178,19 @@ PageObjectLayouter::~PageObjectLayouter()
Point aLocation(0,0);
if (rpPageDescriptor)
aLocation = rpPageDescriptor->GetLocation( bIgnoreLocation );
// Shift the preview of the page down when there is a custom name
if (ePart == Part::Preview && rpPageDescriptor && rpPageDescriptor->GetPage()
&& !rpPageDescriptor->GetPage()->GetRealName().isEmpty())
{
// Adapt coordinates to the requested coordinate system
Point aAdjustedLocation(aLocation);
if (eCoordinateSystem == WindowCoordinateSystem)
aAdjustedLocation += mpWindow->GetMapMode().GetOrigin();
return ::tools::Rectangle(maPreviewWithNameBoundingBox.TopLeft() + aAdjustedLocation,
maPreviewWithNameBoundingBox.BottomRight() + aAdjustedLocation);
}
return GetBoundingBox(aLocation, ePart, eCoordinateSystem);
}
@@ -198,6 +224,9 @@ PageObjectLayouter::~PageObjectLayouter()
case Part::CustomAnimationEffectIndicator:
aBoundingBox = maCustomAnimationEffectBoundingBox;
break;
case Part::PageName:
aBoundingBox = maPageNameAreaBoundingBox;
break;
}
// Adapt coordinates to the requested coordinate system.
@@ -77,6 +77,7 @@ void PageObjectPainter::PaintPageObject (
PaintBackground(pPageObjectLayouter, rDevice, rpDescriptor);
PaintPreview(pPageObjectLayouter, rDevice, rpDescriptor);
PaintPageNumber(pPageObjectLayouter, rDevice, rpDescriptor);
PaintPageName(pPageObjectLayouter, rDevice, rpDescriptor);
PaintTransitionEffect(pPageObjectLayouter, rDevice, rpDescriptor);
if (rpDescriptor->GetPage()->hasAnimationNode())
PaintCustomAnimationEffect(pPageObjectLayouter, rDevice, rpDescriptor);
@@ -210,6 +211,39 @@ Bitmap PageObjectPainter::GetPreviewBitmap (
}
}
Color PageObjectPainter::GetPageTextColor(const model::SharedPageDescriptor& rpDescriptor) const
{
Color aColor(mpTheme->GetColor(Theme::Color_PageNumberDefault));
if (rpDescriptor->HasState(model::PageDescriptor::ST_MouseOver)
|| rpDescriptor->HasState(model::PageDescriptor::ST_Selected))
{
aColor = mpTheme->GetColor(Theme::Color_PageNumberHover);
}
else
{
const Color aBackgroundColor(mpTheme->GetColor(Theme::Color_Background));
const sal_Int32 nBackgroundLuminance(aBackgroundColor.GetLuminance());
// When the background color is black then this is interpreted as
// high contrast mode and the font color is set to white.
if (nBackgroundLuminance == 0)
aColor = mpTheme->GetColor(Theme::Color_PageNumberHighContrast);
else
{
// When the font and background luminance are too similar, switch to
// a darker (preferred) or brighter color for legibility.
const sal_Int32 nFontLuminance(aColor.GetLuminance());
if (abs(nBackgroundLuminance - nFontLuminance) < 60)
{
if (nBackgroundLuminance > nFontLuminance - 30)
aColor = mpTheme->GetColor(Theme::Color_PageNumberBrightBackground);
else
aColor = mpTheme->GetColor(Theme::Color_PageNumberDarkBackground);
}
}
}
return aColor;
}
void PageObjectPainter::PaintPageNumber (
PageObjectLayouter *pPageObjectLayouter,
OutputDevice& rDevice,
@@ -220,49 +254,34 @@ void PageObjectPainter::PaintPageNumber (
PageObjectLayouter::Part::PageNumber,
PageObjectLayouter::ModelCoordinateSystem));
// Determine the color of the page number.
Color aPageNumberColor (mpTheme->GetColor(Theme::Color_PageNumberDefault));
if (rpDescriptor->HasState(model::PageDescriptor::ST_MouseOver) ||
rpDescriptor->HasState(model::PageDescriptor::ST_Selected))
{
// Page number is painted on background for hover or selection or
// both. Each of these background colors has a predefined luminance
// which is compatible with the PageNumberHover color.
aPageNumberColor = mpTheme->GetColor(Theme::Color_PageNumberHover);
}
else
{
const Color aBackgroundColor (mpTheme->GetColor(Theme::Color_Background));
const sal_Int32 nBackgroundLuminance (aBackgroundColor.GetLuminance());
// When the background color is black then this is interpreted as
// high contrast mode and the font color is set to white.
if (nBackgroundLuminance == 0)
aPageNumberColor = mpTheme->GetColor(Theme::Color_PageNumberHighContrast);
else
{
// Compare luminance of default page number color and background
// color. When the two are similar then use a darker
// (preferred) or brighter font color.
const sal_Int32 nFontLuminance (aPageNumberColor.GetLuminance());
if (abs(nBackgroundLuminance - nFontLuminance) < 60)
{
if (nBackgroundLuminance > nFontLuminance-30)
aPageNumberColor = mpTheme->GetColor(Theme::Color_PageNumberBrightBackground);
else
aPageNumberColor = mpTheme->GetColor(Theme::Color_PageNumberDarkBackground);
}
}
}
// Paint the page number.
OSL_ASSERT(rpDescriptor->GetPage()!=nullptr);
const sal_Int32 nPageNumber ((rpDescriptor->GetPage()->GetPageNum() - 1) / 2 + 1);
const OUString sPageNumber(OUString::number(nPageNumber));
rDevice.SetFont(*mpPageNumberFont);
rDevice.SetTextColor(aPageNumberColor);
rDevice.SetTextColor(GetPageTextColor(rpDescriptor));
rDevice.DrawText(aBox, sPageNumber, DrawTextFlags::Right | DrawTextFlags::VCenter);
}
void PageObjectPainter::PaintPageName (
PageObjectLayouter *pPageObjectLayouter,
OutputDevice& rDevice,
const model::SharedPageDescriptor& rpDescriptor) const
{
const SdPage* pPage = rpDescriptor->GetPage();
if (!pPage || pPage->GetRealName().isEmpty())
return;
const ::tools::Rectangle aBox(
pPageObjectLayouter->GetBoundingBox(rpDescriptor, PageObjectLayouter::Part::PageName,
PageObjectLayouter::ModelCoordinateSystem));
rDevice.SetFont(*mpPageNumberFont);
rDevice.SetTextColor(GetPageTextColor(rpDescriptor));
rDevice.DrawText(aBox, pPage->GetRealName(),
DrawTextFlags::Left | DrawTextFlags::VCenter | DrawTextFlags::Clip
| DrawTextFlags::EndEllipsis);
}
void PageObjectPainter::PaintTransitionEffect (
PageObjectLayouter *pPageObjectLayouter,
OutputDevice& rDevice,