Paste P430

Masterwork From Distant Lands
ActivePublic

Authored by sitter on Jul 9 2019, 1:57 PM.
diff --git a/src/kpixmapsequence.cpp b/src/kpixmapsequence.cpp
index 5436226..2409762 100644
--- a/src/kpixmapsequence.cpp
+++ b/src/kpixmapsequence.cpp
@@ -26,16 +26,21 @@
#include <QPainter>
#include <QVector>
#include <QtDebug>
+#include <QImageReader>
class Q_DECL_HIDDEN KPixmapSequence::Private : public QSharedData
{
public:
QVector<QPixmap> mFrames;
- void loadSequence(const QPixmap &bigPixmap, const QSize &frameSize);
+ QString mFullPath;
+ QSize mFrameSize;
+ QPixmap mPixmap;
+
+ void loadSequence(const QPixmap &bigPixmap, const QSize &frameSize, const QSize &targetSize = QSize());
};
-void KPixmapSequence::Private::loadSequence(const QPixmap &bigPixmap, const QSize &frameSize)
+void KPixmapSequence::Private::loadSequence(const QPixmap &bigPixmap, const QSize &frameSize, const QSize &targetSize)
{
if (bigPixmap.isNull()) {
qCWarning(KWidgetsAddonsLog) << "Invalid pixmap specified.";
@@ -46,6 +51,7 @@ void KPixmapSequence::Private::loadSequence(const QPixmap &bigPixmap, const QSiz
if (!size.isValid()) {
size = QSize(bigPixmap.width(), bigPixmap.width());
}
+ qDebug() << "frameSize" << frameSize << bigPixmap.size();
if (bigPixmap.width() % size.width() ||
bigPixmap.height() % size.height()) {
qCWarning(KWidgetsAddonsLog) << "Invalid framesize.";
@@ -55,11 +61,30 @@ void KPixmapSequence::Private::loadSequence(const QPixmap &bigPixmap, const QSiz
const int rowCount = bigPixmap.height() / size.height();
const int colCount = bigPixmap.width() / size.width();
mFrames.resize(rowCount * colCount);
+ mFrameSize = frameSize;
+ mPixmap = bigPixmap;
+
+ // Scale the frames when requested. We scale the input image relative to
+ // our detected column/row count and then split that.
+ // This changes the our public frameSize and by extension the widget's
+ // sizeHint.
+ QPixmap scaledPixmap = bigPixmap;
+ if (!targetSize.isEmpty()) {
+ // To scale one most have used the path based constructor, we need to
+ // scale when reading from the file, scaling the pixmap will not actually
+ // perform a vector operation anymore!
+ Q_ASSERT(!mFullPath.isEmpty());
+ qDebug() << "SCALING";
+ QImageReader reader(mFullPath);
+ reader.setScaledSize(QSize(targetSize.width() * colCount, targetSize.height() * rowCount));
+ scaledPixmap = QPixmap::fromImage(reader.read());
+ size = targetSize;
+ }
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());
+ QPixmap pix = scaledPixmap.copy(col * size.width(), row * size.height(), size.width(), size.height());
mFrames[pos++] = pix;
}
}
@@ -84,6 +109,7 @@ KPixmapSequence::KPixmapSequence(const QPixmap &bigPixmap, const QSize &frameSiz
KPixmapSequence::KPixmapSequence(const QString &fullPath, int size)
: d(new Private)
{
+ d->mFullPath = fullPath;
d->loadSequence(QPixmap(fullPath), QSize(size, size));
}
@@ -129,3 +155,8 @@ QPixmap KPixmapSequence::frameAt(int index) const
}
return d->mFrames.at(index);
}
+
+void KPixmapSequence::setOutputFrameSize(const QSize &size)
+{
+ d->loadSequence(d->mPixmap, d->mFrameSize, size);
+}
diff --git a/src/kpixmapsequence.h b/src/kpixmapsequence.h
index 680f31f..6469e6a 100644
--- a/src/kpixmapsequence.h
+++ b/src/kpixmapsequence.h
@@ -113,6 +113,8 @@ public:
*/
QPixmap frameAt(int index) const;
+ void setOutputFrameSize(const QSize &size);
+
private:
class Private;
QSharedDataPointer<Private> d;
sitter edited the content of this paste. (Show Details)Jul 9 2019, 1:57 PM
sitter changed the title of this paste from untitled to Masterwork From Distant Lands.