VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends
makVrv::DtWidgetIconStyleManager Class Reference

The widget icon style manager chooses the icons of QWidgets based on whether the VR-Vantage application is using dark mode or light mode. UI Element classes, e.g. dialogs and other widgets, may have their icon managed by this manager by using one of the following class methods: 1) manageWidget(QObject* widgetToManage, const std::string& iconFileNameOrPath) 2) manageWidget(QObject* widgetToManage, const DtQIconConfigurations& iconConfigurations); 3) manageIndexableWidget(QObject* indexedWidgetToManage, int index, const DtQIconConfigurations& iconConfigurations)

Class methods 1 and 2 are used for non-indexable widgets and class method 3 is used for indexable widgets. Indexable widgets are widgets that can support the rendering of an icon at particular indices, e.g. lists/tables/trees.

QObject does not have a setIcon method (nor anything similar) so the manager will dynamic cast to a supporting widget type when it comes time to update the icons.

The supported un-indexable widget types are:

The supported indexable widget types are:

To support more widget types, subclass this manager class and extend updateIcon(...) to support other un-indexable widget types OR updateIndexedIcon(...) to support other indexable widget types.

Users of this class can use unmanageWidget(QObject* widgetToManage) to stop further management of a widget's icon style.

If the manager is managing a widget that has been deleted - it will detect that case and automatically removed the deleted widget from its internal list of widgets to manage.

To manage a widget, one thing the manager needs to be provided is the file name of icon asset OR the file path to that icon asset. The file name or file path is provided:

The manager uses the provided icon file name or file path in the following way:

Inheritance diagram for makVrv::DtWidgetIconStyleManager:
Inheritance graph
[legend]

Public Types

typedef std::vector< std::pair
< int, DtQIconConfigurations > > 
DtIndexableQIconConfigurations
 

Public Member Functions

 DtWidgetIconStyleManager ()=delete
 
 DtWidgetIconStyleManager (const DtWidgetIconStyleManager &other)=delete
 
DtWidgetIconStyleManageroperator= (const DtWidgetIconStyleManager &other)=delete
 
virtual void manageWidget (QObject *widgetToManage, const std::string &iconFileNameOrPath)
 
virtual void manageWidget (QObject *widgetToManage, const DtQIconConfigurations &iconConfigurations)
 
virtual void manageIndexableWidget (QObject *indexedWidgetToManage, int index, const DtQIconConfigurations &iconConfigurations)
 
virtual void unmanageWidget (QObject *widgetToManage)
 
virtual void clearCache (bool refreshIcons=true)
 
virtual QPixmap generateThemedPixmap (const std::string &iconFileNameOrPath, const QSize &pixmapSize=QSize(16, 16), QIcon::Mode iconModeOfGeneratedPixmap=QIcon::Normal, QIcon::State iconStateOfGeneratedPixmap=QIcon::Off)
 
virtual QIcon createQIconBasedOnConfigurations (const DtQIconConfigurations &configurations)
 
- Public Member Functions inherited from makVrv::DtVirtualBaseClass
 DtVirtualBaseClass ()
 
virtual ~DtVirtualBaseClass ()
 

Static Public Member Functions

static DtWidgetIconStyleManagerinstance (DtDe &de)
 
static void registerInstance (DtDe &de, DtWidgetIconStyleManager *instance)
 

Public Attributes

boost::signalslib::signal< void()> signal_refreshApplicationIcons
 

Protected Member Functions

 DtWidgetIconStyleManager (DtDe &de)
 
virtual ~DtWidgetIconStyleManager ()
 
virtual void slot_darkModeEnabledChanged (bool enabled)
 
virtual void slot_lightModeDarkModeIconsEnabledChanged (bool enabled)
 
virtual void updateAllManagedIcons (bool lightDarkModeIconsEnabled)
 
virtual void updateIcon (QObject *widget, const DtQIconConfigurations &iconConfigurations, bool lightDarkModeIconsEnabled)
 
virtual void updateIndexedIcon (QObject *indexedWidget, const DtIndexableQIconConfigurations &iconConfigurations, bool lightDarkModeIconsEnabled)
 
virtual QPixmap findOrCreatePixmapInCache (const std::string &filePath)
 
virtual QPixmap findOrCreateThemedPixmapInCache (const std::string &fileNameOrPath)
 
virtual std::string iconsDirectory (const std::string &iconFileNameOrPath) const
 
virtual bool iconExistsOnDiskOrInCache (const std::string &iconFilePath) const
 
virtual std::string iconFilePath (const std::string &iconFileNameOrPath) const
 
virtual void generateAndAppendAdditionalIconConfigurationsIfNeeded (QIcon &iconToAppendToIfNeeded, const DtQIconConfigurations &iconConfigurations) const
 
virtual QPixmap generateThemedPixmap (const std::string &iconFileNameOrPath, QIcon::Mode iconModeOfGeneratedPixmap=QIcon::Normal, QIcon::State iconStateOfGeneratedPixmap=QIcon::Off) const
 
virtual bool getPixmapFromSVGAndColorMappings (const std::string &iconFileNameOrPath, const std::vector< std::pair< QColor, QColor >> colorMappings, QPixmap &resultIcon) const
 

Protected Attributes

DtDemyDe
 
DtSignalConnectionManager myConnections
 
std::map< QPointer< QObject >
, DtQIconConfigurations
myWidgetsToManage
 
std::map< QPointer< QObject >
, DtIndexableQIconConfigurations
myIndexedWidgetsToManage
 
std::map< std::string, QPixmap > myFilepathsToPixmapCache
 
DtWidgetIconStyleManagerEventFiltermyEventFilter
 

Friends

class DtWidgetIconStyleManagerEventFilter
 

Member Typedef Documentation

Vector of mappings between a DtQIconConfigurations and the index to apply the configuration to.

Constructor & Destructor Documentation

makVrv::DtWidgetIconStyleManager::DtWidgetIconStyleManager ( )
delete

Default Constructor not implemented.

makVrv::DtWidgetIconStyleManager::DtWidgetIconStyleManager ( const DtWidgetIconStyleManager other)
delete

Copy Constructor not implemented - Copy not allowed.

makVrv::DtWidgetIconStyleManager::DtWidgetIconStyleManager ( DtDe de)
protected

Protected CTOR - use the static instance function to create.

virtual makVrv::DtWidgetIconStyleManager::~DtWidgetIconStyleManager ( )
protectedvirtual

DTOR.

Member Function Documentation

static DtWidgetIconStyleManager& makVrv::DtWidgetIconStyleManager::instance ( DtDe de)
static

Returns a reference to the DtWidgetIconStyleManager instance This function will register the manager with the DtDe if one has not been registered already.

Referenced by makVrf::DtToolButtonWrapperWidget::addActionWithIcon().

static void makVrv::DtWidgetIconStyleManager::registerInstance ( DtDe de,
DtWidgetIconStyleManager instance 
)
static

Register a new widget icon style manager instance and replace the default.

DtWidgetIconStyleManager& makVrv::DtWidgetIconStyleManager::operator= ( const DtWidgetIconStyleManager other)
delete

Assignment Operator not implemented - Assignment not allowed.

virtual void makVrv::DtWidgetIconStyleManager::manageWidget ( QObject widgetToManage,
const std::string &  iconFileNameOrPath 
)
virtual

Add a new widget to the manager. The manager will now manage the icon style for the widget.

Parameters
widgetToManageThe widget to manage the icon for.
iconFileNameOrFilePathThe file name of the icon asset OR the file path to the icon asset.

Referenced by makVrf::DtToolButtonWrapperWidget::addActionWithIcon().

virtual void makVrv::DtWidgetIconStyleManager::manageWidget ( QObject widgetToManage,
const DtQIconConfigurations iconConfigurations 
)
virtual

Add a new widget to the manager. The manager will now manage the icon style for the widget.

Parameters
widgetToManageThe widget to manage the icon for.
iconConfigurationsThe configurations for the widget's icon.
virtual void makVrv::DtWidgetIconStyleManager::manageIndexableWidget ( QObject indexedWidgetToManage,
int  index,
const DtQIconConfigurations iconConfigurations 
)
virtual

Add a new indexable widget to the manager. The manager will now manage the icon style for the widget.

Parameters
widgetToManageThe indexable widget to manage the icon for.
indexThe index of the widget the icon configurations will be applied to.
iconConfigurationsThe configurations for the widget's icon.
virtual void makVrv::DtWidgetIconStyleManager::unmanageWidget ( QObject widgetToManage)
virtual

Remove a new widget the manager. The manager will not manage the icon style.

Parameters
widgetToManageThe (non)indexable widget to no longer manage.
virtual void makVrv::DtWidgetIconStyleManager::clearCache ( bool  refreshIcons = true)
virtual

Clear the cache of QPixmap objects that are used to set the icons.

Parameters
refreshIconsIf true, update all managed widgets after clearing the cache.
virtual QPixmap makVrv::DtWidgetIconStyleManager::generateThemedPixmap ( const std::string &  iconFileNameOrPath,
const QSize &  pixmapSize = QSize(16, 16),
QIcon::Mode  iconModeOfGeneratedPixmap = QIcon::Normal,
QIcon::State  iconStateOfGeneratedPixmap = QIcon::Off 
)
virtual

Generate a pixmap from an SVG and the desired size, mode and state. The generated pixmap is a modified version of the SVG pointed to by the provided icon file name/path with a different set of colors. The colors of the SVG are swapped out with other colors based on mappings maintained by the main window.

See Also
DtQtDeMainWindow::iconColorMappings
virtual QIcon makVrv::DtWidgetIconStyleManager::createQIconBasedOnConfigurations ( const DtQIconConfigurations configurations)
virtual

Helper function for creating a QIcon based on a DtQIconConfigurations.

Parameters
configurationsThe VRV-specific configurations to convert to a QIcon
virtual void makVrv::DtWidgetIconStyleManager::slot_darkModeEnabledChanged ( bool  enabled)
protectedvirtual

Invoked when dark mode has been enabled or disabled.

virtual void makVrv::DtWidgetIconStyleManager::slot_lightModeDarkModeIconsEnabledChanged ( bool  enabled)
protectedvirtual

Invoked when light/dark mode icons has been enabled or disabled.

virtual void makVrv::DtWidgetIconStyleManager::updateAllManagedIcons ( bool  lightDarkModeIconsEnabled)
protectedvirtual

Update all managed icons based on application settings.

virtual void makVrv::DtWidgetIconStyleManager::updateIcon ( QObject widget,
const DtQIconConfigurations iconConfigurations,
bool  lightDarkModeIconsEnabled 
)
protectedvirtual

Helper function to update a single widget that uses the provided icon file name.

virtual void makVrv::DtWidgetIconStyleManager::updateIndexedIcon ( QObject indexedWidget,
const DtIndexableQIconConfigurations iconConfigurations,
bool  lightDarkModeIconsEnabled 
)
protectedvirtual

Helper function to update a single widget that uses the provided icon file name.

virtual QPixmap makVrv::DtWidgetIconStyleManager::findOrCreatePixmapInCache ( const std::string &  filePath)
protectedvirtual

Helper function for getting the QPixmap for the associated asset pointed to by the provided filePath from the manager's QPixmap cache. This function will create a QPixmap and cache it if one does not exist in the cache already.

virtual QPixmap makVrv::DtWidgetIconStyleManager::findOrCreateThemedPixmapInCache ( const std::string &  fileNameOrPath)
protectedvirtual

Attempt to get the QPixmap for the associated asset pointed to by the provided fileName from the manager's QPixmap cache based on the current theme used by the application. This function will create a QPixmap and cache it if one does not exist in the cache already.

Parameters
iconFileNameOrFilePathThe file name of the icon asset OR the file path to the icon asset.
virtual std::string makVrv::DtWidgetIconStyleManager::iconsDirectory ( const std::string &  iconFileNameOrPath) const
protectedvirtual

Helper function to get the base icons directory associated with the provided icon file name or path.

virtual bool makVrv::DtWidgetIconStyleManager::iconExistsOnDiskOrInCache ( const std::string &  iconFilePath) const
protectedvirtual

Helper function that returns whether or not provided iconFilePath exists on disk or is present in the icon cache.

virtual std::string makVrv::DtWidgetIconStyleManager::iconFilePath ( const std::string &  iconFileNameOrPath) const
protectedvirtual

Helper function used to get the full icon file path of an icon configuration This function considers the application setting for whether dark mode or light mode is being used and whether dark mode and light mode -specific icons are used.

virtual void makVrv::DtWidgetIconStyleManager::generateAndAppendAdditionalIconConfigurationsIfNeeded ( QIcon &  iconToAppendToIfNeeded,
const DtQIconConfigurations iconConfigurations 
) const
protectedvirtual

Helper function to generate additional icon configurations, if needed Additional icon configurations need to be generated if the flags maintained by the collection of configurations indicate they should be generated.

The asset used for the generation of an icon for a given mode and state is determined by the following rules:

  • If the user defines an icon file path/name for the mode/state we're generating an icon for, then use that to generate the mode/state-specific versions of the icon. Else...
  • If the user defines an icon file path/name for the Normal mode and the state we're generating an icon for, then use that to generate the mode-specific versions of the icon.
  • Otherwise, do nothing and output an INFO-level warning to the console.

Generation in this context means we create a modified version of a provided icon configuration. The modified version is the same as the provided icon configuration and only differs in the colors it uses. The colors to use for generated icons come from mappings present in the stylesheet of the application and that are maintained by the main window of the application.

See Also
DtQtDeMainWindow
virtual QPixmap makVrv::DtWidgetIconStyleManager::generateThemedPixmap ( const std::string &  iconFileNameOrPath,
QIcon::Mode  iconModeOfGeneratedPixmap = QIcon::Normal,
QIcon::State  iconStateOfGeneratedPixmap = QIcon::Off 
) const
protectedvirtual

Helper function for generating a pixmap from an SVG and the desired mode and state for the pixmap. The generated SVG is a modified version of the SVG pointed to by the provided icon file name/path with a different set of colors. The colors of the SVG are swapped out with other colors based on mappings maintained by the main window.

See Also
DtQtDeMainWindow::iconColorMappings
virtual bool makVrv::DtWidgetIconStyleManager::getPixmapFromSVGAndColorMappings ( const std::string &  iconFileNameOrPath,
const std::vector< std::pair< QColor, QColor >>  colorMappings,
QPixmap &  resultIcon 
) const
protectedvirtual

Helper function that creates a modified version of an icon asset. This function assumes the icon asset is an SVG. The modified version of the SVG swaps out colors with other colors defined in the provided color mappings. If the icon asset is not a SVG, then just return a QPixmap with the icon asset loaded.

Friends And Related Function Documentation

Member Data Documentation

boost::signalslib::signal<void()> makVrv::DtWidgetIconStyleManager::signal_refreshApplicationIcons

Emitted when the manager has updated all of its managed widgets If a widget is managing its own icon (as opposed to this manager managing the icon for the widget), then the widget will likely need to connect to this signal, to be notified when all the other application icons have been refreshed, as the widget will likely need to refresh its own icon also.

DtDe& makVrv::DtWidgetIconStyleManager::myDe
protected
DtSignalConnectionManager makVrv::DtWidgetIconStyleManager::myConnections
protected
std::map<QPointer<QObject>, DtQIconConfigurations> makVrv::DtWidgetIconStyleManager::myWidgetsToManage
protected

Mapping a QObject (UI element with the icon) and its configuration.

std::map<QPointer<QObject>, DtIndexableQIconConfigurations > makVrv::DtWidgetIconStyleManager::myIndexedWidgetsToManage
protected

Mapping an indexed QObject (UI element with indices where each index can have an icon) and its configuration.

std::map<std::string, QPixmap> makVrv::DtWidgetIconStyleManager::myFilepathsToPixmapCache
protected

Mapping a filepath to the cached QPixmap for the asset pointed to by the filepath.

DtWidgetIconStyleManagerEventFilter* makVrv::DtWidgetIconStyleManager::myEventFilter
protected

Event filter to detect changes to enable state of some widget types.


The documentation for this class was generated from the following file:

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)