KIO

kfileplacesview.h
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;
22
23class KFilePlacesViewPrivate;
24
25/**
26 * @class KFilePlacesView kfileplacesview.h <KFilePlacesView>
27 *
28 * This class allows to display a KFilePlacesModel.
29 */
30class KIOFILEWIDGETS_EXPORT KFilePlacesView : public QListView
31{
32 Q_OBJECT
33public:
34 explicit KFilePlacesView(QWidget *parent = nullptr);
35 ~KFilePlacesView() override;
36
37 /**
38 * The teardown function signature. Custom teardown logic
39 * may be provided via the setTeardownFunction method.
40 * @since 5.91
41 */
42 using TeardownFunction = std::function<void(const QModelIndex &)>;
43
44 /**
45 * Whether hidden places, if any, are currently shown.
46 * @since 5.91
47 */
48 bool allPlacesShown() const;
49
50 /**
51 * If \a enabled is true, it is allowed dropping items
52 * above a place for e. g. copy or move operations. The application
53 * has to take care itself to perform the operation
54 * (see KFilePlacesView::urlsDropped()). If
55 * \a enabled is false, it is only possible adding items
56 * as additional place. Per default dropping on a place is
57 * disabled.
58 */
59 void setDropOnPlaceEnabled(bool enabled);
60 bool isDropOnPlaceEnabled() const;
61
62 /**
63 * If \a delay (in ms) is greater than zero, the place will
64 * automatically be activated if an item is dragged over
65 * and held on top of a place for at least that duraton.
66 *
67 * @param delay Delay in ms, default is zero.
68 * @since 5.92
69 */
70 void setDragAutoActivationDelay(int delay);
71 int dragAutoActivationDelay() const;
72
73 /**
74 * If \a enabled is true (the default), items will automatically resize
75 * themselves to fill the view.
76 *
77 */
78 void setAutoResizeItemsEnabled(bool enabled);
79 bool isAutoResizeItemsEnabled() const;
80
81 /**
82 * Sets a custom function that will be called when teardown of
83 * a device (e.g.\ unmounting a drive) is requested.
84 * @since 5.91
85 */
86 void setTeardownFunction(TeardownFunction teardownFunc);
87
88 QSize sizeHint() const override; // clazy:exclude=const-signal-or-slot
89
90public Q_SLOTS:
91 void setUrl(const QUrl &url);
92 void setShowAll(bool showAll);
93
94 void setModel(QAbstractItemModel *model) override;
95
96protected:
97 void keyPressEvent(QKeyEvent *event) override;
98 void contextMenuEvent(QContextMenuEvent *event) override;
99 void resizeEvent(QResizeEvent *event) override;
100 void showEvent(QShowEvent *event) override;
101 void hideEvent(QHideEvent *event) override;
102 void dragEnterEvent(QDragEnterEvent *event) override;
103 void dragLeaveEvent(QDragLeaveEvent *event) override;
104 void dragMoveEvent(QDragMoveEvent *event) override;
105 void dropEvent(QDropEvent *event) override;
106 void paintEvent(QPaintEvent *event) override;
107 void startDrag(Qt::DropActions supportedActions) override;
108 void mousePressEvent(QMouseEvent *event) override;
109
110protected Q_SLOTS:
111 void rowsInserted(const QModelIndex &parent, int start, int end) override;
112 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) override;
113
115 /**
116 * Emitted when an item in the places view is clicked on with left mouse
117 * button with no modifier keys pressed.
118 *
119 * If a storage device needs to be mounted first, this signal is emitted once
120 * mounting has completed successfully.
121 *
122 * @param url The URL of the place
123 * @since 5.91
124 */
125 void placeActivated(const QUrl &url);
126
127 /**
128 * Emitted when the URL \a url should be opened in a new inactive tab because
129 * the user clicked on a place with the middle mouse button or
130 * left-clicked with the Ctrl modifier pressed or selected "Open in New Tab"
131 * from the context menu.
132 *
133 * If a storage device needs to be mounted first, this signal is emitted once
134 * mounting has completed successfully.
135 * @since 5.91
136 */
137 void tabRequested(const QUrl &url);
138
139 /**
140 * Emitted when the URL \a url should be opened in a new active tab because
141 * the user clicked on a place with the middle mouse button with
142 * the Shift modifier pressed or left-clicked with both the Ctrl and Shift
143 * modifiers pressed.
144
145 * If a storage device needs to be mounted first, this signal is emitted once
146 * mounting has completed successfully.
147 * @since 5.91
148 */
149 void activeTabRequested(const QUrl &url);
150
151 /**
152 * Emitted when the URL \a url should be opened in a new window because
153 * the user left-clicked on a place with Shift modifier pressed or selected
154 * "Open in New Window" from the context menu.
155 *
156 * If a storage device needs to be mounted first, this signal is emitted once
157 * mounting has completed successfully.
158 * @since 5.91
159 */
160 void newWindowRequested(const QUrl &url);
161
162 /**
163 * Emitted just before the context menu opens. This can be used to add additional
164 * application actions to the menu.
165 * @param index The model index of the place whose menu is about to open.
166 * @param menu The menu that will be opened.
167 * @since 5.91
168 */
169 void contextMenuAboutToShow(const QModelIndex &index, QMenu *menu);
170
171 /**
172 * Emitted when allPlacesShown changes
173 * @since 5.91
174 */
175 void allPlacesShownChanged(bool allPlacesShown);
176
177 void urlChanged(const QUrl &url);
178
179 /**
180 * Is emitted if items are dropped on the place \a dest.
181 * The application has to take care itself about performing the
182 * corresponding action like copying or moving.
183 */
184 void urlsDropped(const QUrl &dest, QDropEvent *event, QWidget *parent);
185
186private:
187 friend class KFilePlacesViewPrivate;
188 friend class KFilePlacesEventWatcher;
189 std::unique_ptr<KFilePlacesViewPrivate> const d;
190};
191
192#endif
This class allows to display a KFilePlacesModel.
void allPlacesShownChanged(bool allPlacesShown)
Emitted when allPlacesShown changes.
void activeTabRequested(const QUrl &url)
Emitted when the URL url should be opened in a new active tab because the user clicked on a place wit...
void urlsDropped(const QUrl &dest, QDropEvent *event, QWidget *parent)
Is emitted if items are dropped on the place dest.
std::function< void(const QModelIndex &)> TeardownFunction
The teardown function signature.
void contextMenuAboutToShow(const QModelIndex &index, QMenu *menu)
Emitted just before the context menu opens.
void newWindowRequested(const QUrl &url)
Emitted when the URL url should be opened in a new window because the user left-clicked on a place wi...
void placeActivated(const QUrl &url)
Emitted when an item in the places view is clicked on with left mouse button with no modifier keys pr...
void tabRequested(const QUrl &url)
Emitted when the URL url should be opened in a new inactive tab because the user clicked on a place w...
Q_SCRIPTABLE Q_NOREPLY void start()
virtual void dragEnterEvent(QDragEnterEvent *event) override
virtual void keyPressEvent(QKeyEvent *event) override
virtual void mousePressEvent(QMouseEvent *event) override
virtual void setModel(QAbstractItemModel *model)
virtual void contextMenuEvent(QContextMenuEvent *e) override
virtual QSize sizeHint() const const override
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles) override
virtual void dragLeaveEvent(QDragLeaveEvent *e) override
virtual void dragMoveEvent(QDragMoveEvent *e) override
virtual void dropEvent(QDropEvent *event) override
virtual void paintEvent(QPaintEvent *e) override
virtual void resizeEvent(QResizeEvent *e) override
virtual void rowsInserted(const QModelIndex &parent, int start, int end) override
virtual void startDrag(Qt::DropActions supportedActions) override
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
typedef DropActions
virtual void hideEvent(QHideEvent *event)
virtual void showEvent(QShowEvent *event)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:52 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.