File: CellView.h

package info (click to toggle)
calligra 1%3A2.9.11%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 189,332 kB
  • sloc: cpp: 919,806; xml: 27,759; ansic: 10,472; python: 8,190; perl: 2,724; yacc: 2,557; sh: 1,675; lex: 1,431; java: 1,304; sql: 903; ruby: 734; makefile: 48
file content (319 lines) | stat: -rw-r--r-- 10,338 bytes parent folder | download | duplicates (3)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* This file is part of the KDE project
   Copyright 2006-2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
   Copyright 2004 Tomas Mecir <mecirt@gmail.com>
   Copyright 1999-2002,2004 Laurent Montel <montel@kde.org>
   Copyright 2002,2004 Ariya Hidayat <ariya@kde.org>
   Copyright 2002-2003 Norbert Andres <nandres@web.de>
   Copyright 2003 Stefan Hetzl <shetzl@chello.at>
   Copyright 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
   Copyright 2002 Harri Porten <porten@kde.org>
   Copyright 2002 John Dailey <dailey@vt.edu>
   Copyright 1999-2001 David Faure <faure@kde.org>
   Copyright 2000-2001 Werner Trobin <trobin@kde.org>
   Copyright 2000 Simon Hausmann <hausmann@kde.org
   Copyright 1998-1999 Torben Weis <weis@kde.org>
   Copyright 1999 Michael Reiher <michael.reiher@gmx.de>
   Copyright 1999 Reginald Stadlbauer <reggie@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; only
   version 2 of the License.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef CALLIGRA_SHEETS_CELL_VIEW
#define CALLIGRA_SHEETS_CELL_VIEW

// Qt
#include <QExplicitlySharedDataPointer>

// KSpread
#include "Global.h"
#include "Style.h"

class QFontMetricsF;
class QRectF;

namespace Calligra
{
namespace Sheets
{
class Cell;
class Sheet;
class SheetView;
class Style;

/**
 * \ingroup Painting
 * Responsible for the painting of Cell.
 * For each visible Cell exists a CellView, which is cached in the
 * corresponding SheetView. If the content of a Cell has changed, the CellView
 * will be destroyed and a new one will be created.
 */
class CALLIGRA_SHEETS_COMMON_EXPORT CellView
{
    friend class SheetView;
    friend class PixmapCachingSheetView;

public:
    CellView(SheetView* sheetView, int col, int row);
    CellView(const CellView& other);
    virtual ~CellView();
    CellView& operator=(const CellView& other);

    enum Border {
        NoBorder     = 0x0,
        LeftBorder   = 0x1,
        RightBorder  = 0x2,
        TopBorder    = 0x4,
        BottomBorder = 0x8
    };
    Q_DECLARE_FLAGS(Borders, Border)

    /**
     * \return the style for the cell associated with this view
     */
    Style style() const;

    /**
     * Paints the cell's background.
     * \param painter the used painter
     * \param coordinate the top left coordinate (scroll offset dependent)
     */
    void paintCellBackground(QPainter& painter, const QRegion &clipRegion, const QPointF& coordinate) const;

    /**
     * Paints the cell.
     * \param paintRegion the portion of the canvas that is actually in view
     * \param painter the used painter
     * \param coordinate the top left coordinate (scroll offset dependent)
     * \param cell the Cell
     */
    virtual void paintCellContents(const QRectF& paintRegion, QPainter& painter, const QRegion &clipRegion,
                           const QPointF& coordinate,
                           const Cell& cell, SheetView* sheetView) const;

    /**
     * Paints the cell custom borders, the page borders, diagonal lines.
     * \param paintRegion the portion of the canvas that is actually in view
     * \param painter the used painter
     * \param coordinate the top left coordinate (scroll offset dependent)
     * \param cellRange the cell range, that is painted
     * \param cell the Cell
     * \param sheetView the SheetView
     */
    void paintCellBorders(const QRectF& paintRegion, QPainter& painter, const QRegion &clipRegion,
                          const QPointF& coordinate,
                          const QRect& cellRange,
                          const Cell& cell, SheetView* sheetView) const;

    /**
     * Paints the default cell borders.
     * \param painter the used painter
     * \param paintRegion the portion of the canvas that is actually in view
     * \param coordinate the painting coordinate
     * \param paintBorder the borders, that should be painted (should be removed???)
     * \param cellRange the cell range, that is painted
     * \param cell the Cell
     * \param sheetView the SheetView
     */
    void paintDefaultBorders(QPainter& painter, const QRegion &clipRegion, const QRectF &paintRegion,
                             const QPointF& coordinate,
                             Borders paintBorder, const QRect& cellRange,
                             const Cell& cell, SheetView* sheetView) const;

    /**
     * \return width of the text
     */
    qreal textWidth() const;

    /**
     * \return height of the text
     */
    qreal textHeight() const;

    /**
     * \return the rectangle the text covers
     */
    QRectF textRect() const;

    QString testAnchor(SheetView* sheetView, const Cell& cell, qreal x, qreal y) const;

    bool hitTestFilterButton(const Cell& cell, const QRect& cellRect, const QPoint& position) const;

    qreal cellHeight() const;
    qreal cellWidth() const;

    bool dimensionFits() const;

    void detach();
protected:
    /**
     * \ingroup Layout
     * Calculates the layout of the cell.
     *
     * I.e. recalculates the text to be shown, its dimensions, its offset,
     * breaks lines of the text to fit it into the cell, obscures neighbouring
     * cells, if necessary.
     */
    void makeLayout(SheetView* sheetView, const Cell& cell);

    /**
     * \ingroup Layout
     * Determines the text offset relative to the cell's top left corner.
     *
     * This depends on the following variables:
     * \li horizontal alignment
     * \li vertical alignment
     * \li text angle
     * \li text direction (horizontal or vertical)
     * \li text width and height
     * \li single or multiple rows
     * \li cell width and height, including obscured cells
     * \li thickness of the border pens
     *
     * \internal Called from makeLayout().
     */
    void textOffset(const QFontMetricsF& fontMetrics, const Cell& cell);

    /**
     * \ingroup Layout
     * Determines the dimension of this cell including any merged cells.
     * Does NOT consider space, which is available from empty neighbours,
     * and would be able to be obscured.
     *
     * \internal Called from makeLayout().
     */
    void calculateCellDimension(const Cell& cell);

    /**
     * \ingroup Layout
     * Checks, whether horizontal neighbours could be obscured
     * and does so, if necessary.
     *
     * \internal Called from makeLayout().
     */
    void obscureHorizontalCells(SheetView* sheetView, const Cell& cell);

    /**
     * \ingroup Layout
     * Checks, whether vertical neighbours could be obscured
     * and does so, if necessary.
     *
     * \internal Called from makeLayout().
     */
    void obscureVerticalCells(SheetView* sheetView, const Cell& cell);

    /**
     * Adjust the output text, so that it only holds the part that can be
     * displayed. The altered text is only temporary stored. It is restored
     * after the paint event has been processed.
     *
     * This depends on the following variables:
     * \li horizontal alignment
     * \li value format
     * \li text direction (horizontal or vertical)
     * \li indentation
     *
     * \internal Called from paintText().
     */
    QString textDisplaying(const QFontMetricsF& fontMetrics, const Cell& cell);

    /**
     * helper function for paintCell() function
     * @see paintCell()
     * @internal
     */
    void paintCustomBorders(QPainter& painter, const QRectF &paintRegion,
                            const QPointF& coordinate, Borders paintBorder,
                            bool rtl) const;

    /**
     * helper function for paintCell() function
     * @see paintCell()
     * @internal
     */
    void paintPageBorders(QPainter& painter, const QPointF &coordinate,
                          Borders paintBorder, const Cell& cell) const;

    /**
     * helper function for paintCell() function
     * @see paintCell()
     * @internal
     */
    void paintText(QPainter& painter, const QPointF& coordinate, const Cell& cell) const;

    /**
     * helper function for paintCell() function
     * @see paintCell()
     * @internal
     */
    void paintMoreTextIndicator(QPainter& painter, const QPointF& coordinate) const;

    /**
     * helper function for paintCell() function
     * @see paintCell()
     * @internal
     */
    void paintCommentIndicator(QPainter& painter, const QPointF& coordinate,
                               const Cell& cell) const;

    /**
     * helper function for paintCell() function
     * @see paintCell()
     * @internal
     */
    void paintFormulaIndicator(QPainter& painter, const QPointF& coordinate, const Cell& cell) const;

    /**
     * helper function for paintCell() function
     * @see paintCell()
     * @internal
     */
    void paintMatrixElementIndicator(QPainter& painter, const QPointF& coordinate, const Cell& cell) const;

    /**
     * helper function for paintCell() function
     * @see paintCell()
     * @internal
     */
    void paintCellDiagonalLines(QPainter& painter, const QPointF& coordinate) const;

    /**
     * helper function for paintCell() function
     * @see paintCell()
     * @internal
     */
    void paintFilterButton(QPainter& painter, const QPointF& coordinate,
                           const Cell& cell, SheetView* sheetView) const;

    void drawText(QPainter& painter, const QPointF& location, const QStringList& textLines,
                  const Cell& cell, qreal lineSpacing = 0) const;

    /**
     * Default CellView used by SheetView.
     */
    CellView(SheetView* sheetView);

    class Private;
    QExplicitlySharedDataPointer<Private> d;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(CellView::Borders)

} // namespace Sheets
} // namespace Calligra

Q_DECLARE_TYPEINFO(Calligra::Sheets::CellView, Q_MOVABLE_TYPE);

#endif