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

Generated by: LCOV version 1.10