| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2020 The Qt Company Ltd. | 
|---|
| 4 | ** Contact: https://www.qt.io/licensing/ | 
|---|
| 5 | ** | 
|---|
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | 
|---|
| 7 | ** | 
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 9 | ** Commercial License Usage | 
|---|
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
|---|
| 11 | ** accordance with the commercial license agreement provided with the | 
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
|---|
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
|---|
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
|---|
| 16 | ** | 
|---|
| 17 | ** GNU Lesser General Public License Usage | 
|---|
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 19 | ** General Public License version 3 as published by the Free Software | 
|---|
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
|---|
| 21 | ** packaging of this file. Please review the following information to | 
|---|
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
|---|
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
|---|
| 24 | ** | 
|---|
| 25 | ** GNU General Public License Usage | 
|---|
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | 
|---|
| 28 | ** Public license version 3 or any later version approved by the KDE Free | 
|---|
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | 
|---|
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
|---|
| 31 | ** included in the packaging of this file. Please review the following | 
|---|
| 32 | ** information to ensure the GNU General Public License requirements will | 
|---|
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
|---|
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** $QT_END_LICENSE$ | 
|---|
| 37 | ** | 
|---|
| 38 | ****************************************************************************/ | 
|---|
| 39 |  | 
|---|
| 40 | #ifndef QCOLUMNVIEW_P_H | 
|---|
| 41 | #define QCOLUMNVIEW_P_H | 
|---|
| 42 |  | 
|---|
| 43 | // | 
|---|
| 44 | //  W A R N I N G | 
|---|
| 45 | //  ------------- | 
|---|
| 46 | // | 
|---|
| 47 | // This file is not part of the Qt API.  It exists for the convenience | 
|---|
| 48 | // of other Qt classes.  This header file may change from version to | 
|---|
| 49 | // version without notice, or even be removed. | 
|---|
| 50 | // | 
|---|
| 51 | // We mean it. | 
|---|
| 52 | // | 
|---|
| 53 |  | 
|---|
| 54 | #include <QtWidgets/private/qtwidgetsglobal_p.h> | 
|---|
| 55 | #include "qcolumnview.h" | 
|---|
| 56 |  | 
|---|
| 57 | #include <private/qabstractitemview_p.h> | 
|---|
| 58 |  | 
|---|
| 59 | #include <QtCore/qabstractitemmodel.h> | 
|---|
| 60 | #if QT_CONFIG(animation) | 
|---|
| 61 | #include <QtCore/qpropertyanimation.h> | 
|---|
| 62 | #endif | 
|---|
| 63 | #include <QtWidgets/qabstractitemdelegate.h> | 
|---|
| 64 | #include <QtWidgets/qabstractitemview.h> | 
|---|
| 65 | #include <QtWidgets/qstyleditemdelegate.h> | 
|---|
| 66 | #include <qlistview.h> | 
|---|
| 67 | #include <qevent.h> | 
|---|
| 68 | #include <qscrollbar.h> | 
|---|
| 69 |  | 
|---|
| 70 | QT_REQUIRE_CONFIG(columnview); | 
|---|
| 71 |  | 
|---|
| 72 | QT_BEGIN_NAMESPACE | 
|---|
| 73 |  | 
|---|
| 74 | class QColumnViewPreviewColumn : public QAbstractItemView { | 
|---|
| 75 |  | 
|---|
| 76 | public: | 
|---|
| 77 | explicit QColumnViewPreviewColumn(QWidget *parent) : QAbstractItemView(parent), previewWidget(nullptr) { | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | void setPreviewWidget(QWidget *widget) { | 
|---|
| 81 | previewWidget = widget; | 
|---|
| 82 | setMinimumWidth(previewWidget->minimumWidth()); | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | void resizeEvent(QResizeEvent * event) override{ | 
|---|
| 86 | if (!previewWidget) | 
|---|
| 87 | return; | 
|---|
| 88 | previewWidget->resize( | 
|---|
| 89 | qMax(previewWidget->minimumWidth(), event->size().width()), | 
|---|
| 90 | previewWidget->height()); | 
|---|
| 91 | QSize p = viewport()->size(); | 
|---|
| 92 | QSize v = previewWidget->size(); | 
|---|
| 93 | horizontalScrollBar()->setRange(0, v.width() - p.width()); | 
|---|
| 94 | horizontalScrollBar()->setPageStep(p.width()); | 
|---|
| 95 | verticalScrollBar()->setRange(0, v.height() - p.height()); | 
|---|
| 96 | verticalScrollBar()->setPageStep(p.height()); | 
|---|
| 97 |  | 
|---|
| 98 | QAbstractScrollArea::resizeEvent(event); | 
|---|
| 99 | } | 
|---|
| 100 |  | 
|---|
| 101 | void scrollContentsBy(int dx, int dy) override | 
|---|
| 102 | { | 
|---|
| 103 | if (!previewWidget) | 
|---|
| 104 | return; | 
|---|
| 105 | scrollDirtyRegion(dx, dy); | 
|---|
| 106 | viewport()->scroll(dx, dy); | 
|---|
| 107 |  | 
|---|
| 108 | QAbstractItemView::scrollContentsBy(dx, dy); | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|
| 111 | QRect visualRect(const QModelIndex &) const override | 
|---|
| 112 | { | 
|---|
| 113 | return QRect(); | 
|---|
| 114 | } | 
|---|
| 115 | void scrollTo(const QModelIndex &, ScrollHint) override | 
|---|
| 116 | { | 
|---|
| 117 | } | 
|---|
| 118 | QModelIndex indexAt(const QPoint &) const override | 
|---|
| 119 | { | 
|---|
| 120 | return QModelIndex(); | 
|---|
| 121 | } | 
|---|
| 122 | QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override | 
|---|
| 123 | { | 
|---|
| 124 | return QModelIndex(); | 
|---|
| 125 | } | 
|---|
| 126 | int horizontalOffset () const override { | 
|---|
| 127 | return 0; | 
|---|
| 128 | } | 
|---|
| 129 | int verticalOffset () const override { | 
|---|
| 130 | return 0; | 
|---|
| 131 | } | 
|---|
| 132 | QRegion visualRegionForSelection(const QItemSelection &) const override | 
|---|
| 133 | { | 
|---|
| 134 | return QRegion(); | 
|---|
| 135 | } | 
|---|
| 136 | bool isIndexHidden(const QModelIndex &) const override | 
|---|
| 137 | { | 
|---|
| 138 | return false; | 
|---|
| 139 | } | 
|---|
| 140 | void setSelection(const QRect &, QItemSelectionModel::SelectionFlags) override | 
|---|
| 141 | { | 
|---|
| 142 | } | 
|---|
| 143 | private: | 
|---|
| 144 | QWidget *previewWidget; | 
|---|
| 145 | }; | 
|---|
| 146 |  | 
|---|
| 147 | class Q_AUTOTEST_EXPORT QColumnViewPrivate : public QAbstractItemViewPrivate | 
|---|
| 148 | { | 
|---|
| 149 | Q_DECLARE_PUBLIC(QColumnView) | 
|---|
| 150 |  | 
|---|
| 151 | public: | 
|---|
| 152 | QColumnViewPrivate(); | 
|---|
| 153 | ~QColumnViewPrivate(); | 
|---|
| 154 | void initialize(); | 
|---|
| 155 |  | 
|---|
| 156 | QAbstractItemView *createColumn(const QModelIndex &index, bool show); | 
|---|
| 157 |  | 
|---|
| 158 | void updateScrollbars(); | 
|---|
| 159 | void closeColumns(const QModelIndex &parent = QModelIndex(), bool build = false); | 
|---|
| 160 | void doLayout(); | 
|---|
| 161 | void setPreviewWidget(QWidget *widget); | 
|---|
| 162 | void checkColumnCreation(const QModelIndex &parent); | 
|---|
| 163 |  | 
|---|
| 164 |  | 
|---|
| 165 | void _q_gripMoved(int offset); | 
|---|
| 166 | void _q_changeCurrentColumn(); | 
|---|
| 167 | void _q_clicked(const QModelIndex &index); | 
|---|
| 168 | void _q_columnsInserted(const QModelIndex &parent, int start, int end) override; | 
|---|
| 169 |  | 
|---|
| 170 | QList<QAbstractItemView*> columns; | 
|---|
| 171 | QList<int> columnSizes; // used during init and corner moving | 
|---|
| 172 | bool showResizeGrips; | 
|---|
| 173 | int offset; | 
|---|
| 174 | #if QT_CONFIG(animation) | 
|---|
| 175 | QPropertyAnimation currentAnimation; | 
|---|
| 176 | #endif | 
|---|
| 177 | QWidget *previewWidget; | 
|---|
| 178 | QAbstractItemView *previewColumn; | 
|---|
| 179 | }; | 
|---|
| 180 |  | 
|---|
| 181 | /*! | 
|---|
| 182 | * This is a delegate that will paint the triangle | 
|---|
| 183 | */ | 
|---|
| 184 | class QColumnViewDelegate : public QStyledItemDelegate | 
|---|
| 185 | { | 
|---|
| 186 |  | 
|---|
| 187 | public: | 
|---|
| 188 | explicit QColumnViewDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {} | 
|---|
| 189 | ~QColumnViewDelegate() {} | 
|---|
| 190 |  | 
|---|
| 191 | void paint(QPainter *painter, | 
|---|
| 192 | const QStyleOptionViewItem &option, | 
|---|
| 193 | const QModelIndex &index) const override; | 
|---|
| 194 | }; | 
|---|
| 195 |  | 
|---|
| 196 | QT_END_NAMESPACE | 
|---|
| 197 |  | 
|---|
| 198 | #endif //QCOLUMNVIEW_P_H | 
|---|
| 199 |  | 
|---|