1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCOLUMNVIEW_P_H
5#define QCOLUMNVIEW_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include "qcolumnview.h"
20
21#include <private/qabstractitemview_p.h>
22
23#include <QtCore/qabstractitemmodel.h>
24#if QT_CONFIG(animation)
25#include <QtCore/qpropertyanimation.h>
26#endif
27#include <QtWidgets/qabstractitemdelegate.h>
28#include <QtWidgets/qabstractitemview.h>
29#include <QtWidgets/qstyleditemdelegate.h>
30#include <qlistview.h>
31#include <qevent.h>
32#include <qscrollbar.h>
33
34QT_REQUIRE_CONFIG(columnview);
35
36QT_BEGIN_NAMESPACE
37
38class QColumnViewPreviewColumn : public QAbstractItemView {
39
40public:
41 explicit QColumnViewPreviewColumn(QWidget *parent) : QAbstractItemView(parent), previewWidget(nullptr) {
42 }
43
44 void setPreviewWidget(QWidget *widget) {
45 previewWidget = widget;
46 setMinimumWidth(previewWidget->minimumWidth());
47 }
48
49 void resizeEvent(QResizeEvent * event) override{
50 if (!previewWidget)
51 return;
52 previewWidget->resize(
53 w: qMax(a: previewWidget->minimumWidth(), b: event->size().width()),
54 h: previewWidget->height());
55 QSize p = viewport()->size();
56 QSize v = previewWidget->size();
57 horizontalScrollBar()->setRange(min: 0, max: v.width() - p.width());
58 horizontalScrollBar()->setPageStep(p.width());
59 verticalScrollBar()->setRange(min: 0, max: v.height() - p.height());
60 verticalScrollBar()->setPageStep(p.height());
61
62 QAbstractScrollArea::resizeEvent(event);
63 }
64
65 void scrollContentsBy(int dx, int dy) override
66 {
67 if (!previewWidget)
68 return;
69 scrollDirtyRegion(dx, dy);
70 viewport()->scroll(dx, dy);
71
72 QAbstractItemView::scrollContentsBy(dx, dy);
73 }
74
75 QRect visualRect(const QModelIndex &) const override
76 {
77 return QRect();
78 }
79 void scrollTo(const QModelIndex &, ScrollHint) override
80 {
81 }
82 QModelIndex indexAt(const QPoint &) const override
83 {
84 return QModelIndex();
85 }
86 QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override
87 {
88 return QModelIndex();
89 }
90 int horizontalOffset () const override {
91 return 0;
92 }
93 int verticalOffset () const override {
94 return 0;
95 }
96 QRegion visualRegionForSelection(const QItemSelection &) const override
97 {
98 return QRegion();
99 }
100 bool isIndexHidden(const QModelIndex &) const override
101 {
102 return false;
103 }
104 void setSelection(const QRect &, QItemSelectionModel::SelectionFlags) override
105 {
106 }
107private:
108 QWidget *previewWidget;
109};
110
111class Q_AUTOTEST_EXPORT QColumnViewPrivate : public QAbstractItemViewPrivate
112{
113 Q_DECLARE_PUBLIC(QColumnView)
114
115public:
116 QColumnViewPrivate();
117 ~QColumnViewPrivate();
118 void initialize();
119
120 QAbstractItemView *createColumn(const QModelIndex &index, bool show);
121
122 void updateScrollbars();
123 void closeColumns(const QModelIndex &parent = QModelIndex(), bool build = false);
124 void doLayout();
125 void setPreviewWidget(QWidget *widget);
126 void checkColumnCreation(const QModelIndex &parent);
127
128
129 void _q_gripMoved(int offset);
130 void _q_changeCurrentColumn();
131 void _q_clicked(const QModelIndex &index);
132 void _q_columnsInserted(const QModelIndex &parent, int start, int end) override;
133
134 QList<QAbstractItemView*> columns;
135 QList<int> columnSizes; // used during init and corner moving
136 bool showResizeGrips;
137 int offset;
138#if QT_CONFIG(animation)
139 QPropertyAnimation currentAnimation;
140#endif
141 QWidget *previewWidget;
142 QAbstractItemView *previewColumn;
143};
144
145/*!
146 * This is a delegate that will paint the triangle
147 */
148class QColumnViewDelegate : public QStyledItemDelegate
149{
150
151public:
152 explicit QColumnViewDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {}
153 ~QColumnViewDelegate() {}
154
155 void paint(QPainter *painter,
156 const QStyleOptionViewItem &option,
157 const QModelIndex &index) const override;
158};
159
160QT_END_NAMESPACE
161
162#endif //QCOLUMNVIEW_P_H
163

source code of qtbase/src/widgets/itemviews/qcolumnview_p.h