From 1e7b4e396ec3bacc1a769208b990c5e0450f0d3a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 26 Nov 2010 10:41:38 +0100 Subject: Declarative: Fix compiler warnings (Linux/g++) Reviewed-by: Kai Koehne --- src/declarative/debugger/qdeclarativedebugservice.cpp | 8 +++++--- src/declarative/qml/qdeclarativeengine.cpp | 3 ++- src/declarative/qml/qdeclarativepropertycache.cpp | 1 + src/declarative/util/qdeclarativepixmapcache.cpp | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/declarative/debugger/qdeclarativedebugservice.cpp b/src/declarative/debugger/qdeclarativedebugservice.cpp index 8c86ae8..41a6962 100644 --- a/src/declarative/debugger/qdeclarativedebugservice.cpp +++ b/src/declarative/debugger/qdeclarativedebugservice.cpp @@ -226,9 +226,11 @@ QDeclarativeDebugServer *QDeclarativeDebugServer::instance() server->waitForConnection(); } } else { - qWarning(QString::fromAscii("QDeclarativeDebugServer: Ignoring \"-qmljsdebugger=%1\". " - "Format is -qmljsdebugger=port:[,block]").arg( - appD->qmljsDebugArgumentsString()).toAscii().constData()); + const QString message = + QString::fromAscii("QDeclarativeDebugServer: Ignoring \"-qmljsdebugger=%1\". " + "Format is -qmljsdebugger=port:[,block]"). + arg(appD->qmljsDebugArgumentsString()); + qWarning("%s", qPrintable(message)); } } #endif diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 808ba68..19dfcea 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -2225,8 +2225,9 @@ bool QDeclarative_isFileCaseCorrect(const QString &fileName) if (a != c) return false; } +#else + Q_UNUSED(fileName) #endif - return true; } diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 0adcdbd..af3d53f 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -321,6 +321,7 @@ void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaOb Q_ASSERT(engine); Q_ASSERT(metaObject); QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine); + Q_UNUSED(enginePriv) clear(); diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index a07b1bb..380d9bc 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -684,7 +684,7 @@ void QDeclarativePixmapStore::timerEvent(QTimerEvent *) } QDeclarativePixmapReply::QDeclarativePixmapReply(QDeclarativePixmapData *d) -: data(d), reader(0), loading(false), redirectCount(0), requestSize(d->requestSize) +: data(d), reader(0), requestSize(d->requestSize), loading(false), redirectCount(0) { if (finishedIndex == -1) { finishedIndex = QDeclarativePixmapReply::staticMetaObject.indexOfSignal("finished()"); -- cgit v0.12 From 2d7464febd762203a9bbfc6e202913eb93253f98 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 26 Nov 2010 10:45:17 +0100 Subject: Fix whitespace in previous 1e7b4e396ec3bacc1a769208b990c5e0450f0d3a --- src/declarative/debugger/qdeclarativedebugservice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/debugger/qdeclarativedebugservice.cpp b/src/declarative/debugger/qdeclarativedebugservice.cpp index 41a6962..849df73 100644 --- a/src/declarative/debugger/qdeclarativedebugservice.cpp +++ b/src/declarative/debugger/qdeclarativedebugservice.cpp @@ -226,7 +226,7 @@ QDeclarativeDebugServer *QDeclarativeDebugServer::instance() server->waitForConnection(); } } else { - const QString message = + const QString message = QString::fromAscii("QDeclarativeDebugServer: Ignoring \"-qmljsdebugger=%1\". " "Format is -qmljsdebugger=port:[,block]"). arg(appD->qmljsDebugArgumentsString()); -- cgit v0.12 From a061f032bc36f03d31ba39d2565857d1a14d9112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 26 Nov 2010 12:45:08 +0100 Subject: Fixed OpenGL state getting out of sync. Forward begin / endNativePainting from the emulation paint engine. Task-number: QTBUG-15498 Reviewed-by: Gunnar Sletta --- src/gui/painting/qemulationpaintengine.cpp | 9 +++++++++ src/gui/painting/qemulationpaintengine_p.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/gui/painting/qemulationpaintengine.cpp b/src/gui/painting/qemulationpaintengine.cpp index 0510b10..714d5de 100644 --- a/src/gui/painting/qemulationpaintengine.cpp +++ b/src/gui/painting/qemulationpaintengine.cpp @@ -268,6 +268,15 @@ void QEmulationPaintEngine::setState(QPainterState *s) real_engine->setState(s); } +void QEmulationPaintEngine::beginNativePainting() +{ + real_engine->beginNativePainting(); +} + +void QEmulationPaintEngine::endNativePainting() +{ + real_engine->endNativePainting(); +} void QEmulationPaintEngine::fillBGRect(const QRectF &r) { diff --git a/src/gui/painting/qemulationpaintengine_p.h b/src/gui/painting/qemulationpaintengine_p.h index 5835f10..e283645 100644 --- a/src/gui/painting/qemulationpaintengine_p.h +++ b/src/gui/painting/qemulationpaintengine_p.h @@ -93,6 +93,9 @@ public: virtual void setState(QPainterState *s); + virtual void beginNativePainting(); + virtual void endNativePainting(); + virtual uint flags() const {return QPaintEngineEx::IsEmulationEngine | QPaintEngineEx::DoNotEmulate;} inline QPainterState *state() { return (QPainterState *)QPaintEngine::state; } -- cgit v0.12 From 3aabc92c72bdd9f7e7bc67dd22dae203033e958a Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 30 Nov 2010 08:33:25 +1000 Subject: Fix resource leak in QEgl::getCompatibleVisualld() Contributed patch. Task-number: QT-4335 Reviewed-by: Daniel Pope --- src/gui/egl/qegl_x11.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/egl/qegl_x11.cpp b/src/gui/egl/qegl_x11.cpp index 15cc109..29415ed 100644 --- a/src/gui/egl/qegl_x11.cpp +++ b/src/gui/egl/qegl_x11.cpp @@ -165,8 +165,10 @@ VisualID QEgl::getCompatibleVisualId(EGLConfig config) if (chosenVisualInfo) { // Skip size checks if implementation supports non-matching visual // and config (http://bugreports.qt.nokia.com/browse/QTBUG-9444). - if (QEgl::hasExtension("EGL_NV_post_convert_rounding")) + if (QEgl::hasExtension("EGL_NV_post_convert_rounding")) { + XFree(chosenVisualInfo); return visualId; + } int visualRedSize = countBits(chosenVisualInfo->red_mask); int visualGreenSize = countBits(chosenVisualInfo->green_mask); -- cgit v0.12 From 6f18ee7ce50bc9b2688079e923a34c08117b3eb8 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 1 Dec 2010 11:15:46 +1000 Subject: Fix BorderImage painting at sizes less than margin size. If the width < left+right margins or height < top+bottom margins the image was painted with the complete margins, resulting in an ugle pattern. This change reduces the size of the margins proportionately, which gives a much better appearance. Task-number: QTBUG-15736 Reviewed-by: Yann Bodson --- .../graphicsitems/qdeclarativeborderimage.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp index 649c8fb..c0a7d72 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp @@ -509,7 +509,7 @@ void QDeclarativeBorderImage::doUpdate() void QDeclarativeBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QDeclarativeBorderImage); - if (d->pix.isNull()) + if (d->pix.isNull() || d->width() <= 0.0 || d->height() <= 0.0) return; bool oldAA = p->testRenderHint(QPainter::Antialiasing); @@ -518,7 +518,23 @@ void QDeclarativeBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); const QDeclarativeScaleGrid *border = d->getScaleGrid(); - QMargins margins(border->left(), border->top(), border->right(), border->bottom()); + int left = border->left(); + int right = border->right(); + qreal borderWidth = left + right; + if (borderWidth > 0.0 && d->width() < borderWidth) { + qreal diff = borderWidth - d->width() - 1; + left -= qRound(diff * qreal(left) / borderWidth); + right -= qRound(diff * qreal(right) / borderWidth); + } + int top = border->top(); + int bottom = border->bottom(); + qreal borderHeight = top + bottom; + if (borderHeight > 0.0 && d->height() < borderHeight) { + qreal diff = borderHeight - d->height() - 1; + top -= qRound(diff * qreal(top) / borderHeight); + bottom -= qRound(diff * qreal(bottom) / borderHeight); + } + QMargins margins(left, top, right, bottom); QTileRules rules((Qt::TileRule)d->horizontalTileMode, (Qt::TileRule)d->verticalTileMode); qDrawBorderPixmap(p, QRect(0, 0, (int)d->width(), (int)d->height()), margins, d->pix, d->pix.rect(), margins, rules); if (d->smooth) { -- cgit v0.12 From fe90d7a3d9f00fa2ea46c0816f63c65f812c360f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 1 Dec 2010 11:29:23 +1000 Subject: Change pen correctly when drawing cached text Task-number: QTBUG-14568 --- src/declarative/graphicsitems/qdeclarativetextlayout.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp index e8da367..14a1109 100644 --- a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp @@ -361,10 +361,18 @@ void QDeclarativeTextLayout::draw(QPainter *painter, const QPointF &p) d->position = p; } + QPen oldPen = priv->state->pen; + QColor currentColor = oldPen.color(); for (int ii = 0; ii < itemCount; ++ii) { QStaticTextItem &item = d->items[ii]; + if (item.color.isValid() && currentColor != item.color) { + painter->setPen(item.color); + currentColor = item.color; + } priv->extended->drawStaticTextItem(&item); } + if (currentColor != oldPen.color()) + painter->setPen(oldPen); } QT_END_NAMESPACE -- cgit v0.12 From e46bf51f830dcc80932b9219fe608d1bc1a388ad Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 1 Dec 2010 16:03:08 +1000 Subject: Fix license header. --- doc/src/declarative/qmlinuse.qdoc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/src/declarative/qmlinuse.qdoc b/doc/src/declarative/qmlinuse.qdoc index 90ce02c..1127b4c 100644 --- a/doc/src/declarative/qmlinuse.qdoc +++ b/doc/src/declarative/qmlinuse.qdoc @@ -7,11 +7,11 @@ ** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:FDL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in a -** written agreement between you and Nokia. +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. ** ** GNU Free Documentation License ** Alternatively, this file may be used under the terms of the GNU Free -- cgit v0.12 From 1337a3e031477aa4d628d01252557dee622629ff Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 1 Dec 2010 17:30:52 +1000 Subject: ListView header is not visible initially. If the header size was not set explicitly, but determined implicitly from Text height, the view was not positioned so that the header was visible when first shown. Task-number: QTBUG-15599 Reviewed-by: Bea Lam --- .../graphicsitems/qdeclarativegridview.cpp | 16 ++++-- .../graphicsitems/qdeclarativelistview.cpp | 22 ++++--- .../qdeclarativelistview/data/header1.qml | 33 +++++++++++ .../tst_qdeclarativelistview.cpp | 67 ++++++++++++++++------ 4 files changed, 108 insertions(+), 30 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativelistview/data/header1.qml diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 4454284..1615b0f 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1769,8 +1769,10 @@ void QDeclarativeGridView::setFooter(QDeclarativeComponent *footer) d->footer = 0; } d->footerComponent = footer; - d->updateFooter(); - d->updateGrid(); + if (isComponentComplete()) { + d->updateFooter(); + d->updateGrid(); + } emit footerChanged(); } } @@ -1799,9 +1801,11 @@ void QDeclarativeGridView::setHeader(QDeclarativeComponent *header) d->header = 0; } d->headerComponent = header; - d->updateHeader(); - d->updateFooter(); - d->updateGrid(); + if (isComponentComplete()) { + d->updateHeader(); + d->updateFooter(); + d->updateGrid(); + } emit headerChanged(); } } @@ -2226,6 +2230,8 @@ void QDeclarativeGridView::componentComplete() { Q_D(QDeclarativeGridView); QDeclarativeFlickable::componentComplete(); + d->updateHeader(); + d->updateFooter(); d->updateGrid(); if (d->isValid()) { refill(); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index d1f52be..845da79 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -402,6 +402,8 @@ public: void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) { Q_Q(QDeclarativeListView); QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry); + if (!q->isComponentComplete()) + return; if (item != contentItem && (!highlight || item != highlight->item)) { if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height()) || (orient == QDeclarativeListView::Horizontal && newGeometry.width() != oldGeometry.width())) { @@ -1123,8 +1125,6 @@ void QDeclarativeListViewPrivate::updateHeader() QDeclarativeItemPrivate *itemPrivate = static_cast(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); header = new FxListItem(item, q); - if (visibleItems.isEmpty()) - visiblePos = header->size(); } } if (header) { @@ -1137,6 +1137,8 @@ void QDeclarativeListViewPrivate::updateHeader() header->setPosition(startPos - header->size()); } } else { + if (itemCount == 0) + visiblePos = header->size(); header->setPosition(0); } } @@ -2215,8 +2217,10 @@ void QDeclarativeListView::setFooter(QDeclarativeComponent *footer) d->footerComponent = footer; d->minExtentDirty = true; d->maxExtentDirty = true; - d->updateFooter(); - d->updateViewport(); + if (isComponentComplete()) { + d->updateFooter(); + d->updateViewport(); + } emit footerChanged(); } } @@ -2247,9 +2251,11 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header) d->headerComponent = header; d->minExtentDirty = true; d->maxExtentDirty = true; - d->updateHeader(); - d->updateFooter(); - d->updateViewport(); + if (isComponentComplete()) { + d->updateHeader(); + d->updateFooter(); + d->updateViewport(); + } emit headerChanged(); } } @@ -2659,6 +2665,8 @@ void QDeclarativeListView::componentComplete() Q_D(QDeclarativeListView); QDeclarativeFlickable::componentComplete(); updateSections(); + d->updateHeader(); + d->updateFooter(); if (d->isValid()) { refill(); d->moveReason = QDeclarativeListViewPrivate::SetIndex; diff --git a/tests/auto/declarative/qdeclarativelistview/data/header1.qml b/tests/auto/declarative/qdeclarativelistview/data/header1.qml new file mode 100644 index 0000000..f2ab4c1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistview/data/header1.qml @@ -0,0 +1,33 @@ +import QtQuick 1.0 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + + ListModel { id: testModel } + + ListView { + id: list + objectName: "list" + width: parent.width + anchors.top: parent.top + anchors.bottom: parent.bottom + model: testModel + delegate: Text { + objectName: "wrapper" + font.pointSize: 20 + text: index + } + footer: Rectangle { + width: parent.width + height: 40 + color: "green" + } + header: Text { objectName: "header"; text: "Header" } + } + + Component.onCompleted: { + for (var i=0; i<30; i++) testModel.append({"name" : i, "val": i}) + } +} diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 295a75d..759caf2 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -1664,32 +1664,63 @@ void tst_QDeclarativeListView::QTBUG_11105() void tst_QDeclarativeListView::header() { - QDeclarativeView *canvas = createView(); + { + QDeclarativeView *canvas = createView(); - TestModel model; - for (int i = 0; i < 30; i++) - model.addItem("Item" + QString::number(i), ""); + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); - QDeclarativeContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testModel", &model); + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); - canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/header.qml")); - qApp->processEvents(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/header.qml")); + qApp->processEvents(); - QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); - QTRY_VERIFY(listview != 0); + QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); + QTRY_VERIFY(listview != 0); - QDeclarativeItem *contentItem = listview->contentItem(); - QTRY_VERIFY(contentItem != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); - QDeclarativeText *header = findItem(contentItem, "header"); - QVERIFY(header); - QCOMPARE(header->y(), 0.0); + QDeclarativeText *header = findItem(contentItem, "header"); + QVERIFY(header); + QCOMPARE(header->y(), 0.0); - QCOMPARE(listview->contentY(), 0.0); + QCOMPARE(listview->contentY(), 0.0); - model.clear(); - QTRY_COMPARE(header->y(), 0.0); + model.clear(); + QTRY_COMPARE(header->y(), 0.0); + + delete canvas; + } + { + QDeclarativeView *canvas = createView(); + + TestModel model; + + QDeclarativeContext *ctxt = canvas->rootContext(); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/header1.qml")); + qApp->processEvents(); + + QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); + QTRY_VERIFY(listview != 0); + + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QDeclarativeText *header = findItem(contentItem, "header"); + QVERIFY(header); + QCOMPARE(header->y(), 0.0); + + QCOMPARE(listview->contentY(), 0.0); + + model.clear(); + QTRY_COMPARE(header->y(), 0.0); + + delete canvas; + } } void tst_QDeclarativeListView::footer() -- cgit v0.12 From 5822db01277a19d8424b1f0d55868a82c8e719e6 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 1 Dec 2010 08:55:47 +0100 Subject: Fix two minor doc errors Task-number: QTBUG-14929, QTBUG-15739 Reviewed-by: TrustMe --- doc/src/platforms/emb-envvars.qdoc | 2 +- src/corelib/tools/qalgorithms.qdoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/platforms/emb-envvars.qdoc b/doc/src/platforms/emb-envvars.qdoc index 1d109b4..3f318eb 100644 --- a/doc/src/platforms/emb-envvars.qdoc +++ b/doc/src/platforms/emb-envvars.qdoc @@ -112,7 +112,7 @@ device, e.g., \c /dev/mouse for mouse devices and \c /dev/ts for touch panels. - Multiple keyboard drivers can be specified in one go: + Multiple mouse drivers can be specified in one go: \snippet doc/src/snippets/code/doc_src_emb-envvars.qdoc 3 diff --git a/src/corelib/tools/qalgorithms.qdoc b/src/corelib/tools/qalgorithms.qdoc index 898f940..cd33f28 100644 --- a/src/corelib/tools/qalgorithms.qdoc +++ b/src/corelib/tools/qalgorithms.qdoc @@ -266,7 +266,7 @@ \overload - This is the same as qFind(\a{container}.begin(), \a{container}.end(), value); + This is the same as qFind(\a{container}.constBegin(), \a{container}.constEnd(), value); */ /*! \fn void qCount(InputIterator begin, InputIterator end, const T &value, Size &n) -- cgit v0.12 From de30288bb108d70cd66774c3beb7497efb5d0e6d Mon Sep 17 00:00:00 2001 From: aavit Date: Tue, 30 Nov 2010 15:31:09 +0100 Subject: Workaround for certain malformed PNGs that lack the final crc bytes Task-number: QT-4103 Reviewed-by: gunnar --- src/gui/image/qpnghandler.cpp | 80 +++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index 935aba0..a4d669b 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -82,6 +82,41 @@ QT_BEGIN_NAMESPACE Never to grayscale. */ +class QPngHandlerPrivate +{ +public: + enum State { + Ready, + ReadHeader, + ReadingEnd, + Error + }; + + QPngHandlerPrivate(QPngHandler *qq) + : gamma(0.0), quality(2), png_ptr(0), info_ptr(0), + end_info(0), row_pointers(0), state(Ready), q(qq) + { } + + float gamma; + int quality; + QString description; + + png_struct *png_ptr; + png_info *info_ptr; + png_info *end_info; + png_byte **row_pointers; + + bool readPngHeader(); + bool readPngImage(QImage *image); + + QImage::Format readImageFormat(); + + State state; + + QPngHandler *q; +}; + + #if defined(Q_C_CALLBACKS) extern "C" { #endif @@ -118,7 +153,15 @@ private: static void CALLBACK_CALL_TYPE iod_read_fn(png_structp png_ptr, png_bytep data, png_size_t length) { - QIODevice *in = (QIODevice *)png_get_io_ptr(png_ptr); + QPngHandlerPrivate *d = (QPngHandlerPrivate *)png_get_io_ptr(png_ptr); + QIODevice *in = d->q->device(); + + if (d->state == QPngHandlerPrivate::ReadingEnd && in->atEnd() && length == 4) { + // Workaround for certain malformed PNGs that lack the final crc bytes + uchar endcrc[4] = { 0xae, 0x42, 0x60, 0x82 }; + qMemCopy(data, endcrc, 4); + return; + } while (length) { int nr = in->read((char*)data, length); @@ -314,38 +357,6 @@ static void CALLBACK_CALL_TYPE qt_png_warning(png_structp /*png_ptr*/, png_const } #endif -class QPngHandlerPrivate -{ -public: - enum State { - Ready, - ReadHeader, - Error - }; - - QPngHandlerPrivate(QPngHandler *qq) - : gamma(0.0), quality(2), png_ptr(0), info_ptr(0), - end_info(0), row_pointers(0), state(Ready), q(qq) - { } - - float gamma; - int quality; - QString description; - - png_struct *png_ptr; - png_info *info_ptr; - png_info *end_info; - png_byte **row_pointers; - - bool readPngHeader(); - bool readPngImage(QImage *image); - - QImage::Format readImageFormat(); - - State state; - - QPngHandler *q; -}; /*! \internal @@ -379,7 +390,7 @@ bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngHeader() return false; } - png_set_read_fn(png_ptr, q->device(), iod_read_fn); + png_set_read_fn(png_ptr, this, iod_read_fn); png_read_info(png_ptr, info_ptr); #ifndef QT_NO_IMAGE_TEXT @@ -505,6 +516,7 @@ bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngImage(QImage *outImage) } #endif + state = ReadingEnd; png_read_end(png_ptr, end_info); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); delete [] row_pointers; -- cgit v0.12 From fa72ccc5076e80c9a4c51501d8ff7c8161abfdeb Mon Sep 17 00:00:00 2001 From: aavit Date: Wed, 1 Dec 2010 11:52:00 +0100 Subject: Improvement of de30288: handle PNGs having 1 to 4 bytes truncated. Task-number: QT-4103 Reviewed-by: trustme --- src/gui/image/qpnghandler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index a4d669b..1a78bae 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -156,10 +156,11 @@ void CALLBACK_CALL_TYPE iod_read_fn(png_structp png_ptr, png_bytep data, png_siz QPngHandlerPrivate *d = (QPngHandlerPrivate *)png_get_io_ptr(png_ptr); QIODevice *in = d->q->device(); - if (d->state == QPngHandlerPrivate::ReadingEnd && in->atEnd() && length == 4) { + if (d->state == QPngHandlerPrivate::ReadingEnd && !in->isSequential() && (in->size() - in->pos()) < 4 && length == 4) { // Workaround for certain malformed PNGs that lack the final crc bytes uchar endcrc[4] = { 0xae, 0x42, 0x60, 0x82 }; qMemCopy(data, endcrc, 4); + in->seek(in->size()); return; } -- cgit v0.12