diff options
author | Fabien Freling <fabien.freling@nokia.com> | 2011-03-15 13:48:49 (GMT) |
---|---|---|
committer | Fabien Freling <fabien.freling@nokia.com> | 2011-03-15 13:48:49 (GMT) |
commit | d524e983c60ba59f3c65d811ec92f02c97d1a8ab (patch) | |
tree | 6157eb8a3f3123c5dbebbc07591da81653f3331a /src/gui | |
parent | 2b9e7bcede5ca6ba9de2534839244cc621f17e1c (diff) | |
download | Qt-d524e983c60ba59f3c65d811ec92f02c97d1a8ab.zip Qt-d524e983c60ba59f3c65d811ec92f02c97d1a8ab.tar.gz Qt-d524e983c60ba59f3c65d811ec92f02c97d1a8ab.tar.bz2 |
Change the way the unified toolbar is flushed.
The flushing of the unified toolbar is no
longer tied to the main window, making it more
flexible.
Task-number: QTBUG-17754
Reviewed-by: Richard Moe Gustavsen
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qcocoawindowdelegate_mac.mm | 18 | ||||
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 14 | ||||
-rw-r--r-- | src/gui/painting/qunifiedtoolbarsurface_mac.cpp | 31 | ||||
-rw-r--r-- | src/gui/painting/qunifiedtoolbarsurface_mac_p.h | 4 | ||||
-rw-r--r-- | src/gui/painting/qwindowsurface_raster.cpp | 20 |
5 files changed, 50 insertions, 37 deletions
diff --git a/src/gui/kernel/qcocoawindowdelegate_mac.mm b/src/gui/kernel/qcocoawindowdelegate_mac.mm index 9e7aa58..1faf068 100644 --- a/src/gui/kernel/qcocoawindowdelegate_mac.mm +++ b/src/gui/kernel/qcocoawindowdelegate_mac.mm @@ -48,6 +48,9 @@ #include <qlayout.h> #include <qcoreapplication.h> #include <qmenubar.h> +#include <QMainWindow> +#include <QToolBar> +#include <private/qmainwindowlayout_p.h> QT_BEGIN_NAMESPACE extern QWidgetData *qt_qwidget_data(QWidget *); // qwidget.cpp @@ -218,8 +221,21 @@ static void cleanupCocoaWindowDelegate() // We force the repaint to be synchronized with the resize of the window. // Otherwise, the resize looks sluggish because we paint one event loop later. - if ([[window contentView] inLiveResize]) + if ([[window contentView] inLiveResize]) { qwidget->repaint(); + + // We need to repaint the toolbar as well. + QMainWindow* mWindow = qobject_cast<QMainWindow*>(qwidget->window()); + if (mWindow) { + QMainWindowLayout *mLayout = qobject_cast<QMainWindowLayout*>(mWindow->layout()); + QList<QToolBar *> toolbarList = mLayout->qtoolbarsInUnifiedToolbarList; + + for (int i = 0; i < toolbarList.size(); ++i) { + QToolBar* toolbar = toolbarList.at(i); + toolbar->repaint(); + } + } + } } - (void)windowDidMove:(NSNotification *)notification diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 5fc9951..198d4e5 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1367,6 +1367,16 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) QApplication::postEvent(q, new QEvent(QEvent::PolishRequest)); extraPaintEngine = 0; + +#ifdef QT_MAC_USE_COCOA + // If we add a child to the unified toolbar, we have to redirect the painting. + if (parentWidget && parentWidget->d_func() && parentWidget->d_func()->isInUnifiedToolbar) { + if (parentWidget->d_func()->unifiedSurface) { + QWidget *toolbar = parentWidget->d_func()->toolbar_ancestor; + parentWidget->d_func()->unifiedSurface->recursiveRedirect(toolbar, toolbar, toolbar->d_func()->toolbar_offset); + } + } +#endif // QT_MAC_USE_COCOA } @@ -10478,7 +10488,7 @@ void QWidget::update(const QRect &rect) if (hasBackingStoreSupport()) { #ifdef QT_MAC_USE_COCOA if (qt_widget_private(this)->isInUnifiedToolbar) { - qt_widget_private(this)->unifiedSurface->renderToolbar(this); + qt_widget_private(this)->unifiedSurface->renderToolbar(this, true); return; } #endif // QT_MAC_USE_COCOA @@ -10508,7 +10518,7 @@ void QWidget::update(const QRegion &rgn) if (hasBackingStoreSupport()) { #ifdef QT_MAC_USE_COCOA if (qt_widget_private(this)->isInUnifiedToolbar) { - qt_widget_private(this)->unifiedSurface->renderToolbar(this); + qt_widget_private(this)->unifiedSurface->renderToolbar(this, true); return; } #endif // QT_MAC_USE_COCOA diff --git a/src/gui/painting/qunifiedtoolbarsurface_mac.cpp b/src/gui/painting/qunifiedtoolbarsurface_mac.cpp index 87206f3..0993b22 100644 --- a/src/gui/painting/qunifiedtoolbarsurface_mac.cpp +++ b/src/gui/painting/qunifiedtoolbarsurface_mac.cpp @@ -106,16 +106,18 @@ void QUnifiedToolbarSurface::recursiveRemoval(QObject *object) if (object->isWidgetType()) { QWidget *widget = qobject_cast<QWidget *>(object); - if (!(widget->windowType() & Qt::Window)) { - widget->d_func()->unifiedSurface = 0; - widget->d_func()->isInUnifiedToolbar = false; - widget->d_func()->toolbar_offset = QPoint(); - widget->d_func()->toolbar_ancestor = 0; + // If it's a pop-up or something similar, we don't redirect it. + if (widget->windowType() & Qt::Window) + return; + + widget->d_func()->unifiedSurface = 0; + widget->d_func()->isInUnifiedToolbar = false; + widget->d_func()->toolbar_offset = QPoint(); + widget->d_func()->toolbar_ancestor = 0; + } - for (int i = 0; i < object->children().size(); ++i) { - recursiveRemoval(object->children().at(i)); - } - } + for (int i = 0; i < object->children().size(); ++i) { + recursiveRemoval(object->children().at(i)); } } } @@ -154,12 +156,11 @@ void QUnifiedToolbarSurface::updateToolbarOffset(QWidget *widget) mlayout->updateUnifiedToolbarOffset(); } -void QUnifiedToolbarSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset) +void QUnifiedToolbarSurface::flush(QWidget *widget) { Q_D(QUnifiedToolbarSurface); - Q_UNUSED(offset); - if (!d->image || rgn.rectCount() == 0) + if (!d->image) return; if (widget->d_func()->flushRequested) { @@ -173,7 +174,7 @@ void QUnifiedToolbarSurface::prepareBuffer(QImage::Format format, QWidget *widge Q_D(QUnifiedToolbarSurface); int width = geometry().width(); - int height = geometry().height(); + int height = 100; // FIXME if (d->image) { width = qMax(d->image->width(), width); height = qMax(d->image->height(), height); @@ -244,11 +245,11 @@ void QUnifiedToolbarSurface::renderToolbar(QWidget *widget, bool forceFlush) QRegion beginPaintRegion(beginPaintRect); beginPaint(beginPaintRegion); - toolbar->render(paintDevice(), toolbar->d_func()->toolbar_offset, QRegion(), QWidget::DrawChildren); + toolbar->render(paintDevice(), toolbar->d_func()->toolbar_offset, QRegion(toolbar->geometry()), QWidget::DrawChildren); toolbar->d_func()->flushRequested = true; if (forceFlush) - flush(toolbar, beginPaintRegion, toolbar->d_func()->toolbar_offset); + flush(toolbar); } QT_END_NAMESPACE diff --git a/src/gui/painting/qunifiedtoolbarsurface_mac_p.h b/src/gui/painting/qunifiedtoolbarsurface_mac_p.h index 99839fa..8a552fb 100644 --- a/src/gui/painting/qunifiedtoolbarsurface_mac_p.h +++ b/src/gui/painting/qunifiedtoolbarsurface_mac_p.h @@ -79,20 +79,20 @@ public: QUnifiedToolbarSurface(QWidget *widget); ~QUnifiedToolbarSurface(); - void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); + void flush(QWidget *widget); void setGeometry(const QRect &rect); void beginPaint(const QRegion &rgn); void insertToolbar(QWidget *toolbar, const QPoint &offset); void removeToolbar(QToolBar *toolbar); void updateToolbarOffset(QWidget *widget); void renderToolbar(QWidget *widget, bool forceFlush = false); + void recursiveRedirect(QObject *widget, QWidget *parent_toolbar, const QPoint &offset); QPaintDevice *paintDevice(); CGContextRef imageContext(); private: void prepareBuffer(QImage::Format format, QWidget *widget); - void recursiveRedirect(QObject *widget, QWidget *parent_toolbar, const QPoint &offset); void recursiveRemoval(QObject *object); Q_DECLARE_PRIVATE(QUnifiedToolbarSurface) diff --git a/src/gui/painting/qwindowsurface_raster.cpp b/src/gui/painting/qwindowsurface_raster.cpp index 27d8cb9..8170b7a 100644 --- a/src/gui/painting/qwindowsurface_raster.cpp +++ b/src/gui/painting/qwindowsurface_raster.cpp @@ -277,35 +277,21 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi #ifdef Q_WS_MAC + Q_UNUSED(offset); + // This is mainly done for native components like native "open file" dialog. if (widget->testAttribute(Qt::WA_DontShowOnScreen)) { return; } #ifdef QT_MAC_USE_COCOA + this->needsFlush = true; this->regionToFlush += rgn; // The actual flushing will be processed in [view drawRect:rect] qt_mac_setNeedsDisplay(widget); - // Unified toolbar hack. - // We issue a flush call for each QToolBar so they get repainted right after - // the main window. - QMainWindow* mWindow = qobject_cast<QMainWindow*>(widget->window()); - if (mWindow) { - QMainWindowLayout *mLayout = qobject_cast<QMainWindowLayout*>(mWindow->layout()); - QList<QToolBar *> toolbarList = mLayout->qtoolbarsInUnifiedToolbarList; - - for (int i = 0; i < toolbarList.size(); ++i) { - QToolBar* toolbar = toolbarList.at(i); - if (mLayout->toolBarArea(toolbar) == Qt::TopToolBarArea) { - QWidget* tbWidget = (QWidget*) toolbar; - if (tbWidget->d_func()->unifiedSurface) - tbWidget->d_func()->unifiedSurface->flush(tbWidget, rgn, offset); - } - } - } #else // Get a context for the widget. CGContextRef context; |