Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kcolumnview_p.h
- This file was added.
| 1 | /**************************************************************************** | ||||
|---|---|---|---|---|---|
| 2 | ** | ||||
| 3 | ** Copyright (C) 2016 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 KCOLUMNVIEW_P_H | ||||
| 41 | #define KCOLUMNVIEW_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 "kcolumnview.h" | ||||
| 55 | | ||||
| 56 | #include <QtCore/qabstractitemmodel.h> | ||||
| 57 | #include <QtCore/qpropertyanimation.h> | ||||
| 58 | #include <QtWidgets/qabstractitemdelegate.h> | ||||
| 59 | #include <QtWidgets/qabstractitemview.h> | ||||
| 60 | #include <QtWidgets/qitemdelegate.h> | ||||
| 61 | #include <qlistview.h> | ||||
| 62 | #include <qevent.h> | ||||
| 63 | #include <qscrollbar.h> | ||||
| 64 | | ||||
| 65 | QT_REQUIRE_CONFIG(columnview); | ||||
| 66 | | ||||
| 67 | QT_BEGIN_NAMESPACE | ||||
| 68 | | ||||
| 69 | class KColumnViewPreviewColumn : public QAbstractItemView { | ||||
| 70 | | ||||
| 71 | public: | ||||
| 72 | explicit KColumnViewPreviewColumn(QWidget *parent) : QAbstractItemView(parent), previewWidget(0) { | ||||
| 73 | } | ||||
| 74 | | ||||
| 75 | void setPreviewWidget(QWidget *widget) { | ||||
| 76 | previewWidget = widget; | ||||
| 77 | setMinimumWidth(previewWidget->minimumWidth()); | ||||
| 78 | } | ||||
| 79 | | ||||
| 80 | void resizeEvent(QResizeEvent * event) Q_DECL_OVERRIDE{ | ||||
| 81 | if (!previewWidget) | ||||
| 82 | return; | ||||
| 83 | previewWidget->resize( | ||||
| 84 | qMax(previewWidget->minimumWidth(), event->size().width()), | ||||
| 85 | previewWidget->height()); | ||||
| 86 | QSize p = viewport()->size(); | ||||
| 87 | QSize v = previewWidget->size(); | ||||
| 88 | horizontalScrollBar()->setRange(0, v.width() - p.width()); | ||||
| 89 | horizontalScrollBar()->setPageStep(p.width()); | ||||
| 90 | verticalScrollBar()->setRange(0, v.height() - p.height()); | ||||
| 91 | verticalScrollBar()->setPageStep(p.height()); | ||||
| 92 | | ||||
| 93 | QAbstractScrollArea::resizeEvent(event); | ||||
| 94 | } | ||||
| 95 | | ||||
| 96 | void scrollContentsBy(int dx, int dy) Q_DECL_OVERRIDE | ||||
| 97 | { | ||||
| 98 | if (!previewWidget) | ||||
| 99 | return; | ||||
| 100 | scrollDirtyRegion(dx, dy); | ||||
| 101 | viewport()->scroll(dx, dy); | ||||
| 102 | | ||||
| 103 | QAbstractItemView::scrollContentsBy(dx, dy); | ||||
| 104 | } | ||||
| 105 | | ||||
| 106 | QRect visualRect(const QModelIndex &) const Q_DECL_OVERRIDE | ||||
| 107 | { | ||||
| 108 | return QRect(); | ||||
| 109 | } | ||||
| 110 | void scrollTo(const QModelIndex &, ScrollHint) Q_DECL_OVERRIDE | ||||
| 111 | { | ||||
| 112 | } | ||||
| 113 | QModelIndex indexAt(const QPoint &) const Q_DECL_OVERRIDE | ||||
| 114 | { | ||||
| 115 | return QModelIndex(); | ||||
| 116 | } | ||||
| 117 | QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) Q_DECL_OVERRIDE | ||||
| 118 | { | ||||
| 119 | return QModelIndex(); | ||||
| 120 | } | ||||
| 121 | int horizontalOffset () const Q_DECL_OVERRIDE { | ||||
| 122 | return 0; | ||||
| 123 | } | ||||
| 124 | int verticalOffset () const Q_DECL_OVERRIDE { | ||||
| 125 | return 0; | ||||
| 126 | } | ||||
| 127 | QRegion visualRegionForSelection(const QItemSelection &) const Q_DECL_OVERRIDE | ||||
| 128 | { | ||||
| 129 | return QRegion(); | ||||
| 130 | } | ||||
| 131 | bool isIndexHidden(const QModelIndex &) const Q_DECL_OVERRIDE | ||||
| 132 | { | ||||
| 133 | return false; | ||||
| 134 | } | ||||
| 135 | void setSelection(const QRect &, QItemSelectionModel::SelectionFlags) Q_DECL_OVERRIDE | ||||
| 136 | { | ||||
| 137 | } | ||||
| 138 | private: | ||||
| 139 | QWidget *previewWidget; | ||||
| 140 | }; | ||||
| 141 | | ||||
| 142 | class Q_AUTOTEST_EXPORT KColumnView::Private | ||||
| 143 | { | ||||
| 144 | public: | ||||
| 145 | Private(KColumnView *parent); | ||||
| 146 | ~Private(); | ||||
| 147 | void initialize(); | ||||
| 148 | | ||||
| 149 | QAbstractItemView *createColumn(const QModelIndex &index); | ||||
| 150 | | ||||
| 151 | void updateScrollbars(); | ||||
| 152 | void closeColumns(const QModelIndex &parent = QModelIndex(), bool build = false); | ||||
| 153 | void doLayout(); | ||||
| 154 | void setPreviewWidget(QWidget *widget); | ||||
| 155 | void checkColumnCreation(const QModelIndex &parent); | ||||
| 156 | | ||||
| 157 | | ||||
| 158 | void _q_gripMoved(int offset); | ||||
| 159 | void _q_changeCurrentColumn(); | ||||
| 160 | void _q_clicked(const QModelIndex &index); | ||||
| 161 | void _q_columnsInserted(const QModelIndex &parent, int start, int end); | ||||
| 162 | void _q_iconSizeChanged(QSize size); | ||||
| 163 | | ||||
| 164 | KColumnView * const q; | ||||
| 165 | | ||||
| 166 | QList<QAbstractItemView*> columns; | ||||
| 167 | QVector<int> columnSizes; // used during init and corner moving | ||||
| 168 | bool showResizeGrips; | ||||
| 169 | int offset; | ||||
| 170 | #ifndef QT_NO_ANIMATION | ||||
| 171 | QPropertyAnimation currentAnimation; | ||||
| 172 | #endif | ||||
| 173 | QWidget *previewWidget; | ||||
| 174 | QAbstractItemView *previewColumn; | ||||
| 175 | }; | ||||
| 176 | | ||||
| 177 | /*! | ||||
| 178 | * This is a delegate that will paint the triangle | ||||
| 179 | */ | ||||
| 180 | class KColumnViewDelegate : public QItemDelegate | ||||
| 181 | { | ||||
| 182 | | ||||
| 183 | public: | ||||
| 184 | explicit KColumnViewDelegate(QObject *parent = 0) : QItemDelegate(parent) {} | ||||
| 185 | ~KColumnViewDelegate() {} | ||||
| 186 | | ||||
| 187 | void paint(QPainter *painter, | ||||
| 188 | const QStyleOptionViewItem &option, | ||||
| 189 | const QModelIndex &index) const Q_DECL_OVERRIDE; | ||||
| 190 | }; | ||||
| 191 | | ||||
| 192 | QT_END_NAMESPACE | ||||
| 193 | | ||||
| 194 | #endif //KCOLUMNVIEW_P_H | ||||