• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDEUI

kpixmapsequence.cpp

Go to the documentation of this file.
00001 /*
00002   Copyright 2008 Aurélien Gâteau <agateau@kde.org>
00003   Copyright 2009 Sebastian Trueg <trueg@kde.org>
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public License
00016   along with this library; see the file COPYING.LIB.  If not, write to
00017   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018   Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "kpixmapsequence.h"
00022 
00023 #include <QtGui/QPixmap>
00024 #include <QtGui/QPainter>
00025 #include <QtCore/QVector>
00026 
00027 #include <kiconloader.h>
00028 #include <kdebug.h>
00029 
00030 
00031 class KPixmapSequence::Private : public QSharedData
00032 {
00033 public:
00034     QVector<QPixmap> mFrames;
00035 
00036     void loadSequence(const QPixmap& bigPixmap, const QSize &frameSize);
00037 };
00038 
00039 
00040 void KPixmapSequence::Private::loadSequence(const QPixmap& bigPixmap, const QSize &frameSize)
00041 {
00042     if(bigPixmap.isNull()) {
00043         kWarning() << "Invalid pixmap specified.";
00044         return;
00045     }
00046 
00047     QSize size(frameSize);
00048     if(!size.isValid()) {
00049         size = QSize(bigPixmap.width(), bigPixmap.width());
00050     }
00051     if(bigPixmap.width() % size.width() ||
00052        bigPixmap.height() % size.height()) {
00053         kWarning() << "Invalid framesize.";
00054         return;
00055     }
00056 
00057     const int rowCount = bigPixmap.height() / size.height();
00058     const int colCount = bigPixmap.width() / size.width();
00059     mFrames.resize(rowCount * colCount);
00060 
00061     int pos = 0;
00062     for (int row = 0; row < rowCount; ++row) {
00063         for (int col = 0; col < colCount; ++col) {
00064             QPixmap pix = bigPixmap.copy(col * size.width(), row * size.height(), size.width(), size.height());
00065             mFrames[pos++] = pix;
00066         }
00067     }
00068 }
00069 
00070 
00071 KPixmapSequence::KPixmapSequence()
00072         : d(new Private)
00073 {
00074 }
00075 
00076 
00077 KPixmapSequence::KPixmapSequence(const KPixmapSequence &other)
00078 {
00079     d = other.d;
00080 }
00081 
00082 
00083 KPixmapSequence::KPixmapSequence(const QPixmap &bigPixmap, const QSize &frameSize)
00084         : d(new Private)
00085 {
00086     d->loadSequence(bigPixmap, frameSize);
00087 }
00088 
00089 
00090 KPixmapSequence::KPixmapSequence(const QString &xdgIconName, int size)
00091         : d(new Private)
00092 {
00093     d->loadSequence(QPixmap(KIconLoader::global()->iconPath(xdgIconName, -size)), QSize(size, size));
00094 }
00095 
00096 
00097 KPixmapSequence::~KPixmapSequence()
00098 {
00099 }
00100 
00101 
00102 KPixmapSequence &KPixmapSequence::operator=(const KPixmapSequence & other)
00103 {
00104     d = other.d;
00105     return *this;
00106 }
00107 
00108 
00109 bool KPixmapSequence::isValid() const
00110 {
00111     return !isEmpty();
00112 }
00113 
00114 
00115 bool KPixmapSequence::isEmpty() const
00116 {
00117     return d->mFrames.isEmpty();
00118 }
00119 
00120 
00121 QSize KPixmapSequence::frameSize() const
00122 {
00123     if (isEmpty()) {
00124         kWarning() << "No frame loaded";
00125         return QSize();
00126     }
00127     return d->mFrames[0].size();
00128 }
00129 
00130 
00131 int KPixmapSequence::frameCount() const
00132 {
00133     return d->mFrames.size();
00134 }
00135 
00136 
00137 QPixmap KPixmapSequence::frameAt(int index) const
00138 {
00139     if (isEmpty()) {
00140         kWarning() << "No frame loaded";
00141         return QPixmap();
00142     }
00143     return d->mFrames.at(index);
00144 }

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal