qfileiconprovider.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qfileiconprovider.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4static bool isCacheable(const QFileInfo &fi);-
5-
6class QFileIconEngine : public QPixmapIconEngine-
7{-
8public:-
9 QFileIconEngine(const QFileInfo &info, QFileIconProvider::Options opts)-
10 : QPixmapIconEngine(), m_fileInfo(info), m_fipOpts(opts)-
11 { }
never executed: end of block
0
12-
13 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override-
14 {-
15 (void)mode;;-
16 (void)state;;-
17 QPixmap pixmap;-
18-
19 if (!size.isValid()
!size.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
20 return
never executed: return pixmap;
pixmap;
never executed: return pixmap;
0
21-
22 const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme();-
23 if (!theme
!themeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
24 return
never executed: return pixmap;
pixmap;
never executed: return pixmap;
0
25-
26 const QString &keyBase = QLatin1String("qt_.") + m_fileInfo.suffix().toUpper();-
27-
28 bool cacheable = isCacheable(m_fileInfo);-
29 if (cacheable
cacheableDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
30 QPixmapCache::find(keyBase + QString::number(size.width()), pixmap);-
31 if (!pixmap.isNull()
!pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
32 return
never executed: return pixmap;
pixmap;
never executed: return pixmap;
0
33 }
never executed: end of block
0
34-
35 QPlatformTheme::IconOptions iconOptions;-
36 if (m_fipOpts & QFileIconProvider::DontUseCustomDirectoryIcons
m_fipOpts & QF...DirectoryIconsDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
37 iconOptions |= QPlatformTheme::DontUseCustomDirectoryIcons;
never executed: iconOptions |= QPlatformTheme::DontUseCustomDirectoryIcons;
0
38-
39 pixmap = theme->fileIconPixmap(m_fileInfo, size, iconOptions);-
40 if (!pixmap.isNull()
!pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
41 if (cacheable
cacheableDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
42 QPixmapCache::insert(keyBase + QString::number(size.width()), pixmap);
never executed: QPixmapCache::insert(keyBase + QString::number(size.width()), pixmap);
0
43 }
never executed: end of block
0
44-
45 return
never executed: return pixmap;
pixmap;
never executed: return pixmap;
0
46 }-
47-
48 QList<QSize> availableSizes(QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::Off) const override-
49 {-
50 (void)mode;;-
51 (void)state;;-
52 static QList<QSize> sizes;-
53 static QPlatformTheme *theme = 0;-
54 if (!theme
!themeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
55 theme = QGuiApplicationPrivate::platformTheme();-
56 if (!theme
!themeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
57 return
never executed: return sizes;
sizes;
never executed: return sizes;
0
58-
59 QList<int> themeSizes = theme->themeHint(QPlatformTheme::IconPixmapSizes).value<QList<int> >();-
60 if (themeSizes.isEmpty()
themeSizes.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
61 return
never executed: return sizes;
sizes;
never executed: return sizes;
0
62-
63 sizes.reserve(themeSizes.count());-
64 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(themeSizes)>::type> _container_((themeSizes)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (int size = *_container_.i; _container_.control; _container_.control = 0)-
65 sizes << QSize(size, size);
never executed: sizes << QSize(size, size);
0
66 }
never executed: end of block
0
67 return
never executed: return sizes;
sizes;
never executed: return sizes;
0
68 }-
69-
70 QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override-
71 {-
72 const QList<QSize> &sizes = availableSizes(mode, state);-
73 const int numberSizes = sizes.length();-
74 if (numberSizes == 0
numberSizes == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
75 return
never executed: return QSize();
QSize();
never executed: return QSize();
0
76-
77-
78-
79-
80 const int sizeArea = size.width() * size.height();-
81 QSize actualSize = sizes.first();-
82 int actualArea = actualSize.width() * actualSize.height();-
83 for (int i = 1; i < numberSizes
i < numberSizesDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
84 const QSize &s = sizes.at(i);-
85 const int a = s.width() * s.height();-
86 if ((sizeArea <= a
sizeArea <= aDescription
TRUEnever evaluated
FALSEnever evaluated
&& a < actualArea
a < actualAreaDescription
TRUEnever evaluated
FALSEnever evaluated
) || (actualArea < sizeArea
actualArea < sizeAreaDescription
TRUEnever evaluated
FALSEnever evaluated
&& actualArea < a
actualArea < aDescription
TRUEnever evaluated
FALSEnever evaluated
)) {
0
87 actualSize = s;-
88 actualArea = a;-
89 }
never executed: end of block
0
90 }
never executed: end of block
0
91-
92 if (!actualSize.isNull()
!actualSize.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
&& (actualSize.width() > size.width()
actualSize.wid...> size.width()Description
TRUEnever evaluated
FALSEnever evaluated
|| actualSize.height() > size.height()
actualSize.hei... size.height()Description
TRUEnever evaluated
FALSEnever evaluated
))
0
93 actualSize.scale(size, Qt::KeepAspectRatio);
never executed: actualSize.scale(size, Qt::KeepAspectRatio);
0
94-
95 return
never executed: return actualSize;
actualSize;
never executed: return actualSize;
0
96 }-
97-
98private:-
99 QFileInfo m_fileInfo;-
100 QFileIconProvider::Options m_fipOpts;-
101};-
102QFileIconProviderPrivate::QFileIconProviderPrivate(QFileIconProvider *q) :-
103 q_ptr(q), homePath(QDir::home().absolutePath())-
104{-
105}
never executed: end of block
0
106-
107QIcon QFileIconProviderPrivate::getIcon(QStyle::StandardPixmap name) const-
108{-
109 switch (name) {-
110 case
never executed: case QStyle::SP_FileIcon:
QStyle::SP_FileIcon:
never executed: case QStyle::SP_FileIcon:
0
111 if (file.isNull()
file.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
112 file = QApplication::style()->standardIcon(name);
never executed: file = QApplication::style()->standardIcon(name);
0
113 return
never executed: return file;
file;
never executed: return file;
0
114 case
never executed: case QStyle::SP_FileLinkIcon:
QStyle::SP_FileLinkIcon:
never executed: case QStyle::SP_FileLinkIcon:
0
115 if (fileLink.isNull()
fileLink.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
116 fileLink = QApplication::style()->standardIcon(name);
never executed: fileLink = QApplication::style()->standardIcon(name);
0
117 return
never executed: return fileLink;
fileLink;
never executed: return fileLink;
0
118 case
never executed: case QStyle::SP_DirIcon:
QStyle::SP_DirIcon:
never executed: case QStyle::SP_DirIcon:
0
119 if (directory.isNull()
directory.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
120 directory = QApplication::style()->standardIcon(name);
never executed: directory = QApplication::style()->standardIcon(name);
0
121 return
never executed: return directory;
directory;
never executed: return directory;
0
122 case
never executed: case QStyle::SP_DirLinkIcon:
QStyle::SP_DirLinkIcon:
never executed: case QStyle::SP_DirLinkIcon:
0
123 if (directoryLink.isNull()
directoryLink.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
124 directoryLink = QApplication::style()->standardIcon(name);
never executed: directoryLink = QApplication::style()->standardIcon(name);
0
125 return
never executed: return directoryLink;
directoryLink;
never executed: return directoryLink;
0
126 case
never executed: case QStyle::SP_DriveHDIcon:
QStyle::SP_DriveHDIcon:
never executed: case QStyle::SP_DriveHDIcon:
0
127 if (harddisk.isNull()
harddisk.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
128 harddisk = QApplication::style()->standardIcon(name);
never executed: harddisk = QApplication::style()->standardIcon(name);
0
129 return
never executed: return harddisk;
harddisk;
never executed: return harddisk;
0
130 case
never executed: case QStyle::SP_DriveFDIcon:
QStyle::SP_DriveFDIcon:
never executed: case QStyle::SP_DriveFDIcon:
0
131 if (floppy.isNull()
floppy.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
132 floppy = QApplication::style()->standardIcon(name);
never executed: floppy = QApplication::style()->standardIcon(name);
0
133 return
never executed: return floppy;
floppy;
never executed: return floppy;
0
134 case
never executed: case QStyle::SP_DriveCDIcon:
QStyle::SP_DriveCDIcon:
never executed: case QStyle::SP_DriveCDIcon:
0
135 if (cdrom.isNull()
cdrom.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
136 cdrom = QApplication::style()->standardIcon(name);
never executed: cdrom = QApplication::style()->standardIcon(name);
0
137 return
never executed: return cdrom;
cdrom;
never executed: return cdrom;
0
138 case
never executed: case QStyle::SP_DriveNetIcon:
QStyle::SP_DriveNetIcon:
never executed: case QStyle::SP_DriveNetIcon:
0
139 if (network.isNull()
network.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
140 network = QApplication::style()->standardIcon(name);
never executed: network = QApplication::style()->standardIcon(name);
0
141 return
never executed: return network;
network;
never executed: return network;
0
142 case
never executed: case QStyle::SP_ComputerIcon:
QStyle::SP_ComputerIcon:
never executed: case QStyle::SP_ComputerIcon:
0
143 if (computer.isNull()
computer.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
144 computer = QApplication::style()->standardIcon(name);
never executed: computer = QApplication::style()->standardIcon(name);
0
145 return
never executed: return computer;
computer;
never executed: return computer;
0
146 case
never executed: case QStyle::SP_DesktopIcon:
QStyle::SP_DesktopIcon:
never executed: case QStyle::SP_DesktopIcon:
0
147 if (desktop.isNull()
desktop.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
148 desktop = QApplication::style()->standardIcon(name);
never executed: desktop = QApplication::style()->standardIcon(name);
0
149 return
never executed: return desktop;
desktop;
never executed: return desktop;
0
150 case
never executed: case QStyle::SP_TrashIcon:
QStyle::SP_TrashIcon:
never executed: case QStyle::SP_TrashIcon:
0
151 if (trashcan.isNull()
trashcan.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
152 trashcan = QApplication::style()->standardIcon(name);
never executed: trashcan = QApplication::style()->standardIcon(name);
0
153 return
never executed: return trashcan;
trashcan;
never executed: return trashcan;
0
154 case
never executed: case QStyle::SP_DirHomeIcon:
QStyle::SP_DirHomeIcon:
never executed: case QStyle::SP_DirHomeIcon:
0
155 if (home.isNull()
home.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
156 home = QApplication::style()->standardIcon(name);
never executed: home = QApplication::style()->standardIcon(name);
0
157 return
never executed: return home;
home;
never executed: return home;
0
158 default
never executed: default:
:
never executed: default:
0
159 return
never executed: return QIcon();
QIcon();
never executed: return QIcon();
0
160 }-
161 return
dead code: return QIcon();
QIcon();
dead code: return QIcon();
-
162}-
163-
164-
165-
166-
167-
168QFileIconProvider::QFileIconProvider()-
169 : d_ptr(new QFileIconProviderPrivate(this))-
170{-
171}
never executed: end of block
0
172-
173-
174-
175-
176-
177-
178QFileIconProvider::~QFileIconProvider()-
179{-
180}-
181-
182-
183-
184-
185-
186-
187-
188void QFileIconProvider::setOptions(QFileIconProvider::Options options)-
189{-
190 QFileIconProviderPrivate * const d = d_func();-
191 d->options = options;-
192}
never executed: end of block
0
193QFileIconProvider::Options QFileIconProvider::options() const-
194{-
195 const QFileIconProviderPrivate * const d = d_func();-
196 return
never executed: return d->options;
d->options;
never executed: return d->options;
0
197}-
198-
199-
200-
201-
202-
203QIcon QFileIconProvider::icon(IconType type) const-
204{-
205 const QFileIconProviderPrivate * const d = d_func();-
206 switch (type) {-
207 case
never executed: case Computer:
Computer:
never executed: case Computer:
0
208 return
never executed: return d->getIcon(QStyle::SP_ComputerIcon);
d->getIcon(QStyle::SP_ComputerIcon);
never executed: return d->getIcon(QStyle::SP_ComputerIcon);
0
209 case
never executed: case Desktop:
Desktop:
never executed: case Desktop:
0
210 return
never executed: return d->getIcon(QStyle::SP_DesktopIcon);
d->getIcon(QStyle::SP_DesktopIcon);
never executed: return d->getIcon(QStyle::SP_DesktopIcon);
0
211 case
never executed: case Trashcan:
Trashcan:
never executed: case Trashcan:
0
212 return
never executed: return d->getIcon(QStyle::SP_TrashIcon);
d->getIcon(QStyle::SP_TrashIcon);
never executed: return d->getIcon(QStyle::SP_TrashIcon);
0
213 case
never executed: case Network:
Network:
never executed: case Network:
0
214 return
never executed: return d->getIcon(QStyle::SP_DriveNetIcon);
d->getIcon(QStyle::SP_DriveNetIcon);
never executed: return d->getIcon(QStyle::SP_DriveNetIcon);
0
215 case
never executed: case Drive:
Drive:
never executed: case Drive:
0
216 return
never executed: return d->getIcon(QStyle::SP_DriveHDIcon);
d->getIcon(QStyle::SP_DriveHDIcon);
never executed: return d->getIcon(QStyle::SP_DriveHDIcon);
0
217 case
never executed: case Folder:
Folder:
never executed: case Folder:
0
218 return
never executed: return d->getIcon(QStyle::SP_DirIcon);
d->getIcon(QStyle::SP_DirIcon);
never executed: return d->getIcon(QStyle::SP_DirIcon);
0
219 case
never executed: case File:
File:
never executed: case File:
0
220 return
never executed: return d->getIcon(QStyle::SP_FileIcon);
d->getIcon(QStyle::SP_FileIcon);
never executed: return d->getIcon(QStyle::SP_FileIcon);
0
221 default
never executed: default:
:
never executed: default:
0
222 break;
never executed: break;
0
223 };-
224 return
never executed: return QIcon();
QIcon();
never executed: return QIcon();
0
225}-
226-
227static bool isCacheable(const QFileInfo &fi)-
228{-
229 if (!fi.isFile()
!fi.isFile()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
230 return
never executed: return false;
false;
never executed: return false;
0
231 return
never executed: return !fi.isExecutable() && !fi.isSymLink();
!fi.isExecutable() && !fi.isSymLink();
never executed: return !fi.isExecutable() && !fi.isSymLink();
0
232-
233}-
234-
235QIcon QFileIconProviderPrivate::getIcon(const QFileInfo &fi) const-
236{-
237 const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme();-
238 if (!theme
!themeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
239 return
never executed: return QIcon();
QIcon();
never executed: return QIcon();
0
240-
241 QList<int> sizes = theme->themeHint(QPlatformTheme::IconPixmapSizes).value<QList<int> >();-
242 if (sizes.isEmpty()
sizes.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
243 return
never executed: return QIcon();
QIcon();
never executed: return QIcon();
0
244-
245 return
never executed: return QIcon(new QFileIconEngine(fi, options));
QIcon(new QFileIconEngine(fi, options));
never executed: return QIcon(new QFileIconEngine(fi, options));
0
246}-
247-
248-
249-
250-
251-
252QIcon QFileIconProvider::icon(const QFileInfo &info) const-
253{-
254 const QFileIconProviderPrivate * const d = d_func();-
255-
256 QIcon retIcon = d->getIcon(info);-
257 if (!retIcon.isNull()
!retIcon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
258 return
never executed: return retIcon;
retIcon;
never executed: return retIcon;
0
259-
260 if (info.isRoot()
info.isRoot()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
261 return
never executed: return d->getIcon(QStyle::SP_DriveHDIcon);
d->getIcon(QStyle::SP_DriveHDIcon);
never executed: return d->getIcon(QStyle::SP_DriveHDIcon);
0
262-
263-
264 if (info.isFile()
info.isFile()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
265 if (info.isSymLink()
info.isSymLink()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
266 return
never executed: return d->getIcon(QStyle::SP_FileLinkIcon);
d->getIcon(QStyle::SP_FileLinkIcon);
never executed: return d->getIcon(QStyle::SP_FileLinkIcon);
0
267 else-
268 return
never executed: return d->getIcon(QStyle::SP_FileIcon);
d->getIcon(QStyle::SP_FileIcon);
never executed: return d->getIcon(QStyle::SP_FileIcon);
0
269 }-
270 if (info.isDir()
info.isDir()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
271 if (info.isSymLink()
info.isSymLink()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
272 return
never executed: return d->getIcon(QStyle::SP_DirLinkIcon);
d->getIcon(QStyle::SP_DirLinkIcon);
never executed: return d->getIcon(QStyle::SP_DirLinkIcon);
0
273 } else {-
274 if (info.absoluteFilePath() == d->homePath
info.absoluteF...== d->homePathDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
275 return
never executed: return d->getIcon(QStyle::SP_DirHomeIcon);
d->getIcon(QStyle::SP_DirHomeIcon);
never executed: return d->getIcon(QStyle::SP_DirHomeIcon);
0
276 } else {-
277 return
never executed: return d->getIcon(QStyle::SP_DirIcon);
d->getIcon(QStyle::SP_DirIcon);
never executed: return d->getIcon(QStyle::SP_DirIcon);
0
278 }-
279 }-
280 }-
281 return
never executed: return QIcon();
QIcon();
never executed: return QIcon();
0
282}-
283-
284-
285-
286-
287-
288QString QFileIconProvider::type(const QFileInfo &info) const-
289{-
290 if (info.isRoot()
info.isRoot()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
291 return
never executed: return QApplication::translate("QFileDialog", "Drive");
QApplication::translate("QFileDialog", "Drive");
never executed: return QApplication::translate("QFileDialog", "Drive");
0
292 if (info.isFile()
info.isFile()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
293 if (!info.suffix().isEmpty()
!info.suffix().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
294-
295 return
never executed: return QApplication::translate("QFileDialog", "%1 File").arg(info.suffix());
QApplication::translate("QFileDialog", "%1 File").arg(info.suffix());
never executed: return QApplication::translate("QFileDialog", "%1 File").arg(info.suffix());
0
296 }-
297 return
never executed: return QApplication::translate("QFileDialog", "File");
QApplication::translate("QFileDialog", "File");
never executed: return QApplication::translate("QFileDialog", "File");
0
298 }-
299-
300 if (info.isDir()
info.isDir()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
301-
302-
303-
304 return
never executed: return QApplication::translate("QFileDialog", "Folder", "All other platforms");
QApplication::translate("QFileDialog", "Folder", "All other platforms");
never executed: return QApplication::translate("QFileDialog", "Folder", "All other platforms");
0
305-
306-
307-
308-
309-
310-
311 if (info.isSymLink()
info.isSymLink()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
312-
313-
314-
315 return
never executed: return QApplication::translate("QFileDialog", "Shortcut", "All other platforms");
QApplication::translate("QFileDialog", "Shortcut", "All other platforms");
never executed: return QApplication::translate("QFileDialog", "Shortcut", "All other platforms");
0
316-
317-
318-
319-
320-
321-
322 return
never executed: return QApplication::translate("QFileDialog", "Unknown");
QApplication::translate("QFileDialog", "Unknown");
never executed: return QApplication::translate("QFileDialog", "Unknown");
0
323}-
324-
325-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9