556void QApplicationPrivate::initializeWidgetFontHash()
558 const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme();
561 FontHash *fontHash = app_fonts();
564 if (
const QFont *font = theme->font(QPlatformTheme::MenuFont))
565 fontHash->insert(QByteArrayLiteral(
"QMenu"), *font);
566 if (
const QFont *font = theme->font(QPlatformTheme::MenuBarFont))
567 fontHash->insert(QByteArrayLiteral(
"QMenuBar"), *font);
568 if (
const QFont *font = theme->font(QPlatformTheme::MenuItemFont))
569 fontHash->insert(QByteArrayLiteral(
"QMenuItem"), *font);
570 if (
const QFont *font = theme->font(QPlatformTheme::MessageBoxFont))
571 fontHash->insert(QByteArrayLiteral(
"QMessageBox"), *font);
572 if (
const QFont *font = theme->font(QPlatformTheme::LabelFont))
573 fontHash->insert(QByteArrayLiteral(
"QLabel"), *font);
574 if (
const QFont *font = theme->font(QPlatformTheme::TipLabelFont))
575 fontHash->insert(QByteArrayLiteral(
"QTipLabel"), *font);
576 if (
const QFont *font = theme->font(QPlatformTheme::TitleBarFont))
577 fontHash->insert(QByteArrayLiteral(
"QTitleBar"), *font);
578 if (
const QFont *font = theme->font(QPlatformTheme::StatusBarFont))
579 fontHash->insert(QByteArrayLiteral(
"QStatusBar"), *font);
580 if (
const QFont *font = theme->font(QPlatformTheme::MdiSubWindowTitleFont))
581 fontHash->insert(QByteArrayLiteral(
"QMdiSubWindowTitleBar"), *font);
582 if (
const QFont *font = theme->font(QPlatformTheme::DockWidgetTitleFont))
583 fontHash->insert(QByteArrayLiteral(
"QDockWidgetTitle"), *font);
584 if (
const QFont *font = theme->font(QPlatformTheme::PushButtonFont))
585 fontHash->insert(QByteArrayLiteral(
"QPushButton"), *font);
586 if (
const QFont *font = theme->font(QPlatformTheme::CheckBoxFont))
587 fontHash->insert(QByteArrayLiteral(
"QCheckBox"), *font);
588 if (
const QFont *font = theme->font(QPlatformTheme::RadioButtonFont))
589 fontHash->insert(QByteArrayLiteral(
"QRadioButton"), *font);
590 if (
const QFont *font = theme->font(QPlatformTheme::ToolButtonFont))
591 fontHash->insert(QByteArrayLiteral(
"QToolButton"), *font);
592 if (
const QFont *font = theme->font(QPlatformTheme::ItemViewFont))
593 fontHash->insert(QByteArrayLiteral(
"QAbstractItemView"), *font);
594 if (
const QFont *font = theme->font(QPlatformTheme::ListViewFont))
595 fontHash->insert(QByteArrayLiteral(
"QListView"), *font);
596 if (
const QFont *font = theme->font(QPlatformTheme::HeaderViewFont))
597 fontHash->insert(QByteArrayLiteral(
"QHeaderView"), *font);
598 if (
const QFont *font = theme->font(QPlatformTheme::ListBoxFont))
599 fontHash->insert(QByteArrayLiteral(
"QListBox"), *font);
600 if (
const QFont *font = theme->font(QPlatformTheme::ComboMenuItemFont))
601 fontHash->insert(QByteArrayLiteral(
"QComboMenuItem"), *font);
602 if (
const QFont *font = theme->font(QPlatformTheme::ComboLineEditFont))
603 fontHash->insert(QByteArrayLiteral(
"QComboLineEdit"), *font);
604 if (
const QFont *font = theme->font(QPlatformTheme::SmallFont))
605 fontHash->insert(QByteArrayLiteral(
"QSmallFont"), *font);
606 if (
const QFont *font = theme->font(QPlatformTheme::MiniFont))
607 fontHash->insert(QByteArrayLiteral(
"QMiniFont"), *font);
1827void QApplicationPrivate::setActiveWindow(QWidget* act)
1829 QWidget* window = act?act->window():
nullptr;
1831 if (QApplicationPrivate::active_window == window)
1834#if QT_CONFIG(graphicsview)
1835 if (window && window->graphicsProxyWidget()) {
1841 QWidgetList toBeActivated;
1842 QWidgetList toBeDeactivated;
1844 if (QApplicationPrivate::active_window) {
1845 if (QApplication::style()->styleHint(QStyle::SH_Widget_ShareActivation,
nullptr, QApplicationPrivate::active_window)) {
1846 const QWidgetList list = QApplication::topLevelWidgets();
1847 for (
auto *w : list) {
1848 if (w->isVisible() && w->isActiveWindow())
1849 toBeDeactivated.append(w);
1852 toBeDeactivated.append(QApplicationPrivate::active_window);
1856 if (QApplicationPrivate::focus_widget) {
1857 if (QApplicationPrivate::focus_widget->testAttribute(Qt::WA_InputMethodEnabled))
1858 QGuiApplication::inputMethod()->commit();
1860 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange, Qt::ActiveWindowFocusReason);
1861 QCoreApplication::sendEvent(QApplicationPrivate::focus_widget, &focusAboutToChange);
1864 QApplicationPrivate::active_window = window;
1866 if (QApplicationPrivate::active_window) {
1867 if (QApplication::style()->styleHint(QStyle::SH_Widget_ShareActivation,
nullptr, QApplicationPrivate::active_window)) {
1868 const QWidgetList list = QApplication::topLevelWidgets();
1869 for (
auto *w : list) {
1870 if (w->isVisible() && w->isActiveWindow())
1871 toBeActivated.append(w);
1874 toBeActivated.append(QApplicationPrivate::active_window);
1880 QEvent activationChange(QEvent::ActivationChange);
1881 QEvent windowActivate(QEvent::WindowActivate);
1882 QEvent windowDeactivate(QEvent::WindowDeactivate);
1884 for (QWidget *w : std::as_const(toBeActivated)) {
1885 QApplication::sendSpontaneousEvent(w, &windowActivate);
1886 QApplication::sendSpontaneousEvent(w, &activationChange);
1889 for (QWidget *w : std::as_const(toBeDeactivated)) {
1890 QApplication::sendSpontaneousEvent(w, &windowDeactivate);
1891 QApplication::sendSpontaneousEvent(w, &activationChange);
1894 if (!inPopupMode()) {
1896 if (!QApplicationPrivate::active_window && QApplicationPrivate::focus_widget) {
1897 QApplicationPrivate::setFocusWidget(
nullptr, Qt::ActiveWindowFocusReason);
1898 }
else if (QApplicationPrivate::active_window) {
1899 QWidget *w = QApplicationPrivate::active_window->focusWidget();
1900 if (w && w->isVisible() )
1901 w->setFocus(Qt::ActiveWindowFocusReason);
1903 w = QApplicationPrivate::focusNextPrevChild_helper(QApplicationPrivate::active_window,
true);
1905 w->setFocus(Qt::ActiveWindowFocusReason);
1907 w = QApplicationPrivate::focus_widget;
1908 if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus) {
1909 QApplicationPrivate::active_window->setFocus(Qt::ActiveWindowFocusReason);
1910 }
else if (!QApplicationPrivate::active_window->isAncestorOf(w)) {
1912 QApplicationPrivate::setFocusWidget(
nullptr, Qt::ActiveWindowFocusReason);
2048void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave,
const QPointF &globalPosF)
2050 if ((!enter && !leave) || (enter == leave))
2053 QWidgetList leaveList;
2054 QWidgetList enterList;
2056 bool sameWindow = leave && enter && leave->window() == enter->window();
2057 if (leave && !sameWindow) {
2060 leaveList.append(w);
2061 }
while (!w->isWindow() && (w = w->parentWidget()));
2063 if (enter && !sameWindow) {
2066 enterList.append(w);
2067 }
while (!w->isWindow() && (w = w->parentWidget()));
2073 while (!e->isWindow() && (e = e->parentWidget()))
2076 while (!l->isWindow() && (l = l->parentWidget()))
2078 QWidget* wenter = enter;
2079 QWidget* wleave = leave;
2080 while (enterDepth > leaveDepth) {
2081 wenter = wenter->parentWidget();
2084 while (leaveDepth > enterDepth) {
2085 wleave = wleave->parentWidget();
2088 while (!wenter->isWindow() && wenter != wleave) {
2089 wenter = wenter->parentWidget();
2090 wleave = wleave->parentWidget();
2093 for (
auto *w = leave; w != wleave; w = w->parentWidget())
2094 leaveList.append(w);
2096 for (
auto *w = enter; w != wenter; w = w->parentWidget())
2097 enterList.append(w);
2100 QEvent leaveEvent(QEvent::Leave);
2101 for (QWidget *w : std::as_const(leaveList)) {
2102 if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w,
nullptr)) {
2103 QCoreApplication::sendEvent(w, &leaveEvent);
2104 if (w->testAttribute(Qt::WA_Hover) &&
2105 (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
2106 Q_ASSERT(instance());
2107 QHoverEvent he(QEvent::HoverLeave, QPointF(-1, -1), globalPosF, w->mapFromGlobal(globalPosF),
2108 QGuiApplication::keyboardModifiers());
2109 qApp->d_func()->notify_helper(w, &he);
2113 if (!enterList.isEmpty()) {
2115 const QPointF globalPos = qIsInf(globalPosF.x())
2118 const QPointF windowPos = std::as_const(enterList).back()->window()->mapFromGlobal(globalPos);
2119 for (
auto it = enterList.crbegin(), end = enterList.crend(); it != end; ++it) {
2121 if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w,
nullptr)) {
2122 const QPointF localPos = w->mapFromGlobal(globalPos);
2123 QEnterEvent enterEvent(localPos, windowPos, globalPos);
2124 QCoreApplication::sendEvent(w, &enterEvent);
2125 if (w->testAttribute(Qt::WA_Hover) &&
2126 (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
2127 QHoverEvent he(QEvent::HoverEnter, windowPos, QPointF(-1, -1), globalPos,
2128 QGuiApplication::keyboardModifiers());
2129 QMutableEventPoint::setPosition(he.point(0), localPos);
2130 qApp->d_func()->notify_helper(w, &he);
2139 const bool enterOnAlien = (enter && (isAlien(enter) || enter->testAttribute(Qt::WA_DontShowOnScreen)));
2142 QWidget *parentOfLeavingCursor =
nullptr;
2143 for (QWidget *w : std::as_const(leaveList)) {
2146 if (w->testAttribute(Qt::WA_SetCursor)) {
2147 QWidget *parent = w->parentWidget();
2148 while (parent && parent->d_func()->data.in_destructor)
2149 parent = parent->parentWidget();
2150 parentOfLeavingCursor = parent;
2156 if (parentOfLeavingCursor && (!enterOnAlien
2157 || parentOfLeavingCursor->effectiveWinId() != enter->effectiveWinId())) {
2158#if QT_CONFIG(graphicsview)
2159 if (!parentOfLeavingCursor->window()->graphicsProxyWidget())
2162 qt_qpa_set_cursor(parentOfLeavingCursor,
true);
2166 QWidget *cursorWidget = enter;
2167 while (!cursorWidget->isWindow() && !cursorWidget->isEnabled())
2168 cursorWidget = cursorWidget->parentWidget();
2173#if QT_CONFIG(graphicsview)
2174 if (cursorWidget->window()->graphicsProxyWidget()) {
2175 QWidgetPrivate::nearestGraphicsProxyWidget(cursorWidget)->setCursor(cursorWidget->cursor());
2179 qt_qpa_set_cursor(cursorWidget,
true);
2559bool QApplication::notify(QObject *receiver, QEvent *e)
2563 if (QApplicationPrivate::is_app_closing)
2566 if (Q_UNLIKELY(!receiver)) {
2567 qWarning(
"QApplication::notify: Unexpected null receiver");
2571 QCoreApplicationPrivate::checkReceiverThread(receiver,
"QApplication::notify");
2573 const bool isWindowType = receiver->isWindowType();
2574 const bool isWidgetType = receiver->isWidgetType();
2576 && QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(receiver), e)) {
2580 QGuiApplicationPrivate::captureGlobalModifierState(e);
2582#ifndef QT_NO_GESTURES
2584 if (d->gestureManager) {
2585 switch (e->type()) {
2587 case QEvent::MetaCall:
2588 case QEvent::DeferredDelete:
2589 case QEvent::DragEnter:
case QEvent::DragMove:
case QEvent::DragLeave:
2590 case QEvent::Drop:
case QEvent::DragResponse:
2591 case QEvent::ChildAdded:
case QEvent::ChildPolished:
2592 case QEvent::ChildRemoved:
2593 case QEvent::UpdateRequest:
2594 case QEvent::UpdateLater:
2595 case QEvent::LocaleChange:
2597 case QEvent::IconDrag:
2598 case QEvent::StyleChange:
2599 case QEvent::GraphicsSceneDragEnter:
2600 case QEvent::GraphicsSceneDragMove:
2601 case QEvent::GraphicsSceneDragLeave:
2602 case QEvent::GraphicsSceneDrop:
2603 case QEvent::DynamicPropertyChange:
2604 case QEvent::NetworkReplyUpdated:
2607 if (d->gestureManager->thread() == QThread::currentThread()) {
2609 if (d->gestureManager->filterEvent(
static_cast<QWidget *>(receiver), e))
2615 if (d->gestureManager->filterEvent(receiver, e))
2624 switch (e->type()) {
2625 case QEvent::ApplicationDeactivate:
2626 case QEvent::OrientationChange:
2630 d->closeAllPopups();
2633 case QEvent::ActivationChange:
2634 case QEvent::KeyPress:
2635 case QEvent::KeyRelease:
2636 case QEvent::FocusOut:
2637 case QEvent::FocusIn:
2638 case QEvent::MouseButtonPress:
2639 case QEvent::MouseButtonRelease:
2640 case QEvent::MouseButtonDblClick:
2641 d->toolTipFallAsleep.stop();
2644 d->toolTipWakeUp.stop();
2650 switch (e->type()) {
2651 case QEvent::KeyPress: {
2652 QKeyEvent* keyEvent =
static_cast<QKeyEvent*>(e);
2653 const int key = keyEvent->key();
2658 if (!e->spontaneous() && isWidgetType
2659 && qt_sendShortcutOverrideEvent(
static_cast<QWidget *>(receiver), keyEvent->timestamp(),
2660 key, keyEvent->modifiers(), keyEvent->text(),
2661 keyEvent->isAutoRepeat(), keyEvent->count())) {
2664 qt_in_tab_key_event = (key == Qt::Key_Backtab
2665 || key == Qt::Key_Tab
2666 || key == Qt::Key_Left
2667 || key == Qt::Key_Up
2668 || key == Qt::Key_Right
2669 || key == Qt::Key_Down);
2678 QWidget * w =
static_cast<QWidget *>(receiver);
2679 switch (e->type()) {
2680 case QEvent::ShortcutOverride:
2681 case QEvent::KeyPress:
2682 case QEvent::KeyRelease: {
2683 QKeyEvent* key =
static_cast<QKeyEvent*>(e);
2684 bool def = key->isAccepted();
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697 QPointer<QObject> pr = receiver;
2703 res = d->notify_helper(w, e);
2705 if (res && key->isAccepted())
2707 if (!pr || w->isWindow())
2710 w = w->parentWidget();
2712 qt_in_tab_key_event =
false;
2715 case QEvent::MouseButtonPress:
2716 case QEvent::MouseButtonRelease:
2717 case QEvent::MouseButtonDblClick:
2718 case QEvent::MouseMove: {
2719 QMouseEvent* mouse =
static_cast<QMouseEvent*>(e);
2720 QPoint relpos = mouse->position().toPoint();
2722 if (e->spontaneous()) {
2723 if (e->type() != QEvent::MouseMove)
2724 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos);
2733 if (e->type() == QEvent::MouseMove && mouse->buttons() == 0
2734 && w->rect().contains(relpos)) {
2735 d->toolTipWidget = w;
2736 d->toolTipPos = relpos;
2737 d->toolTipGlobalPos = mouse->globalPosition().toPoint();
2738 QStyle *s = d->toolTipWidget->style();
2739 int wakeDelay = s->styleHint(QStyle::SH_ToolTip_WakeUpDelay,
nullptr, d->toolTipWidget,
nullptr);
2740 d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive() ? 20 : wakeDelay,
this);
2744 bool eventAccepted = mouse->isAccepted();
2746 QPointer<QWidget> pw = w;
2748 QMouseEvent me(mouse->type(), relpos, mouse->scenePosition(), mouse->globalPosition(),
2749 mouse->button(), mouse->buttons(), mouse->modifiers(), mouse->source(),
2750 mouse->pointingDevice());
2751 me.m_spont = mouse->spontaneous();
2752 me.setTimestamp(mouse->timestamp());
2753 QMutableSinglePointEvent::setDoubleClick(&me, QMutableSinglePointEvent::isDoubleClick(mouse));
2755 if (!w->hasMouseTracking()
2756 && mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
2758 d->sendThroughApplicationEventFilters(w, w == receiver ? mouse : &me);
2761 w->setAttribute(Qt::WA_NoMouseReplay,
false);
2762 res = d->notify_helper(w, w == receiver ? mouse : &me);
2765 eventAccepted = (w == receiver ? mouse : &me)->isAccepted();
2766 if (res && eventAccepted)
2768 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2771 w = w->parentWidget();
2774 mouse->setAccepted(eventAccepted);
2776 if (e->type() == QEvent::MouseMove) {
2780 w =
static_cast<QWidget *>(receiver);
2781 relpos = mouse->position().toPoint();
2782 QPoint diff = relpos - w->mapFromGlobal(mouse->globalPosition()).toPoint();
2784 if (w->testAttribute(Qt::WA_Hover) &&
2785 (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
2786 QHoverEvent he(QEvent::HoverMove, mouse->scenePosition(), mouse->globalPosition(), relpos - diff, mouse->modifiers());
2787 QMutableEventPoint::setPosition(he.point(0), relpos);
2788 d->notify_helper(w, &he);
2790 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2793 w = w->parentWidget();
2798#if QT_CONFIG(wheelevent)
2799 case QEvent::Wheel: {
2801 if (
const QWidget *popup = QApplication::activePopupWidget()) {
2802 if (w->window() != popup)
2806 QWheelEvent* wheel =
static_cast<QWheelEvent*>(e);
2807 if (!wheel->spontaneous()) {
2809
2810
2811
2812
2813 res = d->notify_helper(w, wheel);
2817 const Qt::ScrollPhase phase = wheel->phase();
2818 QPointF relpos = wheel->position();
2841 if (QApplicationPrivate::wheel_widget) {
2842 Q_ASSERT(phase != Qt::NoScrollPhase);
2843 w = QApplicationPrivate::wheel_widget;
2844 relpos = w->mapFromGlobal(wheel->globalPosition());
2847
2848
2849
2850
2853 QApplicationPrivate::wheel_widget =
nullptr;
2855 case Qt::ScrollBegin:
2856 QApplicationPrivate::wheel_widget = w;
2858 case Qt::ScrollUpdate:
2859 case Qt::ScrollMomentum:
2860 if (!QApplicationPrivate::wheel_widget)
2861 QApplicationPrivate::wheel_widget = w;
2863 case Qt::NoScrollPhase:
2864 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos.toPoint());
2869 QWheelEvent we(relpos, wheel->globalPosition(), wheel->pixelDelta(), wheel->angleDelta(), wheel->buttons(),
2870 wheel->modifiers(), phase, wheel->inverted(), wheel->source(), wheel->pointingDevice());
2872 we.setTimestamp(wheel->timestamp());
2877 we.setAccepted(
true);
2878 we.m_spont = wheel->spontaneous() && w == receiver;
2879 res = d->notify_helper(w, &we);
2880 eventAccepted = we.isAccepted();
2881 if (res && eventAccepted)
2883 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2886 QMutableEventPoint::setPosition(we.point(0), we.position() + w->pos());
2887 w = w->parentWidget();
2889 wheel->setAccepted(eventAccepted);
2893#ifndef QT_NO_CONTEXTMENU
2894 case QEvent::ContextMenu: {
2895 QContextMenuEvent *context =
static_cast<QContextMenuEvent*>(e);
2896 QPoint relpos = context->pos();
2897 bool eventAccepted = context->isAccepted();
2899 QContextMenuEvent ce(relpos, context->globalPos(), context->modifiers(),
2901 ce.m_spont = e->spontaneous();
2902 res = d->notify_helper(w, w == receiver ? context : &ce);
2903 eventAccepted = ((w == receiver) ? context : &ce)->isAccepted();
2906 if (res && eventAccepted)
2908 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2912 w = w->parentWidget();
2914 context->setAccepted(eventAccepted);
2918#if QT_CONFIG(tabletevent)
2919 case QEvent::TabletMove:
2920 case QEvent::TabletPress:
2921 case QEvent::TabletRelease: {
2922 QTabletEvent *tablet =
static_cast<QTabletEvent*>(e);
2923 QPointF relpos = tablet->position();
2924 bool eventAccepted = tablet->isAccepted();
2926 QTabletEvent te(tablet->type(), tablet->pointingDevice(), relpos, tablet->globalPosition(),
2927 tablet->pressure(), tablet->xTilt(), tablet->yTilt(),
2928 tablet->tangentialPressure(), tablet->rotation(), tablet->z(),
2929 tablet->modifiers(), tablet->button(), tablet->buttons());
2930 te.m_spont = e->spontaneous();
2931 te.setTimestamp(tablet->timestamp());
2932 te.setAccepted(
false);
2933 res = d->notify_helper(w, w == receiver ? tablet : &te);
2934 eventAccepted = ((w == receiver) ? tablet : &te)->isAccepted();
2936 if (res && eventAccepted)
2938 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2942 w = w->parentWidget();
2944 tablet->setAccepted(eventAccepted);
2949#if QT_CONFIG(tooltip) || QT_CONFIG(whatsthis)
2950 case QEvent::ToolTip:
2951 case QEvent::WhatsThis:
2952 case QEvent::QueryWhatsThis: {
2953 QHelpEvent *help =
static_cast<QHelpEvent*>(e);
2954 QPoint relpos = help->pos();
2955 bool eventAccepted = help->isAccepted();
2957 QHelpEvent he(help->type(), relpos, help->globalPos());
2958 he.m_spont = e->spontaneous();
2959 res = d->notify_helper(w, w == receiver ? help : &he);
2961 eventAccepted = (w == receiver ? help : &he)->isAccepted();
2962 if (res && eventAccepted)
2968 w = w->parentWidget();
2970 help->setAccepted(eventAccepted);
2974#if QT_CONFIG(statustip) || QT_CONFIG(whatsthis)
2975 case QEvent::StatusTip:
2976 case QEvent::WhatsThisClicked:
2978 res = d->notify_helper(w, e);
2979 if (res && e->isAccepted())
2983 w = w->parentWidget();
2988#if QT_CONFIG(draganddrop)
2989 case QEvent::DragEnter: {
2990 QDragEnterEvent *dragEvent =
static_cast<QDragEnterEvent *>(e);
2991#if QT_CONFIG(graphicsview)
2994 const auto &extra = w->window()->d_func()->extra;
2995 if (extra && extra->proxyWidget) {
2996 res = d->notify_helper(w, dragEvent);
3001 if (w->isEnabled() && w->acceptDrops()) {
3002 res = d->notify_helper(w, dragEvent);
3003 if (res && dragEvent->isAccepted()) {
3004 QDragManager::self()->setCurrentTarget(w);
3010 dragEvent->m_pos = w->mapToParent(dragEvent->m_pos);
3011 w = w->parentWidget();
3015 case QEvent::DragMove:
3017 case QEvent::DragLeave: {
3018#if QT_CONFIG(graphicsview)
3021 const auto &extra = w->window()->d_func()->extra;
3022 bool isProxyWidget = extra && extra->proxyWidget;
3025 w = qobject_cast<QWidget *>(QDragManager::self()->currentTarget());
3032 if (e->type() == QEvent::DragLeave)
3033 w =
static_cast<QWidget *>(receiver);
3037 if (e->type() == QEvent::DragMove || e->type() == QEvent::Drop) {
3038 QDropEvent *dragEvent =
static_cast<QDropEvent *>(e);
3039 QWidget *origReceiver =
static_cast<QWidget *>(receiver);
3040 while (origReceiver && w != origReceiver) {
3041 dragEvent->m_pos = origReceiver->mapToParent(dragEvent->m_pos);
3042 origReceiver = origReceiver->parentWidget();
3045 res = d->notify_helper(w, e);
3046 if (e->type() != QEvent::DragMove
3047#if QT_CONFIG(graphicsview)
3051 QDragManager::self()->setCurrentTarget(
nullptr, e->type() == QEvent::Drop);
3055 case QEvent::TouchBegin: {
3057 QTouchEvent *touchEvent =
static_cast<QTouchEvent *>(e);
3058 bool eventAccepted = touchEvent->isAccepted();
3059 bool acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
3061 if (acceptTouchEvents && e->spontaneous()
3062 && touchEvent->device()->type() != QInputDevice::DeviceType::TouchPad) {
3063 const QPoint localPos = touchEvent->points()[0].position().toPoint();
3064 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, localPos);
3067#ifndef QT_NO_GESTURES
3068 QPointer<QWidget> gesturePendingWidget;
3073 acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
3074 QMutableTouchEvent::setTarget(touchEvent, w);
3075 touchEvent->setAccepted(acceptTouchEvents);
3076 QPointer<QWidget> p = w;
3077 res = acceptTouchEvents && d->notify_helper(w, touchEvent);
3078 eventAccepted = touchEvent->isAccepted();
3083 w->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, res && eventAccepted);
3085 touchEvent->m_spont =
false;
3086 if (res && eventAccepted) {
3088 d->activateImplicitTouchGrab(w, touchEvent);
3091#ifndef QT_NO_GESTURES
3092 if (gesturePendingWidget.isNull() && w && QGestureManager::gesturePending(w))
3093 gesturePendingWidget = w;
3095 if (!w || w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
3098 const QPoint offset = w->pos();
3099 w = w->parentWidget();
3100 QMutableTouchEvent::setTarget(touchEvent, w);
3101 for (qsizetype cnt = touchEvent->pointCount(), i = 0; i < cnt; ++i) {
3102 auto &pt = touchEvent->point(i);
3103 QMutableEventPoint::setPosition(pt, pt.position() + offset);
3107#ifndef QT_NO_GESTURES
3108 if (!eventAccepted && !gesturePendingWidget.isNull()) {
3111 d->activateImplicitTouchGrab(gesturePendingWidget, touchEvent, QApplicationPrivate::GrabAllPoints);
3115 touchEvent->setAccepted(eventAccepted);
3118 case QEvent::TouchUpdate:
3119 case QEvent::TouchEnd:
3123 if (w->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent))
3124 res = d->notify_helper(w, e);
3126 case QEvent::RequestSoftwareInputPanel:
3127 inputMethod()->show();
3129 case QEvent::CloseSoftwareInputPanel:
3130 inputMethod()->hide();
3133#ifndef QT_NO_GESTURES
3134 case QEvent::NativeGesture:
3137 res = d->notify_helper(w, e);
3138 if (res && e->isAccepted())
3142 w = w->parentWidget();
3145 case QEvent::Gesture:
3146 case QEvent::GestureOverride: {
3147 QGestureEvent *gestureEvent =
static_cast<QGestureEvent *>(e);
3148 QList<QGesture *> allGestures = gestureEvent->gestures();
3150 bool eventAccepted = gestureEvent->isAccepted();
3151 bool wasAccepted = eventAccepted;
3154 QList<QGesture *> gestures;
3155 QWidgetPrivate *wd = w->d_func();
3156 for (
int i = 0; i < allGestures.size();) {
3157 QGesture *g = allGestures.at(i);
3158 Qt::GestureType type = g->gestureType();
3159 QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit =
3160 wd->gestureContext.find(type);
3161 bool deliver = contextit != wd->gestureContext.end() &&
3162 (g->state() == Qt::GestureStarted || w == receiver ||
3163 (contextit.value() & Qt::ReceivePartialGestures));
3165 allGestures.removeAt(i);
3171 if (!gestures.isEmpty()) {
3172 QGestureEvent ge(gestures);
3173 ge.t = gestureEvent->t;
3174 ge.m_spont = gestureEvent->spontaneous();
3175 ge.m_accept = wasAccepted;
3176 ge.m_accepted = gestureEvent->m_accepted;
3177 res = d->notify_helper(w, &ge);
3178 gestureEvent->m_spont =
false;
3179 eventAccepted = ge.isAccepted();
3180 for (QGesture *g : std::as_const(gestures)) {
3183 if (eventAccepted || ge.isAccepted(g)) {
3185 gestureEvent->m_targetWidgets[g->gestureType()] = w;
3186 gestureEvent->setAccepted(g,
true);
3190 allGestures.append(g);
3194 if (allGestures.isEmpty())
3198 w = w->parentWidget();
3200 for (QGesture *g : std::as_const(allGestures))
3201 gestureEvent->setAccepted(g,
false);
3202 gestureEvent->m_accept =
false;
3210 if (w->testAttribute(Qt::WA_AcceptTouchEvents)) {
3211 if (QWindow *window = w->window()->windowHandle()) {
3212 if (
auto *cocoaWindow = window->nativeInterface<QNativeInterface::Private::QCocoaWindow>())
3213 cocoaWindow->enableTrackpadTouchDelivery(e->type() == QEvent::Enter);
3216 res = d->notify_helper(receiver, e);
3220 res = d->notify_helper(receiver, e);
3224 res = d->notify_helper(receiver, e);
3767bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
const QTouchEvent *te)
3769 QApplicationPrivate *d = self;
3771 typedef std::pair<QEventPoint::State, QList<QEventPoint> > StatesAndTouchPoints;
3772 QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents;
3774 const auto *device = te->pointingDevice();
3775 auto touchPoints = te->points();
3776 for (
auto &touchPoint : touchPoints) {
3778 QPointer<QObject> target;
3779 if (touchPoint.state() == QEventPoint::State::Pressed) {
3780 if (device->type() == QInputDevice::DeviceType::TouchPad) {
3783 target = QPointingDevicePrivate::get(device)->firstActiveTarget();
3786 if (target.isNull()) {
3789 window = QApplication::topLevelAt(touchPoint.globalPosition().toPoint());
3792 target = window->childAt(window->mapFromGlobal(touchPoint.globalPosition()));
3797 bool usingClosestWidget =
false;
3798 if (device->type() == QInputDevice::DeviceType::TouchScreen) {
3799 QWidget *closestWidget = d->findClosestTouchPointTarget(device, touchPoint);
3800 QWidget *widget =
static_cast<QWidget *>(target.data());
3802 && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) {
3803 target = closestWidget;
3804 usingClosestWidget =
true;
3810 if (device->type() == QInputDevice::DeviceType::TouchPad || usingClosestWidget)
3811 QMutableEventPoint::setTarget(touchPoint, target);
3813 target = QMutableEventPoint::target(touchPoint);
3817 Q_ASSERT(!target.isNull());
3819 QWidget *targetWidget =
static_cast<QWidget *>(target.data());
3826 if (touchPoints.count() == 1
3827 && device->type() == QInputDevice::DeviceType::TouchPad
3828 && !targetWidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents)
3829 && !targetWidget->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent))
3833 StatesAndTouchPoints &maskAndPoints = widgetsNeedingEvents[targetWidget];
3834 maskAndPoints.first = QEventPoint::State(maskAndPoints.first | touchPoint.state());
3835 maskAndPoints.second.append(touchPoint);
3838 if (widgetsNeedingEvents.isEmpty())
3841 bool accepted =
false;
3842 QHash<QWidget *, StatesAndTouchPoints>::ConstIterator it = widgetsNeedingEvents.constBegin();
3843 const QHash<QWidget *, StatesAndTouchPoints>::ConstIterator end = widgetsNeedingEvents.constEnd();
3844 for (; it != end; ++it) {
3845 const QPointer<QWidget> widget = it.key();
3846 if (!QApplicationPrivate::tryModalHelper(widget,
nullptr))
3849 QEvent::Type eventType;
3850 switch (it.value().first) {
3851 case QEventPoint::State::Pressed:
3852 eventType = QEvent::TouchBegin;
3854 case QEventPoint::State::Released:
3855 eventType = QEvent::TouchEnd;
3857 case QEventPoint::State::Stationary:
3861 eventType = QEvent::TouchUpdate;
3865 QMutableTouchEvent touchEvent(eventType, device, QGuiApplication::keyboardModifiers(),
3867 bool containsPress = updateTouchPointsForWidget(widget, &touchEvent);
3868 touchEvent.setTimestamp(te->timestamp());
3869 touchEvent.setTarget(widget);
3872 widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent);
3874 switch (touchEvent.type()) {
3875 case QEvent::TouchBegin:
3879 bool res = te->spontaneous() ? QApplication::sendSpontaneousEvent(widget, &touchEvent)
3880 : QApplication::sendEvent(widget, &touchEvent);
3881 if (res && touchEvent.isAccepted()) {
3883 if (!widget.isNull())
3884 widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent);
3889 if (widget->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent)
3890#ifndef QT_NO_GESTURES
3891 || QGestureManager::gesturePending(widget)
3894 bool res = te->spontaneous() ? QApplication::sendSpontaneousEvent(widget, &touchEvent)
3895 : QApplication::sendEvent(widget, &touchEvent);
3896 if (res && touchEvent.isAccepted())
3899 if (touchEvent.type() == QEvent::TouchEnd && !widget.isNull())
3900 widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent,
false);