| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/image/qiconloader.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | namespace { namespace Q_QGS_iconLoaderInstance { typedef QIconLoader Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
never executed: }guard.store(QtGlobalStatic::Destroyed);never executed: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of blocknever executed: &holder.value;return &holder.value;never executed: } } } static QGlobalStatic<QIconLoader, Q_QGS_iconLoaderInstance::innerFunction, Q_QGS_iconLoaderInstance::guard> iconLoaderInstance;return &holder.value; | 0 | ||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | static QString fallbackTheme() | - | ||||||||||||||||||
| 11 | { | - | ||||||||||||||||||
| 12 | if (const
| 0 | ||||||||||||||||||
| 13 | const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconFallbackThemeName); | - | ||||||||||||||||||
| 14 | if (themeHint.isValid()
| 0 | ||||||||||||||||||
| 15 | return never executed: themeHint.toString();return themeHint.toString();never executed: return themeHint.toString(); | 0 | ||||||||||||||||||
| 16 | } never executed: end of block | 0 | ||||||||||||||||||
| 17 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 18 | } | - | ||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | QIconLoader::QIconLoader() : | - | ||||||||||||||||||
| 21 | m_themeKey(1), m_supportsSvg(false), m_initialized(false) | - | ||||||||||||||||||
| 22 | { | - | ||||||||||||||||||
| 23 | } never executed: end of block | 0 | ||||||||||||||||||
| 24 | - | |||||||||||||||||||
| 25 | static inline QString systemThemeName() | - | ||||||||||||||||||
| 26 | { | - | ||||||||||||||||||
| 27 | if (const
| 0 | ||||||||||||||||||
| 28 | const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconThemeName); | - | ||||||||||||||||||
| 29 | if (themeHint.isValid()
| 0 | ||||||||||||||||||
| 30 | return never executed: themeHint.toString();return themeHint.toString();never executed: return themeHint.toString(); | 0 | ||||||||||||||||||
| 31 | } never executed: end of block | 0 | ||||||||||||||||||
| 32 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 33 | } | - | ||||||||||||||||||
| 34 | - | |||||||||||||||||||
| 35 | static inline QStringList systemIconSearchPaths() | - | ||||||||||||||||||
| 36 | { | - | ||||||||||||||||||
| 37 | if (const
| 0 | ||||||||||||||||||
| 38 | const QVariant themeHint = theme->themeHint(QPlatformTheme::IconThemeSearchPaths); | - | ||||||||||||||||||
| 39 | if (themeHint.isValid()
| 0 | ||||||||||||||||||
| 40 | return never executed: themeHint.toStringList();return themeHint.toStringList();never executed: return themeHint.toStringList(); | 0 | ||||||||||||||||||
| 41 | } never executed: end of block | 0 | ||||||||||||||||||
| 42 | return never executed: QStringList();return QStringList();never executed: return QStringList(); | 0 | ||||||||||||||||||
| 43 | } | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | extern QFactoryLoader *qt_iconEngineFactoryLoader(); | - | ||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | void QIconLoader::ensureInitialized() | - | ||||||||||||||||||
| 50 | { | - | ||||||||||||||||||
| 51 | if (!m_initialized
| 0 | ||||||||||||||||||
| 52 | m_initialized = true; | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | ((!((static_cast<QGuiApplication *>(QCoreApplication::instance())))) ? qt_assert("qApp",__FILE__,100) : qt_noop()); | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | m_systemTheme = systemThemeName(); | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | if (m_systemTheme.isEmpty()
| 0 | ||||||||||||||||||
| 59 | m_systemTheme = fallbackTheme(); never executed: m_systemTheme = fallbackTheme(); | 0 | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | if (qt_iconEngineFactoryLoader()->keyMap().key(QLatin1String("svg"), -1) != -1
| 0 | ||||||||||||||||||
| 62 | m_supportsSvg = true; never executed: m_supportsSvg = true; | 0 | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | } never executed: end of block | 0 | ||||||||||||||||||
| 65 | } never executed: end of block | 0 | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | QIconLoader *QIconLoader::instance() | - | ||||||||||||||||||
| 68 | { | - | ||||||||||||||||||
| 69 | iconLoaderInstance()->ensureInitialized(); | - | ||||||||||||||||||
| 70 | return never executed: iconLoaderInstance();return iconLoaderInstance();never executed: return iconLoaderInstance(); | 0 | ||||||||||||||||||
| 71 | } | - | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | - | |||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | void QIconLoader::updateSystemTheme() | - | ||||||||||||||||||
| 76 | { | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | if (m_userTheme.isEmpty()
| 0 | ||||||||||||||||||
| 79 | QString theme = systemThemeName(); | - | ||||||||||||||||||
| 80 | if (theme.isEmpty()
| 0 | ||||||||||||||||||
| 81 | theme = fallbackTheme(); never executed: theme = fallbackTheme(); | 0 | ||||||||||||||||||
| 82 | if (theme != m_systemTheme
| 0 | ||||||||||||||||||
| 83 | m_systemTheme = theme; | - | ||||||||||||||||||
| 84 | invalidateKey(); | - | ||||||||||||||||||
| 85 | } never executed: end of block | 0 | ||||||||||||||||||
| 86 | } never executed: end of block | 0 | ||||||||||||||||||
| 87 | } never executed: end of block | 0 | ||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | void QIconLoader::setThemeName(const QString &themeName) | - | ||||||||||||||||||
| 90 | { | - | ||||||||||||||||||
| 91 | m_userTheme = themeName; | - | ||||||||||||||||||
| 92 | invalidateKey(); | - | ||||||||||||||||||
| 93 | } never executed: end of block | 0 | ||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | void QIconLoader::setThemeSearchPath(const QStringList &searchPaths) | - | ||||||||||||||||||
| 96 | { | - | ||||||||||||||||||
| 97 | m_iconDirs = searchPaths; | - | ||||||||||||||||||
| 98 | themeList.clear(); | - | ||||||||||||||||||
| 99 | invalidateKey(); | - | ||||||||||||||||||
| 100 | } never executed: end of block | 0 | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | QStringList QIconLoader::themeSearchPaths() const | - | ||||||||||||||||||
| 103 | { | - | ||||||||||||||||||
| 104 | if (m_iconDirs.isEmpty()
| 0 | ||||||||||||||||||
| 105 | m_iconDirs = systemIconSearchPaths(); | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | m_iconDirs.append(QLatin1String(":/icons")); | - | ||||||||||||||||||
| 108 | } never executed: end of block | 0 | ||||||||||||||||||
| 109 | return never executed: m_iconDirs;return m_iconDirs;never executed: return m_iconDirs; | 0 | ||||||||||||||||||
| 110 | } | - | ||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | QIconTheme::QIconTheme(const QString &themeName) | - | ||||||||||||||||||
| 113 | : m_valid(false) | - | ||||||||||||||||||
| 114 | { | - | ||||||||||||||||||
| 115 | QFile themeIndex; | - | ||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | QStringList iconDirs = QIcon::themeSearchPaths(); | - | ||||||||||||||||||
| 118 | for ( int i = 0 ; i < iconDirs.size()
| 0 | ||||||||||||||||||
| 119 | QDir iconDir(iconDirs[i]); | - | ||||||||||||||||||
| 120 | QString themeDir = iconDir.path() + QLatin1Char('/') + themeName; | - | ||||||||||||||||||
| 121 | QFileInfo themeDirInfo(themeDir); | - | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | if (themeDirInfo.isDir()
| 0 | ||||||||||||||||||
| 124 | m_contentDirs << themeDir; never executed: m_contentDirs << themeDir; | 0 | ||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | if (!m_valid
| 0 | ||||||||||||||||||
| 127 | themeIndex.setFileName(themeDir + QLatin1String("/index.theme")); | - | ||||||||||||||||||
| 128 | if (themeIndex.exists()
| 0 | ||||||||||||||||||
| 129 | m_valid = true; never executed: m_valid = true; | 0 | ||||||||||||||||||
| 130 | } never executed: end of block | 0 | ||||||||||||||||||
| 131 | } never executed: end of block | 0 | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | if (themeIndex.exists()
| 0 | ||||||||||||||||||
| 134 | const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat); | - | ||||||||||||||||||
| 135 | QStringListIterator keyIterator(indexReader.allKeys()); | - | ||||||||||||||||||
| 136 | while (keyIterator.hasNext()
| 0 | ||||||||||||||||||
| 137 | - | |||||||||||||||||||
| 138 | const QString key = keyIterator.next(); | - | ||||||||||||||||||
| 139 | if (key.endsWith(QLatin1String("/Size"))
| 0 | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | if (int size = indexReader.value(key).toInt()
| 0 | ||||||||||||||||||
| 143 | QString directoryKey = key.left(key.size() - 5); | - | ||||||||||||||||||
| 144 | QIconDirInfo dirInfo(directoryKey); | - | ||||||||||||||||||
| 145 | dirInfo.size = size; | - | ||||||||||||||||||
| 146 | QString type = indexReader.value(directoryKey + | - | ||||||||||||||||||
| 147 | QLatin1String("/Type") | - | ||||||||||||||||||
| 148 | ).toString(); | - | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | if (type == QLatin1String("Fixed")
| 0 | ||||||||||||||||||
| 151 | dirInfo.type = QIconDirInfo::Fixed; never executed: dirInfo.type = QIconDirInfo::Fixed; | 0 | ||||||||||||||||||
| 152 | else if (type == QLatin1String("Scalable")
| 0 | ||||||||||||||||||
| 153 | dirInfo.type = QIconDirInfo::Scalable; never executed: dirInfo.type = QIconDirInfo::Scalable; | 0 | ||||||||||||||||||
| 154 | else | - | ||||||||||||||||||
| 155 | dirInfo.type = QIconDirInfo::Threshold; never executed: dirInfo.type = QIconDirInfo::Threshold; | 0 | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | dirInfo.threshold = indexReader.value(directoryKey + | - | ||||||||||||||||||
| 158 | QLatin1String("/Threshold"), | - | ||||||||||||||||||
| 159 | 2).toInt(); | - | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | dirInfo.minSize = indexReader.value(directoryKey + | - | ||||||||||||||||||
| 162 | QLatin1String("/MinSize"), | - | ||||||||||||||||||
| 163 | size).toInt(); | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | dirInfo.maxSize = indexReader.value(directoryKey + | - | ||||||||||||||||||
| 166 | QLatin1String("/MaxSize"), | - | ||||||||||||||||||
| 167 | size).toInt(); | - | ||||||||||||||||||
| 168 | m_keyList.append(dirInfo); | - | ||||||||||||||||||
| 169 | } never executed: end of block | 0 | ||||||||||||||||||
| 170 | } never executed: end of block | 0 | ||||||||||||||||||
| 171 | } never executed: end of block | 0 | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | m_parents = indexReader.value( | - | ||||||||||||||||||
| 175 | QLatin1String("Icon Theme/Inherits")).toStringList(); | - | ||||||||||||||||||
| 176 | m_parents.removeAll(QString()); | - | ||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | if (m_parents.isEmpty()
| 0 | ||||||||||||||||||
| 180 | const QString fallback = fallbackTheme(); | - | ||||||||||||||||||
| 181 | if (!fallback.isEmpty()
| 0 | ||||||||||||||||||
| 182 | m_parents.append(fallback); never executed: m_parents.append(fallback); | 0 | ||||||||||||||||||
| 183 | } never executed: end of block | 0 | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | if (!m_parents.contains(QLatin1String("hicolor"))
| 0 | ||||||||||||||||||
| 187 | m_parents.append(QLatin1String("hicolor")); never executed: m_parents.append(QLatin1String("hicolor")); | 0 | ||||||||||||||||||
| 188 | } never executed: end of block | 0 | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | } never executed: end of block | 0 | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName, | - | ||||||||||||||||||
| 193 | const QString &iconName, | - | ||||||||||||||||||
| 194 | QStringList &visited) const | - | ||||||||||||||||||
| 195 | { | - | ||||||||||||||||||
| 196 | QThemeIconInfo info; | - | ||||||||||||||||||
| 197 | ((!(!themeName.isEmpty())) ? qt_assert("!themeName.isEmpty()",__FILE__,243) : qt_noop()); | - | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | visited << themeName; | - | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | QIconTheme theme = themeList.value(themeName); | - | ||||||||||||||||||
| 203 | if (!theme.isValid()
| 0 | ||||||||||||||||||
| 204 | theme = QIconTheme(themeName); | - | ||||||||||||||||||
| 205 | if (!theme.isValid()
| 0 | ||||||||||||||||||
| 206 | theme = QIconTheme(fallbackTheme()); never executed: theme = QIconTheme(fallbackTheme()); | 0 | ||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | themeList.insert(themeName, theme); | - | ||||||||||||||||||
| 209 | } never executed: end of block | 0 | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | const QStringList contentDirs = theme.contentDirs(); | - | ||||||||||||||||||
| 212 | const QVector<QIconDirInfo> subDirs = theme.keyList(); | - | ||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | QString iconNameFallback = iconName; | - | ||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | while (info.entries.isEmpty()
| 0 | ||||||||||||||||||
| 218 | const QString svgIconName = iconNameFallback + QLatin1String(".svg"); | - | ||||||||||||||||||
| 219 | const QString pngIconName = iconNameFallback + QLatin1String(".png"); | - | ||||||||||||||||||
| 220 | - | |||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | for (int i = 0; i < contentDirs.size()
| 0 | ||||||||||||||||||
| 223 | QString contentDir = contentDirs.at(i) + QLatin1Char('/'); | - | ||||||||||||||||||
| 224 | for (int j = 0; j < subDirs.size()
| 0 | ||||||||||||||||||
| 225 | const QIconDirInfo &dirInfo = subDirs.at(j); | - | ||||||||||||||||||
| 226 | QString subdir = dirInfo.path; | - | ||||||||||||||||||
| 227 | QDir currentDir(contentDir + subdir); | - | ||||||||||||||||||
| 228 | if (currentDir.exists(pngIconName)
| 0 | ||||||||||||||||||
| 229 | PixmapEntry *iconEntry = new PixmapEntry; | - | ||||||||||||||||||
| 230 | iconEntry->dir = dirInfo; | - | ||||||||||||||||||
| 231 | iconEntry->filename = currentDir.filePath(pngIconName); | - | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | info.entries.prepend(iconEntry); | - | ||||||||||||||||||
| 235 | } never executed: else if (m_supportsSvgend of block
| 0 | ||||||||||||||||||
| 236 | currentDir.exists(svgIconName)
| 0 | ||||||||||||||||||
| 237 | ScalableEntry *iconEntry = new ScalableEntry; | - | ||||||||||||||||||
| 238 | iconEntry->dir = dirInfo; | - | ||||||||||||||||||
| 239 | iconEntry->filename = currentDir.filePath(svgIconName); | - | ||||||||||||||||||
| 240 | info.entries.append(iconEntry); | - | ||||||||||||||||||
| 241 | } never executed: end of block | 0 | ||||||||||||||||||
| 242 | } never executed: end of block | 0 | ||||||||||||||||||
| 243 | } never executed: end of block | 0 | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | if (!info.entries.isEmpty()
| 0 | ||||||||||||||||||
| 246 | info.iconName = iconNameFallback; | - | ||||||||||||||||||
| 247 | break; never executed: break; | 0 | ||||||||||||||||||
| 248 | } | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | const int indexOfDash = iconNameFallback.lastIndexOf(QLatin1Char('-')); | - | ||||||||||||||||||
| 252 | if (indexOfDash == -1
| 0 | ||||||||||||||||||
| 253 | break; never executed: break; | 0 | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | iconNameFallback.truncate(indexOfDash); | - | ||||||||||||||||||
| 256 | } never executed: end of block | 0 | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | if (info.entries.isEmpty()
| 0 | ||||||||||||||||||
| 259 | const QStringList parents = theme.parents(); | - | ||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | for (int i = 0 ; i < parents.size()
| 0 | ||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | const QString parentTheme = parents.at(i).trimmed(); | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | if (!visited.contains(parentTheme)
| 0 | ||||||||||||||||||
| 266 | info = findIconHelper(parentTheme, iconName, visited); never executed: info = findIconHelper(parentTheme, iconName, visited); | 0 | ||||||||||||||||||
| 267 | - | |||||||||||||||||||
| 268 | if (!info.entries.isEmpty()
| 0 | ||||||||||||||||||
| 269 | break; never executed: break; | 0 | ||||||||||||||||||
| 270 | } never executed: end of block | 0 | ||||||||||||||||||
| 271 | } never executed: end of block | 0 | ||||||||||||||||||
| 272 | return never executed: info;return info;never executed: return info; | 0 | ||||||||||||||||||
| 273 | } | - | ||||||||||||||||||
| 274 | - | |||||||||||||||||||
| 275 | QThemeIconInfo QIconLoader::loadIcon(const QString &name) const | - | ||||||||||||||||||
| 276 | { | - | ||||||||||||||||||
| 277 | if (!themeName().isEmpty()
| 0 | ||||||||||||||||||
| 278 | QStringList visited; | - | ||||||||||||||||||
| 279 | return never executed: findIconHelper(themeName(), name, visited);return findIconHelper(themeName(), name, visited);never executed: return findIconHelper(themeName(), name, visited); | 0 | ||||||||||||||||||
| 280 | } | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | return never executed: QThemeIconInfo();return QThemeIconInfo();never executed: return QThemeIconInfo(); | 0 | ||||||||||||||||||
| 283 | } | - | ||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | - | |||||||||||||||||||
| 287 | - | |||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | QIconLoaderEngine::QIconLoaderEngine(const QString& iconName) | - | ||||||||||||||||||
| 290 | : m_iconName(iconName), m_key(0) | - | ||||||||||||||||||
| 291 | { | - | ||||||||||||||||||
| 292 | } never executed: end of block | 0 | ||||||||||||||||||
| 293 | - | |||||||||||||||||||
| 294 | QIconLoaderEngine::~QIconLoaderEngine() | - | ||||||||||||||||||
| 295 | { | - | ||||||||||||||||||
| 296 | qDeleteAll(m_info.entries); | - | ||||||||||||||||||
| 297 | } never executed: end of block | 0 | ||||||||||||||||||
| 298 | - | |||||||||||||||||||
| 299 | QIconLoaderEngine::QIconLoaderEngine(const QIconLoaderEngine &other) | - | ||||||||||||||||||
| 300 | : QIconEngine(other), | - | ||||||||||||||||||
| 301 | m_iconName(other.m_iconName), | - | ||||||||||||||||||
| 302 | m_key(0) | - | ||||||||||||||||||
| 303 | { | - | ||||||||||||||||||
| 304 | } never executed: end of block | 0 | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | QIconEngine *QIconLoaderEngine::clone() const | - | ||||||||||||||||||
| 307 | { | - | ||||||||||||||||||
| 308 | return never executed: new QIconLoaderEngine(*this);return new QIconLoaderEngine(*this);never executed: return new QIconLoaderEngine(*this); | 0 | ||||||||||||||||||
| 309 | } | - | ||||||||||||||||||
| 310 | - | |||||||||||||||||||
| 311 | bool QIconLoaderEngine::read(QDataStream &in) { | - | ||||||||||||||||||
| 312 | in >> m_iconName; | - | ||||||||||||||||||
| 313 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 314 | } | - | ||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | bool QIconLoaderEngine::write(QDataStream &out) const | - | ||||||||||||||||||
| 317 | { | - | ||||||||||||||||||
| 318 | out << m_iconName; | - | ||||||||||||||||||
| 319 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 320 | } | - | ||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | bool QIconLoaderEngine::hasIcon() const | - | ||||||||||||||||||
| 323 | { | - | ||||||||||||||||||
| 324 | return never executed: !(m_info.entries.isEmpty());return !(m_info.entries.isEmpty());never executed: return !(m_info.entries.isEmpty()); | 0 | ||||||||||||||||||
| 325 | } | - | ||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | void QIconLoaderEngine::ensureLoaded() | - | ||||||||||||||||||
| 329 | { | - | ||||||||||||||||||
| 330 | if (!(QIconLoader::instance()->themeKey() == m_key)
| 0 | ||||||||||||||||||
| 331 | qDeleteAll(m_info.entries); | - | ||||||||||||||||||
| 332 | m_info.entries.clear(); | - | ||||||||||||||||||
| 333 | m_info.iconName.clear(); | - | ||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | ((!(m_info.entries.size() == 0)) ? qt_assert("m_info.entries.size() == 0",__FILE__,381) : qt_noop()); | - | ||||||||||||||||||
| 336 | m_info = QIconLoader::instance()->loadIcon(m_iconName); | - | ||||||||||||||||||
| 337 | m_key = QIconLoader::instance()->themeKey(); | - | ||||||||||||||||||
| 338 | } never executed: end of block | 0 | ||||||||||||||||||
| 339 | } never executed: end of block | 0 | ||||||||||||||||||
| 340 | - | |||||||||||||||||||
| 341 | void QIconLoaderEngine::paint(QPainter *painter, const QRect &rect, | - | ||||||||||||||||||
| 342 | QIcon::Mode mode, QIcon::State state) | - | ||||||||||||||||||
| 343 | { | - | ||||||||||||||||||
| 344 | QSize pixmapSize = rect.size(); | - | ||||||||||||||||||
| 345 | painter->drawPixmap(rect, pixmap(pixmapSize, mode, state)); | - | ||||||||||||||||||
| 346 | } never executed: end of block | 0 | ||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | - | |||||||||||||||||||
| 349 | - | |||||||||||||||||||
| 350 | - | |||||||||||||||||||
| 351 | - | |||||||||||||||||||
| 352 | static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize) | - | ||||||||||||||||||
| 353 | { | - | ||||||||||||||||||
| 354 | if (dir.type == QIconDirInfo::Fixed
| 0 | ||||||||||||||||||
| 355 | return never executed: dir.size == iconsize;return dir.size == iconsize;never executed: return dir.size == iconsize; | 0 | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | } else if (dir.type == QIconDirInfo::Scalable
| 0 | ||||||||||||||||||
| 358 | return never executed: iconsize <= dir.maxSizereturn iconsize <= dir.maxSize && iconsize >= dir.minSize;
never executed: return iconsize <= dir.maxSize && iconsize >= dir.minSize; | 0 | ||||||||||||||||||
| 359 | iconsize >= dir.minSize
never executed: return iconsize <= dir.maxSize && iconsize >= dir.minSize; | 0 | ||||||||||||||||||
| 360 | - | |||||||||||||||||||
| 361 | } else if (dir.type == QIconDirInfo::Threshold
| 0 | ||||||||||||||||||
| 362 | return never executed: iconsize >= dir.size - dir.thresholdreturn iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold;
never executed: return iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold; | 0 | ||||||||||||||||||
| 363 | iconsize <= dir.size + dir.threshold
never executed: return iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold; | 0 | ||||||||||||||||||
| 364 | } | - | ||||||||||||||||||
| 365 | - | |||||||||||||||||||
| 366 | ((!(1)) ? qt_assert("1",__FILE__,412) : qt_noop()); | - | ||||||||||||||||||
| 367 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 368 | } | - | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | - | |||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | - | |||||||||||||||||||
| 373 | - | |||||||||||||||||||
| 374 | static int directorySizeDistance(const QIconDirInfo &dir, int iconsize) | - | ||||||||||||||||||
| 375 | { | - | ||||||||||||||||||
| 376 | if (dir.type == QIconDirInfo::Fixed
| 0 | ||||||||||||||||||
| 377 | return never executed: qAbs(dir.size - iconsize);return qAbs(dir.size - iconsize);never executed: return qAbs(dir.size - iconsize); | 0 | ||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | } else if (dir.type == QIconDirInfo::Scalable
| 0 | ||||||||||||||||||
| 380 | if (iconsize < dir.minSize
| 0 | ||||||||||||||||||
| 381 | return never executed: dir.minSize - iconsize;return dir.minSize - iconsize;never executed: return dir.minSize - iconsize; | 0 | ||||||||||||||||||
| 382 | else if (iconsize > dir.maxSize
| 0 | ||||||||||||||||||
| 383 | return never executed: iconsize - dir.maxSize;return iconsize - dir.maxSize;never executed: return iconsize - dir.maxSize; | 0 | ||||||||||||||||||
| 384 | else | - | ||||||||||||||||||
| 385 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 386 | - | |||||||||||||||||||
| 387 | } else if (dir.type == QIconDirInfo::Threshold
| 0 | ||||||||||||||||||
| 388 | if (iconsize < dir.size - dir.threshold
| 0 | ||||||||||||||||||
| 389 | return never executed: dir.minSize - iconsize;return dir.minSize - iconsize;never executed: return dir.minSize - iconsize; | 0 | ||||||||||||||||||
| 390 | else if (iconsize > dir.size + dir.threshold
| 0 | ||||||||||||||||||
| 391 | return never executed: iconsize - dir.maxSize;return iconsize - dir.maxSize;never executed: return iconsize - dir.maxSize; | 0 | ||||||||||||||||||
| 392 | else return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 393 | } | - | ||||||||||||||||||
| 394 | - | |||||||||||||||||||
| 395 | ((!(1)) ? qt_assert("1",__FILE__,441) : qt_noop()); | - | ||||||||||||||||||
| 396 | return never executed: 2147483647;return 2147483647;never executed: return 2147483647; | 0 | ||||||||||||||||||
| 397 | } | - | ||||||||||||||||||
| 398 | - | |||||||||||||||||||
| 399 | QIconLoaderEngineEntry *QIconLoaderEngine::entryForSize(const QSize &size) | - | ||||||||||||||||||
| 400 | { | - | ||||||||||||||||||
| 401 | int iconsize = qMin(size.width(), size.height()); | - | ||||||||||||||||||
| 402 | - | |||||||||||||||||||
| 403 | - | |||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | const int numEntries = m_info.entries.size(); | - | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | for (int i = 0; i < numEntries
| 0 | ||||||||||||||||||
| 410 | QIconLoaderEngineEntry *entry = m_info.entries.at(i); | - | ||||||||||||||||||
| 411 | if (directoryMatchesSize(entry->dir, iconsize)
| 0 | ||||||||||||||||||
| 412 | return never executed: entry;return entry;never executed: return entry; | 0 | ||||||||||||||||||
| 413 | } | - | ||||||||||||||||||
| 414 | } never executed: end of block | 0 | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | int minimalSize = 2147483647; | - | ||||||||||||||||||
| 418 | QIconLoaderEngineEntry *closestMatch = 0; | - | ||||||||||||||||||
| 419 | for (int i = 0; i < numEntries
| 0 | ||||||||||||||||||
| 420 | QIconLoaderEngineEntry *entry = m_info.entries.at(i); | - | ||||||||||||||||||
| 421 | int distance = directorySizeDistance(entry->dir, iconsize); | - | ||||||||||||||||||
| 422 | if (distance < minimalSize
| 0 | ||||||||||||||||||
| 423 | minimalSize = distance; | - | ||||||||||||||||||
| 424 | closestMatch = entry; | - | ||||||||||||||||||
| 425 | } never executed: end of block | 0 | ||||||||||||||||||
| 426 | } never executed: end of block | 0 | ||||||||||||||||||
| 427 | return never executed: closestMatch;return closestMatch;never executed: return closestMatch; | 0 | ||||||||||||||||||
| 428 | } | - | ||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | - | |||||||||||||||||||
| 431 | - | |||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | - | |||||||||||||||||||
| 434 | - | |||||||||||||||||||
| 435 | - | |||||||||||||||||||
| 436 | QSize QIconLoaderEngine::actualSize(const QSize &size, QIcon::Mode mode, | - | ||||||||||||||||||
| 437 | QIcon::State state) | - | ||||||||||||||||||
| 438 | { | - | ||||||||||||||||||
| 439 | ensureLoaded(); | - | ||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | QIconLoaderEngineEntry *entry = entryForSize(size); | - | ||||||||||||||||||
| 442 | if (entry
| 0 | ||||||||||||||||||
| 443 | const QIconDirInfo &dir = entry->dir; | - | ||||||||||||||||||
| 444 | if (dir.type == QIconDirInfo::Scalable
| 0 | ||||||||||||||||||
| 445 | return never executed: size;return size;never executed: return size; | 0 | ||||||||||||||||||
| 446 | else { | - | ||||||||||||||||||
| 447 | int result = qMin<int>(dir.size, qMin(size.width(), size.height())); | - | ||||||||||||||||||
| 448 | return never executed: QSize(result, result);return QSize(result, result);never executed: return QSize(result, result); | 0 | ||||||||||||||||||
| 449 | } | - | ||||||||||||||||||
| 450 | } | - | ||||||||||||||||||
| 451 | return never executed: QIconEngine::actualSize(size, mode, state);return QIconEngine::actualSize(size, mode, state);never executed: return QIconEngine::actualSize(size, mode, state); | 0 | ||||||||||||||||||
| 452 | } | - | ||||||||||||||||||
| 453 | - | |||||||||||||||||||
| 454 | QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) | - | ||||||||||||||||||
| 455 | { | - | ||||||||||||||||||
| 456 | (void)state;; | - | ||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | - | |||||||||||||||||||
| 459 | - | |||||||||||||||||||
| 460 | if (basePixmap.isNull()
| 0 | ||||||||||||||||||
| 461 | basePixmap.load(filename); never executed: basePixmap.load(filename); | 0 | ||||||||||||||||||
| 462 | - | |||||||||||||||||||
| 463 | QSize actualSize = basePixmap.size(); | - | ||||||||||||||||||
| 464 | if (!actualSize.isNull()
| 0 | ||||||||||||||||||
| 465 | actualSize.scale(size, Qt::KeepAspectRatio); never executed: actualSize.scale(size, Qt::KeepAspectRatio); | 0 | ||||||||||||||||||
| 466 | - | |||||||||||||||||||
| 467 | QString key = QLatin1String("$qt_theme_") | - | ||||||||||||||||||
| 468 | % HexString<qint64>(basePixmap.cacheKey()) | - | ||||||||||||||||||
| 469 | % HexString<int>(mode) | - | ||||||||||||||||||
| 470 | % HexString<qint64>(QGuiApplication::palette().cacheKey()) | - | ||||||||||||||||||
| 471 | % HexString<int>(actualSize.width()) | - | ||||||||||||||||||
| 472 | % HexString<int>(actualSize.height()); | - | ||||||||||||||||||
| 473 | - | |||||||||||||||||||
| 474 | QPixmap cachedPixmap; | - | ||||||||||||||||||
| 475 | if (QPixmapCache::find(key, &cachedPixmap)
| 0 | ||||||||||||||||||
| 476 | return never executed: cachedPixmap;return cachedPixmap;never executed: return cachedPixmap; | 0 | ||||||||||||||||||
| 477 | } else { | - | ||||||||||||||||||
| 478 | if (basePixmap.size() != actualSize
| 0 | ||||||||||||||||||
| 479 | cachedPixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); never executed: cachedPixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); | 0 | ||||||||||||||||||
| 480 | else | - | ||||||||||||||||||
| 481 | cachedPixmap = basePixmap; never executed: cachedPixmap = basePixmap; | 0 | ||||||||||||||||||
| 482 | if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>((static_cast<QGuiApplication *>(QCoreApplication::instance())))
| 0 | ||||||||||||||||||
| 483 | cachedPixmap = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, cachedPixmap); never executed: cachedPixmap = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, cachedPixmap); | 0 | ||||||||||||||||||
| 484 | QPixmapCache::insert(key, cachedPixmap); | - | ||||||||||||||||||
| 485 | } never executed: end of block | 0 | ||||||||||||||||||
| 486 | return never executed: cachedPixmap;return cachedPixmap;never executed: return cachedPixmap; | 0 | ||||||||||||||||||
| 487 | } | - | ||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) | - | ||||||||||||||||||
| 490 | { | - | ||||||||||||||||||
| 491 | if (svgIcon.isNull()
| 0 | ||||||||||||||||||
| 492 | svgIcon = QIcon(filename); never executed: svgIcon = QIcon(filename); | 0 | ||||||||||||||||||
| 493 | - | |||||||||||||||||||
| 494 | - | |||||||||||||||||||
| 495 | return never executed: svgIcon.pixmap(size, mode, state);return svgIcon.pixmap(size, mode, state);never executed: return svgIcon.pixmap(size, mode, state); | 0 | ||||||||||||||||||
| 496 | } | - | ||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | QPixmap QIconLoaderEngine::pixmap(const QSize &size, QIcon::Mode mode, | - | ||||||||||||||||||
| 499 | QIcon::State state) | - | ||||||||||||||||||
| 500 | { | - | ||||||||||||||||||
| 501 | ensureLoaded(); | - | ||||||||||||||||||
| 502 | - | |||||||||||||||||||
| 503 | QIconLoaderEngineEntry *entry = entryForSize(size); | - | ||||||||||||||||||
| 504 | if (entry
| 0 | ||||||||||||||||||
| 505 | return never executed: entry->pixmap(size, mode, state);return entry->pixmap(size, mode, state);never executed: return entry->pixmap(size, mode, state); | 0 | ||||||||||||||||||
| 506 | - | |||||||||||||||||||
| 507 | return never executed: QPixmap();return QPixmap();never executed: return QPixmap(); | 0 | ||||||||||||||||||
| 508 | } | - | ||||||||||||||||||
| 509 | - | |||||||||||||||||||
| 510 | QString QIconLoaderEngine::key() const | - | ||||||||||||||||||
| 511 | { | - | ||||||||||||||||||
| 512 | return never executed: QLatin1String("QIconLoaderEngine");return QLatin1String("QIconLoaderEngine");never executed: return QLatin1String("QIconLoaderEngine"); | 0 | ||||||||||||||||||
| 513 | } | - | ||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | void QIconLoaderEngine::virtual_hook(int id, void *data) | - | ||||||||||||||||||
| 516 | { | - | ||||||||||||||||||
| 517 | ensureLoaded(); | - | ||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | switch (id) { | - | ||||||||||||||||||
| 520 | case never executed: QIconEngine::AvailableSizesHook:case QIconEngine::AvailableSizesHook:never executed: case QIconEngine::AvailableSizesHook: | 0 | ||||||||||||||||||
| 521 | { | - | ||||||||||||||||||
| 522 | QIconEngine::AvailableSizesArgument &arg | - | ||||||||||||||||||
| 523 | = *reinterpret_cast<QIconEngine::AvailableSizesArgument*>(data); | - | ||||||||||||||||||
| 524 | const int N = m_info.entries.size(); | - | ||||||||||||||||||
| 525 | QList<QSize> sizes; | - | ||||||||||||||||||
| 526 | sizes.reserve(N); | - | ||||||||||||||||||
| 527 | - | |||||||||||||||||||
| 528 | - | |||||||||||||||||||
| 529 | for (int i = 0; i < N
| 0 | ||||||||||||||||||
| 530 | int size = m_info.entries.at(i)->dir.size; | - | ||||||||||||||||||
| 531 | sizes.append(QSize(size, size)); | - | ||||||||||||||||||
| 532 | } never executed: end of block | 0 | ||||||||||||||||||
| 533 | arg.sizes.swap(sizes); | - | ||||||||||||||||||
| 534 | } | - | ||||||||||||||||||
| 535 | break; never executed: break; | 0 | ||||||||||||||||||
| 536 | case never executed: QIconEngine::IconNameHook:case QIconEngine::IconNameHook:never executed: case QIconEngine::IconNameHook: | 0 | ||||||||||||||||||
| 537 | { | - | ||||||||||||||||||
| 538 | QString &name = *reinterpret_cast<QString*>(data); | - | ||||||||||||||||||
| 539 | name = m_info.iconName; | - | ||||||||||||||||||
| 540 | } | - | ||||||||||||||||||
| 541 | break; never executed: break; | 0 | ||||||||||||||||||
| 542 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||
| 543 | QIconEngine::virtual_hook(id, data); | - | ||||||||||||||||||
| 544 | } never executed: end of block | 0 | ||||||||||||||||||
| 545 | } | - | ||||||||||||||||||
| 546 | - | |||||||||||||||||||
| 547 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |