Qt 4.8
Public Functions | Static Public Functions | Private Functions | Properties | List of all members
QIconLoader Class Reference

#include <qiconloader_p.h>

Inheritance diagram for QIconLoader:
QObject

Public Functions

QIconDirInfo dirInfo (int dirindex)
 
void ensureInitialized ()
 
void invalidateKey ()
 
QThemeIconEntries loadIcon (const QString &iconName) const
 
 QIconLoader ()
 
void setThemeName (const QString &themeName)
 
void setThemeSearchPath (const QStringList &searchPaths)
 
QIconTheme theme ()
 
uint themeKey () const
 
QString themeName () const
 
QStringList themeSearchPaths () const
 
void updateSystemTheme ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static QIconLoaderinstance ()
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Private Functions

QThemeIconEntries findIconHelper (const QString &themeName, const QString &iconName, QStringList &visited) const
 

Properties

QStringList m_iconDirs
 
bool m_initialized
 
bool m_supportsSvg
 
QString m_systemTheme
 
uint m_themeKey
 
QString m_userTheme
 
QHash< QString, QIconThemethemeList
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 156 of file qiconloader_p.h.

Constructors and Destructors

◆ QIconLoader()

QIconLoader::QIconLoader ( )

Definition at line 89 of file qiconloader.cpp.

89  :
90  m_themeKey(1), m_supportsSvg(false), m_initialized(false)
91 {
92 }
bool m_supportsSvg
bool m_initialized

Functions

◆ dirInfo()

QIconDirInfo QIconLoader::dirInfo ( int  dirindex)

◆ ensureInitialized()

void QIconLoader::ensureInitialized ( )

Definition at line 96 of file qiconloader.cpp.

97 {
98  if (!m_initialized) {
99  m_initialized = true;
100 
101  Q_ASSERT(qApp);
102 
104  if (m_systemTheme.isEmpty())
106 #ifndef QT_NO_LIBRARY
108  QLatin1String("/iconengines"),
110  if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
111  m_supportsSvg = true;
112 #endif //QT_NO_LIBRARY
113  }
114 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QGuiPlatformPlugin * qt_guiPlatformPlugin()
Return (an construct if necesseray) the Gui Platform plugin.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual QString systemIconThemeName()
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define qApp
static QString fallbackTheme()
Definition: qiconloader.cpp:73
bool m_supportsSvg
bool m_initialized
QString m_systemTheme
QIconEngineFactoryInterfaceV2_iid
Definition: qicon.cpp:451

◆ findIconHelper()

QThemeIconEntries QIconLoader::findIconHelper ( const QString themeName,
const QString iconName,
QStringList visited 
) const
private

Definition at line 233 of file qiconloader.cpp.

236 {
238  Q_ASSERT(!themeName.isEmpty());
239 
240  QPixmap pixmap;
241 
242  // Used to protect against potential recursions
243  visited << themeName;
244 
245  QIconTheme theme = themeList.value(themeName);
246  if (!theme.isValid()) {
247  theme = QIconTheme(themeName);
248  if (!theme.isValid())
249  theme = QIconTheme(fallbackTheme());
250 
251  themeList.insert(themeName, theme);
252  }
253 
254  QString contentDir = theme.contentDir() + QLatin1Char('/');
255  QList<QIconDirInfo> subDirs = theme.keyList();
256 
257  const QString svgext(QLatin1String(".svg"));
258  const QString pngext(QLatin1String(".png"));
259 
260  // Add all relevant files
261  for (int i = 0; i < subDirs.size() ; ++i) {
262  const QIconDirInfo &dirInfo = subDirs.at(i);
263  QString subdir = dirInfo.path;
264  QDir currentDir(contentDir + subdir);
265  if (currentDir.exists(iconName + pngext)) {
266  PixmapEntry *iconEntry = new PixmapEntry;
267  iconEntry->dir = dirInfo;
268  iconEntry->filename = currentDir.filePath(iconName + pngext);
269  // Notice we ensure that pixmap entries always come before
270  // scalable to preserve search order afterwards
271  entries.prepend(iconEntry);
272  } else if (m_supportsSvg &&
273  currentDir.exists(iconName + svgext)) {
274  ScalableEntry *iconEntry = new ScalableEntry;
275  iconEntry->dir = dirInfo;
276  iconEntry->filename = currentDir.filePath(iconName + svgext);
277  entries.append(iconEntry);
278  }
279  }
280 
281  if (entries.isEmpty()) {
282  const QStringList parents = theme.parents();
283  // Search recursively through inherited themes
284  for (int i = 0 ; i < parents.size() ; ++i) {
285 
286  const QString parentTheme = parents.at(i).trimmed();
287 
288  if (!visited.contains(parentTheme)) // guard against recursion
289  entries = findIconHelper(parentTheme, iconName, visited);
290 
291  if (!entries.isEmpty()) // success
292  break;
293  }
294  }
295  return entries;
296 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool isValid()
The QString class provides a Unicode character string.
Definition: qstring.h:83
QList< QIconDirInfo > keyList()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QIconDirInfo dirInfo(int dirindex)
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QStringList parents()
static QString fallbackTheme()
Definition: qiconloader.cpp:73
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
bool m_supportsSvg
QIconTheme theme()
static const MacSpecialKey entries[NumEntries]
QString themeName() const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QString contentDir()
QHash< QString, QIconTheme > themeList
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QString path
Definition: qiconloader_p.h:78
QThemeIconEntries findIconHelper(const QString &themeName, const QString &iconName, QStringList &visited) const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ instance()

QIconLoader * QIconLoader::instance ( )
static

Definition at line 116 of file qiconloader.cpp.

Referenced by QIcon::setThemeName(), QIcon::setThemeSearchPaths(), QIcon::themeName(), QIcon::themeSearchPaths(), and QGtkStyleUpdateScheduler::updateTheme().

117 {
118  return iconLoaderInstance();
119 }

◆ invalidateKey()

void QIconLoader::invalidateKey ( )
inline

Definition at line 171 of file qiconloader_p.h.

Referenced by setThemeName(), setThemeSearchPath(), and updateSystemTheme().

171 { m_themeKey++; }

◆ loadIcon()

QThemeIconEntries QIconLoader::loadIcon ( const QString iconName) const

Definition at line 298 of file qiconloader.cpp.

299 {
300  if (!themeName().isEmpty()) {
301  QStringList visited;
302  return findIconHelper(themeName(), name, visited);
303  }
304 
305  return QThemeIconEntries();
306 }
static bool isEmpty(const char *str)
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QList< QIconLoaderEngineEntry * > QThemeIconEntries
QString themeName() const
QThemeIconEntries findIconHelper(const QString &themeName, const QString &iconName, QStringList &visited) const

◆ setThemeName()

void QIconLoader::setThemeName ( const QString themeName)

Definition at line 137 of file qiconloader.cpp.

Referenced by QIcon::setThemeName().

138 {
140  invalidateKey();
141 }
void invalidateKey()
QString themeName() const
QString m_userTheme

◆ setThemeSearchPath()

void QIconLoader::setThemeSearchPath ( const QStringList searchPaths)

Definition at line 143 of file qiconloader.cpp.

Referenced by QIcon::setThemeSearchPaths().

144 {
145  m_iconDirs = searchPaths;
146  themeList.clear();
147  invalidateKey();
148 }
void invalidateKey()
void clear()
Removes all items from the hash.
Definition: qhash.h:574
QStringList m_iconDirs
QHash< QString, QIconTheme > themeList

◆ theme()

QIconTheme QIconLoader::theme ( )
inline

Definition at line 165 of file qiconloader_p.h.

Referenced by updateSystemTheme().

165 { return themeList.value(themeName()); }
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QString themeName() const
QHash< QString, QIconTheme > themeList

◆ themeKey()

uint QIconLoader::themeKey ( ) const
inline

Definition at line 161 of file qiconloader_p.h.

161 { return m_themeKey; }

◆ themeName()

QString QIconLoader::themeName ( ) const
inline

Definition at line 163 of file qiconloader_p.h.

Referenced by setThemeName(), and QIcon::themeName().

bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString m_systemTheme
QString m_userTheme

◆ themeSearchPaths()

QStringList QIconLoader::themeSearchPaths ( ) const

Definition at line 150 of file qiconloader.cpp.

Referenced by QIcon::themeSearchPaths().

151 {
152  if (m_iconDirs.isEmpty()) {
154  // Always add resource directory as search path
155  m_iconDirs.append(QLatin1String(":/icons"));
156  }
157  return m_iconDirs;
158 }
virtual QStringList iconThemeSearchPaths()
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QGuiPlatformPlugin * qt_guiPlatformPlugin()
Return (an construct if necesseray) the Gui Platform plugin.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QStringList m_iconDirs

◆ updateSystemTheme()

void QIconLoader::updateSystemTheme ( )

Definition at line 123 of file qiconloader.cpp.

Referenced by QGtkStyleUpdateScheduler::updateTheme().

124 {
125  // Only change if this is not explicitly set by the user
126  if (m_userTheme.isEmpty()) {
128  if (theme.isEmpty())
129  theme = fallbackTheme();
130  if (theme != m_systemTheme) {
132  invalidateKey();
133  }
134  }
135 }
void invalidateKey()
QGuiPlatformPlugin * qt_guiPlatformPlugin()
Return (an construct if necesseray) the Gui Platform plugin.
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual QString systemIconThemeName()
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString fallbackTheme()
Definition: qiconloader.cpp:73
QIconTheme theme()
QString m_systemTheme
QString m_userTheme

Properties

◆ m_iconDirs

QStringList QIconLoader::m_iconDirs
mutableprivate

Definition at line 184 of file qiconloader_p.h.

Referenced by setThemeSearchPath(), and themeSearchPaths().

◆ m_initialized

bool QIconLoader::m_initialized
private

Definition at line 180 of file qiconloader_p.h.

Referenced by ensureInitialized().

◆ m_supportsSvg

bool QIconLoader::m_supportsSvg
private

Definition at line 179 of file qiconloader_p.h.

Referenced by ensureInitialized().

◆ m_systemTheme

QString QIconLoader::m_systemTheme
mutableprivate

Definition at line 183 of file qiconloader_p.h.

Referenced by ensureInitialized(), and updateSystemTheme().

◆ m_themeKey

uint QIconLoader::m_themeKey
private

Definition at line 178 of file qiconloader_p.h.

◆ m_userTheme

QString QIconLoader::m_userTheme
mutableprivate

Definition at line 182 of file qiconloader_p.h.

Referenced by setThemeName(), and updateSystemTheme().

◆ themeList

QHash<QString, QIconTheme> QIconLoader::themeList
mutableprivate

Definition at line 185 of file qiconloader_p.h.

Referenced by setThemeSearchPath().


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