static void ungrabMouseForPopup(QWidget *popup) { if (QWidget::mouseGrabber()) qt_widget_private(QWidget::mouseGrabber())->stealMouseGrab(true); else qt_widget_private(popup)->stealMouseGrab(false); }
static void ungrabKeyboardForPopup(QWidget *popup) { if (QWidget::keyboardGrabber()) qt_widget_private(QWidget::keyboardGrabber())->stealKeyboardGrab(true); else qt_widget_private(popup)->stealKeyboardGrab(false); }
void QGLWidgetPrivate::init(QGLContext *context, const QGLWidget* shareWidget) { Q_Q(QGLWidget); initContext(context, shareWidget); olcx = 0; QWidget *current = q; while (current) { qt_widget_private(current)->glWidgets.append(QWidgetPrivate::GlWidgetInfo(q)); if (current->isWindow()) break; current = current->parentWidget(); }; qt_widget_private(q)->isGLWidget = 1; #if 0 // overlays are not supported by the GL drivers on the Mac.. // ### remove all overlay code for Qt 5.0 if(q->isValid() && glcx->format().hasOverlay()) { olcx = new QGLContext(QGLFormat::defaultOverlayFormat(), q); if(!olcx->create(shareWidget ? shareWidget->overlayContext() : 0)) { delete olcx; olcx = 0; glcx->d_func()->glFormat.setOverlay(false); } } #endif //updatePaintDevice(); }
static void grabForPopup(QWidget *popup) { Q_ASSERT(popup->testAttribute(Qt::WA_WState_Created)); popupGrabOk = qt_widget_private(popup)->stealKeyboardGrab(true); if (popupGrabOk) { popupGrabOk = qt_widget_private(popup)->stealMouseGrab(true); if (!popupGrabOk) { // transfer grab back to the keyboard grabber if any ungrabKeyboardForPopup(popup); } } }
void QSymbianGraphicsSystemEx::forceToRaster(QWidget *window) { if (window && window->isWindow()) { qt_widget_private(window)->createTLExtra(); if (QTLWExtra *topExtra = qt_widget_private(window)->maybeTopData()) { topExtra->forcedToRaster = 1; if (topExtra->backingStore.data()) { topExtra->backingStore.create(window); topExtra->backingStore.registerWidget(window); } } } }
QWindowSurface *QGLGraphicsSystem::createWindowSurface(QWidget *widget) const { #ifdef Q_WS_WIN // On Windows the QGLWindowSurface class can't handle // drop shadows and native effects, e.g. fading a menu in/out using // top level window opacity. if (widget->windowType() == Qt::Popup) return new QRasterWindowSurface(widget); #endif #if defined(Q_WS_X11) && !defined(QT_NO_EGL) if (m_useX11GL && QX11GLPixmapData::hasX11GLPixmaps()) { // If the widget is a QGraphicsView which will be re-drawing the entire // scene each frame anyway, we should use QGLWindowSurface as this may // provide proper buffer flipping, which should be faster than QX11GL's // blitting approach: QGraphicsView* qgv = qobject_cast<QGraphicsView*>(widget); if (qgv && qgv->viewportUpdateMode() == QGraphicsView::FullViewportUpdate) return new QGLWindowSurface(widget); else return new QX11GLWindowSurface(widget); } #endif #if defined(Q_OS_SYMBIAN) if (!QApplicationPrivate::instance()->useTranslucentEGLSurfaces) { QWidgetPrivate *d = qt_widget_private(widget); if (!d->isOpaque && widget->testAttribute(Qt::WA_TranslucentBackground)) return d->createDefaultWindowSurface_sys(); } #endif return new QGLWindowSurface(widget); }
void QRasterWindowSurface::beginPaint(const QRegion &rgn) { #if defined(Q_WS_X11) && !defined(QT_NO_MITSHM) syncX(); #endif #if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || defined(Q_WS_WIN) if (!qt_widget_private(window())->isOpaque && window()->testAttribute(Qt::WA_TranslucentBackground)) { #if defined(Q_WS_WIN) if (d_ptr->image->image.format() != QImage::Format_ARGB32_Premultiplied) prepareBuffer(QImage::Format_ARGB32_Premultiplied, window()); #endif QPainter p(&d_ptr->image->image); p.setCompositionMode(QPainter::CompositionMode_Source); const QVector<QRect> rects = rgn.rects(); const QColor blank = Qt::transparent; for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) { p.fillRect(*it, blank); } } #else Q_UNUSED(rgn); #endif }
void QS60WindowSurface::beginPaint(const QRegion &rgn) { #ifdef Q_SYMBIAN_SUPPORTS_SURFACES S60->wsSession().Finish(); #endif QWidgetPrivate *windowPrivate = qt_widget_private(window()); if (!windowPrivate->isOpaque || blitWriteAlpha(windowPrivate)) { QSymbianRasterPixmapData *pixmapData = static_cast<QSymbianRasterPixmapData *>(d_ptr->device.data_ptr().data()); TDisplayMode mode = displayMode(false); if (pixmapData->cfbsBitmap->DisplayMode() != mode) pixmapData->convertToDisplayMode(mode); pixmapData->beginDataAccess(); if (!windowPrivate->isOpaque) { QPainter p(&pixmapData->image); p.setCompositionMode(QPainter::CompositionMode_Source); const QVector<QRect> rects = rgn.rects(); const QColor blank = Qt::transparent; for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) { p.fillRect(*it, blank); } } pixmapData->endDataAccess(); } }
QList<QByteArray> QAnnotatorWidget::annotation(const QObject& object) { QList<QByteArray> result; const QWidget* widget = qobject_cast<const QWidget*>(&object); if (widget) { const QWExtra* extra = qt_widget_private(const_cast<QWidget *>(widget))->extraData(); if (extra) { QByteArray array; QTextStream stream(&array); stream << "widget (Symbian): "; stream << "activated " << extra->activated << ' '; stream << "nativePaintMode " << extra->nativePaintMode << ' '; stream.flush(); result.append(array); } } return result; }
void QS60WindowSurface::beginPaint(const QRegion &rgn) { if (!qt_widget_private(window())->isOpaque) { QS60PixmapData *pixmapData = static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data()); pixmapData->beginDataAccess(); QImage &image = pixmapData->image; QRgb *data = reinterpret_cast<QRgb *>(image.bits()); const int row_stride = image.bytesPerLine() / 4; const QVector<QRect> rects = rgn.rects(); for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) { const int x_start = it->x(); const int width = it->width(); const int y_start = it->y(); const int height = it->height(); QRgb *row = data + row_stride * y_start; for (int y = 0; y < height; ++y) { qt_memfill(row + x_start, 0U, width); row += row_stride; } } pixmapData->endDataAccess(); } }
void QSymbianGraphicsSystemEx::releaseAllGpuResources() { releaseCachedGpuResources(); foreach (QWidget *widget, QApplication::topLevelWidgets()) { if (QTLWExtra *topExtra = qt_widget_private(widget)->maybeTopData()) topExtra->backingStore.destroy(); } }
QPlatformScreen * QPlatformScreen::platformScreenForWidget(const QWidget *widget) { QWidget *window = widget->window(); QWidgetPrivate *windowPrivate = qt_widget_private(window); QTLWExtra * topData = windowPrivate->topData(); QPlatformIntegration *integration = QApplicationPrivate::platformIntegration(); return integration->screens()[topData->screenIndex]; }
QWindowSurface *QVGGraphicsSystem::createWindowSurface(QWidget *widget) const { #if defined(Q_OS_SYMBIAN) if (!QApplicationPrivate::instance()->useTranslucentEGLSurfaces) { QWidgetPrivate *d = qt_widget_private(widget); if (!d->isOpaque && widget->testAttribute(Qt::WA_TranslucentBackground)) return d->createDefaultWindowSurface_sys(); } #endif return new QVGWindowSurface(widget); }
/*! \overload Handles the given mouse \a event. */ void QDeclarativeTextEdit::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextEdit); QWidget *widget = event->widget(); if (widget && (d->control->textInteractionFlags() & Qt::TextEditable) && boundingRect().contains(event->pos())) qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), d->focusOnPress); d->control->processEvent(event, QPointF(0, 0)); if (!event->isAccepted()) QDeclarativePaintedItem::mousePressEvent(event); }
void QVGWindowSurface::beginPaint(const QRegion ®ion) { d_ptr->beginPaint(window()); // If the window is not opaque, then fill the region we are about // to paint with the transparent color. if (!qt_widget_private(window())->isOpaque && window()->testAttribute(Qt::WA_TranslucentBackground)) { QVGPaintEngine *engine = static_cast<QVGPaintEngine *> (d_ptr->paintEngine()); engine->fillRegion(region, Qt::transparent, d_ptr->surfaceSize()); } }
void QDirectFBWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) { QWidget *win = window(); if (!win) return; #if !defined(QT_NO_QWS_PROXYSCREEN) && !defined(QT_NO_GRAPHICSVIEW) QWExtra *extra = qt_widget_private(widget)->extraData(); if (extra && extra->proxyWidget) return; #else Q_UNUSED(widget); #endif const quint8 windowOpacity = quint8(win->windowOpacity() * 0xff); const QRect windowGeometry = geometry(); #ifdef QT_DIRECTFB_WM quint8 currentOpacity; Q_ASSERT(dfbWindow); dfbWindow->GetOpacity(dfbWindow, ¤tOpacity); if (currentOpacity != windowOpacity) { dfbWindow->SetOpacity(dfbWindow, windowOpacity); } screen->flipSurface(dfbSurface, flipFlags, region, offset); #else setOpaque(windowOpacity == 0xff); if (mode == Offscreen) { screen->exposeRegion(region.translated(offset + geometry().topLeft()), 0); } else { screen->flipSurface(dfbSurface, flipFlags, region, offset); } #endif #ifdef QT_DIRECTFB_TIMING enum { Secs = 3 }; ++frames; if (timer.elapsed() >= Secs * 1000) { qDebug("%d fps", int(double(frames) / double(Secs))); frames = 0; timer.restart(); } #endif flushPending = false; }
QS60WindowSurface::QS60WindowSurface(QWidget* widget) : QWindowSurface(widget), d_ptr(new QS60WindowSurfacePrivate) { QWidgetPrivate *widgetPrivate = qt_widget_private(widget); const bool opaque = widgetPrivate->isOpaque && !blitWriteAlpha(widgetPrivate); TDisplayMode mode = displayMode(opaque); // We create empty CFbsBitmap here -> it will be resized in setGeometry CFbsBitmap *bitmap = new CFbsBitmap; // CBase derived object needs check on new Q_CHECK_PTR(bitmap); qt_symbian_throwIfError( bitmap->Create( TSize(0, 0), mode ) ); QSymbianRasterPixmapData *data = new QSymbianRasterPixmapData(QPixmapData::PixmapType); if (data) { data->fromSymbianBitmap(bitmap, true); d_ptr->device = QPixmap(data); } }
QRasterWindowSurface::QRasterWindowSurface(QWidget *window) : QWindowSurface(window), d_ptr(new QRasterWindowSurfacePrivate) { #ifdef Q_WS_X11 d_ptr->gc = XCreateGC(X11->display, window->handle(), 0, 0); #ifndef QT_NO_XRENDER d_ptr->translucentBackground = X11->use_xrender && window->x11Info().depth() == 32; #endif #endif #if defined(Q_WS_WIN) && !defined(Q_OS_WINCE) d_ptr->canUseLayeredWindow = ptrUpdateLayeredWindowIndirect && (qt_widget_private(window)->data.window_flags & Qt::FramelessWindowHint); #endif d_ptr->image = 0; d_ptr->inSetGeometry = false; setStaticContentsSupport(true); }
void QRasterWindowSurface::setGeometry(const QRect &rect) { QWindowSurface::setGeometry(rect); Q_D(QRasterWindowSurface); d->inSetGeometry = true; if (d->image == 0 || d->image->width() < rect.width() || d->image->height() < rect.height()) { #if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN) && !defined(Q_WS_WINCE)) #ifndef Q_WS_WIN if (d_ptr->translucentBackground) #else if (!qt_widget_private(window())->isOpaque) #endif prepareBuffer(QImage::Format_ARGB32_Premultiplied, window()); else #endif prepareBuffer(QNativeImage::systemFormat(), window()); } d->inSetGeometry = false; }
QS60WindowSurface::QS60WindowSurface(QWidget* widget) : QWindowSurface(widget), d_ptr(new QS60WindowSurfacePrivate) { TDisplayMode mode = S60->screenDevice()->DisplayMode(); bool isOpaque = qt_widget_private(widget)->isOpaque; if (mode == EColor16MA && isOpaque) mode = EColor16MU; // Faster since 16MU -> 16MA is typically accelerated else if (mode == EColor16MU && !isOpaque) mode = EColor16MA; // Try for transparency anyway // We create empty CFbsBitmap here -> it will be resized in setGeometry CFbsBitmap *bitmap = q_check_ptr(new CFbsBitmap); // CBase derived object needs check on new qt_symbian_throwIfError( bitmap->Create( TSize(0, 0), mode ) ); QS60PixmapData *data = new QS60PixmapData(QPixmapData::PixmapType); data->fromSymbianBitmap(bitmap); d_ptr->device = QPixmap(data); setStaticContentsSupport(true); }
void QRasterWindowSurface::beginPaint(const QRegion &rgn) { #if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN) && !defined(Q_OS_WINCE)) if (!qt_widget_private(window())->isOpaque) { #if defined(Q_WS_WIN) && !defined(Q_OS_WINCE) if (d_ptr->image->image.format() != QImage::Format_ARGB32_Premultiplied && d_ptr->canUseLayeredWindow) prepareBuffer(QImage::Format_ARGB32_Premultiplied, window()); #endif QPainter p(&d_ptr->image->image); p.setCompositionMode(QPainter::CompositionMode_Source); const QVector<QRect> rects = rgn.rects(); const QColor blank = Qt::transparent; for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) { p.fillRect(*it, blank); } } #endif #if defined(Q_OS_WINCE) Q_UNUSED(rgn); #endif }
void QRasterWindowSurface::setGeometry(const QRect &rect) { QWindowSurface::setGeometry(rect); Q_D(QRasterWindowSurface); d->inSetGeometry = true; if (d->image == 0 || d->image->width() < rect.width() || d->image->height() < rect.height()) { #if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN)) #ifndef Q_WS_WIN if (d_ptr->translucentBackground) #else if (!qt_widget_private(window())->isOpaque) #endif prepareBuffer(QImage::Format_ARGB32_Premultiplied, window()); else #endif prepareBuffer(QNativeImage::systemFormat(), window()); } d->inSetGeometry = false; #if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA) QMainWindow* mWindow = qobject_cast<QMainWindow*>(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->setGeometry(rect); } } } } #endif // Q_WS_MAC && QT_MAC_USE_COCOA }
/*! \fn void CSizeGrip::mouseMoveEvent(QMouseEvent * event) Resizes the top-level widget containing this widget. The mouse move event is passed in the \a event parameter. */ void CSizeGrip::mouseMoveEvent(QMouseEvent * e) { if (e->buttons() != Qt::LeftButton) { QWidget::mouseMoveEvent(e); return; } QWidget* tlw = qt_sizegrip_topLevelWidget(); if (!gotMousePress || tlw->testAttribute(Qt::WA_WState_ConfigPending)) return; #ifdef Q_WS_X11 #if QT_VERSION >= 0x050000 if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) && tlw->isTopLevel() && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint) && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) return; #endif #endif #ifdef Q_WS_WIN #if QT_VERSION >= 0x050000 if (tlw->isWindow() && GetSystemMenu(tlw->winId(), FALSE) != 0 && internalWinId() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { MSG msg; while(PeekMessage(&msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)); return; } #endif #endif QPoint np(e->globalPos()); // Don't extend beyond the available geometry; bound to dyMax and dxMax. QSize ns; if (atBottom()) ns.rheight() = r.height() + qMin(np.y() - p.y(), dyMax); else ns.rheight() = r.height() - qMax(np.y() - p.y(), dyMax); if (atLeft()) ns.rwidth() = r.width() - qMax(np.x() - p.x(), dxMax); else ns.rwidth() = r.width() + qMin(np.x() - p.x(), dxMax); ns = QLayout::closestAcceptableSize(tlw, ns); QPoint p; QRect nr(p, ns); if (atBottom()) { if (atLeft()) nr.moveTopRight(r.topRight()); else nr.moveTopLeft(r.topLeft()); } else { if (atLeft()) nr.moveBottomRight(r.bottomRight()); else nr.moveBottomLeft(r.bottomLeft()); } ((CPObject*)tlw)->changeGeometrySize(nr.x(),nr.y(),nr.width(),nr.height()); }
void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset) { Q_D(QRasterWindowSurface); // Not ready for painting yet, bail out. This can happen in // QWidget::create_sys() if (!d->image) return; #ifdef Q_WS_WIN QRect br = rgn.boundingRect(); #ifndef Q_OS_WINCE if (!qt_widget_private(window())->isOpaque && d->canUseLayeredWindow) { QRect r = window()->frameGeometry(); QPoint frameOffset = qt_widget_private(window())->frameStrut().topLeft(); QRect dirtyRect = br.translated(offset + frameOffset); SIZE size = {r.width(), r.height()}; POINT ptDst = {r.x(), r.y()}; POINT ptSrc = {0, 0}; Q_BLENDFUNCTION blend = {AC_SRC_OVER, 0, (int)(255.0 * window()->windowOpacity()), Q_AC_SRC_ALPHA}; RECT dirty = {dirtyRect.x(), dirtyRect.y(), dirtyRect.x() + dirtyRect.width(), dirtyRect.y() + dirtyRect.height()}; Q_UPDATELAYEREDWINDOWINFO info = {sizeof(info), NULL, &ptDst, &size, d->image->hdc, &ptSrc, 0, &blend, Q_ULW_ALPHA, &dirty}; (*ptrUpdateLayeredWindowIndirect)(window()->internalWinId(), &info); } else #endif { QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft(); HDC widget_dc = widget->getDC(); QRect wbr = br.translated(-wOffset); BitBlt(widget_dc, wbr.x(), wbr.y(), wbr.width(), wbr.height(), d->image->hdc, br.x() + offset.x(), br.y() + offset.y(), SRCCOPY); widget->releaseDC(widget_dc); } #ifndef QT_NO_DEBUG static bool flush = !qgetenv("QT_FLUSH_WINDOWSURFACE").isEmpty(); if (flush) { SelectObject(qt_win_display_dc(), GetStockObject(BLACK_BRUSH)); Rectangle(qt_win_display_dc(), 0, 0, d->image->width() + 2, d->image->height() + 2); BitBlt(qt_win_display_dc(), 1, 1, d->image->width(), d->image->height(), d->image->hdc, 0, 0, SRCCOPY); } #endif #endif #ifdef Q_WS_X11 extern void *qt_getClipRects(const QRegion &r, int &num); // in qpaintengine_x11.cpp extern QWidgetData* qt_widget_data(QWidget *); QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft(); if (widget->window() != window()) { XFreeGC(X11->display, d_ptr->gc); d_ptr->gc = XCreateGC(X11->display, widget->handle(), 0, 0); } QRegion wrgn(rgn); if (!wOffset.isNull()) wrgn.translate(-wOffset); QRect wbr = wrgn.boundingRect(); int num; XRectangle *rects = (XRectangle *)qt_getClipRects(wrgn, num); XSetClipRectangles(X11->display, d_ptr->gc, 0, 0, rects, num, YXBanded); QRect br = rgn.boundingRect().translated(offset); #ifndef QT_NO_MITSHM if (d_ptr->image->xshmpm) { XCopyArea(X11->display, d_ptr->image->xshmpm, widget->handle(), d_ptr->gc, br.x(), br.y(), br.width(), br.height(), wbr.x(), wbr.y()); XSync(X11->display, False); } else #endif { const QImage &src = d->image->image; br = br.intersected(src.rect()); if (src.format() != QImage::Format_RGB32) { QX11PixmapData *data = new QX11PixmapData(QPixmapData::PixmapType); data->xinfo = widget->x11Info(); data->fromImage(src, Qt::AutoColor); QPixmap pm = QPixmap(data); XCopyArea(X11->display, pm.handle(), widget->handle(), d_ptr->gc, br.x() , br.y() , br.width(), br.height(), wbr.x(), wbr.y()); } else { // qpaintengine_x11.cpp extern void qt_x11_drawImage(const QRect &rect, const QPoint &pos, const QImage &image, Drawable hd, GC gc, Display *dpy, Visual *visual, int depth); qt_x11_drawImage(br, wbr.topLeft(), src, widget->handle(), d_ptr->gc, X11->display, (Visual *)widget->x11Info().visual(), widget->x11Info().depth()); } } #endif // FALCON #ifdef Q_WS_MAC // qDebug() << "Flushing" << widget << rgn << offset; // d->image->image.save("flush.png"); // Get a context for the widget. #ifndef QT_MAC_USE_COCOA CGContextRef context; CGrafPtr port = GetWindowPort(qt_mac_window_for(widget)); QDBeginCGContext(port, &context); #else extern CGContextRef qt_mac_graphicsContextFor(QWidget *); CGContextRef context = qt_mac_graphicsContextFor(widget); #endif CGContextSaveGState(context); // Flip context. CGContextTranslateCTM(context, 0, widget->height()); CGContextScaleCTM(context, 1, -1); // Clip to region. const QVector<QRect> &rects = rgn.rects(); for (int i = 0; i < rects.size(); ++i) { const QRect &rect = rects.at(i); CGContextAddRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height())); } CGContextClip(context); QRect r = rgn.boundingRect(); const CGRect area = CGRectMake(r.x(), r.y(), r.width(), r.height()); CGImageRef image = CGBitmapContextCreateImage(d->image->cg); 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 #endif }
QLineEditPrivate *QLineEditIconButton::lineEditPrivate() const { QLineEdit *le = qobject_cast<QLineEdit *>(parentWidget()); return le ? static_cast<QLineEditPrivate *>(qt_widget_private(le)) : Q_NULLPTR; }
void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset) { Q_D(QRasterWindowSurface); // Not ready for painting yet, bail out. This can happen in // QWidget::create_sys() if (!d->image || rgn.rectCount() == 0) return; #ifdef Q_WS_WIN QRect br = rgn.boundingRect(); if (!qt_widget_private(window())->isOpaque && window()->testAttribute(Qt::WA_TranslucentBackground) && (qt_widget_private(window())->data.window_flags & Qt::FramelessWindowHint)) { QRect r = window()->frameGeometry(); QPoint frameOffset = qt_widget_private(window())->frameStrut().topLeft(); QRect dirtyRect = br.translated(offset + frameOffset); SIZE size = {r.width(), r.height()}; POINT ptDst = {r.x(), r.y()}; POINT ptSrc = {0, 0}; BLENDFUNCTION blend = {AC_SRC_OVER, 0, (BYTE)(255.0 * window()->windowOpacity()), Q_AC_SRC_ALPHA}; RECT dirty = {dirtyRect.x(), dirtyRect.y(), dirtyRect.x() + dirtyRect.width(), dirtyRect.y() + dirtyRect.height()}; Q_UPDATELAYEREDWINDOWINFO info = {sizeof(info), NULL, &ptDst, &size, d->image->hdc, &ptSrc, 0, &blend, Q_ULW_ALPHA, &dirty}; ptrUpdateLayeredWindowIndirect(window()->internalWinId(), &info); } else { QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft(); HDC widget_dc = widget->getDC(); QRect wbr = br.translated(-wOffset); BitBlt(widget_dc, wbr.x(), wbr.y(), wbr.width(), wbr.height(), d->image->hdc, br.x() + offset.x(), br.y() + offset.y(), SRCCOPY); widget->releaseDC(widget_dc); } #ifndef QT_NO_DEBUG static bool flush = !qgetenv("QT_FLUSH_WINDOWSURFACE").isEmpty(); if (flush) { SelectObject(qt_win_display_dc(), GetStockObject(BLACK_BRUSH)); Rectangle(qt_win_display_dc(), 0, 0, d->image->width() + 2, d->image->height() + 2); BitBlt(qt_win_display_dc(), 1, 1, d->image->width(), d->image->height(), d->image->hdc, 0, 0, SRCCOPY); } #endif #endif #ifdef Q_WS_X11 extern void *qt_getClipRects(const QRegion &r, int &num); // in qpaintengine_x11.cpp extern QWidgetData* qt_widget_data(QWidget *); QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft(); if (widget->window() != window()) { XFreeGC(X11->display, d_ptr->gc); d_ptr->gc = XCreateGC(X11->display, widget->handle(), 0, 0); } QRegion wrgn(rgn); if (!wOffset.isNull()) wrgn.translate(-wOffset); if (wrgn.rectCount() != 1) { int num; XRectangle *rects = (XRectangle *)qt_getClipRects(wrgn, num); XSetClipRectangles(X11->display, d_ptr->gc, 0, 0, rects, num, YXBanded); } QPoint widgetOffset = offset + wOffset; QRect clipRect = widget->rect().translated(widgetOffset).intersected(d_ptr->image->image.rect()); QRect br = rgn.boundingRect().translated(offset).intersected(clipRect); QPoint wpos = br.topLeft() - widgetOffset; #ifndef QT_NO_MITSHM if (d_ptr->image->xshmpm) { XCopyArea(X11->display, d_ptr->image->xshmpm, widget->handle(), d_ptr->gc, br.x(), br.y(), br.width(), br.height(), wpos.x(), wpos.y()); d_ptr->needsSync = true; } else if (d_ptr->image->xshmimg) { XShmPutImage(X11->display, widget->handle(), d_ptr->gc, d_ptr->image->xshmimg, br.x(), br.y(), wpos.x(), wpos.y(), br.width(), br.height(), False); d_ptr->needsSync = true; } else #endif { int depth = widget->x11Info().depth(); const QImage &src = d->image->image; if (src.format() != QImage::Format_RGB32 || depth < 24 || X11->bppForDepth.value(depth) != 32) { Q_ASSERT(src.depth() >= 16); const QImage sub_src(src.scanLine(br.y()) + br.x() * (uint(src.depth()) / 8), br.width(), br.height(), src.bytesPerLine(), src.format()); QX11PixmapData *data = new QX11PixmapData(QPixmapData::PixmapType); data->xinfo = widget->x11Info(); data->fromImage(sub_src, Qt::NoOpaqueDetection); QPixmap pm = QPixmap(data); XCopyArea(X11->display, pm.handle(), widget->handle(), d_ptr->gc, 0 , 0 , br.width(), br.height(), wpos.x(), wpos.y()); } else { // qpaintengine_x11.cpp extern void qt_x11_drawImage(const QRect &rect, const QPoint &pos, const QImage &image, Drawable hd, GC gc, Display *dpy, Visual *visual, int depth); qt_x11_drawImage(br, wpos, src, widget->handle(), d_ptr->gc, X11->display, (Visual *)widget->x11Info().visual(), depth); } } if (wrgn.rectCount() != 1) XSetClipMask(X11->display, d_ptr->gc, XNone); #endif // FALCON #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); #else // Get a context for the widget. CGContextRef context; CGrafPtr port = GetWindowPort(qt_mac_window_for(widget)); QDBeginCGContext(port, &context); CGContextRetain(context); CGContextSaveGState(context); // Flip context. CGContextTranslateCTM(context, 0, widget->height()); CGContextScaleCTM(context, 1, -1); // Clip to region. const QVector<QRect> &rects = rgn.rects(); for (int i = 0; i < rects.size(); ++i) { const QRect &rect = rects.at(i); CGContextAddRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height())); } CGContextClip(context); QRect r = rgn.boundingRect().intersected(d->image->image.rect()); const CGRect area = CGRectMake(r.x(), r.y(), r.width(), r.height()); CGImageRef image = CGBitmapContextCreateImage(d->image->cg); CGImageRef subImage = CGImageCreateWithImageInRect(image, area); qt_mac_drawCGImage(context, &area, subImage); CGImageRelease(subImage); CGImageRelease(image); QDEndCGContext(port, &context); // Restore context. CGContextRestoreGState(context); CGContextRelease(context); #endif // QT_MAC_USE_COCOA #endif // Q_WS_MAC }
/*! \fn void CSizeGrip::mousePressEvent(QMouseEvent * event) Receives the mouse press events for the widget, and primes the resize operation. The mouse press event is passed in the \a event parameter. */ void CSizeGrip::mousePressEvent(QMouseEvent * e) { ungrabGesture(Qt::TapAndHoldGesture); if (e->button() != Qt::LeftButton) { QWidget::mousePressEvent(e); return; } QWidget *tlw = qt_sizegrip_topLevelWidget(); p = e->globalPos(); gotMousePress = true; r = tlw->geometry(); #ifdef Q_WS_X11 #if QT_VERSION >= 0x050000 // Use a native X11 sizegrip for "real" top-level windows if supported. if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint) && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.message_type = ATOM(_NET_WM_MOVERESIZE); xev.xclient.display = X11->display; xev.xclient.window = tlw->winId(); xev.xclient.format = 32; xev.xclient.data.l[0] = e->globalPos().x(); xev.xclient.data.l[1] = e->globalPos().y(); if (atBottom()) xev.xclient.data.l[2] = atLeft() ? 6 : 4; // bottomleft/bottomright else xev.xclient.data.l[2] = atLeft() ? 0 : 2; // topleft/topright xev.xclient.data.l[3] = Button1; xev.xclient.data.l[4] = 0; XUngrabPointer(X11->display, X11->time); XSendEvent(X11->display, QX11Info::appRootWindow(x11Info().screen()), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); return; } #endif #endif // Q_WS_X11 #ifdef Q_WS_WIN #if QT_VERSION >= 0x050000 if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { uint orientation = 0; if (atBottom()) orientation = atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT; else orientation = atLeft() ? SZ_SIZETOPLEFT : SZ_SIZETOPRIGHT; ReleaseCapture(); PostMessage(tlw->winId(), WM_SYSCOMMAND, orientation, 0); return; } #endif #endif // Q_WS_WIN // Find available desktop/workspace geometry. QRect availableGeometry; bool hasVerticalSizeConstraint = true; bool hasHorizontalSizeConstraint = true; if (tlw->isWindow()) availableGeometry = QApplication::desktop()->availableGeometry(tlw); else { const QWidget *tlwParent = tlw->parentWidget(); // Check if tlw is inside QAbstractScrollArea/QScrollArea. // If that's the case tlw->parentWidget() will return the viewport // and tlw->parentWidget()->parentWidget() will return the scroll area. #ifndef QT_NO_SCROLLAREA QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(tlwParent->parentWidget()); if (scrollArea) { hasHorizontalSizeConstraint = scrollArea->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; hasVerticalSizeConstraint = scrollArea->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; } #endif // QT_NO_SCROLLAREA availableGeometry = tlwParent->contentsRect(); } // Find frame geometries, title bar height, and decoration sizes. const QRect frameGeometry = tlw->frameGeometry(); const int titleBarHeight = qMax(tlw->geometry().y() - frameGeometry.y(), 0); const int bottomDecoration = qMax(frameGeometry.height() - tlw->height() - titleBarHeight, 0); const int leftRightDecoration = qMax((frameGeometry.width() - tlw->width()) / 2, 0); // Determine dyMax depending on whether the sizegrip is at the bottom // of the widget or not. if (atBottom()) { if (hasVerticalSizeConstraint) dyMax = availableGeometry.bottom() - r.bottom() - bottomDecoration; else dyMax = INT_MAX; } else { if (hasVerticalSizeConstraint) dyMax = availableGeometry.y() - r.y() + titleBarHeight; else dyMax = -INT_MAX; } // In RTL mode, the size grip is to the left; find dxMax from the desktop/workspace // geometry, the size grip geometry and the width of the decoration. if (atLeft()) { if (hasHorizontalSizeConstraint) dxMax = availableGeometry.x() - r.x() + leftRightDecoration; else dxMax = -INT_MAX; } else { if (hasHorizontalSizeConstraint) dxMax = availableGeometry.right() - r.right() - leftRightDecoration; else dxMax = INT_MAX; } }