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/fillgraphicattribute.hxx>
16 #include <drawinglayer/primitive2d/fillgraphicprimitive2d.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>
24 #include <vcl/graph.hxx>
26 using namespace basegfx
;
27 using namespace basegfx::tools
;
28 using namespace drawinglayer::attribute
;
29 using namespace drawinglayer::primitive2d
;
31 TemplateContainerItem::TemplateContainerItem (ThumbnailView
&rView
, sal_uInt16 nId
)
32 : ThumbnailViewItem(rView
, nId
)
37 TemplateContainerItem::~TemplateContainerItem ()
41 void TemplateContainerItem::calculateItemsPosition (const long nThumbnailHeight
, const long nDisplayHeight
,
42 const long nPadding
, sal_uInt32 nMaxTextLength
,
43 const ThumbnailItemAttributes
*pAttrs
)
45 ThumbnailViewItem::calculateItemsPosition( nThumbnailHeight
, nDisplayHeight
, nPadding
, nMaxTextLength
, pAttrs
);
46 Point
aPos (maDrawArea
.getX() + nPadding
, maDrawArea
.getY() + nPadding
);
47 maThumbnailArea
= Rectangle(aPos
, Size(maDrawArea
.GetWidth() - 2 * nPadding
, nThumbnailHeight
));
50 void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D
*pProcessor
,
51 const ThumbnailItemAttributes
*pAttrs
)
56 if (!maPreview1
.IsEmpty())
59 if (!maPreview2
.IsEmpty())
62 if (!maPreview3
.IsEmpty())
65 if (!maPreview4
.IsEmpty())
68 BColor aFillColor
= pAttrs
->aFillColor
;
69 drawinglayer::primitive2d::Primitive2DSequence
aSeq(nSeqSize
);
70 double fTransparence
= 0.0;
73 if ( mbSelected
|| mbHover
)
74 aFillColor
= pAttrs
->aHighlightColor
;
77 fTransparence
= pAttrs
->fHighlightTransparence
;
79 aSeq
[nCount
++] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonSelectionPrimitive2D(
80 B2DPolyPolygon(Polygon(maDrawArea
,5,5).getB2DPolygon()),
86 // Create rounded rectangle border
87 aSeq
[nCount
++] = drawinglayer::primitive2d::Primitive2DReference(new PolygonStrokePrimitive2D(
88 Polygon(maThumbnailArea
, 5, 5).getB2DPolygon(),
89 LineAttribute(BColor(0.5, 0.5, 0.5), 2.0)));
91 // Paint the thumbnails side by side on a 2x2 grid
92 long nThumbPadding
= 4;
93 Size
aThumbSize( ( maThumbnailArea
.getWidth() - 3 * nThumbPadding
) / 2, ( maThumbnailArea
.getHeight() - 3* nThumbPadding
) / 2 );
96 for (int i
=0; i
<4; ++i
)
100 BitmapEx
* pImage
= NULL
;
105 pImage
= &maPreview1
;
108 pImage
= &maPreview2
;
109 nPosX
= aThumbSize
.getWidth() + nThumbPadding
;
112 pImage
= &maPreview3
;
113 nPosY
= aThumbSize
.getHeight() + nThumbPadding
;
116 pImage
= &maPreview4
;
117 nPosX
= aThumbSize
.getWidth() + nThumbPadding
;
118 nPosY
= aThumbSize
.getHeight() + nThumbPadding
;
122 if (!pImage
->IsEmpty())
124 // Check the size of the picture and resize if needed
125 Size aImageSize
= pImage
->GetSizePixel();
126 if (aImageSize
.getWidth() > aThumbSize
.getWidth() || aImageSize
.getHeight() > aThumbSize
.getHeight())
128 // Resize the picture and store it for next times
129 *pImage
= TemplateAbstractView::scaleImg( *pImage
, aThumbSize
.getWidth(), aThumbSize
.getHeight() );
130 aImageSize
= pImage
->GetSizePixel();
133 float nOffX
= (aThumbSize
.getWidth() - aImageSize
.getWidth()) / 2.0;
134 float nOffY
= (aThumbSize
.getHeight() - aImageSize
.getHeight()) / 2.0;
136 float fWidth
= aImageSize
.Width();
137 float fHeight
= aImageSize
.Height();
138 float fPosX
= maThumbnailArea
.Left() + nThumbPadding
+ nPosX
+ nOffX
;
139 float fPosY
= maThumbnailArea
.Top() + nThumbPadding
+ nPosY
+ nOffY
;
142 aBounds
.append(B2DPoint(fPosX
,fPosY
));
143 aBounds
.append(B2DPoint(fPosX
+fWidth
,fPosY
));
144 aBounds
.append(B2DPoint(fPosX
+fWidth
,fPosY
+fHeight
));
145 aBounds
.append(B2DPoint(fPosX
,fPosY
+fHeight
));
146 aBounds
.setClosed(true);
148 aSeq
[nCount
++] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonColorPrimitive2D(
149 B2DPolyPolygon(aBounds
), Color(COL_WHITE
).getBColor()));
150 aSeq
[nCount
++] = drawinglayer::primitive2d::Primitive2DReference( new FillGraphicPrimitive2D(
151 createScaleTranslateB2DHomMatrix(1.0,1.0,fPosX
,fPosY
),
152 FillGraphicAttribute(Graphic(*pImage
),
155 B2DPoint(aImageSize
.Width(),aImageSize
.Height())),
159 // draw thumbnail borders
160 aSeq
[nCount
++] = drawinglayer::primitive2d::Primitive2DReference(createBorderLine(aBounds
));
164 addTextPrimitives(maTitle
, pAttrs
, maTextPos
, aSeq
);
166 pProcessor
->process(aSeq
);
169 bool TemplateContainerItem::HasMissingPreview( )
171 return maPreview1
.IsEmpty() || maPreview2
.IsEmpty() || maPreview3
.IsEmpty() || maPreview4
.IsEmpty();
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */