LCOV - code coverage report
Current view: top level - sfx2/source/control - templateviewitem.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 47 0.0 %
Date: 2014-04-14 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  */
       9             : 
      10             : #include <sfx2/templateviewitem.hxx>
      11             : 
      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>
      23             : 
      24             : #define SUBTITLE_SCALE_FACTOR 0.85
      25             : 
      26             : using namespace basegfx;
      27             : using namespace basegfx::tools;
      28             : using namespace drawinglayer::attribute;
      29             : using namespace drawinglayer::primitive2d;
      30             : 
      31           0 : TemplateViewItem::TemplateViewItem (ThumbnailView &rView, sal_uInt16 nId)
      32             :     : ThumbnailViewItem(rView, nId),
      33             :       mnRegionId(USHRT_MAX),
      34           0 :       mnDocId(USHRT_MAX)
      35             : {
      36           0 : }
      37             : 
      38           0 : TemplateViewItem::~TemplateViewItem ()
      39             : {
      40           0 : }
      41             : 
      42           0 : void TemplateViewItem::calculateItemsPosition(const long nThumbnailHeight, const long nDisplayHeight,
      43             :                                               const long nPadding, sal_uInt32 nMaxTextLength,
      44             :                                               const ThumbnailItemAttributes *pAttrs)
      45             : {
      46           0 :     ThumbnailViewItem::calculateItemsPosition(nThumbnailHeight,nDisplayHeight,nPadding,nMaxTextLength, pAttrs);
      47             : 
      48           0 :     if (!maSubTitle.isEmpty())
      49             :     {
      50           0 :         Size aRectSize = maDrawArea.GetSize();
      51             : 
      52           0 :         drawinglayer::primitive2d::TextLayouterDevice aTextDev;
      53             :         aTextDev.setFontAttribute(pAttrs->aFontAttr,
      54             :                                   pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
      55           0 :                                   com::sun::star::lang::Locale() );
      56             : 
      57           0 :         long nSpace = (nDisplayHeight + nPadding - 2*aTextDev.getTextHeight()) / 3;
      58             : 
      59             :         // Set subtitle position
      60           0 :         maSubTitlePos.setY(maTextPos.getY() + nSpace + aTextDev.getTextHeight());
      61           0 :         maSubTitlePos.setX(maDrawArea.Left() +
      62           0 :                            (aRectSize.Width() - aTextDev.getTextWidth(maSubTitle,0,nMaxTextLength)*SUBTITLE_SCALE_FACTOR)/2);
      63             :     }
      64           0 : }
      65             : 
      66           0 : void TemplateViewItem::Paint(drawinglayer::processor2d::BaseProcessor2D *pProcessor,
      67             :                                    const ThumbnailItemAttributes *pAttrs)
      68             : {
      69           0 :     BColor aFillColor = pAttrs->aFillColor;
      70             : 
      71           0 :     int nCount = maSubTitle.isEmpty() ? 5 : 6;
      72           0 :     drawinglayer::primitive2d::Primitive2DSequence aSeq(nCount);
      73             : 
      74             :     // Draw background
      75           0 :     if ( mbSelected || mbHover )
      76           0 :         aFillColor = pAttrs->aHighlightColor;
      77             : 
      78           0 :     aSeq[0] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonColorPrimitive2D(
      79             :                                                B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
      80           0 :                                                aFillColor));
      81             : 
      82             :     // Draw thumbnail
      83           0 :     Size aImageSize = maPreview1.GetSizePixel();
      84             : 
      85           0 :     float fWidth = aImageSize.Width();
      86           0 :     float fHeight = aImageSize.Height();
      87           0 :     float fPosX = maPrev1Pos.getX();
      88           0 :     float fPosY = maPrev1Pos.getY();
      89             : 
      90           0 :     B2DPolygon aBounds;
      91           0 :     aBounds.append(B2DPoint(fPosX,fPosY));
      92           0 :     aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
      93           0 :     aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
      94           0 :     aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
      95           0 :     aBounds.setClosed(true);
      96             : 
      97           0 :     aSeq[1] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonColorPrimitive2D(
      98           0 :                                         B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
      99             : 
     100           0 :     aSeq[2] = drawinglayer::primitive2d::Primitive2DReference( new FillGraphicPrimitive2D(
     101           0 :                                         createTranslateB2DHomMatrix(maPrev1Pos.X(),maPrev1Pos.Y()),
     102             :                                         FillGraphicAttribute(Graphic(maPreview1),
     103             :                                                             B2DRange(
     104             :                                                                 B2DPoint(0,0),
     105           0 :                                                                 B2DPoint(aImageSize.Width(),aImageSize.Height())),
     106             :                                                             false)
     107           0 :                                         ));
     108             : 
     109             :     // draw thumbnail borders
     110           0 :     aSeq[3] = drawinglayer::primitive2d::Primitive2DReference(createBorderLine(aBounds));
     111             : 
     112           0 :     addTextPrimitives(maTitle, pAttrs, maTextPos, aSeq);
     113             : 
     114           0 :     if (!maSubTitle.isEmpty())
     115             :     {
     116           0 :         addTextPrimitives(maSubTitle, pAttrs, maSubTitlePos, aSeq);
     117             :     }
     118             : 
     119           0 :     pProcessor->process(aSeq);
     120           0 : }
     121             : 
     122             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
     123             : 
     124             : 

Generated by: LCOV version 1.10