StyledIcon
Qualified name: mv::util::StyledIcon
-
class StyledIcon
Styled icon class.
StyledIcon class is a wrapper around QIcon that allows for easy creation of icons from icon fonts.
Support icon fonts (FontAwesome, Material Design Icons, etc.)
Supports custom icons
Theme-aware (due to StyledIconEngine)
- Author
Thomas Kroes
Public Functions
-
explicit StyledIcon(const QString &iconName = "", const QString &iconFontName = defaultIconFontName, const Version &iconFontVersion = defaultIconFontVersion)
Construct from
iconName,iconFontNameandiconFontVersion.- Parameters:
iconName – Name of the icon
iconFontName – Name of the icon font
iconFontVersion – Version of the icon font
-
explicit StyledIcon(const QIcon &other)
Copy construct from
otherstyled icon.- Parameters:
icon –
-
inline operator QIcon() const
Implicit conversion to QIcon.
- Returns:
Icon
-
inline operator QVariant() const
Implicit conversion to QVariant.
- Returns:
Variant
-
inline StyledIcon &operator=(const StyledIcon &other)
Assign
otherstyled icon.- Parameters:
other – Other styled icon to assign from
- Returns:
Copied result
-
void set(const QString &iconName, const QString &iconFontName = defaultIconFontName, const util::Version &iconFontVersion = defaultIconFontVersion)
Configure the styled icon by
iconNameand possibly override the defaulticonFontNameandiconFontVersion.- Parameters:
iconName – Name of the icon
iconFontName – Name of the icon font
iconFontVersion – Version of the icon font
-
StyledIcon &withColorGroups(const QPalette::ColorGroup &colorGroupLightTheme, const QPalette::ColorGroup &colorGroupDarkTheme)
Return styled icon with changed color groups
colorGroupLightThemeandcolorGroupDarkTheme.- Parameters:
colorGroupLightTheme – Color group for light theme
colorGroupDarkTheme – Color group for dark theme
- Returns:
Reference to changed styled icon
-
StyledIcon &withColorRoles(const QPalette::ColorRole &colorRoleLightTheme, const QPalette::ColorRole &colorRoleDarkTheme)
Return styled icon with changed color roles
colorRoleLightThemeandcolorRoleDarkTheme.- Parameters:
colorRoleLightTheme – Color role for light theme
colorRoleDarkTheme – Color role for dark theme
- Returns:
Reference to changed styled icon
-
StyledIcon &withBadge(const Badge::Parameters &badgeParameters)
Return styled icon with
badgeparameters.- Parameters:
badgeParameters – Badge parameters
- Returns:
Reference to changed styled icon
-
StyledIcon &withColor(const QColor &color)
Return styled icon with changed
color.- Parameters:
color – Color
- Returns:
Reference to changed styled icon
-
StyledIcon withMode(const StyledIconMode &mode)
Return styled icon with
mode.- Parameters:
mode – The mode of the styled icon
- Returns:
Reference to changed styled icon
-
StyledIcon withModifier(const QString &iconName, const QString &iconFontName = defaultIconFontName, const Version &iconFontVersion = defaultIconFontVersion)
Set icon modifier.
- Parameters:
iconName – Name of the modifier icon
iconFontName – Name of the modifier icon font
iconFontVersion – Version of the modifier icon font
-
Badge::Parameters getBadge() const
Get badge.
- Returns:
Public Static Functions
-
static StyledIcon fromFontAwesomeRegular(const QString &iconName, const Version &version = defaultIconFontVersion)
Create icon with
iconNamefromversionof Font Awesome regular.- Parameters:
iconName – Name of the icon
version – Font Awesome version
- Returns:
Named icon
-
static StyledIcon fromFontAwesomeBrandsRegular(const QString &iconName, const Version &version = defaultIconFontVersion)
Create icon with
iconNamefromversionof Font Awesome Brands.- Parameters:
iconName – Name of the icon
version – Font Awesome version
- Returns:
Named icon
-
static StyledIcon fromQIcon(const QIcon &icon, const StyledIconMode &mode = StyledIconMode::ThemeAware)
Create a styled icon from a Qt
iconwithmode.- Parameters:
icon – Icon to create the styled icon from
mode – The mode of the styled icon
- Returns:
Styled icon
-
static QFont getIconFont(std::int32_t fontPointSize = -1, const QString &iconFontName = defaultIconFontName, const Version &iconFontVersion = defaultIconFontVersion)
Get icon font for
iconFontNameaticonFontVersion.- Parameters:
fontPointSize – Point size of the font
iconFontName – Name of the icon font
iconFontVersion – Version of the icon font
- Returns:
Icon font
-
static QString getIconCharacter(const QString &iconName, const QString &iconFontName = defaultIconFontName, const Version &iconFontVersion = defaultIconFontVersion)
Converts human readable
iconname to icon character (unicode)- Parameters:
iconName – Name of the icon
iconFontName – Name of the icon font
iconFontVersion – Version of the icon font
- Returns:
Unicode icon character (empty if not found)
Protected Static Functions
-
static void initializeIconFont(const QString &iconFontName, const Version &iconFontVersion)
Initialize
versionoficonFontName.- Parameters:
iconFontName – Name of the icon font
iconFontVersion – Font Awesome version
-
static QString getIconFontResourceName(const QString &iconFontName, const Version &iconFontVersion)
Get icon font resource name for
iconFontNameatversion.- Parameters:
iconFontName – Name of the icon font
iconFontVersion – Icon font version
- Returns:
Icon font resource name
-
static QString getIconFontResourcePath(const QString &iconFontName, const Version &iconFontVersion)
Get icon font resource path for
iconFontNameatversion.- Parameters:
iconFontName – Name of the icon font
iconFontVersion – Icon font version
- Returns:
Icon font resource path
-
static QString getIconFontMetadataResourcePath(const QString &iconFontName, const Version &iconFontVersion)
Get icon font metadata resource path for
iconFontNameatversion.- Parameters:
iconFontName – Name of the icon font
iconFontVersion – Icon font version
- Returns:
Icon font metadata resource path
-
static QPixmap createIconPixmap(const QString &iconName, const QString &iconFontName, const Version &iconFontVersion, const QColor &foregroundColor = QColor(0, 0, 0, 0), const QColor &backgroundColor = Qt::transparent)
Create icon pixmap from
iconName,iconFontNameandiconFontVersion.- Parameters:
iconName – Icon name
iconFontName – Font name
iconFontVersion – Font version
foregroundColor – Foreground color
backgroundColor – Background color
- Returns:
Icon pixmap
Protected Static Attributes
-
static QMap<QString, QFont> fonts
Font-specific metadata.
-
static QString defaultIconFontName
Icon fonts.
-
static QMap<QString, QPixmap> pixmaps
Default icon font version.
-
static QVector<QStringList> iconFontPreferenceGroups
All pixmaps for icons.
Friends
- friend class StyledIconEngine