File indexing completed on 2024-05-12 16:36:10

0001 /* This file is part of the KDE project
0002    Copyright 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef CALLIGRA_SHEETS_SHEET_VIEW
0021 #define CALLIGRA_SHEETS_SHEET_VIEW
0022 
0023 #include <QObject>
0024 #include <QPoint>
0025 #include <QPointF>
0026 #include <QRect>
0027 
0028 #include "sheets_common_export.h"
0029 
0030 class QPainter;
0031 class QRect;
0032 class QRectF;
0033 class QSize;
0034 class QSizeF;
0035 class QColor;
0036 
0037 class KoViewConverter;
0038 
0039 namespace Calligra
0040 {
0041 namespace Sheets
0042 {
0043 class CellView;
0044 class Region;
0045 class Sheet;
0046 class CanvasBase;
0047 
0048 /**
0049  * \ingroup Painting
0050  * The SheetView controls the painting of the sheets' cells.
0051  * It caches a set of CellViews.
0052  */
0053 class CALLIGRA_SHEETS_COMMON_EXPORT SheetView : public QObject
0054 {
0055     Q_OBJECT
0056 
0057     friend class CellView;
0058 
0059 public:
0060     /**
0061      * Constructor.
0062      */
0063     explicit SheetView(const Sheet* sheet);
0064 
0065     /**
0066      * Destructor.
0067      */
0068     ~SheetView() override;
0069 
0070     /**
0071      * \return the Sheet
0072      */
0073     const Sheet* sheet() const;
0074 
0075     /**
0076      * Sets the KoViewConverter used by this SheetView.
0077      */
0078     void setViewConverter(const KoViewConverter* viewConverter);
0079 
0080     /**
0081      * \return the view in which the Sheet is painted
0082      */
0083     const KoViewConverter* viewConverter() const;
0084 
0085     /**
0086      * Looks up a CellView for the position \p col , \p row in the cache.
0087      * If no CellView exists yet, one is created and inserted into the cache.
0088      *
0089      * \return the CellView for the position
0090      */
0091 #ifdef CALLIGRA_SHEETS_MT
0092     CellView cellView(int col, int row);
0093     CellView cellView(const QPoint& pos);
0094 #else
0095     const CellView& cellView(int col, int row);
0096     const CellView& cellView(const QPoint& pos);
0097 #endif
0098 
0099     /**
0100      * Set the cell range, that should be painted to \p rect .
0101      * It also adjusts the cache size linear to the size of \p rect .
0102      */
0103     void setPaintCellRange(const QRect& rect);
0104 
0105     /**
0106      * Invalidates all cached CellViews in \p region .
0107      */
0108     void invalidateRegion(const Region& region);
0109 
0110     /**
0111      * Invalidates all CellViews, the cached and the default.
0112      */
0113     virtual void invalidate();
0114 
0115     /**
0116      * Paints the cells.
0117      */
0118     virtual void paintCells(QPainter& painter, const QRectF& paintRect, const QPointF& topLeft, CanvasBase* canvas = 0, const QRect& visibleRect = QRect());
0119 
0120     QPoint obscuringCell(const QPoint& obscuredCell) const;
0121     QSize obscuredRange(const QPoint& obscuringCell) const;
0122     QRect obscuredArea(const QPoint& cell) const;
0123     bool isObscured(const QPoint& cell) const;
0124     bool obscuresCells(const QPoint& cell) const;
0125     QSize totalObscuredRange() const;
0126 
0127     /*
0128      * Highlighting cells.
0129      */
0130     bool isHighlighted(const QPoint& cell) const;
0131     void setHighlighted(const QPoint& cell, bool isHighlighted);
0132     bool hasHighlightedCells() const;
0133     void clearHighlightedCells();
0134     QPoint activeHighlight() const;
0135     void setActiveHighlight(const QPoint& cell);
0136 
0137     void setHighlightMaskColor(const QColor& color);
0138     void setHighlightColor(const QColor& color);
0139     void setActiveHighlightColor(const QColor& color);
0140 public Q_SLOTS:
0141     void updateAccessedCellRange(const QPoint& location = QPoint());
0142 
0143 Q_SIGNALS:
0144     void visibleSizeChanged(const QSizeF&);
0145     void obscuredRangeChanged(const QSize&);
0146 
0147 protected:
0148     virtual CellView* createDefaultCellView();
0149     virtual CellView* createCellView(int col, int row);
0150     QRect paintCellRange() const;
0151 protected:
0152     /**
0153      * Helper method for invalidateRegion().
0154      * Invalidates all cached CellViews in \p range .
0155      * \internal
0156      */
0157     virtual void invalidateRange(const QRect& range);
0158 
0159     /**
0160      * Marks other CellViews in \p range as obscured by the CellView at \p position .
0161      * Used by CellView.
0162      */
0163     void obscureCells(const QPoint& position, int numXCells, int numYCells);
0164 
0165     /**
0166      * Returns the default CellView.
0167      * Used by CellView.
0168      */
0169 #ifdef CALLIGRA_SHEETS_MT
0170     CellView defaultCellView() const;
0171 #else
0172     const CellView& defaultCellView() const;
0173 #endif
0174 
0175 private:
0176     Q_DISABLE_COPY(SheetView)
0177 
0178     class Private;
0179     Private * const d;
0180 };
0181 
0182 } // namespace Sheets
0183 } // namespace Calligra
0184 
0185 #endif // CALLIGRA_SHEETS_SHEET_VIEW