Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qfileiconprovider.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 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
// Qt-Security score:significant reason:default
4
5
#
include
"qfileiconprovider.h"
6
#
include
"qfileiconprovider_p.h"
7
8
#
include
<
qapplication
.
h
>
9
#
include
<
qdir
.
h
>
10
#
include
<
qpixmapcache
.
h
>
11
#
include
<
private
/
qfunctions_p
.
h
>
12
#
include
<
private
/
qguiapplication_p
.
h
>
13
#
include
<
private
/
qicon_p
.
h
>
14
#
include
<
private
/
qfilesystementry_p
.
h
>
15
#
include
<
qpa
/
qplatformintegration
.
h
>
16
#
include
<
qpa
/
qplatformservices
.
h
>
17
#
include
<
qpa
/
qplatformtheme
.
h
>
18
19
#
if
defined
(
Q_OS_WIN
)
20
#
include
<
qt_windows
.
h
>
21
#
include
<
commctrl
.
h
>
22
#
include
<
objbase
.
h
>
23
#
endif
24
25
QT_BEGIN_NAMESPACE
26
27
/*!
28
\class QFileIconProvider
29
30
\inmodule QtWidgets
31
32
\brief The QFileIconProvider class provides file icons for the QFileSystemModel class.
33
*/
34
35
QFileIconProviderPrivate::QFileIconProviderPrivate(QFileIconProvider *q)
36
: QAbstractFileIconProviderPrivate(q), homePath(QDir::home().absolutePath())
37
{
38
}
39
40
QIcon
QFileIconProviderPrivate
::
getIcon
(QStyle::StandardPixmap name)
const
41
{
42
switch
(name) {
43
case
QStyle::SP_FileIcon:
44
if
(file.isNull())
45
file = QApplication::style()->standardIcon(name);
46
return
file;
47
case
QStyle::SP_FileLinkIcon:
48
if
(fileLink.isNull())
49
fileLink = QApplication::style()->standardIcon(name);
50
return
fileLink;
51
case
QStyle::SP_DirIcon:
52
if
(directory.isNull())
53
directory = QApplication::style()->standardIcon(name);
54
return
directory;
55
case
QStyle::SP_DirLinkIcon:
56
if
(directoryLink.isNull())
57
directoryLink = QApplication::style()->standardIcon(name);
58
return
directoryLink;
59
case
QStyle::SP_DriveHDIcon:
60
if
(harddisk.isNull())
61
harddisk = QApplication::style()->standardIcon(name);
62
return
harddisk;
63
case
QStyle::SP_DriveFDIcon:
64
if
(floppy.isNull())
65
floppy = QApplication::style()->standardIcon(name);
66
return
floppy;
67
case
QStyle::SP_DriveCDIcon:
68
if
(cdrom.isNull())
69
cdrom = QApplication::style()->standardIcon(name);
70
return
cdrom;
71
case
QStyle::SP_DriveNetIcon:
72
if
(network.isNull())
73
network = QApplication::style()->standardIcon(name);
74
return
network;
75
case
QStyle::SP_ComputerIcon:
76
if
(computer.isNull())
77
computer = QApplication::style()->standardIcon(name);
78
return
computer;
79
case
QStyle::SP_DesktopIcon:
80
if
(desktop.isNull())
81
desktop = QApplication::style()->standardIcon(name);
82
return
desktop;
83
case
QStyle::SP_TrashIcon:
84
if
(trashcan.isNull())
85
trashcan = QApplication::style()->standardIcon(name);
86
return
trashcan;
87
case
QStyle::SP_DirHomeIcon:
88
if
(home.isNull())
89
home = QApplication::style()->standardIcon(name);
90
return
home;
91
default
:
92
return
QIcon();
93
}
94
return
QIcon();
95
}
96
97
/*!
98
Constructs a file icon provider.
99
*/
100
101
QFileIconProvider::QFileIconProvider()
102
: QAbstractFileIconProvider(*
new
QFileIconProviderPrivate(
this
))
103
{
104
}
105
106
/*!
107
Destroys the file icon provider.
108
*/
109
110
QFileIconProvider::~QFileIconProvider() =
default
;
111
112
/*!
113
\reimp
114
*/
115
116
QIcon QFileIconProvider::icon(IconType type)
const
117
{
118
Q_D(
const
QFileIconProvider);
119
switch
(type) {
120
case
Computer:
121
return
d->getIcon(QStyle::SP_ComputerIcon);
122
case
Desktop:
123
return
d->getIcon(QStyle::SP_DesktopIcon);
124
case
Trashcan:
125
return
d->getIcon(QStyle::SP_TrashIcon);
126
case
Network:
127
return
d->getIcon(QStyle::SP_DriveNetIcon);
128
case
Drive:
129
return
d->getIcon(QStyle::SP_DriveHDIcon);
130
case
Folder:
131
return
d->getIcon(QStyle::SP_DirIcon);
132
case
File:
133
return
d->getIcon(QStyle::SP_FileIcon);
134
default
:
135
break
;
136
};
137
return
QIcon();
138
}
139
140
QIcon
QFileIconProviderPrivate
::
getIcon
(
const
QFileInfo &fi)
const
141
{
142
return
getPlatformThemeIcon(fi);
143
}
144
145
/*!
146
\reimp
147
*/
148
149
QIcon QFileIconProvider::icon(
const
QFileInfo &info)
const
150
{
151
Q_D(
const
QFileIconProvider);
152
153
QIcon retIcon = d->getIcon(info);
154
if
(!retIcon.isNull())
155
return
retIcon;
156
157
const
QString &path = info.absoluteFilePath();
158
if
(path.isEmpty() || QFileSystemEntry::isRootPath(path))
159
#
if
defined
(
Q_OS_WIN
)
160
{
161
UINT type = GetDriveType(
reinterpret_cast
<
const
wchar_t
*>(path.utf16()));
162
163
switch
(type) {
164
case
DRIVE_REMOVABLE:
165
return
d->getIcon(QStyle::SP_DriveFDIcon);
166
case
DRIVE_FIXED:
167
return
d->getIcon(QStyle::SP_DriveHDIcon);
168
case
DRIVE_REMOTE:
169
return
d->getIcon(QStyle::SP_DriveNetIcon);
170
case
DRIVE_CDROM:
171
return
d->getIcon(QStyle::SP_DriveCDIcon);
172
case
DRIVE_RAMDISK:
173
case
DRIVE_UNKNOWN:
174
case
DRIVE_NO_ROOT_DIR:
175
default
:
176
return
d->getIcon(QStyle::SP_DriveHDIcon);
177
}
178
}
179
#
else
180
return
d->getIcon(QStyle::SP_DriveHDIcon);
181
#
endif
182
183
if
(info.isFile()) {
184
if
(info.isSymLink())
185
return
d->getIcon(QStyle::SP_FileLinkIcon);
186
else
187
return
d->getIcon(QStyle::SP_FileIcon);
188
}
189
if
(info.isDir()) {
190
if
(info.isSymLink()) {
191
return
d->getIcon(QStyle::SP_DirLinkIcon);
192
}
else
{
193
if
(info.absoluteFilePath() == d->homePath) {
194
return
d->getIcon(QStyle::SP_DirHomeIcon);
195
}
else
{
196
return
d->getIcon(QStyle::SP_DirIcon);
197
}
198
}
199
}
200
return
QIcon();
201
}
202
203
QT_END_NAMESPACE
QFileIconProviderPrivate
Definition
qfileiconprovider_p.h:32
QFileIconProviderPrivate::getIcon
QIcon getIcon(QStyle::StandardPixmap name) const
Definition
qfileiconprovider.cpp:40
QFileIconProviderPrivate::getIcon
QIcon getIcon(const QFileInfo &fi) const
Definition
qfileiconprovider.cpp:140
qtbase
src
widgets
itemviews
qfileiconprovider.cpp
Generated on
for Qt by
1.18.0