| 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 QSIDEBAR_H |
| 41 | #define |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists purely as an |
| 48 | // implementation detail. 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 <qlistview.h> |
| 56 | #include <qstandarditemmodel.h> |
| 57 | #include <qstyleditemdelegate.h> |
| 58 | #include <qurl.h> |
| 59 | #include <qvector.h> |
| 60 | |
| 61 | QT_REQUIRE_CONFIG(filedialog); |
| 62 | |
| 63 | QT_BEGIN_NAMESPACE |
| 64 | |
| 65 | class QFileSystemModel; |
| 66 | |
| 67 | class : public QStyledItemDelegate |
| 68 | { |
| 69 | public: |
| 70 | (QWidget *parent = nullptr) : QStyledItemDelegate(parent) {} |
| 71 | void (QStyleOptionViewItem *option, |
| 72 | const QModelIndex &index) const override; |
| 73 | }; |
| 74 | |
| 75 | class Q_AUTOTEST_EXPORT QUrlModel : public QStandardItemModel |
| 76 | { |
| 77 | Q_OBJECT |
| 78 | |
| 79 | public: |
| 80 | enum Roles { |
| 81 | UrlRole = Qt::UserRole + 1, |
| 82 | EnabledRole = Qt::UserRole + 2 |
| 83 | }; |
| 84 | |
| 85 | QUrlModel(QObject *parent = nullptr); |
| 86 | |
| 87 | QStringList mimeTypes() const override; |
| 88 | QMimeData *mimeData(const QModelIndexList &indexes) const override; |
| 89 | #if QT_CONFIG(draganddrop) |
| 90 | bool canDrop(QDragEnterEvent *event); |
| 91 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; |
| 92 | #endif |
| 93 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
| 94 | bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override; |
| 95 | |
| 96 | void setUrls(const QList<QUrl> &list); |
| 97 | void addUrls(const QList<QUrl> &urls, int row = -1, bool move = true); |
| 98 | QList<QUrl> urls() const; |
| 99 | void setFileSystemModel(QFileSystemModel *model); |
| 100 | bool showFullPath; |
| 101 | |
| 102 | private Q_SLOTS: |
| 103 | void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); |
| 104 | void layoutChanged(); |
| 105 | |
| 106 | private: |
| 107 | void setUrl(const QModelIndex &index, const QUrl &url, const QModelIndex &dirIndex); |
| 108 | void changed(const QString &path); |
| 109 | void addIndexToWatch(const QString &path, const QModelIndex &index); |
| 110 | QFileSystemModel *fileSystemModel; |
| 111 | struct WatchItem { |
| 112 | QModelIndex index; |
| 113 | QString path; |
| 114 | }; |
| 115 | friend class QTypeInfo<WatchItem>; |
| 116 | |
| 117 | QVector<WatchItem> watching; |
| 118 | QList<QUrl> invalidUrls; |
| 119 | }; |
| 120 | Q_DECLARE_TYPEINFO(QUrlModel::WatchItem, Q_MOVABLE_TYPE); |
| 121 | |
| 122 | class Q_AUTOTEST_EXPORT : public QListView |
| 123 | { |
| 124 | Q_OBJECT |
| 125 | |
| 126 | Q_SIGNALS: |
| 127 | void (const QUrl &url); |
| 128 | |
| 129 | public: |
| 130 | (QWidget *parent = nullptr); |
| 131 | void setModelAndUrls(QFileSystemModel *model, const QList<QUrl> &newUrls); |
| 132 | (); |
| 133 | |
| 134 | QSize () const override; |
| 135 | |
| 136 | void (const QList<QUrl> &list) { urlModel->setUrls(list); } |
| 137 | void (const QList<QUrl> &list, int row) { urlModel->addUrls(urls: list, row); } |
| 138 | QList<QUrl> () const { return urlModel->urls(); } |
| 139 | |
| 140 | void (const QUrl &url); |
| 141 | |
| 142 | protected: |
| 143 | bool (QEvent * e) override; |
| 144 | void (QFocusEvent *event) override; |
| 145 | #if QT_CONFIG(draganddrop) |
| 146 | void (QDragEnterEvent *event) override; |
| 147 | #endif |
| 148 | |
| 149 | private Q_SLOTS: |
| 150 | void (const QModelIndex &index); |
| 151 | #if QT_CONFIG(menu) |
| 152 | void (const QPoint &position); |
| 153 | #endif |
| 154 | void (); |
| 155 | |
| 156 | private: |
| 157 | QUrlModel *; |
| 158 | }; |
| 159 | |
| 160 | QT_END_NAMESPACE |
| 161 | |
| 162 | #endif // QSIDEBAR_H |
| 163 | |
| 164 | |