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

KDEUI

  • kdeui
  • util
kpixmapsequence.cpp
Go to the documentation of this file.
1/*
2 Copyright 2008 Aurélien Gâteau <agateau@kde.org>
3 Copyright 2009 Sebastian Trueg <trueg@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "kpixmapsequence.h"
22
23#include <QtGui/QPixmap>
24#include <QtGui/QPainter>
25#include <QtCore/QVector>
26
27#include <kiconloader.h>
28#include <kdebug.h>
29
30
31class KPixmapSequence::Private : public QSharedData
32{
33public:
34 QVector<QPixmap> mFrames;
35
36 void loadSequence(const QPixmap& bigPixmap, const QSize &frameSize);
37};
38
39
40void KPixmapSequence::Private::loadSequence(const QPixmap& bigPixmap, const QSize &frameSize)
41{
42 if(bigPixmap.isNull()) {
43 kWarning() << "Invalid pixmap specified.";
44 return;
45 }
46
47 QSize size(frameSize);
48 if(!size.isValid()) {
49 size = QSize(bigPixmap.width(), bigPixmap.width());
50 }
51 if(bigPixmap.width() % size.width() ||
52 bigPixmap.height() % size.height()) {
53 kWarning() << "Invalid framesize.";
54 return;
55 }
56
57 const int rowCount = bigPixmap.height() / size.height();
58 const int colCount = bigPixmap.width() / size.width();
59 mFrames.resize(rowCount * colCount);
60
61 int pos = 0;
62 for (int row = 0; row < rowCount; ++row) {
63 for (int col = 0; col < colCount; ++col) {
64 QPixmap pix = bigPixmap.copy(col * size.width(), row * size.height(), size.width(), size.height());
65 mFrames[pos++] = pix;
66 }
67 }
68}
69
70
71KPixmapSequence::KPixmapSequence()
72 : d(new Private)
73{
74}
75
76
77KPixmapSequence::KPixmapSequence(const KPixmapSequence &other)
78{
79 d = other.d;
80}
81
82
83KPixmapSequence::KPixmapSequence(const QPixmap &bigPixmap, const QSize &frameSize)
84 : d(new Private)
85{
86 d->loadSequence(bigPixmap, frameSize);
87}
88
89
90KPixmapSequence::KPixmapSequence(const QString &xdgIconName, int size)
91 : d(new Private)
92{
93 d->loadSequence(QPixmap(KIconLoader::global()->iconPath(xdgIconName, -size)), QSize(size, size));
94}
95
96
97KPixmapSequence::~KPixmapSequence()
98{
99}
100
101
102KPixmapSequence &KPixmapSequence::operator=(const KPixmapSequence & other)
103{
104 d = other.d;
105 return *this;
106}
107
108
109bool KPixmapSequence::isValid() const
110{
111 return !isEmpty();
112}
113
114
115bool KPixmapSequence::isEmpty() const
116{
117 return d->mFrames.isEmpty();
118}
119
120
121QSize KPixmapSequence::frameSize() const
122{
123 if (isEmpty()) {
124 kWarning() << "No frame loaded";
125 return QSize();
126 }
127 return d->mFrames[0].size();
128}
129
130
131int KPixmapSequence::frameCount() const
132{
133 return d->mFrames.size();
134}
135
136
137QPixmap KPixmapSequence::frameAt(int index) const
138{
139 if (isEmpty()) {
140 kWarning() << "No frame loaded";
141 return QPixmap();
142 }
143 return d->mFrames.at(index);
144}
KIconLoader::global
static KIconLoader * global()
Returns the global icon loader initialized with the global KComponentData.
KPixmapSequence
Loads and gives access to the frames of a typical multi-row pixmap as often used for spinners.
Definition: kpixmapsequence.h:46
KPixmapSequence::frameSize
QSize frameSize() const
Definition: kpixmapsequence.cpp:121
KPixmapSequence::~KPixmapSequence
~KPixmapSequence()
Destructor.
Definition: kpixmapsequence.cpp:97
KPixmapSequence::KPixmapSequence
KPixmapSequence()
Create an empty sequence.
Definition: kpixmapsequence.cpp:71
KPixmapSequence::operator=
KPixmapSequence & operator=(const KPixmapSequence &other)
Create a copy of other.
Definition: kpixmapsequence.cpp:102
KPixmapSequence::isValid
bool isValid() const
Definition: kpixmapsequence.cpp:109
KPixmapSequence::frameCount
int frameCount() const
The number of frames in this sequence.
Definition: kpixmapsequence.cpp:131
KPixmapSequence::isEmpty
bool isEmpty() const
Definition: kpixmapsequence.cpp:115
KPixmapSequence::frameAt
QPixmap frameAt(int index) const
Retrieve the frame at index.
Definition: kpixmapsequence.cpp:137
kWarning
#define kWarning
kdebug.h
kiconloader.h
kpixmapsequence.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal