555void QApplicationPrivate::initializeWidgetFontHash()
557 const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme();
560 FontHash *fontHash = app_fonts();
563 if (
const QFont *font = theme->font(QPlatformTheme::MenuFont))
564 fontHash->insert(QByteArrayLiteral(
"QMenu"), *font);
565 if (
const QFont *font = theme->font(QPlatformTheme::MenuBarFont))
566 fontHash->insert(QByteArrayLiteral(
"QMenuBar"), *font);
567 if (
const QFont *font = theme->font(QPlatformTheme::MenuItemFont))
568 fontHash->insert(QByteArrayLiteral(
"QMenuItem"), *font);
569 if (
const QFont *font = theme->font(QPlatformTheme::MessageBoxFont))
570 fontHash->insert(QByteArrayLiteral(
"QMessageBox"), *font);
571 if (
const QFont *font = theme->font(QPlatformTheme::LabelFont))
572 fontHash->insert(QByteArrayLiteral(
"QLabel"), *font);
573 if (
const QFont *font = theme->font(QPlatformTheme::TipLabelFont))
574 fontHash->insert(QByteArrayLiteral(
"QTipLabel"), *font);
575 if (
const QFont *font = theme->font(QPlatformTheme::TitleBarFont))
576 fontHash->insert(QByteArrayLiteral(
"QTitleBar"), *font);
577 if (
const QFont *font = theme->font(QPlatformTheme::StatusBarFont))
578 fontHash->insert(QByteArrayLiteral(
"QStatusBar"), *font);
579 if (
const QFont *font = theme->font(QPlatformTheme::MdiSubWindowTitleFont))
580 fontHash->insert(QByteArrayLiteral(
"QMdiSubWindowTitleBar"), *font);
581 if (
const QFont *font = theme->font(QPlatformTheme::DockWidgetTitleFont))
582 fontHash->insert(QByteArrayLiteral(
"QDockWidgetTitle"), *font);
583 if (
const QFont *font = theme->font(QPlatformTheme::PushButtonFont))
584 fontHash->insert(QByteArrayLiteral(
"QPushButton"), *font);
585 if (
const QFont *font = theme->font(QPlatformTheme::CheckBoxFont))
586 fontHash->insert(QByteArrayLiteral(
"QCheckBox"), *font);
587 if (
const QFont *font = theme->font(QPlatformTheme::RadioButtonFont))
588 fontHash->insert(QByteArrayLiteral(
"QRadioButton"), *font);
589 if (
const QFont *font = theme->font(QPlatformTheme::ToolButtonFont))
590 fontHash->insert(QByteArrayLiteral(
"QToolButton"), *font);
591 if (
const QFont *font = theme->font(QPlatformTheme::ItemViewFont))
592 fontHash->insert(QByteArrayLiteral(
"QAbstractItemView"), *font);
593 if (
const QFont *font = theme->font(QPlatformTheme::ListViewFont))
594 fontHash->insert(QByteArrayLiteral(
"QListView"), *font);
595 if (
const QFont *font = theme->font(QPlatformTheme::HeaderViewFont))
596 fontHash->insert(QByteArrayLiteral(
"QHeaderView"), *font);
597 if (
const QFont *font = theme->font(QPlatformTheme::ListBoxFont))
598 fontHash->insert(QByteArrayLiteral(
"QListBox"), *font);
599 if (
const QFont *font = theme->font(QPlatformTheme::ComboMenuItemFont))
600 fontHash->insert(QByteArrayLiteral(
"QComboMenuItem"), *font);
601 if (
const QFont *font = theme->font(QPlatformTheme::ComboLineEditFont))
602 fontHash->insert(QByteArrayLiteral(
"QComboLineEdit"), *font);
603 if (
const QFont *font = theme->font(QPlatformTheme::SmallFont))
604 fontHash->insert(QByteArrayLiteral(
"QSmallFont"), *font);
605 if (
const QFont *font = theme->font(QPlatformTheme::MiniFont))
606 fontHash->insert(QByteArrayLiteral(
"QMiniFont"), *font);
1823void QApplicationPrivate::setActiveWindow(QWidget* act)
1825 QWidget* window = act?act->window():
nullptr;
1827 if (QApplicationPrivate::active_window == window)
1830#if QT_CONFIG(graphicsview)
1831 if (window && window->graphicsProxyWidget()) {
1837 QWidgetList toBeActivated;
1838 QWidgetList toBeDeactivated;
1840 if (QApplicationPrivate::active_window) {
1841 if (QApplication::style()->styleHint(QStyle::SH_Widget_ShareActivation,
nullptr, QApplicationPrivate::active_window)) {
1842 const QWidgetList list = QApplication::topLevelWidgets();
1843 for (
auto *w : list) {
1844 if (w->isVisible() && w->isActiveWindow())
1845 toBeDeactivated.append(w);
1848 toBeDeactivated.append(QApplicationPrivate::active_window);
1852 if (QApplicationPrivate::focus_widget) {
1853 if (QApplicationPrivate::focus_widget->testAttribute(Qt::WA_InputMethodEnabled))
1854 QGuiApplication::inputMethod()->commit();
1856 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange, Qt::ActiveWindowFocusReason);
1857 QCoreApplication::sendEvent(QApplicationPrivate::focus_widget, &focusAboutToChange);
1860 QApplicationPrivate::active_window = window;
1862 if (QApplicationPrivate::active_window) {
1863 if (QApplication::style()->styleHint(QStyle::SH_Widget_ShareActivation,
nullptr, QApplicationPrivate::active_window)) {
1864 const QWidgetList list = QApplication::topLevelWidgets();
1865 for (
auto *w : list) {
1866 if (w->isVisible() && w->isActiveWindow())
1867 toBeActivated.append(w);
1870 toBeActivated.append(QApplicationPrivate::active_window);
1876 QEvent activationChange(QEvent::ActivationChange);
1877 QEvent windowActivate(QEvent::WindowActivate);
1878 QEvent windowDeactivate(QEvent::WindowDeactivate);
1880 for (QWidget *w : std::as_const(toBeActivated)) {
1881 QApplication::sendSpontaneousEvent(w, &windowActivate);
1882 QApplication::sendSpontaneousEvent(w, &activationChange);
1885 for (QWidget *w : std::as_const(toBeDeactivated)) {
1886 QApplication::sendSpontaneousEvent(w, &windowDeactivate);
1887 QApplication::sendSpontaneousEvent(w, &activationChange);
1890 if (!inPopupMode()) {
1892 if (!QApplicationPrivate::active_window && QApplicationPrivate::focus_widget) {
1893 QApplicationPrivate::setFocusWidget(
nullptr, Qt::ActiveWindowFocusReason);
1894 }
else if (QApplicationPrivate::active_window) {
1895 QWidget *w = QApplicationPrivate::active_window->focusWidget();
1896 if (w && w->isVisible() )
1897 w->setFocus(Qt::ActiveWindowFocusReason);
1899 w = QApplicationPrivate::focusNextPrevChild_helper(QApplicationPrivate::active_window,
true);
1901 w->setFocus(Qt::ActiveWindowFocusReason);
1903 w = QApplicationPrivate::focus_widget;
1904 if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus) {
1905 QApplicationPrivate::active_window->setFocus(Qt::ActiveWindowFocusReason);
1906 }
else if (!QApplicationPrivate::active_window->isAncestorOf(w)) {
1908 QApplicationPrivate::setFocusWidget(
nullptr, Qt::ActiveWindowFocusReason);
2044void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave,
const QPointF &globalPosF)
2046 if ((!enter && !leave) || (enter == leave))
2049 QWidgetList leaveList;
2050 QWidgetList enterList;
2052 bool sameWindow = leave && enter && leave->window() == enter->window();
2053 if (leave && !sameWindow) {
2056 leaveList.append(w);
2057 }
while (!w->isWindow() && (w = w->parentWidget()));
2059 if (enter && !sameWindow) {
2062 enterList.append(w);
2063 }
while (!w->isWindow() && (w = w->parentWidget()));
2069 while (!e->isWindow() && (e = e->parentWidget()))
2072 while (!l->isWindow() && (l = l->parentWidget()))
2074 QWidget* wenter = enter;
2075 QWidget* wleave = leave;
2076 while (enterDepth > leaveDepth) {
2077 wenter = wenter->parentWidget();
2080 while (leaveDepth > enterDepth) {
2081 wleave = wleave->parentWidget();
2084 while (!wenter->isWindow() && wenter != wleave) {
2085 wenter = wenter->parentWidget();
2086 wleave = wleave->parentWidget();
2089 for (
auto *w = leave; w != wleave; w = w->parentWidget())
2090 leaveList.append(w);
2092 for (
auto *w = enter; w != wenter; w = w->parentWidget())
2093 enterList.append(w);
2096 QEvent leaveEvent(QEvent::Leave);
2097 for (QWidget *w : std::as_const(leaveList)) {
2098 if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w,
nullptr)) {
2099 QCoreApplication::sendEvent(w, &leaveEvent);
2100 if (w->testAttribute(Qt::WA_Hover) &&
2101 (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
2102 Q_ASSERT(instance());
2103 QHoverEvent he(QEvent::HoverLeave, QPointF(-1, -1), globalPosF, w->mapFromGlobal(globalPosF),
2104 QGuiApplication::keyboardModifiers());
2105 qApp->d_func()->notify_helper(w, &he);
2109 if (!enterList.isEmpty()) {
2111 const QPointF globalPos = qIsInf(globalPosF.x())
2114 const QPointF windowPos = std::as_const(enterList).back()->window()->mapFromGlobal(globalPos);
2115 for (
auto it = enterList.crbegin(), end = enterList.crend(); it != end; ++it) {
2117 if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w,
nullptr)) {
2118 const QPointF localPos = w->mapFromGlobal(globalPos);
2119 QEnterEvent enterEvent(localPos, windowPos, globalPos);
2120 QCoreApplication::sendEvent(w, &enterEvent);
2121 if (w->testAttribute(Qt::WA_Hover) &&
2122 (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
2123 QHoverEvent he(QEvent::HoverEnter, windowPos, QPointF(-1, -1), globalPos,
2124 QGuiApplication::keyboardModifiers());
2125 QMutableEventPoint::setPosition(he.point(0), localPos);
2126 qApp->d_func()->notify_helper(w, &he);
2135 const bool enterOnAlien = (enter && (isAlien(enter) || enter->testAttribute(Qt::WA_DontShowOnScreen)));
2138 QWidget *parentOfLeavingCursor =
nullptr;
2139 for (QWidget *w : std::as_const(leaveList)) {
2142 if (w->testAttribute(Qt::WA_SetCursor)) {
2143 QWidget *parent = w->parentWidget();
2144 while (parent && parent->d_func()->data.in_destructor)
2145 parent = parent->parentWidget();
2146 parentOfLeavingCursor = parent;
2152 if (parentOfLeavingCursor && (!enterOnAlien
2153 || parentOfLeavingCursor->effectiveWinId() != enter->effectiveWinId())) {
2154#if QT_CONFIG(graphicsview)
2155 if (!parentOfLeavingCursor->window()->graphicsProxyWidget())
2158 qt_qpa_set_cursor(parentOfLeavingCursor,
true);
2162 QWidget *cursorWidget = enter;
2163 while (!cursorWidget->isWindow() && !cursorWidget->isEnabled())
2164 cursorWidget = cursorWidget->parentWidget();
2169#if QT_CONFIG(graphicsview)
2170 if (cursorWidget->window()->graphicsProxyWidget()) {
2171 QWidgetPrivate::nearestGraphicsProxyWidget(cursorWidget)->setCursor(cursorWidget->cursor());
2175 qt_qpa_set_cursor(cursorWidget,
true);
2555bool QApplication::notify(QObject *receiver, QEvent *e)
2559 if (QApplicationPrivate::is_app_closing)
2562 if (Q_UNLIKELY(!receiver)) {
2563 qWarning(
"QApplication::notify: Unexpected null receiver");
2567 QCoreApplicationPrivate::checkReceiverThread(receiver,
"QApplication::notify");
2569 const bool isWindowType = receiver->isWindowType();
2570 const bool isWidgetType = receiver->isWidgetType();
2572 && QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(receiver), e)) {
2576 QGuiApplicationPrivate::captureGlobalModifierState(e);
2578#ifndef QT_NO_GESTURES
2580 if (d->gestureManager) {
2581 switch (e->type()) {
2583 case QEvent::MetaCall:
2584 case QEvent::DeferredDelete:
2585 case QEvent::DragEnter:
case QEvent::DragMove:
case QEvent::DragLeave:
2586 case QEvent::Drop:
case QEvent::DragResponse:
2587 case QEvent::ChildAdded:
case QEvent::ChildPolished:
2588 case QEvent::ChildRemoved:
2589 case QEvent::UpdateRequest:
2590 case QEvent::UpdateLater:
2591 case QEvent::LocaleChange:
2593 case QEvent::IconDrag:
2594 case QEvent::StyleChange:
2595 case QEvent::GraphicsSceneDragEnter:
2596 case QEvent::GraphicsSceneDragMove:
2597 case QEvent::GraphicsSceneDragLeave:
2598 case QEvent::GraphicsSceneDrop:
2599 case QEvent::DynamicPropertyChange:
2600 case QEvent::NetworkReplyUpdated:
2603 if (d->gestureManager->thread() == QThread::currentThread()) {
2605 if (d->gestureManager->filterEvent(
static_cast<QWidget *>(receiver), e))
2611 if (d->gestureManager->filterEvent(receiver, e))
2620 switch (e->type()) {
2621 case QEvent::ApplicationDeactivate:
2622 case QEvent::OrientationChange:
2626 d->closeAllPopups();
2629 case QEvent::ActivationChange:
2630 case QEvent::KeyPress:
2631 case QEvent::KeyRelease:
2632 case QEvent::FocusOut:
2633 case QEvent::FocusIn:
2634 case QEvent::MouseButtonPress:
2635 case QEvent::MouseButtonRelease:
2636 case QEvent::MouseButtonDblClick:
2637 d->toolTipFallAsleep.stop();
2640 d->toolTipWakeUp.stop();
2646 switch (e->type()) {
2647 case QEvent::KeyPress: {
2648 QKeyEvent* keyEvent =
static_cast<QKeyEvent*>(e);
2649 const int key = keyEvent->key();
2654 if (!e->spontaneous() && isWidgetType
2655 && qt_sendShortcutOverrideEvent(
static_cast<QWidget *>(receiver), keyEvent->timestamp(),
2656 key, keyEvent->modifiers(), keyEvent->text(),
2657 keyEvent->isAutoRepeat(), keyEvent->count())) {
2660 qt_in_tab_key_event = (key == Qt::Key_Backtab
2661 || key == Qt::Key_Tab
2662 || key == Qt::Key_Left
2663 || key == Qt::Key_Up
2664 || key == Qt::Key_Right
2665 || key == Qt::Key_Down);
2674 QWidget * w =
static_cast<QWidget *>(receiver);
2675 switch (e->type()) {
2676 case QEvent::ShortcutOverride:
2677 case QEvent::KeyPress:
2678 case QEvent::KeyRelease: {
2679 QKeyEvent* key =
static_cast<QKeyEvent*>(e);
2680 bool def = key->isAccepted();
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693 QPointer<QObject> pr = receiver;
2699 res = d->notify_helper(w, e);
2701 if (res && key->isAccepted())
2703 if (!pr || w->isWindow())
2706 w = w->parentWidget();
2708 qt_in_tab_key_event =
false;
2711 case QEvent::MouseButtonPress:
2712 case QEvent::MouseButtonRelease:
2713 case QEvent::MouseButtonDblClick:
2714 case QEvent::MouseMove: {
2715 QMouseEvent* mouse =
static_cast<QMouseEvent*>(e);
2716 QPoint relpos = mouse->position().toPoint();
2718 if (e->spontaneous()) {
2719 if (e->type() != QEvent::MouseMove)
2720 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos);
2729 if (e->type() == QEvent::MouseMove && mouse->buttons() == 0
2730 && w->rect().contains(relpos)) {
2731 d->toolTipWidget = w;
2732 d->toolTipPos = relpos;
2733 d->toolTipGlobalPos = mouse->globalPosition().toPoint();
2734 QStyle *s = d->toolTipWidget->style();
2735 int wakeDelay = s->styleHint(QStyle::SH_ToolTip_WakeUpDelay,
nullptr, d->toolTipWidget,
nullptr);
2736 d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive() ? 20 : wakeDelay,
this);
2740 bool eventAccepted = mouse->isAccepted();
2742 QPointer<QWidget> pw = w;
2744 QMouseEvent me(mouse->type(), relpos, mouse->scenePosition(), mouse->globalPosition(),
2745 mouse->button(), mouse->buttons(), mouse->modifiers(), mouse->source(),
2746 mouse->pointingDevice());
2747 me.m_spont = mouse->spontaneous();
2748 me.setTimestamp(mouse->timestamp());
2749 QMutableSinglePointEvent::setDoubleClick(&me, QMutableSinglePointEvent::isDoubleClick(mouse));
2751 if (!w->hasMouseTracking()
2752 && mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
2754 d->sendThroughApplicationEventFilters(w, w == receiver ? mouse : &me);
2757 w->setAttribute(Qt::WA_NoMouseReplay,
false);
2758 res = d->notify_helper(w, w == receiver ? mouse : &me);
2761 eventAccepted = (w == receiver ? mouse : &me)->isAccepted();
2762 if (res && eventAccepted)
2764 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2767 w = w->parentWidget();
2770 mouse->setAccepted(eventAccepted);
2772 if (e->type() == QEvent::MouseMove) {
2776 w =
static_cast<QWidget *>(receiver);
2777 relpos = mouse->position().toPoint();
2778 QPoint diff = relpos - w->mapFromGlobal(mouse->globalPosition()).toPoint();
2780 if (w->testAttribute(Qt::WA_Hover) &&
2781 (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
2782 QHoverEvent he(QEvent::HoverMove, mouse->scenePosition(), mouse->globalPosition(), relpos - diff, mouse->modifiers());
2783 QMutableEventPoint::setPosition(he.point(0), relpos);
2784 d->notify_helper(w, &he);
2786 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2789 w = w->parentWidget();
2794#if QT_CONFIG(wheelevent)
2795 case QEvent::Wheel: {
2797 if (
const QWidget *popup = QApplication::activePopupWidget()) {
2798 if (w->window() != popup)
2802 QWheelEvent* wheel =
static_cast<QWheelEvent*>(e);
2803 if (!wheel->spontaneous()) {
2805
2806
2807
2808
2809 res = d->notify_helper(w, wheel);
2813 const Qt::ScrollPhase phase = wheel->phase();
2814 QPointF relpos = wheel->position();
2837 if (QApplicationPrivate::wheel_widget) {
2838 Q_ASSERT(phase != Qt::NoScrollPhase);
2839 w = QApplicationPrivate::wheel_widget;
2840 relpos = w->mapFromGlobal(wheel->globalPosition());
2843
2844
2845
2846
2849 QApplicationPrivate::wheel_widget =
nullptr;
2851 case Qt::ScrollBegin:
2852 QApplicationPrivate::wheel_widget = w;
2854 case Qt::ScrollUpdate:
2855 case Qt::ScrollMomentum:
2856 if (!QApplicationPrivate::wheel_widget)
2857 QApplicationPrivate::wheel_widget = w;
2859 case Qt::NoScrollPhase:
2860 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos.toPoint());
2865 QWheelEvent we(relpos, wheel->globalPosition(), wheel->pixelDelta(), wheel->angleDelta(), wheel->buttons(),
2866 wheel->modifiers(), phase, wheel->inverted(), wheel->source(), wheel->pointingDevice());
2868 we.setTimestamp(wheel->timestamp());
2873 we.setAccepted(
true);
2874 we.m_spont = wheel->spontaneous() && w == receiver;
2875 res = d->notify_helper(w, &we);
2876 eventAccepted = we.isAccepted();
2877 if (res && eventAccepted)
2879 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2882 QMutableEventPoint::setPosition(we.point(0), we.position() + w->pos());
2883 w = w->parentWidget();
2885 wheel->setAccepted(eventAccepted);
2889#ifndef QT_NO_CONTEXTMENU
2890 case QEvent::ContextMenu: {
2891 QContextMenuEvent *context =
static_cast<QContextMenuEvent*>(e);
2892 QPoint relpos = context->pos();
2893 bool eventAccepted = context->isAccepted();
2895 QContextMenuEvent ce(context->reason(), relpos, context->globalPos(), context->modifiers());
2896 ce.m_spont = e->spontaneous();
2897 res = d->notify_helper(w, w == receiver ? context : &ce);
2898 eventAccepted = ((w == receiver) ? context : &ce)->isAccepted();
2901 if (res && eventAccepted)
2903 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2907 w = w->parentWidget();
2909 context->setAccepted(eventAccepted);
2913#if QT_CONFIG(tabletevent)
2914 case QEvent::TabletMove:
2915 case QEvent::TabletPress:
2916 case QEvent::TabletRelease: {
2917 QTabletEvent *tablet =
static_cast<QTabletEvent*>(e);
2918 QPointF relpos = tablet->position();
2919 bool eventAccepted = tablet->isAccepted();
2921 QTabletEvent te(tablet->type(), tablet->pointingDevice(), relpos, tablet->globalPosition(),
2922 tablet->pressure(), tablet->xTilt(), tablet->yTilt(),
2923 tablet->tangentialPressure(), tablet->rotation(), tablet->z(),
2924 tablet->modifiers(), tablet->button(), tablet->buttons());
2925 te.m_spont = e->spontaneous();
2926 te.setTimestamp(tablet->timestamp());
2927 te.setAccepted(
false);
2928 res = d->notify_helper(w, w == receiver ? tablet : &te);
2929 eventAccepted = ((w == receiver) ? tablet : &te)->isAccepted();
2931 if (res && eventAccepted)
2933 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2937 w = w->parentWidget();
2939 tablet->setAccepted(eventAccepted);
2944#if QT_CONFIG(tooltip) || QT_CONFIG(whatsthis)
2945 case QEvent::ToolTip:
2946 case QEvent::WhatsThis:
2947 case QEvent::QueryWhatsThis: {
2948 QHelpEvent *help =
static_cast<QHelpEvent*>(e);
2949 QPoint relpos = help->pos();
2950 bool eventAccepted = help->isAccepted();
2952 QHelpEvent he(help->type(), relpos, help->globalPos());
2953 he.m_spont = e->spontaneous();
2954 res = d->notify_helper(w, w == receiver ? help : &he);
2956 eventAccepted = (w == receiver ? help : &he)->isAccepted();
2957 if (res && eventAccepted)
2963 w = w->parentWidget();
2965 help->setAccepted(eventAccepted);
2969#if QT_CONFIG(statustip) || QT_CONFIG(whatsthis)
2970 case QEvent::StatusTip:
2971 case QEvent::WhatsThisClicked:
2973 res = d->notify_helper(w, e);
2974 if (res && e->isAccepted())
2978 w = w->parentWidget();
2983#if QT_CONFIG(draganddrop)
2984 case QEvent::DragEnter: {
2985 QDragEnterEvent *dragEvent =
static_cast<QDragEnterEvent *>(e);
2986#if QT_CONFIG(graphicsview)
2989 const auto &extra = w->window()->d_func()->extra;
2990 if (extra && extra->proxyWidget) {
2991 res = d->notify_helper(w, dragEvent);
2996 if (w->isEnabled() && w->acceptDrops()) {
2997 res = d->notify_helper(w, dragEvent);
2998 if (res && dragEvent->isAccepted()) {
2999 QDragManager::self()->setCurrentTarget(w);
3005 dragEvent->m_pos = w->mapToParent(dragEvent->m_pos);
3006 w = w->parentWidget();
3010 case QEvent::DragMove:
3012 case QEvent::DragLeave: {
3013#if QT_CONFIG(graphicsview)
3016 const auto &extra = w->window()->d_func()->extra;
3017 bool isProxyWidget = extra && extra->proxyWidget;
3020 w = qobject_cast<QWidget *>(QDragManager::self()->currentTarget());
3027 if (e->type() == QEvent::DragLeave)
3028 w =
static_cast<QWidget *>(receiver);
3032 if (e->type() == QEvent::DragMove || e->type() == QEvent::Drop) {
3033 QDropEvent *dragEvent =
static_cast<QDropEvent *>(e);
3034 QWidget *origReceiver =
static_cast<QWidget *>(receiver);
3035 while (origReceiver && w != origReceiver) {
3036 dragEvent->m_pos = origReceiver->mapToParent(dragEvent->m_pos);
3037 origReceiver = origReceiver->parentWidget();
3040 res = d->notify_helper(w, e);
3041 if (e->type() != QEvent::DragMove
3042#if QT_CONFIG(graphicsview)
3046 QDragManager::self()->setCurrentTarget(
nullptr, e->type() == QEvent::Drop);
3050 case QEvent::TouchBegin: {
3052 QTouchEvent *touchEvent =
static_cast<QTouchEvent *>(e);
3053 bool eventAccepted = touchEvent->isAccepted();
3054 bool acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
3056 if (acceptTouchEvents && e->spontaneous()
3057 && touchEvent->device()->type() != QInputDevice::DeviceType::TouchPad) {
3058 const QPoint localPos = touchEvent->points()[0].position().toPoint();
3059 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, localPos);
3062#ifndef QT_NO_GESTURES
3063 QPointer<QWidget> gesturePendingWidget;
3068 acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
3069 QMutableTouchEvent::setTarget(touchEvent, w);
3070 touchEvent->setAccepted(acceptTouchEvents);
3071 QPointer<QWidget> p = w;
3072 res = acceptTouchEvents && d->notify_helper(w, touchEvent);
3073 eventAccepted = touchEvent->isAccepted();
3078 w->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, res && eventAccepted);
3080 touchEvent->m_spont =
false;
3081 if (res && eventAccepted) {
3083 d->activateImplicitTouchGrab(w, touchEvent);
3086#ifndef QT_NO_GESTURES
3087 if (gesturePendingWidget.isNull() && w && QGestureManager::gesturePending(w))
3088 gesturePendingWidget = w;
3090 if (!w || w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
3093 const QPoint offset = w->pos();
3094 w = w->parentWidget();
3095 QMutableTouchEvent::setTarget(touchEvent, w);
3096 for (qsizetype cnt = touchEvent->pointCount(), i = 0; i < cnt; ++i) {
3097 auto &pt = touchEvent->point(i);
3098 QMutableEventPoint::setPosition(pt, pt.position() + offset);
3102#ifndef QT_NO_GESTURES
3103 if (!eventAccepted && !gesturePendingWidget.isNull()) {
3106 d->activateImplicitTouchGrab(gesturePendingWidget, touchEvent, QApplicationPrivate::GrabAllPoints);
3110 touchEvent->setAccepted(eventAccepted);
3113 case QEvent::TouchUpdate:
3114 case QEvent::TouchEnd:
3118 if (w->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent))
3119 res = d->notify_helper(w, e);
3121 case QEvent::RequestSoftwareInputPanel:
3122 inputMethod()->show();
3124 case QEvent::CloseSoftwareInputPanel:
3125 inputMethod()->hide();
3128#ifndef QT_NO_GESTURES
3129 case QEvent::NativeGesture:
3132 res = d->notify_helper(w, e);
3133 if (res && e->isAccepted())
3137 w = w->parentWidget();
3140 case QEvent::Gesture:
3141 case QEvent::GestureOverride: {
3142 QGestureEvent *gestureEvent =
static_cast<QGestureEvent *>(e);
3143 QList<QGesture *> allGestures = gestureEvent->gestures();
3145 bool eventAccepted = gestureEvent->isAccepted();
3146 bool wasAccepted = eventAccepted;
3149 QList<QGesture *> gestures;
3150 QWidgetPrivate *wd = w->d_func();
3151 for (
int i = 0; i < allGestures.size();) {
3152 QGesture *g = allGestures.at(i);
3153 Qt::GestureType type = g->gestureType();
3154 QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit =
3155 wd->gestureContext.find(type);
3156 bool deliver = contextit != wd->gestureContext.end() &&
3157 (g->state() == Qt::GestureStarted || w == receiver ||
3158 (contextit.value() & Qt::ReceivePartialGestures));
3160 allGestures.removeAt(i);
3166 if (!gestures.isEmpty()) {
3167 QGestureEvent ge(gestures);
3168 ge.t = gestureEvent->t;
3169 ge.m_spont = gestureEvent->spontaneous();
3170 ge.m_accept = wasAccepted;
3171 ge.m_accepted = gestureEvent->m_accepted;
3172 res = d->notify_helper(w, &ge);
3173 gestureEvent->m_spont =
false;
3174 eventAccepted = ge.isAccepted();
3175 for (QGesture *g : std::as_const(gestures)) {
3178 if (eventAccepted || ge.isAccepted(g)) {
3180 gestureEvent->m_targetWidgets[g->gestureType()] = w;
3181 gestureEvent->setAccepted(g,
true);
3185 allGestures.append(g);
3189 if (allGestures.isEmpty())
3193 w = w->parentWidget();
3195 for (QGesture *g : std::as_const(allGestures))
3196 gestureEvent->setAccepted(g,
false);
3197 gestureEvent->m_accept =
false;
3205 if (w->testAttribute(Qt::WA_AcceptTouchEvents)) {
3206 if (QWindow *window = w->window()->windowHandle()) {
3207 if (
auto *cocoaWindow = window->nativeInterface<QNativeInterface::Private::QCocoaWindow>())
3208 cocoaWindow->enableTrackpadTouchDelivery(e->type() == QEvent::Enter);
3211 res = d->notify_helper(receiver, e);
3215 res = d->notify_helper(receiver, e);
3219 res = d->notify_helper(receiver, e);
3762bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
const QTouchEvent *te)
3764 QApplicationPrivate *d = self;
3766 typedef std::pair<QEventPoint::State, QList<QEventPoint> > StatesAndTouchPoints;
3767 QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents;
3769 const auto *device = te->pointingDevice();
3770 auto touchPoints = te->points();
3771 for (
auto &touchPoint : touchPoints) {
3773 QPointer<QObject> target;
3774 if (touchPoint.state() == QEventPoint::State::Pressed) {
3775 if (device->type() == QInputDevice::DeviceType::TouchPad) {
3778 target = QPointingDevicePrivate::get(device)->firstActiveTarget();
3781 if (target.isNull()) {
3784 window = QApplication::topLevelAt(touchPoint.globalPosition().toPoint());
3787 target = window->childAt(window->mapFromGlobal(touchPoint.globalPosition()));
3792 bool usingClosestWidget =
false;
3793 if (device->type() == QInputDevice::DeviceType::TouchScreen) {
3794 QWidget *closestWidget = d->findClosestTouchPointTarget(device, touchPoint);
3795 QWidget *widget =
static_cast<QWidget *>(target.data());
3797 && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) {
3798 target = closestWidget;
3799 usingClosestWidget =
true;
3805 if (device->type() == QInputDevice::DeviceType::TouchPad || usingClosestWidget)
3806 QMutableEventPoint::setTarget(touchPoint, target);
3808 target = QMutableEventPoint::target(touchPoint);
3812 Q_ASSERT(!target.isNull());
3814 QWidget *targetWidget =
static_cast<QWidget *>(target.data());
3821 if (touchPoints.count() == 1
3822 && device->type() == QInputDevice::DeviceType::TouchPad
3823 && !targetWidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents)
3824 && !targetWidget->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent))
3828 StatesAndTouchPoints &maskAndPoints = widgetsNeedingEvents[targetWidget];
3829 maskAndPoints.first = QEventPoint::State(maskAndPoints.first | touchPoint.state());
3830 maskAndPoints.second.append(touchPoint);
3833 if (widgetsNeedingEvents.isEmpty())
3836 bool accepted =
false;
3837 QHash<QWidget *, StatesAndTouchPoints>::ConstIterator it = widgetsNeedingEvents.constBegin();
3838 const QHash<QWidget *, StatesAndTouchPoints>::ConstIterator end = widgetsNeedingEvents.constEnd();
3839 for (; it != end; ++it) {
3840 const QPointer<QWidget> widget = it.key();
3841 if (!QApplicationPrivate::tryModalHelper(widget,
nullptr))
3844 QEvent::Type eventType;
3845 switch (it.value().first) {
3846 case QEventPoint::State::Pressed:
3847 eventType = QEvent::TouchBegin;
3849 case QEventPoint::State::Released:
3850 eventType = QEvent::TouchEnd;
3852 case QEventPoint::State::Stationary:
3856 eventType = QEvent::TouchUpdate;
3860 QMutableTouchEvent touchEvent(eventType, device, QGuiApplication::keyboardModifiers(),
3862 bool containsPress = updateTouchPointsForWidget(widget, &touchEvent);
3863 touchEvent.setTimestamp(te->timestamp());
3864 touchEvent.setTarget(widget);
3867 widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent);
3869 switch (touchEvent.type()) {
3870 case QEvent::TouchBegin:
3874 bool res = te->spontaneous() ? QApplication::sendSpontaneousEvent(widget, &touchEvent)
3875 : QApplication::sendEvent(widget, &touchEvent);
3876 if (res && touchEvent.isAccepted()) {
3878 if (!widget.isNull())
3879 widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent);
3884 if (widget->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent)
3885#ifndef QT_NO_GESTURES
3886 || QGestureManager::gesturePending(widget)
3889 bool res = te->spontaneous() ? QApplication::sendSpontaneousEvent(widget, &touchEvent)
3890 : QApplication::sendEvent(widget, &touchEvent);
3891 if (res && touchEvent.isAccepted())
3894 if (touchEvent.type() == QEvent::TouchEnd && !widget.isNull())
3895 widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent,
false);