Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickfiledialogdelegate.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtCore/qfileinfo.h>
7#include <QtGui/qpa/qplatformtheme.h>
8#include <QtQml/QQmlFile>
9#include <QtQml/qqmlexpression.h>
10#include <QtQuick/private/qquicklistview_p.h>
11#include <QtQuickTemplates2/private/qquickitemdelegate_p_p.h>
12
15
17
19{
20public:
21 Q_DECLARE_PUBLIC(QQuickFileDialogDelegate)
22
23 void highlightFile();
24 void chooseFile();
25
26 bool acceptKeyClick(Qt::Key key) const override;
27
28 QQuickDialog *dialog = nullptr;
32};
33
35{
37 QQuickListViewAttached *attached = static_cast<QQuickListViewAttached*>(
38 qmlAttachedPropertiesObject<QQuickListView>(q));
39 if (!attached)
40 return;
41
42 QQmlContext *delegateContext = qmlContext(q);
43 if (!delegateContext)
44 return;
45
46 bool converted = false;
47 const int index = q->property("index").toInt(&converted);
48 if (converted) {
49 attached->view()->setCurrentIndex(index);
50 if (fileDialog)
52 else if (folderDialog)
54 }
55}
56
58{
60 if (fileInfo.isDir()) {
61 // If it's a directory, navigate to it.
62 if (fileDialog)
64 else
66 } else {
68 // Otherwise it's a file, so select it and close the dialog.
71 }
72}
73
75{
76 return key == Qt::Key_Return || key == Qt::Key_Enter;
77}
78
81{
83 // Clicking and tabbing should result in it getting focus,
84 // as e.g. Ubuntu and Windows both allow tabbing through file dialogs.
86 setCheckable(true);
91}
92
94{
95 Q_D(const QQuickFileDialogDelegate);
96 return d->dialog;
97}
98
100{
102 if (dialog == d->dialog)
103 return;
104
105 d->dialog = dialog;
106 d->fileDialog = qobject_cast<QQuickFileDialogImpl*>(dialog);
107 d->folderDialog = qobject_cast<QQuickFolderDialogImpl*>(dialog);
109}
110
112{
113 Q_D(const QQuickFileDialogDelegate);
114 return d->file;
115}
116
118{
120 QUrl adjustedFile = file;
121#ifdef Q_OS_WIN32
122 // Work around QTBUG-99105 (FolderListModel uses lowercase drive letter).
123 QString path = adjustedFile.path();
124 const int driveColonIndex = path.indexOf(QLatin1Char(':'));
125 if (driveColonIndex == 2) {
126 path.replace(1, 1, path.at(1).toUpper());
127 adjustedFile.setPath(path);
128 }
129#endif
130 if (adjustedFile == d->file)
131 return;
132
133 d->file = adjustedFile;
135}
136
138{
140 // We need to respond to being triggered by enter being pressed,
141 // but we can't use event->isAccepted() to check, because events are pre-accepted.
144
146
148}
149
151
152#include "moc_qquickfiledialogdelegate_p.cpp"
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory.
The QKeyEvent class describes a key event.
Definition qevent.h:423
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:298
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
static QString urlToLocalFileOrQrc(const QString &)
If url is a local file returns a path suitable for passing to QFile.
Definition qqmlfile.cpp:643
void setCheckable(bool checkable)
void setFocusPolicy(Qt::FocusPolicy policy)
virtual void accept()
\qmlmethod void QtQuick.Controls::Dialog::accept()
bool acceptKeyClick(Qt::Key key) const override
void setDialog(QQuickDialog *dialog)
void keyReleaseEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key release events for an item.
QQuickFileDialogDelegate(QQuickItem *parent=nullptr)
void setSelectedFile(const QUrl &file)
void setCurrentFolder(const QUrl &currentFolder, SetReason setReason=SetReason::External)
void setSelectedFolder(const QUrl &selectedFolder)
void setCurrentFolder(const QUrl &folder)
void setCurrentIndex(int idx)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key release events for an item.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QString & replace(qsizetype i, qsizetype len, QChar after)
Definition qstring.cpp:3794
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4420
\inmodule QtCore
Definition qurl.h:94
void setPath(const QString &path, ParsingMode mode=DecodedMode)
Sets the path of the URL to path.
Definition qurl.cpp:2411
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
Definition qurl.cpp:2465
Combined button and popup list for selecting options.
@ StrongFocus
Definition qnamespace.h:109
@ Key_Return
Definition qnamespace.h:662
@ Key_Enter
Definition qnamespace.h:663
DBusConnection * connection
GLuint64 key
GLuint index
[2]
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLsizei const GLchar *const * path
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:71
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
QFile file
[0]
myObject disconnect()
[26]
QFileDialog dialog(this)
[1]
\inmodule QtCore \reentrant
Definition qchar.h:17
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent