From 1771526b2e13607f9e5e3cef15622f74349f4e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Thu, 28 Jan 2010 17:50:49 +0100 Subject: Warn if the plugin seems to not exist instead of simply passing. follow-up to 0585997b7dbe25ece9f60684171c16206d10d65f Task-number: related to QTBUG-7688 Reviewed-by: TRUSTME --- tests/auto/qimagereader/tst_qimagereader.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index e7cfe68..b1a5d26 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -1641,10 +1641,16 @@ void tst_QImageReader::pixelCompareWithBaseline() { QFETCH(QString, fileName); + static int enteredCount = 0; // Used for better error diagnostics if something fails. We + static int loadFailCount = 0; // don't know if the reason load() fails is that the plugin + // does not exist or because of a bug in the plugin. But if at + // least one file succeeded we know that the plugin was built. + // The other failures are then real failures. QImage icoImg; const QString inputFileName(QString::fromAscii("images/%1").arg(fileName)); QFileInfo fi(inputFileName); + ++enteredCount; // might fail if the plugin does not exist, which is ok. if (icoImg.load(inputFileName)) { icoImg = icoImg.convertToFormat(QImage::Format_ARGB32_Premultiplied); @@ -1658,6 +1664,13 @@ void tst_QImageReader::pixelCompareWithBaseline() QCOMPARE(int(baseImg.format()), int(icoImg.format())); QCOMPARE(baseImg, icoImg); #endif + } else { + ++loadFailCount; + if (enteredCount != loadFailCount) { + QFAIL("Plugin is built, but some did not load properly"); + } else { + qWarning("loading failed, check if ico plugin is built"); + } } } -- cgit v0.12 From d98d31ca34a84a03dbac20fbf1dc88c0f8fd93cb Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Fri, 29 Jan 2010 11:41:28 +0100 Subject: Doc fix. No need to put something deprecated if it's not. Reviewed-by:TrustMe --- src/gui/dialogs/qfiledialog.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 21650bb..089e04a 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -229,11 +229,10 @@ Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook \value ReadOnly Indicates that the model is readonly. \value HideNameFilterDetails Indicates if the is hidden or not. - This value is obsolete and does nothing since Qt 4.5: \value DontUseSheet In previous versions of Qt, the static functions would create a sheet by default if the static function - was given a parent. This is no longer supported in Qt 4.5, The + was given a parent. This is no longer supported and does nothing in Qt 4.5, The static functions will always be an application modal dialog. If you want to use sheets, use QFileDialog::open() instead. -- cgit v0.12 From 9e95ce2a68ef167e17dccc5789cbf3bf74712280 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Fri, 29 Jan 2010 11:39:06 +0100 Subject: Fix GL texture leaks when pixmaps are deleted This fixes quite a lot of issues: * QtOpenGL only registered qpixmap destruction hooks on X11 and those only cleanup the EGL/GLX surface, not the texture object. * The QPixmap destruction hooks were only being called from the QPixmap destructor. However, this means when a QPixmap is assigned to another QPixmap, the hooks don't get called. Task-number: QTBUG-7647 Reviewed-By: Samuel Reviewed-By: Trond --- src/gui/image/qimagepixmapcleanuphooks.cpp | 20 +-- src/gui/image/qimagepixmapcleanuphooks_p.h | 23 +-- src/gui/image/qpixmap.cpp | 12 +- src/gui/image/qpixmap_x11.cpp | 7 + src/gui/image/qpixmapdata.cpp | 11 ++ src/gui/image/qpixmapdata_p.h | 8 + src/opengl/qgl.cpp | 32 ++-- src/opengl/qgl_p.h | 9 +- src/opengl/qglpixmapfilter.cpp | 22 +-- tests/auto/qgl/qgl.pro | 4 +- tests/auto/qgl/qgl.qrc | 5 + tests/auto/qgl/tst_qgl.cpp | 240 +++++++++++++++++++++++++++++ 12 files changed, 326 insertions(+), 67 deletions(-) create mode 100644 tests/auto/qgl/qgl.qrc diff --git a/src/gui/image/qimagepixmapcleanuphooks.cpp b/src/gui/image/qimagepixmapcleanuphooks.cpp index 61d538f..ace4bb6 100644 --- a/src/gui/image/qimagepixmapcleanuphooks.cpp +++ b/src/gui/image/qimagepixmapcleanuphooks.cpp @@ -62,12 +62,12 @@ QImagePixmapCleanupHooks *QImagePixmapCleanupHooks::instance() return qt_image_and_pixmap_cleanup_hooks(); } -void QImagePixmapCleanupHooks::addPixmapModificationHook(_qt_pixmap_cleanup_hook_pm hook) +void QImagePixmapCleanupHooks::addPixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd hook) { pixmapModificationHooks.append(hook); } -void QImagePixmapCleanupHooks::addPixmapDestructionHook(_qt_pixmap_cleanup_hook_pm hook) +void QImagePixmapCleanupHooks::addPixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd hook) { pixmapDestructionHooks.append(hook); } @@ -78,12 +78,12 @@ void QImagePixmapCleanupHooks::addImageHook(_qt_image_cleanup_hook_64 hook) imageHooks.append(hook); } -void QImagePixmapCleanupHooks::removePixmapModificationHook(_qt_pixmap_cleanup_hook_pm hook) +void QImagePixmapCleanupHooks::removePixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd hook) { pixmapModificationHooks.removeAll(hook); } -void QImagePixmapCleanupHooks::removePixmapDestructionHook(_qt_pixmap_cleanup_hook_pm hook) +void QImagePixmapCleanupHooks::removePixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd hook) { pixmapDestructionHooks.removeAll(hook); } @@ -93,24 +93,24 @@ void QImagePixmapCleanupHooks::removeImageHook(_qt_image_cleanup_hook_64 hook) imageHooks.removeAll(hook); } -void QImagePixmapCleanupHooks::executePixmapModificationHooks(QPixmap* pm) +void QImagePixmapCleanupHooks::executePixmapDataModificationHooks(QPixmapData* pmd) { QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks(); for (int i = 0; i < h->pixmapModificationHooks.count(); ++i) - h->pixmapModificationHooks[i](pm); + h->pixmapModificationHooks[i](pmd); if (qt_pixmap_cleanup_hook_64) - qt_pixmap_cleanup_hook_64(pm->cacheKey()); + qt_pixmap_cleanup_hook_64(pmd->cacheKey()); } -void QImagePixmapCleanupHooks::executePixmapDestructionHooks(QPixmap* pm) +void QImagePixmapCleanupHooks::executePixmapDataDestructionHooks(QPixmapData* pmd) { QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks(); for (int i = 0; i < h->pixmapDestructionHooks.count(); ++i) - h->pixmapDestructionHooks[i](pm); + h->pixmapDestructionHooks[i](pmd); if (qt_pixmap_cleanup_hook_64) - qt_pixmap_cleanup_hook_64(pm->cacheKey()); + qt_pixmap_cleanup_hook_64(pmd->cacheKey()); } void QImagePixmapCleanupHooks::executeImageHooks(qint64 key) diff --git a/src/gui/image/qimagepixmapcleanuphooks_p.h b/src/gui/image/qimagepixmapcleanuphooks_p.h index 7176044..88dd3a6 100644 --- a/src/gui/image/qimagepixmapcleanuphooks_p.h +++ b/src/gui/image/qimagepixmapcleanuphooks_p.h @@ -58,7 +58,8 @@ QT_BEGIN_NAMESPACE typedef void (*_qt_image_cleanup_hook_64)(qint64); -typedef void (*_qt_pixmap_cleanup_hook_pm)(QPixmap*); +typedef void (*_qt_pixmap_cleanup_hook_pmd)(QPixmapData*); + class QImagePixmapCleanupHooks; @@ -71,27 +72,27 @@ public: static void enableCleanupHooks(const QPixmap &pixmap); static void enableCleanupHooks(QPixmapData *pixmapData); - // Gets called when a pixmap is about to be modified: - void addPixmapModificationHook(_qt_pixmap_cleanup_hook_pm); + // Gets called when a pixmap data is about to be modified: + void addPixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd); - // Gets called when a pixmap is about to be destroyed: - void addPixmapDestructionHook(_qt_pixmap_cleanup_hook_pm); + // Gets called when a pixmap data is about to be destroyed: + void addPixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd); // Gets called when an image is about to be modified or destroyed: void addImageHook(_qt_image_cleanup_hook_64); - void removePixmapModificationHook(_qt_pixmap_cleanup_hook_pm); - void removePixmapDestructionHook(_qt_pixmap_cleanup_hook_pm); + void removePixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd); + void removePixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd); void removeImageHook(_qt_image_cleanup_hook_64); - static void executePixmapModificationHooks(QPixmap*); - static void executePixmapDestructionHooks(QPixmap*); + static void executePixmapDataModificationHooks(QPixmapData*); + static void executePixmapDataDestructionHooks(QPixmapData*); static void executeImageHooks(qint64 key); private: QList<_qt_image_cleanup_hook_64> imageHooks; - QList<_qt_pixmap_cleanup_hook_pm> pixmapModificationHooks; - QList<_qt_pixmap_cleanup_hook_pm> pixmapDestructionHooks; + QList<_qt_pixmap_cleanup_hook_pmd> pixmapModificationHooks; + QList<_qt_pixmap_cleanup_hook_pmd> pixmapDestructionHooks; }; QT_END_NAMESPACE diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index f823fdc..d1e5c40 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -320,8 +320,6 @@ QPixmap::QPixmap(const char * const xpm[]) QPixmap::~QPixmap() { Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again - if (data && data->is_cached && data->ref == 1) // ref will be decrememnted after destructor returns - QImagePixmapCleanupHooks::executePixmapDestructionHooks(this); } /*! @@ -1025,12 +1023,8 @@ qint64 QPixmap::cacheKey() const if (isNull()) return 0; - int classKey = data->classId(); - if (classKey >= 1024) - classKey = -(classKey >> 10); - return ((((qint64) classKey) << 56) - | (((qint64) data->serialNumber()) << 32) - | ((qint64) (data->detach_no))); + Q_ASSERT(data); + return data->cacheKey(); } static void sendResizeEvents(QWidget *target) @@ -1943,7 +1937,7 @@ void QPixmap::detach() } if (data->is_cached && data->ref == 1) - QImagePixmapCleanupHooks::executePixmapModificationHooks(this); + QImagePixmapCleanupHooks::executePixmapDataModificationHooks(data.data()); #if defined(Q_WS_MAC) QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast(data.data()) : 0; diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index 0e66e09..169a2ec 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -68,6 +68,7 @@ #include "qx11info_x11.h" #include #include +#include #include @@ -1228,6 +1229,12 @@ void QX11PixmapData::fill(const QColor &fillColor) QX11PixmapData::~QX11PixmapData() { + // Cleanup hooks have to be called before the handles are freed + if (is_cached) { + QImagePixmapCleanupHooks::executePixmapDataDestructionHooks(this); + is_cached = false; + } + release(); } diff --git a/src/gui/image/qpixmapdata.cpp b/src/gui/image/qpixmapdata.cpp index 65032da..ea4fe6b 100644 --- a/src/gui/image/qpixmapdata.cpp +++ b/src/gui/image/qpixmapdata.cpp @@ -45,6 +45,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -80,6 +81,16 @@ QPixmapData::QPixmapData(PixelType pixelType, int objectId) QPixmapData::~QPixmapData() { + // Sometimes the pixmap cleanup hooks will be called from derrived classes, which will + // then set is_cached to false. For example, on X11 QtOpenGL needs to delete the GLXPixmap + // or EGL Pixmap Surface for a given pixmap _before_ the native X11 pixmap is deleted, + // otherwise some drivers will leak the GL surface. In this case, QX11PixmapData will + // call the cleanup hooks itself before deleting the native pixmap and set is_cached to + // false. + if (is_cached) { + QImagePixmapCleanupHooks::executePixmapDataDestructionHooks(this); + is_cached = false; + } } QPixmapData *QPixmapData::createCompatiblePixmapData() const diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h index 1125515..827fa18 100644 --- a/src/gui/image/qpixmapdata_p.h +++ b/src/gui/image/qpixmapdata_p.h @@ -117,6 +117,14 @@ public: inline int colorCount() const { return metric(QPaintDevice::PdmNumColors); } inline int depth() const { return d; } inline bool isNull() const { return is_null; } + inline qint64 cacheKey() const { + int classKey = id; + if (classKey >= 1024) + classKey = -(classKey >> 10); + return ((((qint64) classKey) << 56) + | (((qint64) ser_no) << 32) + | ((qint64) detach_no)); + } #if defined(Q_OS_SYMBIAN) virtual void* toNativeType(NativeType type); diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 2a60708..dd977cb 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1590,10 +1590,8 @@ QGLTextureCache::QGLTextureCache() Q_ASSERT(qt_gl_texture_cache == 0); qt_gl_texture_cache = this; - QImagePixmapCleanupHooks::instance()->addPixmapModificationHook(cleanupTextures); -#ifdef Q_WS_X11 - QImagePixmapCleanupHooks::instance()->addPixmapDestructionHook(cleanupPixmapSurfaces); -#endif + QImagePixmapCleanupHooks::instance()->addPixmapDataModificationHook(cleanupTextures); + QImagePixmapCleanupHooks::instance()->addPixmapDataDestructionHook(cleanupBeforePixmapDestruction); QImagePixmapCleanupHooks::instance()->addImageHook(imageCleanupHook); } @@ -1601,10 +1599,8 @@ QGLTextureCache::~QGLTextureCache() { qt_gl_texture_cache = 0; - QImagePixmapCleanupHooks::instance()->removePixmapModificationHook(cleanupTextures); -#ifdef Q_WS_X11 - QImagePixmapCleanupHooks::instance()->removePixmapDestructionHook(cleanupPixmapSurfaces); -#endif + QImagePixmapCleanupHooks::instance()->removePixmapDataModificationHook(cleanupTextures); + QImagePixmapCleanupHooks::instance()->removePixmapDataDestructionHook(cleanupBeforePixmapDestruction); QImagePixmapCleanupHooks::instance()->removeImageHook(imageCleanupHook); } @@ -1672,30 +1668,30 @@ void QGLTextureCache::imageCleanupHook(qint64 cacheKey) } -void QGLTextureCache::cleanupTextures(QPixmap* pixmap) +void QGLTextureCache::cleanupTextures(QPixmapData* pmd) { // ### remove when the GL texture cache becomes thread-safe if (qApp->thread() == QThread::currentThread()) { - const qint64 cacheKey = pixmap->cacheKey(); + const qint64 cacheKey = pmd->cacheKey(); QGLTexture *texture = instance()->getTexture(cacheKey); if (texture && texture->options & QGLContext::MemoryManagedBindOption) instance()->remove(cacheKey); } } -#if defined(Q_WS_X11) -void QGLTextureCache::cleanupPixmapSurfaces(QPixmap* pixmap) +void QGLTextureCache::cleanupBeforePixmapDestruction(QPixmapData* pmd) { // Remove any bound textures first: - cleanupTextures(pixmap); + cleanupTextures(pmd); + Q_ASSERT(instance()->getTexture(pmd->cacheKey()) == 0); - QPixmapData *pd = pixmap->data_ptr().data(); - if (pd->classId() == QPixmapData::X11Class) { - Q_ASSERT(pd->ref == 1); // Make sure reference counting isn't broken - QGLContextPrivate::destroyGlSurfaceForPixmap(pd); +#if defined(Q_WS_X11) + if (pmd->classId() == QPixmapData::X11Class) { + Q_ASSERT(pmd->ref == 0); // Make sure reference counting isn't broken + QGLContextPrivate::destroyGlSurfaceForPixmap(pmd); } -} #endif +} void QGLTextureCache::deleteIfEmpty() { diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index 0104f07..713b067 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -522,7 +522,7 @@ public: QSize bindCompressedTexturePVR(const char *buf, int len); }; -class QGLTextureCache { +class Q_AUTOTEST_EXPORT QGLTextureCache { public: QGLTextureCache(); ~QGLTextureCache(); @@ -539,11 +539,8 @@ public: static QGLTextureCache *instance(); static void deleteIfEmpty(); static void imageCleanupHook(qint64 cacheKey); - static void cleanupTextures(QPixmap* pixmap); -#ifdef Q_WS_X11 - // X11 needs to catch pixmap data destruction to delete EGL/GLX pixmap surfaces - static void cleanupPixmapSurfaces(QPixmap* pixmap); -#endif + static void cleanupTextures(QPixmapData* pixmap); + static void cleanupBeforePixmapDestruction(QPixmapData* pixmap); private: QCache m_cache; diff --git a/src/opengl/qglpixmapfilter.cpp b/src/opengl/qglpixmapfilter.cpp index 11011ee..37bb7c0 100644 --- a/src/opengl/qglpixmapfilter.cpp +++ b/src/opengl/qglpixmapfilter.cpp @@ -319,14 +319,14 @@ public: ~QGLBlurTextureCache(); QGLBlurTextureInfo *takeBlurTextureInfo(const QPixmap &pixmap); - bool hasBlurTextureInfo(const QPixmap &pixmap) const; + bool hasBlurTextureInfo(quint64 cacheKey) const; void insertBlurTextureInfo(const QPixmap &pixmap, QGLBlurTextureInfo *info); - void clearBlurTextureInfo(const QPixmap &pixmap); + void clearBlurTextureInfo(quint64 cacheKey); void timerEvent(QTimerEvent *event); private: - static void pixmapDestroyed(QPixmap *pixmap); + static void pixmapDestroyed(QPixmapData *pixmap); QCache cache; @@ -379,21 +379,21 @@ QGLBlurTextureInfo *QGLBlurTextureCache::takeBlurTextureInfo(const QPixmap &pixm return cache.take(pixmap.cacheKey()); } -void QGLBlurTextureCache::clearBlurTextureInfo(const QPixmap &pixmap) +void QGLBlurTextureCache::clearBlurTextureInfo(quint64 cacheKey) { - cache.remove(pixmap.cacheKey()); + cache.remove(cacheKey); } -bool QGLBlurTextureCache::hasBlurTextureInfo(const QPixmap &pixmap) const +bool QGLBlurTextureCache::hasBlurTextureInfo(quint64 cacheKey) const { - return cache.contains(pixmap.cacheKey()); + return cache.contains(cacheKey); } void QGLBlurTextureCache::insertBlurTextureInfo(const QPixmap &pixmap, QGLBlurTextureInfo *info) { static bool hookAdded = false; if (!hookAdded) { - QImagePixmapCleanupHooks::instance()->addPixmapDestructionHook(pixmapDestroyed); + QImagePixmapCleanupHooks::instance()->addPixmapDataDestructionHook(pixmapDestroyed); hookAdded = true; } @@ -406,11 +406,11 @@ void QGLBlurTextureCache::insertBlurTextureInfo(const QPixmap &pixmap, QGLBlurTe timerId = startTimer(8000); } -void QGLBlurTextureCache::pixmapDestroyed(QPixmap *pixmap) +void QGLBlurTextureCache::pixmapDestroyed(QPixmapData *pmd) { foreach (QGLBlurTextureCache *cache, blurTextureCaches) { - if (cache->hasBlurTextureInfo(*pixmap)) - cache->clearBlurTextureInfo(*pixmap); + if (cache->hasBlurTextureInfo(pmd->cacheKey())) + cache->clearBlurTextureInfo(pmd->cacheKey()); } } diff --git a/tests/auto/qgl/qgl.pro b/tests/auto/qgl/qgl.pro index 420c4bb..9116f39 100644 --- a/tests/auto/qgl/qgl.pro +++ b/tests/auto/qgl/qgl.pro @@ -6,6 +6,6 @@ load(qttest_p4) requires(contains(QT_CONFIG,opengl)) QT += opengl -SOURCES += tst_qgl.cpp - +SOURCES += tst_qgl.cpp +RESOURCES = qgl.qrc diff --git a/tests/auto/qgl/qgl.qrc b/tests/auto/qgl/qgl.qrc new file mode 100644 index 0000000..653794a --- /dev/null +++ b/tests/auto/qgl/qgl.qrc @@ -0,0 +1,5 @@ + + + ../qpixmap/images/designer.png + + diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index cf4616e..d37d727 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -56,6 +56,7 @@ #ifdef QT_BUILD_INTERNAL #include +#include #endif //TESTED_CLASS= @@ -91,6 +92,8 @@ private slots: void clipTest(); void destroyFBOAfterContext(); void shareRegister(); + void qglContextDefaultBindTexture(); + void textureCleanup(); }; tst_QGL::tst_QGL() @@ -1938,5 +1941,242 @@ void tst_QGL::shareRegister() #endif } +// Tests QGLContext::bindTexture with default options +void tst_QGL::qglContextDefaultBindTexture() +{ +#ifdef QT_BUILD_INTERNAL + QGLWidget w; + w.makeCurrent(); + + QGLContext *ctx = const_cast(w.context()); + + QImage *boundImage = new QImage(256, 256, QImage::Format_RGB32); + boundImage->fill(0xFFFFFFFF); + QPixmap *boundPixmap = new QPixmap(256, 256); + boundPixmap->fill(Qt::red); + + // Check that calling QGLContext::bindTexture with default args adds textures to cache + int startCacheItemCount = QGLTextureCache::instance()->size(); + GLuint boundImageTextureId = ctx->bindTexture(*boundImage); + GLuint boundPixmapTextureId = ctx->bindTexture(*boundPixmap); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + + // Make sure the texture IDs returned are valid: + QCOMPARE((bool)glIsTexture(boundImageTextureId), GL_TRUE); + QCOMPARE((bool)glIsTexture(boundPixmapTextureId), GL_TRUE); + + // Make sure the textures are still there after we delete the image/pixmap: + delete boundImage; + boundImage = 0; + delete boundPixmap; + boundPixmap = 0; + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + + // Make sure the textures are deleted from the cache after calling QGLContext::deleteTexture() + ctx->deleteTexture(boundImageTextureId); + ctx->deleteTexture(boundPixmapTextureId); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + + // Finally, make sure QGLContext::deleteTexture also deleted the texture IDs: + QCOMPARE((bool)glIsTexture(boundImageTextureId), GL_FALSE); + QCOMPARE((bool)glIsTexture(boundPixmapTextureId), GL_FALSE); +#endif +} + +void tst_QGL::textureCleanup() +{ +#ifdef QT_BUILD_INTERNAL + QGLWidget w; + w.resize(200,200); + w.show(); + w.makeCurrent(); + + // Test pixmaps which have been loaded via QPixmapCache are removed from the texture cache + // when the pixmap cache is cleared + { + int startCacheItemCount = QGLTextureCache::instance()->size(); + QPainter p(&w); + + QPixmap boundPixmap(":designer.png"); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + + p.drawPixmap(0, 0, boundPixmap); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + // Need to call end for the GL2 paint engine to release references to pixmap if using tfp + p.end(); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + // Check that the texture doesn't get removed from the cache when the pixmap is cleared + // as it should still be in the cache: + boundPixmap = QPixmap(); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + QPixmapCache::clear(); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + } + + // Test pixmaps which have been loaded via QPixmapCache are removed from the texture cache + // when they are explicitly removed from the pixmap cache + { + int startCacheItemCount = QGLTextureCache::instance()->size(); + QPainter p(&w); + + QPixmap boundPixmap(128, 128); + QString cacheKey = QString::fromLatin1("myPixmap"); + QPixmapCache::insert(cacheKey, boundPixmap); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + + p.drawPixmap(0, 0, boundPixmap); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + // Need to call end for the GL2 paint engine to release references to pixmap if using tfp + p.end(); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + // Check that the texture doesn't get removed from the cache when the pixmap is cleared + // as it should still be in the cache: + boundPixmap = QPixmap(); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + // Finally, we check that the texture cache entry is removed when we remove the + // pixmap cache entry, which should hold the last reference: + QPixmapCache::remove(cacheKey); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + } + + // Check images & pixmaps are removed from the cache when they are deleted + { + int startCacheItemCount = QGLTextureCache::instance()->size(); + QPainter p(&w); + + QImage *boundImage = new QImage(256, 256, QImage::Format_RGB32); + boundImage->fill(0xFFFFFFFF); + QPixmap *boundPixmap = new QPixmap(256, 256); + boundPixmap->fill(Qt::red); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + + p.drawImage(0, 0, *boundImage); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + p.drawPixmap(0, 0, *boundPixmap); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + + // Need to call end for the GL2 paint engine to release references to pixmap if using tfp + p.end(); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + + delete boundImage; + boundImage = 0; + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + delete boundPixmap; + boundPixmap = 0; + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + } + + // Check images & pixmaps are removed from the cache when they are assigned to + { + int startCacheItemCount = QGLTextureCache::instance()->size(); + QPainter p(&w); + + QImage boundImage(256, 256, QImage::Format_RGB32); + boundImage.fill(0xFFFFFFFF); + QPixmap boundPixmap(256, 256); + boundPixmap.fill(Qt::red); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + + p.drawImage(0, 0, boundImage); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + p.drawPixmap(0, 0, boundPixmap); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + + // Need to call end for the GL2 paint engine to release references to pixmap if using tfp + p.end(); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + + boundImage = QImage(64, 64, QImage::Format_RGB32); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + boundPixmap = QPixmap(64, 64); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + } + + // Check images & pixmaps are removed from the cache when they are modified (detached) + { + int startCacheItemCount = QGLTextureCache::instance()->size(); + QPainter p(&w); + + QImage boundImage(256, 256, QImage::Format_RGB32); + boundImage.fill(0xFFFFFFFF); + QPixmap boundPixmap(256, 256); + boundPixmap.fill(Qt::red); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + + p.drawImage(0, 0, boundImage); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + p.drawPixmap(0, 0, boundPixmap); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + + // Need to call end for the GL2 paint engine to release references to pixmap if using tfp + p.end(); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + + boundImage.fill(0x00000000); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + boundPixmap.fill(Qt::blue); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + } + + // Check that images/pixmaps aren't removed from the cache if a shallow copy has been made + QImage copyOfImage; + QPixmap copyOfPixmap; + int startCacheItemCount = QGLTextureCache::instance()->size(); + { + QPainter p(&w); + + QImage boundImage(256, 256, QImage::Format_RGB32); + boundImage.fill(0xFFFFFFFF); + QPixmap boundPixmap(256, 256); + boundPixmap.fill(Qt::red); + + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); + + p.drawImage(0, 0, boundImage); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + p.drawPixmap(0, 0, boundPixmap); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + + // Need to call end for the GL2 paint engine to release references to pixmap if using tfp + p.end(); + + copyOfImage = boundImage; + copyOfPixmap = boundPixmap; + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + } // boundImage & boundPixmap would have been deleted when they went out of scope + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); + + copyOfImage = QImage(); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); + + copyOfPixmap = QPixmap(); + QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); +#endif +} + QTEST_MAIN(tst_QGL) #include "tst_qgl.moc" -- cgit v0.12 From 4a5e81f5320daa82352b13e670718998b0d2d23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Fri, 29 Jan 2010 16:14:00 +0100 Subject: Fixed a crash when QPixmaps are destroyed after the ~QApplication. Destroying QPixmaps after the QApp destructor will leak native pixmap objects on X11, and it's a general rule that all GUI objects must be destroyed before the QApp destuctor is called. Task-number: QTBUG-7746 Reviewed-by: Kim --- src/gui/image/qpixmap_x11.cpp | 7 ++++++- src/gui/painting/qpainter.cpp | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index 169a2ec..e1e8a0d 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -1243,8 +1243,13 @@ void QX11PixmapData::release() delete pengine; pengine = 0; - if (!X11) + if (!X11) { +#ifndef QT_NO_DEBUG + qWarning("~QX11PixmapData(): QPixmap objects must be destroyed before the QApplication" + " object, otherwise the native pixmap object will be leaked."); +#endif return; + } if (x11_mask) { #ifndef QT_NO_XRENDER diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index cde6a2d..bf12c6b 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -7509,7 +7509,7 @@ QPaintDevice *QPainter::redirected(const QPaintDevice *device, QPoint *offset) return widgetPrivate->redirected(offset); } - if (*globalRedirectionAtomic() == 0) + if (!globalRedirectionAtomic() || *globalRedirectionAtomic() == 0) return 0; QMutexLocker locker(globalRedirectionsMutex()); @@ -7529,7 +7529,7 @@ QPaintDevice *QPainter::redirected(const QPaintDevice *device, QPoint *offset) void qt_painter_removePaintDevice(QPaintDevice *dev) { - if (*globalRedirectionAtomic() == 0) + if (!globalRedirectionAtomic() || *globalRedirectionAtomic() == 0) return; QMutex *mutex = 0; -- cgit v0.12 From 519760c4256997f26c039cb4b047c6207470b54f Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Thu, 28 Jan 2010 18:09:39 +0100 Subject: Adds convenience functions QGraphicsItemPrivate::isOpacityNull This should unify the error constant used along the code and enforce qreal to avoid unnecessary double conversions. Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsitem_p.h | 10 ++++++++-- src/gui/graphicsview/qgraphicsscene.cpp | 7 ++++--- src/gui/graphicsview/qgraphicssceneindex.cpp | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 5ad6cd5..b3ca3b5 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -358,14 +358,20 @@ public: return o; } + inline bool isOpacityNull() const + { return (opacity < qreal(0.001)); } + + static inline bool isOpacityNull(qreal opacity) + { return (opacity < qreal(0.001)); } + inline bool isFullyTransparent() const { - if (opacity < 0.001) + if (isOpacityNull()) return true; if (!parent) return false; - return calcEffectiveOpacity() < 0.001; + return isOpacityNull(calcEffectiveOpacity()); } inline qreal effectiveOpacity() const { diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 54d47fa..842d368 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4630,7 +4630,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * return; // Item has neither contents nor children!(?) const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); - const bool itemIsFullyTransparent = (opacity < 0.0001); + const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity())) return; @@ -4750,7 +4750,7 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q qreal opacity, const QTransform *effectTransform, bool wasDirtyParentSceneTransform, bool drawItem) { - const bool itemIsFullyTransparent = (opacity < 0.0001); + const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape); const bool itemHasChildren = !item->d_ptr->children.isEmpty(); @@ -4980,7 +4980,8 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool } const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); - const bool itemIsFullyTransparent = !item->d_ptr->ignoreOpacity && opacity < 0.0001; + const bool itemIsFullyTransparent = !item->d_ptr->ignoreOpacity + && QGraphicsItemPrivate::isOpacityNull(opacity); if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity())) { resetDirtyItem(item, /*recursive=*/itemHasChildren); return; diff --git a/src/gui/graphicsview/qgraphicssceneindex.cpp b/src/gui/graphicsview/qgraphicssceneindex.cpp index 043c4eb..707c71f 100644 --- a/src/gui/graphicsview/qgraphicssceneindex.cpp +++ b/src/gui/graphicsview/qgraphicssceneindex.cpp @@ -279,7 +279,7 @@ void QGraphicsSceneIndexPrivate::recursive_items_helper(QGraphicsItem *item, QRe return; const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); - const bool itemIsFullyTransparent = (opacity < 0.0001); + const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); const bool itemHasChildren = !item->d_ptr->children.isEmpty(); if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity())) return; @@ -554,7 +554,7 @@ QList QGraphicsSceneIndex::estimateTopLevelItems(const QRectF & /*! \fn QList QGraphicsSceneIndex::items(Qt::SortOrder order = Qt::DescendingOrder) const - + This pure virtual function all items in the index and sort them using \a order. */ -- cgit v0.12 From 3db33d41ad48953ec7c8d74db24d17fc3685895f Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Wed, 27 Jan 2010 13:47:25 +0100 Subject: Cleanup in graphicsitem autotest Unified multiple class definitions for MyGraphicsView and cleaned whitespaces. Reviewed-by: bnilsen --- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 68 ++++++-------------------- 1 file changed, 16 insertions(+), 52 deletions(-) diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 14b9ef0..a515481 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -251,6 +251,21 @@ public: QBrush brush; }; +class MyGraphicsView : public QGraphicsView +{ +public: + int repaints; + QRegion paintedRegion; + MyGraphicsView(QGraphicsScene *scene) : QGraphicsView(scene), repaints(0) {} + void paintEvent(QPaintEvent *e) + { + paintedRegion += e->region(); + ++repaints; + QGraphicsView::paintEvent(e); + } + void reset() { repaints = 0; paintedRegion = QRegion(); } +}; + class tst_QGraphicsItem : public QObject { Q_OBJECT @@ -3165,7 +3180,6 @@ void tst_QGraphicsItem::childrenBoundingRect() childChild->setPos(500, 500); child->rotate(90); - scene.addPolygon(parent->mapToScene(parent->boundingRect() | parent->childrenBoundingRect()))->setPen(QPen(Qt::red));; QGraphicsView view(&scene); @@ -6252,13 +6266,6 @@ void tst_QGraphicsItem::opacity2() QGraphicsScene scene; scene.addItem(parent); - class MyGraphicsView : public QGraphicsView - { public: - int repaints; - MyGraphicsView(QGraphicsScene *scene) : QGraphicsView(scene), repaints(0) {} - void paintEvent(QPaintEvent *e) { ++repaints; QGraphicsView::paintEvent(e); } - }; - MyGraphicsView view(&scene); view.show(); QTest::qWaitForWindowShown(&view); @@ -6336,20 +6343,6 @@ void tst_QGraphicsItem::opacityZeroUpdates() QGraphicsScene scene; scene.addItem(parent); - class MyGraphicsView : public QGraphicsView - { public: - int repaints; - QRegion paintedRegion; - MyGraphicsView(QGraphicsScene *scene) : QGraphicsView(scene), repaints(0) {} - void paintEvent(QPaintEvent *e) - { - ++repaints; - paintedRegion += e->region(); - QGraphicsView::paintEvent(e); - } - void reset() { repaints = 0; paintedRegion = QRegion(); } - }; - MyGraphicsView view(&scene); view.show(); QTest::qWaitForWindowShown(&view); @@ -7076,21 +7069,6 @@ void tst_QGraphicsItem::deviceTransform() QCOMPARE(rect3->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult3); } -class MyGraphicsView : public QGraphicsView -{ -public: - int repaints; - QRegion paintedRegion; - MyGraphicsView(QGraphicsScene *scene) : QGraphicsView(scene), repaints(0) {} - void paintEvent(QPaintEvent *e) - { - paintedRegion += e->region(); - ++repaints; - QGraphicsView::paintEvent(e); - } - void reset() { repaints = 0; paintedRegion = QRegion(); } -}; - void tst_QGraphicsItem::update() { QGraphicsScene scene; @@ -9835,7 +9813,7 @@ void tst_QGraphicsItem::scenePosChange() QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); } -void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() +void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() { struct Item : public QGraphicsTextItem { @@ -9914,20 +9892,6 @@ void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent() QGraphicsScene scene; scene.addItem(parent); - class MyGraphicsView : public QGraphicsView - { public: - int repaints; - QRegion paintedRegion; - MyGraphicsView(QGraphicsScene *scene) : QGraphicsView(scene), repaints(0) {} - void paintEvent(QPaintEvent *e) - { - ++repaints; - paintedRegion += e->region(); - QGraphicsView::paintEvent(e); - } - void reset() { repaints = 0; paintedRegion = QRegion(); } - }; - MyGraphicsView view(&scene); view.show(); QTest::qWaitForWindowShown(&view); -- cgit v0.12 From 08c649e6a81ab13d0c7db6aa1b480ed149e3f770 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Wed, 20 Jan 2010 15:11:58 +0100 Subject: Avoids missing opacity updates by not propagating the ignoreOpacity flag When doing a full update of a parent item, by setting one of these flags, QGraphicsItem::ItemIgnoresTransformations | ItemClipsChildrenToShape | ItemIsSelectable, the child items that were transparent would not be shown when setting their respective opacity to 1.0 We just need to set the ignoreOpacity flag when setting opacity to 0.0. This avoids propagating this flag to the child items when it's not needed. Task-number: QT-2653 Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsitem.cpp | 2 +- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 40 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index ed36f87..86780da 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2584,7 +2584,7 @@ void QGraphicsItem::setOpacity(qreal opacity) d_ptr->scene->d_func()->markDirty(this, QRectF(), /*invalidateChildren=*/true, /*force=*/false, - /*ignoreOpacity=*/true); + /*ignoreOpacity=*/d_ptr->isOpacityNull()); } if (d_ptr->isObject) diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index a515481..dd8d555 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -434,6 +434,7 @@ private slots: void QTBUG_4233_updateCachedWithSceneRect(); void QTBUG_5418_textItemSetDefaultColor(); void QTBUG_6738_missingUpdateWithSetParent(); + void QT_2653_fullUpdateDiscardingOpacityUpdate(); private: QList paintedItems; @@ -9919,5 +9920,44 @@ void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent() QTRY_VERIFY(view.repaints == 1); } +void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate() +{ + QGraphicsScene scene(0, 0, 200, 200); + MyGraphicsView view(&scene); + + EventTester *parentGreen = new EventTester(); + parentGreen->setGeometry(QRectF(20, 20, 100, 100)); + parentGreen->brush = Qt::green; + + EventTester *childYellow = new EventTester(parentGreen); + childYellow->setGeometry(QRectF(10, 10, 50, 50)); + childYellow->brush = Qt::yellow; + + scene.addItem(parentGreen); + + childYellow->setOpacity(0.0); + parentGreen->setOpacity(0.0); + + // set any of the flags below to trigger a fullUpdate to reproduce the bug: + // ItemIgnoresTransformations, ItemClipsChildrenToShape, ItemIsSelectable + parentGreen->setFlag(QGraphicsItem::ItemIgnoresTransformations); + + view.show(); + QTest::qWaitForWindowShown(&view); + view.reset(); + + parentGreen->setOpacity(1.0); + + QTRY_COMPARE(view.repaints, 1); + + view.reset(); + childYellow->repaints = 0; + + childYellow->setOpacity(1.0); + + QTRY_COMPARE(view.repaints, 1); + QTRY_COMPARE(childYellow->repaints, 1); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" -- cgit v0.12 From 37f1aec1a4e71a7102e8cd2e2908c8d3be7e29f5 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Thu, 28 Jan 2010 15:43:12 +0100 Subject: Fixes missing update when setting opacity on an item that had opacity 0.0 We need to set the paintedViewBoundingRectsNeedRepaint flag when an item becomes visible again because when the item has opacity 0.0 the paintedViewBoundingRects struct can get set as outside of viewport, so the next time the item is set to visible again we need to diregard this cached data (otherwise the item will not be updated). Task-number: QTBUG-7714 Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsitem.cpp | 3 ++ tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 39 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 86780da..b4e19d1 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2569,6 +2569,7 @@ void QGraphicsItem::setOpacity(qreal opacity) if (newOpacity == d_ptr->opacity) return; + bool wasFullyTransparent = d_ptr->isOpacityNull(); d_ptr->opacity = newOpacity; // Notify change. @@ -2585,6 +2586,8 @@ void QGraphicsItem::setOpacity(qreal opacity) /*invalidateChildren=*/true, /*force=*/false, /*ignoreOpacity=*/d_ptr->isOpacityNull()); + if (wasFullyTransparent) + d_ptr->paintedViewBoundingRectsNeedRepaint = 1; } if (d_ptr->isObject) diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index dd8d555..ae038e7 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -434,6 +434,7 @@ private slots: void QTBUG_4233_updateCachedWithSceneRect(); void QTBUG_5418_textItemSetDefaultColor(); void QTBUG_6738_missingUpdateWithSetParent(); + void QTBUG_7714_fullUpdateDiscardingOpacityUpdate2(); void QT_2653_fullUpdateDiscardingOpacityUpdate(); private: @@ -9959,5 +9960,43 @@ void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate() QTRY_COMPARE(childYellow->repaints, 1); } +void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() +{ + QGraphicsScene scene(0, 0, 200, 200); + MyGraphicsView view(&scene); + MyGraphicsView origView(&scene); + + EventTester *parentGreen = new EventTester(); + parentGreen->setGeometry(QRectF(20, 20, 100, 100)); + parentGreen->brush = Qt::green; + + EventTester *childYellow = new EventTester(parentGreen); + childYellow->setGeometry(QRectF(10, 10, 50, 50)); + childYellow->brush = Qt::yellow; + + scene.addItem(parentGreen); + + origView.show(); + QTest::qWaitForWindowShown(&origView); + + parentGreen->setFlag(QGraphicsItem::ItemIgnoresTransformations); + + origView.reset(); + childYellow->setOpacity(0.0); + + QTRY_COMPARE(origView.repaints, 1); + + view.show(); + + QTest::qWaitForWindowShown(&view); + view.reset(); + origView.reset(); + + childYellow->setOpacity(1.0); + + QTRY_COMPARE(origView.repaints, 1); + QTRY_COMPARE(view.repaints, 1); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" -- cgit v0.12 From 465a63d00c2294641539af820435a9a4315f0251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Mon, 1 Feb 2010 09:03:48 +0100 Subject: Don't crash when running Qt on KDE with Oxygen style. It crashed on application exit because of the order of Q_GLOBAL_STATICs are not defined if the global statics are in different modules. Thus, the globalRedirectionAtomic was destroyed first, then the K_GLOBAL_STATIC(OxygenHelper, ...) got destroyed. Since the OxygeneHelper contained a QCache of pixmaps it would eventually call ~QPixmap() and reference the destroyed globalRedirectionAtomic.... Task-number: QTBUG-7734 Reviewed-by: gunnar --- src/gui/painting/qpainter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index cde6a2d..0f28f7a 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -7529,7 +7529,7 @@ QPaintDevice *QPainter::redirected(const QPaintDevice *device, QPoint *offset) void qt_painter_removePaintDevice(QPaintDevice *dev) { - if (*globalRedirectionAtomic() == 0) + if (!globalRedirectionAtomic() || *globalRedirectionAtomic() == 0) return; QMutex *mutex = 0; -- cgit v0.12 From d785467dbb97d4be9de66504dd6fb891da19abff Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 1 Feb 2010 12:49:37 +0100 Subject: fix crash in Phonon::DS9 backend When using a VideoWidget in a QGraphicsProxyWidget, then Phonon::DS9 crashed, if the VideoWidget didn't have a MediaSource. Reviewed-by: Thierry --- src/3rdparty/phonon/ds9/videowidget.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/3rdparty/phonon/ds9/videowidget.cpp b/src/3rdparty/phonon/ds9/videowidget.cpp index 091be16..95423c6 100644 --- a/src/3rdparty/phonon/ds9/videowidget.cpp +++ b/src/3rdparty/phonon/ds9/videowidget.cpp @@ -218,6 +218,9 @@ namespace Phonon if (toNative && m_noNativeRendererSupported) return current; //no switch here + if (!mediaObject()) + return current; + //firt we delete the renderer //initialization of the widgets for(int i = 0; i < FILTER_COUNT; ++i) { -- cgit v0.12 From afe0f17eb5974adbedd1bc1f2fcd98459d92df47 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Mon, 1 Feb 2010 14:30:15 +0100 Subject: Fixed garbled 3D Qt logo in the overpainting example. Disable vertex attribute arrays in the GL2 paint engine when calling QPainter::beginNativePainting() and QPainter::end(). Task-number: QTBUG-7781 Reviewed-by: Trond --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index b282676..35e95be 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -558,6 +558,9 @@ void QGL2PaintEngineExPrivate::resetGLState() glStencilMask(0xff); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glStencilFunc(GL_ALWAYS, 0, 0xff); + glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); + glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR); + glDisableVertexAttribArray(QT_OPACITY_ATTR); } void QGL2PaintEngineEx::endNativePainting() -- cgit v0.12 From 94f5f21ac88de0d940d6ac27d222f1ef8e66d939 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 1 Feb 2010 18:03:06 +0100 Subject: Assert failure when setting a widget focus proxy as its successor in tab order Now we check that and skip it from the tab list. Auto-test included. Reviewed-by: leo Task-number: QTBUG-7532 --- src/gui/kernel/qwidget.cpp | 2 ++ tests/auto/qwidget/tst_qwidget.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index ffad38b..4054d2a 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -6414,6 +6414,8 @@ void QWidget::setTabOrder(QWidget* first, QWidget *second) first = fp; } + if (fp == second) + return; if (QWidget *sp = second->focusProxy()) second = sp; diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index ea90ae3..1fb323e 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -396,6 +396,8 @@ private slots: void focusProxyAndInputMethods(); void scrollWithoutBackingStore(); + void taskQTBUG_7532_tabOrderWithFocusProxy(); + private: bool ensureScreenSize(int width, int height); QWidget *testWidget; @@ -9783,5 +9785,17 @@ void tst_QWidget::scrollWithoutBackingStore() QCOMPARE(child.pos(),QPoint(25,25)); } +void tst_QWidget::taskQTBUG_7532_tabOrderWithFocusProxy() +{ + QWidget w; + w.setFocusPolicy(Qt::TabFocus); + QWidget *fp = new QWidget(&w); + fp->setFocusPolicy(Qt::TabFocus); + w.setFocusProxy(fp); + QWidget::setTabOrder(&w, fp); + + // No Q_ASSERT, then it's allright. +} + QTEST_MAIN(tst_QWidget) #include "tst_qwidget.moc" -- cgit v0.12 From 9258959f4f81b9c3efa4418aa344a5be5f9d12ab Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Mon, 1 Feb 2010 19:55:07 +0100 Subject: Fix QTBUG_7714_fullUpdateDiscardingOpacityUpdate2 autotest in qws-linux The two views were displayed on top of each other, so some repaints were not triggered. --- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index ae038e7..7b54a3b 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -9978,6 +9978,8 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() origView.show(); QTest::qWaitForWindowShown(&origView); + origView.setGeometry(origView.width() + 20, 20, + origView.width(), origView.height()); parentGreen->setFlag(QGraphicsItem::ItemIgnoresTransformations); -- cgit v0.12 From 787824cb4add4d45a0e90fd736a54e75fa048475 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Tue, 2 Feb 2010 10:18:15 +0100 Subject: Fixed missing textures in the boxes demo. The boxes demo assumed that the current GL colour was the default white, but the GL2 paint engine set it to black. Fixed by resetting the colour to white in resetGLState(). Task-number: QTBUG-7779 Reviewed-by: Trond --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 35e95be..406112a 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -561,6 +561,7 @@ void QGL2PaintEngineExPrivate::resetGLState() glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR); glDisableVertexAttribArray(QT_OPACITY_ATTR); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // color may have been changed by glVertexAttrib() } void QGL2PaintEngineEx::endNativePainting() -- cgit v0.12 From e8b6c949c006393ab690aa3e890cd48defc97b77 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 2 Feb 2010 11:06:59 +0100 Subject: Document that QModelIndex::child does not work for the root item Reviewed-by: Thierry --- src/corelib/kernel/qabstractitemmodel.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/corelib/kernel/qabstractitemmodel.cpp b/src/corelib/kernel/qabstractitemmodel.cpp index dbf422e..36e4af9 100644 --- a/src/corelib/kernel/qabstractitemmodel.cpp +++ b/src/corelib/kernel/qabstractitemmodel.cpp @@ -1006,6 +1006,9 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, Returns the child of the model index that is stored in the given \a row and \a column. + \note This function does not work for an invalid model index which is often + used as the root index. + \sa parent(), sibling() */ -- cgit v0.12 From db5f673ccf5a56772ff83cad52beab7b14cd9520 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Tue, 2 Feb 2010 12:46:52 +0100 Subject: fix whitespace --- configure | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure b/configure index dc23392..9a3ee32 100755 --- a/configure +++ b/configure @@ -3369,10 +3369,10 @@ Configure options: -debug-and-release . Compile and link two versions of Qt, with and without debugging turned on (Mac only). - -developer-build.... Compile and link Qt with Qt developer options (including auto-tests exporting) + -developer-build ... Compile and link Qt with Qt developer options (including auto-tests exporting) - -opensource......... Compile and link the Open-Source Edition of Qt. - -commercial......... Compile and link the Commercial Edition of Qt. + -opensource ........ Compile and link the Open-Source Edition of Qt. + -commercial ........ Compile and link the Commercial Edition of Qt. * -shared ............ Create and use shared Qt libraries. @@ -3765,7 +3765,7 @@ Qt/X11 only: Requires fontconfig/fontconfig.h, libfontconfig, freetype.h and libfreetype. - $XIN -no-xinput.......... Do not compile Xinput support. + $XIN -no-xinput ......... Do not compile Xinput support. $XIY -xinput ............ Compile Xinput support. This also enabled tablet support which requires IRIX with wacom.h and libXi or XFree86 with X11/extensions/XInput.h and libXi. -- cgit v0.12 From 88c4000c21be7af37bc490a2edd9d1f481b3a862 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Tue, 2 Feb 2010 13:20:10 +0100 Subject: Fixed compilation of the GL2 engine for OpenGL ES 2. glColor4f is not defined in OpenGL ES 2. Reviewed-by: Trond --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 406112a..07f3159 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -561,7 +561,9 @@ void QGL2PaintEngineExPrivate::resetGLState() glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR); glDisableVertexAttribArray(QT_OPACITY_ATTR); +#ifndef QT_OPENGL_ES_2 glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // color may have been changed by glVertexAttrib() +#endif } void QGL2PaintEngineEx::endNativePainting() -- cgit v0.12 From 94b3918fb52858064811c4993dac6392d0043b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Tue, 2 Feb 2010 15:05:54 +0100 Subject: Implemented QGifHandler::imageCount(). Task-number: QTBUG-7514 Reviewed-by: Kim --- src/plugins/imageformats/gif/qgifhandler.cpp | 235 ++++++++++++++++++++++++++- src/plugins/imageformats/gif/qgifhandler.h | 1 + tests/auto/qimagereader/tst_qimagereader.cpp | 6 + 3 files changed, 241 insertions(+), 1 deletion(-) diff --git a/src/plugins/imageformats/gif/qgifhandler.cpp b/src/plugins/imageformats/gif/qgifhandler.cpp index 6f049be..6cd7841 100644 --- a/src/plugins/imageformats/gif/qgifhandler.cpp +++ b/src/plugins/imageformats/gif/qgifhandler.cpp @@ -72,6 +72,7 @@ public: int decode(QImage *image, const uchar* buffer, int length, int *nextFrameDelay, int *loopCount, QSize *nextSize); + static int imageCount(QIODevice *device); bool newFrame; bool partialNewFrame; @@ -645,6 +646,234 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length, return initial-length; } +/*! + Returns the number of images that can be read from \a device. +*/ + +int QGIFFormat::imageCount(QIODevice *device) +{ + if (!device) + return 0; + + qint64 oldPos = device->pos(); + if (!device->seek(0)) + return 0; + + int colorCount = 0; + int localColorCount = 0; + int globalColorCount = 0; + int colorReadCount = 0; + bool localColormap = false; + bool globalColormap = false; + int count = 0; + int blockSize = 0; + bool done = false; + uchar hold[16]; + int imageCount = 0; + State state = Header; + + const int readBufferSize = 40960; // 40k read buffer + QByteArray readBuffer(device->read(readBufferSize)); + + if (readBuffer.isEmpty()) + return 0; + + // this is a specialized version of the state machine from decode(), + // which doesn't do any image decoding or mallocing, and has an + // optimized way of skipping SkipBlocks, ImageDataBlocks and + // Global/LocalColorMaps. + + while (!readBuffer.isEmpty()) { + int length = readBuffer.size(); + const uchar *buffer = (const uchar *) readBuffer.constData(); + while (!done && length) { + length--; + uchar ch = *buffer++; + switch (state) { + case Header: + hold[count++] = ch; + if (count == 6) { + state = LogicalScreenDescriptor; + count = 0; + } + break; + case LogicalScreenDescriptor: + hold[count++] = ch; + if (count == 7) { + globalColormap = !!(hold[4] & 0x80); + globalColorCount = 2 << (hold[4] & 0x7); + count = 0; + colorCount = globalColorCount; + if (globalColormap) { + int colorTableSize = 3 * globalColorCount; + if (length >= colorTableSize) { + // skip the global color table in one go + length -= colorTableSize; + buffer += colorTableSize; + state = Introducer; + } else { + colorReadCount = 0; + state = GlobalColorMap; + } + } else { + state=Introducer; + } + } + break; + case GlobalColorMap: + case LocalColorMap: + hold[count++] = ch; + if (count == 3) { + if (++colorReadCount >= colorCount) { + if (state == LocalColorMap) + state = TableImageLZWSize; + else + state = Introducer; + } + count = 0; + } + break; + case Introducer: + hold[count++] = ch; + switch (ch) { + case 0x2c: + state = ImageDescriptor; + break; + case 0x21: + state = ExtensionLabel; + break; + case 0x3b: + state = Done; + break; + default: + done = true; + state = Error; + } + break; + case ImageDescriptor: + hold[count++] = ch; + if (count == 10) { + localColormap = !!(hold[9] & 0x80); + localColorCount = localColormap ? (2 << (hold[9] & 0x7)) : 0; + if (localColorCount) + colorCount = localColorCount; + else + colorCount = globalColorCount; + imageCount++; + + count = 0; + if (localColormap) { + int colorTableSize = 3 * localColorCount; + if (length >= colorTableSize) { + // skip the local color table in one go + length -= colorTableSize; + buffer += colorTableSize; + state = TableImageLZWSize; + } else { + colorReadCount = 0; + state = LocalColorMap; + } + } else { + state = TableImageLZWSize; + } + } + break; + case TableImageLZWSize: + if (ch > max_lzw_bits) + state = Error; + else + state = ImageDataBlockSize; + count = 0; + break; + case ImageDataBlockSize: + blockSize = ch; + if (blockSize) { + if (length >= blockSize) { + // we can skip the block in one go + length -= blockSize; + buffer += blockSize; + count = 0; + } else { + state = ImageDataBlock; + } + } else { + state = Introducer; + } + break; + case ImageDataBlock: + ++count; + if (count == blockSize) { + count = 0; + state = ImageDataBlockSize; + } + break; + case ExtensionLabel: + switch (ch) { + case 0xf9: + state = GraphicControlExtension; + break; + case 0xff: + state = ApplicationExtension; + break; + default: + state = SkipBlockSize; + } + count = 0; + break; + case ApplicationExtension: + if (count < 11) + hold[count] = ch; + ++count; + if (count == hold[0] + 1) { + state = SkipBlockSize; + count = 0; + } + break; + case GraphicControlExtension: + if (count < 5) + hold[count] = ch; + ++count; + if (count == hold[0] + 1) { + count = 0; + state = SkipBlockSize; + } + break; + case NetscapeExtensionBlockSize: // fallthrough + case SkipBlockSize: + blockSize = ch; + count = 0; + if (blockSize) { + if (length >= blockSize) { + // we can skip the block in one go + length -= blockSize; + buffer += blockSize; + } else { + state = SkipBlock; + } + } else { + state = Introducer; + } + break; + case NetscapeExtensionBlock: // fallthrough + case SkipBlock: + ++count; + if (count == blockSize) + state = SkipBlockSize; + break; + case Done: + done = true; + break; + case Error: + device->seek(oldPos); + return 0; + } + } + readBuffer = device->read(readBufferSize); + } + device->seek(oldPos); + return imageCount; +} + void QGIFFormat::fillRect(QImage *image, int col, int row, int w, int h, QRgb color) { if (w>0) { @@ -766,6 +995,7 @@ QGifHandler::QGifHandler() loopCnt = 0; frameNumber = -1; nextSize = QSize(); + imageCnt = -1; } QGifHandler::~QGifHandler() @@ -883,7 +1113,10 @@ int QGifHandler::nextImageDelay() const int QGifHandler::imageCount() const { - return 0; // Don't know + if (imageCnt != -1) + return imageCnt; + imageCnt = QGIFFormat::imageCount(device()); + return imageCnt; } int QGifHandler::loopCount() const diff --git a/src/plugins/imageformats/gif/qgifhandler.h b/src/plugins/imageformats/gif/qgifhandler.h index a6e520f..830cd38 100644 --- a/src/plugins/imageformats/gif/qgifhandler.h +++ b/src/plugins/imageformats/gif/qgifhandler.h @@ -88,6 +88,7 @@ private: mutable int loopCnt; int frameNumber; mutable QSize nextSize; + mutable int imageCnt; }; QT_END_NAMESPACE diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index b1a5d26..debc090 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -765,6 +765,8 @@ void tst_QImageReader::gifImageCount() QVERIFY(io.canRead()); QImage greenFrame = io.read(); + QVERIFY(io.imageCount() == 4); + QVERIFY(io.canRead()); QImage blueFrame = io.read(); @@ -876,6 +878,10 @@ void tst_QImageReader::gifImageCount() QCOMPARE(blueFrame.size(), QSize(64,64)); QVERIFY(emptyFrame.isNull()); } + { + QImageReader io(":images/trolltech.gif"); + QVERIFY(io.imageCount() == 34); + } } #endif -- cgit v0.12 From 3d2dbeb65089efaff4b92b7d13c13c1a234f71b0 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 2 Feb 2010 16:39:40 +0100 Subject: Avoids a possible crash when saving the state of a main window The crash could appear when saving the state of the main window in response to the visibilityChanged of the dock widgets. Task-number: QTBUG-7838 Reviewed-by: ogoffart --- src/gui/widgets/qmainwindowlayout.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gui/widgets/qmainwindowlayout.cpp b/src/gui/widgets/qmainwindowlayout.cpp index d1e7285..fc75c92 100644 --- a/src/gui/widgets/qmainwindowlayout.cpp +++ b/src/gui/widgets/qmainwindowlayout.cpp @@ -1627,6 +1627,13 @@ void QMainWindowLayout::animationFinished(QWidget *widget) tb->d_func()->plug(currentGapRect); #endif + savedState.clear(); + currentGapPos.clear(); + pluggingWidget = 0; + //applying the state will make sure that the currentGap is updated correctly + //and all the geometries (especially the one from the central widget) is correct + layoutState.apply(false); + #ifndef QT_NO_DOCKWIDGET #ifndef QT_NO_TABBAR if (qobject_cast(widget) != 0) { @@ -1637,13 +1644,6 @@ void QMainWindowLayout::animationFinished(QWidget *widget) } #endif #endif - - savedState.clear(); - currentGapPos.clear(); - pluggingWidget = 0; - //applying the state will make sure that the currentGap is updated correctly - //and all the geometries (especially the one from the central widget) is correct - layoutState.apply(false); } if (!widgetAnimator.animating()) { -- cgit v0.12 From 85578c6c37d9e4eb0da888937b20ba93a26d8805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Tue, 2 Feb 2010 17:39:19 +0100 Subject: 4.6.2 changes --- dist/changes-4.6.2 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/dist/changes-4.6.2 b/dist/changes-4.6.2 index d35f945..2a884fe 100644 --- a/dist/changes-4.6.2 +++ b/dist/changes-4.6.2 @@ -46,8 +46,14 @@ QtCore QtGui ----- - - foo - * bar + - QBmpHandler + * [QTBUG-7530] Fixed an infinite loop that could occur when reading invalid BMP images. + + - QImage + * [QTBUG-7231] Avoid an unnecessary copy in QImage::scaled(). + + - QPDFEngine + * [QTBUG-7249] Fixed the encoding of the Tile and Creator tags in the PDF engine. QtDBus ------ @@ -64,8 +70,14 @@ QtNetwork QtOpenGL -------- - - foo - * bar + - QGLWidget + * [QTBUG-7213] Fixed QGLWidget::renderPixmap() on Windows. + + - QGLPixelBuffer + * [QTBUG-7476] Fixed a crash under X11 when drawing QPixmaps to QGLPixelBuffers. + + - QGL2PaintEngineEx + * [QTBUG-7203] Reset the GL stencil mask, op and function in resetGLState(). QtScript -------- @@ -121,7 +133,8 @@ Qt for Windows Qt for Mac OS X --------------- - - + - QPrintPreviewDialog + * [QTBUG-7481] Re-added the Close button in QPrintPreviewDialog for Mac/Carbon. Qt for Embedded Linux --------------------- -- cgit v0.12 From d5d882280fe9577c580d41f1efb5abbd5d57f6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Tue, 2 Feb 2010 17:57:19 +0100 Subject: Fixed a failure in tst_qgl. The assert wrong, it may be that the texture isn't removed from the cache if it doesn't have the MemoryManaged bind option set. Reviewed-by: Samuel --- src/opengl/qgl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index dd977cb..fce9fdb 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1683,7 +1683,6 @@ void QGLTextureCache::cleanupBeforePixmapDestruction(QPixmapData* pmd) { // Remove any bound textures first: cleanupTextures(pmd); - Q_ASSERT(instance()->getTexture(pmd->cacheKey()) == 0); #if defined(Q_WS_X11) if (pmd->classId() == QPixmapData::X11Class) { -- cgit v0.12 From c186c0402781ec6ef6ee97e2168d16f0b043044e Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Tue, 2 Feb 2010 13:51:43 -0800 Subject: Make DSFLIP_ONSYNC part of the default flip flags. Reviewed-by: Jervey Kong --- src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index 6b251c7..cd4d5c2 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -921,7 +921,7 @@ void QDirectFBScreenPrivate::setFlipFlags(const QStringList &args) qPrintable(flip)); } } else { - flipFlags = DSFLIP_BLIT; + flipFlags = DSFLIP_BLIT|DSFLIP_ONSYNC; } } -- cgit v0.12 From 7d4ef9167249df5f00831dc07e57705eb1ddd22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 3 Feb 2010 10:36:15 +0100 Subject: Update changes-4.6.2. --- dist/changes-4.6.2 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dist/changes-4.6.2 b/dist/changes-4.6.2 index 58dcf0e..292b3ef 100644 --- a/dist/changes-4.6.2 +++ b/dist/changes-4.6.2 @@ -49,6 +49,10 @@ QtGui - QBmpHandler * [QTBUG-7530] Fixed an infinite loop that could occur when reading invalid BMP images. + - QGraphicsEffect + * [QTBUG-6901] Fixed performance problem when translating items with + graphics effects. + - QImage * [QTBUG-7231] Avoid an unnecessary copy in QImage::scaled(). -- cgit v0.12 From 7e46016d55a80e9d49797efe34779893d80b71e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sakari=20Peltom=C3=A4ki?= Date: Wed, 3 Feb 2010 10:42:54 +0100 Subject: Proper Fav icon is not shown, for all the links default fav icon shown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added two functions on QtIcoHandler(inherited from QImageIOHandler): bool supports Option(ImageOption option) const QVariant option(ImageOption option) const implementation of these functions make possible to open fav.ico eg. via web browser. (if using fav.ico icons via webkit, browser should initialize webcore::icondatabase using QWebSettings::enablePersistentStorage() ) Merge-request: 2150 Reviewed-by: Jan-Arve Sæther --- src/plugins/imageformats/ico/qicohandler.cpp | 24 ++++++++++++++++++++++++ src/plugins/imageformats/ico/qicohandler.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/plugins/imageformats/ico/qicohandler.cpp b/src/plugins/imageformats/ico/qicohandler.cpp index b2351fa..4edb87a 100644 --- a/src/plugins/imageformats/ico/qicohandler.cpp +++ b/src/plugins/imageformats/ico/qicohandler.cpp @@ -53,6 +53,7 @@ #include #include #include +#include // These next two structs represent how the icon information is stored // in an ICO file. typedef struct @@ -772,6 +773,29 @@ QtIcoHandler::~QtIcoHandler() delete m_pICOReader; } +QVariant QtIcoHandler::option(ImageOption option) const +{ + if (option == Size) { + QIODevice *device = QImageIOHandler::device(); + qint64 oldPos = device->pos(); + ICONDIRENTRY iconEntry; + if (device->seek(oldPos + ICONDIR_SIZE + (m_currentIconIndex * ICONDIRENTRY_SIZE))) { + if (readIconDirEntry(device, &iconEntry)) { + device->seek(oldPos); + return QSize(iconEntry.bWidth, iconEntry.bHeight); + } + } + if (!device->isSequential()) + device->seek(oldPos); + } + return QVariant(); +} + +bool QtIcoHandler::supportsOption(ImageOption option) const +{ + return option == Size; +} + /*! * Verifies if some values (magic bytes) are set as expected in the header of the file. * If the magic bytes were found, it is assumed that the QtIcoHandler can read the file. diff --git a/src/plugins/imageformats/ico/qicohandler.h b/src/plugins/imageformats/ico/qicohandler.h index b9ef27e..394a5eb 100644 --- a/src/plugins/imageformats/ico/qicohandler.h +++ b/src/plugins/imageformats/ico/qicohandler.h @@ -62,6 +62,9 @@ public: static bool canRead(QIODevice *device); + bool supportsOption(ImageOption option) const; + QVariant option(ImageOption option) const; + private: int m_currentIconIndex; ICOReader *m_pICOReader; -- cgit v0.12 From d53315d30b38352db11063096ee3867a40bdc234 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 3 Feb 2010 11:30:20 +0100 Subject: Revert "QAbstractScrollArea: Wheel over a scrollarea that has only one horizontal scrollbar" This reverts commit 46a3e518b3070cf7cb4cbbb2cb58254454cf169d. This shown to cause more problem than it solved Also update the changelog Reviewed-by: Thierry --- dist/changes-4.6.2 | 3 + src/gui/widgets/qabstractscrollarea.cpp | 11 +-- src/gui/widgets/qabstractslider.cpp | 2 + .../tst_qabstractscrollarea.cpp | 97 +--------------------- 4 files changed, 11 insertions(+), 102 deletions(-) diff --git a/dist/changes-4.6.2 b/dist/changes-4.6.2 index 292b3ef..4127e13 100644 --- a/dist/changes-4.6.2 +++ b/dist/changes-4.6.2 @@ -46,6 +46,9 @@ QtCore QtGui ----- + - QAbstractScrollArea + * [QTBUG-1760] Reverted horizontal scrolling with mouse wheel when vertical scrollbar is hidden + - QBmpHandler * [QTBUG-7530] Fixed an infinite loop that could occur when reading invalid BMP images. diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index 87f6c83..1d496d5 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -1134,13 +1134,10 @@ void QAbstractScrollArea::mouseMoveEvent(QMouseEvent *e) void QAbstractScrollArea::wheelEvent(QWheelEvent *e) { Q_D(QAbstractScrollArea); - QScrollBar *const bars[2] = { d->hbar, d->vbar }; - int idx = (e->orientation() == Qt::Vertical) ? 1 : 0; - int other = (idx + 1) % 2; - if (!bars[idx]->isVisible() && bars[other]->isVisible()) - idx = other; // If the scrollbar of the event orientation is hidden, fallback to the other. - - QApplication::sendEvent(bars[idx], e); + if (static_cast(e)->orientation() == Qt::Horizontal) + QApplication::sendEvent(d->hbar, e); + else + QApplication::sendEvent(d->vbar, e); } #endif diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index 2874647..77c5a01 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -697,6 +697,8 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e) { Q_D(QAbstractSlider); e->ignore(); + if (e->orientation() != d->orientation && !rect().contains(e->pos())) + return; int stepsToScroll = 0; qreal offset = qreal(e->delta()) / 120; diff --git a/tests/auto/qabstractscrollarea/tst_qabstractscrollarea.cpp b/tests/auto/qabstractscrollarea/tst_qabstractscrollarea.cpp index 3e062b8..da83826 100644 --- a/tests/auto/qabstractscrollarea/tst_qabstractscrollarea.cpp +++ b/tests/auto/qabstractscrollarea/tst_qabstractscrollarea.cpp @@ -71,8 +71,6 @@ private slots: void viewportCrash(); void task214488_layoutDirection_data(); void task214488_layoutDirection(); - void wheelEvent_data(); - void wheelEvent(); }; tst_QAbstractScrollArea::tst_QAbstractScrollArea() @@ -298,10 +296,10 @@ public: setAttribute(Qt::WA_DropSiteRegistered, true); - startTimer(200); + startTimer(2000); } - void timerEvent(QTimerEvent *) + void timerEvent(QTimerEvent *event) { // should not crash. (void)new QScrollArea(this); @@ -387,96 +385,5 @@ void tst_QAbstractScrollArea::patternBackground() QCOMPARE(image.pixel(QPoint(20,20)) , QColor(Qt::red).rgb()); } -Q_DECLARE_METATYPE(QWheelEvent *); - -void tst_QAbstractScrollArea::wheelEvent_data() -{ - QTest::addColumn("widgetSize"); - QTest::addColumn("initialOffset"); - QTest::addColumn("event"); - QTest::addColumn("movedX"); // -1 , 0 , or 1 - QTest::addColumn("movedY"); - - QPoint pos(100,100); - int delta =-120; - - QTest::newRow("1") << QSize(600,600) << QPoint(50,50) - << new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 1 << 0; - - QTest::newRow("2") << QSize(600,600) << QPoint(50,50) - << new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 0 << 1; - - QTest::newRow("3") << QSize(600,600) << QPoint(50,50) - << new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << -1 << 0; - - QTest::newRow("4") << QSize(600,600) << QPoint(50,50) - << new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << 0 << -1; - - QTest::newRow("5") << QSize(20,600) << QPoint(0,50) - << new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 0 << 1; - - QTest::newRow("6") << QSize(20,600) << QPoint(0,50) - << new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 0 << 1; - - QTest::newRow("7") << QSize(20,600) << QPoint(0,50) - << new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << 0 << -1; - - QTest::newRow("8") << QSize(20,600) << QPoint(0,50) - << new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << 0 << -1; - - QTest::newRow("9") << QSize(600,20) << QPoint(50,0) - << new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 1 << 0; - - QTest::newRow("a") << QSize(600,20) << QPoint(50,0) - << new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 1 << 0; - - QTest::newRow("b") << QSize(600,20) << QPoint(50,0) - << new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << -1 << 0; - - QTest::newRow("c") << QSize(600,20) << QPoint(50,0) - << new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << -1 << 0; -} - - - - -void tst_QAbstractScrollArea::wheelEvent() -{ - QFETCH(QSize, widgetSize); - QFETCH(QPoint, initialOffset); - QFETCH(QWheelEvent *, event); - QFETCH(int, movedX); - QFETCH(int, movedY); - - QScrollArea scrollArea; - scrollArea.resize(200, 200); - QLabel widget("H e l l o"); - widget.resize(widgetSize); - scrollArea.setWidget(&widget); - scrollArea.show(); - QTest::qWait(20); - - scrollArea.verticalScrollBar()->setValue(initialOffset.y()); - scrollArea.horizontalScrollBar()->setValue(initialOffset.x()); - - QCOMPARE(scrollArea.verticalScrollBar()->value(), initialOffset.y()); - QCOMPARE(scrollArea.horizontalScrollBar()->value(), initialOffset.x()); - - QApplication::sendEvent(scrollArea.viewport(), event); - - if(movedX == 0) - QCOMPARE(scrollArea.horizontalScrollBar()->value(), initialOffset.x()); - else - QVERIFY(movedX * scrollArea.horizontalScrollBar()->value() > movedX * initialOffset.x()); - - if(movedY == 0) - QCOMPARE(scrollArea.verticalScrollBar()->value(), initialOffset.y()); - else - QVERIFY(movedY * scrollArea.verticalScrollBar()->value() > movedY * initialOffset.y()); - - delete event; -} - - QTEST_MAIN(tst_QAbstractScrollArea) #include "tst_qabstractscrollarea.moc" -- cgit v0.12 From cc585886ba9da17064a7fc858f5d717967da6e85 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 3 Feb 2010 12:47:34 +0100 Subject: QStyleSheetStyle: Fix combinaison of border-image and border-radius Regression since b4d642e639eabde5d72a4 Task-number: QTBUG-7737 Reviewed-by: Gabriel --- src/gui/styles/qstylesheetstyle.cpp | 2 + .../baseline/css_qtbug7737_borderimageradius.ui | 44 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/auto/uiloader/baseline/css_qtbug7737_borderimageradius.ui diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index 498313b..b36294a 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -1125,6 +1125,7 @@ void QRenderRule::fixupBorder(int nativeWidth) void QRenderRule::drawBorderImage(QPainter *p, const QRect& rect) { + setClip(p, rect); static const Qt::TileRule tileMode2TileRule[] = { Qt::StretchTile, Qt::RoundTile, Qt::StretchTile, Qt::RepeatTile, Qt::StretchTile }; @@ -1142,6 +1143,7 @@ void QRenderRule::drawBorderImage(QPainter *p, const QRect& rect) QRect(QPoint(), borderImageData->pixmap.size()), sourceMargins, QTileRules(tileMode2TileRule[borderImageData->horizStretch], tileMode2TileRule[borderImageData->vertStretch])); p->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothPixmapTransform); + unsetClip(p); } QRect QRenderRule::originRect(const QRect &rect, Origin origin) const diff --git a/tests/auto/uiloader/baseline/css_qtbug7737_borderimageradius.ui b/tests/auto/uiloader/baseline/css_qtbug7737_borderimageradius.ui new file mode 100644 index 0000000..089cb76 --- /dev/null +++ b/tests/auto/uiloader/baseline/css_qtbug7737_borderimageradius.ui @@ -0,0 +1,44 @@ + + + Form + + + + 0 + 0 + 207 + 69 + + + + Form + + + QPushButton { border-image: url("images/pushbutton.png") 5 5 5 5; border-radius:8px; } + + + + + + Border image and radius + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + -- cgit v0.12 From 80e114ad0b7974894858a17153d6f54546835066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 3 Feb 2010 11:17:19 +0100 Subject: QGraphicsScene: Use QPainter::setClipRect instead of setClipPath if possible. Using QPainter::setClipPath results in complex (and slow) alphamasking so this must be avoided if possible. Task-number: QTBUG-7790 Reviewed-by: samuel --- src/gui/graphicsview/qgraphicsscene.cpp | 18 +++++++++++++++--- src/gui/painting/qpathclipper.cpp | 4 +--- src/gui/painting/qpathclipper_p.h | 2 ++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 842d368..4bfe9ad 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -251,6 +251,7 @@ #endif #include #include +#include // #define GESTURE_DEBUG #ifndef GESTURE_DEBUG @@ -4765,7 +4766,12 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q painter->setWorldTransform(*transformPtr * *effectTransform); else painter->setWorldTransform(*transformPtr); - painter->setClipPath(item->shape(), Qt::IntersectClip); + QRectF clipRect; + const QPainterPath clipPath(item->shape()); + if (QPathClipper::pathToRect(clipPath, &clipRect)) + painter->setClipRect(clipRect, Qt::IntersectClip); + else + painter->setClipPath(clipPath, Qt::IntersectClip); } // Draw children behind @@ -4801,8 +4807,14 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q painter->setWorldTransform(*transformPtr); } - if (itemClipsToShape) - painter->setClipPath(item->shape(), Qt::IntersectClip); + if (itemClipsToShape) { + QRectF clipRect; + const QPainterPath clipPath(item->shape()); + if (QPathClipper::pathToRect(clipPath, &clipRect)) + painter->setClipRect(clipRect, Qt::IntersectClip); + else + painter->setClipPath(clipPath, Qt::IntersectClip); + } painter->setOpacity(opacity); if (!item->d_ptr->cacheMode && !item->d_ptr->isWidget) diff --git a/src/gui/painting/qpathclipper.cpp b/src/gui/painting/qpathclipper.cpp index 7997e77..5702ede 100644 --- a/src/gui/painting/qpathclipper.cpp +++ b/src/gui/painting/qpathclipper.cpp @@ -90,8 +90,6 @@ static QPointF normalize(const QPointF &p) return p / qSqrt(p.x() * p.x() + p.y() * p.y()); } -static bool pathToRect(const QPainterPath &path, QRectF *rect = 0); - struct QIntersection { qreal alphaA; @@ -1660,7 +1658,7 @@ static bool fuzzyCompare(qreal a, qreal b) return qFuzzyCompare(a, b); } -static bool pathToRect(const QPainterPath &path, QRectF *rect) +bool QPathClipper::pathToRect(const QPainterPath &path, QRectF *rect) { if (path.elementCount() != 5) return false; diff --git a/src/gui/painting/qpathclipper_p.h b/src/gui/painting/qpathclipper_p.h index 0d2c049..b900862 100644 --- a/src/gui/painting/qpathclipper_p.h +++ b/src/gui/painting/qpathclipper_p.h @@ -86,6 +86,8 @@ public: bool intersect(); bool contains(); + static bool pathToRect(const QPainterPath &path, QRectF *rect = 0); + private: Q_DISABLE_COPY(QPathClipper) -- cgit v0.12 From 09fe8e377fea67b4279521e3cb08bb937ef65474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 3 Feb 2010 11:26:50 +0100 Subject: Optimize QPathClipper::pathToRect. Patch speaks for itself :-) Reviewed-by: samuel --- src/gui/painting/qpathclipper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/painting/qpathclipper.cpp b/src/gui/painting/qpathclipper.cpp index 5702ede..bc81514 100644 --- a/src/gui/painting/qpathclipper.cpp +++ b/src/gui/painting/qpathclipper.cpp @@ -1691,7 +1691,7 @@ bool QPathClipper::pathToRect(const QPainterPath &path, QRectF *rect) return false; if (rect) - *rect = QRectF(QPointF(x1, y1), QPointF(x2, y2)); + rect->setCoords(x1, y1, x2, y2); return true; } -- cgit v0.12 From 71e2f9d35a922fb0ec8fff40bdc7d2d47d42dd8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 3 Feb 2010 14:56:43 +0100 Subject: Compiler warning in QAbstractSlider. --- src/gui/widgets/qabstractslider.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index 77c5a01..dca44a4 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -214,8 +214,8 @@ QT_BEGIN_NAMESPACE */ QAbstractSliderPrivate::QAbstractSliderPrivate() - : minimum(0), maximum(99), singleStep(1), pageStep(10), - value(0), position(0), pressValue(-1), offset_accumulated(0), tracking(true), + : minimum(0), maximum(99), pageStep(10), value(0), position(0), pressValue(-1), + singleStep(1), offset_accumulated(0), tracking(true), blocktracking(false), pressed(false), invertedAppearance(false), invertedControls(false), orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction) -- cgit v0.12 From dda8a57c085216db609f822837c50bae38006b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 3 Feb 2010 19:39:17 +0100 Subject: QGraphicsWidget is painted twice on the first show. We want to discard all update requests when we there's a full update pending. The problem was that 'updateAll' was reset too early causing update requests to fall through. To prevent this from happening we reset 'updateAll' right before the items are actually painted. Auto-test included. Task-number: QTBUG-6956 --- src/gui/graphicsview/qgraphicsscene.cpp | 7 +++++- tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 27 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 4bfe9ad..66707fc 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -373,7 +373,10 @@ void QGraphicsScenePrivate::_q_emitUpdated() } } } else { - updateAll = false; + if (views.isEmpty()) { + updateAll = false; + return; + } for (int i = 0; i < views.size(); ++i) views.at(i)->d_func()->processPendingUpdates(); // It's important that we update all views before we dispatch, hence two for-loops. @@ -4604,6 +4607,7 @@ void QGraphicsScenePrivate::drawItems(QPainter *painter, const QTransform *const if (!unpolishedItems.isEmpty()) _q_polishItems(); + updateAll = false; QRectF exposedSceneRect; if (exposedRegion && indexMethod != QGraphicsScene::NoIndex) { exposedSceneRect = exposedRegion->boundingRect().adjusted(-1, -1, 1, 1); @@ -5166,6 +5170,7 @@ void QGraphicsScene::drawItems(QPainter *painter, if (!d->unpolishedItems.isEmpty()) d->_q_polishItems(); + d->updateAll = false; QTransform viewTransform = painter->worldTransform(); Q_UNUSED(options); diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index d3132fe..526486e 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -164,6 +164,7 @@ private slots: void polishEvent(); void polishEvent2(); void initialShow(); + void initialShow2(); // Task fixes void task236127_bspTreeIndexFails(); @@ -2881,6 +2882,32 @@ void tst_QGraphicsWidget::initialShow() QCOMPARE(widget->repaints, 1); } +void tst_QGraphicsWidget::initialShow2() +{ + class MyGraphicsWidget : public QGraphicsWidget + { public: + MyGraphicsWidget() : repaints(0) {} + int repaints; + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } + void polishEvent() { update(); } + }; + + MyGraphicsWidget *widget = new MyGraphicsWidget; + widget->resize(100, 100); + + QGraphicsScene scene(0, 0, 200, 200); + scene.addItem(widget); + + QGraphicsView view(&scene); + view.show(); + // Not using QTest::qWaitForWindowShown(&view); on purpose, because there's + // a bug in qt_x11_wait_for_window_manager that prevents this test + // to pass. Denis is looking into it. + QTest::qWait(300); + + QCOMPARE(widget->repaints, 1); +} + void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() { QGraphicsScene scene; -- cgit v0.12 From 1677382148ed9e8d037d03a6fcc7bbe40458d69a Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Thu, 4 Feb 2010 07:30:37 +1000 Subject: Optimize single-rect IntersectClip in OpenVG using the scissor Task-number: QTBUG-7791 Reviewed-by: Sarah Smith --- src/openvg/qpaintengine_vg.cpp | 46 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index cc9ba77..bff3328 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -188,6 +188,7 @@ public: bool maskValid; // True if vgMask() contains valid data. bool maskIsSet; // True if mask would be fully set if it was valid. + bool scissorMask; // True if scissor is used in place of the mask. bool rawVG; // True if processing a raw VG escape. QRect maskRect; // Rectangle version of mask if it is simple. @@ -355,6 +356,7 @@ void QVGPaintEnginePrivate::init() maskValid = false; maskIsSet = false; + scissorMask = false; rawVG = false; scissorActive = false; @@ -1664,12 +1666,12 @@ void QVGPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) if (op == Qt::NoClip) { d->maskValid = false; d->maskIsSet = true; + d->scissorMask = false; d->maskRect = QRect(); vgSeti(VG_MASKING, VG_FALSE); return; } -#if defined(QVG_NO_RENDER_TO_MASK) // We don't have vgRenderToMask(), so handle simple QRectF's only. if (path.shape() == QVectorPath::RectangleHint && path.elementCount() == 4 && clipTransformIsSimple(d->transform)) { @@ -1679,8 +1681,10 @@ void QVGPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) QRectF rect(points[0], points[1], points[2] - points[0], points[5] - points[1]); clip(rect.toRect(), op); + return; } -#else + +#if !defined(QVG_NO_RENDER_TO_MASK) QPaintDevice *pdev = paintDevice(); int width = pdev->width(); int height = pdev->height(); @@ -1711,6 +1715,7 @@ void QVGPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) vgSeti(VG_MASKING, VG_TRUE); d->maskValid = true; d->maskIsSet = false; + d->scissorMask = false; #endif } @@ -1731,6 +1736,7 @@ void QVGPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) { d->maskValid = false; d->maskIsSet = true; + d->scissorMask = false; d->maskRect = QRect(); vgSeti(VG_MASKING, VG_FALSE); } @@ -1746,6 +1752,7 @@ void QVGPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) vgSeti(VG_MASKING, VG_FALSE); d->maskValid = false; d->maskIsSet = true; + d->scissorMask = false; d->maskRect = QRect(); } else { // Special case: if the intersection of the system @@ -1763,6 +1770,7 @@ void QVGPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) if (clip.rectCount() != 1) { d->maskValid = false; d->maskIsSet = false; + d->scissorMask = false; d->maskRect = QRect(); d->modifyMask(this, VG_FILL_MASK, r); break; @@ -1771,6 +1779,7 @@ void QVGPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) } d->maskValid = false; d->maskIsSet = false; + d->scissorMask = true; d->maskRect = clipRect; vgSeti(VG_MASKING, VG_FALSE); updateScissor(); @@ -1781,13 +1790,30 @@ void QVGPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) case Qt::IntersectClip: { QRect r = d->transform.mapRect(rect); - if (d->maskIsSet && isDefaultClipRect(r)) { + if (!d->maskValid) { + // Mask has not been used yet, so intersect with + // the previous scissor-based region in maskRect. + if (d->scissorMask) + r = r.intersect(d->maskRect); + if (isDefaultClipRect(r)) { + // The clip is the full window, so turn off clipping. + d->maskIsSet = true; + d->maskRect = QRect(); + } else { + // Activate the scissor on a smaller maskRect. + d->maskIsSet = false; + d->maskRect = r; + } + d->scissorMask = true; + updateScissor(); + } else if (d->maskIsSet && isDefaultClipRect(r)) { // Intersecting a full-window clip with a full-window // region is the same as turning off clipping. if (d->maskValid) vgSeti(VG_MASKING, VG_FALSE); d->maskValid = false; d->maskIsSet = true; + d->scissorMask = false; d->maskRect = QRect(); } else { d->modifyMask(this, VG_INTERSECT_MASK, r); @@ -1829,6 +1855,7 @@ void QVGPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) { d->maskValid = false; d->maskIsSet = true; + d->scissorMask = false; d->maskRect = QRect(); vgSeti(VG_MASKING, VG_FALSE); } @@ -1844,6 +1871,7 @@ void QVGPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) vgSeti(VG_MASKING, VG_FALSE); d->maskValid = false; d->maskIsSet = true; + d->scissorMask = false; d->maskRect = QRect(); } else { // Special case: if the intersection of the system @@ -1857,12 +1885,14 @@ void QVGPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) if (clip.rectCount() == 1) { d->maskValid = false; d->maskIsSet = false; + d->scissorMask = true; d->maskRect = clip.boundingRect(); vgSeti(VG_MASKING, VG_FALSE); updateScissor(); } else { d->maskValid = false; d->maskIsSet = false; + d->scissorMask = false; d->maskRect = QRect(); d->modifyMask(this, VG_FILL_MASK, r); } @@ -1887,6 +1917,7 @@ void QVGPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) vgSeti(VG_MASKING, VG_FALSE); d->maskValid = false; d->maskIsSet = true; + d->scissorMask = false; d->maskRect = QRect(); } else { d->modifyMask(this, VG_INTERSECT_MASK, r); @@ -1965,6 +1996,7 @@ void QVGPaintEngine::clip(const QPainterPath &path, Qt::ClipOperation op) if (op == Qt::NoClip) { d->maskValid = false; d->maskIsSet = true; + d->scissorMask = false; d->maskRect = QRect(); vgSeti(VG_MASKING, VG_FALSE); return; @@ -2000,6 +2032,7 @@ void QVGPaintEngine::clip(const QPainterPath &path, Qt::ClipOperation op) vgSeti(VG_MASKING, VG_TRUE); d->maskValid = true; d->maskIsSet = false; + d->scissorMask = false; #else QPaintEngineEx::clip(path, op); #endif @@ -2043,6 +2076,7 @@ void QVGPaintEnginePrivate::modifyMask vgSeti(VG_MASKING, VG_TRUE); maskValid = true; maskIsSet = false; + scissorMask = false; } void QVGPaintEnginePrivate::modifyMask @@ -2064,6 +2098,7 @@ void QVGPaintEnginePrivate::modifyMask vgSeti(VG_MASKING, VG_TRUE); maskValid = true; maskIsSet = false; + scissorMask = false; } #endif // !QVG_SCISSOR_CLIP @@ -2096,7 +2131,7 @@ void QVGPaintEngine::updateScissor() { #if !defined(QVG_SCISSOR_CLIP) // Combine the system clip with the simple mask rectangle. - if (!d->maskRect.isNull()) { + if (d->scissorMask) { if (region.isEmpty()) region = d->maskRect; else @@ -2187,6 +2222,7 @@ void QVGPaintEngine::clipEnabledChanged() // Replay the entire clip stack to put the mask into the right state. d->maskValid = false; d->maskIsSet = true; + d->scissorMask = false; d->maskRect = QRect(); s->clipRegion = defaultClipRegion(); d->replayClipOperations(); @@ -2196,6 +2232,7 @@ void QVGPaintEngine::clipEnabledChanged() vgSeti(VG_MASKING, VG_FALSE); d->maskValid = false; d->maskIsSet = false; + d->scissorMask = false; d->maskRect = QRect(); } #endif @@ -3398,6 +3435,7 @@ void QVGPaintEngine::restoreState(QPaintEngine::DirtyFlags dirty) QPaintEngine::DirtyClipEnabled)) != 0) { d->maskValid = false; d->maskIsSet = false; + d->scissorMask = false; d->maskRect = QRect(); clipEnabledChanged(); } -- cgit v0.12 From 4c84020bd1c049ce82e0deb77196829616b91f4a Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Thu, 4 Feb 2010 10:12:14 +1000 Subject: Use OpenVG scissor on 90/180/270 rotations and simple clips. Task-number: QTBUG-7864 Reviewed-by: Sarah Smith --- src/openvg/qpaintengine_vg.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index bff3328..6813d2f 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -1544,7 +1544,28 @@ void QVGPaintEngine::stroke(const QVectorPath &path, const QPen &pen) static inline bool clipTransformIsSimple(const QTransform& transform) { QTransform::TransformationType type = transform.type(); - return (type == QTransform::TxNone || type == QTransform::TxTranslate); + if (type == QTransform::TxNone || type == QTransform::TxTranslate) + return true; + if (type == QTransform::TxRotate) { + // Check for 0, 90, 180, and 270 degree rotations. + // (0 might happen after 4 rotations of 90 degrees). + qreal m11 = transform.m11(); + qreal m12 = transform.m12(); + qreal m21 = transform.m21(); + qreal m22 = transform.m22(); + if (m11 == 0.0f && m22 == 0.0f) { + if (m12 == 1.0f && m21 == -1.0f) + return true; // 90 degrees. + else if (m12 == -1.0f && m21 == 1.0f) + return true; // 270 degrees. + } else if (m12 == 0.0f && m21 == 0.0f) { + if (m11 == -1.0f && m22 == -1.0f) + return true; // 180 degrees. + else if (m11 == 1.0f && m22 == 1.0f) + return true; // 0 degrees. + } + } + return false; } #if defined(QVG_SCISSOR_CLIP) @@ -2351,12 +2372,7 @@ bool QVGPaintEngine::clearRect(const QRectF &rect, const QColor &color) Q_D(QVGPaintEngine); QVGPainterState *s = state(); if (!s->clipEnabled || s->clipOperation == Qt::NoClip) { - // The transform will either be identity or a simple translation, - // so do a simpler version of "r = d->transform.map(rect).toRect()". - QRect r = QRect(qRound(rect.x() + d->transform.dx()), - qRound(rect.y() + d->transform.dy()), - qRound(rect.width()), - qRound(rect.height())); + QRect r = d->transform.mapRect(rect).toRect(); int height = paintDevice()->height(); if (d->clearColor != color || d->clearOpacity != s->opacity) { VGfloat values[4]; -- cgit v0.12 From 39523f9f78a7c93643924711b1ed8006ebfcf5ce Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 4 Feb 2010 09:54:47 +0100 Subject: Fix the QAbstractSlider autotest. This reverts part of commit d53315d30b38352db11063096ee3867a40bdc234. --- src/gui/widgets/qabstractslider.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index dca44a4..defebb9 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -697,8 +697,6 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e) { Q_D(QAbstractSlider); e->ignore(); - if (e->orientation() != d->orientation && !rect().contains(e->pos())) - return; int stepsToScroll = 0; qreal offset = qreal(e->delta()) / 120; -- cgit v0.12 From 6d1d425e219b0a5e03603f7d708cd740b7d3a3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Thu, 4 Feb 2010 11:44:44 +0100 Subject: Cache the sizes of the images in an animated GIF. Rework the previous commit a bit and include caching of image sizes. Task-number: QTBUG-6696 Reviewed-by: Kim --- src/plugins/imageformats/gif/qgifhandler.cpp | 85 ++++++++++++++++++---------- src/plugins/imageformats/gif/qgifhandler.h | 4 +- tests/auto/qimagereader/tst_qimagereader.cpp | 1 + 3 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/plugins/imageformats/gif/qgifhandler.cpp b/src/plugins/imageformats/gif/qgifhandler.cpp index 6cd7841..6d473e3 100644 --- a/src/plugins/imageformats/gif/qgifhandler.cpp +++ b/src/plugins/imageformats/gif/qgifhandler.cpp @@ -71,8 +71,8 @@ public: ~QGIFFormat(); int decode(QImage *image, const uchar* buffer, int length, - int *nextFrameDelay, int *loopCount, QSize *nextSize); - static int imageCount(QIODevice *device); + int *nextFrameDelay, int *loopCount); + static void scan(QIODevice *device, QVector *imageSizes); bool newFrame; bool partialNewFrame; @@ -230,7 +230,7 @@ void QGIFFormat::disposePrevious(QImage *image) Returns the number of bytes consumed. */ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length, - int *nextFrameDelay, int *loopCount, QSize *nextSize) + int *nextFrameDelay, int *loopCount) { // We are required to state that // "The Graphics Interchange Format(c) is the Copyright property of @@ -347,10 +347,6 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length, bpl = image->bytesPerLine(); bits = image->bits(); memset(bits, 0, image->byteCount()); - - // ### size of the upcoming frame, should rather - // be known before decoding it. - *nextSize = QSize(swidth, sheight); } disposePrevious(image); @@ -647,17 +643,17 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length, } /*! - Returns the number of images that can be read from \a device. + Scans through the data stream defined by \a device and returns the image + sizes found in the stream in the \a imageSizes vector. */ - -int QGIFFormat::imageCount(QIODevice *device) +void QGIFFormat::scan(QIODevice *device, QVector *imageSizes) { if (!device) - return 0; + return; qint64 oldPos = device->pos(); if (!device->seek(0)) - return 0; + return; int colorCount = 0; int localColorCount = 0; @@ -667,18 +663,21 @@ int QGIFFormat::imageCount(QIODevice *device) bool globalColormap = false; int count = 0; int blockSize = 0; + int imageWidth = 0; + int imageHeight = 0; bool done = false; uchar hold[16]; - int imageCount = 0; State state = Header; const int readBufferSize = 40960; // 40k read buffer QByteArray readBuffer(device->read(readBufferSize)); - if (readBuffer.isEmpty()) - return 0; + if (readBuffer.isEmpty()) { + device->seek(oldPos); + return; + } - // this is a specialized version of the state machine from decode(), + // This is a specialized version of the state machine from decode(), // which doesn't do any image decoding or mallocing, and has an // optimized way of skipping SkipBlocks, ImageDataBlocks and // Global/LocalColorMaps. @@ -700,6 +699,8 @@ int QGIFFormat::imageCount(QIODevice *device) case LogicalScreenDescriptor: hold[count++] = ch; if (count == 7) { + imageWidth = LM(hold[0], hold[1]); + imageHeight = LM(hold[2], hold[3]); globalColormap = !!(hold[4] & 0x80); globalColorCount = 2 << (hold[4] & 0x7); count = 0; @@ -753,13 +754,29 @@ int QGIFFormat::imageCount(QIODevice *device) case ImageDescriptor: hold[count++] = ch; if (count == 10) { + int newLeft = LM(hold[1], hold[2]); + int newTop = LM(hold[3], hold[4]); + int newWidth = LM(hold[5], hold[6]); + int newHeight = LM(hold[7], hold[8]); + + if (imageWidth/10 > qMax(newWidth,200)) + imageWidth = -1; + if (imageHeight/10 > qMax(newHeight,200)) + imageHeight = -1; + + if (imageWidth <= 0) + imageWidth = newLeft + newWidth; + if (imageHeight <= 0) + imageHeight = newTop + newHeight; + + *imageSizes << QSize(imageWidth, imageHeight); + localColormap = !!(hold[9] & 0x80); localColorCount = localColormap ? (2 << (hold[9] & 0x7)) : 0; if (localColorCount) colorCount = localColorCount; else colorCount = globalColorCount; - imageCount++; count = 0; if (localColormap) { @@ -865,13 +882,13 @@ int QGIFFormat::imageCount(QIODevice *device) break; case Error: device->seek(oldPos); - return 0; + return; } } readBuffer = device->read(readBufferSize); } device->seek(oldPos); - return imageCount; + return; } void QGIFFormat::fillRect(QImage *image, int col, int row, int w, int h, QRgb color) @@ -994,8 +1011,7 @@ QGifHandler::QGifHandler() nextDelay = 0; loopCnt = 0; frameNumber = -1; - nextSize = QSize(); - imageCnt = -1; + scanIsCached = false; } QGifHandler::~QGifHandler() @@ -1017,7 +1033,7 @@ bool QGifHandler::imageIsComing() const } int decoded = gifFormat->decode(&lastImage, (const uchar *)buffer.constData(), buffer.size(), - &nextDelay, &loopCnt, &nextSize); + &nextDelay, &loopCnt); if (decoded == -1) break; buffer.remove(0, decoded); @@ -1061,7 +1077,7 @@ bool QGifHandler::read(QImage *image) } int decoded = gifFormat->decode(&lastImage, (const uchar *)buffer.constData(), buffer.size(), - &nextDelay, &loopCnt, &nextSize); + &nextDelay, &loopCnt); if (decoded == -1) break; buffer.remove(0, decoded); @@ -1092,8 +1108,18 @@ bool QGifHandler::supportsOption(ImageOption option) const QVariant QGifHandler::option(ImageOption option) const { if (option == Size) { - if (imageIsComing()) - return nextSize; + if (!scanIsCached) { + QGIFFormat::scan(device(), &imageSizes); + scanIsCached = true; + } + // before the first frame is read, or we have an empty data stream + if (frameNumber == -1) + return (imageSizes.count() > 0) ? QVariant(imageSizes.at(0)) : QVariant(); + // after the last frame has been read, the next size is undefined + if (frameNumber >= imageSizes.count() - 1) + return QVariant(); + // and the last case: the size of the next frame + return imageSizes.at(frameNumber + 1); } else if (option == Animation) { return true; } @@ -1113,10 +1139,11 @@ int QGifHandler::nextImageDelay() const int QGifHandler::imageCount() const { - if (imageCnt != -1) - return imageCnt; - imageCnt = QGIFFormat::imageCount(device()); - return imageCnt; + if (!scanIsCached) { + QGIFFormat::scan(device(), &imageSizes); + scanIsCached = true; + } + return imageSizes.count(); } int QGifHandler::loopCount() const diff --git a/src/plugins/imageformats/gif/qgifhandler.h b/src/plugins/imageformats/gif/qgifhandler.h index 830cd38..8e07aff 100644 --- a/src/plugins/imageformats/gif/qgifhandler.h +++ b/src/plugins/imageformats/gif/qgifhandler.h @@ -87,8 +87,8 @@ private: mutable int nextDelay; mutable int loopCnt; int frameNumber; - mutable QSize nextSize; - mutable int imageCnt; + mutable QVector imageSizes; + mutable bool scanIsCached; }; QT_END_NAMESPACE diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index debc090..3e40527 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -881,6 +881,7 @@ void tst_QImageReader::gifImageCount() { QImageReader io(":images/trolltech.gif"); QVERIFY(io.imageCount() == 34); + QVERIFY(io.size() == QSize(128,64)); } } #endif -- cgit v0.12 From 34f1758428282a327c12b0d8040061c1f67ecc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Thu, 4 Feb 2010 11:35:27 +0100 Subject: Crash when closing any top-level widget on Symbian. The window surface must be deleted while the window is valid because on some graphics systems a notifcation is sent to the window when the surface is released. This fix is also an optmization as we no longer process any backing store requests while deleting the top-level. Previously it would handle requests from the window itself and all its children. Task-number: QT-2513 Reviewed-by: jbarron --- src/gui/kernel/qwidget.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 4054d2a..4520a1b 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1439,7 +1439,16 @@ QWidget::~QWidget() } #endif - if (QWidgetBackingStore *bs = d->maybeBackingStore()) { + if (d->extra && d->extra->topextra && d->extra->topextra->backingStore) { + // Okay, we are about to destroy the top-level window that owns + // the backing store. Make sure we delete the backing store right away + // before the window handle is invalid. This is important because + // the backing store will delete its window surface, which may or may + // not have a reference to this widget that will be used later to + // notify the window it no longer has a surface. + delete d->extra->topextra->backingStore; + d->extra->topextra->backingStore = 0; + } else if (QWidgetBackingStore *bs = d->maybeBackingStore()) { bs->removeDirtyWidget(this); if (testAttribute(Qt::WA_StaticContents)) bs->removeStaticWidget(this); -- cgit v0.12 From 417e269c648fab4ad6e2075014419cc7fad69145 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Thu, 4 Feb 2010 12:29:47 +0100 Subject: Fix copy/pasto Reviewed-by: trustme --- src/gui/text/qzipreader_p.h | 2 +- src/gui/text/qzipwriter_p.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qzipreader_p.h b/src/gui/text/qzipreader_p.h index 1086464..67a2ace 100644 --- a/src/gui/text/qzipreader_p.h +++ b/src/gui/text/qzipreader_p.h @@ -49,7 +49,7 @@ // ------------- // // This file is not part of the Qt API. It exists for the convenience -// of the QLibrary class. This header file may change from +// of the QZipReader class. This header file may change from // version to version without notice, or even be removed. // // We mean it. diff --git a/src/gui/text/qzipwriter_p.h b/src/gui/text/qzipwriter_p.h index 7b97937..9322f4a 100644 --- a/src/gui/text/qzipwriter_p.h +++ b/src/gui/text/qzipwriter_p.h @@ -47,7 +47,7 @@ // ------------- // // This file is not part of the Qt API. It exists for the convenience -// of the QLibrary class. This header file may change from +// of the QZipWriter class. This header file may change from // version to version without notice, or even be removed. // // We mean it. -- cgit v0.12 From bc1638138b71adf056f5972b7b1239f4eeffcfec Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Thu, 4 Feb 2010 12:30:18 +0100 Subject: Make sure we define S_IFDIR on Windows Reviewed-by: Thierry Bastian --- src/gui/text/qzip.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gui/text/qzip.cpp b/src/gui/text/qzip.cpp index 2fc1940..d30c996 100644 --- a/src/gui/text/qzip.cpp +++ b/src/gui/text/qzip.cpp @@ -54,10 +54,13 @@ #include #if defined(Q_OS_WIN) -#undef S_IFREG -#define S_IFREG 0100000 +# undef S_IFREG +# define S_IFREG 0100000 +# ifndef S_IFDIR +# define S_IFDIR 0040000 +# endif # ifndef S_ISDIR -# define S_ISDIR(x) ((x) & 0040000) > 0 +# define S_ISDIR(x) ((x) & S_IFDIR) > 0 # endif # ifndef S_ISREG # define S_ISREG(x) ((x) & 0170000) == S_IFREG -- cgit v0.12 From 63d50974f104f3626fee13c24251b91a6b3d046b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Thu, 4 Feb 2010 14:51:59 +0100 Subject: Stabilize tst_QGraphicsWidget::initialShow2 (new test) --- tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 526486e..a7195c4 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -2892,6 +2892,26 @@ void tst_QGraphicsWidget::initialShow2() void polishEvent() { update(); } }; + // Don't let paint events triggered by the windowing system + // influence our test case. We're only interested in knowing + // whether a QGraphicsWidget generates an additional repaint + // on the inital show. Hence create a dummy scenario to find out + // how many repaints we should expect. + QGraphicsScene dummyScene(0, 0, 200, 200); + dummyScene.addItem(new QGraphicsRectItem(0, 0, 100, 100)); + + QGraphicsView *dummyView = new QGraphicsView(&dummyScene); + EventSpy paintSpy(dummyView->viewport(), QEvent::Paint); + dummyView->show(); + // Not using QTest::qWaitForWindowShown(&view); on purpose, because there's + // a bug in qt_x11_wait_for_window_manager that prevents this test + // to pass. Denis is looking into it. + QTest::qWait(300); + const int expectedRepaintCount = paintSpy.count(); + delete dummyView; + dummyView = 0; + QTest::qWait(200); + MyGraphicsWidget *widget = new MyGraphicsWidget; widget->resize(100, 100); @@ -2905,7 +2925,7 @@ void tst_QGraphicsWidget::initialShow2() // to pass. Denis is looking into it. QTest::qWait(300); - QCOMPARE(widget->repaints, 1); + QCOMPARE(widget->repaints, expectedRepaintCount); } void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() -- cgit v0.12 From 030c620e9f3f4e86b77a69e77a604a0c1e946229 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Thu, 4 Feb 2010 13:30:13 +0100 Subject: Improved QTest::qWaitForWindowShown on X11. The function is supposed to wait until the window has been managed by the window manager on X11 - i.e. it has been reparented to a frame, mapped and received at least one Expose event after that. Reviewed-by: Olivier Goffart --- src/gui/kernel/qwidget_x11.cpp | 75 +++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp index 4684bc1..007de7f 100644 --- a/src/gui/kernel/qwidget_x11.cpp +++ b/src/gui/kernel/qwidget_x11.cpp @@ -346,11 +346,6 @@ Q_GUI_EXPORT void qt_x11_enforce_cursor(QWidget * w) qt_x11_enforce_cursor(w, false); } -static Bool checkForConfigureAndExpose(Display *, XEvent *e, XPointer) -{ - return e->type == ConfigureNotify || e->type == Expose; -} - Q_GUI_EXPORT void qt_x11_wait_for_window_manager(QWidget* w) { if (!w || (!w->isWindow() && !w->internalWinId())) @@ -363,38 +358,58 @@ Q_GUI_EXPORT void qt_x11_wait_for_window_manager(QWidget* w) if (!w->testAttribute(Qt::WA_WState_Created)) return; - if (!(w->windowFlags() & Qt::X11BypassWindowManagerHint)) { - // if the window is not override-redirect, then the window manager - // will reparent us to the frame decoration window. - while (!XCheckTypedWindowEvent(X11->display, w->effectiveWinId(), ReparentNotify, &ev)) { - if (t.elapsed() > maximumWaitTime) - return; - qApp->syncX(); // non-busy wait - } - } + // first deliver events that are already in the local queue + QApplication::sendPostedEvents(); - while (!XCheckTypedWindowEvent(X11->display, w->effectiveWinId(), MapNotify, &ev)) { - if (t.elapsed() > maximumWaitTime) - return; - qApp->syncX(); // non-busy wait - } + // the normal sequence is: + // ... ConfigureNotify ... ReparentNotify ... MapNotify ... Expose + // with X11BypassWindowManagerHint: + // ConfigureNotify ... MapNotify ... Expose - qApp->x11ProcessEvent(&ev); + enum State { + Initial, Reparented, Mapped + } state = Initial; - // ok, seems like the window manager successfully reparented us, we'll wait - // for the first paint event to arrive, while handling ConfigureNotify in - // the arrival order - while(1) - { - if (XCheckIfEvent(X11->display, &ev, checkForConfigureAndExpose, 0)) { + do { + if (XEventsQueued(X11->display, QueuedAlready)) { + XNextEvent(X11->display, &ev); qApp->x11ProcessEvent(&ev); - if (ev.type == Expose) - return; + + if (w->windowFlags() & Qt::X11BypassWindowManagerHint) { + switch (state) { + case Initial: + case Reparented: + if (ev.type == MapNotify) + state = Mapped; + break; + case Mapped: + if (ev.type == Expose) + return; + break; + } + } else { + switch (state) { + case Initial: + if (ev.type == ReparentNotify) + state = Reparented; + break; + case Reparented: + if (ev.type == MapNotify) + state = Mapped; + break; + case Mapped: + if (ev.type == Expose) + return; + break; + } + } + } else { + if (!XEventsQueued(X11->display, QueuedAfterFlush)) + qApp->syncX(); // non-busy wait } if (t.elapsed() > maximumWaitTime) return; - qApp->syncX(); // non-busy wait - } + } while(1); } void qt_change_net_wm_state(const QWidget* w, bool set, Atom one, Atom two = 0) -- cgit v0.12 From 555d5b7a87b8c3a2f207c93c7eda30892de5ecc6 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Thu, 4 Feb 2010 13:55:36 +0100 Subject: Changed qgraphicswidget autotest to use qWaitForWindowShown. Make use of (yet another time) improved QTest::qWaitForWindowShown. Reviewed-by: trustme --- tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index a7195c4..2bf1521 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -2919,11 +2919,9 @@ void tst_QGraphicsWidget::initialShow2() scene.addItem(widget); QGraphicsView view(&scene); + view.setWindowFlags(Qt::X11BypassWindowManagerHint); view.show(); - // Not using QTest::qWaitForWindowShown(&view); on purpose, because there's - // a bug in qt_x11_wait_for_window_manager that prevents this test - // to pass. Denis is looking into it. - QTest::qWait(300); + QTest::qWaitForWindowShown(&view); QCOMPARE(widget->repaints, expectedRepaintCount); } -- cgit v0.12 From 39bbc477e418d4d34c2f44fd10e76950a1ae781d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Thu, 4 Feb 2010 17:44:14 +0100 Subject: Cleanup after "QGraphicsWidget is painted twice on the first show" Commit: dda8a57c085216db609f822837c50bae38006b4e We don't want to reset 'updateAll' at that point, for the same reason as mentioned in the above commit. More details in the task. Task-number: QTBUG-6956 --- src/gui/graphicsview/qgraphicsview.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 451f183..96b9373 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -2748,7 +2748,6 @@ bool QGraphicsView::viewportEvent(QEvent *event) } } } - d->scene->d_func()->updateAll = false; } break; case QEvent::TouchBegin: -- cgit v0.12 From e2f439d8ff3529d9ef50ac58da61432627a8f350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Thu, 4 Feb 2010 17:54:24 +0100 Subject: Cleanup after "Changed qgraphicswidget autotest to use qWaitForWindowShown" Commit: 555d5b7a87b8c3a2f207c93c7eda30892de5ecc6 We also have to do the same for the "dummyView". --- tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 2bf1521..00bf144 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -2901,12 +2901,10 @@ void tst_QGraphicsWidget::initialShow2() dummyScene.addItem(new QGraphicsRectItem(0, 0, 100, 100)); QGraphicsView *dummyView = new QGraphicsView(&dummyScene); + dummyView->setWindowFlags(Qt::X11BypassWindowManagerHint); EventSpy paintSpy(dummyView->viewport(), QEvent::Paint); dummyView->show(); - // Not using QTest::qWaitForWindowShown(&view); on purpose, because there's - // a bug in qt_x11_wait_for_window_manager that prevents this test - // to pass. Denis is looking into it. - QTest::qWait(300); + QTest::qWaitForWindowShown(dummyView); const int expectedRepaintCount = paintSpy.count(); delete dummyView; dummyView = 0; -- cgit v0.12 From 3baf7b981a8f40ed13c2ffb62d2188a16005f69c Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 5 Feb 2010 09:48:22 +0100 Subject: fix regression from Qt 4.5 wrt missing text pixels in QTabBar The line spacing fix showed a bug in QCommonStylePrivate::tabLayout. Since QFontMetrics::height() now usually returns one pixel less than in Qt 4.5, the tab bar is one pixel smaller. Squeezing the tab rect vertically can result in missing pixels. This depends on anti-aliasing settings and font size. The new behaviour in tabLayout is now: If we have to shift the tab rect, then we move its position instead of changing its height. Task-number: QTBUG-7137 Reviewed-by: jbache --- src/gui/styles/qcommonstyle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 74d3ec3..b1924e7 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -1149,10 +1149,10 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTabV3 *opt, const QWidget int vpadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabVSpace, opt, widget) / 2; if (opt->shape == QTabBar::RoundedSouth || opt->shape == QTabBar::TriangularSouth) verticalShift = -verticalShift; - tr.adjust(hpadding, vpadding, horizontalShift - hpadding, verticalShift - vpadding); + tr.adjust(hpadding, verticalShift - vpadding, horizontalShift - hpadding, vpadding); bool selected = opt->state & QStyle::State_Selected; if (selected) { - tr.setBottom(tr.bottom() - verticalShift); + tr.setTop(tr.top() - verticalShift); tr.setRight(tr.right() - horizontalShift); } -- cgit v0.12 From 7a300d4d3a89d7002643bd7e70b1525d72967681 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 5 Feb 2010 12:52:37 +0100 Subject: Fixed the context menu test case in the qgraphicsscene autotest. When creating a custom QContextMenuEvent to send to a viewport we should use the viewport to convert the mouse cursor position to screen coordinates. Reviewed-by: Olivier Goffart --- tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index 6743fbe..469ded0 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -2806,14 +2806,14 @@ void tst_QGraphicsScene::contextMenuEvent_ItemIgnoresTransformations() { QPoint pos(50, 50); - QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.mapToGlobal(pos)); + QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); QVERIFY(event.isAccepted()); } { QPoint pos(150, 150); - QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.mapToGlobal(pos)); + QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); QVERIFY(!event.isAccepted()); @@ -2821,14 +2821,14 @@ void tst_QGraphicsScene::contextMenuEvent_ItemIgnoresTransformations() view.scale(1.5, 1.5); { QPoint pos(25, 25); - QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.mapToGlobal(pos)); + QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); QVERIFY(event.isAccepted()); } { QPoint pos(55, 55); - QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.mapToGlobal(pos)); + QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); QVERIFY(!event.isAccepted()); -- cgit v0.12 From fc58ceb0041626baa95d00eaaa2e740171d4767c Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Thu, 21 Jan 2010 17:27:27 +0100 Subject: fix compile error when linuxinput keyboard driver is compiled as plugin When creating the driver instance two parameters are given to the driver. But it accepts only the name of the device to be used. Reviewed-by: Paul Merge-request: 2288 --- src/plugins/kbddrivers/linuxinput/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/kbddrivers/linuxinput/main.cpp b/src/plugins/kbddrivers/linuxinput/main.cpp index 19a3145..db5167e 100644 --- a/src/plugins/kbddrivers/linuxinput/main.cpp +++ b/src/plugins/kbddrivers/linuxinput/main.cpp @@ -69,7 +69,7 @@ QWSKeyboardHandler* QLinuxInputKbdDriver::create(const QString &driver, Q_UNUSED(device); if (driver.compare(QLatin1String("LinuxInput"), Qt::CaseInsensitive)) return 0; - return new QWSLinuxInputKeyboardHandler(driver, device); + return new QWSLinuxInputKeyboardHandler(device); } Q_EXPORT_PLUGIN2(qwslinuxinputkbddriver, QLinuxInputKbdDriver) -- cgit v0.12 From f9c314aa306bfd4a237594775a8aeb14c858e66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Fri, 5 Feb 2010 13:59:16 +0100 Subject: Fix tst_QAccessiblity failure. This started to fail after 34f1758428282a327c12b0d8040061c1f67ecc7f. Or actually, the test crashes on my machine. Reason is that the the test first creates a top-level line edit (which then gets its own backing store). The line edit is then reparented into another top-level. When the line edit is destroyed extra->topextra->backingStore is true and we delete the backing store it first got when created as a top-level. However, the line edit was reparented so this backing store is not the "active" one. We should still delete topextra->backingstore, but we must also remove any pointer references to the line edit in the "active" backing store. Reviewed-by: jbarron --- src/gui/kernel/qwidget.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 4520a1b..8b8768c 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1448,7 +1448,8 @@ QWidget::~QWidget() // notify the window it no longer has a surface. delete d->extra->topextra->backingStore; d->extra->topextra->backingStore = 0; - } else if (QWidgetBackingStore *bs = d->maybeBackingStore()) { + } + if (QWidgetBackingStore *bs = d->maybeBackingStore()) { bs->removeDirtyWidget(this); if (testAttribute(Qt::WA_StaticContents)) bs->removeStaticWidget(this); -- cgit v0.12 From 381f5ae82cccec3774b68674b4c0e782e9f49f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Fri, 5 Feb 2010 16:06:33 +0100 Subject: Fixed QGifHandler::loopCount(). Task-number: QTBUG-7037 Reviewed-by: Kim --- src/plugins/imageformats/gif/qgifhandler.cpp | 38 ++++++++++++++++++----- tests/auto/qimagereader/images/qt-gif-anim.gif | Bin 0 -> 1661 bytes tests/auto/qimagereader/images/qt-gif-noanim.gif | Bin 0 -> 1642 bytes tests/auto/qimagereader/qimagereader.qrc | 4 ++- tests/auto/qimagereader/tst_qimagereader.cpp | 14 +++++++++ 5 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 tests/auto/qimagereader/images/qt-gif-anim.gif create mode 100644 tests/auto/qimagereader/images/qt-gif-noanim.gif diff --git a/src/plugins/imageformats/gif/qgifhandler.cpp b/src/plugins/imageformats/gif/qgifhandler.cpp index 6d473e3..25d3dfa 100644 --- a/src/plugins/imageformats/gif/qgifhandler.cpp +++ b/src/plugins/imageformats/gif/qgifhandler.cpp @@ -72,7 +72,7 @@ public: int decode(QImage *image, const uchar* buffer, int length, int *nextFrameDelay, int *loopCount); - static void scan(QIODevice *device, QVector *imageSizes); + static void scan(QIODevice *device, QVector *imageSizes, int *loopCount); bool newFrame; bool partialNewFrame; @@ -646,7 +646,7 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length, Scans through the data stream defined by \a device and returns the image sizes found in the stream in the \a imageSizes vector. */ -void QGIFFormat::scan(QIODevice *device, QVector *imageSizes) +void QGIFFormat::scan(QIODevice *device, QVector *imageSizes, int *loopCount) { if (!device) return; @@ -842,7 +842,10 @@ void QGIFFormat::scan(QIODevice *device, QVector *imageSizes) hold[count] = ch; ++count; if (count == hold[0] + 1) { - state = SkipBlockSize; + if (qstrncmp((char*)(hold+1), "NETSCAPE", 8) == 0) + state=NetscapeExtensionBlockSize; + else + state=SkipBlockSize; count = 0; } break; @@ -855,7 +858,23 @@ void QGIFFormat::scan(QIODevice *device, QVector *imageSizes) state = SkipBlockSize; } break; - case NetscapeExtensionBlockSize: // fallthrough + case NetscapeExtensionBlockSize: + blockSize = ch; + count = 0; + if (blockSize) + state = NetscapeExtensionBlock; + else + state = Introducer; + break; + case NetscapeExtensionBlock: + if (count < 3) + hold[count] = ch; + count++; + if (count == blockSize) { + *loopCount = LM(hold[1], hold[2]); + state = SkipBlockSize; + } + break; case SkipBlockSize: blockSize = ch; count = 0; @@ -871,7 +890,6 @@ void QGIFFormat::scan(QIODevice *device, QVector *imageSizes) state = Introducer; } break; - case NetscapeExtensionBlock: // fallthrough case SkipBlock: ++count; if (count == blockSize) @@ -1009,7 +1027,7 @@ QGifHandler::QGifHandler() { gifFormat = new QGIFFormat; nextDelay = 0; - loopCnt = 0; + loopCnt = 1; frameNumber = -1; scanIsCached = false; } @@ -1109,7 +1127,7 @@ QVariant QGifHandler::option(ImageOption option) const { if (option == Size) { if (!scanIsCached) { - QGIFFormat::scan(device(), &imageSizes); + QGIFFormat::scan(device(), &imageSizes, &loopCnt); scanIsCached = true; } // before the first frame is read, or we have an empty data stream @@ -1140,7 +1158,7 @@ int QGifHandler::nextImageDelay() const int QGifHandler::imageCount() const { if (!scanIsCached) { - QGIFFormat::scan(device(), &imageSizes); + QGIFFormat::scan(device(), &imageSizes, &loopCnt); scanIsCached = true; } return imageSizes.count(); @@ -1148,6 +1166,10 @@ int QGifHandler::imageCount() const int QGifHandler::loopCount() const { + if (!scanIsCached) { + QGIFFormat::scan(device(), &imageSizes, &loopCnt); + scanIsCached = true; + } return loopCnt-1; // In GIF, loop count is iteration count, so subtract one } diff --git a/tests/auto/qimagereader/images/qt-gif-anim.gif b/tests/auto/qimagereader/images/qt-gif-anim.gif new file mode 100644 index 0000000..8bca4a8 Binary files /dev/null and b/tests/auto/qimagereader/images/qt-gif-anim.gif differ diff --git a/tests/auto/qimagereader/images/qt-gif-noanim.gif b/tests/auto/qimagereader/images/qt-gif-noanim.gif new file mode 100644 index 0000000..b6a8540 Binary files /dev/null and b/tests/auto/qimagereader/images/qt-gif-noanim.gif differ diff --git a/tests/auto/qimagereader/qimagereader.qrc b/tests/auto/qimagereader/qimagereader.qrc index 58f2f74..bc48244 100644 --- a/tests/auto/qimagereader/qimagereader.qrc +++ b/tests/auto/qimagereader/qimagereader.qrc @@ -1,5 +1,5 @@ - + images/16bpp.bmp images/4bpp-rle.bmp images/YCbCr_cmyk.jpg @@ -59,5 +59,7 @@ images/qt8.gif images/endless-anim.gif images/four-frames.gif + images/qt-gif-anim.gif + images/qt-gif-noanim.gif diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index 3e40527..121a8fa 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -142,6 +142,7 @@ private slots: void gifHandlerBugs(); void animatedGif(); void gifImageCount(); + void gifLoopCount(); #endif void readCorruptImage_data(); @@ -884,6 +885,19 @@ void tst_QImageReader::gifImageCount() QVERIFY(io.size() == QSize(128,64)); } } + +void tst_QImageReader::gifLoopCount() +{ + { + QImageReader io(":images/qt-gif-anim.gif"); + QCOMPARE(io.loopCount(), -1); // infinite loop + } + { + QImageReader io(":images/qt-gif-noanim.gif"); + QCOMPARE(io.loopCount(), 0); // no loop + } +} + #endif class Server : public QObject -- cgit v0.12 From fb8d0593198313b975ed6c0c9ba99624d1d1fbec Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Fri, 5 Feb 2010 16:44:51 +0100 Subject: Revert change 34f1758 on non-Synbian platforms The change introduces behavior changes (including crashing on QWS). It is only critical for Symbian. To reduce risk, we only apply it on the Symbian platform for now. Task-number: Autotest regression Reviewed-by: Jesper --- src/gui/kernel/qwidget.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 72388f0..c072d9d 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1439,6 +1439,7 @@ QWidget::~QWidget() } #endif +#ifdef Q_OS_SYMBIAN if (d->extra && d->extra->topextra && d->extra->topextra->backingStore) { // Okay, we are about to destroy the top-level window that owns // the backing store. Make sure we delete the backing store right away @@ -1449,6 +1450,7 @@ QWidget::~QWidget() delete d->extra->topextra->backingStore; d->extra->topextra->backingStore = 0; } +#endif if (QWidgetBackingStore *bs = d->maybeBackingStore()) { bs->removeDirtyWidget(this); if (testAttribute(Qt::WA_StaticContents)) -- cgit v0.12 From 2bc5d161e6820d459f00ac687ed99830a731cb74 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 5 Feb 2010 16:59:33 +0100 Subject: Fixed qt_x11_wait_for_window_manager When we wait for the window to be shown by looking for ReparentNotify, MapNotify, etc events in the event queue, we should check if those events come for the right window, otherwise we might exit too early if there are event for an other window in the queue. Reviewed-by: Leonardo Sobral Cunha --- src/gui/kernel/qwidget_x11.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp index 007de7f..10fb009 100644 --- a/src/gui/kernel/qwidget_x11.cpp +++ b/src/gui/kernel/qwidget_x11.cpp @@ -358,6 +358,8 @@ Q_GUI_EXPORT void qt_x11_wait_for_window_manager(QWidget* w) if (!w->testAttribute(Qt::WA_WState_Created)) return; + WId winid = w->internalWinId(); + // first deliver events that are already in the local queue QApplication::sendPostedEvents(); @@ -379,26 +381,26 @@ Q_GUI_EXPORT void qt_x11_wait_for_window_manager(QWidget* w) switch (state) { case Initial: case Reparented: - if (ev.type == MapNotify) + if (ev.type == MapNotify && ev.xany.window == winid) state = Mapped; break; case Mapped: - if (ev.type == Expose) + if (ev.type == Expose && ev.xany.window == winid) return; break; } } else { switch (state) { case Initial: - if (ev.type == ReparentNotify) + if (ev.type == ReparentNotify && ev.xany.window == winid) state = Reparented; break; case Reparented: - if (ev.type == MapNotify) + if (ev.type == MapNotify && ev.xany.window == winid) state = Mapped; break; case Mapped: - if (ev.type == Expose) + if (ev.type == Expose && ev.xany.window == winid) return; break; } -- cgit v0.12