StockIcon::StockIcon(const char *icon_name) : QIcon() { if (strcmp(icon_name, "document-open") == 0) { QIcon dir_icon = fromTheme(icon_name, wsApp->style()->standardIcon(QStyle::SP_DirIcon)); #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) swap(dir_icon); #endif return; } if (hasThemeIcon(icon_name)) { QIcon theme_icon = fromTheme(icon_name); #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) swap(theme_icon); #endif return; } else { QStringList types = QStringList() << "12x12" << "16x16" << "24x24"; foreach (QString type, types) { QString icon_path = path_pfx_ + QString("%1/%2.png").arg(type).arg(icon_name); if (QFile::exists(icon_path)) { addFile(icon_path); } // Along with each name check for "<name>.on" to use for the on (checked) state. // XXX Add checks for each combination of QIcon::Mode + QIcon::State QString icon_path_on = path_pfx_ + QString("%1/%2.on.png").arg(type).arg(icon_name); if (QFile::exists(icon_path_on)) { addFile(icon_path_on, QSize(), QIcon::Normal, QIcon::On); } } }
QIcon IconUtils::icon(const char *name) { #ifdef APP_LINUX QIcon icon = fromTheme(name); if (icon.isNull()) icon = fromResources(name); return icon; #else return fromResources(name); #endif }
QIcon IconUtils::icon(const QString &name) { #if defined(APP_MAC) || defined(APP_WIN) return fromResources(name); #else QIcon icon = fromTheme(name); if (icon.isNull()) icon = fromResources(name); return icon; #endif }
QPixmap IconTranslationMatrix::requestPixmap(const QString& identifier, QSize* size, const QSize& requested_size) { bool has_icon = false; // Create the pixmap QPixmap pixmap(requested_size.width() > 0 ? requested_size.width() : DEFAULT_SIZE, requested_size.height() > 0 ? requested_size.height() : DEFAULT_SIZE); pixmap.fill(QColor(Qt::transparent)); // Analyze the request QStringList parts = identifier.split('/'); QString id = parts[0]; bool is_active = true; if (parts.count() == 2) { if (parts[1] == "inactive") { is_active = false; } } #ifdef Q_OS_ANDROID has_icon = fromMaterialFont(id, is_active, &pixmap); #else has_icon = fromTheme(id, is_active, &pixmap); if (!has_icon) { // Fallback to Material icon has_icon = fromMaterialFont(id, is_active, &pixmap); } #endif // If we didn't have an icon, return a size of (1, 1) if (!has_icon) { pixmap = QPixmap(1, 1); if (size) *size = QSize(1, 1); } else if (size) { *size = QSize(DEFAULT_SIZE, DEFAULT_SIZE); } return pixmap; }
foreach (QString iconName, iconNames) { QIcon icon = fromTheme(iconName); if (!icon.isNull()) return icon; }
/*! \since 4.6 Returns true if there is an icon available for \a name in the current icon theme, otherwise returns false. \sa themeSearchPaths(), fromTheme(), setThemeName() */ bool QIcon::hasThemeIcon(const QString &name) { QIcon icon = fromTheme(name); return !icon.isNull(); }
/*! \since 4.6 Returns \c true if there is an icon available for \a name in the current icon theme, otherwise returns \c false. \sa themeSearchPaths(), fromTheme(), setThemeName() */ bool QIcon::hasThemeIcon(const QString &name) { QIcon icon = fromTheme(name); return icon.name() == name; }