mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kdeui: minor KPixmapSequence optimization
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
d24e1c1437
commit
ecb617b9c8
2 changed files with 19 additions and 27 deletions
|
@ -20,36 +20,34 @@
|
|||
|
||||
#include "kpixmapsequence.h"
|
||||
|
||||
#include <QtGui/QPixmap>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtCore/QVector>
|
||||
#include <QPainter>
|
||||
#include <QVector>
|
||||
|
||||
#include <kiconloader.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
|
||||
class KPixmapSequence::Private : public QSharedData
|
||||
{
|
||||
public:
|
||||
QVector<QPixmap> mFrames;
|
||||
|
||||
void loadSequence(const QPixmap& bigPixmap, const QSize &frameSize);
|
||||
void loadSequence(const QPixmap &bigPixmap, const QSize &frameSize);
|
||||
};
|
||||
|
||||
|
||||
void KPixmapSequence::Private::loadSequence(const QPixmap& bigPixmap, const QSize &frameSize)
|
||||
void KPixmapSequence::Private::loadSequence(const QPixmap &bigPixmap, const QSize &frameSize)
|
||||
{
|
||||
if(bigPixmap.isNull()) {
|
||||
if (bigPixmap.isNull()) {
|
||||
kWarning() << "Invalid pixmap specified.";
|
||||
return;
|
||||
}
|
||||
|
||||
QSize size(frameSize);
|
||||
if(!size.isValid()) {
|
||||
if (!size.isValid()) {
|
||||
size = QSize(bigPixmap.width(), bigPixmap.width());
|
||||
}
|
||||
if(bigPixmap.width() % size.width() ||
|
||||
bigPixmap.height() % size.height()) {
|
||||
if (bigPixmap.width() % size.width() ||
|
||||
bigPixmap.height() % size.height()) {
|
||||
kWarning() << "Invalid framesize.";
|
||||
return;
|
||||
}
|
||||
|
@ -61,15 +59,14 @@ void KPixmapSequence::Private::loadSequence(const QPixmap& bigPixmap, const QSiz
|
|||
int pos = 0;
|
||||
for (int row = 0; row < rowCount; ++row) {
|
||||
for (int col = 0; col < colCount; ++col) {
|
||||
QPixmap pix = bigPixmap.copy(col * size.width(), row * size.height(), size.width(), size.height());
|
||||
mFrames[pos++] = pix;
|
||||
mFrames[pos++] = bigPixmap.copy(col * size.width(), row * size.height(), size.width(), size.height());;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
KPixmapSequence::KPixmapSequence()
|
||||
: d(new Private)
|
||||
: d(new Private())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -81,14 +78,14 @@ KPixmapSequence::KPixmapSequence(const KPixmapSequence &other)
|
|||
|
||||
|
||||
KPixmapSequence::KPixmapSequence(const QPixmap &bigPixmap, const QSize &frameSize)
|
||||
: d(new Private)
|
||||
: d(new Private())
|
||||
{
|
||||
d->loadSequence(bigPixmap, frameSize);
|
||||
}
|
||||
|
||||
|
||||
KPixmapSequence::KPixmapSequence(const QString &xdgIconName, int size)
|
||||
: d(new Private)
|
||||
: d(new Private())
|
||||
{
|
||||
d->loadSequence(QPixmap(KIconLoader::global()->iconPath(xdgIconName, -size)), QSize(size, size));
|
||||
}
|
||||
|
@ -98,8 +95,7 @@ KPixmapSequence::~KPixmapSequence()
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
KPixmapSequence &KPixmapSequence::operator=(const KPixmapSequence & other)
|
||||
KPixmapSequence& KPixmapSequence::operator=(const KPixmapSequence &other)
|
||||
{
|
||||
d = other.d;
|
||||
return *this;
|
||||
|
@ -111,13 +107,11 @@ bool KPixmapSequence::isValid() const
|
|||
return !isEmpty();
|
||||
}
|
||||
|
||||
|
||||
bool KPixmapSequence::isEmpty() const
|
||||
{
|
||||
return d->mFrames.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
QSize KPixmapSequence::frameSize() const
|
||||
{
|
||||
if (isEmpty()) {
|
||||
|
@ -133,7 +127,6 @@ int KPixmapSequence::frameCount() const
|
|||
return d->mFrames.size();
|
||||
}
|
||||
|
||||
|
||||
QPixmap KPixmapSequence::frameAt(int index) const
|
||||
{
|
||||
if (isEmpty()) {
|
||||
|
|
|
@ -18,17 +18,16 @@
|
|||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _K_PIXMAPSEQUENCE_H_
|
||||
#define _K_PIXMAPSEQUENCE_H_
|
||||
#ifndef KPIXMAPSEQUENCE_H
|
||||
#define KPIXMAPSEQUENCE_H
|
||||
|
||||
#include <QtCore/qshareddata.h>
|
||||
#include <QtCore/qsize.h>
|
||||
#include <QSharedDataPointer>
|
||||
#include <QSize>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "kdeui_export.h"
|
||||
#include <kiconloader.h>
|
||||
|
||||
#include <QPixmap>
|
||||
|
||||
/**
|
||||
* \class KPixmapSequence kpixmapsequence.h KPixmapSequence
|
||||
*
|
||||
|
@ -119,4 +118,4 @@ private:
|
|||
QSharedDataPointer<Private> d;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // KPIXMAPSEQUENCE_H
|
||||
|
|
Loading…
Add table
Reference in a new issue