File indexing completed on 2024-04-28 17:07:10

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