File indexing completed on 2024-04-21 05:53:02
0001 /* 0002 This file is part of the Okteta Gui library, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2003, 2007-2009 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef OKTETA_ABSTRACTCOLUMNRENDERER_HPP 0010 #define OKTETA_ABSTRACTCOLUMNRENDERER_HPP 0011 0012 // lib 0013 #include "oktetagui_export.hpp" 0014 #include "pixelmetrics.hpp" 0015 // Qt 0016 #include <QtGlobal> 0017 // Std 0018 #include <memory> 0019 0020 class QPainter; 0021 0022 namespace Okteta { 0023 0024 class AbstractColumnStylist; 0025 0026 class AbstractColumnRendererPrivate; 0027 0028 /** base class for columns of the ColumnsView 0029 * 0030 * 0031 * @author Friedrich W. H. Kossebau 0032 */ 0033 0034 class OKTETAGUI_EXPORT AbstractColumnRenderer 0035 { 0036 // friend class ColumnsView; 0037 0038 protected: 0039 OKTETAGUI_NO_EXPORT explicit AbstractColumnRenderer(AbstractColumnRendererPrivate* d); 0040 0041 public: 0042 explicit AbstractColumnRenderer(AbstractColumnStylist* stylist); 0043 AbstractColumnRenderer(const AbstractColumnRenderer&) = delete; 0044 0045 virtual ~AbstractColumnRenderer(); 0046 0047 AbstractColumnRenderer& operator=(const AbstractColumnRenderer&) = delete; 0048 0049 public: // API to be reimplemented in the subclasses 0050 /** Before an update of the columns view each column that intersects with the area to be painted 0051 * will be called with this function. As often multiple lines of a column are affected 0052 * for each lines the same values (like first and last char positions) might be calculated. 0053 * This function enables a one-time-calculation for such data that must be stored in some 0054 * class members, though. 0055 * @param painter painter variable 0056 * @param xSpan 0057 * @param firstLineIndex no of the first of the range of lines to paint 0058 */ 0059 virtual void renderFirstLine(QPainter* painter, const PixelXRange& xSpan, int firstLineIndex); 0060 /** the actual painting call for a column's line. 0061 * The default implementation simply paints the background 0062 */ 0063 virtual void renderNextLine(QPainter* painter); 0064 0065 /** */ 0066 virtual void renderColumn(QPainter* painter, const PixelXRange& xSpan, const PixelYRange& ySpan); 0067 /** */ 0068 virtual void renderEmptyColumn(QPainter* painter, const PixelXRange& xSpan, const PixelYRange& ySpan); 0069 0070 public: // modification access 0071 /** sets starting point of the column */ 0072 void setX(PixelX x); 0073 /** sets visibily */ 0074 void setVisible(bool isVisible); 0075 /** buffer actual line height in column */ 0076 void setLineHeight(PixelY lineHeight); 0077 0078 public: // value access 0079 /** */ 0080 AbstractColumnStylist* stylist() const; 0081 /** left offset x in pixel */ 0082 PixelX x() const; 0083 /** total width in pixel */ 0084 PixelX width() const; 0085 /** right offset x in pixel */ 0086 PixelX rightX() const; 0087 /** should Column be displayed? */ 0088 bool isVisible() const; 0089 /** convenience: returns width if visible else 0 */ 0090 PixelX visibleWidth() const; 0091 /** */ 0092 PixelY lineHeight() const; 0093 0094 public: // functional logic 0095 /** true if column overlaps with pixels between x-positions x1, x2 */ 0096 bool overlaps(const PixelXRange& xSpan) const; 0097 0098 protected: 0099 /** sets width of the column */ 0100 void setWidth(PixelX width); 0101 /** */ 0102 void restrictToXSpan(PixelXRange* xSpan) const; 0103 /** */ 0104 void renderBlankLine(QPainter* painter) const; 0105 0106 protected: 0107 const std::unique_ptr<AbstractColumnRendererPrivate> d_ptr; 0108 0109 private: 0110 Q_DECLARE_PRIVATE(AbstractColumnRenderer) 0111 }; 0112 0113 } 0114 0115 #endif