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 | |
34 | #include <vector> |
35 | |
36 | QT_REQUIRE_CONFIG(columnview); |
37 | |
38 | QT_BEGIN_NAMESPACE |
39 | |
40 | class QColumnViewPreviewColumn : public QAbstractItemView { |
41 | |
42 | public: |
43 | explicit QColumnViewPreviewColumn(QWidget *parent) : QAbstractItemView(parent), previewWidget(nullptr) { |
44 | } |
45 | |
46 | void setPreviewWidget(QWidget *widget) { |
47 | previewWidget = widget; |
48 | setMinimumWidth(previewWidget->minimumWidth()); |
49 | } |
50 | |
51 | void resizeEvent(QResizeEvent * event) override{ |
52 | if (!previewWidget) |
53 | return; |
54 | previewWidget->resize( |
55 | w: qMax(a: previewWidget->minimumWidth(), b: event->size().width()), |
56 | h: previewWidget->height()); |
57 | QSize p = viewport()->size(); |
58 | QSize v = previewWidget->size(); |
59 | horizontalScrollBar()->setRange(min: 0, max: v.width() - p.width()); |
60 | horizontalScrollBar()->setPageStep(p.width()); |
61 | verticalScrollBar()->setRange(min: 0, max: v.height() - p.height()); |
62 | verticalScrollBar()->setPageStep(p.height()); |
63 | |
64 | QAbstractScrollArea::resizeEvent(event); |
65 | } |
66 | |
67 | void scrollContentsBy(int dx, int dy) override |
68 | { |
69 | if (!previewWidget) |
70 | return; |
71 | scrollDirtyRegion(dx, dy); |
72 | viewport()->scroll(dx, dy); |
73 | |
74 | QAbstractItemView::scrollContentsBy(dx, dy); |
75 | } |
76 | |
77 | QRect visualRect(const QModelIndex &) const override |
78 | { |
79 | return QRect(); |
80 | } |
81 | void scrollTo(const QModelIndex &, ScrollHint) override |
82 | { |
83 | } |
84 | QModelIndex indexAt(const QPoint &) const override |
85 | { |
86 | return QModelIndex(); |
87 | } |
88 | QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override |
89 | { |
90 | return QModelIndex(); |
91 | } |
92 | int horizontalOffset () const override { |
93 | return 0; |
94 | } |
95 | int verticalOffset () const override { |
96 | return 0; |
97 | } |
98 | QRegion visualRegionForSelection(const QItemSelection &) const override |
99 | { |
100 | return QRegion(); |
101 | } |
102 | bool isIndexHidden(const QModelIndex &) const override |
103 | { |
104 | return false; |
105 | } |
106 | void setSelection(const QRect &, QItemSelectionModel::SelectionFlags) override |
107 | { |
108 | } |
109 | private: |
110 | QWidget *previewWidget; |
111 | }; |
112 | |
113 | class Q_AUTOTEST_EXPORT QColumnViewPrivate : public QAbstractItemViewPrivate |
114 | { |
115 | Q_DECLARE_PUBLIC(QColumnView) |
116 | |
117 | public: |
118 | QColumnViewPrivate(); |
119 | ~QColumnViewPrivate(); |
120 | void initialize(); |
121 | void clearConnections(); |
122 | |
123 | QAbstractItemView *createColumn(const QModelIndex &index, bool show); |
124 | |
125 | void updateScrollbars(); |
126 | void closeColumns(const QModelIndex &parent = QModelIndex(), bool build = false); |
127 | void disconnectView(QAbstractItemView *view); |
128 | void doLayout(); |
129 | void setPreviewWidget(QWidget *widget); |
130 | void checkColumnCreation(const QModelIndex &parent); |
131 | |
132 | |
133 | void gripMoved(int offset); |
134 | void changeCurrentColumn(); |
135 | void clicked(const QModelIndex &index); |
136 | void columnsInserted(const QModelIndex &parent, int start, int end) override; |
137 | |
138 | QList<QAbstractItemView*> columns; |
139 | QList<int> columnSizes; // used during init and corner moving |
140 | bool showResizeGrips; |
141 | int offset; |
142 | #if QT_CONFIG(animation) |
143 | QPropertyAnimation currentAnimation; |
144 | QMetaObject::Connection animationConnection; |
145 | #endif |
146 | std::vector<QMetaObject::Connection> gripConnections; |
147 | using ViewConnections = std::vector<QMetaObject::Connection>; |
148 | QHash<QAbstractItemView *, ViewConnections> viewConnections; |
149 | |
150 | QWidget *previewWidget; |
151 | QAbstractItemView *previewColumn; |
152 | }; |
153 | |
154 | /*! |
155 | * This is a delegate that will paint the triangle |
156 | */ |
157 | class QColumnViewDelegate : public QStyledItemDelegate |
158 | { |
159 | |
160 | public: |
161 | explicit QColumnViewDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {} |
162 | ~QColumnViewDelegate() {} |
163 | |
164 | void paint(QPainter *painter, |
165 | const QStyleOptionViewItem &option, |
166 | const QModelIndex &index) const override; |
167 | }; |
168 | |
169 | QT_END_NAMESPACE |
170 | |
171 | #endif //QCOLUMNVIEW_P_H |
172 | |