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 QSIDEBAR_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 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
61QT_REQUIRE_CONFIG(filedialog);
62
63QT_BEGIN_NAMESPACE
64
65class QFileSystemModel;
66
67class QSideBarDelegate : public QStyledItemDelegate
68{
69 public:
70 QSideBarDelegate(QWidget *parent = nullptr) : QStyledItemDelegate(parent) {}
71 void initStyleOption(QStyleOptionViewItem *option,
72 const QModelIndex &index) const override;
73};
74
75class Q_AUTOTEST_EXPORT QUrlModel : public QStandardItemModel
76{
77 Q_OBJECT
78
79public:
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
102private Q_SLOTS:
103 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
104 void layoutChanged();
105
106private:
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};
120Q_DECLARE_TYPEINFO(QUrlModel::WatchItem, Q_MOVABLE_TYPE);
121
122class Q_AUTOTEST_EXPORT QSidebar : public QListView
123{
124 Q_OBJECT
125
126Q_SIGNALS:
127 void goToUrl(const QUrl &url);
128
129public:
130 QSidebar(QWidget *parent = nullptr);
131 void setModelAndUrls(QFileSystemModel *model, const QList<QUrl> &newUrls);
132 ~QSidebar();
133
134 QSize sizeHint() const override;
135
136 void setUrls(const QList<QUrl> &list) { urlModel->setUrls(list); }
137 void addUrls(const QList<QUrl> &list, int row) { urlModel->addUrls(urls: list, row); }
138 QList<QUrl> urls() const { return urlModel->urls(); }
139
140 void selectUrl(const QUrl &url);
141
142protected:
143 bool event(QEvent * e) override;
144 void focusInEvent(QFocusEvent *event) override;
145#if QT_CONFIG(draganddrop)
146 void dragEnterEvent(QDragEnterEvent *event) override;
147#endif
148
149private Q_SLOTS:
150 void clicked(const QModelIndex &index);
151#if QT_CONFIG(menu)
152 void showContextMenu(const QPoint &position);
153#endif
154 void removeEntry();
155
156private:
157 QUrlModel *urlModel;
158};
159
160QT_END_NAMESPACE
161
162#endif // QSIDEBAR_H
163
164

source code of qtbase/src/widgets/dialogs/qsidebar_p.h