void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) { Q_Q(QWidget); bool wasCreated = q->testAttribute(Qt::WA_WState_Created); if (q->isVisible() && q->parentWidget() && parent != q->parentWidget()) q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); #ifndef QT_NO_CURSOR QCursor oldcurs; bool setcurs=q->testAttribute(Qt::WA_SetCursor); if (setcurs) { oldcurs = q->cursor(); q->unsetCursor(); } #endif WId old_winid = data.winid; if ((q->windowType() == Qt::Desktop)) old_winid = 0; if (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_WState_Created)) hide_sys(); setWinId(0); if (parent != newparent) { QWidget *oldparent = q->parentWidget(); QObjectPrivate::setParent_helper(newparent); if (oldparent) { // oldparent->d_func()->setChildrenAllocatedDirty(); // oldparent->data->paintable_region_dirty = true; } if (newparent) { // newparent->d_func()->setChildrenAllocatedDirty(); // newparent->data->paintable_region_dirty = true; //@@@@@@@ } } Qt::FocusPolicy fp = q->focusPolicy(); QSize s = q->size(); //QBrush bgc = background(); // save colors bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide); data.window_flags = f; q->setAttribute(Qt::WA_WState_Created, false); q->setAttribute(Qt::WA_WState_Visible, false); q->setAttribute(Qt::WA_WState_Hidden, false); adjustFlags(data.window_flags, q); // keep compatibility with previous versions, we need to preserve the created state // (but we recreate the winId for the widget being reparented, again for compatibility) if (wasCreated || (!q->isWindow() && newparent->testAttribute(Qt::WA_WState_Created))) createWinId(); if (q->isWindow() || (!newparent || newparent->isVisible()) || explicitlyHidden) q->setAttribute(Qt::WA_WState_Hidden); q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden); if (q->isWindow()) { QRect fs = frameStrut(); data.crect = QRect(fs.left(), fs.top(), s.width(), s.height()); if ((data.window_flags & Qt::FramelessWindowHint) && extra && extra->topextra) extra->topextra->frameStrut.setCoords(0, 0, 0, 0); } else { data.crect = QRect(0, 0, s.width(), s.height()); } q->setFocusPolicy(fp); if (extra && !extra->mask.isEmpty()) { QRegion r = extra->mask; extra->mask = QRegion(); q->setMask(r); } if ((int)old_winid > 0) { QWidget::qwsDisplay()->destroyRegion(old_winid); extra->topextra->backingStore->windowSurface->setGeometry(QRect()); } #ifndef QT_NO_CURSOR if (setcurs) { q->setCursor(oldcurs); } #endif }
void QWidgetPrivate::stackUnder_sys(QWidget*) { Q_Q(QWidget); if (QWidget *p = q->parentWidget()) { setDirtyOpaqueRegion(); p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); } }
void QWidgetPrivate::lower_sys() { Q_Q(QWidget); if (q->isWindow() || q->testAttribute(Qt::WA_NativeWindow)) { Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); q->windowHandle()->lower(); } else if (QWidget *p = q->parentWidget()) { setDirtyOpaqueRegion(); p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); } }
void QWidgetPrivate::lower_sys() { Q_Q(QWidget); if (q->isWindow()) { Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); QWidget::qwsDisplay()->setAltitude(data.winid, QWSChangeAltitudeCommand::Lower); } else if (QWidget *p = q->parentWidget()) { setDirtyOpaqueRegion(); p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); } }
//parent's coordinates; move whole rect; update parent and widget //assume the screen blt has already been done, so we don't need to refresh that part void QWidgetPrivate::moveRect(const QRect &rect, int dx, int dy) { Q_Q(QWidget); if (!q->isVisible() || (dx == 0 && dy == 0)) return; QWidget *tlw = q->window(); QTLWExtra* x = tlw->d_func()->topData(); if (x->inTopLevelResize) return; static int accelEnv = -1; if (accelEnv == -1) { accelEnv = qgetenv("QT_NO_FAST_MOVE").toInt() == 0; } QWidget *pw = q->parentWidget(); QPoint toplevelOffset = pw->mapTo(tlw, QPoint()); QWidgetPrivate *pd = pw->d_func(); QRect clipR(pd->clipRect()); const QRect newRect(rect.translated(dx, dy)); QRect destRect = rect.intersected(clipR); if (destRect.isValid()) destRect = destRect.translated(dx, dy).intersected(clipR); const QRect sourceRect(destRect.translated(-dx, -dy)); const QRect parentRect(rect & clipR); bool accelerateMove = accelEnv && isOpaque #ifndef QT_NO_GRAPHICSVIEW // No accelerate move for proxy widgets. && !tlw->d_func()->extra->proxyWidget #endif && !isOverlapped(sourceRect) && !isOverlapped(destRect); if (!accelerateMove) { QRegion parentR(effectiveRectFor(parentRect)); if (!extra || !extra->hasMask) { parentR -= newRect; } else { // invalidateBuffer() excludes anything outside the mask parentR += newRect & clipR; } pd->invalidateBuffer(parentR); invalidateBuffer((newRect & clipR).translated(-data.crect.topLeft())); } else { QWidgetBackingStore *wbs = x->backingStore.data(); QRegion childExpose(newRect & clipR); if (sourceRect.isValid() && wbs->bltRect(sourceRect, dx, dy, pw)) childExpose -= destRect; if (!pw->updatesEnabled()) return; const bool childUpdatesEnabled = q->updatesEnabled(); if (childUpdatesEnabled && !childExpose.isEmpty()) { childExpose.translate(-data.crect.topLeft()); wbs->markDirty(childExpose, q); isMoved = true; } QRegion parentExpose(parentRect); parentExpose -= newRect; if (extra && extra->hasMask) parentExpose += QRegion(newRect) - extra->mask.translated(data.crect.topLeft()); if (!parentExpose.isEmpty()) { wbs->markDirty(parentExpose, pw); pd->isMoved = true; } if (childUpdatesEnabled) { QRegion needsFlush(sourceRect); needsFlush += destRect; wbs->markDirtyOnScreen(needsFlush, pw, toplevelOffset); } } }
/*! Invalidates the buffer when the widget is resized. Static areas are never invalidated unless absolutely needed. */ void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize) { Q_Q(QWidget); Q_ASSERT(!q->isWindow()); Q_ASSERT(q->parentWidget()); const bool staticContents = q->testAttribute(Qt::WA_StaticContents); const bool sizeDecreased = (data.crect.width() < oldSize.width()) || (data.crect.height() < oldSize.height()); const QPoint offset(data.crect.x() - oldPos.x(), data.crect.y() - oldPos.y()); const bool parentAreaExposed = !offset.isNull() || sizeDecreased; const QRect newWidgetRect(q->rect()); const QRect oldWidgetRect(0, 0, oldSize.width(), oldSize.height()); if (!staticContents || graphicsEffect) { QRegion staticChildren; QWidgetBackingStore *bs = 0; if (offset.isNull() && (bs = maybeBackingStore())) staticChildren = bs->staticContents(q, oldWidgetRect); const bool hasStaticChildren = !staticChildren.isEmpty(); if (hasStaticChildren) { QRegion dirty(newWidgetRect); dirty -= staticChildren; invalidateBuffer(dirty); } else { // Entire widget needs repaint. invalidateBuffer(newWidgetRect); } if (!parentAreaExposed) return; // Invalidate newly exposed area of the parent. if (!graphicsEffect && extra && extra->hasMask) { QRegion parentExpose(extra->mask.translated(oldPos)); parentExpose &= QRect(oldPos, oldSize); if (hasStaticChildren) parentExpose -= data.crect; // Offset is unchanged, safe to do this. q->parentWidget()->d_func()->invalidateBuffer(parentExpose); } else { if (hasStaticChildren && !graphicsEffect) { QRegion parentExpose(QRect(oldPos, oldSize)); parentExpose -= data.crect; // Offset is unchanged, safe to do this. q->parentWidget()->d_func()->invalidateBuffer(parentExpose); } else { q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(QRect(oldPos, oldSize))); } } return; } // Move static content to its new position. if (!offset.isNull()) { if (sizeDecreased) { const QSize minSize(qMin(oldSize.width(), data.crect.width()), qMin(oldSize.height(), data.crect.height())); moveRect(QRect(oldPos, minSize), offset.x(), offset.y()); } else { moveRect(QRect(oldPos, oldSize), offset.x(), offset.y()); } } // Invalidate newly visible area of the widget. if (!sizeDecreased || !oldWidgetRect.contains(newWidgetRect)) { QRegion newVisible(newWidgetRect); newVisible -= oldWidgetRect; invalidateBuffer(newVisible); } if (!parentAreaExposed) return; // Invalidate newly exposed area of the parent. const QRect oldRect(oldPos, oldSize); if (extra && extra->hasMask) { QRegion parentExpose(oldRect); parentExpose &= extra->mask.translated(oldPos); parentExpose -= (extra->mask.translated(data.crect.topLeft()) & data.crect); q->parentWidget()->d_func()->invalidateBuffer(parentExpose); } else { QRegion parentExpose(oldRect); parentExpose -= data.crect; q->parentWidget()->d_func()->invalidateBuffer(parentExpose); } }