diff options
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 138 |
1 files changed, 70 insertions, 68 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index e1ce731418..51b2bf8b5f 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -4508,8 +4508,7 @@ void QWidget::setForegroundRole(QPalette::ColorRole role) style, depend on third party APIs to render the content of widgets, and these styles typically do not follow the palette. Because of this, assigning roles to a widget's palette is not guaranteed to change the - appearance of the widget. Instead, you may choose to apply a \l - styleSheet. + appearance of the widget. Instead, you may choose to apply a \l {styleSheet}. \warning Do not use this function in conjunction with \l{Qt Style Sheets}. When using style sheets, the palette of a widget can be customized using @@ -5313,7 +5312,7 @@ void QWidget::setGraphicsEffect(QGraphicsEffect *effect) return; if (d->graphicsEffect) { - d->invalidateBuffer(rect()); + d->invalidateBackingStore(rect()); delete d->graphicsEffect; d->graphicsEffect = 0; } @@ -7330,11 +7329,11 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) if (renderToTexture) { QRegion updateRegion(q->geometry()); updateRegion += QRect(oldPos, olds); - q->parentWidget()->d_func()->invalidateBuffer(updateRegion); + q->parentWidget()->d_func()->invalidateBackingStore(updateRegion); } else if (isMove && !isResize) { moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y()); } else { - invalidateBuffer_resizeHelper(oldPos, olds); + invalidateBackingStore_resizeHelper(oldPos, olds); } } } @@ -8096,7 +8095,7 @@ void QWidgetPrivate::show_sys() QWidgetWindow *window = windowHandle(); if (q->testAttribute(Qt::WA_DontShowOnScreen)) { - invalidateBuffer(q->rect()); + invalidateBackingStore(q->rect()); q->setAttribute(Qt::WA_Mapped); // add our window the modal window list (native dialogs) if (window && q->isWindow() @@ -8139,7 +8138,7 @@ void QWidgetPrivate::show_sys() #ifndef QT_NO_CURSOR qt_qpa_set_cursor(q, false); // Needed in case cursor was set before show #endif - invalidateBuffer(q->rect()); + invalidateBackingStore(q->rect()); window->setNativeWindowVisibility(true); // Was the window moved by the Window system or QPlatformWindow::initialGeometry() ? if (window->isTopLevel()) { @@ -8253,12 +8252,12 @@ void QWidgetPrivate::hide_sys() QWidget *p = q->parentWidget(); if (p &&p->isVisible()) { if (renderToTexture) - p->d_func()->invalidateBuffer(q->geometry()); + p->d_func()->invalidateBackingStore(q->geometry()); else - invalidateBuffer(q->rect()); + invalidateBackingStore(q->rect()); } } else { - invalidateBuffer(q->rect()); + invalidateBackingStore(q->rect()); } if (window) @@ -8288,49 +8287,57 @@ void QWidgetPrivate::hide_sys() \endlist */ - void QWidget::setVisible(bool visible) { - if (visible) { // show - if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) - return; + if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden) == !visible) + return; - Q_D(QWidget); + // Remember that setVisible was called explicitly + setAttribute(Qt::WA_WState_ExplicitShowHide); + + Q_D(QWidget); + d->setVisible(visible); +} +// This method is called from QWidgetWindow in response to QWindow::setVisible, +// and should match the semantics of QWindow::setVisible. QWidget::setVisible on +// the other hand keeps track of WA_WState_ExplicitShowHide in addition. +void QWidgetPrivate::setVisible(bool visible) +{ + Q_Q(QWidget); + if (visible) { // show // Designer uses a trick to make grabWidget work without showing - if (!isWindow() && parentWidget() && parentWidget()->isVisible() - && !parentWidget()->testAttribute(Qt::WA_WState_Created)) - parentWidget()->window()->d_func()->createRecursively(); + if (!q->isWindow() && q->parentWidget() && q->parentWidget()->isVisible() + && !q->parentWidget()->testAttribute(Qt::WA_WState_Created)) + q->parentWidget()->window()->d_func()->createRecursively(); //create toplevels but not children of non-visible parents - QWidget *pw = parentWidget(); - if (!testAttribute(Qt::WA_WState_Created) - && (isWindow() || pw->testAttribute(Qt::WA_WState_Created))) { - create(); + QWidget *pw = q->parentWidget(); + if (!q->testAttribute(Qt::WA_WState_Created) + && (q->isWindow() || pw->testAttribute(Qt::WA_WState_Created))) { + q->create(); } - bool wasResized = testAttribute(Qt::WA_Resized); - Qt::WindowStates initialWindowState = windowState(); + bool wasResized = q->testAttribute(Qt::WA_Resized); + Qt::WindowStates initialWindowState = q->windowState(); // polish if necessary - ensurePolished(); + q->ensurePolished(); - // remember that show was called explicitly - setAttribute(Qt::WA_WState_ExplicitShowHide); // whether we need to inform the parent widget immediately - bool needUpdateGeometry = !isWindow() && testAttribute(Qt::WA_WState_Hidden); + bool needUpdateGeometry = !q->isWindow() && q->testAttribute(Qt::WA_WState_Hidden); // we are no longer hidden - setAttribute(Qt::WA_WState_Hidden, false); + q->setAttribute(Qt::WA_WState_Hidden, false); if (needUpdateGeometry) - d->updateGeometry_helper(true); + updateGeometry_helper(true); // activate our layout before we and our children become visible - if (d->layout) - d->layout->activate(); + if (layout) + layout->activate(); - if (!isWindow()) { - QWidget *parent = parentWidget(); + if (!q->isWindow()) { + QWidget *parent = q->parentWidget(); while (parent && parent->isVisible() && parent->d_func()->layout && !parent->data->in_show) { parent->d_func()->layout->activate(); if (parent->isWindow()) @@ -8343,30 +8350,28 @@ void QWidget::setVisible(bool visible) // adjust size if necessary if (!wasResized - && (isWindow() || !parentWidget()->d_func()->layout)) { - if (isWindow()) { - adjustSize(); - if (windowState() != initialWindowState) - setWindowState(initialWindowState); + && (q->isWindow() || !q->parentWidget()->d_func()->layout)) { + if (q->isWindow()) { + q->adjustSize(); + if (q->windowState() != initialWindowState) + q->setWindowState(initialWindowState); } else { - adjustSize(); + q->adjustSize(); } - setAttribute(Qt::WA_Resized, false); + q->setAttribute(Qt::WA_Resized, false); } - setAttribute(Qt::WA_KeyboardFocusChange, false); + q->setAttribute(Qt::WA_KeyboardFocusChange, false); - if (isWindow() || parentWidget()->isVisible()) { - d->show_helper(); + if (q->isWindow() || q->parentWidget()->isVisible()) { + show_helper(); - qApp->d_func()->sendSyntheticEnterLeave(this); + qApp->d_func()->sendSyntheticEnterLeave(q); } QEvent showToParentEvent(QEvent::ShowToParent); - QApplication::sendEvent(this, &showToParentEvent); + QApplication::sendEvent(q, &showToParentEvent); } else { // hide - if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) - return; #if 0 // Used to be included in Qt4 for Q_WS_WIN // reset WS_DISABLED style in a Blocked window if(isWindow() && testAttribute(Qt::WA_WState_Created) @@ -8377,33 +8382,30 @@ void QWidget::setVisible(bool visible) SetWindowLong(winId(), GWL_STYLE, dwStyle); } #endif - if (QApplicationPrivate::hidden_focus_widget == this) + if (QApplicationPrivate::hidden_focus_widget == q) QApplicationPrivate::hidden_focus_widget = 0; - Q_D(QWidget); - // hw: The test on getOpaqueRegion() needs to be more intelligent // currently it doesn't work if the widget is hidden (the region will // be clipped). The real check should be testing the cached region // (and dirty flag) directly. - if (!isWindow() && parentWidget()) // && !d->getOpaqueRegion().isEmpty()) - parentWidget()->d_func()->setDirtyOpaqueRegion(); + if (!q->isWindow() && q->parentWidget()) // && !d->getOpaqueRegion().isEmpty()) + q->parentWidget()->d_func()->setDirtyOpaqueRegion(); - setAttribute(Qt::WA_WState_Hidden); - setAttribute(Qt::WA_WState_ExplicitShowHide); - if (testAttribute(Qt::WA_WState_Created)) - d->hide_helper(); + q->setAttribute(Qt::WA_WState_Hidden); + if (q->testAttribute(Qt::WA_WState_Created)) + hide_helper(); // invalidate layout similar to updateGeometry() - if (!isWindow() && parentWidget()) { - if (parentWidget()->d_func()->layout) - parentWidget()->d_func()->layout->invalidate(); - else if (parentWidget()->isVisible()) - QApplication::postEvent(parentWidget(), new QEvent(QEvent::LayoutRequest)); + if (!q->isWindow() && q->parentWidget()) { + if (q->parentWidget()->d_func()->layout) + q->parentWidget()->d_func()->layout->invalidate(); + else if (q->parentWidget()->isVisible()) + QApplication::postEvent(q->parentWidget(), new QEvent(QEvent::LayoutRequest)); } QEvent hideToParentEvent(QEvent::HideToParent); - QApplication::sendEvent(this, &hideToParentEvent); + QApplication::sendEvent(q, &hideToParentEvent); } } @@ -11891,7 +11893,7 @@ void QWidget::raise() QRegion region(rect()); d->subtractOpaqueSiblings(region); - d->invalidateBuffer(region); + d->invalidateBackingStore(region); } if (testAttribute(Qt::WA_WState_Created)) d->raise_sys(); @@ -11911,7 +11913,7 @@ void QWidgetPrivate::raise_sys() } else if (renderToTexture) { if (QWidget *p = q->parentWidget()) { setDirtyOpaqueRegion(); - p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); + p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry())); } } } @@ -11961,7 +11963,7 @@ void QWidgetPrivate::lower_sys() q->windowHandle()->lower(); } else if (QWidget *p = q->parentWidget()) { setDirtyOpaqueRegion(); - p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); + p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry())); } } @@ -12005,7 +12007,7 @@ void QWidgetPrivate::stackUnder_sys(QWidget*) Q_Q(QWidget); if (QWidget *p = q->parentWidget()) { setDirtyOpaqueRegion(); - p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); + p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry())); } } @@ -12447,7 +12449,7 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows) d->aboutToDestroy(); if (!isWindow() && parentWidget()) - parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry())); + parentWidget()->d_func()->invalidateBackingStore(d->effectiveRectFor(geometry())); d->deactivateWidgetCleanup(); if ((windowType() == Qt::Popup) && qApp) |