1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2007 Kevin Ottens <ervin@kde.org>
4 SPDX-FileCopyrightText: 2022 Kai Uwe Broulik <kde@broulik.de>
5
6 SPDX-License-Identifier: LGPL-2.0-only
7*/
8
9#ifndef KFILEPLACESVIEW_H
10#define KFILEPLACESVIEW_H
11
12#include "kiofilewidgets_export.h"
13
14#include <QListView>
15#include <QUrl>
16
17#include <functional>
18#include <memory>
19
20class QResizeEvent;
21class QContextMenuEvent;
22
23class KFilePlacesViewPrivate;
24
25/*!
26 * \class KFilePlacesView
27 *
28 * \inmodule KIOFileWidgets
29 *
30 * \brief This class allows to display a KFilePlacesModel.
31 */
32class KIOFILEWIDGETS_EXPORT KFilePlacesView : public QListView
33{
34 Q_OBJECT
35public:
36 /*!
37 *
38 */
39 explicit KFilePlacesView(QWidget *parent = nullptr);
40 ~KFilePlacesView() override;
41
42 /*!
43 * The teardown function signature. Custom teardown logic
44 * may be provided via the setTeardownFunction method.
45 * \since 5.91
46 */
47 using TeardownFunction = std::function<void(const QModelIndex &)>;
48
49 /*!
50 * Returns whether hidden places, if any, are currently shown.
51 * \since 5.91
52 */
53 bool allPlacesShown() const;
54
55 /*!
56 * If \a enabled is true, it is allowed dropping items
57 * above a place for e. g. copy or move operations. The application
58 * has to take care itself to perform the operation
59 * (see KFilePlacesView::urlsDropped()). If
60 * \a enabled is false, it is only possible adding items
61 * as additional place. Per default dropping on a place is
62 * disabled.
63 */
64 void setDropOnPlaceEnabled(bool enabled);
65
66 /*!
67 *
68 */
69 bool isDropOnPlaceEnabled() const;
70
71 /*!
72 * If \a delay (in ms) is greater than zero, the place will
73 * automatically be activated if an item is dragged over
74 * and held on top of a place for at least that duraton.
75 *
76 * \a delay Delay in ms, default is zero.
77 * \since 5.92
78 */
79 void setDragAutoActivationDelay(int delay);
80
81 /*!
82 *
83 */
84 int dragAutoActivationDelay() const;
85
86 /*!
87 * If \a enabled is true (the default), items will automatically resize
88 * themselves to fill the view.
89 *
90 */
91 void setAutoResizeItemsEnabled(bool enabled);
92
93 /*!
94 *
95 */
96 bool isAutoResizeItemsEnabled() const;
97
98 /*!
99 * Sets a custom function that will be called when teardown of
100 * a device (e.g.\ unmounting a drive) is requested.
101 * \since 5.91
102 */
103 void setTeardownFunction(TeardownFunction teardownFunc);
104
105 QSize sizeHint() const override; // clazy:exclude=const-signal-or-slot
106
107public Q_SLOTS:
108 /*!
109 *
110 */
111 void setUrl(const QUrl &url);
112
113 /*!
114 *
115 */
116 void setShowAll(bool showAll);
117
118 void setModel(QAbstractItemModel *model) override;
119
120protected:
121 void keyPressEvent(QKeyEvent *event) override;
122 void contextMenuEvent(QContextMenuEvent *event) override;
123 void resizeEvent(QResizeEvent *event) override;
124 void showEvent(QShowEvent *event) override;
125 void hideEvent(QHideEvent *event) override;
126 void dragEnterEvent(QDragEnterEvent *event) override;
127 void dragLeaveEvent(QDragLeaveEvent *event) override;
128 void dragMoveEvent(QDragMoveEvent *event) override;
129 void dropEvent(QDropEvent *event) override;
130 void paintEvent(QPaintEvent *event) override;
131 void startDrag(Qt::DropActions supportedActions) override;
132 void mousePressEvent(QMouseEvent *event) override;
133
134protected Q_SLOTS:
135 void rowsInserted(const QModelIndex &parent, int start, int end) override;
136 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) override;
137
138Q_SIGNALS:
139 /*!
140 * Emitted when an item in the places view is clicked on with left mouse
141 * button with no modifier keys pressed.
142 *
143 * If a storage device needs to be mounted first, this signal is emitted once
144 * mounting has completed successfully.
145 *
146 * \a url The URL of the place
147 * \since 5.91
148 */
149 void placeActivated(const QUrl &url);
150
151 /*!
152 * Emitted when the URL \a url should be opened in a new inactive tab because
153 * the user clicked on a place with the middle mouse button or
154 * left-clicked with the Ctrl modifier pressed or selected "Open in New Tab"
155 * from the context menu.
156 *
157 * If a storage device needs to be mounted first, this signal is emitted once
158 * mounting has completed successfully.
159 * \since 5.91
160 */
161 void tabRequested(const QUrl &url);
162
163 /*!
164 * Emitted when the URL \a url should be opened in a new active tab because
165 * the user clicked on a place with the middle mouse button with
166 * the Shift modifier pressed or left-clicked with both the Ctrl and Shift
167 * modifiers pressed.
168
169 * If a storage device needs to be mounted first, this signal is emitted once
170 * mounting has completed successfully.
171 * \since 5.91
172 */
173 void activeTabRequested(const QUrl &url);
174
175 /*!
176 * Emitted when the URL \a url should be opened in a new window because
177 * the user left-clicked on a place with Shift modifier pressed or selected
178 * "Open in New Window" from the context menu.
179 *
180 * If a storage device needs to be mounted first, this signal is emitted once
181 * mounting has completed successfully.
182 * \since 5.91
183 */
184 void newWindowRequested(const QUrl &url);
185
186 /*!
187 * Emitted just before the context menu opens. This can be used to add additional
188 * application actions to the menu.
189 *
190 * \a index The model index of the place whose menu is about to open.
191 *
192 * \a menu The menu that will be opened.
193 * \since 5.91
194 */
195 void contextMenuAboutToShow(const QModelIndex &index, QMenu *menu);
196
197 /*!
198 * Emitted when allPlacesShown changes
199 * \since 5.91
200 */
201 void allPlacesShownChanged(bool allPlacesShown);
202
203 void urlChanged(const QUrl &url);
204
205 /*!
206 * Is emitted if items are dropped on the place \a dest.
207 *
208 * The application has to take care itself about performing the
209 * corresponding action like copying or moving.
210 */
211 void urlsDropped(const QUrl &dest, QDropEvent *event, QWidget *parent);
212
213private:
214 friend class KFilePlacesViewPrivate;
215 friend class KFilePlacesEventWatcher;
216 std::unique_ptr<KFilePlacesViewPrivate> const d;
217};
218
219#endif
220

source code of kio/src/filewidgets/kfileplacesview.h