LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/control - templateviewitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 53 0.0 %
Date: 2012-12-27 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             :  * Copyright 2012 LibreOffice contributors.
       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/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>
      22             : 
      23             : #define SUBTITLE_SCALE_FACTOR 0.85
      24             : 
      25             : using namespace basegfx;
      26             : using namespace basegfx::tools;
      27             : using namespace drawinglayer::attribute;
      28             : using namespace drawinglayer::primitive2d;
      29             : 
      30           0 : TemplateViewItem::TemplateViewItem (ThumbnailView &rView)
      31           0 :     : ThumbnailViewItem(rView)
      32             : {
      33           0 : }
      34             : 
      35           0 : TemplateViewItem::~TemplateViewItem ()
      36             : {
      37           0 : }
      38             : 
      39           0 : void TemplateViewItem::calculateItemsPosition(const long nThumbnailHeight, const long nDisplayHeight,
      40             :                                               const long nPadding, sal_uInt32 nMaxTextLenght,
      41             :                                               const ThumbnailItemAttributes *pAttrs)
      42             : {
      43           0 :     ThumbnailViewItem::calculateItemsPosition(nThumbnailHeight,nDisplayHeight,nPadding,nMaxTextLenght, pAttrs);
      44             : 
      45           0 :     if (!maSubTitle.isEmpty())
      46             :     {
      47           0 :         Size aRectSize = maDrawArea.GetSize();
      48             : 
      49           0 :         drawinglayer::primitive2d::TextLayouterDevice aTextDev;
      50             :         aTextDev.setFontAttribute(pAttrs->aFontAttr,
      51             :                                   pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
      52           0 :                                   com::sun::star::lang::Locale() );
      53             : 
      54           0 :         long nSpace = (nDisplayHeight + nPadding - 2*aTextDev.getTextHeight()) / 3;
      55             : 
      56             :         // Set title position
      57           0 :         maTextPos.setY(maDrawArea.getY() + nThumbnailHeight + nPadding + nSpace + aTextDev.getTextHeight());
      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,nMaxTextLenght)*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 :     Primitive2DSequence aSeq(nCount);
      73             : 
      74             :     // Draw background
      75           0 :     if ( mbSelected || mbHover )
      76           0 :         aFillColor = pAttrs->aHighlightColor;
      77             : 
      78           0 :     aSeq[0] = 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] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
      98           0 :                                         B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
      99             : 
     100           0 :     aSeq[2] = Primitive2DReference( new FillBitmapPrimitive2D(
     101           0 :                                         createTranslateB2DHomMatrix(maPrev1Pos.X(),maPrev1Pos.Y()),
     102             :                                         FillBitmapAttribute(maPreview1,
     103             :                                                             B2DPoint(0,0),
     104           0 :                                                             B2DVector(aImageSize.Width(),aImageSize.Height()),
     105             :                                                             false)
     106           0 :                                         ));
     107             : 
     108             :     // draw thumbnail borders
     109           0 :     aSeq[3] = Primitive2DReference(createBorderLine(aBounds));
     110             : 
     111             :     // Draw centered text below thumbnail
     112             : 
     113             :     // Create the text primitive
     114             :     basegfx::B2DHomMatrix aTitleMatrix( createScaleTranslateB2DHomMatrix(
     115             :                 pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
     116           0 :                 double( maTextPos.X() ), double( maTextPos.Y() ) ) );
     117             : 
     118           0 :     aSeq[4] = Primitive2DReference(
     119             :                 new TextSimplePortionPrimitive2D(aTitleMatrix,
     120             :                                                  maTitle,0,pAttrs->nMaxTextLenght,
     121             :                                                  std::vector< double >( ),
     122             :                                                  pAttrs->aFontAttr,
     123             :                                                  com::sun::star::lang::Locale(),
     124           0 :                                                  Color(COL_BLACK).getBColor() ) );
     125             : 
     126           0 :     if (!maSubTitle.isEmpty())
     127             :     {
     128             :         basegfx::B2DHomMatrix aSubTitleMatrix( createScaleTranslateB2DHomMatrix(
     129           0 :                     pAttrs->aFontSize.getX()*SUBTITLE_SCALE_FACTOR, pAttrs->aFontSize.getY()*SUBTITLE_SCALE_FACTOR,
     130           0 :                     double( maSubTitlePos.X() ), double( maSubTitlePos.Y() ) ) );
     131             : 
     132           0 :         aSeq[5] = Primitive2DReference(
     133             :                     new TextSimplePortionPrimitive2D(aSubTitleMatrix,
     134             :                                                      maSubTitle,0,pAttrs->nMaxTextLenght,
     135             :                                                      std::vector< double >( ),
     136             :                                                      pAttrs->aFontAttr,
     137             :                                                      com::sun::star::lang::Locale(),
     138           0 :                                                      Color(COL_BLACK).getBColor() ) );
     139             :     }
     140             : 
     141           0 :     pProcessor->process(aSeq);
     142           0 : }
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
     145             : 
     146             : 

Generated by: LCOV version 1.10