📄 qbackingstore.cpp
字号:
QDecoration::Normal);#endif toClean = QRegion(0, 0, tlw->width(), tlw->height()); } else { toClean = dirty; } tlwOffset = buffer.tlwOffset();#else // not QWS QSize tlwSize = tlw->size(); if (buffer.size() != tlwSize) {#if defined(Q_WS_X11) extern int qt_x11_preferred_pixmap_depth; int old_qt_x11_preferred_pixmap_depth = qt_x11_preferred_pixmap_depth; qt_x11_preferred_pixmap_depth = widget->x11Info().depth(); QPixmap::x11SetDefaultScreen(widget->x11Info().screen()); buffer = QPixmap(tlwSize); qt_x11_preferred_pixmap_depth = old_qt_x11_preferred_pixmap_depth;#elif defined(Q_WS_WIN) releaseBuffer();#endif // Q_WS_X11 toClean = QRegion(0, 0, tlw->width(), tlw->height()); } else { toClean = dirty; }#endif //Q_WS_QWS#ifdef Q_WS_QWS buffer.lock();#endif if(!toClean.isEmpty()) { dirty -= toClean; if (tlw->updatesEnabled()) {#ifdef Q_WS_QWS tlw->d_func()->drawWidget(buffer.paintDevice(), toClean, tlwOffset);#else tlw->d_func()->drawWidget(&buffer, toClean, tlwOffset);#endif } } QRegion toFlush = rgn;#ifdef Q_WS_QWS#ifndef QT_NO_QWS_MANAGER if (topextra->qwsManager) toFlush += topextra->qwsManager->d_func()->paint(buffer.paintDevice());#endif buffer.unlock();#endif // Q_WS_QWS if (recursiveCopyToScreen) { toFlush.translate(widget->mapTo(tlw, QPoint())); copyToScreen(toFlush, tlw, tlwOffset, recursiveCopyToScreen); } else {#ifdef Q_WS_X11 toFlush += widget->d_func()->dirtyOnScreen;#endif copyToScreen(toFlush, widget, widget->mapTo(tlw, QPoint()), false); } }}#ifdef Q_WS_QWSvoid QWidgetBackingStore::releaseBuffer(){ buffer.detach(); QWidget::qwsDisplay()->requestRegion(tlw->data->winid, 0, buffer.windowType(), QRegion(0), QImage::Format_Invalid);}#elif defined(Q_WS_WIN)void QWidgetBackingStore::releaseBuffer(){ if (buffer.paintEngine()) ((QRasterPaintEngine *)buffer.paintEngine())->releaseBuffer();}#endifbool QWidgetBackingStore::isOpaque(const QWidget *widget){ return widget->d_func()->isOpaque();}void QWidgetBackingStore::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn, const QPoint &offset, int flags){ QWidget *w = 0; do { QWidget *x = qobject_cast<QWidget*>(siblings.at(index)); if (x && !x->isWindow() && !x->isHidden() && qRectIntersects(rgn.boundingRect(), x->geometry())) { w = x; break; } --index; } while (index >= 0); if (!w) return; QWExtra *extra = w->d_func()->extraData(); if (index > 0) { QRegion wr = rgn; if (isOpaque(w)) { if(!extra || extra->mask.isEmpty()) { wr -= w->geometry(); } else { wr -= extra->mask.translated(w->pos()); } } paintSiblingsRecursive(pdev, siblings, index - 1, wr, offset, flags); } if(w->updatesEnabled()) { QRegion wRegion(rgn & w->geometry()); wRegion.translate(-w->pos()); if(extra && !extra->mask.isEmpty()) wRegion &= extra->mask; if(!wRegion.isEmpty()) w->d_func()->drawWidget(pdev, wRegion, offset+w->pos(), flags); }}void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags){ Q_Q(QWidget); if (rgn.isEmpty()) return; const bool asRoot = flags & DrawAsRoot; const bool alsoOnScreen = flags & DrawPaintOnScreen; const bool recursive = flags & DrawRecursive; const bool alsoInvisible = flags & DrawInvisible; QRegion toBePainted = rgn; if (asRoot && !alsoInvisible) toBePainted &= clipRect(); //(rgn & visibleRegion()); subtractOpaqueChildren(toBePainted, q->rect(), QPoint()); if (!toBePainted.isEmpty()) { bool onScreen = QWidgetBackingStore::paintOnScreen(q); if (!onScreen || alsoOnScreen) { //update the "in paint event" flag if (q->testAttribute(Qt::WA_WState_InPaintEvent)) qWarning("QWidget::repaint: recursive repaint detected."); q->setAttribute(Qt::WA_WState_InPaintEvent); //clip away the new area bool flushed = qt_flushPaint(q, toBePainted); QPainter::setRedirected(q, pdev, -offset); QRegion wrgn = toBePainted; wrgn.translate(offset); QPaintEngine *paintEngine = pdev->paintEngine(); if (paintEngine) { paintEngine->setSystemRect(q->data->crect); paintEngine->setSystemClip(wrgn); //paint the background if ((asRoot || q->autoFillBackground() || onScreen) && !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) { QPainter p(q); paintBackground(&p, toBePainted.boundingRect(), asRoot || onScreen); } if (q->testAttribute(Qt::WA_TintedBackground) && !onScreen && !asRoot && !isOpaque() ) { QPainter p(q); QColor tint = q->palette().window().color(); tint.setAlphaF(.6); p.fillRect(toBePainted.boundingRect(), tint); } }#if 0 qDebug() << "painting" << q << "opaque ==" << isOpaque(); qDebug() << "clipping to" << toBePainted << "location == " << offset << "geometry ==" << QRect(q->mapTo(q->window(), QPoint(0, 0)), q->size());#endif //actually send the paint event QPaintEvent e(toBePainted); qt_sendSpontaneousEvent(q, &e); //restore if (paintEngine) { paintEngine->setSystemRect(QRect()); pdev->paintEngine()->setSystemClip(QRegion()); QPainter::restoreRedirected(q); } q->setAttribute(Qt::WA_WState_InPaintEvent, false); if(!q->testAttribute(Qt::WA_PaintOutsidePaintEvent) && q->paintingActive()) qWarning("It is dangerous to leave painters active on a widget outside of the PaintEvent"); if (flushed) qt_unflushPaint(q, toBePainted); } else if(q->isWindow()) { if (pdev->paintEngine()) { QPainter p(pdev); p.setClipRegion(toBePainted); const QBrush bg = q->palette().brush(QPalette::Window); if (bg.style() == Qt::TexturePattern) p.drawTiledPixmap(q->rect(), bg.texture()); else p.fillRect(q->rect(), bg); } } } if (recursive) { const QObjectList children = q->children(); if (!children.isEmpty()) QWidgetBackingStore::paintSiblingsRecursive(pdev, children, children.size()-1, rgn, offset, flags & ~DrawAsRoot); }}/* cross-platform QWidget code */void QWidgetPrivate::invalidateBuffer(const QRegion &rgn){ if(qApp && qApp->closingDown()) return; Q_Q(QWidget); QWidget *tlw = q->window(); QTLWExtra *x = tlw->d_func()->topData(); if (x->backingStore) x->backingStore->dirtyRegion(rgn, q);}void QWidget::repaint(const QRegion& rgn){ if (testAttribute(Qt::WA_WState_ConfigPending)) { update(rgn); return; } if (!isVisible() || !updatesEnabled() || rgn.isEmpty()) return; Q_D(QWidget);// qDebug() << "repaint" << this << rgn; if (!QWidgetBackingStore::paintOnScreen(this)) { QWidget *tlw = window(); QTLWExtra* x = tlw->d_func()->topData(); QRegion wrgn(rgn); d->subtractOpaqueChildren(wrgn, rect(), QPoint()); x->backingStore->dirtyRegion(wrgn, this); x->backingStore->cleanRegion(wrgn, this); }#ifndef Q_WS_QWS// QWS doesn't support paint-on-screen else { d->cleanWidget_sys(rgn); // qDebug() << "QWidget::repaint paintOnScreen" << this << "region" << rgn; qt_flushPaint(this, rgn); QPaintEngine *engine = paintEngine(); QRegion systemClipRgn(rgn); if (engine) { if (!data->wrect.topLeft().isNull()) { QPainter::setRedirected(this, this, data->wrect.topLeft()); systemClipRgn.translate(-data->wrect.topLeft()); } engine->setSystemClip(systemClipRgn); engine->setSystemRect(data->crect); } d->drawWidget(this, rgn, QPoint(), QWidgetPrivate::DrawAsRoot | QWidgetPrivate::DrawPaintOnScreen);#ifdef Q_WS_WIN if (engine && engine->type() == QPaintEngine::Raster) { bool tmp_dc = !d->hd; if (tmp_dc) d->hd = GetDC(winId()); static_cast<QRasterPaintEngine *>(engine)->flush(this, QPoint(0, 0)); if (tmp_dc) { ReleaseDC(winId(), (HDC)d->hd); d->hd = 0; } }#endif if (engine) { if (!data->wrect.topLeft().isNull()) QPainter::restoreRedirected(this); engine->setSystemClip(QRegion()); engine->setSystemRect(QRect()); } if(!testAttribute(Qt::WA_PaintOutsidePaintEvent) && paintingActive()) qWarning("It is dangerous to leave painters active on a widget outside of the PaintEvent"); }#endif //Q_WS_QWS}void QWidget::update(){ update(rect());}void QWidget::update(const QRect &r){ update(QRegion(r));}void QWidget::update(const QRegion& rgn){ if(!isVisible() || !updatesEnabled() || rgn.isEmpty()) return; if (testAttribute(Qt::WA_WState_InPaintEvent)) { QApplication::postEvent(this, new QUpdateLaterEvent(rgn)); } else { QWidget *tlw = window(); QTLWExtra* x = tlw->d_func()->topData(); QRegion wrgn(rgn); d_func()->subtractOpaqueChildren(wrgn, rect(), QPoint()); x->backingStore->dirtyRegion(wrgn, this); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -