BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
IconFactory Class Reference

Icon theme manipulator and provider. More...

#include <iconfactory.h>

Collaboration diagram for IconFactory:
Collaboration graph

Public Member Functions

QIcon fromTheme (const QString &name)
 Returns icon from active theme. More...
 
void setupSearchPaths ()
 Adds custom application path to be search for icons.
 
QStringList installedIconThemes () const
 Access to list of icon themes. More...
 
void loadCurrentIconTheme ()
 Loads name of selected icon theme (from settings) for the application and activates it. More...
 
QString currentIconTheme () const
 Gets name of current theme. More...
 
void setCurrentIconTheme (const QString &theme_name)
 Sets icon theme with given name as the active one and loads it. More...
 

Static Public Member Functions

static IconFactoryinstance ()
 Singleton getter. More...
 

Detailed Description

Icon theme manipulator and provider.

Definition at line 47 of file iconfactory.h.

Member Function Documentation

QString IconFactory::currentIconTheme ( ) const
inline

Gets name of current theme.

Returns
Returns name of currently activated theme for the application.

Definition at line 87 of file iconfactory.h.

87  {
88  return m_currentIconTheme;
89  }
QIcon IconFactory::fromTheme ( const QString &  name)
inline

Returns icon from active theme.

Parameters
nameName of the icon.
Returns
Returns icon from active theme or invalid icon if "no icon theme" is set.

Definition at line 58 of file iconfactory.h.

58  {
59  if (m_currentIconTheme == APP_NO_THEME) {
60  return QIcon();
61  }
62 
63  if (!m_cachedIcons.contains(name)) {
64  // Icon is not cached yet.
65  m_cachedIcons.insert(name, QIcon(APP_THEME_PATH + QDir::separator() +
66  m_currentIconTheme + QDir::separator() +
67  name + APP_THEME_SUFFIX));
68  }
69 
70  return m_cachedIcons.value(name);
71  }
QStringList IconFactory::installedIconThemes ( ) const

Access to list of icon themes.

Returns
Returns list of installed themes, including "default" theme.

Definition at line 101 of file iconfactory.cpp.

101  {
102  QStringList icon_theme_names;
103  icon_theme_names << APP_NO_THEME;
104 
105  // Iterate all directories with icon themes.
106  QStringList icon_themes_paths = QIcon::themeSearchPaths();
107  icon_themes_paths.removeDuplicates();
108 
109  foreach (const QString &icon_path, icon_themes_paths) {
110  QDir icon_dir(icon_path);
111 
112  // Iterate all icon themes in this directory.
113  foreach (const QString &icon_theme_path, icon_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot |
114  QDir::Readable | QDir::CaseSensitive |
115  QDir::NoSymLinks,
116  QDir::Time)) {
117  icon_theme_names << icon_theme_path;
118  }
119  }
120 
121  icon_theme_names.removeDuplicates();
122  return icon_theme_names;
123 }

Here is the caller graph for this function:

IconFactory * IconFactory::instance ( )
static

Singleton getter.

Returns
Returns pointer to singleton.

Definition at line 48 of file iconfactory.cpp.

48  {
49  if (s_instance.isNull()) {
50  s_instance = new IconFactory(qApp);
51  }
52 
53  return s_instance;
54 }
Icon theme manipulator and provider.
Definition: iconfactory.h:47

Here is the caller graph for this function:

void IconFactory::loadCurrentIconTheme ( )

Loads name of selected icon theme (from settings) for the application and activates it.

Note
If that particular theme is not installed, then "default" theme is loaded.

Definition at line 69 of file iconfactory.cpp.

69  {
70  QStringList installed_themes = installedIconThemes();
71  QString theme_name_from_settings = qApp->settings()->value(APP_CFG_GUI,
72  "icon_theme",
73  APP_THEME_DEFAULT).toString();
74 
75  if (m_currentIconTheme == theme_name_from_settings) {
76  qDebug("Icon theme '%s' already loaded.",
77  qPrintable(theme_name_from_settings));
78  return;
79  }
80 
81  // Display list of installed themes.
82  qDebug("Installed icon themes are: %s.",
83  qPrintable(QStringList(installed_themes).replaceInStrings(QRegExp("^|$"),
84  "\'").join(", ")));
85 
86  if (installed_themes.contains(theme_name_from_settings)) {
87  // Desired icon theme is installed and can be loaded.
88  qDebug("Loading icon theme '%s'.", qPrintable(theme_name_from_settings));
89  m_currentIconTheme = theme_name_from_settings;
90  }
91  else {
92  // Desired icon theme is not currently available.
93  // Install "default" icon theme instead.
94  qDebug("Icon theme '%s' cannot be loaded because it is not installed. "
95  "No icon theme is loaded now.",
96  qPrintable(theme_name_from_settings));
97  m_currentIconTheme = APP_NO_THEME;
98  }
99 }
QStringList installedIconThemes() const
Access to list of icon themes.

Here is the call graph for this function:

void IconFactory::setCurrentIconTheme ( const QString &  theme_name)

Sets icon theme with given name as the active one and loads it.

Parameters
theme_nameNew theme name.

Definition at line 65 of file iconfactory.cpp.

65  {
66  qApp->settings()->setValue(APP_CFG_GUI, "icon_theme", theme_name);
67 }

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