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/templateviewitem.hxx>
12 #include <basegfx/matrix/b2dhommatrixtools.hxx>
13 #include <basegfx/polygon/b2dpolygon.hxx>
14 #include <drawinglayer/attribute/fillgraphicattribute.hxx>
15 #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx>
16 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
17 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
18 #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
19 #include <drawinglayer/primitive2d/textprimitive2d.hxx>
20 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
21 #include <vcl/button.hxx>
22 #include <vcl/graph.hxx>
24 #define SUBTITLE_SCALE_FACTOR 0.85
26 using namespace basegfx
;
27 using namespace basegfx::tools
;
28 using namespace drawinglayer::attribute
;
29 using namespace drawinglayer::primitive2d
;
31 TemplateViewItem::TemplateViewItem (ThumbnailView
&rView
, sal_uInt16 nId
)
32 : ThumbnailViewItem(rView
, nId
),
33 mnRegionId(USHRT_MAX
),
38 TemplateViewItem::~TemplateViewItem ()
42 void TemplateViewItem::calculateItemsPosition(const long nThumbnailHeight
, const long nDisplayHeight
,
43 const long nPadding
, sal_uInt32 nMaxTextLength
,
44 const ThumbnailItemAttributes
*pAttrs
)
46 ThumbnailViewItem::calculateItemsPosition(nThumbnailHeight
,nDisplayHeight
,nPadding
,nMaxTextLength
, pAttrs
);
48 if (!maSubTitle
.isEmpty())
50 Size aRectSize
= maDrawArea
.GetSize();
52 drawinglayer::primitive2d::TextLayouterDevice aTextDev
;
53 aTextDev
.setFontAttribute(pAttrs
->aFontAttr
,
54 pAttrs
->aFontSize
.getX(), pAttrs
->aFontSize
.getY(),
55 com::sun::star::lang::Locale() );
57 long nSpace
= (nDisplayHeight
+ nPadding
- 2*aTextDev
.getTextHeight()) / 3;
59 // Set subtitle position
60 maSubTitlePos
.setY(maTextPos
.getY() + nSpace
+ aTextDev
.getTextHeight());
61 maSubTitlePos
.setX(maDrawArea
.Left() +
62 (aRectSize
.Width() - aTextDev
.getTextWidth(maSubTitle
,0,nMaxTextLength
)*SUBTITLE_SCALE_FACTOR
)/2);
66 void TemplateViewItem::Paint(drawinglayer::processor2d::BaseProcessor2D
*pProcessor
,
67 const ThumbnailItemAttributes
*pAttrs
)
69 BColor aFillColor
= pAttrs
->aFillColor
;
71 int nCount
= maSubTitle
.isEmpty() ? 5 : 6;
72 drawinglayer::primitive2d::Primitive2DSequence
aSeq(nCount
);
73 double fTransparence
= 0.0;
76 if ( mbSelected
|| mbHover
)
77 aFillColor
= pAttrs
->aHighlightColor
;
80 fTransparence
= pAttrs
->fHighlightTransparence
;
82 aSeq
[0] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonSelectionPrimitive2D(
83 B2DPolyPolygon(Polygon(maDrawArea
,5,5).getB2DPolygon()),
90 Size aImageSize
= maPreview1
.GetSizePixel();
92 float fWidth
= aImageSize
.Width();
93 float fHeight
= aImageSize
.Height();
94 float fPosX
= maPrev1Pos
.getX();
95 float fPosY
= maPrev1Pos
.getY();
98 aBounds
.append(B2DPoint(fPosX
,fPosY
));
99 aBounds
.append(B2DPoint(fPosX
+fWidth
,fPosY
));
100 aBounds
.append(B2DPoint(fPosX
+fWidth
,fPosY
+fHeight
));
101 aBounds
.append(B2DPoint(fPosX
,fPosY
+fHeight
));
102 aBounds
.setClosed(true);
104 aSeq
[1] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonColorPrimitive2D(
105 B2DPolyPolygon(aBounds
), Color(COL_WHITE
).getBColor()));
107 aSeq
[2] = drawinglayer::primitive2d::Primitive2DReference( new FillGraphicPrimitive2D(
108 createTranslateB2DHomMatrix(maPrev1Pos
.X(),maPrev1Pos
.Y()),
109 FillGraphicAttribute(Graphic(maPreview1
),
112 B2DPoint(aImageSize
.Width(),aImageSize
.Height())),
116 // draw thumbnail borders
117 aSeq
[3] = drawinglayer::primitive2d::Primitive2DReference(createBorderLine(aBounds
));
119 addTextPrimitives(maTitle
, pAttrs
, maTextPos
, aSeq
);
121 if (!maSubTitle
.isEmpty())
123 addTextPrimitives(maSubTitle
, pAttrs
, maSubTitlePos
, aSeq
);
126 pProcessor
->process(aSeq
);
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */