1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QSIDEBAR_H
|
---|
43 | #define QSIDEBAR_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include <qlistwidget.h>
|
---|
57 | #include <qstandarditemmodel.h>
|
---|
58 | #include <qstyleditemdelegate.h>
|
---|
59 | #include <qurl.h>
|
---|
60 |
|
---|
61 | #ifndef QT_NO_FILEDIALOG
|
---|
62 |
|
---|
63 | QT_BEGIN_NAMESPACE
|
---|
64 |
|
---|
65 | class QFileSystemModel;
|
---|
66 |
|
---|
67 | class QSideBarDelegate : public QStyledItemDelegate
|
---|
68 | {
|
---|
69 | public:
|
---|
70 | QSideBarDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {}
|
---|
71 | void initStyleOption(QStyleOptionViewItem *option,
|
---|
72 | const QModelIndex &index) const;
|
---|
73 | QSize sizeHint (const QStyleOptionViewItem &option,
|
---|
74 | const QModelIndex &index) const;
|
---|
75 | };
|
---|
76 |
|
---|
77 | class Q_AUTOTEST_EXPORT QUrlModel : public QStandardItemModel
|
---|
78 | {
|
---|
79 | Q_OBJECT
|
---|
80 |
|
---|
81 | public:
|
---|
82 | enum Roles {
|
---|
83 | UrlRole = Qt::UserRole + 1,
|
---|
84 | EnabledRole = Qt::UserRole + 2
|
---|
85 | };
|
---|
86 |
|
---|
87 | QUrlModel(QObject *parent = 0);
|
---|
88 |
|
---|
89 | QStringList mimeTypes() const;
|
---|
90 | QMimeData *mimeData(const QModelIndexList &indexes) const;
|
---|
91 | #ifndef QT_NO_DRAGANDDROP
|
---|
92 | bool canDrop(QDragEnterEvent *event);
|
---|
93 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
---|
94 | #endif
|
---|
95 | Qt::ItemFlags flags(const QModelIndex &index) const;
|
---|
96 | bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole);
|
---|
97 |
|
---|
98 | void setUrls(const QList<QUrl> &list);
|
---|
99 | void addUrls(const QList<QUrl> &urls, int row = -1, bool move = true);
|
---|
100 | QList<QUrl> urls() const;
|
---|
101 | void setFileSystemModel(QFileSystemModel *model);
|
---|
102 | bool showFullPath;
|
---|
103 |
|
---|
104 | private Q_SLOTS:
|
---|
105 | void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
---|
106 | void layoutChanged();
|
---|
107 |
|
---|
108 | private:
|
---|
109 | void setUrl(const QModelIndex &index, const QUrl &url, const QModelIndex &dirIndex);
|
---|
110 | void changed(const QString &path);
|
---|
111 | void addIndexToWatch(const QString &path, const QModelIndex &index);
|
---|
112 | QFileSystemModel *fileSystemModel;
|
---|
113 | QList<QPair<QModelIndex, QString> > watching;
|
---|
114 | QList<QUrl> invalidUrls;
|
---|
115 | };
|
---|
116 |
|
---|
117 | class Q_AUTOTEST_EXPORT QSidebar : public QListView
|
---|
118 | {
|
---|
119 | Q_OBJECT
|
---|
120 |
|
---|
121 | Q_SIGNALS:
|
---|
122 | void goToUrl(const QUrl &url);
|
---|
123 |
|
---|
124 | public:
|
---|
125 | QSidebar(QWidget *parent = 0);
|
---|
126 | void init(QFileSystemModel *model, const QList<QUrl> &newUrls);
|
---|
127 | ~QSidebar();
|
---|
128 |
|
---|
129 | QSize sizeHint() const;
|
---|
130 |
|
---|
131 | void setUrls(const QList<QUrl> &list) { urlModel->setUrls(list); }
|
---|
132 | void addUrls(const QList<QUrl> &list, int row) { urlModel->addUrls(list, row); }
|
---|
133 | QList<QUrl> urls() const { return urlModel->urls(); }
|
---|
134 |
|
---|
135 | void selectUrl(const QUrl &url);
|
---|
136 |
|
---|
137 | protected:
|
---|
138 | bool event(QEvent * e);
|
---|
139 | void focusInEvent(QFocusEvent *event);
|
---|
140 | #ifndef QT_NO_DRAGANDDROP
|
---|
141 | void dragEnterEvent(QDragEnterEvent *event);
|
---|
142 | #endif
|
---|
143 |
|
---|
144 | private Q_SLOTS:
|
---|
145 | void clicked(const QModelIndex &index);
|
---|
146 | #ifndef QT_NO_MENU
|
---|
147 | void showContextMenu(const QPoint &position);
|
---|
148 | #endif
|
---|
149 | void removeEntry();
|
---|
150 |
|
---|
151 | private:
|
---|
152 | QUrlModel *urlModel;
|
---|
153 | };
|
---|
154 |
|
---|
155 | QT_END_NAMESPACE
|
---|
156 |
|
---|
157 | #endif // QT_NO_FILEDIALOG
|
---|
158 |
|
---|
159 | #endif // QSIDEBAR_H
|
---|
160 |
|
---|