Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / control / templateviewitem.cxx
blob462667634c3d18004fe59f8d17f113601d3bf499
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <sfx2/templateviewitem.hxx>
12 #include <basegfx/matrix/b2dhommatrixtools.hxx>
13 #include <basegfx/polygon/b2dpolygon.hxx>
14 #include <drawinglayer/attribute/fillbitmapattribute.hxx>
15 #include <drawinglayer/primitive2d/fillbitmapprimitive2d.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>
23 #define SUBTITLE_SCALE_FACTOR 0.85
25 using namespace basegfx;
26 using namespace basegfx::tools;
27 using namespace drawinglayer::attribute;
28 using namespace drawinglayer::primitive2d;
30 TemplateViewItem::TemplateViewItem (ThumbnailView &rView)
31 : ThumbnailViewItem(rView),
32 mnRegionId(USHRT_MAX),
33 mnDocId(USHRT_MAX)
37 TemplateViewItem::~TemplateViewItem ()
41 void TemplateViewItem::calculateItemsPosition(const long nThumbnailHeight, const long nDisplayHeight,
42 const long nPadding, sal_uInt32 nMaxTextLenght,
43 const ThumbnailItemAttributes *pAttrs)
45 ThumbnailViewItem::calculateItemsPosition(nThumbnailHeight,nDisplayHeight,nPadding,nMaxTextLenght, pAttrs);
47 if (!maSubTitle.isEmpty())
49 Size aRectSize = maDrawArea.GetSize();
51 drawinglayer::primitive2d::TextLayouterDevice aTextDev;
52 aTextDev.setFontAttribute(pAttrs->aFontAttr,
53 pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
54 com::sun::star::lang::Locale() );
56 long nSpace = (nDisplayHeight + nPadding - 2*aTextDev.getTextHeight()) / 3;
58 // Set subtitle position
59 maSubTitlePos.setY(maTextPos.getY() + nSpace + aTextDev.getTextHeight());
60 maSubTitlePos.setX(maDrawArea.Left() +
61 (aRectSize.Width() - aTextDev.getTextWidth(maSubTitle,0,nMaxTextLenght)*SUBTITLE_SCALE_FACTOR)/2);
65 void TemplateViewItem::Paint(drawinglayer::processor2d::BaseProcessor2D *pProcessor,
66 const ThumbnailItemAttributes *pAttrs)
68 BColor aFillColor = pAttrs->aFillColor;
70 int nCount = maSubTitle.isEmpty() ? 5 : 6;
71 Primitive2DSequence aSeq(nCount);
73 // Draw background
74 if ( mbSelected || mbHover )
75 aFillColor = pAttrs->aHighlightColor;
77 aSeq[0] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
78 B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
79 aFillColor));
81 // Draw thumbnail
82 Size aImageSize = maPreview1.GetSizePixel();
84 float fWidth = aImageSize.Width();
85 float fHeight = aImageSize.Height();
86 float fPosX = maPrev1Pos.getX();
87 float fPosY = maPrev1Pos.getY();
89 B2DPolygon aBounds;
90 aBounds.append(B2DPoint(fPosX,fPosY));
91 aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
92 aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
93 aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
94 aBounds.setClosed(true);
96 aSeq[1] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
97 B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
99 aSeq[2] = Primitive2DReference( new FillBitmapPrimitive2D(
100 createTranslateB2DHomMatrix(maPrev1Pos.X(),maPrev1Pos.Y()),
101 FillBitmapAttribute(maPreview1,
102 B2DPoint(0,0),
103 B2DVector(aImageSize.Width(),aImageSize.Height()),
104 false)
107 // draw thumbnail borders
108 aSeq[3] = Primitive2DReference(createBorderLine(aBounds));
110 addTextPrimitives(maTitle, pAttrs, maTextPos, aSeq);
112 if (!maSubTitle.isEmpty())
114 addTextPrimitives(maSubTitle, pAttrs, maSubTitlePos, aSeq);
117 pProcessor->process(aSeq);
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */