| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qwidgetwindow.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "private/qwindow_p.h" | - | ||||||||||||
| 41 | #include "qwidgetwindow_p.h" | - | ||||||||||||
| 42 | #include "qlayout.h" | - | ||||||||||||
| 43 | - | |||||||||||||
| 44 | #include "private/qwidget_p.h" | - | ||||||||||||
| 45 | #include "private/qapplication_p.h" | - | ||||||||||||
| 46 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||
| 47 | #include <QtGui/qaccessible.h> | - | ||||||||||||
| 48 | #endif | - | ||||||||||||
| 49 | #include <private/qwidgetbackingstore_p.h> | - | ||||||||||||
| 50 | #include <qpa/qwindowsysteminterface_p.h> | - | ||||||||||||
| 51 | #include <qpa/qplatformtheme.h> | - | ||||||||||||
| 52 | #include <qpa/qplatformwindow.h> | - | ||||||||||||
| 53 | #include <private/qgesturemanager_p.h> | - | ||||||||||||
| 54 | #include <private/qhighdpiscaling_p.h> | - | ||||||||||||
| 55 | - | |||||||||||||
| 56 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 57 | - | |||||||||||||
| 58 | Q_WIDGETS_EXPORT extern bool qt_tab_all_widgets(); | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | QWidget *qt_button_down = 0; // widget got last button-down | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | // popup control | - | ||||||||||||
| 63 | QWidget *qt_popup_down = 0; // popup that contains the pressed widget | - | ||||||||||||
| 64 | extern int openPopupCount; | - | ||||||||||||
| 65 | bool qt_replay_popup_mouse_event = false; | - | ||||||||||||
| 66 | extern bool qt_try_modal(QWidget *widget, QEvent::Type type); | - | ||||||||||||
| 67 | - | |||||||||||||
| 68 | class QWidgetWindowPrivate : public QWindowPrivate | - | ||||||||||||
| 69 | { | - | ||||||||||||
| 70 | Q_DECLARE_PUBLIC(QWidgetWindow) | - | ||||||||||||
| 71 | public: | - | ||||||||||||
| 72 | QWindow *eventReceiver() Q_DECL_OVERRIDE { | - | ||||||||||||
| 73 | Q_Q(QWidgetWindow); | - | ||||||||||||
| 74 | QWindow *w = q; | - | ||||||||||||
| 75 | while (w->parent() && qobject_cast<QWidgetWindow *>(w) && qobject_cast<QWidgetWindow *>(w->parent())) { | - | ||||||||||||
| 76 | w = w->parent(); | - | ||||||||||||
| 77 | } | - | ||||||||||||
| 78 | return w; | - | ||||||||||||
| 79 | } | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | void clearFocusObject() Q_DECL_OVERRIDE | - | ||||||||||||
| 82 | { | - | ||||||||||||
| 83 | Q_Q(QWidgetWindow); | - | ||||||||||||
| 84 | QWidget *widget = q->widget(); | - | ||||||||||||
| 85 | if (widget && widget->focusWidget()) | - | ||||||||||||
| 86 | widget->focusWidget()->clearFocus(); | - | ||||||||||||
| 87 | } | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | QRectF closestAcceptableGeometry(const QRectF &rect) const Q_DECL_OVERRIDE; | - | ||||||||||||
| 90 | }; | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | QRectF QWidgetWindowPrivate::closestAcceptableGeometry(const QRectF &rect) const | - | ||||||||||||
| 93 | { | - | ||||||||||||
| 94 | Q_Q(const QWidgetWindow); | - | ||||||||||||
| 95 | const QWidget *widget = q->widget(); | - | ||||||||||||
| 96 | if (!widget || !widget->isWindow() || !widget->hasHeightForWidth()) | - | ||||||||||||
| 97 | return QRect(); | - | ||||||||||||
| 98 | const QSize oldSize = rect.size().toSize(); | - | ||||||||||||
| 99 | const QSize newSize = QLayout::closestAcceptableSize(widget, oldSize); | - | ||||||||||||
| 100 | if (newSize == oldSize) | - | ||||||||||||
| 101 | return QRectF(); | - | ||||||||||||
| 102 | const int dw = newSize.width() - oldSize.width(); | - | ||||||||||||
| 103 | const int dh = newSize.height() - oldSize.height(); | - | ||||||||||||
| 104 | QRectF result = rect; | - | ||||||||||||
| 105 | const QRectF currentGeometry(widget->geometry()); | - | ||||||||||||
| 106 | const qreal topOffset = result.top() - currentGeometry.top(); | - | ||||||||||||
| 107 | const qreal bottomOffset = result.bottom() - currentGeometry.bottom(); | - | ||||||||||||
| 108 | if (qAbs(topOffset) > qAbs(bottomOffset)) | - | ||||||||||||
| 109 | result.setTop(result.top() - dh); // top edge drag | - | ||||||||||||
| 110 | else | - | ||||||||||||
| 111 | result.setBottom(result.bottom() + dh); // bottom edge drag | - | ||||||||||||
| 112 | const qreal leftOffset = result.left() - currentGeometry.left(); | - | ||||||||||||
| 113 | const qreal rightOffset = result.right() - currentGeometry.right(); | - | ||||||||||||
| 114 | if (qAbs(leftOffset) > qAbs(rightOffset)) | - | ||||||||||||
| 115 | result.setLeft(result.left() - dw); // left edge drag | - | ||||||||||||
| 116 | else | - | ||||||||||||
| 117 | result.setRight(result.right() + dw); // right edge drag | - | ||||||||||||
| 118 | return result; | - | ||||||||||||
| 119 | } | - | ||||||||||||
| 120 | - | |||||||||||||
| 121 | QWidgetWindow::QWidgetWindow(QWidget *widget) | - | ||||||||||||
| 122 | : QWindow(*new QWidgetWindowPrivate(), 0) | - | ||||||||||||
| 123 | , m_widget(widget) | - | ||||||||||||
| 124 | { | - | ||||||||||||
| 125 | updateObjectName(); | - | ||||||||||||
| 126 | // Enable QOpenGLWidget/QQuickWidget children if the platform plugin supports it, | - | ||||||||||||
| 127 | // and the application developer has not explicitly disabled it. | - | ||||||||||||
| 128 | if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RasterGLSurface) | - | ||||||||||||
| 129 | && !QApplication::testAttribute(Qt::AA_ForceRasterWidgets)) { | - | ||||||||||||
| 130 | setSurfaceType(QSurface::RasterGLSurface); | - | ||||||||||||
| 131 | } | - | ||||||||||||
| 132 | connect(widget, &QObject::objectNameChanged, this, &QWidgetWindow::updateObjectName); | - | ||||||||||||
| 133 | connect(this, SIGNAL(screenChanged(QScreen*)), this, SLOT(handleScreenChange())); | - | ||||||||||||
| 134 | } | - | ||||||||||||
| 135 | - | |||||||||||||
| 136 | QWidgetWindow::~QWidgetWindow() | - | ||||||||||||
| 137 | { | - | ||||||||||||
| 138 | } | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||
| 141 | QAccessibleInterface *QWidgetWindow::accessibleRoot() const | - | ||||||||||||
| 142 | { | - | ||||||||||||
| 143 | if (m_widget) | - | ||||||||||||
| 144 | return QAccessible::queryAccessibleInterface(m_widget); | - | ||||||||||||
| 145 | return 0; | - | ||||||||||||
| 146 | } | - | ||||||||||||
| 147 | #endif | - | ||||||||||||
| 148 | - | |||||||||||||
| 149 | QObject *QWidgetWindow::focusObject() const | - | ||||||||||||
| 150 | { | - | ||||||||||||
| 151 | QWidget *windowWidget = m_widget; | - | ||||||||||||
| 152 | if (!windowWidget) | - | ||||||||||||
| 153 | return Q_NULLPTR; | - | ||||||||||||
| 154 | - | |||||||||||||
| 155 | QWidget *widget = windowWidget->focusWidget(); | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | if (!widget) | - | ||||||||||||
| 158 | widget = windowWidget; | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | QObject *focusObj = QWidgetPrivate::get(widget)->focusObject(); | - | ||||||||||||
| 161 | if (focusObj) | - | ||||||||||||
| 162 | return focusObj; | - | ||||||||||||
| 163 | - | |||||||||||||
| 164 | return widget; | - | ||||||||||||
| 165 | } | - | ||||||||||||
| 166 | - | |||||||||||||
| 167 | static inline bool shouldBePropagatedToWidget(QEvent *event) | - | ||||||||||||
| 168 | { | - | ||||||||||||
| 169 | switch (event->type()) { | - | ||||||||||||
| 170 | // Handing show events to widgets would cause them to be triggered twice | - | ||||||||||||
| 171 | case QEvent::Show: | - | ||||||||||||
| 172 | case QEvent::Hide: | - | ||||||||||||
| 173 | case QEvent::Timer: | - | ||||||||||||
| 174 | case QEvent::DynamicPropertyChange: | - | ||||||||||||
| 175 | case QEvent::ChildAdded: | - | ||||||||||||
| 176 | case QEvent::ChildRemoved: | - | ||||||||||||
| 177 | return false; | - | ||||||||||||
| 178 | default: | - | ||||||||||||
| 179 | return true; | - | ||||||||||||
| 180 | } | - | ||||||||||||
| 181 | } | - | ||||||||||||
| 182 | - | |||||||||||||
| 183 | bool QWidgetWindow::event(QEvent *event) | - | ||||||||||||
| 184 | { | - | ||||||||||||
| 185 | if (!m_widget) | - | ||||||||||||
| 186 | return QWindow::event(event); | - | ||||||||||||
| 187 | - | |||||||||||||
| 188 | if (m_widget->testAttribute(Qt::WA_DontShowOnScreen)) { | - | ||||||||||||
| 189 | // \a event is uninteresting for QWidgetWindow, the event was probably | - | ||||||||||||
| 190 | // generated before WA_DontShowOnScreen was set | - | ||||||||||||
| 191 | if (!shouldBePropagatedToWidget(event)) | - | ||||||||||||
| 192 | return true; | - | ||||||||||||
| 193 | return QCoreApplication::sendEvent(m_widget, event); | - | ||||||||||||
| 194 | } | - | ||||||||||||
| 195 | - | |||||||||||||
| 196 | switch (event->type()) { | - | ||||||||||||
| 197 | case QEvent::Close: | - | ||||||||||||
| 198 | handleCloseEvent(static_cast<QCloseEvent *>(event)); | - | ||||||||||||
| 199 | return true; | - | ||||||||||||
| 200 | - | |||||||||||||
| 201 | case QEvent::Enter: | - | ||||||||||||
| 202 | case QEvent::Leave: | - | ||||||||||||
| 203 | handleEnterLeaveEvent(event); | - | ||||||||||||
| 204 | return true; | - | ||||||||||||
| 205 | - | |||||||||||||
| 206 | // these should not be sent to QWidget, the corresponding events | - | ||||||||||||
| 207 | // are sent by QApplicationPrivate::notifyActiveWindowChange() | - | ||||||||||||
| 208 | case QEvent::FocusIn: | - | ||||||||||||
| 209 | handleFocusInEvent(static_cast<QFocusEvent *>(event)); | - | ||||||||||||
| 210 | // Fallthrough | - | ||||||||||||
| 211 | case QEvent::FocusOut: { | - | ||||||||||||
| 212 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||
| 213 | QAccessible::State state; | - | ||||||||||||
| 214 | state.active = true; | - | ||||||||||||
| 215 | QAccessibleStateChangeEvent ev(m_widget, state); | - | ||||||||||||
| 216 | QAccessible::updateAccessibility(&ev); | - | ||||||||||||
| 217 | #endif | - | ||||||||||||
| 218 | return false; } | - | ||||||||||||
| 219 | - | |||||||||||||
| 220 | case QEvent::FocusAboutToChange: | - | ||||||||||||
| 221 | if (QApplicationPrivate::focus_widget) { | - | ||||||||||||
| 222 | if (QApplicationPrivate::focus_widget->testAttribute(Qt::WA_InputMethodEnabled)) | - | ||||||||||||
| 223 | QGuiApplication::inputMethod()->commit(); | - | ||||||||||||
| 224 | - | |||||||||||||
| 225 | QGuiApplication::sendSpontaneousEvent(QApplicationPrivate::focus_widget, event); | - | ||||||||||||
| 226 | } | - | ||||||||||||
| 227 | return true; | - | ||||||||||||
| 228 | - | |||||||||||||
| 229 | case QEvent::KeyPress: | - | ||||||||||||
| 230 | case QEvent::KeyRelease: | - | ||||||||||||
| 231 | case QEvent::ShortcutOverride: | - | ||||||||||||
| 232 | handleKeyEvent(static_cast<QKeyEvent *>(event)); | - | ||||||||||||
| 233 | return true; | - | ||||||||||||
| 234 | - | |||||||||||||
| 235 | case QEvent::MouseMove: | - | ||||||||||||
| 236 | case QEvent::MouseButtonPress: | - | ||||||||||||
| 237 | case QEvent::MouseButtonRelease: | - | ||||||||||||
| 238 | case QEvent::MouseButtonDblClick: | - | ||||||||||||
| 239 | handleMouseEvent(static_cast<QMouseEvent *>(event)); | - | ||||||||||||
| 240 | return true; | - | ||||||||||||
| 241 | - | |||||||||||||
| 242 | case QEvent::NonClientAreaMouseMove: | - | ||||||||||||
| 243 | case QEvent::NonClientAreaMouseButtonPress: | - | ||||||||||||
| 244 | case QEvent::NonClientAreaMouseButtonRelease: | - | ||||||||||||
| 245 | case QEvent::NonClientAreaMouseButtonDblClick: | - | ||||||||||||
| 246 | handleNonClientAreaMouseEvent(static_cast<QMouseEvent *>(event)); | - | ||||||||||||
| 247 | return true; | - | ||||||||||||
| 248 | - | |||||||||||||
| 249 | case QEvent::TouchBegin: | - | ||||||||||||
| 250 | case QEvent::TouchUpdate: | - | ||||||||||||
| 251 | case QEvent::TouchEnd: | - | ||||||||||||
| 252 | case QEvent::TouchCancel: | - | ||||||||||||
| 253 | handleTouchEvent(static_cast<QTouchEvent *>(event)); | - | ||||||||||||
| 254 | return true; | - | ||||||||||||
| 255 | - | |||||||||||||
| 256 | case QEvent::Move: | - | ||||||||||||
| 257 | handleMoveEvent(static_cast<QMoveEvent *>(event)); | - | ||||||||||||
| 258 | return true; | - | ||||||||||||
| 259 | - | |||||||||||||
| 260 | case QEvent::Resize: | - | ||||||||||||
| 261 | handleResizeEvent(static_cast<QResizeEvent *>(event)); | - | ||||||||||||
| 262 | return true; | - | ||||||||||||
| 263 | - | |||||||||||||
| 264 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||
| 265 | case QEvent::Wheel: | - | ||||||||||||
| 266 | handleWheelEvent(static_cast<QWheelEvent *>(event)); | - | ||||||||||||
| 267 | return true; | - | ||||||||||||
| 268 | #endif | - | ||||||||||||
| 269 | - | |||||||||||||
| 270 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||
| 271 | case QEvent::DragEnter: | - | ||||||||||||
| 272 | case QEvent::DragMove: | - | ||||||||||||
| 273 | handleDragEnterMoveEvent(static_cast<QDragMoveEvent *>(event)); | - | ||||||||||||
| 274 | return true; | - | ||||||||||||
| 275 | case QEvent::DragLeave: | - | ||||||||||||
| 276 | handleDragLeaveEvent(static_cast<QDragLeaveEvent *>(event)); | - | ||||||||||||
| 277 | return true; | - | ||||||||||||
| 278 | case QEvent::Drop: | - | ||||||||||||
| 279 | handleDropEvent(static_cast<QDropEvent *>(event)); | - | ||||||||||||
| 280 | return true; | - | ||||||||||||
| 281 | #endif | - | ||||||||||||
| 282 | - | |||||||||||||
| 283 | case QEvent::Expose: | - | ||||||||||||
| 284 | handleExposeEvent(static_cast<QExposeEvent *>(event)); | - | ||||||||||||
| 285 | return true; | - | ||||||||||||
| 286 | - | |||||||||||||
| 287 | case QEvent::WindowStateChange: | - | ||||||||||||
| 288 | handleWindowStateChangedEvent(static_cast<QWindowStateChangeEvent *>(event)); | - | ||||||||||||
| 289 | return true; | - | ||||||||||||
| 290 | - | |||||||||||||
| 291 | case QEvent::ThemeChange: { | - | ||||||||||||
| 292 | QEvent widgetEvent(QEvent::ThemeChange); | - | ||||||||||||
| 293 | QGuiApplication::sendSpontaneousEvent(m_widget, &widgetEvent); | - | ||||||||||||
| 294 | } | - | ||||||||||||
| 295 | return true; | - | ||||||||||||
| 296 | - | |||||||||||||
| 297 | #ifndef QT_NO_TABLETEVENT | - | ||||||||||||
| 298 | case QEvent::TabletPress: | - | ||||||||||||
| 299 | case QEvent::TabletMove: | - | ||||||||||||
| 300 | case QEvent::TabletRelease: | - | ||||||||||||
| 301 | handleTabletEvent(static_cast<QTabletEvent *>(event)); | - | ||||||||||||
| 302 | return true; | - | ||||||||||||
| 303 | #endif | - | ||||||||||||
| 304 | - | |||||||||||||
| 305 | #ifndef QT_NO_GESTURES | - | ||||||||||||
| 306 | case QEvent::NativeGesture: | - | ||||||||||||
| 307 | handleGestureEvent(static_cast<QNativeGestureEvent *>(event)); | - | ||||||||||||
| 308 | return true; | - | ||||||||||||
| 309 | #endif | - | ||||||||||||
| 310 | - | |||||||||||||
| 311 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||
| 312 | case QEvent::ContextMenu: | - | ||||||||||||
| 313 | handleContextMenuEvent(static_cast<QContextMenuEvent *>(event)); | - | ||||||||||||
| 314 | return true; | - | ||||||||||||
| 315 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||
| 316 | - | |||||||||||||
| 317 | case QEvent::WindowBlocked: | - | ||||||||||||
| 318 | qt_button_down = 0; | - | ||||||||||||
| 319 | break; | - | ||||||||||||
| 320 | - | |||||||||||||
| 321 | case QEvent::UpdateRequest: | - | ||||||||||||
| 322 | // This is not the same as an UpdateRequest for a QWidget. That just | - | ||||||||||||
| 323 | // syncs the backing store while here we also must mark as dirty. | - | ||||||||||||
| 324 | m_widget->repaint(); | - | ||||||||||||
| 325 | return true; | - | ||||||||||||
| 326 | - | |||||||||||||
| 327 | default: | - | ||||||||||||
| 328 | break; | - | ||||||||||||
| 329 | } | - | ||||||||||||
| 330 | - | |||||||||||||
| 331 | if (shouldBePropagatedToWidget(event) && QCoreApplication::sendEvent(m_widget, event)) | - | ||||||||||||
| 332 | return true; | - | ||||||||||||
| 333 | - | |||||||||||||
| 334 | return QWindow::event(event); | - | ||||||||||||
| 335 | } | - | ||||||||||||
| 336 | - | |||||||||||||
| 337 | QPointer<QWidget> qt_last_mouse_receiver = 0; | - | ||||||||||||
| 338 | - | |||||||||||||
| 339 | void QWidgetWindow::handleEnterLeaveEvent(QEvent *event) | - | ||||||||||||
| 340 | { | - | ||||||||||||
| 341 | #if !defined(Q_OS_OSX) && !defined(Q_OS_IOS) // Cocoa tracks popups | - | ||||||||||||
| 342 | // Ignore all enter/leave events from QPA if we are not on the first-level context menu. | - | ||||||||||||
| 343 | // This prevents duplicated events on most platforms. Fake events will be delivered in | - | ||||||||||||
| 344 | // QWidgetWindow::handleMouseEvent(QMouseEvent *). Make an exception whether the widget | - | ||||||||||||
| 345 | // is already under mouse - let the mouse leave. | - | ||||||||||||
| 346 | if (QApplicationPrivate::inPopupMode() && m_widget != QApplication::activePopupWidget() && !m_widget->underMouse()) | - | ||||||||||||
| 347 | return; | - | ||||||||||||
| 348 | #endif | - | ||||||||||||
| 349 | if (event->type() == QEvent::Leave) { | - | ||||||||||||
| 350 | QWidget *enter = 0; | - | ||||||||||||
| 351 | // Check from window system event queue if the next queued enter targets a window | - | ||||||||||||
| 352 | // in the same window hierarchy (e.g. enter a child of this window). If so, | - | ||||||||||||
| 353 | // remove the enter event from queue and handle both in single dispatch. | - | ||||||||||||
| 354 | QWindowSystemInterfacePrivate::EnterEvent *systemEvent = | - | ||||||||||||
| 355 | static_cast<QWindowSystemInterfacePrivate::EnterEvent *> | - | ||||||||||||
| 356 | (QWindowSystemInterfacePrivate::peekWindowSystemEvent(QWindowSystemInterfacePrivate::Enter)); | - | ||||||||||||
| 357 | const QPointF globalPosF = systemEvent ? systemEvent->globalPos : QGuiApplicationPrivate::lastCursorPosition; | - | ||||||||||||
| 358 | if (systemEvent) { | - | ||||||||||||
| 359 | if (QWidgetWindow *enterWindow = qobject_cast<QWidgetWindow *>(systemEvent->enter)) | - | ||||||||||||
| 360 | { | - | ||||||||||||
| 361 | QWindow *thisParent = this; | - | ||||||||||||
| 362 | QWindow *enterParent = enterWindow; | - | ||||||||||||
| 363 | while (thisParent->parent()) | - | ||||||||||||
| 364 | thisParent = thisParent->parent(); | - | ||||||||||||
| 365 | while (enterParent->parent()) | - | ||||||||||||
| 366 | enterParent = enterParent->parent(); | - | ||||||||||||
| 367 | if (thisParent == enterParent) { | - | ||||||||||||
| 368 | QGuiApplicationPrivate::currentMouseWindow = enterWindow; | - | ||||||||||||
| 369 | enter = enterWindow->widget(); | - | ||||||||||||
| 370 | QWindowSystemInterfacePrivate::removeWindowSystemEvent(systemEvent); | - | ||||||||||||
| 371 | } | - | ||||||||||||
| 372 | } | - | ||||||||||||
| 373 | } | - | ||||||||||||
| 374 | // Enter-leave between sibling widgets is ignored when there is a mousegrabber - this makes | - | ||||||||||||
| 375 | // both native and non-native widgets work similarly. | - | ||||||||||||
| 376 | // When mousegrabbing, leaves are only generated if leaving the parent window. | - | ||||||||||||
| 377 | if (!enter || !QWidget::mouseGrabber()) { | - | ||||||||||||
| 378 | // Preferred leave target is the last mouse receiver, unless it has native window, | - | ||||||||||||
| 379 | // in which case it is assumed to receive it's own leave event when relevant. | - | ||||||||||||
| 380 | QWidget *leave = m_widget; | - | ||||||||||||
| 381 | if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId()) | - | ||||||||||||
| 382 | leave = qt_last_mouse_receiver.data(); | - | ||||||||||||
| 383 | QApplicationPrivate::dispatchEnterLeave(enter, leave, globalPosF); | - | ||||||||||||
| 384 | qt_last_mouse_receiver = enter; | - | ||||||||||||
| 385 | } | - | ||||||||||||
| 386 | } else { | - | ||||||||||||
| 387 | const QEnterEvent *ee = static_cast<QEnterEvent *>(event); | - | ||||||||||||
| 388 | QWidget *child = m_widget->childAt(ee->pos()); | - | ||||||||||||
| 389 | QWidget *receiver = child ? child : m_widget.data(); | - | ||||||||||||
| 390 | QWidget *leave = Q_NULLPTR; | - | ||||||||||||
| 391 | if (QApplicationPrivate::inPopupMode() && receiver == m_widget | - | ||||||||||||
| 392 | && qt_last_mouse_receiver != m_widget) { | - | ||||||||||||
| 393 | // This allows to deliver the leave event to the native widget | - | ||||||||||||
| 394 | // action on first-level menu. | - | ||||||||||||
| 395 | leave = qt_last_mouse_receiver; | - | ||||||||||||
| 396 | } | - | ||||||||||||
| 397 | QApplicationPrivate::dispatchEnterLeave(receiver, leave, ee->screenPos()); | - | ||||||||||||
| 398 | qt_last_mouse_receiver = receiver; | - | ||||||||||||
| 399 | } | - | ||||||||||||
| 400 | } | - | ||||||||||||
| 401 | - | |||||||||||||
| 402 | QWidget *QWidgetWindow::getFocusWidget(FocusWidgets fw) | - | ||||||||||||
| 403 | { | - | ||||||||||||
| 404 | QWidget *tlw = m_widget; | - | ||||||||||||
| 405 | QWidget *w = tlw->nextInFocusChain(); | - | ||||||||||||
| 406 | - | |||||||||||||
| 407 | QWidget *last = tlw; | - | ||||||||||||
| 408 | - | |||||||||||||
| 409 | uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus; | - | ||||||||||||
| 410 | - | |||||||||||||
| 411 | while (w != tlw) | - | ||||||||||||
| 412 | { | - | ||||||||||||
| 413 | if (((w->focusPolicy() & focus_flag) == focus_flag) | - | ||||||||||||
| 414 | && w->isVisibleTo(m_widget) && w->isEnabled()) | - | ||||||||||||
| 415 | { | - | ||||||||||||
| 416 | last = w; | - | ||||||||||||
| 417 | if (fw == FirstFocusWidget) | - | ||||||||||||
| 418 | break; | - | ||||||||||||
| 419 | } | - | ||||||||||||
| 420 | w = w->nextInFocusChain(); | - | ||||||||||||
| 421 | } | - | ||||||||||||
| 422 | - | |||||||||||||
| 423 | return last; | - | ||||||||||||
| 424 | } | - | ||||||||||||
| 425 | - | |||||||||||||
| 426 | void QWidgetWindow::handleFocusInEvent(QFocusEvent *e) | - | ||||||||||||
| 427 | { | - | ||||||||||||
| 428 | QWidget *focusWidget = 0; | - | ||||||||||||
| 429 | if (e->reason() == Qt::BacktabFocusReason) | - | ||||||||||||
| 430 | focusWidget = getFocusWidget(LastFocusWidget); | - | ||||||||||||
| 431 | else if (e->reason() == Qt::TabFocusReason) | - | ||||||||||||
| 432 | focusWidget = getFocusWidget(FirstFocusWidget); | - | ||||||||||||
| 433 | - | |||||||||||||
| 434 | if (focusWidget != 0) | - | ||||||||||||
| 435 | focusWidget->setFocus(); | - | ||||||||||||
| 436 | } | - | ||||||||||||
| 437 | - | |||||||||||||
| 438 | void QWidgetWindow::handleNonClientAreaMouseEvent(QMouseEvent *e) | - | ||||||||||||
| 439 | { | - | ||||||||||||
| 440 | QApplication::sendSpontaneousEvent(m_widget, e); | - | ||||||||||||
| 441 | } | - | ||||||||||||
| 442 | - | |||||||||||||
| 443 | void QWidgetWindow::handleMouseEvent(QMouseEvent *event) | - | ||||||||||||
| 444 | { | - | ||||||||||||
| 445 | static const QEvent::Type contextMenuTrigger = | - | ||||||||||||
| 446 | QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ? | - | ||||||||||||
| 447 | QEvent::MouseButtonRelease : QEvent::MouseButtonPress; | - | ||||||||||||
| 448 | if (qApp->d_func()->inPopupMode()) {
| 0 | ||||||||||||
| 449 | QWidget *activePopupWidget = qApp->activePopupWidget(); | - | ||||||||||||
| 450 | QPoint mapped = event->pos(); | - | ||||||||||||
| 451 | if (activePopupWidget != m_widget)
| 0 | ||||||||||||
| 452 | mapped = activePopupWidget->mapFromGlobal(event->globalPos()); never executed: mapped = activePopupWidget->mapFromGlobal(event->globalPos()); | 0 | ||||||||||||
| 453 | bool releaseAfter = false; | - | ||||||||||||
| 454 | QWidget *popupChild = activePopupWidget->childAt(mapped); | - | ||||||||||||
| 455 | - | |||||||||||||
| 456 | if (activePopupWidget != qt_popup_down) {
| 0 | ||||||||||||
| 457 | qt_button_down = 0; | - | ||||||||||||
| 458 | qt_popup_down = 0; | - | ||||||||||||
| 459 | } never executed: end of block | 0 | ||||||||||||
| 460 | - | |||||||||||||
| 461 | switch (event->type()) { | - | ||||||||||||
| 462 | case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||
| 463 | case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||
| 464 | qt_button_down = popupChild; | - | ||||||||||||
| 465 | qt_popup_down = activePopupWidget; | - | ||||||||||||
| 466 | break; never executed: break; | 0 | ||||||||||||
| 467 | case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||
| 468 | releaseAfter = true; | - | ||||||||||||
| 469 | break; never executed: break; | 0 | ||||||||||||
| 470 | default: never executed: default: | 0 | ||||||||||||
| 471 | break; // nothing for mouse move never executed: break; | 0 | ||||||||||||
| 472 | } | - | ||||||||||||
| 473 | - | |||||||||||||
| 474 | int oldOpenPopupCount = openPopupCount; | - | ||||||||||||
| 475 | - | |||||||||||||
| 476 | if (activePopupWidget->isEnabled()) {
| 0 | ||||||||||||
| 477 | // deliver event | - | ||||||||||||
| 478 | qt_replay_popup_mouse_event = false; | - | ||||||||||||
| 479 | QWidget *receiver = activePopupWidget; | - | ||||||||||||
| 480 | QPoint widgetPos = mapped; | - | ||||||||||||
| 481 | if (qt_button_down)
| 0 | ||||||||||||
| 482 | receiver = qt_button_down; never executed: receiver = qt_button_down; | 0 | ||||||||||||
| 483 | else if (popupChild)
| 0 | ||||||||||||
| 484 | receiver = popupChild; never executed: receiver = popupChild; | 0 | ||||||||||||
| 485 | if (receiver != activePopupWidget)
| 0 | ||||||||||||
| 486 | widgetPos = receiver->mapFromGlobal(event->globalPos()); never executed: widgetPos = receiver->mapFromGlobal(event->globalPos()); | 0 | ||||||||||||
| 487 | - | |||||||||||||
| 488 | #if !defined(Q_OS_OSX) && !defined(Q_OS_IOS) // Cocoa tracks popups | - | ||||||||||||
| 489 | const bool reallyUnderMouse = activePopupWidget->rect().contains(mapped); | - | ||||||||||||
| 490 | const bool underMouse = activePopupWidget->underMouse(); | - | ||||||||||||
| 491 | if (underMouse != reallyUnderMouse) {
| 0 | ||||||||||||
| 492 | if (reallyUnderMouse) {
| 0 | ||||||||||||
| 493 | const QPoint receiverMapped = receiver->mapFromGlobal(event->screenPos().toPoint()); | - | ||||||||||||
| 494 | // Prevent negative mouse position on enter event - this event | - | ||||||||||||
| 495 | // should be properly handled in "handleEnterLeaveEvent()". | - | ||||||||||||
| 496 | if (receiverMapped.x() >= 0 && receiverMapped.y() >= 0) {
| 0 | ||||||||||||
| 497 | QApplicationPrivate::dispatchEnterLeave(receiver, Q_NULLPTR, event->screenPos()); | - | ||||||||||||
| 498 | qt_last_mouse_receiver = receiver; | - | ||||||||||||
| 499 | } never executed: end of block | 0 | ||||||||||||
| 500 | } else { never executed: end of block | 0 | ||||||||||||
| 501 | QApplicationPrivate::dispatchEnterLeave(Q_NULLPTR, qt_last_mouse_receiver, event->screenPos()); | - | ||||||||||||
| 502 | qt_last_mouse_receiver = receiver; | - | ||||||||||||
| 503 | receiver = activePopupWidget; | - | ||||||||||||
| 504 | } never executed: end of block | 0 | ||||||||||||
| 505 | } | - | ||||||||||||
| 506 | #endif | - | ||||||||||||
| 507 | - | |||||||||||||
| 508 | QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), | - | ||||||||||||
| 509 | event->button(), event->buttons(), event->modifiers(), event->source()); | - | ||||||||||||
| 510 | e.setTimestamp(event->timestamp()); | - | ||||||||||||
| 511 | QApplicationPrivate::sendMouseEvent(receiver, &e, receiver, receiver->window(), &qt_button_down, qt_last_mouse_receiver); | - | ||||||||||||
| 512 | qt_last_mouse_receiver = receiver; | - | ||||||||||||
| 513 | } else { never executed: end of block | 0 | ||||||||||||
| 514 | // close disabled popups when a mouse button is pressed or released | - | ||||||||||||
| 515 | switch (event->type()) { | - | ||||||||||||
| 516 | case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||
| 517 | case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||
| 518 | case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||
| 519 | activePopupWidget->close(); | - | ||||||||||||
| 520 | break; never executed: break; | 0 | ||||||||||||
| 521 | default: never executed: default: | 0 | ||||||||||||
| 522 | break; never executed: break; | 0 | ||||||||||||
| 523 | } | - | ||||||||||||
| 524 | } | - | ||||||||||||
| 525 | - | |||||||||||||
| 526 | if (qApp->activePopupWidget() != activePopupWidget
| 0 | ||||||||||||
| 527 | && qt_replay_popup_mouse_event
| 0 | ||||||||||||
| 528 | && QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ReplayMousePressOutsidePopup).toBool()) {
| 0 | ||||||||||||
| 529 | if (m_widget->windowType() != Qt::Popup)
| 0 | ||||||||||||
| 530 | qt_button_down = 0; never executed: qt_button_down = 0; | 0 | ||||||||||||
| 531 | if (event->type() == QEvent::MouseButtonPress) {
| 0 | ||||||||||||
| 532 | // the popup disappeared, replay the mouse press event | - | ||||||||||||
| 533 | QWidget *w = QApplication::widgetAt(event->globalPos()); | - | ||||||||||||
| 534 | if (w && !QApplicationPrivate::isBlockedByModal(w)) {
| 0 | ||||||||||||
| 535 | // activate window of the widget under mouse pointer | - | ||||||||||||
| 536 | if (!w->isActiveWindow()) {
| 0 | ||||||||||||
| 537 | w->activateWindow(); | - | ||||||||||||
| 538 | w->window()->raise(); | - | ||||||||||||
| 539 | } never executed: end of block | 0 | ||||||||||||
| 540 | - | |||||||||||||
| 541 | QWindow *win = w->windowHandle(); | - | ||||||||||||
| 542 | if (!win)
| 0 | ||||||||||||
| 543 | win = w->nativeParentWidget()->windowHandle(); never executed: win = w->nativeParentWidget()->windowHandle(); | 0 | ||||||||||||
| 544 | if (win) {
| 0 | ||||||||||||
| 545 | const QRect globalGeometry = win->isTopLevel()
| 0 | ||||||||||||
| 546 | ? win->geometry() | - | ||||||||||||
| 547 | : QRect(win->mapToGlobal(QPoint(0, 0)), win->size()); | - | ||||||||||||
| 548 | if (globalGeometry.contains(event->globalPos())) {
| 0 | ||||||||||||
| 549 | // Use postEvent() to ensure the local QEventLoop terminates when called from QMenu::exec() | - | ||||||||||||
| 550 | const QPoint localPos = win->mapFromGlobal(event->globalPos()); | - | ||||||||||||
| 551 | QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), | - | ||||||||||||
| 552 | event->button(), event->buttons(), event->modifiers(), event->source()); | - | ||||||||||||
| 553 | QCoreApplicationPrivate::setEventSpontaneous(e, true); | - | ||||||||||||
| 554 | e->setTimestamp(event->timestamp()); | - | ||||||||||||
| 555 | QCoreApplication::postEvent(win, e); | - | ||||||||||||
| 556 | } never executed: end of block | 0 | ||||||||||||
| 557 | } never executed: end of block | 0 | ||||||||||||
| 558 | } never executed: end of block | 0 | ||||||||||||
| 559 | } never executed: end of block | 0 | ||||||||||||
| 560 | qt_replay_popup_mouse_event = false; | - | ||||||||||||
| 561 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||
| 562 | } else if (event->type() == contextMenuTrigger never executed: end of block
| 0 | ||||||||||||
| 563 | && event->button() == Qt::RightButton
| 0 | ||||||||||||
| 564 | && (openPopupCount == oldOpenPopupCount)) {
| 0 | ||||||||||||
| 565 | QWidget *popupEvent = activePopupWidget; | - | ||||||||||||
| 566 | if (qt_button_down)
| 0 | ||||||||||||
| 567 | popupEvent = qt_button_down; never executed: popupEvent = qt_button_down; | 0 | ||||||||||||
| 568 | else if(popupChild)
| 0 | ||||||||||||
| 569 | popupEvent = popupChild; never executed: popupEvent = popupChild; | 0 | ||||||||||||
| 570 | QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers()); | - | ||||||||||||
| 571 | QApplication::sendSpontaneousEvent(popupEvent, &e); | - | ||||||||||||
| 572 | #endif} never executed: end of block | 0 | ||||||||||||
| 573 | #else | - | ||||||||||||
| 574 | Q_UNUSED(contextMenuTrigger) | - | ||||||||||||
| 575 | Q_UNUSED(oldOpenPopupCount) | - | ||||||||||||
| 576 | } | - | ||||||||||||
| 577 | #endif | - | ||||||||||||
| 578 | - | |||||||||||||
| 579 | if (releaseAfter) {
| 0 | ||||||||||||
| 580 | qt_button_down = 0; | - | ||||||||||||
| 581 | qt_popup_down = 0; | - | ||||||||||||
| 582 | } never executed: end of block | 0 | ||||||||||||
| 583 | return; never executed: return; | 0 | ||||||||||||
| 584 | } | - | ||||||||||||
| 585 | - | |||||||||||||
| 586 | // modal event handling | - | ||||||||||||
| 587 | if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
| 0 | ||||||||||||
| 588 | return; never executed: return; | 0 | ||||||||||||
| 589 | - | |||||||||||||
| 590 | // which child should have it? | - | ||||||||||||
| 591 | QWidget *widget = m_widget->childAt(event->pos()); | - | ||||||||||||
| 592 | QPoint mapped = event->pos(); | - | ||||||||||||
| 593 | - | |||||||||||||
| 594 | if (!widget)
| 0 | ||||||||||||
| 595 | widget = m_widget; never executed: widget = m_widget; | 0 | ||||||||||||
| 596 | - | |||||||||||||
| 597 | if (event->type() == QEvent::MouseButtonPress)
| 0 | ||||||||||||
| 598 | qt_button_down = widget; never executed: qt_button_down = widget; | 0 | ||||||||||||
| 599 | - | |||||||||||||
| 600 | QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(), | - | ||||||||||||
| 601 | qt_button_down, widget); | - | ||||||||||||
| 602 | - | |||||||||||||
| 603 | if (!receiver) {
| 0 | ||||||||||||
| 604 | if (event->type() == QEvent::MouseButtonRelease)
| 0 | ||||||||||||
| 605 | QApplicationPrivate::mouse_buttons &= ~event->button(); never executed: QApplicationPrivate::mouse_buttons &= ~event->button(); | 0 | ||||||||||||
| 606 | return; never executed: return; | 0 | ||||||||||||
| 607 | } | - | ||||||||||||
| 608 | if ((event->type() != QEvent::MouseButtonPress)
| 0 | ||||||||||||
| 609 | || !(event->flags().testFlag(Qt::MouseEventCreatedDoubleClick))) {
| 0 | ||||||||||||
| 610 | - | |||||||||||||
| 611 | // The preceding statement excludes MouseButtonPress events which caused | - | ||||||||||||
| 612 | // creation of a MouseButtonDblClick event. QTBUG-25831 | - | ||||||||||||
| 613 | QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(), | - | ||||||||||||
| 614 | event->button(), event->buttons(), event->modifiers(), event->source()); | - | ||||||||||||
| 615 | translated.setTimestamp(event->timestamp()); | - | ||||||||||||
| 616 | QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget, | - | ||||||||||||
| 617 | &qt_button_down, qt_last_mouse_receiver); | - | ||||||||||||
| 618 | event->setAccepted(translated.isAccepted()); | - | ||||||||||||
| 619 | } never executed: end of block | 0 | ||||||||||||
| 620 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||
| 621 | if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton
| 0 | ||||||||||||
| 622 | && m_widget->rect().contains(event->pos())) {
| 0 | ||||||||||||
| 623 | QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers()); | - | ||||||||||||
| 624 | QGuiApplication::sendSpontaneousEvent(receiver, &e); | - | ||||||||||||
| 625 | } never executed: end of block | 0 | ||||||||||||
| 626 | #endif | - | ||||||||||||
| 627 | } never executed: end of block | 0 | ||||||||||||
| 628 | - | |||||||||||||
| 629 | void QWidgetWindow::handleTouchEvent(QTouchEvent *event) | - | ||||||||||||
| 630 | { | - | ||||||||||||
| 631 | if (event->type() == QEvent::TouchCancel) { | - | ||||||||||||
| 632 | QApplicationPrivate::translateTouchCancel(event->device(), event->timestamp()); | - | ||||||||||||
| 633 | event->accept(); | - | ||||||||||||
| 634 | } else if (qApp->d_func()->inPopupMode()) { | - | ||||||||||||
| 635 | // Ignore touch events for popups. This will cause QGuiApplication to synthesise mouse | - | ||||||||||||
| 636 | // events instead, which QWidgetWindow::handleMouseEvent will forward correctly: | - | ||||||||||||
| 637 | event->ignore(); | - | ||||||||||||
| 638 | } else { | - | ||||||||||||
| 639 | event->setAccepted(QApplicationPrivate::translateRawTouchEvent(m_widget, event->device(), event->touchPoints(), event->timestamp())); | - | ||||||||||||
| 640 | } | - | ||||||||||||
| 641 | } | - | ||||||||||||
| 642 | - | |||||||||||||
| 643 | void QWidgetWindow::handleKeyEvent(QKeyEvent *event) | - | ||||||||||||
| 644 | { | - | ||||||||||||
| 645 | if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type())) | - | ||||||||||||
| 646 | return; | - | ||||||||||||
| 647 | - | |||||||||||||
| 648 | QObject *receiver = QWidget::keyboardGrabber(); | - | ||||||||||||
| 649 | if (!receiver && QApplicationPrivate::inPopupMode()) { | - | ||||||||||||
| 650 | QWidget *popup = QApplication::activePopupWidget(); | - | ||||||||||||
| 651 | QWidget *popupFocusWidget = popup->focusWidget(); | - | ||||||||||||
| 652 | receiver = popupFocusWidget ? popupFocusWidget : popup; | - | ||||||||||||
| 653 | } | - | ||||||||||||
| 654 | if (!receiver) | - | ||||||||||||
| 655 | receiver = focusObject(); | - | ||||||||||||
| 656 | QGuiApplication::sendSpontaneousEvent(receiver, event); | - | ||||||||||||
| 657 | } | - | ||||||||||||
| 658 | - | |||||||||||||
| 659 | bool QWidgetWindow::updateSize() | - | ||||||||||||
| 660 | { | - | ||||||||||||
| 661 | bool changed = false; | - | ||||||||||||
| 662 | if (m_widget->testAttribute(Qt::WA_OutsideWSRange)) | - | ||||||||||||
| 663 | return changed; | - | ||||||||||||
| 664 | if (m_widget->data->crect.size() != geometry().size()) { | - | ||||||||||||
| 665 | changed = true; | - | ||||||||||||
| 666 | m_widget->data->crect.setSize(geometry().size()); | - | ||||||||||||
| 667 | } | - | ||||||||||||
| 668 | - | |||||||||||||
| 669 | updateMargins(); | - | ||||||||||||
| 670 | return changed; | - | ||||||||||||
| 671 | } | - | ||||||||||||
| 672 | - | |||||||||||||
| 673 | bool QWidgetWindow::updatePos() | - | ||||||||||||
| 674 | { | - | ||||||||||||
| 675 | bool changed = false; | - | ||||||||||||
| 676 | if (m_widget->testAttribute(Qt::WA_OutsideWSRange)) | - | ||||||||||||
| 677 | return changed; | - | ||||||||||||
| 678 | if (m_widget->data->crect.topLeft() != geometry().topLeft()) { | - | ||||||||||||
| 679 | changed = true; | - | ||||||||||||
| 680 | m_widget->data->crect.moveTopLeft(geometry().topLeft()); | - | ||||||||||||
| 681 | } | - | ||||||||||||
| 682 | updateMargins(); | - | ||||||||||||
| 683 | return changed; | - | ||||||||||||
| 684 | } | - | ||||||||||||
| 685 | - | |||||||||||||
| 686 | void QWidgetWindow::updateMargins() | - | ||||||||||||
| 687 | { | - | ||||||||||||
| 688 | const QMargins margins = frameMargins(); | - | ||||||||||||
| 689 | QTLWExtra *te = m_widget->d_func()->topData(); | - | ||||||||||||
| 690 | te->posIncludesFrame= false; | - | ||||||||||||
| 691 | te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom()); | - | ||||||||||||
| 692 | m_widget->data->fstrut_dirty = false; | - | ||||||||||||
| 693 | } | - | ||||||||||||
| 694 | - | |||||||||||||
| 695 | static void sendScreenChangeRecursively(QWidget *widget) | - | ||||||||||||
| 696 | { | - | ||||||||||||
| 697 | QEvent e(QEvent::ScreenChangeInternal); | - | ||||||||||||
| 698 | QApplication::sendEvent(widget, &e); | - | ||||||||||||
| 699 | QWidgetPrivate *d = QWidgetPrivate::get(widget); | - | ||||||||||||
| 700 | for (int i = 0; i < d->children.size(); ++i) { | - | ||||||||||||
| 701 | QWidget *w = qobject_cast<QWidget *>(d->children.at(i)); | - | ||||||||||||
| 702 | if (w) | - | ||||||||||||
| 703 | sendScreenChangeRecursively(w); | - | ||||||||||||
| 704 | } | - | ||||||||||||
| 705 | } | - | ||||||||||||
| 706 | - | |||||||||||||
| 707 | void QWidgetWindow::handleScreenChange() | - | ||||||||||||
| 708 | { | - | ||||||||||||
| 709 | // Send an event recursively to the widget and its children. | - | ||||||||||||
| 710 | sendScreenChangeRecursively(m_widget); | - | ||||||||||||
| 711 | - | |||||||||||||
| 712 | // Invalidate the backing store buffer and repaint immediately. | - | ||||||||||||
| 713 | if (screen()) | - | ||||||||||||
| 714 | repaintWindow(); | - | ||||||||||||
| 715 | } | - | ||||||||||||
| 716 | - | |||||||||||||
| 717 | void QWidgetWindow::repaintWindow() | - | ||||||||||||
| 718 | { | - | ||||||||||||
| 719 | if (!m_widget->isVisible() || !m_widget->updatesEnabled() || !m_widget->rect().isValid()) | - | ||||||||||||
| 720 | return; | - | ||||||||||||
| 721 | - | |||||||||||||
| 722 | QTLWExtra *tlwExtra = m_widget->window()->d_func()->maybeTopData(); | - | ||||||||||||
| 723 | if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) | - | ||||||||||||
| 724 | tlwExtra->backingStoreTracker->markDirty(m_widget->rect(), m_widget, | - | ||||||||||||
| 725 | QWidgetBackingStore::UpdateNow, QWidgetBackingStore::BufferInvalid); | - | ||||||||||||
| 726 | } | - | ||||||||||||
| 727 | - | |||||||||||||
| 728 | Qt::WindowState effectiveState(Qt::WindowStates state); | - | ||||||||||||
| 729 | - | |||||||||||||
| 730 | // Store normal geometry used for saving application settings. | - | ||||||||||||
| 731 | void QWidgetWindow::updateNormalGeometry() | - | ||||||||||||
| 732 | { | - | ||||||||||||
| 733 | QTLWExtra *tle = m_widget->d_func()->maybeTopData(); | - | ||||||||||||
| 734 | if (!tle) | - | ||||||||||||
| 735 | return; | - | ||||||||||||
| 736 | // Ask platform window, default to widget geometry. | - | ||||||||||||
| 737 | QRect normalGeometry; | - | ||||||||||||
| 738 | if (const QPlatformWindow *pw = handle()) | - | ||||||||||||
| 739 | normalGeometry = QHighDpi::fromNativePixels(pw->normalGeometry(), this); | - | ||||||||||||
| 740 | if (!normalGeometry.isValid() && effectiveState(m_widget->windowState()) == Qt::WindowNoState) | - | ||||||||||||
| 741 | normalGeometry = m_widget->geometry(); | - | ||||||||||||
| 742 | if (normalGeometry.isValid()) | - | ||||||||||||
| 743 | tle->normalGeometry = normalGeometry; | - | ||||||||||||
| 744 | } | - | ||||||||||||
| 745 | - | |||||||||||||
| 746 | void QWidgetWindow::handleMoveEvent(QMoveEvent *event) | - | ||||||||||||
| 747 | { | - | ||||||||||||
| 748 | if (updatePos()) | - | ||||||||||||
| 749 | QGuiApplication::sendSpontaneousEvent(m_widget, event); | - | ||||||||||||
| 750 | } | - | ||||||||||||
| 751 | - | |||||||||||||
| 752 | void QWidgetWindow::handleResizeEvent(QResizeEvent *event) | - | ||||||||||||
| 753 | { | - | ||||||||||||
| 754 | QSize oldSize = m_widget->data->crect.size(); | - | ||||||||||||
| 755 | - | |||||||||||||
| 756 | if (updateSize()) { | - | ||||||||||||
| 757 | QGuiApplication::sendSpontaneousEvent(m_widget, event); | - | ||||||||||||
| 758 | - | |||||||||||||
| 759 | if (m_widget->d_func()->paintOnScreen()) { | - | ||||||||||||
| 760 | QRegion updateRegion(geometry()); | - | ||||||||||||
| 761 | if (m_widget->testAttribute(Qt::WA_StaticContents)) | - | ||||||||||||
| 762 | updateRegion -= QRect(0, 0, oldSize.width(), oldSize.height()); | - | ||||||||||||
| 763 | m_widget->d_func()->syncBackingStore(updateRegion); | - | ||||||||||||
| 764 | } else { | - | ||||||||||||
| 765 | m_widget->d_func()->syncBackingStore(); | - | ||||||||||||
| 766 | } | - | ||||||||||||
| 767 | } | - | ||||||||||||
| 768 | } | - | ||||||||||||
| 769 | - | |||||||||||||
| 770 | void QWidgetWindow::handleCloseEvent(QCloseEvent *event) | - | ||||||||||||
| 771 | { | - | ||||||||||||
| 772 | bool is_closing = m_widget->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent); | - | ||||||||||||
| 773 | event->setAccepted(is_closing); | - | ||||||||||||
| 774 | } | - | ||||||||||||
| 775 | - | |||||||||||||
| 776 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||
| 777 | - | |||||||||||||
| 778 | void QWidgetWindow::handleWheelEvent(QWheelEvent *event) | - | ||||||||||||
| 779 | { | - | ||||||||||||
| 780 | if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
| 0 | ||||||||||||
| 781 | return; never executed: return; | 0 | ||||||||||||
| 782 | - | |||||||||||||
| 783 | QWidget *rootWidget = m_widget; | - | ||||||||||||
| 784 | QPoint pos = event->pos(); | - | ||||||||||||
| 785 | - | |||||||||||||
| 786 | // Use proper popup window for wheel event. Some QPA sends the wheel | - | ||||||||||||
| 787 | // event to the root menu, so redirect it to the proper popup window. | - | ||||||||||||
| 788 | QWidget *activePopupWidget = QApplication::activePopupWidget(); | - | ||||||||||||
| 789 | if (activePopupWidget && activePopupWidget != m_widget) {
| 0 | ||||||||||||
| 790 | rootWidget = activePopupWidget; | - | ||||||||||||
| 791 | pos = rootWidget->mapFromGlobal(event->globalPos()); | - | ||||||||||||
| 792 | } never executed: end of block | 0 | ||||||||||||
| 793 | - | |||||||||||||
| 794 | // which child should have it? | - | ||||||||||||
| 795 | QWidget *widget = rootWidget->childAt(pos); | - | ||||||||||||
| 796 | - | |||||||||||||
| 797 | if (!widget)
| 0 | ||||||||||||
| 798 | widget = rootWidget; never executed: widget = rootWidget; | 0 | ||||||||||||
| 799 | - | |||||||||||||
| 800 | QPoint mapped = widget->mapFrom(rootWidget, pos); | - | ||||||||||||
| 801 | - | |||||||||||||
| 802 | QWheelEvent translated(mapped, event->globalPos(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers(), event->phase(), event->source(), event->inverted()); | - | ||||||||||||
| 803 | QGuiApplication::sendSpontaneousEvent(widget, &translated); | - | ||||||||||||
| 804 | } never executed: end of block | 0 | ||||||||||||
| 805 | - | |||||||||||||
| 806 | #endif // QT_NO_WHEELEVENT | - | ||||||||||||
| 807 | - | |||||||||||||
| 808 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||
| 809 | - | |||||||||||||
| 810 | void QWidgetWindow::handleDragEnterMoveEvent(QDragMoveEvent *event) | - | ||||||||||||
| 811 | { | - | ||||||||||||
| 812 | Q_ASSERT(event->type() ==QEvent::DragMove || !m_dragTarget); | - | ||||||||||||
| 813 | // Find a target widget under mouse that accepts drops (QTBUG-22987). | - | ||||||||||||
| 814 | QWidget *widget = m_widget->childAt(event->pos()); | - | ||||||||||||
| 815 | if (!widget) | - | ||||||||||||
| 816 | widget = m_widget; | - | ||||||||||||
| 817 | for ( ; widget && !widget->isWindow() && !widget->acceptDrops(); widget = widget->parentWidget()) ; | - | ||||||||||||
| 818 | if (widget && !widget->acceptDrops()) | - | ||||||||||||
| 819 | widget = 0; | - | ||||||||||||
| 820 | // Target widget unchanged: DragMove | - | ||||||||||||
| 821 | if (widget && widget == m_dragTarget.data()) { | - | ||||||||||||
| 822 | Q_ASSERT(event->type() == QEvent::DragMove); | - | ||||||||||||
| 823 | const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->pos())); | - | ||||||||||||
| 824 | QDragMoveEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); | - | ||||||||||||
| 825 | translated.setDropAction(event->dropAction()); | - | ||||||||||||
| 826 | if (event->isAccepted()) { // Handling 'DragEnter' should suffice for the application. | - | ||||||||||||
| 827 | translated.accept(); | - | ||||||||||||
| 828 | translated.setDropAction(event->dropAction()); | - | ||||||||||||
| 829 | } | - | ||||||||||||
| 830 | QGuiApplication::sendSpontaneousEvent(widget, &translated); | - | ||||||||||||
| 831 | if (translated.isAccepted()) { | - | ||||||||||||
| 832 | event->accept(); | - | ||||||||||||
| 833 | } else { | - | ||||||||||||
| 834 | event->ignore(); | - | ||||||||||||
| 835 | } | - | ||||||||||||
| 836 | event->setDropAction(translated.dropAction()); | - | ||||||||||||
| 837 | return; | - | ||||||||||||
| 838 | } | - | ||||||||||||
| 839 | // Target widget changed: Send DragLeave to previous, DragEnter to new if there is any | - | ||||||||||||
| 840 | if (m_dragTarget.data()) { | - | ||||||||||||
| 841 | QDragLeaveEvent le; | - | ||||||||||||
| 842 | QGuiApplication::sendSpontaneousEvent(m_dragTarget.data(), &le); | - | ||||||||||||
| 843 | m_dragTarget = 0; | - | ||||||||||||
| 844 | } | - | ||||||||||||
| 845 | if (!widget) { | - | ||||||||||||
| 846 | event->ignore(); | - | ||||||||||||
| 847 | return; | - | ||||||||||||
| 848 | } | - | ||||||||||||
| 849 | m_dragTarget = widget; | - | ||||||||||||
| 850 | const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->pos())); | - | ||||||||||||
| 851 | QDragEnterEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); | - | ||||||||||||
| 852 | QGuiApplication::sendSpontaneousEvent(widget, &translated); | - | ||||||||||||
| 853 | if (translated.isAccepted()) { | - | ||||||||||||
| 854 | event->accept(); | - | ||||||||||||
| 855 | } else { | - | ||||||||||||
| 856 | event->ignore(); | - | ||||||||||||
| 857 | } | - | ||||||||||||
| 858 | event->setDropAction(translated.dropAction()); | - | ||||||||||||
| 859 | } | - | ||||||||||||
| 860 | - | |||||||||||||
| 861 | void QWidgetWindow::handleDragLeaveEvent(QDragLeaveEvent *event) | - | ||||||||||||
| 862 | { | - | ||||||||||||
| 863 | if (m_dragTarget) | - | ||||||||||||
| 864 | QGuiApplication::sendSpontaneousEvent(m_dragTarget.data(), event); | - | ||||||||||||
| 865 | m_dragTarget = 0; | - | ||||||||||||
| 866 | } | - | ||||||||||||
| 867 | - | |||||||||||||
| 868 | void QWidgetWindow::handleDropEvent(QDropEvent *event) | - | ||||||||||||
| 869 | { | - | ||||||||||||
| 870 | if (Q_UNLIKELY(m_dragTarget.isNull())())) {
| 0 | ||||||||||||
| 871 | qWarning() << m_widget << ": No drag target set."; | - | ||||||||||||
| 872 | event->ignore(); | - | ||||||||||||
| 873 | return; never executed: return; | 0 | ||||||||||||
| 874 | } | - | ||||||||||||
| 875 | const QPoint mapped = m_dragTarget.data()->mapFromGlobal(m_widget->mapToGlobal(event->pos())); | - | ||||||||||||
| 876 | QDropEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); | - | ||||||||||||
| 877 | QGuiApplication::sendSpontaneousEvent(m_dragTarget.data(), &translated); | - | ||||||||||||
| 878 | if (translated.isAccepted())
| 0 | ||||||||||||
| 879 | event->accept(); never executed: event->accept(); | 0 | ||||||||||||
| 880 | event->setDropAction(translated.dropAction()); | - | ||||||||||||
| 881 | m_dragTarget = 0; | - | ||||||||||||
| 882 | } never executed: end of block | 0 | ||||||||||||
| 883 | - | |||||||||||||
| 884 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||
| 885 | - | |||||||||||||
| 886 | void QWidgetWindow::handleExposeEvent(QExposeEvent *event) | - | ||||||||||||
| 887 | { | - | ||||||||||||
| 888 | QWidgetPrivate *wPriv = m_widget->d_func(); | - | ||||||||||||
| 889 | const bool exposed = isExposed(); | - | ||||||||||||
| 890 | - | |||||||||||||
| 891 | if (wPriv->childrenHiddenByWState) { | - | ||||||||||||
| 892 | // If widgets has been previously hidden by window state change event | - | ||||||||||||
| 893 | // and they aren't yet shown... | - | ||||||||||||
| 894 | if (exposed) { | - | ||||||||||||
| 895 | // If the window becomes exposed... | - | ||||||||||||
| 896 | if (!wPriv->childrenShownByExpose) { | - | ||||||||||||
| 897 | // ... and they haven't been shown by this function yet - show it. | - | ||||||||||||
| 898 | wPriv->showChildren(true); | - | ||||||||||||
| 899 | QShowEvent showEvent; | - | ||||||||||||
| 900 | QCoreApplication::sendSpontaneousEvent(m_widget, &showEvent); | - | ||||||||||||
| 901 | wPriv->childrenShownByExpose = true; | - | ||||||||||||
| 902 | } | - | ||||||||||||
| 903 | } else { | - | ||||||||||||
| 904 | // If the window becomes not exposed... | - | ||||||||||||
| 905 | if (wPriv->childrenShownByExpose) { | - | ||||||||||||
| 906 | // ... and child widgets was previously shown by the expose event - hide widgets again. | - | ||||||||||||
| 907 | // This is a workaround, because sometimes when window is minimized programatically, | - | ||||||||||||
| 908 | // the QPA can notify that the window is exposed after changing window state to minimized | - | ||||||||||||
| 909 | // and then, the QPA can send next expose event with null exposed region (not exposed). | - | ||||||||||||
| 910 | wPriv->hideChildren(true); | - | ||||||||||||
| 911 | QHideEvent hideEvent; | - | ||||||||||||
| 912 | QCoreApplication::sendSpontaneousEvent(m_widget, &hideEvent); | - | ||||||||||||
| 913 | wPriv->childrenShownByExpose = false; | - | ||||||||||||
| 914 | } | - | ||||||||||||
| 915 | } | - | ||||||||||||
| 916 | } | - | ||||||||||||
| 917 | - | |||||||||||||
| 918 | if (exposed) { | - | ||||||||||||
| 919 | m_widget->setAttribute(Qt::WA_Mapped); | - | ||||||||||||
| 920 | if (!event->region().isNull()) | - | ||||||||||||
| 921 | wPriv->syncBackingStore(event->region()); | - | ||||||||||||
| 922 | } else { | - | ||||||||||||
| 923 | m_widget->setAttribute(Qt::WA_Mapped, false); | - | ||||||||||||
| 924 | } | - | ||||||||||||
| 925 | } | - | ||||||||||||
| 926 | - | |||||||||||||
| 927 | void QWidgetWindow::handleWindowStateChangedEvent(QWindowStateChangeEvent *event) | - | ||||||||||||
| 928 | { | - | ||||||||||||
| 929 | // QWindow does currently not know 'active'. | - | ||||||||||||
| 930 | Qt::WindowStates eventState = event->oldState(); | - | ||||||||||||
| 931 | Qt::WindowStates widgetState = m_widget->windowState(); | - | ||||||||||||
| 932 | if (widgetState & Qt::WindowActive) | - | ||||||||||||
| 933 | eventState |= Qt::WindowActive; | - | ||||||||||||
| 934 | - | |||||||||||||
| 935 | // Determine the new widget state, remember maximized/full screen | - | ||||||||||||
| 936 | // during minimized. | - | ||||||||||||
| 937 | switch (windowState()) { | - | ||||||||||||
| 938 | case Qt::WindowNoState: | - | ||||||||||||
| 939 | widgetState &= ~(Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen); | - | ||||||||||||
| 940 | break; | - | ||||||||||||
| 941 | case Qt::WindowMinimized: | - | ||||||||||||
| 942 | widgetState |= Qt::WindowMinimized; | - | ||||||||||||
| 943 | break; | - | ||||||||||||
| 944 | case Qt::WindowMaximized: | - | ||||||||||||
| 945 | updateNormalGeometry(); | - | ||||||||||||
| 946 | widgetState |= Qt::WindowMaximized; | - | ||||||||||||
| 947 | widgetState &= ~(Qt::WindowMinimized | Qt::WindowFullScreen); | - | ||||||||||||
| 948 | break; | - | ||||||||||||
| 949 | case Qt::WindowFullScreen: | - | ||||||||||||
| 950 | updateNormalGeometry(); | - | ||||||||||||
| 951 | widgetState |= Qt::WindowFullScreen; | - | ||||||||||||
| 952 | widgetState &= ~(Qt::WindowMinimized); | - | ||||||||||||
| 953 | break; | - | ||||||||||||
| 954 | case Qt::WindowActive: // Not handled by QWindow | - | ||||||||||||
| 955 | break; | - | ||||||||||||
| 956 | } | - | ||||||||||||
| 957 | - | |||||||||||||
| 958 | // Sent event if the state changed (that is, it is not triggered by | - | ||||||||||||
| 959 | // QWidget::setWindowState(), which also sends an event to the widget). | - | ||||||||||||
| 960 | if (widgetState != int(m_widget->data->window_state)) { | - | ||||||||||||
| 961 | m_widget->data->window_state = widgetState; | - | ||||||||||||
| 962 | QWindowStateChangeEvent widgetEvent(eventState); | - | ||||||||||||
| 963 | QGuiApplication::sendSpontaneousEvent(m_widget, &widgetEvent); | - | ||||||||||||
| 964 | } | - | ||||||||||||
| 965 | } | - | ||||||||||||
| 966 | - | |||||||||||||
| 967 | bool QWidgetWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) | - | ||||||||||||
| 968 | { | - | ||||||||||||
| 969 | return m_widget->nativeEvent(eventType, message, result); | - | ||||||||||||
| 970 | } | - | ||||||||||||
| 971 | - | |||||||||||||
| 972 | #ifndef QT_NO_TABLETEVENT | - | ||||||||||||
| 973 | void QWidgetWindow::handleTabletEvent(QTabletEvent *event) | - | ||||||||||||
| 974 | { | - | ||||||||||||
| 975 | static QPointer<QWidget> qt_tablet_target = 0; | - | ||||||||||||
| 976 | if (event->type() == QEvent::TabletPress) {
| 0 | ||||||||||||
| 977 | QWidget *widget = m_widget->childAt(event->pos()); | - | ||||||||||||
| 978 | if (!widget)
| 0 | ||||||||||||
| 979 | widget = m_widget; never executed: widget = m_widget; | 0 | ||||||||||||
| 980 | - | |||||||||||||
| 981 | qt_tablet_target = widget; | - | ||||||||||||
| 982 | } never executed: end of block | 0 | ||||||||||||
| 983 | - | |||||||||||||
| 984 | if (qt_tablet_target) {
| 0 | ||||||||||||
| 985 | QPointF delta = event->globalPosF() - event->globalPos(); | - | ||||||||||||
| 986 | QPointF mapped = qt_tablet_target->mapFromGlobal(event->globalPos()) + delta; | - | ||||||||||||
| 987 | QTabletEvent ev(event->type(), mapped, event->globalPosF(), event->device(), event->pointerType(), | - | ||||||||||||
| 988 | event->pressure(), event->xTilt(), event->yTilt(), event->tangentialPressure(), | - | ||||||||||||
| 989 | event->rotation(), event->z(), event->modifiers(), event->uniqueId(), event->button(), event->buttons()); | - | ||||||||||||
| 990 | ev.setTimestamp(event->timestamp()); | - | ||||||||||||
| 991 | QGuiApplication::sendSpontaneousEvent(qt_tablet_target, &ev); | - | ||||||||||||
| 992 | event->setAccepted(ev.isAccepted()); | - | ||||||||||||
| 993 | } never executed: end of block | 0 | ||||||||||||
| 994 | - | |||||||||||||
| 995 | if (event->type() == QEvent::TabletRelease && event->buttons() == Qt::NoButton)
| 0 | ||||||||||||
| 996 | qt_tablet_target = 0; never executed: qt_tablet_target = 0; | 0 | ||||||||||||
| 997 | } never executed: end of block | 0 | ||||||||||||
| 998 | #endif // QT_NO_TABLETEVENT | - | ||||||||||||
| 999 | - | |||||||||||||
| 1000 | #ifndef QT_NO_GESTURES | - | ||||||||||||
| 1001 | void QWidgetWindow::handleGestureEvent(QNativeGestureEvent *e) | - | ||||||||||||
| 1002 | { | - | ||||||||||||
| 1003 | // copy-pasted code to find correct widget follows: | - | ||||||||||||
| 1004 | QObject *receiver = 0; | - | ||||||||||||
| 1005 | if (QApplicationPrivate::inPopupMode()) { | - | ||||||||||||
| 1006 | QWidget *popup = QApplication::activePopupWidget(); | - | ||||||||||||
| 1007 | QWidget *popupFocusWidget = popup->focusWidget(); | - | ||||||||||||
| 1008 | receiver = popupFocusWidget ? popupFocusWidget : popup; | - | ||||||||||||
| 1009 | } | - | ||||||||||||
| 1010 | if (!receiver) | - | ||||||||||||
| 1011 | receiver = QApplication::widgetAt(e->globalPos()); | - | ||||||||||||
| 1012 | if (!receiver) | - | ||||||||||||
| 1013 | receiver = m_widget; // last resort | - | ||||||||||||
| 1014 | - | |||||||||||||
| 1015 | QApplication::sendSpontaneousEvent(receiver, e); | - | ||||||||||||
| 1016 | } | - | ||||||||||||
| 1017 | #endif // QT_NO_GESTURES | - | ||||||||||||
| 1018 | - | |||||||||||||
| 1019 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||
| 1020 | void QWidgetWindow::handleContextMenuEvent(QContextMenuEvent *e) | - | ||||||||||||
| 1021 | { | - | ||||||||||||
| 1022 | // We are only interested in keyboard originating context menu events here, | - | ||||||||||||
| 1023 | // mouse originated context menu events for widgets are generated in mouse handling methods. | - | ||||||||||||
| 1024 | if (e->reason() != QContextMenuEvent::Keyboard) | - | ||||||||||||
| 1025 | return; | - | ||||||||||||
| 1026 | - | |||||||||||||
| 1027 | QWidget *fw = QWidget::keyboardGrabber(); | - | ||||||||||||
| 1028 | if (!fw) { | - | ||||||||||||
| 1029 | if (QApplication::activePopupWidget()) { | - | ||||||||||||
| 1030 | fw = (QApplication::activePopupWidget()->focusWidget() | - | ||||||||||||
| 1031 | ? QApplication::activePopupWidget()->focusWidget() | - | ||||||||||||
| 1032 | : QApplication::activePopupWidget()); | - | ||||||||||||
| 1033 | } else if (QApplication::focusWidget()) { | - | ||||||||||||
| 1034 | fw = QApplication::focusWidget(); | - | ||||||||||||
| 1035 | } else { | - | ||||||||||||
| 1036 | fw = m_widget; | - | ||||||||||||
| 1037 | } | - | ||||||||||||
| 1038 | } | - | ||||||||||||
| 1039 | if (fw && fw->isEnabled()) { | - | ||||||||||||
| 1040 | QPoint pos = fw->inputMethodQuery(Qt::ImMicroFocus).toRect().center(); | - | ||||||||||||
| 1041 | QContextMenuEvent widgetEvent(QContextMenuEvent::Keyboard, pos, fw->mapToGlobal(pos), | - | ||||||||||||
| 1042 | e->modifiers()); | - | ||||||||||||
| 1043 | QGuiApplication::sendSpontaneousEvent(fw, &widgetEvent); | - | ||||||||||||
| 1044 | } | - | ||||||||||||
| 1045 | } | - | ||||||||||||
| 1046 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||
| 1047 | - | |||||||||||||
| 1048 | void QWidgetWindow::updateObjectName() | - | ||||||||||||
| 1049 | { | - | ||||||||||||
| 1050 | QString name = m_widget->objectName(); | - | ||||||||||||
| 1051 | if (name.isEmpty())
| 0 | ||||||||||||
| 1052 | name = QString::fromUtf8(m_widget->metaObject()->className()) + QStringLiteralQLatin1String("Class"); never executed: name = QString::fromUtf8(m_widget->metaObject()->className()) + QLatin1String("Class"); | 0 | ||||||||||||
| 1053 | name += QStringLiteralQLatin1String("Window"); | - | ||||||||||||
| 1054 | setObjectName(name); | - | ||||||||||||
| 1055 | } never executed: end of block | 0 | ||||||||||||
| 1056 | - | |||||||||||||
| 1057 | QT_END_NAMESPACE | - | ||||||||||||
| 1058 | - | |||||||||||||
| 1059 | #include "moc_qwidgetwindow_p.cpp" | - | ||||||||||||
| Source code | Switch to Preprocessed file |