LCOV - code coverage report
Current view: top level - sfx2/source/control - templateviewitem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 51 2.0 %
Date: 2014-11-03 Functions: 2 7 28.6 %
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             : #include <svtools/optionsdrawinglayer.hxx>
      24             : 
      25             : #define SUBTITLE_SCALE_FACTOR 0.85
      26             : 
      27             : using namespace basegfx;
      28             : using namespace basegfx::tools;
      29             : using namespace drawinglayer::attribute;
      30             : using namespace drawinglayer::primitive2d;
      31             : 
      32           0 : TemplateViewItem::TemplateViewItem (ThumbnailView &rView, sal_uInt16 nId)
      33             :     : ThumbnailViewItem(rView, nId),
      34             :       mnRegionId(USHRT_MAX),
      35           0 :       mnDocId(USHRT_MAX)
      36             : {
      37           0 : }
      38             : 
      39           0 : TemplateViewItem::~TemplateViewItem ()
      40             : {
      41           0 : }
      42             : 
      43           0 : void TemplateViewItem::calculateItemsPosition(const long nThumbnailHeight, const long nDisplayHeight,
      44             :                                               const long nPadding, sal_uInt32 nMaxTextLength,
      45             :                                               const ThumbnailItemAttributes *pAttrs)
      46             : {
      47           0 :     ThumbnailViewItem::calculateItemsPosition(nThumbnailHeight,nDisplayHeight,nPadding,nMaxTextLength, pAttrs);
      48             : 
      49           0 :     if (!maSubTitle.isEmpty())
      50             :     {
      51           0 :         Size aRectSize = maDrawArea.GetSize();
      52             : 
      53           0 :         drawinglayer::primitive2d::TextLayouterDevice aTextDev;
      54             :         aTextDev.setFontAttribute(pAttrs->aFontAttr,
      55             :                                   pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
      56           0 :                                   com::sun::star::lang::Locale() );
      57             : 
      58           0 :         long nSpace = (nDisplayHeight + nPadding - 2*aTextDev.getTextHeight()) / 3;
      59             : 
      60             :         // Set subtitle position
      61           0 :         maSubTitlePos.setY(maTextPos.getY() + nSpace + aTextDev.getTextHeight());
      62           0 :         maSubTitlePos.setX(maDrawArea.Left() +
      63           0 :                            (aRectSize.Width() - aTextDev.getTextWidth(maSubTitle,0,nMaxTextLength)*SUBTITLE_SCALE_FACTOR)/2);
      64             :     }
      65           0 : }
      66             : 
      67           0 : void TemplateViewItem::Paint(drawinglayer::processor2d::BaseProcessor2D *pProcessor,
      68             :                                    const ThumbnailItemAttributes *pAttrs)
      69             : {
      70           0 :     BColor aFillColor = pAttrs->aFillColor;
      71             : 
      72           0 :     int nCount = maSubTitle.isEmpty() ? 5 : 6;
      73           0 :     drawinglayer::primitive2d::Primitive2DSequence aSeq(nCount);
      74           0 :     double fTransparence = 0.0;
      75             : 
      76             :     // Draw background
      77           0 :     if ( mbSelected || mbHover )
      78           0 :         aFillColor = pAttrs->aHighlightColor;
      79             : 
      80           0 :     if(mbHover)
      81             :     {
      82           0 :         const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
      83           0 :         fTransparence = aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() * 0.01;
      84             :     }
      85             : 
      86           0 :     aSeq[0] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonSelectionPrimitive2D(
      87             :                                                B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
      88             :                                                aFillColor,
      89             :                                                fTransparence,
      90             :                                                0.0,
      91           0 :                                                true));
      92             : 
      93             :     // Draw thumbnail
      94           0 :     Size aImageSize = maPreview1.GetSizePixel();
      95             : 
      96           0 :     float fWidth = aImageSize.Width();
      97           0 :     float fHeight = aImageSize.Height();
      98           0 :     float fPosX = maPrev1Pos.getX();
      99           0 :     float fPosY = maPrev1Pos.getY();
     100             : 
     101           0 :     B2DPolygon aBounds;
     102           0 :     aBounds.append(B2DPoint(fPosX,fPosY));
     103           0 :     aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
     104           0 :     aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
     105           0 :     aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
     106           0 :     aBounds.setClosed(true);
     107             : 
     108           0 :     aSeq[1] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonColorPrimitive2D(
     109           0 :                                         B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
     110             : 
     111           0 :     aSeq[2] = drawinglayer::primitive2d::Primitive2DReference( new FillGraphicPrimitive2D(
     112           0 :                                         createTranslateB2DHomMatrix(maPrev1Pos.X(),maPrev1Pos.Y()),
     113             :                                         FillGraphicAttribute(Graphic(maPreview1),
     114             :                                                             B2DRange(
     115             :                                                                 B2DPoint(0,0),
     116           0 :                                                                 B2DPoint(aImageSize.Width(),aImageSize.Height())),
     117             :                                                             false)
     118           0 :                                         ));
     119             : 
     120             :     // draw thumbnail borders
     121           0 :     aSeq[3] = drawinglayer::primitive2d::Primitive2DReference(createBorderLine(aBounds));
     122             : 
     123           0 :     addTextPrimitives(maTitle, pAttrs, maTextPos, aSeq);
     124             : 
     125           0 :     if (!maSubTitle.isEmpty())
     126             :     {
     127           0 :         addTextPrimitives(maSubTitle, pAttrs, maSubTitlePos, aSeq);
     128             :     }
     129             : 
     130           0 :     pProcessor->process(aSeq);
     131         951 : }
     132             : 
     133             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
     134             : 
     135             : 

Generated by: LCOV version 1.10