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_COLUMNSVIEW_HPP 0010 #define OKTETA_COLUMNSVIEW_HPP 0011 0012 // lib 0013 #include "oktetagui_export.hpp" 0014 #include "pixelmetrics.hpp" 0015 #include "linerange.hpp" 0016 // Qt 0017 #include <QAbstractScrollArea> 0018 // Std 0019 #include <memory> 0020 0021 namespace Okteta { 0022 0023 class AbstractColumnRenderer; 0024 class ColumnsViewPrivate; 0025 0026 /** general class for widgets with columns that display different aspects of the same data 0027 * with the same lineheight for all lines 0028 * 0029 * @author Friedrich W. H. Kossebau 0030 */ 0031 0032 class OKTETAGUI_EXPORT ColumnsView : public QAbstractScrollArea 0033 { 0034 Q_OBJECT 0035 0036 protected: 0037 OKTETAGUI_NO_EXPORT explicit ColumnsView(ColumnsViewPrivate* d, QWidget* parent = nullptr); 0038 0039 public: 0040 explicit ColumnsView(/*bool R = false,*/ QWidget* parent = nullptr); 0041 ~ColumnsView() override; 0042 0043 public: // data-wise sizes 0044 /** returns the number of all lines */ 0045 LineSize noOfLines() const; 0046 /** returns number of fully visible lines, at least 1 (as needed by page down/up) 0047 * doesn't care about the total height being smaller than the display height 0048 */ 0049 LineSize noOfLinesPerPage() const; 0050 0051 public: // pixel-wise sizes 0052 /** returns the height of each line */ 0053 PixelY lineHeight() const; 0054 /** returns the width of all visible columns together */ 0055 PixelX columnsWidth() const; 0056 /** returns the height of all lines together */ 0057 PixelY columnsHeight() const; 0058 0059 public: // services 0060 /** gives the index of the line that would include y in pixel coord. 0061 * y is not forced to be inside the total height. 0062 */ 0063 Line lineAt(PixelY y) const; 0064 /** gives the index of the first and the last line that would be visible 0065 * these lines might not contain anything 0066 */ 0067 LineRange visibleLines() const; 0068 /** gives the index of the first and the last line that would be visible in the given pixel range 0069 * these lines might not contain anything 0070 */ 0071 LineRange visibleLines(const PixelYRange& yPixels) const; 0072 0073 /** @return visible width of the current view */ 0074 PixelX visibleWidth() const; 0075 /** @return visible height of the current view */ 0076 PixelY visibleHeight() const; 0077 /** @return x offset of the current view */ 0078 PixelX xOffset() const; 0079 /** @return y offset of the current view */ 0080 PixelY yOffset() const; 0081 0082 /** @return y offset of the current view */ 0083 PixelY yOffsetOfLine(Line lineIndex) const; 0084 0085 /** translates the point to coordinates in the columns */ 0086 QPoint viewportToColumns(QPoint point) const; 0087 0088 public: 0089 /** */ 0090 void setColumnsPos(PixelX x, PixelY y); 0091 0092 protected: // QAbstractScrollArea API 0093 bool event(QEvent* event) override; 0094 void resizeEvent(QResizeEvent* event) override; 0095 void paintEvent(QPaintEvent* paintEvent) override; 0096 void scrollContentsBy(int dx, int dy) override; 0097 0098 protected: // our API 0099 /** draws all columns in columns coordinates */ 0100 virtual void renderColumns(QPainter* painter, int cx, int cy, int cw, int ch); 0101 /** draws area without columns in columns coordinates */ 0102 virtual void renderEmptyArea(QPainter* painter, int cx, int cy, int cw, int ch); 0103 0104 protected: 0105 /** sets height of all lines and propagates this information to all columns 0106 * doesn't update the content size 0107 * @param lineHeight height in pixels 0108 */ 0109 virtual void setLineHeight(PixelY lineHeight); 0110 /** sets the number of lines 0111 * doesn't update the content size 0112 * @param noOfLines new number of lines to display 0113 */ 0114 virtual void setNoOfLines(LineSize noOfLines); 0115 0116 protected: 0117 void addColumn(AbstractColumnRenderer* columnRenderer); 0118 void removeColumn(AbstractColumnRenderer* columnRenderer); 0119 0120 protected: // recalculations 0121 /** recalculates the positions of the columns and the total width */ 0122 void updateWidths(); 0123 void updateScrollBars(); 0124 /** calls updateContent for the Column */ 0125 void updateColumn(AbstractColumnRenderer& columnRenderer); 0126 /** calls updateContent for the Column for the given lines, if needed */ 0127 void updateColumn(AbstractColumnRenderer& columnRenderer, const LineRange& lines); 0128 0129 protected: 0130 const std::unique_ptr<ColumnsViewPrivate> d_ptr; 0131 0132 private: 0133 Q_DECLARE_PRIVATE(ColumnsView) 0134 }; 0135 0136 } 0137 0138 #endif