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>
41 qCDebug(lcWidgetShowHide) <<
"Setting visibility of" <<
q->widget()
42 <<
"to" <<
visible <<
"via QWidgetWindowPrivate";
65 while (
w->parent() && qobject_cast<QWidgetWindow *>(
w) && qobject_cast<QWidgetWindow *>(
w->parent())) {
85 QWidget *newFocusWidget =
nullptr;
89 newFocusWidget =
q->getFocusWidget(QWidgetWindow::FirstFocusWidget);
92 newFocusWidget =
q->getFocusWidget(QWidgetWindow::LastFocusWidget);
131 const QSize oldSize =
rect.size().toSize();
133 if (newSize == oldSize)
135 const int dw = newSize.
width() - oldSize.
width();
139 const qreal topOffset =
result.top() - currentGeometry.top();
140 const qreal bottomOffset =
result.bottom() - currentGeometry.bottom();
141 if (
qAbs(topOffset) >
qAbs(bottomOffset))
164 setSurfaceType(
type);
187 topData->
window =
nullptr;
190#if QT_CONFIG(accessibility)
194 return QAccessible::queryAccessibleInterface(m_widget);
201 QWidget *windowWidget = m_widget;
224 qCDebug(lcWidgetShowHide) <<
"Setting visibility of" <<
this
225 <<
"to" <<
visible <<
"via QWidgetWindow::setNativeWindowVisibility";
230 d->QWindowPrivate::setVisible(
visible);
235 switch (
event->type()) {
256 switch (
event->type()) {
268#if QT_CONFIG(accessibility)
271 QAccessibleStateChangeEvent ev(m_widget,
state);
272 QAccessible::updateAccessibility(&ev);
320#if QT_CONFIG(wheelevent)
322 handleWheelEvent(
static_cast<QWheelEvent *
>(
event));
326#if QT_CONFIG(draganddrop)
328 handleDragEnterEvent(
static_cast<QDragEnterEvent *
>(
event));
331 handleDragMoveEvent(
static_cast<QDragMoveEvent *
>(
event));
334 handleDragLeaveEvent(
static_cast<QDragLeaveEvent *
>(
event));
337 handleDropEvent(
static_cast<QDropEvent *
>(
event));
352 QCoreApplication::forwardEvent(m_widget, &widgetEvent,
event);
356#if QT_CONFIG(tabletevent)
360 handleTabletEvent(
static_cast<QTabletEvent *
>(
event));
364#ifndef QT_NO_GESTURES
370#ifndef QT_NO_CONTEXTMENU
387 handleDevicePixelRatioChange();
421 if (
QWidgetWindow *enterWindow = qobject_cast<QWidgetWindow *>(systemEvent->enter))
424 QWindow *enterParent = enterWindow;
425 while (thisParent->parent())
426 thisParent = thisParent->parent();
427 while (enterParent->parent())
428 enterParent = enterParent->parent();
429 if (thisParent == enterParent) {
431 enter = enterWindow->widget();
464QWidget *QWidgetWindow::getFocusWidget(FocusWidgets fw)
475 if (((
w->focusPolicy() & focus_flag) == focus_flag)
476 &&
w->isVisibleTo(m_widget) &&
w->isEnabled())
479 if (fw == FirstFocusWidget)
490 QWidget *focusWidget =
nullptr;
492 focusWidget = getFocusWidget(LastFocusWidget);
494 focusWidget = getFocusWidget(FirstFocusWidget);
496 if (focusWidget !=
nullptr)
502 QApplication::forwardEvent(m_widget, e);
509 QPointF mapped =
event->position();
510 if (activePopupWidget != m_widget)
511 mapped = activePopupWidget->mapFromGlobal(
event->globalPosition());
512 bool releaseAfter =
false;
513 QWidget *popupChild = activePopupWidget->childAt(mapped.toPoint());
520 switch (
event->type()) {
534 if (activePopupWidget->isEnabled()) {
536 QPointer<QWidget> receiver = activePopupWidget;
541 receiver = popupChild;
542 if (receiver != activePopupWidget)
543 widgetPos = receiver->mapFromGlobal(
event->globalPosition());
545 const bool reallyUnderMouse = activePopupWidget->rect().contains(mapped.toPoint());
546 const bool underMouse = activePopupWidget->underMouse();
547 if (underMouse != reallyUnderMouse) {
548 if (reallyUnderMouse) {
549 const QPoint receiverMapped = receiver->mapFromGlobal(
event->globalPosition().toPoint());
552 if (receiverMapped.x() >= 0 && receiverMapped.y() >= 0) {
559 receiver = activePopupWidget;
576 switch (
event->type()) {
580 activePopupWidget->close();
602 QPoint mapped =
event->position().toPoint();
607 const bool initialPress =
event->buttons() ==
event->button();
618 mapped =
event->position().toPoint();
633#ifndef QT_NO_CONTEXTMENU
638 QGuiApplication::forwardEvent(receiver, &e,
event);
668 receiver = popupFocusWidget ? popupFocusWidget : popup;
672 QGuiApplication::forwardEvent(receiver,
event);
675bool QWidgetWindow::updateSize()
677 bool changed =
false;
683 if (m_widget->data->crect.
size() != geometry().
size()) {
685 m_widget->data->crect.setSize(geometry().
size());
692void QWidgetWindow::updateMargins()
696 QTLWExtra *te = m_widget->d_func()->topData();
697 if (te->window ==
nullptr || te->window->handle() ==
nullptr)
699 const QMargins margins = frameMargins();
700 te->posIncludesFrame=
false;
701 te->frameStrut.setCoords(margins.
left(), margins.
top(), margins.
right(), margins.
bottom());
702 m_widget->data->fstrut_dirty =
false;
710 for (
int i = 0;
i <
d->children.size(); ++
i) {
717void QWidgetWindow::handleScreenChange()
727void QWidgetWindow::handleDevicePixelRatioChange()
737void QWidgetWindow::repaintWindow()
743 if (tlwExtra && tlwExtra->backingStore)
744 tlwExtra->repaintManager->markDirty(m_widget->
rect(), m_widget,
749void QWidgetWindow::updateNormalGeometry()
751 QTLWExtra *tle = m_widget->d_func()->maybeTopData();
755 QRect normalGeometry;
759 normalGeometry = m_widget->
geometry();
761 tle->normalGeometry = normalGeometry;
771 auto oldPosition = m_widget->data->crect.topLeft();
772 auto newPosition = geometry().topLeft();
782 m_widget->data->crect.moveTopLeft(newPosition);
788 QGuiApplication::forwardEvent(m_widget, &widgetEvent,
event);
794 auto oldRect = m_widget->
rect();
797 QGuiApplication::forwardEvent(m_widget,
event);
799 if (m_widget->d_func()->shouldPaintOnScreen()) {
802 dirtyRegion -= oldRect;
803 m_widget->d_func()->syncBackingStore(dirtyRegion);
805 m_widget->d_func()->syncBackingStore();
819 event->setAccepted(accepted);
845 return q->widget()->isVisible();
848#if QT_CONFIG(wheelevent)
850void QWidgetWindow::handleWheelEvent(QWheelEvent *
event)
855 QWidget *rootWidget = m_widget;
861 if (activePopupWidget && activePopupWidget != m_widget) {
862 rootWidget = activePopupWidget;
874 QWheelEvent translated(mapped,
event->globalPosition(),
event->pixelDelta(),
event->angleDelta(),
877 translated.setTimestamp(
event->timestamp());
878 QGuiApplication::forwardEvent(
widget, &translated,
event);
883#if QT_CONFIG(draganddrop)
901 widget = findDnDTarget(m_widget,
event->position().toPoint());
909 QDragEnterEvent translated(mapped,
event->possibleActions(),
event->mimeData(),
911 QGuiApplication::forwardEvent(m_dragTarget, &translated,
event);
912 event->setAccepted(translated.isAccepted());
913 event->setDropAction(translated.dropAction());
916void QWidgetWindow::handleDragMoveEvent(QDragMoveEvent *
event)
918 QPointer<QWidget>
widget = findDnDTarget(m_widget,
event->position().toPoint());
922 QDragLeaveEvent leaveEvent;
923 QWidget *dragTarget = m_dragTarget;
924 m_dragTarget =
nullptr;
925 QGuiApplication::forwardEvent(dragTarget, &leaveEvent,
event);
929 QDragMoveEvent translated(mapped,
event->possibleActions(),
event->mimeData(),
932 if (
widget == m_dragTarget) {
933 translated.setDropAction(
event->dropAction());
934 translated.setAccepted(
event->isAccepted());
935 QGuiApplication::forwardEvent(m_dragTarget, &translated,
event);
938 QDragLeaveEvent leaveEvent;
939 QWidget *dragTarget = m_dragTarget;
940 m_dragTarget =
nullptr;
941 QGuiApplication::forwardEvent(dragTarget, &leaveEvent,
event);
946 handleDragEnterEvent(
static_cast<QDragEnterEvent*
>(
event),
widget);
948 translated.setDropAction(
event->dropAction());
949 translated.setAccepted(
event->isAccepted());
953 QGuiApplication::forwardEvent(m_dragTarget, &translated,
event);
956 event->setAccepted(translated.isAccepted());
957 event->setDropAction(translated.dropAction());
961void QWidgetWindow::handleDragLeaveEvent(QDragLeaveEvent *
event)
964 QWidget *dragTarget = m_dragTarget;
965 m_dragTarget =
nullptr;
966 QGuiApplication::forwardEvent(dragTarget,
event);
970void QWidgetWindow::handleDropEvent(QDropEvent *
event)
973 qWarning() << m_widget <<
": No drag target set.";
978 QDropEvent translated(mapped,
event->possibleActions(),
event->mimeData(),
event->buttons(),
event->modifiers());
979 QWidget *dragTarget = m_dragTarget;
980 m_dragTarget =
nullptr;
981 QGuiApplication::forwardEvent(dragTarget, &translated,
event);
982 event->setAccepted(translated.isAccepted());
983 event->setDropAction(translated.dropAction());
994 const bool exposed = isExposed();
996 if (wPriv->childrenHiddenByWState) {
1001 if (!wPriv->childrenShownByExpose) {
1003 wPriv->showChildren(
true);
1006 wPriv->childrenShownByExpose =
true;
1010 if (wPriv->childrenShownByExpose) {
1015 wPriv->hideChildren(
true);
1018 wPriv->childrenShownByExpose =
false;
1028 if (!
event->m_region.isNull())
1029 wPriv->syncBackingStore(
event->m_region);
1038 Qt::WindowStates eventState =
event->oldState();
1039 Qt::WindowStates widgetState = m_widget->
windowState();
1040 Qt::WindowStates windowState = windowStates();
1051 updateNormalGeometry();
1056 if (widgetState != Qt::WindowStates::Int(m_widget->data->window_state)) {
1057 m_widget->data->window_state =
uint(widgetState);
1059 QGuiApplication::forwardEvent(m_widget, &widgetEvent,
event);
1068#if QT_CONFIG(tabletevent)
1069void QWidgetWindow::handleTabletEvent(QTabletEvent *
event)
1071 static QPointer<QWidget> qt_tablet_target =
nullptr;
1080 qt_tablet_target =
widget;
1084 QPointF delta =
event->globalPosition() -
event->globalPosition().
toPoint();
1086 QTabletEvent ev(
event->type(),
event->pointingDevice(), mapped,
event->globalPosition(),
1089 ev.setTimestamp(
event->timestamp());
1090 ev.setAccepted(
false);
1091 QGuiApplication::forwardEvent(
widget, &ev,
event);
1092 event->setAccepted(ev.isAccepted());
1096 qt_tablet_target =
nullptr;
1100#ifndef QT_NO_GESTURES
1108 receiver = popupFocusWidget ? popupFocusWidget : popup;
1113 receiver = m_widget;
1115 QApplication::forwardEvent(receiver, e);
1119#ifndef QT_NO_CONTEXTMENU
1143 QGuiApplication::forwardEvent(fw, &widgetEvent, e);
1148void QWidgetWindow::updateObjectName()
1153 name +=
"Window"_L1;
1159#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 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 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.
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 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)
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