Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include "qfileiconprovider.h"
6
7#include <qapplication.h>
8#include <qdir.h>
9#include <qpixmapcache.h>
10#include <private/qfunctions_p.h>
11#include <private/qguiapplication_p.h>
12#include <private/qicon_p.h>
13#include <private/qfilesystementry_p.h>
14#include <qpa/qplatformintegration.h>
15#include <qpa/qplatformservices.h>
16#include <qpa/qplatformtheme.h>
17
18#if defined(Q_OS_WIN)
19# include <qt_windows.h>
20# include <commctrl.h>
21# include <objbase.h>
22#endif
23
25
38
40{
41 switch (name) {
43 if (file.isNull())
44 file = QApplication::style()->standardIcon(name);
45 return file;
47 if (fileLink.isNull())
48 fileLink = QApplication::style()->standardIcon(name);
49 return fileLink;
51 if (directory.isNull())
52 directory = QApplication::style()->standardIcon(name);
53 return directory;
55 if (directoryLink.isNull())
56 directoryLink = QApplication::style()->standardIcon(name);
57 return directoryLink;
59 if (harddisk.isNull())
60 harddisk = QApplication::style()->standardIcon(name);
61 return harddisk;
63 if (floppy.isNull())
64 floppy = QApplication::style()->standardIcon(name);
65 return floppy;
67 if (cdrom.isNull())
68 cdrom = QApplication::style()->standardIcon(name);
69 return cdrom;
71 if (network.isNull())
72 network = QApplication::style()->standardIcon(name);
73 return network;
75 if (computer.isNull())
76 computer = QApplication::style()->standardIcon(name);
77 return computer;
79 if (desktop.isNull())
80 desktop = QApplication::style()->standardIcon(name);
81 return desktop;
83 if (trashcan.isNull())
84 trashcan = QApplication::style()->standardIcon(name);
85 return trashcan;
87 if (home.isNull())
88 home = QApplication::style()->standardIcon(name);
89 return home;
90 default:
91 return QIcon();
92 }
93 return QIcon();
94}
95
104
110
116{
117 Q_D(const QFileIconProvider);
118 switch (type) {
119 case Computer:
120 return d->getIcon(QStyle::SP_ComputerIcon);
121 case Desktop:
122 return d->getIcon(QStyle::SP_DesktopIcon);
123 case Trashcan:
124 return d->getIcon(QStyle::SP_TrashIcon);
125 case Network:
126 return d->getIcon(QStyle::SP_DriveNetIcon);
127 case Drive:
128 return d->getIcon(QStyle::SP_DriveHDIcon);
129 case Folder:
130 return d->getIcon(QStyle::SP_DirIcon);
131 case File:
132 return d->getIcon(QStyle::SP_FileIcon);
133 default:
134 break;
135 };
136 return QIcon();
137}
138
143
149{
150 Q_D(const QFileIconProvider);
151
152 QIcon retIcon = d->getIcon(info);
153 if (!retIcon.isNull())
154 return retIcon;
155
156 const QString &path = info.absoluteFilePath();
157 if (path.isEmpty() || QFileSystemEntry::isRootPath(path))
158#if defined (Q_OS_WIN)
159 {
160 UINT type = GetDriveType(reinterpret_cast<const wchar_t *>(path.utf16()));
161
162 switch (type) {
163 case DRIVE_REMOVABLE:
164 return d->getIcon(QStyle::SP_DriveFDIcon);
165 case DRIVE_FIXED:
166 return d->getIcon(QStyle::SP_DriveHDIcon);
167 case DRIVE_REMOTE:
168 return d->getIcon(QStyle::SP_DriveNetIcon);
169 case DRIVE_CDROM:
170 return d->getIcon(QStyle::SP_DriveCDIcon);
171 case DRIVE_RAMDISK:
172 case DRIVE_UNKNOWN:
173 case DRIVE_NO_ROOT_DIR:
174 default:
175 return d->getIcon(QStyle::SP_DriveHDIcon);
176 }
177 }
178#else
179 return d->getIcon(QStyle::SP_DriveHDIcon);
180#endif
181
182 if (info.isFile()) {
183 if (info.isSymLink())
184 return d->getIcon(QStyle::SP_FileLinkIcon);
185 else
186 return d->getIcon(QStyle::SP_FileIcon);
187 }
188 if (info.isDir()) {
189 if (info.isSymLink()) {
190 return d->getIcon(QStyle::SP_DirLinkIcon);
191 } else {
192 if (info.absoluteFilePath() == d->homePath) {
193 return d->getIcon(QStyle::SP_DirHomeIcon);
194 } else {
195 return d->getIcon(QStyle::SP_DirIcon);
196 }
197 }
198 }
199 return QIcon();
200}
201
QIcon getPlatformThemeIcon(QAbstractFileIconProvider::IconType type) const
IconType
\value Computer The icon used for the computing device as a whole \value Desktop The icon for the spe...
static QStyle * style()
Returns the application's style object.
\inmodule QtCore
Definition qdir.h:20
QFileIconProviderPrivate(QFileIconProvider *q)
QIcon getIcon(QStyle::StandardPixmap name) const
\inmodule QtWidgets
~QFileIconProvider()
Destroys the file icon provider.
QFileIconProvider()
Constructs a file icon provider.
QIcon icon(IconType type) const override
\reimp
static Q_CORE_EXPORT bool isRootPath(const QString &path)
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition qicon.cpp:1019
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
StandardPixmap
This enum describes the available standard pixmaps.
Definition qstyle.h:716
@ SP_DirIcon
Definition qstyle.h:755
@ SP_FileIcon
Definition qstyle.h:742
@ SP_DirLinkIcon
Definition qstyle.h:740
@ SP_DriveNetIcon
Definition qstyle.h:737
@ SP_ComputerIcon
Definition qstyle.h:732
@ SP_DesktopIcon
Definition qstyle.h:730
@ SP_DriveCDIcon
Definition qstyle.h:735
@ SP_TrashIcon
Definition qstyle.h:731
@ SP_DirHomeIcon
Definition qstyle.h:773
@ SP_DriveHDIcon
Definition qstyle.h:734
@ SP_DriveFDIcon
Definition qstyle.h:733
@ SP_FileLinkIcon
Definition qstyle.h:743
#define this
Definition dialogs.cpp:9
Combined button and popup list for selecting options.
GLenum type
GLuint name
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLsizei const GLchar *const * path
static QString absolutePath(const QString &path)
QHostInfo info
[0]