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

The QtIcoHandler class provides support for the ICO image format. More...

#include <qicohandler.h>

Inheritance diagram for QtIcoHandler:
QImageIOHandler

Public Functions

bool canRead () const
 Verifies if some values (magic bytes) are set as expected in the header of the file. More...
 
int imageCount () const
 Reimplemented Function More...
 
bool jumpToImage (int imageNumber)
 Reimplemented Function More...
 
bool jumpToNextImage ()
 Reimplemented Function More...
 
QByteArray name () const
 Return the common identifier of the format. More...
 
QVariant option (ImageOption option) const
 Returns the value assigned to option as a QVariant. More...
 
 QtIcoHandler (QIODevice *device)
 Constructs an instance of QtIcoHandler initialized to use device. More...
 
bool read (QImage *image)
 Reimplemented Function More...
 
bool supportsOption (ImageOption option) const
 Returns true if the QImageIOHandler supports the option option; otherwise returns false. More...
 
bool write (const QImage &image)
 Reimplemented Function More...
 
virtual ~QtIcoHandler ()
 Destructor for QtIcoHandler. More...
 
- Public Functions inherited from QImageIOHandler
virtual int currentImageNumber () const
 For image formats that support animation, this function returns the sequence number of the current image in the animation. More...
 
virtual QRect currentImageRect () const
 Returns the rect of the current image. More...
 
QIODevicedevice () const
 Returns the device currently assigned to the QImageIOHandler. More...
 
QByteArray format () const
 Returns the format that is currently assigned to QImageIOHandler. More...
 
virtual int loopCount () const
 For image formats that support animation, this function returns the number of times the animation should loop. More...
 
virtual int nextImageDelay () const
 For image formats that support animation, this function returns the number of milliseconds to wait until reading the next image. More...
 
 QImageIOHandler ()
 Constructs a QImageIOHandler object. More...
 
void setDevice (QIODevice *device)
 Sets the device of the QImageIOHandler to device. More...
 
void setFormat (const QByteArray &format)
 Sets the format of the QImageIOHandler to format. More...
 
void setFormat (const QByteArray &format) const
 Sets the format of the QImageIOHandler to format. More...
 
virtual void setOption (ImageOption option, const QVariant &value)
 Sets the option option with the value value. More...
 
virtual ~QImageIOHandler ()
 Destructs the QImageIOHandler object. More...
 

Static Public Functions

static bool canRead (QIODevice *device)
 This static function is used by the plugin code, and is provided for convenience only. More...
 

Properties

int m_currentIconIndex
 
ICOReaderm_pICOReader
 

Additional Inherited Members

- Public Types inherited from QImageIOHandler
enum  ImageOption {
  Size, ClipRect, Description, ScaledClipRect,
  ScaledSize, CompressionRatio, Gamma, Quality,
  Name, SubType, IncrementalReading, Endianness,
  Animation, BackgroundColor, ImageFormat
}
 This enum describes the different options supported by QImageIOHandler. More...
 
- Protected Functions inherited from QImageIOHandler
 QImageIOHandler (QImageIOHandlerPrivate &dd)
 Constructs a QImageIOHandler object, using the private member dd. More...
 
- Protected Variables inherited from QImageIOHandler
QScopedPointer< QImageIOHandlerPrivated_ptr
 

Detailed Description

The QtIcoHandler class provides support for the ICO image format.

Since
4.4
Warning
This function is not part of the public interface.

Definition at line 49 of file qicohandler.h.

Constructors and Destructors

◆ QtIcoHandler()

QtIcoHandler::QtIcoHandler ( QIODevice device)

Constructs an instance of QtIcoHandler initialized to use device.

Definition at line 769 of file qicohandler.cpp.

770 {
771  m_currentIconIndex = 0;
772  setDevice(device);
773  m_pICOReader = new ICOReader(device);
774 }
int m_currentIconIndex
Definition: qicohandler.h:71
void setDevice(QIODevice *device)
Sets the device of the QImageIOHandler to device.
ICOReader * m_pICOReader
Definition: qicohandler.h:72

◆ ~QtIcoHandler()

QtIcoHandler::~QtIcoHandler ( )
virtual

Destructor for QtIcoHandler.

Definition at line 779 of file qicohandler.cpp.

780 {
781  delete m_pICOReader;
782 }
ICOReader * m_pICOReader
Definition: qicohandler.h:72

Functions

◆ canRead() [1/2]

bool QtIcoHandler::canRead ( ) const
virtual

Verifies if some values (magic bytes) are set as expected in the header of the file.

If the magic bytes were found, it is assumed that the QtIcoHandler can read the file.

Implements QImageIOHandler.

Definition at line 812 of file qicohandler.cpp.

Referenced by QICOPlugin::capabilities().

813 {
814  bool bCanRead = false;
816  if (device) {
817  bCanRead = ICOReader::canRead(device);
818  if (bCanRead)
819  setFormat("ico");
820  } else {
821  qWarning("QtIcoHandler::canRead() called with no device");
822  }
823  return bCanRead;
824 }
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
Q_CORE_EXPORT void qWarning(const char *,...)
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
static bool canRead(QIODevice *iodev)
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66

◆ canRead() [2/2]

bool QtIcoHandler::canRead ( QIODevice device)
static

This static function is used by the plugin code, and is provided for convenience only.

device must be an opened device with pointing to the start of the header data of the ICO file.

Definition at line 829 of file qicohandler.cpp.

830 {
831  Q_ASSERT(device);
832  return ICOReader::canRead(device);
833 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static bool canRead(QIODevice *iodev)

◆ imageCount()

int QtIcoHandler::imageCount ( ) const
virtual

Reimplemented Function

Reimplemented from QImageIOHandler.

Definition at line 877 of file qicohandler.cpp.

878 {
879  return m_pICOReader->count();
880 }
ICOReader * m_pICOReader
Definition: qicohandler.h:72

◆ jumpToImage()

bool QtIcoHandler::jumpToImage ( int  imageNumber)
virtual

Reimplemented Function

Reimplemented from QImageIOHandler.

Definition at line 885 of file qicohandler.cpp.

886 {
887  if (imageNumber < imageCount()) {
888  m_currentIconIndex = imageNumber;
889  }
890 
891  return (imageNumber < imageCount()) ? true : false;
892 }
int imageCount() const
Reimplemented Function
int m_currentIconIndex
Definition: qicohandler.h:71

◆ jumpToNextImage()

bool QtIcoHandler::jumpToNextImage ( )
virtual

Reimplemented Function

Reimplemented from QImageIOHandler.

Definition at line 897 of file qicohandler.cpp.

898 {
899  return jumpToImage(m_currentIconIndex + 1);
900 }
int m_currentIconIndex
Definition: qicohandler.h:71
bool jumpToImage(int imageNumber)
Reimplemented Function

◆ name()

QByteArray QtIcoHandler::name ( ) const
virtual

Return the common identifier of the format.

For ICO format this will return "ico".

Reimplemented from QImageIOHandler.

Definition at line 868 of file qicohandler.cpp.

869 {
870  return "ico";
871 }

◆ option()

QVariant QtIcoHandler::option ( ImageOption  option) const
virtual

Returns the value assigned to option as a QVariant.

The type of the value depends on the option. For example, option(Size) returns a QSize variant.

See also
setOption(), supportsOption()

Reimplemented from QImageIOHandler.

Definition at line 784 of file qicohandler.cpp.

785 {
786  if (option == Size) {
788  qint64 oldPos = device->pos();
789  ICONDIRENTRY iconEntry;
790  if (device->seek(oldPos + ICONDIR_SIZE + (m_currentIconIndex * ICONDIRENTRY_SIZE))) {
791  if (readIconDirEntry(device, &iconEntry)) {
792  device->seek(oldPos);
793  return QSize(iconEntry.bWidth, iconEntry.bHeight);
794  }
795  }
796  if (!device->isSequential())
797  device->seek(oldPos);
798  }
799  return QVariant();
800 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define ICONDIR_SIZE
Definition: qicohandler.cpp:85
quint8 bHeight
Definition: qicohandler.cpp:68
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
Definition: qiodevice.cpp:624
#define ICONDIRENTRY_SIZE
Definition: qicohandler.cpp:76
__int64 qint64
Definition: qglobal.h:942
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
Definition: qiodevice.cpp:454
int m_currentIconIndex
Definition: qicohandler.h:71
static bool readIconDirEntry(QIODevice *iodev, ICONDIRENTRY *iconDirEntry)
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
Definition: qiodevice.cpp:659

◆ read()

bool QtIcoHandler::read ( QImage image)
virtual

Reimplemented Function

Implements QImageIOHandler.

Definition at line 838 of file qicohandler.cpp.

839 {
840  bool bSuccess = false;
842 
843  // Make sure we only write to \a image when we succeed.
844  if (!img.isNull()) {
845  bSuccess = true;
846  *image = img;
847  }
848 
849  return bSuccess;
850 }
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QImage iconAt(int index)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int m_currentIconIndex
Definition: qicohandler.h:71
ICOReader * m_pICOReader
Definition: qicohandler.h:72

◆ supportsOption()

bool QtIcoHandler::supportsOption ( ImageOption  option) const
virtual

Returns true if the QImageIOHandler supports the option option; otherwise returns false.

For example, if the QImageIOHandler supports the Size option, supportsOption(Size) must return true.

See also
setOption(), option()

Reimplemented from QImageIOHandler.

Definition at line 802 of file qicohandler.cpp.

803 {
804  return option == Size;
805 }
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.

◆ write()

bool QtIcoHandler::write ( const QImage image)
virtual

Reimplemented Function

Reimplemented from QImageIOHandler.

Definition at line 856 of file qicohandler.cpp.

857 {
859  QList<QImage> imgs;
860  imgs.append(image);
861  return ICOReader::write(device, imgs);
862 }
static bool write(QIODevice *device, const QList< QImage > &images)
Writes all the QImages in the images list to the given device.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66

Properties

◆ m_currentIconIndex

int QtIcoHandler::m_currentIconIndex
private

Definition at line 71 of file qicohandler.h.

◆ m_pICOReader

ICOReader* QtIcoHandler::m_pICOReader
private

Definition at line 72 of file qicohandler.h.


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