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, iconFontName and iconFontVersion.

Parameters:
  • iconName – Name of the icon

  • iconFontName – Name of the icon font

  • iconFontVersionVersion of the icon font

explicit StyledIcon(const QIcon &other)

Copy construct from other styled 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 other styled 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 iconName and possibly override the default iconFontName and iconFontVersion.

Parameters:
  • iconName – Name of the icon

  • iconFontName – Name of the icon font

  • iconFontVersionVersion of the icon font

StyledIcon &withColorGroups(const QPalette::ColorGroup &colorGroupLightTheme, const QPalette::ColorGroup &colorGroupDarkTheme)

Return styled icon with changed color groups colorGroupLightTheme and colorGroupDarkTheme.

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 colorRoleLightTheme and colorRoleDarkTheme.

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 badge parameters.

Parameters:

badgeParametersBadge 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

  • iconFontVersionVersion of the modifier icon font

Badge::Parameters getBadge() const

Get badge.

Returns:

Badge

void setBadgeEnabled(bool badgeEnabled)

Set badge enabled to badgeEnabled.

Parameters:

badgeEnabledBadge enabled

bool isBadgeEnabled() const

Get badge enabled.

Returns:

Badge enabled

Public Static Functions

static StyledIcon fromFontAwesomeRegular(const QString &iconName, const Version &version = defaultIconFontVersion)

Create icon with iconName from version of 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 iconName from version of 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 icon with mode.

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 iconFontName at iconFontVersion.

Parameters:
  • fontPointSize – Point size of the font

  • iconFontName – Name of the icon font

  • iconFontVersionVersion of the icon font

Returns:

Icon font

static QString getIconCharacter(const QString &iconName, const QString &iconFontName = defaultIconFontName, const Version &iconFontVersion = defaultIconFontVersion)

Converts human readable icon name to icon character (unicode)

Parameters:
  • iconName – Name of the icon

  • iconFontName – Name of the icon font

  • iconFontVersionVersion 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 version of iconFontName.

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 iconFontName at version.

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 iconFontName at version.

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 iconFontName at version.

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, iconFontName and iconFontVersion.

Parameters:
  • iconName – Icon name

  • iconFontName – Font name

  • iconFontVersion – Font version

  • foregroundColor – Foreground color

  • backgroundColor – Background color

Returns:

Icon pixmap

static QString getIconFontVersionString(const Version &version)

Get icon font version string for version.

Returns:

Icon font version string (e.g. 2.4)

Protected Static Attributes

static QMap<QString, QVariantMap> fontMetadata

Version of the modifier icon font.

static QMap<QString, QFont> fonts

Font-specific metadata.

static QString defaultIconFontName

Icon fonts.

static Version defaultIconFontVersion

Default icon font name.

static QMap<QString, QPixmap> pixmaps

Default icon font version.

static QVector<QStringList> iconFontPreferenceGroups

All pixmaps for icons.

static QMap<QString, QVector<Version>> iconFontVersions

The order in each usb-vector determines fetching precedence.

Friends

friend class StyledIconEngine