LCOV - code coverage report
Current view: top level - sfx2/source/control - templatecontaineritem.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 76 0.0 %
Date: 2014-04-11 Functions: 0 6 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/templatecontaineritem.hxx>
      11             : #include <sfx2/templateabstractview.hxx>
      12             : 
      13             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      14             : #include <basegfx/polygon/b2dpolygon.hxx>
      15             : #include <drawinglayer/attribute/fillgraphicattribute.hxx>
      16             : #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx>
      17             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      18             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      19             : #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
      20             : #include <drawinglayer/primitive2d/textprimitive2d.hxx>
      21             : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
      22             : #include <sfx2/templateviewitem.hxx>
      23             : #include <vcl/button.hxx>
      24             : #include <vcl/graph.hxx>
      25             : 
      26             : using namespace basegfx;
      27             : using namespace basegfx::tools;
      28             : using namespace drawinglayer::attribute;
      29             : using namespace drawinglayer::primitive2d;
      30             : 
      31           0 : TemplateContainerItem::TemplateContainerItem (ThumbnailView &rView, sal_uInt16 nId)
      32             :     : ThumbnailViewItem(rView, nId)
      33           0 :     , mnRegionId(0)
      34             : {
      35           0 : }
      36             : 
      37           0 : TemplateContainerItem::~TemplateContainerItem ()
      38             : {
      39           0 : }
      40             : 
      41           0 : void TemplateContainerItem::calculateItemsPosition (const long nThumbnailHeight, const long nDisplayHeight,
      42             :                                      const long nPadding, sal_uInt32 nMaxTextLength,
      43             :                                      const ThumbnailItemAttributes *pAttrs)
      44             : {
      45           0 :     ThumbnailViewItem::calculateItemsPosition( nThumbnailHeight, nDisplayHeight, nPadding, nMaxTextLength, pAttrs);
      46           0 :     Point aPos (maDrawArea.getX() + nPadding, maDrawArea.getY() + nPadding);
      47           0 :     maThumbnailArea = Rectangle(aPos, Size(maDrawArea.GetWidth() - 2 * nPadding, nThumbnailHeight));
      48           0 : }
      49             : 
      50           0 : void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
      51             :                                     const ThumbnailItemAttributes *pAttrs)
      52             : {
      53           0 :     int nCount = 0;
      54           0 :     int nSeqSize = 3;
      55             : 
      56           0 :     if (!maPreview1.IsEmpty())
      57           0 :         nSeqSize += 3;
      58             : 
      59           0 :     if (!maPreview2.IsEmpty())
      60           0 :         nSeqSize += 3;
      61             : 
      62           0 :     if (!maPreview3.IsEmpty())
      63           0 :         nSeqSize += 3;
      64             : 
      65           0 :     if (!maPreview4.IsEmpty())
      66           0 :         nSeqSize += 3;
      67             : 
      68           0 :     BColor aFillColor = pAttrs->aFillColor;
      69           0 :     drawinglayer::primitive2d::Primitive2DSequence aSeq(nSeqSize);
      70             : 
      71             :     // Draw background
      72           0 :     if ( mbSelected || mbHover )
      73           0 :         aFillColor = pAttrs->aHighlightColor;
      74             : 
      75           0 :     aSeq[nCount++] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonColorPrimitive2D(
      76             :                                                B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
      77           0 :                                                aFillColor));
      78             : 
      79             :     // Create rounded rectangle border
      80           0 :     aSeq[nCount++] = drawinglayer::primitive2d::Primitive2DReference( new PolygonStrokePrimitive2D(
      81             :                                               Polygon(maThumbnailArea,5,5).getB2DPolygon(),
      82           0 :                                               LineAttribute(BColor(0.8, 0.8, 0.8), 2.0)));
      83             : 
      84             :     // Paint the thumbnails side by side on a 2x2 grid
      85           0 :     long nThumbPadding = 4;
      86           0 :     Size aThumbSize( ( maThumbnailArea.getWidth() - 3 * nThumbPadding ) / 2, ( maThumbnailArea.getHeight() - 3* nThumbPadding ) / 2 );
      87             : 
      88             :     // Draw thumbnail
      89           0 :     for (int i=0; i<4; ++i)
      90             :     {
      91           0 :         long nPosX = 0;
      92           0 :         long nPosY = 0;
      93           0 :         BitmapEx* pImage = NULL;
      94             : 
      95           0 :         switch (i)
      96             :         {
      97             :             case 0:
      98           0 :                 pImage = &maPreview1;
      99           0 :                 break;
     100             :             case 1:
     101           0 :                 pImage = &maPreview2;
     102           0 :                 nPosX = aThumbSize.getWidth() + nThumbPadding;
     103           0 :                 break;
     104             :             case 2:
     105           0 :                 pImage = &maPreview3;
     106           0 :                 nPosY = aThumbSize.getHeight() + nThumbPadding;
     107           0 :                 break;
     108             :             case 3:
     109           0 :                 pImage = &maPreview4;
     110           0 :                 nPosX = aThumbSize.getWidth() + nThumbPadding;
     111           0 :                 nPosY = aThumbSize.getHeight() + nThumbPadding;
     112           0 :                 break;
     113             :         }
     114             : 
     115           0 :         if (!pImage->IsEmpty())
     116             :         {
     117             :             // Check the size of the picture and resize if needed
     118           0 :             Size aImageSize = pImage->GetSizePixel();
     119           0 :             if (aImageSize.getWidth() > aThumbSize.getWidth() || aImageSize.getHeight() > aThumbSize.getHeight())
     120             :             {
     121             :                 // Resize the picture and store it for next times
     122           0 :                 *pImage = TemplateAbstractView::scaleImg( *pImage, aThumbSize.getWidth(), aThumbSize.getHeight() );
     123           0 :                 aImageSize = pImage->GetSizePixel();
     124             :             }
     125             : 
     126           0 :             float nOffX = (aThumbSize.getWidth() - aImageSize.getWidth()) / 2;
     127           0 :             float nOffY = (aThumbSize.getHeight() - aImageSize.getHeight()) / 2;
     128             : 
     129           0 :             float fWidth = aImageSize.Width();
     130           0 :             float fHeight = aImageSize.Height();
     131           0 :             float fPosX = maThumbnailArea.Left() + nThumbPadding + nPosX + nOffX;
     132           0 :             float fPosY = maThumbnailArea.Top() + nThumbPadding + nPosY + nOffY;
     133             : 
     134           0 :             B2DPolygon aBounds;
     135           0 :             aBounds.append(B2DPoint(fPosX,fPosY));
     136           0 :             aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
     137           0 :             aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
     138           0 :             aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
     139           0 :             aBounds.setClosed(true);
     140             : 
     141           0 :             aSeq[nCount++] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonColorPrimitive2D(
     142           0 :                                                 B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
     143           0 :             aSeq[nCount++] = drawinglayer::primitive2d::Primitive2DReference( new FillGraphicPrimitive2D(
     144             :                                                 createScaleTranslateB2DHomMatrix(1.0,1.0,fPosX,fPosY),
     145             :                                                 FillGraphicAttribute(Graphic(*pImage),
     146             :                                                                     B2DRange(
     147             :                                                                         B2DPoint(0.0,0.0),
     148           0 :                                                                         B2DPoint(aImageSize.Width(),aImageSize.Height())),
     149             :                                                                     false)
     150           0 :                                                 ));
     151             : 
     152             :             // draw thumbnail borders
     153           0 :             aSeq[nCount++] = drawinglayer::primitive2d::Primitive2DReference(createBorderLine(aBounds));
     154             :         }
     155             :     }
     156             : 
     157           0 :     addTextPrimitives(maTitle, pAttrs, maTextPos, aSeq);
     158             : 
     159           0 :     pProcessor->process(aSeq);
     160           0 : }
     161             : 
     162           0 : bool TemplateContainerItem::HasMissingPreview( )
     163             : {
     164           0 :     return maPreview1.IsEmpty() || maPreview2.IsEmpty() || maPreview3.IsEmpty() || maPreview4.IsEmpty();
     165             : }
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
     168             : 
     169             : 

Generated by: LCOV version 1.10