1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sfx2/templatecontaineritem.hxx>
11 #include <sfx2/templateabstractview.hxx>
13 #include <basegfx/matrix/b2dhommatrixtools.hxx>
14 #include <basegfx/polygon/b2dpolygon.hxx>
15 #include <drawinglayer/attribute/fillbitmapattribute.hxx>
16 #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
17 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
18 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
19 #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
20 #include <drawinglayer/primitive2d/textprimitive2d.hxx>
21 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
22 #include <sfx2/templateviewitem.hxx>
23 #include <vcl/button.hxx>
25 using namespace basegfx
;
26 using namespace basegfx::tools
;
27 using namespace drawinglayer::attribute
;
28 using namespace drawinglayer::primitive2d
;
30 TemplateContainerItem::TemplateContainerItem (ThumbnailView
&rView
)
31 : ThumbnailViewItem(rView
)
35 TemplateContainerItem::~TemplateContainerItem ()
39 void TemplateContainerItem::calculateItemsPosition (const long nThumbnailHeight
, const long nDisplayHeight
,
40 const long nPadding
, sal_uInt32 nMaxTextLenght
,
41 const ThumbnailItemAttributes
*pAttrs
)
43 ThumbnailViewItem::calculateItemsPosition( nThumbnailHeight
, nDisplayHeight
, nPadding
, nMaxTextLenght
, pAttrs
);
44 Point
aPos (maDrawArea
.getX() + nPadding
, maDrawArea
.getY() + nPadding
);
45 maThumbnailArea
= Rectangle(aPos
, Size(maDrawArea
.GetWidth() - 2 * nPadding
, nThumbnailHeight
));
48 void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D
*pProcessor
,
49 const ThumbnailItemAttributes
*pAttrs
)
54 if (!maPreview1
.IsEmpty())
57 if (!maPreview2
.IsEmpty())
60 if (!maPreview3
.IsEmpty())
63 if (!maPreview4
.IsEmpty())
66 BColor aFillColor
= pAttrs
->aFillColor
;
67 Primitive2DSequence
aSeq(nSeqSize
);
70 if ( mbSelected
|| mbHover
)
71 aFillColor
= pAttrs
->aHighlightColor
;
73 aSeq
[nCount
++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
74 B2DPolyPolygon(Polygon(maDrawArea
,5,5).getB2DPolygon()),
77 // Create rounded rectangle border
78 aSeq
[nCount
++] = Primitive2DReference( new PolygonStrokePrimitive2D(
79 Polygon(maThumbnailArea
,5,5).getB2DPolygon(),
80 LineAttribute(BColor(0.8, 0.8, 0.8), 2.0)));
82 // Paint the thumbnails side by side on a 2x2 grid
83 long nThumbPadding
= 4;
84 Size
aThumbSize( ( maThumbnailArea
.getWidth() - 3 * nThumbPadding
) / 2, ( maThumbnailArea
.getHeight() - 3* nThumbPadding
) / 2 );
87 for (int i
=0; i
<4; ++i
)
91 BitmapEx
* pImage
= NULL
;
100 nPosX
= aThumbSize
.getWidth() + nThumbPadding
;
103 pImage
= &maPreview3
;
104 nPosY
= aThumbSize
.getHeight() + nThumbPadding
;
107 pImage
= &maPreview4
;
108 nPosX
= aThumbSize
.getWidth() + nThumbPadding
;
109 nPosY
= aThumbSize
.getHeight() + nThumbPadding
;
113 if (!pImage
->IsEmpty())
115 // Check the size of the picture and resize if needed
116 Size aImageSize
= pImage
->GetSizePixel();
117 if (aImageSize
.getWidth() > aThumbSize
.getWidth() || aImageSize
.getHeight() > aThumbSize
.getHeight())
119 // Resize the picture and store it for next times
120 *pImage
= TemplateAbstractView::scaleImg( *pImage
, aThumbSize
.getWidth(), aThumbSize
.getHeight() );
121 aImageSize
= pImage
->GetSizePixel();
124 float nOffX
= (aThumbSize
.getWidth() - aImageSize
.getWidth()) / 2;
125 float nOffY
= (aThumbSize
.getHeight() - aImageSize
.getHeight()) / 2;
127 float fWidth
= aImageSize
.Width();
128 float fHeight
= aImageSize
.Height();
129 float fPosX
= maThumbnailArea
.Left() + nThumbPadding
+ nPosX
+ nOffX
;
130 float fPosY
= maThumbnailArea
.Top() + nThumbPadding
+ nPosY
+ nOffY
;
133 aBounds
.append(B2DPoint(fPosX
,fPosY
));
134 aBounds
.append(B2DPoint(fPosX
+fWidth
,fPosY
));
135 aBounds
.append(B2DPoint(fPosX
+fWidth
,fPosY
+fHeight
));
136 aBounds
.append(B2DPoint(fPosX
,fPosY
+fHeight
));
137 aBounds
.setClosed(true);
139 aSeq
[nCount
++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
140 B2DPolyPolygon(aBounds
), Color(COL_WHITE
).getBColor()));
141 aSeq
[nCount
++] = Primitive2DReference( new FillBitmapPrimitive2D(
142 createScaleTranslateB2DHomMatrix(1.0,1.0,fPosX
,fPosY
),
143 FillBitmapAttribute(*pImage
,
145 B2DVector(aImageSize
.Width(),aImageSize
.Height()),
149 // draw thumbnail borders
150 aSeq
[nCount
++] = Primitive2DReference(createBorderLine(aBounds
));
154 addTextPrimitives(maTitle
, pAttrs
, maTextPos
, aSeq
);
156 pProcessor
->process(aSeq
);
159 bool TemplateContainerItem::HasMissingPreview( )
161 return maPreview1
.IsEmpty() || maPreview2
.IsEmpty() || maPreview3
.IsEmpty() || maPreview4
.IsEmpty();
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */