Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/control/templateviewitem.cxx
Line
Count
Source
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 <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/PolygonHairlinePrimitive2D.hxx>
17
#include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
18
#include <drawinglayer/primitive2d/PolyPolygonSelectionPrimitive2D.hxx>
19
#include <drawinglayer/primitive2d/discretebitmapprimitive2d.hxx>
20
#include <drawinglayer/processor2d/baseprocessor2d.hxx>
21
#include <tools/poly.hxx>
22
#include <vcl/graph.hxx>
23
24
#include <bitmaps.hlst>
25
26
using namespace basegfx;
27
using namespace basegfx::utils;
28
using namespace drawinglayer::attribute;
29
using namespace drawinglayer::primitive2d;
30
31
TemplateViewItem::TemplateViewItem(ThumbnailView& rView, sal_uInt16 nId)
32
0
    : ThumbnailViewItem(rView, nId),
33
0
      mnRegionId(USHRT_MAX),
34
0
      mnDocId(USHRT_MAX),
35
0
      maDefaultBitmap(BMP_DEFAULT),
36
0
      mbIsDefaultTemplate(false)
37
0
{
38
0
}
39
40
TemplateViewItem::~TemplateViewItem ()
41
0
{
42
0
}
43
44
::tools::Rectangle TemplateViewItem::getDefaultIconArea() const
45
0
{
46
0
    ::tools::Rectangle aArea(getDrawArea());
47
0
    Size aSize(maDefaultBitmap.GetSizePixel());
48
49
0
    return ::tools::Rectangle(
50
0
            Point(aArea.Left() + THUMBNAILVIEW_ITEM_CORNER, aArea.Top() + THUMBNAILVIEW_ITEM_CORNER),
51
0
            aSize);
52
0
}
53
54
void TemplateViewItem::Paint(drawinglayer::processor2d::BaseProcessor2D *pProcessor,
55
                                   const ThumbnailItemAttributes *pAttrs)
56
0
{
57
0
    BColor aFillColor = pAttrs->aFillColor;
58
59
0
    drawinglayer::primitive2d::Primitive2DContainer aSeq(5);
60
0
    double fTransparence = 0.0;
61
62
    // Draw background
63
0
    if( mbSelected && mbHover)
64
0
        aFillColor = pAttrs->aHighlightColor;
65
0
    else if (mbSelected || mbHover)
66
0
    {
67
0
        aFillColor = pAttrs->aHighlightColor;
68
0
        if (mbHover)
69
0
            fTransparence = pAttrs->fHighlightTransparence;
70
0
    }
71
72
0
    aSeq[0] =
73
0
            new PolyPolygonSelectionPrimitive2D( B2DPolyPolygon(::tools::Polygon(maDrawArea,5,5).getB2DPolygon()),
74
0
                                                 aFillColor,
75
0
                                                 fTransparence,
76
0
                                                 0.0,
77
0
                                                 true);
78
79
    // Draw thumbnail
80
0
    Size aImageSize = maPreview.GetSizePixel();
81
82
0
    float fWidth = aImageSize.Width();
83
0
    float fHeight = aImageSize.Height();
84
0
    float fPosX = maPrev1Pos.getX();
85
0
    float fPosY = maPrev1Pos.getY();
86
87
0
    B2DPolygon aBounds;
88
0
    aBounds.append(B2DPoint(fPosX,fPosY));
89
0
    aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
90
0
    aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
91
0
    aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
92
0
    aBounds.setClosed(true);
93
94
0
    aSeq[1] = new PolyPolygonColorPrimitive2D(
95
0
                    B2DPolyPolygon(aBounds), COL_WHITE.getBColor());
96
97
0
    aSeq[2] = new FillGraphicPrimitive2D(
98
0
                    createTranslateB2DHomMatrix(maPrev1Pos.X(),maPrev1Pos.Y()),
99
0
                    FillGraphicAttribute(Graphic(maPreview),
100
0
                                        B2DRange(
101
0
                                            B2DPoint(0,0),
102
0
                                            B2DPoint(aImageSize.Width(),aImageSize.Height())),
103
0
                                        false)
104
0
                    );
105
106
    // draw thumbnail borders
107
0
    aSeq[3] = createBorderLine(aBounds);
108
109
0
    if(mbIsDefaultTemplate)
110
0
    {
111
0
        Point aIconPos(getDefaultIconArea().TopLeft());
112
113
0
        aSeq[4] = new DiscreteBitmapPrimitive2D( maDefaultBitmap,
114
0
                    B2DPoint(aIconPos.X(), aIconPos.Y()));
115
0
    }
116
117
0
    addTextPrimitives(maTitle, pAttrs, maTextPos, aSeq);
118
119
0
    pProcessor->process(aSeq);
120
0
}
121
122
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
123
124