4#include "private/qwindow_p.h"
8#include "private/qwidget_p.h"
9#include "private/qapplication_p.h"
10#if QT_CONFIG(accessibility)
11#include <QtGui/qaccessible.h>
13#include <private/qwidgetrepaintmanager_p.h>
14#include <qpa/qwindowsysteminterface_p.h>
15#include <qpa/qplatformtheme.h>
16#include <qpa/qplatformwindow.h>
17#include <private/qgesturemanager_p.h>
18#include <private/qhighdpiscaling_p.h>
42 qCDebug(lcWidgetShowHide) <<
"Setting visibility of" <<
q->widget()
43 <<
"to" <<
visible <<
"via QWidgetWindowPrivate";
66 while (
w->parent() && qobject_cast<QWidgetWindow *>(
w) && qobject_cast<QWidgetWindow *>(
w->parent())) {
86 QWidget *newFocusWidget =
nullptr;
90 newFocusWidget =
q->getFocusWidget(QWidgetWindow::FirstFocusWidget);
93 newFocusWidget =
q->getFocusWidget(QWidgetWindow::LastFocusWidget);
132 const QSize oldSize =
rect.size().toSize();
134 if (newSize == oldSize)
136 const int dw = newSize.
width() - oldSize.
width();
140 const qreal topOffset =
result.top() - currentGeometry.top();
141 const qreal bottomOffset =
result.bottom() - currentGeometry.bottom();
142 if (
qAbs(topOffset) >
qAbs(bottomOffset))
165 setSurfaceType(
type);
188 topData->
window =
nullptr;
191#if QT_CONFIG(accessibility)
195 return QAccessible::queryAccessibleInterface(m_widget);
202 QWidget *windowWidget = m_widget;
225 qCDebug(lcWidgetShowHide) <<
"Setting visibility of" <<
this
226 <<
"to" <<
visible <<
"via QWidgetWindow::setNativeWindowVisibility";
231 d->QWindowPrivate::setVisible(
visible);
236 switch (
event->type()) {
257 switch (
event->type()) {
269#if QT_CONFIG(accessibility)
272 QAccessibleStateChangeEvent ev(m_widget,
state);
273 QAccessible::updateAccessibility(&ev);
321#if QT_CONFIG(wheelevent)
323 handleWheelEvent(
static_cast<QWheelEvent *
>(
event));
327#if QT_CONFIG(draganddrop)
329 handleDragEnterEvent(
static_cast<QDragEnterEvent *
>(
event));
332 handleDragMoveEvent(
static_cast<QDragMoveEvent *
>(
event));
335 handleDragLeaveEvent(
static_cast<QDragLeaveEvent *
>(
event));
338 handleDropEvent(
static_cast<QDropEvent *
>(
event));
353 QCoreApplication::forwardEvent(m_widget, &widgetEvent,
event);
357#if QT_CONFIG(tabletevent)
361 handleTabletEvent(
static_cast<QTabletEvent *
>(
event));
365#ifndef QT_NO_GESTURES
371#ifndef QT_NO_CONTEXTMENU
388 handleDevicePixelRatioChange();
422 if (
QWidgetWindow *enterWindow = qobject_cast<QWidgetWindow *>(systemEvent->enter))
425 QWindow *enterParent = enterWindow;
426 while (thisParent->parent())
427 thisParent = thisParent->parent();
428 while (enterParent->parent())
429 enterParent = enterParent->parent();
430 if (thisParent == enterParent) {
432 enter = enterWindow->widget();
465QWidget *QWidgetWindow::getFocusWidget(FocusWidgets fw)
476 if (((
w->focusPolicy() & focus_flag) == focus_flag)
477 &&
w->isVisibleTo(m_widget) &&
w->isEnabled())
480 if (fw == FirstFocusWidget)
491 QWidget *focusWidget =
nullptr;
493 focusWidget = getFocusWidget(LastFocusWidget);
495 focusWidget = getFocusWidget(FirstFocusWidget);
497 if (focusWidget !=
nullptr)
503 QApplication::forwardEvent(m_widget, e);
510 QPointF mapped =
event->position();
511 if (activePopupWidget != m_widget)
512 mapped = activePopupWidget->mapFromGlobal(
event->globalPosition());
513 bool releaseAfter =
false;
514 QWidget *popupChild = activePopupWidget->childAt(mapped.toPoint());
521 switch (
event->type()) {
537 if (activePopupWidget->isEnabled()) {
540 QPointer<QWidget> receiver = activePopupWidget;
545 receiver = popupChild;
546 if (receiver != activePopupWidget)
547 widgetPos = receiver->mapFromGlobal(
event->globalPosition());
549 const bool reallyUnderMouse = activePopupWidget->rect().contains(mapped.toPoint());
550 const bool underMouse = activePopupWidget->underMouse();
551 if (underMouse != reallyUnderMouse) {
552 if (reallyUnderMouse) {
553 const QPoint receiverMapped = receiver->mapFromGlobal(
event->globalPosition().toPoint());
556 if (receiverMapped.x() >= 0 && receiverMapped.y() >= 0) {
563 receiver = activePopupWidget;
580 switch (
event->type()) {
584 activePopupWidget->close();
601 if (!
w->isActiveWindow()) {
603 w->window()->raise();
607 const QRect globalGeometry =
win->isTopLevel()
610 if (globalGeometry.
contains(
event->globalPosition().toPoint())) {
623#ifndef QT_NO_CONTEXTMENU
627 QWidget *receiver = activePopupWidget;
631 receiver = popupChild;
634 QApplication::forwardEvent(receiver, &e,
event);
656 QPoint mapped =
event->position().toPoint();
661 const bool initialPress =
event->buttons() ==
event->button();
677 translated.setTimestamp(
event->timestamp());
680 event->setAccepted(translated.isAccepted());
682#ifndef QT_NO_CONTEXTMENU
685 && m_widget->rect().contains(
event->position().toPoint())) {
687 QGuiApplication::forwardEvent(receiver, &e,
event);
717 receiver = popupFocusWidget ? popupFocusWidget : popup;
721 QGuiApplication::forwardEvent(receiver,
event);
724bool QWidgetWindow::updateSize()
726 bool changed =
false;
732 if (m_widget->data->crect.
size() != geometry().
size()) {
734 m_widget->data->crect.setSize(geometry().
size());
741void QWidgetWindow::updateMargins()
745 QTLWExtra *te = m_widget->d_func()->topData();
746 if (te->window ==
nullptr || te->window->handle() ==
nullptr)
748 const QMargins margins = frameMargins();
749 te->posIncludesFrame=
false;
750 te->frameStrut.setCoords(margins.
left(), margins.
top(), margins.
right(), margins.
bottom());
751 m_widget->data->fstrut_dirty =
false;
759 for (
int i = 0;
i <
d->children.size(); ++
i) {
766void QWidgetWindow::handleScreenChange()
776void QWidgetWindow::handleDevicePixelRatioChange()
786void QWidgetWindow::repaintWindow()
792 if (tlwExtra && tlwExtra->backingStore)
793 tlwExtra->repaintManager->markDirty(m_widget->
rect(), m_widget,
798void QWidgetWindow::updateNormalGeometry()
800 QTLWExtra *tle = m_widget->d_func()->maybeTopData();
804 QRect normalGeometry;
808 normalGeometry = m_widget->
geometry();
810 tle->normalGeometry = normalGeometry;
820 auto oldPosition = m_widget->data->crect.topLeft();
821 auto newPosition = geometry().topLeft();
831 m_widget->data->crect.moveTopLeft(newPosition);
837 QGuiApplication::forwardEvent(m_widget, &widgetEvent,
event);
843 auto oldRect = m_widget->
rect();
846 QGuiApplication::forwardEvent(m_widget,
event);
848 if (m_widget->d_func()->shouldPaintOnScreen()) {
851 dirtyRegion -= oldRect;
852 m_widget->d_func()->syncBackingStore(dirtyRegion);
854 m_widget->d_func()->syncBackingStore();
864 event->setAccepted(accepted);
890 return q->widget()->isVisible();
893#if QT_CONFIG(wheelevent)
895void QWidgetWindow::handleWheelEvent(QWheelEvent *
event)
900 QWidget *rootWidget = m_widget;
906 if (activePopupWidget && activePopupWidget != m_widget) {
907 rootWidget = activePopupWidget;
919 QWheelEvent translated(mapped,
event->globalPosition(),
event->pixelDelta(),
event->angleDelta(),
922 translated.setTimestamp(
event->timestamp());
923 QGuiApplication::forwardEvent(
widget, &translated,
event);
928#if QT_CONFIG(draganddrop)
946 widget = findDnDTarget(m_widget,
event->position().toPoint());
954 QDragEnterEvent translated(mapped,
event->possibleActions(),
event->mimeData(),
956 QGuiApplication::forwardEvent(m_dragTarget, &translated,
event);
957 event->setAccepted(translated.isAccepted());
958 event->setDropAction(translated.dropAction());
961void QWidgetWindow::handleDragMoveEvent(QDragMoveEvent *
event)
963 QPointer<QWidget>
widget = findDnDTarget(m_widget,
event->position().toPoint());
967 QDragLeaveEvent leaveEvent;
968 QWidget *dragTarget = m_dragTarget;
969 m_dragTarget =
nullptr;
970 QGuiApplication::forwardEvent(dragTarget, &leaveEvent,
event);
974 QDragMoveEvent translated(mapped,
event->possibleActions(),
event->mimeData(),
977 if (
widget == m_dragTarget) {
978 translated.setDropAction(
event->dropAction());
979 translated.setAccepted(
event->isAccepted());
980 QGuiApplication::forwardEvent(m_dragTarget, &translated,
event);
983 QDragLeaveEvent leaveEvent;
984 QWidget *dragTarget = m_dragTarget;
985 m_dragTarget =
nullptr;
986 QGuiApplication::forwardEvent(dragTarget, &leaveEvent,
event);
991 handleDragEnterEvent(
static_cast<QDragEnterEvent*
>(
event),
widget);
993 translated.setDropAction(
event->dropAction());
994 translated.setAccepted(
event->isAccepted());
998 QGuiApplication::forwardEvent(m_dragTarget, &translated,
event);
1001 event->setAccepted(translated.isAccepted());
1002 event->setDropAction(translated.dropAction());
1006void QWidgetWindow::handleDragLeaveEvent(QDragLeaveEvent *
event)
1009 QWidget *dragTarget = m_dragTarget;
1010 m_dragTarget =
nullptr;
1011 QGuiApplication::forwardEvent(dragTarget,
event);
1015void QWidgetWindow::handleDropEvent(QDropEvent *
event)
1018 qWarning() << m_widget <<
": No drag target set.";
1023 QDropEvent translated(mapped,
event->possibleActions(),
event->mimeData(),
event->buttons(),
event->modifiers());
1024 QWidget *dragTarget = m_dragTarget;
1025 m_dragTarget =
nullptr;
1026 QGuiApplication::forwardEvent(dragTarget, &translated,
event);
1027 event->setAccepted(translated.isAccepted());
1028 event->setDropAction(translated.dropAction());
1039 const bool exposed = isExposed();
1041 if (wPriv->childrenHiddenByWState) {
1046 if (!wPriv->childrenShownByExpose) {
1048 wPriv->showChildren(
true);
1051 wPriv->childrenShownByExpose =
true;
1055 if (wPriv->childrenShownByExpose) {
1060 wPriv->hideChildren(
true);
1063 wPriv->childrenShownByExpose =
false;
1073 if (!
event->m_region.isNull())
1074 wPriv->syncBackingStore(
event->m_region);
1083 Qt::WindowStates eventState =
event->oldState();
1084 Qt::WindowStates widgetState = m_widget->
windowState();
1085 Qt::WindowStates windowState = windowStates();
1096 updateNormalGeometry();
1101 if (widgetState != Qt::WindowStates::Int(m_widget->data->window_state)) {
1102 m_widget->data->window_state =
uint(widgetState);
1104 QGuiApplication::forwardEvent(m_widget, &widgetEvent,
event);
1113#if QT_CONFIG(tabletevent)
1114void QWidgetWindow::handleTabletEvent(QTabletEvent *
event)
1116 static QPointer<QWidget> qt_tablet_target =
nullptr;
1125 qt_tablet_target =
widget;
1129 QPointF delta =
event->globalPosition() -
event->globalPosition().
toPoint();
1131 QTabletEvent ev(
event->type(),
event->pointingDevice(), mapped,
event->globalPosition(),
1134 ev.setTimestamp(
event->timestamp());
1135 ev.setAccepted(
false);
1136 QGuiApplication::forwardEvent(
widget, &ev,
event);
1137 event->setAccepted(ev.isAccepted());
1141 qt_tablet_target =
nullptr;
1145#ifndef QT_NO_GESTURES
1153 receiver = popupFocusWidget ? popupFocusWidget : popup;
1158 receiver = m_widget;
1160 QApplication::forwardEvent(receiver, e);
1164#ifndef QT_NO_CONTEXTMENU
1188 QGuiApplication::forwardEvent(fw, &widgetEvent, e);
1193void QWidgetWindow::updateObjectName()
1198 name +=
"Window"_L1;
1204#include "moc_qwidgetwindow_p.cpp"
static QWidget * pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, QPoint *pos, QEvent::Type type, Qt::MouseButtons buttons, QWidget *buttonDown, QWidget *alienWidget)
static QApplicationPrivate * instance()
static QWidget * focus_widget
static bool inPopupMode()
static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF)
static bool isBlockedByModal(QWidget *widget)
static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent)
static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget, QWidget *native, QWidget **buttonDown, QPointer< QWidget > &lastMouseReceiver, bool spontaneous=true, bool onlyDispatchEnterLeave=false)
static void translateTouchCancel(const QPointingDevice *device, ulong timestamp)
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or \nullptr if there is no Qt widget there.
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
static QWidget * activePopupWidget()
Returns the active popup widget.
The QCloseEvent class contains parameters that describe a close event.
static void setEventSpontaneous(QEvent *e, bool spontaneous)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
Type
This enum type defines the valid event types in Qt.
@ NonClientAreaMouseButtonDblClick
@ NonClientAreaMouseButtonRelease
@ NonClientAreaMouseButtonPress
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
The QFocusEvent class contains event parameters for widget focus events.
Qt::FocusReason reason() const
Returns the reason for this focus event.
static QPlatformIntegration * platformIntegration()
static QEvent::Type contextMenuEventType()
static QWindow * currentMouseWindow
static struct QGuiApplicationPrivate::QLastCursorPosition lastCursorPosition
static QInputMethod * inputMethod()
returns the input method.
The QHideEvent class provides an event which is sent after a widget is hidden.
The QKeyEvent class describes a key event.
static QSize closestAcceptableSize(const QWidget *w, const QSize &s)
Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is ...
constexpr int bottom() const noexcept
Returns the bottom margin.
constexpr int left() const noexcept
Returns the left margin.
constexpr int right() const noexcept
Returns the right margin.
constexpr int top() const noexcept
Returns the top margin.
The QMoveEvent class contains event parameters for move events.
static QMutableSinglePointEvent * from(QSinglePointEvent *e)
The QNativeGestureEvent class contains parameters that describe a gesture event. \inmodule QtGui.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QString objectName
the name of this object
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
void objectNameChanged(const QString &objectName, QPrivateSignal)
This signal is emitted after the object's name has been changed.
\inmodule QtCore\reentrant
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
\inmodule QtCore\reentrant
void setTimestamp(quint64 timestamp) override
T * data() const noexcept
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QRegion class specifies a clip region for a painter.
The QResizeEvent class contains event parameters for resize events.
The QShowEvent class provides an event that is sent when a widget is shown.
QPointF globalPosition() const
Returns the position of the point in this event on the screen or virtual desktop.
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SurfaceType
The SurfaceType enum describes what type of surface this is.
The QTouchEvent class contains parameters that describe a touch event.
virtual void setVisible(bool visible)
virtual bool participatesInLastWindowClosed() const
static void removeWindowSystemEvent(WindowSystemEvent *event)
static WindowSystemEvent * peekWindowSystemEvent(EventType t)
virtual QAccessibleInterface * accessibleRoot() const
Returns the accessibility interface for the object that the window represents.
bool visible
whether the window is visible or not
QSize size() const override
Returns the size of the window excluding any window frame.
virtual bool event(QEvent *) override
Override this to handle any event (ev) sent to the window.
virtual void hideEvent(QHideEvent *)
Override this to handle hide events (ev).
void screenChanged(QScreen *screen)
This signal is emitted when a window's screen changes, either by being set explicitly with setScreen(...
virtual void showEvent(QShowEvent *)
Override this to handle show events (ev).
T fromNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
QFuture< QtPrivate::MapResultType< Sequence, MapFunctor > > mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
bool qt_replay_popup_mouse_event
bool qt_popup_down_closed
Q_WIDGETS_EXPORT QWidget * qt_button_down
bool qt_try_modal(QWidget *widget, QEvent::Type type)
static const double leftOffset
static const double rightOffset
#define qCDebug(category,...)
constexpr T qAbs(const T &t)
GLuint64 GLenum void * handle
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLsizei const GLchar * message
GLdouble GLdouble GLdouble GLdouble q
QPointer< QWindow > qt_last_mouse_receiver
QT_BEGIN_NAMESPACE bool toBool(const QString &str)