summaryrefslogtreecommitdiff
path: root/sfx2/source/control/templatecontaineritem.cxx
diff options
context:
space:
mode:
authorCédric Bosdonnat <cedric.bosdonnat@free.fr>2013-01-14 16:50:03 +0100
committerCédric Bosdonnat <cedric.bosdonnat@free.fr>2013-01-16 14:17:42 +0100
commit34856077702907aed5568ff3d4b98888ced37edf (patch)
tree6fc55a02d5c448bf64c06217c40a27f540ab1957 /sfx2/source/control/templatecontaineritem.cxx
parentc56651e76c2dc8068d53406dcdd6cb6bd1bd9bce (diff)
Template Manager: show folders with 4 previews inside a rounded rect
The previous display had the inconvenient to be misleading if there was one or no template inside a folder. Change-Id: I16faa2556ca02380bd4dac0d821ecac45b98b8c3 Reviewed-on: https://gerrit.libreoffice.org/1678 Reviewed-by: Noel Power <noel.power@suse.com> Tested-by: Noel Power <noel.power@suse.com>
Diffstat (limited to 'sfx2/source/control/templatecontaineritem.cxx')
-rw-r--r--sfx2/source/control/templatecontaineritem.cxx156
1 files changed, 95 insertions, 61 deletions
diff --git a/sfx2/source/control/templatecontaineritem.cxx b/sfx2/source/control/templatecontaineritem.cxx
index d63ce8a8150b..25fa5fe89920 100644
--- a/sfx2/source/control/templatecontaineritem.cxx
+++ b/sfx2/source/control/templatecontaineritem.cxx
@@ -8,6 +8,7 @@
*/
#include <sfx2/templatecontaineritem.hxx>
+#include <sfx2/templateabstractview.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
@@ -35,11 +36,20 @@ TemplateContainerItem::~TemplateContainerItem ()
{
}
+void TemplateContainerItem::calculateItemsPosition (const long nThumbnailHeight, const long nDisplayHeight,
+ const long nPadding, sal_uInt32 nMaxTextLenght,
+ const ThumbnailItemAttributes *pAttrs)
+{
+ ThumbnailViewItem::calculateItemsPosition( nThumbnailHeight, nDisplayHeight, nPadding, nMaxTextLenght, pAttrs);
+ Point aPos (maDrawArea.getX() + nPadding, maDrawArea.getY() + nPadding);
+ maThumbnailArea = Rectangle(aPos, Size(maDrawArea.GetWidth() - 2 * nPadding, nThumbnailHeight));
+}
+
void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
const ThumbnailItemAttributes *pAttrs)
{
int nCount = 0;
- int nSeqSize = 2;
+ int nSeqSize = 3;
if (!maPreview1.IsEmpty())
nSeqSize += 3;
@@ -47,6 +57,12 @@ void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *p
if (!maPreview2.IsEmpty())
nSeqSize += 3;
+ if (!maPreview3.IsEmpty())
+ nSeqSize += 3;
+
+ if (!maPreview4.IsEmpty())
+ nSeqSize += 3;
+
BColor aFillColor = pAttrs->aFillColor;
Primitive2DSequence aSeq(nSeqSize);
@@ -58,70 +74,83 @@ void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *p
B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
aFillColor));
- // Draw thumbnail
- Point aPos = maPrev1Pos;
- Size aImageSize = maPreview1.GetSizePixel();
+ // Create rounded rectangle border
+ aSeq[nCount++] = Primitive2DReference( new PolygonStrokePrimitive2D(
+ Polygon(maThumbnailArea,5,5).getB2DPolygon(),
+ LineAttribute(BColor(0.8, 0.8, 0.8), 2.0)));
- float fScaleX = 1.0f;
- float fScaleY = 1.0f;
+ // Paint the thumbnails side by side on a 2x2 grid
+ long nThumbPadding = 4;
+ Size aThumbSize( ( maThumbnailArea.getWidth() - 3 * nThumbPadding ) / 2, ( maThumbnailArea.getHeight() - 3* nThumbPadding ) / 2 );
- if (!maPreview2.IsEmpty())
- {
- fScaleX = 0.8f;
- fScaleY = 0.8f;
-
- float fWidth = aImageSize.Width()*fScaleX;
- float fHeight = aImageSize.Height()*fScaleY;
- float fPosX = aPos.getX()+35*fScaleX;
- float fPosY = aPos.getY()+20*fScaleY;
-
- B2DPolygon aBounds;
- aBounds.append(B2DPoint(fPosX,fPosY));
- aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
- aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
- aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
- aBounds.setClosed(true);
-
- aSeq[nCount++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
- B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
- aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D(
- createScaleTranslateB2DHomMatrix(fScaleX,fScaleY,aPos.X(),aPos.Y()),
- FillBitmapAttribute(maPreview2,
- B2DPoint(35,20),
- B2DVector(aImageSize.Width(),aImageSize.Height()),
- false)
- ));
-
- // draw thumbnail borders
- aSeq[nCount++] = Primitive2DReference(createBorderLine(aBounds));
- }
+ // Draw thumbnail
+ Point aPos = maPrev1Pos;
- if (!maPreview1.IsEmpty())
+ for (int i=0; i<4; ++i)
{
- // draw thumbnail borders
- float fWidth = aImageSize.Width()*fScaleX;
- float fHeight = aImageSize.Height()*fScaleY;
- float fPosX = aPos.getX();
- float fPosY = aPos.getY();
-
- B2DPolygon aBounds;
- aBounds.append(B2DPoint(fPosX,fPosY));
- aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
- aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
- aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
- aBounds.setClosed(true);
-
- aSeq[nCount++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
- B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
- aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D(
- createScaleTranslateB2DHomMatrix(fScaleX,fScaleY,aPos.X(),aPos.Y()),
- FillBitmapAttribute(maPreview1,
- B2DPoint(0,0),
- B2DVector(aImageSize.Width(),aImageSize.Height()),
- false)
- ));
-
- aSeq[nCount++] = Primitive2DReference(createBorderLine(aBounds));
+ long nPosX = 0;
+ long nPosY = 0;
+ BitmapEx* pImage = NULL;
+
+ switch (i)
+ {
+ case 0:
+ pImage = &maPreview1;
+ break;
+ case 1:
+ pImage = &maPreview2;
+ nPosX = aThumbSize.getWidth() + nThumbPadding;
+ break;
+ case 2:
+ pImage = &maPreview3;
+ nPosY = aThumbSize.getHeight() + nThumbPadding;
+ break;
+ case 3:
+ pImage = &maPreview4;
+ nPosX = aThumbSize.getWidth() + nThumbPadding;
+ nPosY = aThumbSize.getHeight() + nThumbPadding;
+ break;
+ }
+
+ if (!pImage->IsEmpty())
+ {
+ // Check the size of the picture and resize if needed
+ Size aImageSize = pImage->GetSizePixel();
+ if (aImageSize.getWidth() > aThumbSize.getWidth() || aImageSize.getHeight() > aThumbSize.getHeight())
+ {
+ // Resize the picture and store it for next times
+ *pImage = TemplateAbstractView::scaleImg( *pImage, aThumbSize.getWidth(), aThumbSize.getHeight() );
+ aImageSize = pImage->GetSizePixel();
+ }
+
+ float nOffX = (aThumbSize.getWidth() - aImageSize.getWidth()) / 2;
+ float nOffY = (aThumbSize.getHeight() - aImageSize.getHeight()) / 2;
+
+ float fWidth = aImageSize.Width();
+ float fHeight = aImageSize.Height();
+ float fPosX = maThumbnailArea.Left() + nThumbPadding + nPosX + nOffX;
+ float fPosY = maThumbnailArea.Top() + nThumbPadding + nPosY + nOffY;
+
+ B2DPolygon aBounds;
+ aBounds.append(B2DPoint(fPosX,fPosY));
+ aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
+ aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
+ aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
+ aBounds.setClosed(true);
+
+ aSeq[nCount++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
+ B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
+ aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D(
+ createScaleTranslateB2DHomMatrix(1.0,1.0,fPosX,fPosY),
+ FillBitmapAttribute(*pImage,
+ B2DPoint(0.0,0.0),
+ B2DVector(aImageSize.Width(),aImageSize.Height()),
+ false)
+ ));
+
+ // draw thumbnail borders
+ aSeq[nCount++] = Primitive2DReference(createBorderLine(aBounds));
+ }
}
// Draw centered text below thumbnail
@@ -143,6 +172,11 @@ void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *p
pProcessor->process(aSeq);
}
+bool TemplateContainerItem::HasMissingPreview( )
+{
+ return maPreview1.IsEmpty() || maPreview2.IsEmpty() || maPreview3.IsEmpty() || maPreview4.IsEmpty();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */