diff -r 56cd8111b7f7 -r 41300fa6a67c src/gui/kernel/qwidget.cpp --- a/src/gui/kernel/qwidget.cpp Tue Jan 26 12:42:25 2010 +0200 +++ b/src/gui/kernel/qwidget.cpp Tue Feb 02 00:43:10 2010 +0200 @@ -197,6 +197,7 @@ , picture(0) #elif defined(Q_WS_WIN) , noPaintOnScreen(0) + , nativeGesturePanEnabled(0) #elif defined(Q_WS_MAC) , needWindowChange(0) , isGLWidget(0) @@ -229,7 +230,9 @@ if (extra) deleteExtra(); +#ifndef QT_NO_GRAPHICSEFFECT delete graphicsEffect; +#endif //QT_NO_GRAPHICSEFFECT } QWindowSurface *QWidgetPrivate::createDefaultWindowSurface() @@ -363,7 +366,8 @@ normally; otherwise, Qt::Key_Up and Qt::Key_Down are used to change focus. - This feature is only available in Qt for Embedded Linux. + This feature is only available in Qt for Embedded Linux and Qt + for Symbian. \sa hasEditFocus(), QApplication::keypadNavigationEnabled() */ @@ -897,7 +901,7 @@ passing a \c QAction with a softkey role set on it. When the widget containing the softkey actions has focus, its softkeys should appear in the user interface. Softkeys are discovered by traversing the widget - heirarchy so it is possible to define a single set of softkeys that are + hierarchy so it is possible to define a single set of softkeys that are present at all times by calling addAction() for a given top level widget. On some platforms, this concept overlaps with \c QMenuBar such that if no @@ -1549,7 +1553,9 @@ extra = new QWExtra; extra->glContext = 0; extra->topextra = 0; +#ifndef QT_NO_GRAPHICSVIEW extra->proxyWidget = 0; +#endif #ifndef QT_NO_CURSOR extra->curs = 0; #endif @@ -1699,12 +1705,13 @@ { Q_Q(QWidget); // Propagate a new inherited mask to all children. +#ifndef QT_NO_GRAPHICSVIEW if (!q->parentWidget() && extra && extra->proxyWidget) { -#ifndef QT_NO_GRAPHICSVIEW QGraphicsProxyWidget *p = extra->proxyWidget; inheritedPaletteResolveMask = p->d_func()->inheritedPaletteResolveMask | p->palette().resolve(); + } else #endif //QT_NO_GRAPHICSVIEW - } else if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) { + if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) { inheritedPaletteResolveMask = 0; } int mask = data.pal.resolve() | inheritedPaletteResolveMask; @@ -1789,6 +1796,7 @@ return r; } +#ifndef QT_NO_GRAPHICSEFFECT void QWidgetPrivate::invalidateGraphicsEffectsRecursively() { Q_Q(QWidget); @@ -1803,6 +1811,7 @@ w = w->parentWidget(); } while (w); } +#endif //QT_NO_GRAPHICSEFFECT void QWidgetPrivate::setDirtyOpaqueRegion() { @@ -1810,7 +1819,9 @@ dirtyOpaqueChildren = true; +#ifndef QT_NO_GRAPHICSEFFECT invalidateGraphicsEffectsRecursively(); +#endif //QT_NO_GRAPHICSEFFECT if (q->isWindow()) return; @@ -1825,18 +1836,6 @@ pd->setDirtyOpaqueRegion(); } -QRegion QWidgetPrivate::getOpaqueRegion() const -{ - Q_Q(const QWidget); - - QRegion r = isOpaque ? q->rect() : getOpaqueChildren(); - if (extra && extra->hasMask) - r &= extra->mask; - if (r.isEmpty()) - return r; - return r & clipRect(); -} - const QRegion &QWidgetPrivate::getOpaqueChildren() const { if (!dirtyOpaqueChildren) @@ -1851,9 +1850,17 @@ continue; const QPoint offset = child->geometry().topLeft(); - that->opaqueChildren += child->d_func()->getOpaqueRegion().translated(offset); - } - + QWidgetPrivate *childd = child->d_func(); + QRegion r = childd->isOpaque ? child->rect() : childd->getOpaqueChildren(); + if (childd->extra && childd->extra->hasMask) + r &= childd->extra->mask; + if (r.isEmpty()) + continue; + r.translate(offset); + that->opaqueChildren += r; + } + + that->opaqueChildren &= q_func()->rect(); that->dirtyOpaqueChildren = false; return that->opaqueChildren; @@ -1963,10 +1970,12 @@ const QWidget *w = q; QPoint offset; +#ifndef QT_NO_GRAPHICSEFFECT if (graphicsEffect) { w = q->parentWidget(); offset -= data.crect.topLeft(); } +#endif //QT_NO_GRAPHICSEFFECT while (w) { const QWidgetPrivate *wd = w->d_func(); @@ -2001,11 +2010,13 @@ // hw: todo: only needed if opacity actually changed setDirtyOpaqueRegion(); +#ifndef QT_NO_GRAPHICSEFFECT if (graphicsEffect) { // ### We should probably add QGraphicsEffect::isOpaque at some point. setOpaque(false); return; } +#endif //QT_NO_GRAPHICSEFFECT Q_Q(QWidget); #ifdef Q_WS_X11 @@ -3072,15 +3083,18 @@ #if defined(Q_WS_MAC) setEnabled_helper_sys(enable); #endif +#ifndef QT_NO_IM if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) { - QInputContext *qic = inputContext(); + QWidget *focusWidget = effectiveFocusWidget(); + QInputContext *qic = focusWidget->d_func()->inputContext(); if (enable) { - qic->setFocusWidget(q); + qic->setFocusWidget(focusWidget); } else { qic->reset(); qic->setFocusWidget(0); } } +#endif //QT_NO_IM QEvent e(QEvent::EnabledChange); QApplication::sendEvent(q, &e); #ifdef QT3_SUPPORT @@ -4379,7 +4393,11 @@ Q_Q(const QWidget); QPalette naturalPalette = QApplication::palette(q); if (!q->testAttribute(Qt::WA_StyleSheet) - && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) || (extra && extra->proxyWidget))) { + && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) +#ifndef QT_NO_GRAPHICSVIEW + || (extra && extra->proxyWidget) +#endif //QT_NO_GRAPHICSVIEW + )) { if (QWidget *p = q->parentWidget()) { if (!p->testAttribute(Qt::WA_StyleSheet)) { if (!naturalPalette.isCopyOf(QApplication::palette())) { @@ -4390,13 +4408,14 @@ naturalPalette = p->palette(); } } - } else if (extra && extra->proxyWidget) { + } #ifndef QT_NO_GRAPHICSVIEW + else if (extra && extra->proxyWidget) { QPalette inheritedPalette = extra->proxyWidget->palette(); inheritedPalette.resolve(inheritedMask); naturalPalette = inheritedPalette.resolve(naturalPalette); + } #endif //QT_NO_GRAPHICSVIEW - } } naturalPalette.resolve(0); return naturalPalette; @@ -4514,7 +4533,11 @@ Q_Q(const QWidget); QFont naturalFont = QApplication::font(q); if (!q->testAttribute(Qt::WA_StyleSheet) - && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) || (extra && extra->proxyWidget))) { + && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) +#ifndef QT_NO_GRAPHICSVIEW + || (extra && extra->proxyWidget) +#endif //QT_NO_GRAPHICSVIEW + )) { if (QWidget *p = q->parentWidget()) { if (!p->testAttribute(Qt::WA_StyleSheet)) { if (!naturalFont.isCopyOf(QApplication::font())) { @@ -4525,13 +4548,14 @@ naturalFont = p->font(); } } - } else if (extra && extra->proxyWidget) { + } #ifndef QT_NO_GRAPHICSVIEW + else if (extra && extra->proxyWidget) { QFont inheritedFont = extra->proxyWidget->font(); inheritedFont.resolve(inheritedMask); naturalFont = inheritedFont.resolve(naturalFont); + } #endif //QT_NO_GRAPHICSVIEW - } } naturalFont.resolve(0); return naturalFont; @@ -4578,12 +4602,13 @@ data.fnt.x11SetScreen(xinfo.screen()); #endif // Combine new mask with natural mask and propagate to children. +#ifndef QT_NO_GRAPHICSVIEW if (!q->parentWidget() && extra && extra->proxyWidget) { -#ifndef QT_NO_GRAPHICSVIEW QGraphicsProxyWidget *p = extra->proxyWidget; inheritedFontResolveMask = p->d_func()->inheritedFontResolveMask | p->font().resolve(); + } else #endif //QT_NO_GRAPHICSVIEW - } else if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) { + if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) { inheritedFontResolveMask = 0; } uint newMask = data.fnt.resolve() | inheritedFontResolveMask; @@ -4653,8 +4678,10 @@ By default, this property is set to Qt::LeftToRight. When the layout direction is set on a widget, it will propagate to - the widget's children. Children added after the call to \c - setLayoutDirection() will not inherit the parent's layout + the widget's children, but not to a child that is a window and not + to a child for which setLayoutDirection() has been explicitly + called. Also, child widgets added \e after setLayoutDirection() + has been called for the parent do not inherit the parent's layout direction. \sa QApplication::layoutDirection @@ -5000,11 +5027,13 @@ \sa setGraphicsEffect() */ +#ifndef QT_NO_GRAPHICSEFFECT QGraphicsEffect *QWidget::graphicsEffect() const { Q_D(const QWidget); return d->graphicsEffect; } +#endif //QT_NO_GRAPHICSEFFECT /*! @@ -5017,41 +5046,39 @@ If \a effect is the installed on a different widget, setGraphicsEffect() will remove the effect from the widget and install it on this widget. + QWidget takes ownership of \a effect. + \note This function will apply the effect on itself and all its children. \since 4.6 \sa graphicsEffect() */ +#ifndef QT_NO_GRAPHICSEFFECT void QWidget::setGraphicsEffect(QGraphicsEffect *effect) { Q_D(QWidget); if (d->graphicsEffect == effect) return; - if (d->graphicsEffect && effect) { + if (d->graphicsEffect) { + d->invalidateBuffer(rect()); delete d->graphicsEffect; d->graphicsEffect = 0; } - if (!effect) { - // Unset current effect. - QGraphicsEffectPrivate *oldEffectPrivate = d->graphicsEffect->d_func(); - d->graphicsEffect = 0; - if (oldEffectPrivate) { - oldEffectPrivate->setGraphicsEffectSource(0); // deletes the current source. - } - } else { + if (effect) { // Set new effect. QGraphicsEffectSourcePrivate *sourced = new QWidgetEffectSourcePrivate(this); QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced); d->graphicsEffect = effect; effect->d_func()->setGraphicsEffectSource(source); + update(); } d->updateIsOpaque(); - update(); -} +} +#endif //QT_NO_GRAPHICSEFFECT bool QWidgetPrivate::isAboutToShow() const { @@ -5144,8 +5171,7 @@ return; QPixmap pixmap(size); - if (!(renderFlags & QWidget::DrawWindowBackground) - || !q->palette().brush(q->backgroundRole()).isOpaque()) + if (!(renderFlags & QWidget::DrawWindowBackground) || !isOpaque) pixmap.fill(Qt::transparent); q->render(&pixmap, QPoint(), toBePainted, renderFlags); @@ -5198,6 +5224,7 @@ return; Q_Q(QWidget); +#ifndef QT_NO_GRAPHICSEFFECT if (graphicsEffect && graphicsEffect->isEnabled()) { QGraphicsEffectSource *source = graphicsEffect->d_func()->source; QWidgetEffectSourcePrivate *sourced = static_cast @@ -5211,7 +5238,7 @@ QPainter p(pdev); p.translate(offset); context.painter = &p; - graphicsEffect->draw(&p, source); + graphicsEffect->draw(&p); paintEngine->d_func()->systemClip = QRegion(); } else { context.painter = sharedPainter; @@ -5221,13 +5248,14 @@ } sharedPainter->save(); sharedPainter->translate(offset); - graphicsEffect->draw(sharedPainter, source); + graphicsEffect->draw(sharedPainter); sharedPainter->restore(); } sourced->context = 0; return; } } +#endif //QT_NO_GRAFFICSEFFECT const bool asRoot = flags & DrawAsRoot; const bool alsoOnScreen = flags & DrawPaintOnScreen; @@ -5382,7 +5410,6 @@ QWidgetPrivate *wd = w->d_func(); const QPoint widgetPos(w->data->crect.topLeft()); const bool hasMask = wd->extra && wd->extra->hasMask && !wd->graphicsEffect; - if (index > 0) { QRegion wr(rgn); if (wd->isOpaque) @@ -5394,7 +5421,11 @@ , sharedPainter, backingStore); } - if (w->updatesEnabled() && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget)) { + if (w->updatesEnabled() +#ifndef QT_NO_GRAPHICSVIEW + && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget) +#endif //QT_NO_GRAPHICSVIEW + ) { QRegion wRegion(rgn); wRegion &= wd->effectiveRectFor(w->data->crect); wRegion.translate(-widgetPos); @@ -5404,6 +5435,7 @@ } } +#ifndef QT_NO_GRAPHICSEFFECT QRectF QWidgetEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const { if (system != Qt::DeviceCoordinates) @@ -5437,7 +5469,8 @@ context->sharedPainter, context->backingStore); } -QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset) const +QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset, + QGraphicsEffect::PixmapPadMode mode) const { const bool deviceCoordinates = (system == Qt::DeviceCoordinates); if (!context && deviceCoordinates) { @@ -5455,7 +5488,20 @@ pixmapOffset = painterTransform.map(pixmapOffset); } - QRect effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect(); + + QRect effectRect; + + if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) { + effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect(); + + } else if (mode == QGraphicsEffect::PadToTransparentBorder) { + effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect(); + + } else { + effectRect = sourceRect.toAlignedRect(); + + } + if (offset) *offset = effectRect.topLeft(); @@ -5490,6 +5536,7 @@ m_widget->render(&pixmap, pixmapOffset); return pixmap; } +#endif //QT_NO_GRAPHICSEFFECT #ifndef QT_NO_GRAPHICSVIEW /*! @@ -5995,6 +6042,11 @@ (Nothing happens if the focus in and focus out widgets are the same.) + \note On embedded platforms, setFocus() will not cause an input panel + to be opened by the input method. If you want this to happen, you + have to send a QEvent::RequestSoftwareInputPanel event to the + widget yourself. + setFocus() gives focus to a widget regardless of its focus policy, but does not clear any keyboard grab (see grabKeyboard()). @@ -6007,7 +6059,7 @@ \sa hasFocus(), clearFocus(), focusInEvent(), focusOutEvent(), setFocusPolicy(), focusWidget(), QApplication::focusWidget(), grabKeyboard(), - grabMouse(), {Keyboard Focus} + grabMouse(), {Keyboard Focus}, QEvent::RequestSoftwareInputPanel */ void QWidget::setFocus(Qt::FocusReason reason) @@ -7320,7 +7372,7 @@ break; parent = parent->parentWidget(); } - if (parent && !d->getOpaqueRegion().isEmpty()) + if (parent) parent->d_func()->setDirtyOpaqueRegion(); } @@ -8198,7 +8250,8 @@ QList childList = d->children; for (int i = 0; i < childList.size(); ++i) { QObject *o = childList.at(i); - QApplication::sendEvent(o, event); + if (o) + QApplication::sendEvent(o, event); } } update(); @@ -8227,7 +8280,7 @@ QList childList = d->children; for (int i = 0; i < childList.size(); ++i) { QObject *o = childList.at(i); - if (o != QApplication::activeModalWidget()) { + if (o && o != QApplication::activeModalWidget()) { if (qobject_cast(o) && static_cast(o)->isWindow()) { // do not forward the event to child windows, // QApplication does this for us @@ -8323,9 +8376,10 @@ case QEvent::TouchUpdate: case QEvent::TouchEnd: { +#ifndef Q_WS_MAC QTouchEvent *touchEvent = static_cast(event); const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first(); - if (touchPoint.isPrimary()) + if (touchPoint.isPrimary() || touchEvent->deviceType() == QTouchEvent::TouchPad) break; // fake a mouse event! @@ -8354,6 +8408,7 @@ Qt::LeftButton, touchEvent->modifiers()); (void) QApplication::sendEvent(this, &mouseEvent); +#endif // Q_WS_MAC break; } case QEvent::Gesture: @@ -8950,11 +9005,16 @@ Qt::InputMethodHints QWidget::inputMethodHints() const { Q_D(const QWidget); +#ifndef QT_NO_IM return d->imHints; +#else //QT_NO_IM + return 0; +#endif //QT_NO_IM } void QWidget::setInputMethodHints(Qt::InputMethodHints hints) { +#ifndef QT_NO_IM Q_D(QWidget); d->imHints = hints; // Optimisation to update input context only it has already been created. @@ -8963,6 +9023,7 @@ if (ic) ic->update(); } +#endif //QT_NO_IM } @@ -9840,13 +9901,13 @@ Q_D(QWidget); #ifndef QT_NO_GRAPHICSVIEW if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) { - // Graphics View maintains its own dirty region as a list of rects; - // until we can connect item updates directly to the view, we must - // separately add a translated dirty region. - if (!d->dirty.isEmpty()) { - foreach (const QRect &rect, (d->dirty.translated(dx, dy)).rects()) - proxy->update(rect); - } + // Graphics View maintains its own dirty region as a list of rects; + // until we can connect item updates directly to the view, we must + // separately add a translated dirty region. + if (!d->dirty.isEmpty()) { + foreach (const QRect &rect, (d->dirty.translated(dx, dy)).rects()) + proxy->update(rect); + } proxy->scroll(dx, dy, proxy->subWidgetRect(this)); return; } @@ -9875,13 +9936,13 @@ Q_D(QWidget); #ifndef QT_NO_GRAPHICSVIEW if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) { - // Graphics View maintains its own dirty region as a list of rects; - // until we can connect item updates directly to the view, we must - // separately add a translated dirty region. - if (!d->dirty.isEmpty()) { - foreach (const QRect &rect, (d->dirty.translated(dx, dy) & r).rects()) - proxy->update(rect); - } + // Graphics View maintains its own dirty region as a list of rects; + // until we can connect item updates directly to the view, we must + // separately add a translated dirty region. + if (!d->dirty.isEmpty()) { + foreach (const QRect &rect, (d->dirty.translated(dx, dy) & r).rects()) + proxy->update(rect); + } proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint())); return; } @@ -10294,9 +10355,11 @@ QApplication::sendEvent(this, &e); break; } case Qt::WA_NativeWindow: { +#ifndef QT_NO_IM + QWidget *focusWidget = d->effectiveFocusWidget(); QInputContext *ic = 0; if (on && !internalWinId() && testAttribute(Qt::WA_InputMethodEnabled) && hasFocus()) { - ic = d->inputContext(); + ic = focusWidget->d_func()->inputContext(); ic->reset(); ic->setFocusWidget(0); } @@ -10305,7 +10368,8 @@ if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created)) d->createWinId(); if (ic && isEnabled()) - ic->setFocusWidget(this); + ic->setFocusWidget(focusWidget); +#endif //QT_NO_IM break; } case Qt::WA_PaintOnScreen: @@ -10335,17 +10399,20 @@ #endif break; case Qt::WA_InputMethodEnabled: { - QInputContext *ic = d->ic; +#ifndef QT_NO_IM + QWidget *focusWidget = d->effectiveFocusWidget(); + QInputContext *ic = focusWidget->d_func()->ic; if (!ic && (!on || hasFocus())) - ic = d->inputContext(); + ic = focusWidget->d_func()->inputContext(); if (ic) { - if (on && hasFocus() && ic->focusWidget() != this && isEnabled()) { - ic->setFocusWidget(this); - } else if (!on && ic->focusWidget() == this) { + if (on && hasFocus() && ic->focusWidget() != focusWidget && isEnabled()) { + ic->setFocusWidget(focusWidget); + } else if (!on && ic->focusWidget() == focusWidget) { ic->reset(); ic->setFocusWidget(0); } } +#endif //QT_NO_IM break; } case Qt::WA_WindowPropagation: @@ -11405,6 +11472,17 @@ \sa QWidget::setMaximumSize() */ +/*! + \fn QWidget::setupUi(QWidget *widget) + + Sets up the user interface for the specified \a widget. + + \note This function is available with widgets that derive from user + interface descriptions created using \l{uic}. + + \sa {Using a Designer UI File in Your Application} +*/ + QRect QWidgetPrivate::frameStrut() const { Q_Q(const QWidget); @@ -11696,21 +11774,33 @@ */ /*! - Subscribes the widget to a given \a gesture with a \a context. - - \sa QGestureEvent + Subscribes the widget to a given \a gesture with specific \a flags. + + \sa ungrabGesture(), QGestureEvent \since 4.6 */ -void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureContext context) +void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags) { Q_D(QWidget); - d->gestureContext.insert(gesture, context); + d->gestureContext.insert(gesture, flags); (void)QGestureManager::instance(); // create a gesture manager } -QT_END_NAMESPACE - -#include "moc_qwidget.cpp" +/*! + Unsubscribes the widget from a given \a gesture type + + \sa grabGesture(), QGestureEvent + \since 4.6 +*/ +void QWidget::ungrabGesture(Qt::GestureType gesture) +{ + Q_D(QWidget); + if (d->gestureContext.remove(gesture)) { + QGestureManager *manager = QGestureManager::instance(); + manager->cleanupCachedGestures(this, gesture); + } +} + /*! \typedef WId @@ -11786,8 +11876,7 @@ isVisible() returns false for a widget, that widget cannot call grabMouse(). - \sa releaseMouse() grabKeyboard() releaseKeyboard() grabKeyboard() - focusWidget() + \sa releaseMouse() grabKeyboard() releaseKeyboard() */ /*! @@ -12028,3 +12117,8 @@ delete winId; } #endif + +QT_END_NAMESPACE + +#include "moc_qwidget.cpp" +