From c8bb76ec0b19da9e24512852dc8b00461e1a1b7b Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Thu, 22 Jul 2010 16:15:55 +0200 Subject: Fix the CGContext on Mac OS X. Sometimes we got a bad context, resulting in wrong paintings. It also unify the raster engine behavior among platforms. Reviewed-by: Jason Barron --- src/gui/graphicsview/qgraphicsview_p.h | 34 +++++++++++++++++------------- src/gui/kernel/qcocoaview_mac.mm | 4 ++-- src/gui/kernel/qt_cocoa_helpers_mac.mm | 2 +- src/gui/painting/qwindowsurface_raster.cpp | 16 ++++---------- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h index 7bd9ecb..62be800 100644 --- a/src/gui/graphicsview/qgraphicsview_p.h +++ b/src/gui/graphicsview/qgraphicsview_p.h @@ -62,6 +62,7 @@ #include "qgraphicssceneevent.h" #include #include +#include QT_BEGIN_NAMESPACE @@ -180,21 +181,24 @@ public: inline void dispatchPendingUpdateRequests() { -#ifndef Q_WS_MAC - // QWidget::update() works slightly different on the Mac; it's not part of - // our backing store so it needs special threatment. - if (qt_widget_private(viewport)->paintOnScreen()) - QCoreApplication::sendPostedEvents(viewport, QEvent::UpdateRequest); - else - QCoreApplication::sendPostedEvents(viewport->window(), QEvent::UpdateRequest); -#else - // At this point either HIViewSetNeedsDisplay (Carbon) or setNeedsDisplay: YES (Cocoa) - // is called, which means there's a pending update request. We want to dispatch it - // now because otherwise graphics view updates would require two - // round-trips in the event loop before the item is painted. - extern void qt_mac_dispatchPendingUpdateRequests(QWidget *); - qt_mac_dispatchPendingUpdateRequests(viewport->window()); -#endif +#ifdef Q_WS_MAC + // QWidget::update() works slightly different on the Mac without the raster engine; + // it's not part of our backing store so it needs special threatment. + if (QApplicationPrivate::graphics_system_name != "raster") { + // At this point either HIViewSetNeedsDisplay (Carbon) or setNeedsDisplay: YES (Cocoa) + // is called, which means there's a pending update request. We want to dispatch it + // now because otherwise graphics view updates would require two + // round-trips in the event loop before the item is painted. + extern void qt_mac_dispatchPendingUpdateRequests(QWidget *); + qt_mac_dispatchPendingUpdateRequests(viewport->window()); + } else +#endif // !Q_WS_MAC + { + if (qt_widget_private(viewport)->paintOnScreen()) + QCoreApplication::sendPostedEvents(viewport, QEvent::UpdateRequest); + else + QCoreApplication::sendPostedEvents(viewport->window(), QEvent::UpdateRequest); + } } void setUpdateClip(QGraphicsItem *); diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 3665557..c9fa79b 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -498,9 +498,9 @@ static int qCocoaViewCount = 0; return; if (QApplicationPrivate::graphicsSystem() != 0) { - if (QWidgetBackingStore *bs = qwidgetprivate->maybeBackingStore()) - bs->markDirty(qwidget->rect(), qwidget); + qwidget->update(qwidget->rect()); qwidgetprivate->syncBackingStore(qwidget->rect()); + return; } CGContextRef cg = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index e3478e6..2eee434 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -1332,7 +1332,7 @@ CGContextRef qt_mac_graphicsContextFor(QWidget *widget) CGrafPtr port = GetWindowPort(qt_mac_window_for(widget)); QDBeginCGContext(port, &context); #else - CGContextRef context = reinterpret_cast([[qt_mac_window_for(widget) graphicsContext] graphicsPort]); + CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithWindow:qt_mac_window_for(widget)] graphicsPort]; #endif return context; } diff --git a/src/gui/painting/qwindowsurface_raster.cpp b/src/gui/painting/qwindowsurface_raster.cpp index f3e1e4e..6a2cb1e 100644 --- a/src/gui/painting/qwindowsurface_raster.cpp +++ b/src/gui/painting/qwindowsurface_raster.cpp @@ -248,10 +248,6 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi #ifdef Q_WS_MAC -// qDebug() << "Flushing" << widget << rgn << offset; - -// d->image->image.save("flush.png"); - Q_UNUSED(offset); // Get a context for the widget. #ifndef QT_MAC_USE_COCOA @@ -282,23 +278,19 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi CGImageRef subImage = CGImageCreateWithImageInRect(image, area); qt_mac_drawCGImage(context, &area, subImage); + CGImageRelease(subImage); CGImageRelease(image); -// CGSize size = { d->image->image.width(), d->image->image.height() }; -// CGLayerRef layer = CGLayerCreateWithContext(d->image->cg, size, 0); -// CGPoint pt = { 0, 0 }; -// CGContextDrawLayerAtPoint(context, pt, layer); -// CGLayerRelease(layer); - - // Restore context. - CGContextRestoreGState(context); #ifndef QT_MAC_USE_COCOA QDEndCGContext(port, &context); #else CGContextFlush(context); #endif + // Restore context. + CGContextRestoreGState(context); + #endif // Q_WS_MAC #ifdef Q_OS_SYMBIAN -- cgit v0.12 From d9d877326b13c55dc33b1cac13f3ee70e8de62bf Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Thu, 22 Jul 2010 17:53:59 +0200 Subject: Make QPalette::operator== return false if the currentColorGroup differs This was affecting QLineEdit's selected text color when the window is inactive. Task-number: QTBUG-697 Reviewed-by: ogoffart --- src/gui/kernel/qpalette.cpp | 2 ++ src/gui/widgets/qlineedit.cpp | 2 +- tests/auto/qpalette/tst_qpalette.cpp | 30 ++++++++++++++++++++++++++++++ tests/auto/qwidget/tst_qwidget.cpp | 6 +++--- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index 98e8f66..910dfa9 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -876,6 +876,8 @@ void QPalette::detach() */ bool QPalette::operator==(const QPalette &p) const { + if (p.currentColorGroup() != current_group) + return false; if (isCopyOf(p)) return true; for(int grp = 0; grp < (int)NColorGroups; grp++) { diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index 1bffde1..98f0f44 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1946,7 +1946,7 @@ void QLineEdit::paintEvent(QPaintEvent *) if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){ flags |= QLineControl::DrawSelections; // Palette only used for selections/mask and may not be in sync - if(d->control->palette() != pal) + if (d->control->palette() != pal) d->control->setPalette(pal); } diff --git a/tests/auto/qpalette/tst_qpalette.cpp b/tests/auto/qpalette/tst_qpalette.cpp index 2501f8d..65eabbd 100644 --- a/tests/auto/qpalette/tst_qpalette.cpp +++ b/tests/auto/qpalette/tst_qpalette.cpp @@ -65,6 +65,7 @@ public slots: private slots: void roleValues_data(); void roleValues(); + void operators(); }; tst_QPalette::tst_QPalette() @@ -128,5 +129,34 @@ void tst_QPalette::roleValues() QCOMPARE(role, value); } +void tst_QPalette::operators() +{ + { + QPalette palette = qApp->palette(); + QPalette copy = palette; + QCOMPARE(palette.currentColorGroup(), copy.currentColorGroup()); + QCOMPARE(palette.resolve(), copy.resolve()); + QVERIFY(copy.isCopyOf(palette)); + + } + + { + QPalette palette = qApp->palette(); + QPalette copy = palette; + copy.setColor(QPalette::Base, palette.color(QPalette::Base).lighter()); + QVERIFY(palette != copy); + QVERIFY(!copy.isCopyOf(palette)); + } + + { + QPalette palette = qApp->palette(); + QPalette copy = palette; + copy.setCurrentColorGroup(QPalette::Inactive); + palette.setCurrentColorGroup(QPalette::Active); + QVERIFY(palette != copy); + } + +} + QTEST_MAIN(tst_QPalette) #include "tst_qpalette.moc" diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 2d559c8..f0c40e8 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -988,8 +988,8 @@ void tst_QWidget::palettePropagation2() { // ! Note, the code below is executed in tst_QWidget's constructor. // QPalette palette; - // font.setColor(QPalette::ToolTipBase, QColor(12, 13, 14)); - // font.setColor(QPalette::Text, QColor(21, 22, 23)); + // palette.setColor(QPalette::ToolTipBase, QColor(12, 13, 14)); + // palette.setColor(QPalette::Text, QColor(21, 22, 23)); // qApp->setPalette(palette, "QPropagationTestWidget"); QWidget *root = new QWidget; @@ -1000,7 +1000,7 @@ void tst_QWidget::palettePropagation2() QWidget *child4 = new QWidget(child3); QWidget *child5 = new QWidget(child4); root->show(); - QTest::qWait(100); + QTest::qWaitForWindowShown(root); // These colors are unlikely to be imposed on the default palette of // QWidget ;-). -- cgit v0.12 From f8c82039e9b665cabaf605a3d363108e732d8205 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Fri, 23 Jul 2010 11:01:38 +0200 Subject: Revert "Make QPalette::operator== return false if the currentColorGroup differs" This reverts commit d9d877326b13c55dc33b1cac13f3ee70e8de62bf. The behavior change it implied was bigger than expected and made too many autotests fail. Will document better that the currentColorGroup is not taken into account when comparing palettes. --- src/gui/kernel/qpalette.cpp | 2 -- src/gui/widgets/qlineedit.cpp | 2 +- tests/auto/qpalette/tst_qpalette.cpp | 30 ------------------------------ tests/auto/qwidget/tst_qwidget.cpp | 6 +++--- 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index 910dfa9..98e8f66 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -876,8 +876,6 @@ void QPalette::detach() */ bool QPalette::operator==(const QPalette &p) const { - if (p.currentColorGroup() != current_group) - return false; if (isCopyOf(p)) return true; for(int grp = 0; grp < (int)NColorGroups; grp++) { diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index 98f0f44..1bffde1 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1946,7 +1946,7 @@ void QLineEdit::paintEvent(QPaintEvent *) if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){ flags |= QLineControl::DrawSelections; // Palette only used for selections/mask and may not be in sync - if (d->control->palette() != pal) + if(d->control->palette() != pal) d->control->setPalette(pal); } diff --git a/tests/auto/qpalette/tst_qpalette.cpp b/tests/auto/qpalette/tst_qpalette.cpp index 65eabbd..2501f8d 100644 --- a/tests/auto/qpalette/tst_qpalette.cpp +++ b/tests/auto/qpalette/tst_qpalette.cpp @@ -65,7 +65,6 @@ public slots: private slots: void roleValues_data(); void roleValues(); - void operators(); }; tst_QPalette::tst_QPalette() @@ -129,34 +128,5 @@ void tst_QPalette::roleValues() QCOMPARE(role, value); } -void tst_QPalette::operators() -{ - { - QPalette palette = qApp->palette(); - QPalette copy = palette; - QCOMPARE(palette.currentColorGroup(), copy.currentColorGroup()); - QCOMPARE(palette.resolve(), copy.resolve()); - QVERIFY(copy.isCopyOf(palette)); - - } - - { - QPalette palette = qApp->palette(); - QPalette copy = palette; - copy.setColor(QPalette::Base, palette.color(QPalette::Base).lighter()); - QVERIFY(palette != copy); - QVERIFY(!copy.isCopyOf(palette)); - } - - { - QPalette palette = qApp->palette(); - QPalette copy = palette; - copy.setCurrentColorGroup(QPalette::Inactive); - palette.setCurrentColorGroup(QPalette::Active); - QVERIFY(palette != copy); - } - -} - QTEST_MAIN(tst_QPalette) #include "tst_qpalette.moc" diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index f0c40e8..2d559c8 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -988,8 +988,8 @@ void tst_QWidget::palettePropagation2() { // ! Note, the code below is executed in tst_QWidget's constructor. // QPalette palette; - // palette.setColor(QPalette::ToolTipBase, QColor(12, 13, 14)); - // palette.setColor(QPalette::Text, QColor(21, 22, 23)); + // font.setColor(QPalette::ToolTipBase, QColor(12, 13, 14)); + // font.setColor(QPalette::Text, QColor(21, 22, 23)); // qApp->setPalette(palette, "QPropagationTestWidget"); QWidget *root = new QWidget; @@ -1000,7 +1000,7 @@ void tst_QWidget::palettePropagation2() QWidget *child4 = new QWidget(child3); QWidget *child5 = new QWidget(child4); root->show(); - QTest::qWaitForWindowShown(root); + QTest::qWait(100); // These colors are unlikely to be imposed on the default palette of // QWidget ;-). -- cgit v0.12