File indexing completed on 2024-05-12 16:36:07
0001 /* This file is part of the KDE project 0002 Copyright 2006-2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 Copyright 2004 Tomas Mecir <mecirt@gmail.com> 0004 Copyright 1999-2002,2004 Laurent Montel <montel@kde.org> 0005 Copyright 2002,2004 Ariya Hidayat <ariya@kde.org> 0006 Copyright 2002-2003 Norbert Andres <nandres@web.de> 0007 Copyright 2003 Stefan Hetzl <shetzl@chello.at> 0008 Copyright 2001-2002 Philipp Mueller <philipp.mueller@gmx.de> 0009 Copyright 2002 Harri Porten <porten@kde.org> 0010 Copyright 2002 John Dailey <dailey@vt.edu> 0011 Copyright 1999-2001 David Faure <faure@kde.org> 0012 Copyright 2000-2001 Werner Trobin <trobin@kde.org> 0013 Copyright 2000 Simon Hausmann <hausmann@kde.org 0014 Copyright 1998-1999 Torben Weis <weis@kde.org> 0015 Copyright 1999 Michael Reiher <michael.reiher@gmx.de> 0016 Copyright 1999 Reginald Stadlbauer <reggie@kde.org> 0017 0018 This library is free software; you can redistribute it and/or 0019 modify it under the terms of the GNU Library General Public 0020 License as published by the Free Software Foundation; only 0021 version 2 of the License. 0022 0023 This library is distributed in the hope that it will be useful, 0024 but WITHOUT ANY WARRANTY; without even the implied warranty of 0025 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0026 Library General Public License for more details. 0027 0028 You should have received a copy of the GNU Library General Public License 0029 along with this library; see the file COPYING.LIB. If not, write to 0030 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0031 Boston, MA 02110-1301, USA. 0032 */ 0033 0034 #ifndef CALLIGRA_SHEETS_CELL_VIEW 0035 #define CALLIGRA_SHEETS_CELL_VIEW 0036 0037 // Qt 0038 #include <QExplicitlySharedDataPointer> 0039 0040 // Sheets 0041 #include "Global.h" 0042 #include "Style.h" 0043 #include "sheets_common_export.h" 0044 0045 class QFontMetricsF; 0046 class QRectF; 0047 0048 namespace Calligra 0049 { 0050 namespace Sheets 0051 { 0052 class Cell; 0053 class Sheet; 0054 class SheetView; 0055 class Style; 0056 0057 /** 0058 * \ingroup Painting 0059 * Responsible for the painting of Cell. 0060 * For each visible Cell exists a CellView, which is cached in the 0061 * corresponding SheetView. If the content of a Cell has changed, the CellView 0062 * will be destroyed and a new one will be created. 0063 */ 0064 class CALLIGRA_SHEETS_COMMON_EXPORT CellView 0065 { 0066 friend class SheetView; 0067 friend class PixmapCachingSheetView; 0068 0069 public: 0070 CellView(SheetView* sheetView, int col, int row); 0071 CellView(const CellView& other); 0072 virtual ~CellView(); 0073 CellView& operator=(const CellView& other); 0074 0075 enum Border { 0076 NoBorder = 0x0, 0077 LeftBorder = 0x1, 0078 RightBorder = 0x2, 0079 TopBorder = 0x4, 0080 BottomBorder = 0x8 0081 }; 0082 Q_DECLARE_FLAGS(Borders, Border) 0083 0084 /** 0085 * \return the style for the cell associated with this view 0086 */ 0087 Style style() const; 0088 0089 /** 0090 * Paints the cell's background. 0091 * \param painter the used painter 0092 * \param clipRegion the clip region 0093 * \param coordinate the top left coordinate (scroll offset dependent) 0094 */ 0095 void paintCellBackground(QPainter& painter, const QRegion &clipRegion, const QPointF& coordinate) const; 0096 0097 /** 0098 * Paints the cell. 0099 * \param paintRegion the portion of the canvas that is actually in view 0100 * \param painter the used painter 0101 * \param clipRegion the clip region 0102 * \param coordinate the top left coordinate (scroll offset dependent) 0103 * \param cell the Cell 0104 * \param sheetView the sheet view 0105 */ 0106 virtual void paintCellContents(const QRectF& paintRegion, QPainter& painter, const QRegion &clipRegion, 0107 const QPointF& coordinate, 0108 const Cell& cell, SheetView* sheetView) const; 0109 0110 /** 0111 * Paints the cell custom borders, the page borders, diagonal lines. 0112 * \param paintRegion the portion of the canvas that is actually in view 0113 * \param painter the used painter 0114 * \param clipRegion the clip region 0115 * \param coordinate the top left coordinate (scroll offset dependent) 0116 * \param cellRange the cell range, that is painted 0117 * \param cell the Cell 0118 * \param sheetView the SheetView 0119 */ 0120 void paintCellBorders(const QRectF& paintRegion, QPainter& painter, const QRegion &clipRegion, 0121 const QPointF& coordinate, 0122 const QRect& cellRange, 0123 const Cell& cell, SheetView* sheetView) const; 0124 0125 /** 0126 * Paints the default cell borders. 0127 * \param painter the used painter 0128 * \param clipRegion the clip region 0129 * \param paintRegion the portion of the canvas that is actually in view 0130 * \param coordinate the painting coordinate 0131 * \param paintBorder the borders, that should be painted (should be removed???) 0132 * \param cellRange the cell range, that is painted 0133 * \param cell the Cell 0134 * \param sheetView the SheetView 0135 */ 0136 void paintDefaultBorders(QPainter& painter, const QRegion &clipRegion, const QRectF &paintRegion, 0137 const QPointF& coordinate, 0138 Borders paintBorder, const QRect& cellRange, 0139 const Cell& cell, SheetView* sheetView) const; 0140 0141 /** 0142 * \return width of the text 0143 */ 0144 qreal textWidth() const; 0145 0146 /** 0147 * \return height of the text 0148 */ 0149 qreal textHeight() const; 0150 0151 /** 0152 * \return the rectangle the text covers 0153 */ 0154 QRectF textRect() const; 0155 0156 QString testAnchor(SheetView* sheetView, const Cell& cell, qreal x, qreal y) const; 0157 0158 bool hitTestFilterButton(const Cell& cell, const QRect& cellRect, const QPoint& position) const; 0159 0160 qreal cellHeight() const; 0161 qreal cellWidth() const; 0162 0163 bool dimensionFits() const; 0164 0165 void detach(); 0166 protected: 0167 /** 0168 * \ingroup Layout 0169 * Calculates the layout of the cell. 0170 * 0171 * I.e. recalculates the text to be shown, its dimensions, its offset, 0172 * breaks lines of the text to fit it into the cell, obscures neighbouring 0173 * cells, if necessary. 0174 */ 0175 void makeLayout(SheetView* sheetView, const Cell& cell); 0176 0177 /** 0178 * \ingroup Layout 0179 * Determines the text offset relative to the cell's top left corner. 0180 * 0181 * This depends on the following variables: 0182 * \li horizontal alignment 0183 * \li vertical alignment 0184 * \li text angle 0185 * \li text direction (horizontal or vertical) 0186 * \li text width and height 0187 * \li single or multiple rows 0188 * \li cell width and height, including obscured cells 0189 * \li thickness of the border pens 0190 * 0191 * \internal Called from makeLayout(). 0192 */ 0193 void textOffset(const QFontMetricsF& fontMetrics, const Cell& cell); 0194 0195 /** 0196 * \ingroup Layout 0197 * Determines the dimension of this cell including any merged cells. 0198 * Does NOT consider space, which is available from empty neighbours, 0199 * and would be able to be obscured. 0200 * 0201 * \internal Called from makeLayout(). 0202 */ 0203 void calculateCellDimension(const Cell& cell); 0204 0205 /** 0206 * \ingroup Layout 0207 * Checks, whether horizontal neighbours could be obscured 0208 * and does so, if necessary. 0209 * 0210 * \internal Called from makeLayout(). 0211 */ 0212 void obscureHorizontalCells(SheetView* sheetView, const Cell& cell); 0213 0214 /** 0215 * \ingroup Layout 0216 * Checks, whether vertical neighbours could be obscured 0217 * and does so, if necessary. 0218 * 0219 * \internal Called from makeLayout(). 0220 */ 0221 void obscureVerticalCells(SheetView* sheetView, const Cell& cell); 0222 0223 /** 0224 * Adjust the output text, so that it only holds the part that can be 0225 * displayed. The altered text is only temporary stored. It is restored 0226 * after the paint event has been processed. 0227 * 0228 * This depends on the following variables: 0229 * \li horizontal alignment 0230 * \li value format 0231 * \li text direction (horizontal or vertical) 0232 * \li indentation 0233 * 0234 * \internal Called from paintText(). 0235 */ 0236 QString textDisplaying(const QFontMetricsF& fontMetrics, const Cell& cell); 0237 0238 /** 0239 * helper function for paintCell() function 0240 * @see paintCell() 0241 * @internal 0242 */ 0243 void paintCustomBorders(QPainter& painter, const QRectF &paintRegion, 0244 const QPointF& coordinate, Borders paintBorder, 0245 bool rtl) const; 0246 0247 /** 0248 * helper function for paintCell() function 0249 * @see paintCell() 0250 * @internal 0251 */ 0252 void paintPageBorders(QPainter& painter, const QPointF &coordinate, 0253 Borders paintBorder, const Cell& cell) const; 0254 0255 /** 0256 * helper function for paintCell() function 0257 * @see paintCell() 0258 * @internal 0259 */ 0260 void paintText(QPainter& painter, const QPointF& coordinate, const Cell& cell) const; 0261 0262 /** 0263 * helper function for paintCell() function 0264 * @see paintCell() 0265 * @internal 0266 */ 0267 void paintMoreTextIndicator(QPainter& painter, const QPointF& coordinate) const; 0268 0269 /** 0270 * helper function for paintCell() function 0271 * @see paintCell() 0272 * @internal 0273 */ 0274 void paintCommentIndicator(QPainter& painter, const QPointF& coordinate, 0275 const Cell& cell) const; 0276 0277 /** 0278 * helper function for paintCell() function 0279 * @see paintCell() 0280 * @internal 0281 */ 0282 void paintFormulaIndicator(QPainter& painter, const QPointF& coordinate, const Cell& cell) const; 0283 0284 /** 0285 * helper function for paintCell() function 0286 * @see paintCell() 0287 * @internal 0288 */ 0289 void paintMatrixElementIndicator(QPainter& painter, const QPointF& coordinate, const Cell& cell) const; 0290 0291 /** 0292 * helper function for paintCell() function 0293 * @see paintCell() 0294 * @internal 0295 */ 0296 void paintCellDiagonalLines(QPainter& painter, const QPointF& coordinate) const; 0297 0298 /** 0299 * helper function for paintCell() function 0300 * @see paintCell() 0301 * @internal 0302 */ 0303 void paintFilterButton(QPainter& painter, const QPointF& coordinate, 0304 const Cell& cell, SheetView* sheetView) const; 0305 0306 void drawText(QPainter& painter, const QPointF& location, const QStringList& textLines, 0307 const Cell& cell, qreal lineSpacing = 0) const; 0308 0309 /** 0310 * Default CellView used by SheetView. 0311 */ 0312 CellView(SheetView* sheetView); 0313 0314 class Private; 0315 QExplicitlySharedDataPointer<Private> d; 0316 }; 0317 0318 Q_DECLARE_OPERATORS_FOR_FLAGS(CellView::Borders) 0319 0320 } // namespace Sheets 0321 } // namespace Calligra 0322 0323 Q_DECLARE_TYPEINFO(Calligra::Sheets::CellView, Q_MOVABLE_TYPE); 0324 0325 #endif