File: KoTextBlockBorderData.h

package info (click to toggle)
calligra 1%3A25.04.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 309,164 kB
  • sloc: cpp: 667,890; xml: 126,105; perl: 2,724; python: 2,497; yacc: 1,817; ansic: 1,326; sh: 1,223; lex: 1,107; javascript: 495; makefile: 24
file content (112 lines) | stat: -rw-r--r-- 3,724 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* This file is part of the KDE project
 * SPDX-FileCopyrightText: 2006 Thomas Zander <zander@kde.org>
 *
 * SPDX-License-Identifier: LGPL-2.0-or-later
 */
#ifndef KOTEXTBLOCKBORDERDATA_H
#define KOTEXTBLOCKBORDERDATA_H

#include "styles/KoParagraphStyle.h"

#include "kotext_export.h"

class QRectF;
class QPainter;

/**
 * This class holds data for paragraph-borders.
 * All the information needed to paint the borders, but also to calculate the insets that the borders
 * cause on text-layout is stored in here.
 * An instance of this class is owned by the KoTextBlockData and this class is being refcounted
 * to allow multiple paragraphs to share one border.
 *
 */
class KOTEXT_EXPORT KoTextBlockBorderData
{
public:
    /// Enum used to differentiate between the 4 types of borders this class maintains
    enum Side {
        Top = 0, ///< References the border at the top of the paragraph
        Left, ///< References the border at the left side of the paragraph
        Bottom, ///< References the border at the bottom of the paragraph
        Right ///< References the border at the right side of the paragraph
    };
    /**
     * Constructor for the border data.
     * Will create a border-set with the param rectangle but all the borders will
     * be turned off.
     * @param paragRect the rectangle that will be used to paint the border inside of.
     * @see setEdge() to set the actual border properties.
     */
    explicit KoTextBlockBorderData(const QRectF &paragRect);

    /**
     * Copy constructor for the border data.
     * @param other the original object which will be duplicated.
     */
    explicit KoTextBlockBorderData(const KoTextBlockBorderData &other);

    ~KoTextBlockBorderData();

    /**
     * Increments the use-value.
     * Returns true if the new value is non-zero, false otherwise.
     */
    bool ref();
    /**
     * Decrements the use-value.
     * Returns true if the new value is non-zero, false otherwise.
     */
    bool deref();
    /// return the usage count
    int useCount() const;

    /**
     * Set the properties of an edge based on a paragraph-format.
     * @param side defines which edge this is for.
     * @param bf the format of the paragraph See QTextBlock.blockFormat()
     * @param style the border style for this side.
     * @param width the thickness of the border-line.
     * @param color the property for the color of the border-line(s).
     * @param space the amount of spacing between the outer border and the inner border in case of style being double
     * @param innerWidth the thickness of the inner border-line in case of style being double
     */
    void setEdge(Side side,
                 const QTextBlockFormat &bf,
                 KoParagraphStyle::Property style,
                 KoParagraphStyle::Property width,
                 KoParagraphStyle::Property color,
                 KoParagraphStyle::Property space,
                 KoParagraphStyle::Property innerWidth);

    /**
     * Set if this border should possibly be merged with the next.
     */
    void setMergeWithNext(bool merge);

    /**
     * @return true if there has been at least one border set.
     */
    bool hasBorders() const;

    /**
     * Find the inset that a border causes for a specific side.
     * @see applyInsets()
     */
    qreal inset(Side side) const;

    /// returns true if the borders of param border are the same as this one.
    bool operator==(const KoTextBlockBorderData &border) const;
    bool equals(const KoTextBlockBorderData &border) const;

    /**
     * Paint the borders.
     */
    void paint(QPainter &painter, const QRectF &clip) const;

private:
    class Private;
    Private *const d;
};

#endif