slide-sorter: re-factor to improve bbox calcuation

Always use a SlsPageDescriptor to calculate bbox, so we can
adapt it to merge slides attributes where possible.

Change-Id: Id71945bbbb9adb069654ab712e22ea79fea96c1f
This commit is contained in:
Michael Meeks 2013-04-12 16:31:48 +01:00 committed by Markus Mohrhard
parent 9af5c13851
commit 0036ced049
7 changed files with 95 additions and 140 deletions

View File

@ -98,18 +98,29 @@ public:
@param eCoodinateSystem @param eCoodinateSystem
The bounding box can be returned in model and in pixel The bounding box can be returned in model and in pixel
(window) coordinates. (window) coordinates.
@param bIgnoreLocation
Return a position ignoring the slides' location, ie. as if
we were the first slide.
*/ */
Rectangle GetBoundingBox ( Rectangle GetBoundingBox (
const model::SharedPageDescriptor& rpPageDescriptor, const model::SharedPageDescriptor& rpPageDescriptor,
const Part ePart, const Part ePart,
const CoordinateSystem eCoordinateSystem); const CoordinateSystem eCoordinateSystem,
bool bIgnoreLocation = false);
/// the size of the embedded preview: position independent
Size GetPreviewSize(const CoordinateSystem eCoordinateSystem);
/// the maximum size of each tile, also position independent
Size GetGridMaxSize(const CoordinateSystem eCoordinateSystem);
Image GetTransitionEffectIcon (void) const;
private:
Rectangle GetBoundingBox ( Rectangle GetBoundingBox (
const Point& rPageObjectLocation, const Point& rPageObjectLocation,
const Part ePart, const Part ePart,
const CoordinateSystem eCoordinateSystem); const CoordinateSystem eCoordinateSystem);
Size GetSize (
const Part ePart,
const CoordinateSystem eCoordinateSystem);
Image GetTransitionEffectIcon (void) const { return maTransitionEffectIcon;} Image GetTransitionEffectIcon (void) const { return maTransitionEffectIcon;}
Image GetCustomAnimationEffectIcon (void) const { return maCustomAnimationEffectIcon;} Image GetCustomAnimationEffectIcon (void) const { return maCustomAnimationEffectIcon;}

View File

@ -108,8 +108,12 @@ private:
OutputDevice& rDevice, OutputDevice& rDevice,
const Theme::GradientColorType eColorType, const Theme::GradientColorType eColorType,
const Rectangle& rBox) const; const Rectangle& rBox) const;
void PaintBackgroundDetail(
OutputDevice& rDevice,
const model::SharedPageDescriptor& rpDescriptor);
#if 0
Bitmap& GetBackgroundForState ( Bitmap& GetBackgroundForState (
const model::SharedPageDescriptor& rpDescriptor,
const OutputDevice& rTemplateDevice); const OutputDevice& rTemplateDevice);
Bitmap& GetBackground( Bitmap& GetBackground(
Bitmap& rBackground, Bitmap& rBackground,
@ -120,6 +124,7 @@ private:
const OutputDevice& rReferenceDevice, const OutputDevice& rReferenceDevice,
const Theme::GradientColorType eType, const Theme::GradientColorType eType,
const bool bHasFocusBorder) const; const bool bHasFocusBorder) const;
#endif
Bitmap CreateMarkedPreview( Bitmap CreateMarkedPreview(
const Size& rSize, const Size& rSize,
const Bitmap& rPreview, const Bitmap& rPreview,

View File

@ -477,9 +477,7 @@ void SlideSorterView::Layout ()
mpLayouter->GetPageObjectLayouter()); mpLayouter->GetPageObjectLayouter());
if (pPageObjectLayouter) if (pPageObjectLayouter)
{ {
const Size aNewPreviewSize (mpLayouter->GetPageObjectLayouter()->GetSize( const Size aNewPreviewSize (mpLayouter->GetPageObjectLayouter()->GetPreviewSize(PageObjectLayouter::WindowCoordinateSystem));
PageObjectLayouter::Preview,
PageObjectLayouter::WindowCoordinateSystem));
if (maPreviewSize != aNewPreviewSize && GetPreviewCache()) if (maPreviewSize != aNewPreviewSize && GetPreviewCache())
{ {
mpPreviewCache->ChangeSize(aNewPreviewSize, false); mpPreviewCache->ChangeSize(aNewPreviewSize, false);

View File

@ -129,8 +129,7 @@ void InsertionIndicatorOverlay::Create (
::boost::shared_ptr<view::PageObjectLayouter> pPageObjectLayouter ( ::boost::shared_ptr<view::PageObjectLayouter> pPageObjectLayouter (
rLayouter.GetPageObjectLayouter()); rLayouter.GetPageObjectLayouter());
::boost::shared_ptr<view::Theme> pTheme (mrSlideSorter.GetTheme()); ::boost::shared_ptr<view::Theme> pTheme (mrSlideSorter.GetTheme());
const Size aOriginalPreviewSize (pPageObjectLayouter->GetSize( const Size aOriginalPreviewSize (pPageObjectLayouter->GetPreviewSize(
PageObjectLayouter::Preview,
PageObjectLayouter::WindowCoordinateSystem)); PageObjectLayouter::WindowCoordinateSystem));
const double nPreviewScale (0.5); const double nPreviewScale (0.5);

View File

@ -592,8 +592,8 @@ bool Layouter::Implementation::Rearrange (
rPreviewModelSize, rPreviewModelSize,
mpWindow, mpWindow,
mnPageCount)); mnPageCount));
maPageObjectSize = mpPageObjectLayouter->GetSize(
PageObjectLayouter::FocusIndicator, maPageObjectSize = mpPageObjectLayouter->GetGridMaxSize(
PageObjectLayouter::WindowCoordinateSystem); PageObjectLayouter::WindowCoordinateSystem);
CalculateMaxRowAndColumnCount(rWindowSize); CalculateMaxRowAndColumnCount(rWindowSize);
@ -871,17 +871,14 @@ Rectangle Layouter::Implementation::GetInnerBoundingBox (
if ( ! pDescriptor) if ( ! pDescriptor)
return Rectangle(); return Rectangle();
const Point aLocation (pDescriptor->GetLocation(true)); PageObjectLayouter::Part ePart = PageObjectLayouter::Preview;
if (pDescriptor->HasState(model::PageDescriptor::ST_Selected)) if (pDescriptor->HasState(model::PageDescriptor::ST_Selected))
ePart = PageObjectLayouter::PageObject;
return mpPageObjectLayouter->GetBoundingBox( return mpPageObjectLayouter->GetBoundingBox(
aLocation, pDescriptor, ePart,
PageObjectLayouter::PageObject, PageObjectLayouter::ModelCoordinateSystem, true);
PageObjectLayouter::ModelCoordinateSystem);
else
return mpPageObjectLayouter->GetBoundingBox(
aLocation,
PageObjectLayouter::Preview,
PageObjectLayouter::ModelCoordinateSystem);
} }

View File

@ -165,22 +165,19 @@ Rectangle PageObjectLayouter::CalculatePreviewBoundingBox (
nTop + nPreviewHeight); nTop + nPreviewHeight);
} }
Rectangle PageObjectLayouter::GetBoundingBox ( Rectangle PageObjectLayouter::GetBoundingBox (
const model::SharedPageDescriptor& rpPageDescriptor, const model::SharedPageDescriptor& rpPageDescriptor,
const Part ePart, const Part ePart,
const CoordinateSystem eCoordinateSystem) const CoordinateSystem eCoordinateSystem,
bool bIgnoreLocation)
{ {
OSL_ASSERT(rpPageDescriptor); OSL_ASSERT(rpPageDescriptor);
Point aLocation (rpPageDescriptor ? rpPageDescriptor->GetLocation() : Point(0,0)); Point aLocation(0,0);
if (rpPageDescriptor)
aLocation = rpPageDescriptor->GetLocation( bIgnoreLocation );
return GetBoundingBox(aLocation, ePart, eCoordinateSystem); return GetBoundingBox(aLocation, ePart, eCoordinateSystem);
} }
Rectangle PageObjectLayouter::GetBoundingBox ( Rectangle PageObjectLayouter::GetBoundingBox (
const Point& rPageObjectLocation, const Point& rPageObjectLocation,
const Part ePart, const Part ePart,
@ -228,18 +225,18 @@ Rectangle PageObjectLayouter::GetBoundingBox (
aBoundingBox.BottomRight() + aLocation); aBoundingBox.BottomRight() + aLocation);
} }
Size PageObjectLayouter::GetPreviewSize (
Size PageObjectLayouter::GetSize (
const Part ePart,
const CoordinateSystem eCoordinateSystem) const CoordinateSystem eCoordinateSystem)
{ {
return GetBoundingBox(Point(0,0), ePart, eCoordinateSystem).GetSize(); return GetBoundingBox(Point(0,0), PageObjectLayouter::Preview,
eCoordinateSystem).GetSize();
} }
Size PageObjectLayouter::GetGridMaxSize(const CoordinateSystem eCoordinateSystem)
{
return GetBoundingBox(Point(0,0), PageObjectLayouter::FocusIndicator,
eCoordinateSystem).GetSize();
}
Size PageObjectLayouter::GetPageNumberAreaSize (const int nPageCount) Size PageObjectLayouter::GetPageNumberAreaSize (const int nPageCount)
{ {

View File

@ -121,8 +121,7 @@ void PageObjectPainter::NotifyResize (const bool bForce)
InvalidateBitmaps(); InvalidateBitmaps();
else if (UpdatePageObjectLayouter()) else if (UpdatePageObjectLayouter())
{ {
const Size aSize (mpPageObjectLayouter->GetSize( const Size aSize (mpPageObjectLayouter->GetGridMaxSize(
PageObjectLayouter::FocusIndicator,
PageObjectLayouter::WindowCoordinateSystem)); PageObjectLayouter::WindowCoordinateSystem));
if (maSize != aSize) if (maSize != aSize)
{ {
@ -147,29 +146,17 @@ void PageObjectPainter::InvalidateBitmaps (void)
maMouseOverSelectedAndFocusedBackground.SetEmpty(); maMouseOverSelectedAndFocusedBackground.SetEmpty();
} }
void PageObjectPainter::SetTheme (const ::boost::shared_ptr<view::Theme>& rpTheme) void PageObjectPainter::SetTheme (const ::boost::shared_ptr<view::Theme>& rpTheme)
{ {
mpTheme = rpTheme; mpTheme = rpTheme;
NotifyResize(true); NotifyResize(true);
} }
void PageObjectPainter::PaintBackground ( void PageObjectPainter::PaintBackground (
OutputDevice& rDevice, OutputDevice& rDevice,
const model::SharedPageDescriptor& rpDescriptor) const model::SharedPageDescriptor& rpDescriptor)
{ {
const Rectangle aBox (mpPageObjectLayouter->GetBoundingBox( PaintBackgroundDetail(rDevice, rpDescriptor);
rpDescriptor,
PageObjectLayouter::FocusIndicator,
PageObjectLayouter::ModelCoordinateSystem));
const Bitmap& rBackground (GetBackgroundForState(rpDescriptor, rDevice));
rDevice.DrawBitmap(aBox.TopLeft(), rBackground);
// Fill the interior of the preview area with the default background // Fill the interior of the preview area with the default background
// color of the page. // color of the page.
@ -384,14 +371,15 @@ Bitmap& PageObjectPainter::GetBackgroundForState (
| (rpDescriptor->HasState(model::PageDescriptor::ST_MouseOver) ? MouseOver : None) | (rpDescriptor->HasState(model::PageDescriptor::ST_MouseOver) ? MouseOver : None)
| (rpDescriptor->HasState(model::PageDescriptor::ST_Focused) ? Focused : None); | (rpDescriptor->HasState(model::PageDescriptor::ST_Focused) ? Focused : None);
bool bHasFocusBorder;
Theme::GradientColorType eColorType;
switch (eState) switch (eState)
{ {
case MouseOver | Selected | Focused: case MouseOver | Selected | Focused:
return GetBackground( eColorType = Theme::Gradient_MouseOverSelectedAndFocusedPage;
maMouseOverSelectedAndFocusedBackground, bHasFocusBorder = true;
Theme::Gradient_MouseOverSelectedAndFocusedPage, break;
rReferenceDevice,
true);
case MouseOver | Selected: case MouseOver | Selected:
return GetBackground( return GetBackground(
@ -401,87 +389,52 @@ Bitmap& PageObjectPainter::GetBackgroundForState (
false); false);
case MouseOver: case MouseOver:
return GetBackground( eColorType = Theme::Gradient_MouseOverPage;
maMouseOverBackground, bHasFocusBorder = false;
Theme::Gradient_MouseOverPage, break;
rReferenceDevice,
false);
case MouseOver | Focused: case MouseOver | Focused:
return GetBackground( eColorType = Theme::Gradient_MouseOverPage;
maMouseOverFocusedBackground, bHasFocusBorder = true;
Theme::Gradient_MouseOverPage, break;
rReferenceDevice,
true);
case Selected | Focused: case Selected | Focused:
return GetBackground( eColorType = Theme::Gradient_SelectedAndFocusedPage;
maFocusedSelectionBackground, bHasFocusBorder = true;
Theme::Gradient_SelectedAndFocusedPage, break;
rReferenceDevice,
true);
case Selected: case Selected:
return GetBackground( eColorType = Theme::Gradient_SelectedPage;
maSelectionBackground, bHasFocusBorder = false;
Theme::Gradient_SelectedPage, break;
rReferenceDevice,
false);
case Focused: case Focused:
return GetBackground( eColorType = Theme::Gradient_FocusedPage;
maFocusedBackground, bHasFocusBorder = true;
Theme::Gradient_FocusedPage, break;
rReferenceDevice,
true);
case None: case None:
default: default:
return GetBackground( eColorType = Theme::Gradient_NormalPage;
maNormalBackground, bHasFocusBorder = false;
Theme::Gradient_NormalPage, break;
rReferenceDevice,
false);
}
} }
const Rectangle aFocusSize (mpPageObjectLayouter->GetBoundingBox(
rpDescriptor,
Bitmap& PageObjectPainter::GetBackground(
Bitmap& rBackground,
Theme::GradientColorType eType,
const OutputDevice& rReferenceDevice,
const bool bHasFocusBorder)
{
if (rBackground.IsEmpty())
rBackground = CreateBackgroundBitmap(rReferenceDevice, eType, bHasFocusBorder);
return rBackground;
}
Bitmap PageObjectPainter::CreateBackgroundBitmap(
const OutputDevice& rReferenceDevice,
const Theme::GradientColorType eColorType,
const bool bHasFocusBorder) const
{
const Size aSize (mpPageObjectLayouter->GetSize(
PageObjectLayouter::FocusIndicator, PageObjectLayouter::FocusIndicator,
PageObjectLayouter::WindowCoordinateSystem)); PageObjectLayouter::ModelCoordinateSystem));
const Rectangle aPageObjectBox (mpPageObjectLayouter->GetBoundingBox( const Rectangle aPageObjectBox (mpPageObjectLayouter->GetBoundingBox(
Point(0,0), rpDescriptor,
PageObjectLayouter::PageObject, PageObjectLayouter::PageObject,
PageObjectLayouter::ModelCoordinateSystem)); PageObjectLayouter::ModelCoordinateSystem));
VirtualDevice aBitmapDevice (rReferenceDevice);
aBitmapDevice.SetOutputSizePixel(aSize);
// Fill the background with the background color of the slide sorter. // Fill the background with the background color of the slide sorter.
const Color aBackgroundColor (mpTheme->GetColor(Theme::Color_Background)); const Color aBackgroundColor (mpTheme->GetColor(Theme::Color_Background));
aBitmapDevice.SetFillColor(aBackgroundColor); rDevice.SetFillColor(aBackgroundColor);
aBitmapDevice.SetLineColor(aBackgroundColor); rDevice.SetLineColor(aBackgroundColor);
aBitmapDevice.DrawRect(Rectangle(Point(0,0), aSize)); rDevice.DrawRect(aFocusSize);
// Paint the slide area with a linear gradient that starts some pixels // Paint the slide area with a linear gradient that starts some pixels
// below the top and ends some pixels above the bottom. // below the top and ends some pixels above the bottom.
@ -503,47 +456,42 @@ Bitmap PageObjectPainter::CreateBackgroundBitmap(
for (sal_Int32 nY=0; nY<nHeight; ++nY) for (sal_Int32 nY=0; nY<nHeight; ++nY)
{ {
if (nY<=nY1) if (nY<=nY1)
aBitmapDevice.SetLineColor(aTopColor); rDevice.SetLineColor(aTopColor);
else if (nY>=nY2) else if (nY>=nY2)
aBitmapDevice.SetLineColor(aBottomColor); rDevice.SetLineColor(aBottomColor);
else else
{ {
Color aColor (aTopColor); Color aColor (aTopColor);
aColor.Merge(aBottomColor, 255 * (nY2-nY) / (nY2-nY1)); aColor.Merge(aBottomColor, 255 * (nY2-nY) / (nY2-nY1));
aBitmapDevice.SetLineColor(aColor); rDevice.SetLineColor(aColor);
} }
aBitmapDevice.DrawLine( rDevice.DrawLine(
Point(aPageObjectBox.Left(), nY+nTop), Point(aPageObjectBox.Left(), nY+nTop),
Point(aPageObjectBox.Right(), nY+nTop)); Point(aPageObjectBox.Right(), nY+nTop));
} }
} }
else else
{ {
aBitmapDevice.SetFillColor(aTopColor); rDevice.SetFillColor(aTopColor);
aBitmapDevice.DrawRect(aPageObjectBox); rDevice.DrawRect(aPageObjectBox);
} }
// Paint the simple border and, for some backgrounds, the focus border. // Paint the simple border and, for some backgrounds, the focus border.
if (bHasFocusBorder) if (bHasFocusBorder)
mpFocusBorderPainter->PaintFrame(aBitmapDevice, aPageObjectBox); mpFocusBorderPainter->PaintFrame(rDevice, aPageObjectBox);
else else
PaintBorder(aBitmapDevice, eColorType, aPageObjectBox); PaintBorder(rDevice, eColorType, aPageObjectBox);
// Get bounding box of the preview around which a shadow is painted. // Get bounding box of the preview around which a shadow is painted.
// Compensate for the border around the preview. // Compensate for the border around the preview.
const Rectangle aBox (mpPageObjectLayouter->GetBoundingBox( const Rectangle aBox (mpPageObjectLayouter->GetBoundingBox(
Point(0,0), rpDescriptor,
PageObjectLayouter::Preview, PageObjectLayouter::Preview,
PageObjectLayouter::ModelCoordinateSystem)); PageObjectLayouter::ModelCoordinateSystem));
Rectangle aFrameBox (aBox.Left()-1,aBox.Top()-1,aBox.Right()+1,aBox.Bottom()+1); Rectangle aFrameBox (aBox.Left()-1,aBox.Top()-1,aBox.Right()+1,aBox.Bottom()+1);
mpShadowPainter->PaintFrame(aBitmapDevice, aFrameBox); mpShadowPainter->PaintFrame(rDevice, aFrameBox);
return aBitmapDevice.GetBitmap (Point(0,0),aSize);
} }
void PageObjectPainter::PaintBorder ( void PageObjectPainter::PaintBorder (
OutputDevice& rDevice, OutputDevice& rDevice,
const Theme::GradientColorType eColorType, const Theme::GradientColorType eColorType,