Qt 4.8
Public Functions | Private Functions | Properties | Friends | List of all members
QIconLoaderEngine Class Reference

#include <qiconloader_p.h>

Inheritance diagram for QIconLoaderEngine:
QIconEngineV2 QIconEngine

Public Functions

QSize actualSize (const QSize &size, QIcon::Mode mode, QIcon::State state)
 Returns the actual size of the icon the engine provides for the requested size, mode and state. More...
 
QIconEngineV2clone () const
 Returns a clone of this icon engine. More...
 
void paint (QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)
 Uses the given painter to paint the icon with the required mode and state into the rectangle rect. More...
 
QPixmap pixmap (const QSize &size, QIcon::Mode mode, QIcon::State state)
 Returns the icon as a pixmap with the required size, mode, and state. More...
 
 QIconLoaderEngine (const QString &iconName=QString())
 
bool read (QDataStream &in)
 Reads icon engine contents from the QDataStream in. More...
 
bool write (QDataStream &out) const
 Writes the contents of this engine to the QDataStream out. More...
 
 ~QIconLoaderEngine ()
 
- Public Functions inherited from QIconEngineV2
QList< QSizeavailableSizes (QIcon::Mode mode=QIcon::Normal, QIcon::State state=QIcon::Off)
 Returns sizes of all images that are contained in the engine for the specific mode and state. More...
 
QString iconName ()
 Returns the name used to create the engine, if available. More...
 
- Public Functions inherited from QIconEngine
virtual void addFile (const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
 Called by QIcon::addFile(). More...
 
virtual void addPixmap (const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
 Called by QIcon::addPixmap(). More...
 
virtual ~QIconEngine ()
 Destroys the icon engine. More...
 

Private Functions

void ensureLoaded ()
 
QIconLoaderEngineEntryentryForSize (const QSize &size)
 
bool hasIcon () const
 
QString key () const
 Returns a key that identifies this icon engine. More...
 
 QIconLoaderEngine (const QIconLoaderEngine &other)
 
void virtual_hook (int id, void *data)
 Additional method to allow extending QIconEngineV2 without adding new virtual methods (and without breaking binary compatibility). More...
 

Properties

QThemeIconEntries m_entries
 
QString m_iconName
 
uint m_key
 

Friends

class QIconLoader
 

Additional Inherited Members

- Public Types inherited from QIconEngineV2
enum  IconEngineHook { AvailableSizesHook = 1, IconNameHook }
 These enum values are used for virtual_hook() to allow additional queries to icon engine without breaking binary compatibility. More...
 

Detailed Description

Definition at line 112 of file qiconloader_p.h.

Constructors and Destructors

◆ QIconLoaderEngine() [1/2]

QIconLoaderEngine::QIconLoaderEngine ( const QString iconName = QString())

Definition at line 312 of file qiconloader.cpp.

Referenced by clone().

313  : m_iconName(iconName), m_key(0)
314 {
315 }

◆ ~QIconLoaderEngine()

QIconLoaderEngine::~QIconLoaderEngine ( )

Definition at line 317 of file qiconloader.cpp.

318 {
319  while (!m_entries.isEmpty())
320  delete m_entries.takeLast();
321  Q_ASSERT(m_entries.size() == 0);
322 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QThemeIconEntries m_entries
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492

◆ QIconLoaderEngine() [2/2]

QIconLoaderEngine::QIconLoaderEngine ( const QIconLoaderEngine other)
private

Definition at line 324 of file qiconloader.cpp.

325  : QIconEngineV2(other),
326  m_iconName(other.m_iconName),
327  m_key(0)
328 {
329 }
The QIconEngineV2 class provides an abstract base class for QIcon renderers.
Definition: qiconengine.h:73

Functions

◆ actualSize()

QSize QIconLoaderEngine::actualSize ( const QSize size,
QIcon::Mode  mode,
QIcon::State  state 
)
virtual

Returns the actual size of the icon the engine provides for the requested size, mode and state.

The default implementation returns the given size.

Reimplemented from QIconEngine.

Definition at line 465 of file qiconloader.cpp.

Referenced by PixmapEntry::pixmap().

467 {
468  ensureLoaded();
469 
470  QIconLoaderEngineEntry *entry = entryForSize(size);
471  if (entry) {
472  const QIconDirInfo &dir = entry->dir;
473  if (dir.type == QIconDirInfo::Scalable)
474  return size;
475  else {
476  int result = qMin<int>(dir.size, qMin(size.width(), size.height()));
477  return QSize(result, result);
478  }
479  }
480  return QIconEngineV2::actualSize(size, mode, state);
481 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
virtual QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the actual size of the icon the engine provides for the requested size, mode and state...
Definition: qiconengine.cpp:87
int width() const
Returns the width.
Definition: qsize.h:126
int height() const
Returns the height.
Definition: qsize.h:129
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QIconLoaderEngineEntry * entryForSize(const QSize &size)

◆ clone()

QIconEngineV2 * QIconLoaderEngine::clone ( ) const
virtual

Returns a clone of this icon engine.

Reimplemented from QIconEngineV2.

Definition at line 331 of file qiconloader.cpp.

332 {
333  return new QIconLoaderEngine(*this);
334 }
QIconLoaderEngine(const QString &iconName=QString())

◆ ensureLoaded()

void QIconLoaderEngine::ensureLoaded ( )
private

Definition at line 353 of file qiconloader.cpp.

Referenced by actualSize(), pixmap(), and virtual_hook().

354 {
355 
356  iconLoaderInstance()->ensureInitialized();
357 
358  if (!(iconLoaderInstance()->themeKey() == m_key)) {
359 
360  while (!m_entries.isEmpty())
361  delete m_entries.takeLast();
362 
363  Q_ASSERT(m_entries.size() == 0);
364  m_entries = iconLoaderInstance()->loadIcon(m_iconName);
365  m_key = iconLoaderInstance()->themeKey();
366  }
367 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QThemeIconEntries m_entries
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492

◆ entryForSize()

QIconLoaderEngineEntry * QIconLoaderEngine::entryForSize ( const QSize size)
private

Definition at line 430 of file qiconloader.cpp.

Referenced by actualSize(), and pixmap().

431 {
432  int iconsize = qMin(size.width(), size.height());
433 
434  // Note that m_entries are sorted so that png-files
435  // come first
436 
437  // Search for exact matches first
438  for (int i = 0; i < m_entries.count(); ++i) {
439  QIconLoaderEngineEntry *entry = m_entries.at(i);
440  if (directoryMatchesSize(entry->dir, iconsize)) {
441  return entry;
442  }
443  }
444 
445  // Find the minimum distance icon
446  int minimalSize = INT_MAX;
448  for (int i = 0; i < m_entries.count(); ++i) {
449  QIconLoaderEngineEntry *entry = m_entries.at(i);
450  int distance = directorySizeDistance(entry->dir, iconsize);
451  if (distance < minimalSize) {
452  minimalSize = distance;
453  closestMatch = entry;
454  }
455  }
456  return closestMatch;
457 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int width() const
Returns the width.
Definition: qsize.h:126
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize)
static int distance(QWidget *source, QWidget *target, QAccessible::RelationFlag relation)
QThemeIconEntries m_entries
int height() const
Returns the height.
Definition: qsize.h:129
static int directorySizeDistance(const QIconDirInfo &dir, int iconsize)
static int closestMatch(QRgb pixel, const QVector< QRgb > &clut)
Definition: qimage.cpp:4015
#define INT_MAX

◆ hasIcon()

bool QIconLoaderEngine::hasIcon ( ) const
private

Definition at line 347 of file qiconloader.cpp.

348 {
349  return !(m_entries.isEmpty());
350 }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QThemeIconEntries m_entries

◆ key()

QString QIconLoaderEngine::key ( ) const
privatevirtual

Returns a key that identifies this icon engine.

Reimplemented from QIconEngineV2.

Definition at line 533 of file qiconloader.cpp.

Referenced by PixmapEntry::pixmap().

534 {
535  return QLatin1String("QIconLoaderEngine");
536 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ paint()

void QIconLoaderEngine::paint ( QPainter painter,
const QRect rect,
QIcon::Mode  mode,
QIcon::State  state 
)
virtual

Uses the given painter to paint the icon with the required mode and state into the rectangle rect.

Implements QIconEngine.

Definition at line 369 of file qiconloader.cpp.

371 {
372  QSize pixmapSize = rect.size();
373 #if defined(Q_WS_MAC)
374  pixmapSize *= qt_mac_get_scalefactor();
375 #endif
376  painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
377 }
CGFloat qt_mac_get_scalefactor()
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the icon as a pixmap with the required size, mode, and state.
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ pixmap()

QPixmap QIconLoaderEngine::pixmap ( const QSize size,
QIcon::Mode  mode,
QIcon::State  state 
)
virtual

Returns the icon as a pixmap with the required size, mode, and state.

The default implementation creates a new pixmap and calls paint() to fill it.

Reimplemented from QIconEngine.

Definition at line 521 of file qiconloader.cpp.

Referenced by paint().

523 {
524  ensureLoaded();
525 
526  QIconLoaderEngineEntry *entry = entryForSize(size);
527  if (entry)
528  return entry->pixmap(size, mode, state);
529 
530  return QPixmap();
531 }
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QIconLoaderEngineEntry * entryForSize(const QSize &size)
virtual QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)=0

◆ read()

bool QIconLoaderEngine::read ( QDataStream in)
virtual

Reads icon engine contents from the QDataStream in.

Returns true if the contents were read; otherwise returns false.

QIconEngineV2's default implementation always return false.

Reimplemented from QIconEngineV2.

Definition at line 336 of file qiconloader.cpp.

336  {
337  in >> m_iconName;
338  return true;
339 }

◆ virtual_hook()

void QIconLoaderEngine::virtual_hook ( int  id,
void *  data 
)
privatevirtual

Additional method to allow extending QIconEngineV2 without adding new virtual methods (and without breaking binary compatibility).

Since
4.5

The actual action and format of data depends on id argument which is in fact a constant from IconEngineHook enum.

See also
IconEngineHook

Reimplemented from QIconEngineV2.

Definition at line 538 of file qiconloader.cpp.

539 {
540  ensureLoaded();
541 
542  switch (id) {
544  {
546  = *reinterpret_cast<QIconEngineV2::AvailableSizesArgument*>(data);
547  const QList<QIconDirInfo> directoryKey = iconLoaderInstance()->theme().keyList();
548  arg.sizes.clear();
549 
550  // Gets all sizes from the DirectoryInfo entries
551  for (int i = 0 ; i < m_entries.size() ; ++i) {
552  int size = m_entries.at(i)->dir.size;
553  arg.sizes.append(QSize(size, size));
554  }
555  }
556  break;
558  {
559  QString &name = *reinterpret_cast<QString*>(data);
560  name = m_iconName;
561  }
562  break;
563  default:
565  }
566 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
This struct represents arguments to virtual_hook() function when id parameter is QIconEngineV2::Avail...
Definition: qiconengine.h:85
const char * name
virtual void virtual_hook(int id, void *data)
Additional method to allow extending QIconEngineV2 without adding new virtual methods (and without br...
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QSize > sizes
image sizes that are available with specified mode and
Definition: qiconengine.h:89
static const char * data(const QByteArray &arr)
void clear()
Removes all items from the list.
Definition: qlist.h:764
QThemeIconEntries m_entries
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ write()

bool QIconLoaderEngine::write ( QDataStream out) const
virtual

Writes the contents of this engine to the QDataStream out.

Returns true if the contents were written; otherwise returns false.

QIconEngineV2's default implementation always return false.

Reimplemented from QIconEngineV2.

Definition at line 341 of file qiconloader.cpp.

342 {
343  out << m_iconName;
344  return true;
345 }

Friends and Related Functions

◆ QIconLoader

friend class QIconLoader
friend

Definition at line 136 of file qiconloader_p.h.

Properties

◆ m_entries

QThemeIconEntries QIconLoaderEngine::m_entries
private

◆ m_iconName

QString QIconLoaderEngine::m_iconName
private

Definition at line 133 of file qiconloader_p.h.

Referenced by ensureLoaded(), read(), virtual_hook(), and write().

◆ m_key

uint QIconLoaderEngine::m_key
private

Definition at line 134 of file qiconloader_p.h.

Referenced by ensureLoaded().


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