From 6226b770ea25cac7e9d2254fe01a057262b14e13 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 7 Jun 2019 13:43:43 +0000 Subject: [PATCH] QEvent cleanup Signed-off-by: Ivailo Monev --- README | 1 + cmake/modules/KatieBuildMacros.cmake | 2 +- src/core/io/qfile.h | 1 + src/core/kernel/qcoreapplication.cpp | 9 +- src/core/kernel/qcoreevent.cpp | 5 +- src/core/kernel/qcoreevent.h | 91 ++++---- .../components/formeditor/formwindowmanager.cpp | 5 +- src/gui/graphicsview/qgraphicsproxywidget.cpp | 11 +- src/gui/graphicsview/qgraphicsscene.cpp | 7 +- src/gui/graphicsview/qgraphicsscene_p.h | 2 +- src/gui/graphicsview/qgraphicsview.cpp | 27 ++- src/gui/kernel/qapplication.cpp | 4 +- src/gui/kernel/qapplication_x11.cpp | 6 +- src/gui/kernel/qclipboard_x11.cpp | 5 +- src/gui/kernel/qevent.cpp | 239 ++++++--------------- src/gui/kernel/qevent.h | 103 ++++----- src/gui/kernel/qevent_p.h | 43 +--- src/gui/kernel/qgesturemanager.cpp | 4 +- src/shared/qclass_lib_map.h | 4 +- src/tools/designer/qdesigner.cpp | 6 - 20 files changed, 210 insertions(+), 365 deletions(-) diff --git a/README b/README index 97d9b2a3d..f36937770 100644 --- a/README +++ b/README @@ -17,6 +17,7 @@ There are several things you should be aware before considering Katie: - QIconEnginePluginV{2} classes have been merged - QIconEngineFactoryInterfaceV{2} classes and interfaces have been merged - QKeyEventEx and QKeyEvent classes have been merged + - QMouseEventEx and QMouseEvent classes have been merged - QGuiPlatformPlugin class is public - zlib, OpenSSL, PCRE, Freetype and X11 are required for building - OpenSSL, D-Bus, CUPS, resolv and NSL cannot be runtime dependencies, they diff --git a/cmake/modules/KatieBuildMacros.cmake b/cmake/modules/KatieBuildMacros.cmake index 8ceda5f7a..6ab705c23 100644 --- a/cmake/modules/KatieBuildMacros.cmake +++ b/cmake/modules/KatieBuildMacros.cmake @@ -314,7 +314,7 @@ macro(KATIE_TEST TESTNAME TESTSOURCES) ) endmacro() -# a macro to add tests easily by setting them up with the assumptions they make +# a macro to add tests that require GUI easily by setting them up with the assumptions they make macro(KATIE_GUI_TEST TESTNAME TESTSOURCES) katie_resources(${TESTSOURCES} ${ARGN}) diff --git a/src/core/io/qfile.h b/src/core/io/qfile.h index 06f6648de..cddfce042 100644 --- a/src/core/io/qfile.h +++ b/src/core/io/qfile.h @@ -35,6 +35,7 @@ #define QFILE_H #include + #include #ifdef open diff --git a/src/core/kernel/qcoreapplication.cpp b/src/core/kernel/qcoreapplication.cpp index 4daf7f442..b5c608979 100644 --- a/src/core/kernel/qcoreapplication.cpp +++ b/src/core/kernel/qcoreapplication.cpp @@ -1006,7 +1006,7 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) if (event->type() == QEvent::DeferredDelete && data == QThreadData::current()) { // remember the current running eventloop for DeferredDelete // events posted in the receiver's thread - event->d = reinterpret_cast(quintptr(data->loopLevel)); + event->looplevel = data->loopLevel; } // delete the event on exceptions to protect against memory leaks till the event is @@ -1132,10 +1132,9 @@ void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int event_type // (s.a. QEvent::DeferredDelete), and then only if the event loop that // posted the event has returned. const bool allowDeferredDelete = - (quintptr(pe.event->d) > unsigned(data->loopLevel) - || (!quintptr(pe.event->d) && data->loopLevel > 0) - || (event_type == QEvent::DeferredDelete - && quintptr(pe.event->d) == unsigned(data->loopLevel))); + (pe.event->looplevel > data->loopLevel + || (!pe.event->looplevel && data->loopLevel > 0) + || (event_type == QEvent::DeferredDelete && pe.event->looplevel == data->loopLevel)); if (!allowDeferredDelete) { // cannot send deferred delete if (!event_type && !receiver) { diff --git a/src/core/kernel/qcoreevent.cpp b/src/core/kernel/qcoreevent.cpp index eff17debf..6c0caaf7e 100644 --- a/src/core/kernel/qcoreevent.cpp +++ b/src/core/kernel/qcoreevent.cpp @@ -178,7 +178,6 @@ QT_BEGIN_NAMESPACE \value PaletteChange Palette of the widget changed. \value ParentAboutToChange The widget parent is about to change. \value ParentChange The widget parent has changed. - \value PlatformPanel A platform specific panel has been requested. \value Polish The widget is polished. \value PolishRequest The widget should be polished. \value QueryWhatsThis The widget should accept the event if it has "What's This?" help. @@ -189,8 +188,6 @@ QT_BEGIN_NAMESPACE \value Show Widget was shown on screen (QShowEvent). \value ShowToParent A child widget has been shown. \value SockAct Socket activated, used to implement QSocketNotifier. - \value StateMachineSignal A signal delivered to a state machine (QStateMachine::SignalEvent). - \value StateMachineWrapped The event is a wrapper for, i.e., contains, another event (QStateMachine::WrappedEvent). \value StatusTip A status tip is requested (QStatusTipEvent). \value StyleChange Widget's style has been changed. \value Timer Regular timer events (QTimerEvent). @@ -261,7 +258,7 @@ QT_BEGIN_NAMESPACE Contructs an event object of type \a type. */ QEvent::QEvent(Type type) - : d(0), t(type), posted(false), spont(false), m_accept(true) + : t(type), looplevel(0), posted(false), spont(false), m_accept(true) {} /*! diff --git a/src/core/kernel/qcoreevent.h b/src/core/kernel/qcoreevent.h index d037996fe..5d39e1884 100644 --- a/src/core/kernel/qcoreevent.h +++ b/src/core/kernel/qcoreevent.h @@ -41,8 +41,6 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE - -class QEventPrivate; class Q_CORE_EXPORT QEvent // event base class { Q_GADGET @@ -141,46 +139,44 @@ public: ActionAdded = 76, ActionRemoved = 77, - FileOpen = 78, // file open request - - Shortcut = 79, // shortcut triggered - ShortcutOverride = 80, // shortcut override request - + Shortcut = 78, // shortcut triggered + ShortcutOverride = 79, // shortcut override request - WhatsThisClicked = 81, + WhatsThisClicked = 80, - ToolBarChange = 82, // toolbar visibility toggled + ToolBarChange = 81, // toolbar visibility toggled - ApplicationActivate = 83, // application has been changed to active - ApplicationDeactivate = 84, // application has been changed to inactive + ApplicationActivate = 82, // application has been changed to active + ApplicationDeactivate = 83, // application has been changed to inactive - QueryWhatsThis = 85, // query what's this widget help - EnterWhatsThisMode = 86, - LeaveWhatsThisMode = 87, + QueryWhatsThis = 84, // query what's this widget help + EnterWhatsThisMode = 85, + LeaveWhatsThisMode = 86, - ZOrderChange = 88, // child widget has had its z-order changed + ZOrderChange = 87, // child widget has had its z-order changed - HoverEnter = 89, // mouse cursor enters a hover widget - HoverLeave = 90, // mouse cursor leaves a hover widget - HoverMove = 91, // mouse cursor move inside a hover widget + HoverEnter = 88, // mouse cursor enters a hover widget + HoverLeave = 89, // mouse cursor leaves a hover widget + HoverMove = 90, // mouse cursor move inside a hover widget - AccessibilityHelp = 92, // accessibility help text request - AccessibilityDescription = 93, // accessibility description text request + AccessibilityHelp = 91, // accessibility help text request + AccessibilityDescription = 92, // accessibility description text request #ifdef QT_KEYPAD_NAVIGATION - EnterEditFocus = 94, // enter edit mode in keypad navigation (Defined only with QT_KEYPAD_NAVIGATION) - LeaveEditFocus = 95, // leave edit mode in keypad navigation (Defined only with QT_KEYPAD_NAVIGATION) + EnterEditFocus = 93, // enter edit mode in keypad navigation (Defined only with QT_KEYPAD_NAVIGATION) + LeaveEditFocus = 94, // leave edit mode in keypad navigation (Defined only with QT_KEYPAD_NAVIGATION) #endif - AcceptDropsChange = 96, - - GraphicsSceneMouseMove = 97, // GraphicsView - GraphicsSceneMousePress = 98, - GraphicsSceneMouseRelease = 99, - GraphicsSceneMouseDoubleClick = 100, - GraphicsSceneContextMenu = 101, - GraphicsSceneHoverEnter = 102, - GraphicsSceneHoverMove = 103, - GraphicsSceneHoverLeave = 104, + AcceptDropsChange = 95, + + GraphicsSceneMouseMove = 94, // GraphicsView + GraphicsSceneMousePress = 97, + GraphicsSceneMouseRelease = 98, + GraphicsSceneMouseDoubleClick = 99, + GraphicsSceneContextMenu = 100, + GraphicsSceneHoverEnter = 101, + GraphicsSceneHoverMove = 102, + GraphicsSceneHoverLeave = 103, + GraphicsSceneLeave = 104, // internal GraphicsSceneHelp = 105, GraphicsSceneDragEnter = 106, GraphicsSceneDragMove = 107, @@ -214,27 +210,22 @@ public: GrabKeyboard = 126, UngrabKeyboard = 127, - StateMachineSignal = 128, - StateMachineWrapped = 129, - - TouchBegin = 130, - TouchUpdate = 131, - TouchEnd = 132, + TouchBegin = 128, + TouchUpdate = 129, + TouchEnd = 130, #ifndef QT_NO_GESTURES - NativeGesture = 133, // Internal for platform gesture support + NativeGesture = 131, // Internal for platform gesture support #endif - RequestSoftwareInputPanel = 134, - CloseSoftwareInputPanel = 135, + RequestSoftwareInputPanel = 132, + CloseSoftwareInputPanel = 133, - WinIdChange = 136, + WinIdChange = 134, #ifndef QT_NO_GESTURES - Gesture = 137, - GestureOverride = 138, + Gesture = 135, + GestureOverride = 136, #endif - PlatformPanel = 139, - User = 1000, // first user event id MaxUser = 65535 // last user event id }; @@ -253,13 +244,13 @@ public: static int registerEventType(int hint = -1); protected: - QEventPrivate *d; Type t; + int looplevel; private: - bool posted : 1; - bool spont : 1; - bool m_accept : 1; + bool posted; + bool spont; + bool m_accept; friend class QCoreApplication; friend class QCoreApplicationPrivate; diff --git a/src/designer/components/formeditor/formwindowmanager.cpp b/src/designer/components/formeditor/formwindowmanager.cpp index 7e84d2998..51ee0da60 100644 --- a/src/designer/components/formeditor/formwindowmanager.cpp +++ b/src/designer/components/formeditor/formwindowmanager.cpp @@ -174,7 +174,6 @@ bool FormWindowManager::eventFilter(QObject *o, QEvent *e) case QEvent::Clipboard: case QEvent::ContentsRectChange: case QEvent::DeferredDelete: - case QEvent::FileOpen: case QEvent::LanguageChange: case QEvent::MetaCall: case QEvent::ModifiedChange: @@ -290,14 +289,14 @@ void FormWindowManager::removeFormWindow(QDesignerFormWindowInterface *w) m_formWindows.removeAt(idx); emit formWindowRemoved(formWindow); - if (formWindow == m_activeFormWindow) + if (formWindow == m_activeFormWindow) { setActiveFormWindow(0); if (m_formWindows.size() == 0 && m_core->widgetBox()) { // Make sure that widget box is enabled by default m_core->widgetBox()->setEnabled(true); } - + } } void FormWindowManager::setActiveFormWindow(QDesignerFormWindowInterface *w) diff --git a/src/gui/graphicsview/qgraphicsproxywidget.cpp b/src/gui/graphicsview/qgraphicsproxywidget.cpp index c8f332572..f831d0881 100644 --- a/src/gui/graphicsview/qgraphicsproxywidget.cpp +++ b/src/gui/graphicsview/qgraphicsproxywidget.cpp @@ -273,12 +273,12 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent pos = mapToReceiver(pos, receiver); // Send mouse event. - QMouseEvent *mouseEvent = QMouseEvent::createExtendedMouseEvent(type, pos, - receiver->mapToGlobal(pos.toPoint()), event->button(), - event->buttons(), event->modifiers()); + QMouseEvent mouseEvent = QMouseEvent(type, pos, + receiver->mapToGlobal(pos.toPoint()), event->button(), + event->buttons(), event->modifiers()); QWidget *embeddedMouseGrabberPtr = (QWidget *)embeddedMouseGrabber; - QApplicationPrivate::sendMouseEvent(receiver, mouseEvent, alienWidget, widget, + QApplicationPrivate::sendMouseEvent(receiver, &mouseEvent, alienWidget, widget, &embeddedMouseGrabberPtr, lastWidgetUnderMouse, event->spontaneous()); embeddedMouseGrabber = embeddedMouseGrabberPtr; @@ -301,8 +301,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent #endif } - event->setAccepted(mouseEvent->isAccepted()); - delete mouseEvent; + event->setAccepted(mouseEvent.isAccepted()); } void QGraphicsProxyWidgetPrivate::sendWidgetKeyEvent(QKeyEvent *event) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index d4544ed48..216d68d59 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -3391,9 +3391,9 @@ bool QGraphicsScene::event(QEvent *event) d->dispatchHoverEvent(hoverEvent); break; } - case QEvent::Leave: + case QEvent::GraphicsSceneLeave: // hackieshly unpacking the viewport pointer from the leave event. - d->leaveScene(reinterpret_cast(event->d)); + d->leaveScene(static_cast(event)); break; case QEvent::GraphicsSceneHelp: helpEvent(static_cast(event)); @@ -3865,11 +3865,12 @@ bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEv Handles all actions necessary to clean up the scene when the mouse leaves the view. */ -void QGraphicsScenePrivate::leaveScene(QWidget *viewport) +void QGraphicsScenePrivate::leaveScene(QGraphicsSceneEvent *event) { #ifndef QT_NO_TOOLTIP QToolTip::hideText(); #endif + QWidget *viewport = event->widget(); QGraphicsView *view = qobject_cast(viewport->parent()); // Send HoverLeave events to all existing hover items, topmost first. QGraphicsSceneHoverEvent hoverEvent; diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index 55afe614d..ab6415e2c 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -192,7 +192,7 @@ public: bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent); bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const; - void leaveScene(QWidget *viewport); + void leaveScene(QGraphicsSceneEvent *leaveEvent); void cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest, QGraphicsSceneDragDropEvent *source); diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 0ff34b597..dcf87da04 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -2672,13 +2672,15 @@ bool QGraphicsView::viewportEvent(QEvent *event) return QAbstractScrollArea::viewportEvent(event); switch (event->type()) { - case QEvent::Enter: + case QEvent::Enter: { QApplication::sendEvent(d->scene, event); break; - case QEvent::WindowActivate: + } + case QEvent::WindowActivate: { QApplication::sendEvent(d->scene, event); break; - case QEvent::WindowDeactivate: + } + case QEvent::WindowDeactivate: { // ### This is a temporary fix for until we get proper mouse // grab events. mouseGrabberItem should be set to 0 if we lose // the mouse grab. @@ -2687,20 +2689,23 @@ bool QGraphicsView::viewportEvent(QEvent *event) d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.first()); QApplication::sendEvent(d->scene, event); break; - case QEvent::Show: + } + case QEvent::Show: { if (d->scene && isActiveWindow()) { QEvent windowActivate(QEvent::WindowActivate); QApplication::sendEvent(d->scene, &windowActivate); } break; - case QEvent::Hide: + } + case QEvent::Hide: { // spontaneous event will generate a WindowDeactivate. if (!event->spontaneous() && d->scene && isActiveWindow()) { QEvent windowDeactivate(QEvent::WindowDeactivate); QApplication::sendEvent(d->scene, &windowDeactivate); } break; - case QEvent::Leave: + } + case QEvent::Leave: { // ### This is a temporary fix for until we get proper mouse grab // events. activeMouseGrabberItem should be set to 0 if we lose the // mouse grab. @@ -2712,10 +2717,11 @@ bool QGraphicsView::viewportEvent(QEvent *event) } d->useLastMouseEvent = false; // a hack to pass a viewport pointer to the scene inside the leave event - Q_ASSERT(event->d == 0); - event->d = reinterpret_cast(viewport()); - QApplication::sendEvent(d->scene, event); + QGraphicsSceneEvent leaveEvent(QEvent::GraphicsSceneLeave); + leaveEvent.setWidget(viewport()); + QApplication::sendEvent(d->scene, &leaveEvent); break; + } #ifndef QT_NO_TOOLTIP case QEvent::ToolTip: { QHelpEvent *toolTip = static_cast(event); @@ -2728,7 +2734,7 @@ bool QGraphicsView::viewportEvent(QEvent *event) return true; } #endif - case QEvent::Paint: + case QEvent::Paint: { // Reset full update d->fullUpdatePending = false; d->dirtyScrollOffset = QPoint(); @@ -2749,6 +2755,7 @@ bool QGraphicsView::viewportEvent(QEvent *event) } } break; + } case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index ae36884f0..4dd7f805a 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -3735,7 +3735,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) ge.t = gestureEvent->t; ge.spont = gestureEvent->spont; ge.m_accept = wasAccepted; - ge.d_func()->accepted = gestureEvent->d_func()->accepted; + ge.m_accepted = gestureEvent->m_accepted; res = d->notify_helper(w, &ge); gestureEvent->spont = false; eventAccepted = ge.isAccepted(); @@ -3745,7 +3745,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) // packed into a single QEvent depends on not consuming the event if (eventAccepted || ge.isAccepted(g)) { // if the gesture was accepted, mark the target widget for it - gestureEvent->d_func()->targetWidgets[g->gestureType()] = w; + gestureEvent->m_targetWidgets[g->gestureType()] = w; gestureEvent->setAccepted(g, true); } else { // if the gesture was explicitly ignored by the application, diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index 309b5f3aa..f35bb86f2 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -2681,7 +2681,7 @@ int QApplication::x11ProcessEvent(XEvent* event) qt_x11Data->xdndHandleSelectionRequest(req); } else if (qt_clipboard) { - QClipboardEvent e(reinterpret_cast(event)); + QClipboardEvent e(event); QApplication::sendSpontaneousEvent(qt_clipboard, &e); } break; @@ -2693,7 +2693,7 @@ int QApplication::x11ProcessEvent(XEvent* event) break; if (qt_clipboard && !qt_x11Data->use_xfixes) { - QClipboardEvent e(reinterpret_cast(event)); + QClipboardEvent e(event); QApplication::sendSpontaneousEvent(qt_clipboard, &e); } break; @@ -2706,7 +2706,7 @@ int QApplication::x11ProcessEvent(XEvent* event) break; if (qt_clipboard) { - QClipboardEvent e(reinterpret_cast(event)); + QClipboardEvent e(event); QApplication::sendSpontaneousEvent(qt_clipboard, &e); } break; diff --git a/src/gui/kernel/qclipboard_x11.cpp b/src/gui/kernel/qclipboard_x11.cpp index 9f4701078..ad929b781 100644 --- a/src/gui/kernel/qclipboard_x11.cpp +++ b/src/gui/kernel/qclipboard_x11.cpp @@ -77,7 +77,8 @@ #include "qelapsedtimer.h" #include "qvariant.h" #include "qdnd_p.h" -#include +#include "qwidget_p.h" +#include "qevent_p.h" QT_BEGIN_NAMESPACE @@ -909,7 +910,7 @@ bool QClipboard::event(QEvent *e) return QObject::event(e); } - XEvent *xevent = (XEvent *)(((QClipboardEvent *)e)->data()); + XEvent *xevent = static_cast(e)->m_event; Display *dpy = qt_x11Data->display; if (!xevent) { diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 3b7074611..baecc16f3 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -168,6 +168,13 @@ QMouseEvent::QMouseEvent(Type type, const QPoint &position, Qt::MouseButton butt g = QCursor::pos(); } +QMouseEvent::QMouseEvent(Type type, const QPointF &position, Qt::MouseButton button, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) + : QInputEvent(type, modifiers), p(position), b(button), mouseState(buttons) +{ + g = QCursor::pos(); +} + /*! \internal */ @@ -200,22 +207,27 @@ QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos, : QInputEvent(type, modifiers), p(pos), g(globalPos), b(button), mouseState(buttons) {} -/*! - \internal -*/ -QMouseEvent *QMouseEvent::createExtendedMouseEvent(Type type, const QPointF &pos, - const QPoint &globalPos, Qt::MouseButton button, - Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) -{ - return new QMouseEventEx(type, pos, globalPos, button, buttons, modifiers); -} +QMouseEvent::QMouseEvent(Type type, const QPointF &pos, const QPointF &globalPos, + Qt::MouseButton button, Qt::MouseButtons buttons, + Qt::KeyboardModifiers modifiers) + : QInputEvent(type, modifiers), p(pos), g(globalPos), b(button), mouseState(buttons) +{} /*! - \fn bool QMouseEvent::hasExtendedInfo() const - \internal + \fn const QPoint &QMouseEvent::pos() const + + Returns the position of the mouse cursor, relative to the widget + that received the event. + + If you move the widget as a result of the mouse event, use the + global position returned by globalPos() to avoid a shaking + motion. + + \sa x() y() globalPos() */ /*! + \fn const QPointF &QMouseEvent::posF() const \since 4.4 Returns the position of the mouse cursor as a QPointF, relative to the @@ -227,44 +239,22 @@ QMouseEvent *QMouseEvent::createExtendedMouseEvent(Type type, const QPointF &pos \sa x() y() pos() globalPos() */ -QPointF QMouseEvent::posF() const -{ - return hasExtendedInfo() ? reinterpret_cast(this)->posF : QPointF(pos()); -} - -/*! - \internal -*/ -QMouseEventEx::QMouseEventEx(Type type, const QPointF &pos, const QPoint &globalPos, - Qt::MouseButton button, Qt::MouseButtons buttons, - Qt::KeyboardModifiers modifiers) - : QMouseEvent(type, pos.toPoint(), globalPos, button, buttons, modifiers), posF(pos) -{ - d = reinterpret_cast(this); -} /*! - \internal -*/ -QMouseEventEx::~QMouseEventEx() -{ -} - -/*! - \fn const QPoint &QMouseEvent::pos() const - - Returns the position of the mouse cursor, relative to the widget - that received the event. + \fn const QPoint &QMouseEvent::globalPos() const - If you move the widget as a result of the mouse event, use the - global position returned by globalPos() to avoid a shaking - motion. + Returns the global position of the mouse cursor \e{at the time + of the event}. This is important on asynchronous window systems + like X11. Whenever you move your widgets around in response to + mouse events, globalPos() may differ a lot from the current + pointer position QCursor::pos(), and from + QWidget::mapToGlobal(pos()). - \sa x() y() globalPos() + \sa globalX() globalY() */ /*! - \fn const QPoint &QMouseEvent::globalPos() const + \fn const QPointF &QMouseEvent::globalPosF() const Returns the global position of the mouse cursor \e{at the time of the event}. This is important on asynchronous window systems @@ -446,6 +436,12 @@ QHoverEvent::QHoverEvent(Type type, const QPoint &pos, const QPoint &oldPos) { } +QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos) + : QEvent(type), p(pos), op(oldPos) +{ +} + + /*! \internal */ @@ -516,6 +512,14 @@ QWheelEvent::QWheelEvent(const QPoint &pos, int delta, g = QCursor::pos(); } +QWheelEvent::QWheelEvent(const QPointF &pos, int delta, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, + Qt::Orientation orient) + : QInputEvent(Wheel, modifiers), p(pos), d(delta), mouseState(buttons), o(orient) +{ + g = QCursor::pos(); +} + /*! \internal */ @@ -541,6 +545,12 @@ QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), d(delta), mouseState(buttons), o(orient) {} +QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, + Qt::Orientation orient) + : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), d(delta), mouseState(buttons), o(orient) +{} + #endif // QT_NO_WHEELEVENT /*! @@ -2087,97 +2097,6 @@ QShowEvent::~QShowEvent() Use QDropEvent::encodedData(). */ -/*! - \class QFileOpenEvent - \brief The QFileOpenEvent class provides an event that will be - sent when there is a request to open a file or a URL. - - \ingroup events - - File open events will be sent to the QApplication::instance() - when the operating system requests that a file or URL should be opened. - This is a high-level event that can be caused by different user actions - depending on the user's desktop environment; for example, double - clicking on an file icon in the Finder on Mac OS X. - - This event is only used to notify the application of a request. - It may be safely ignored. - - \note This class is currently supported for Mac OS X only. -*/ - -QFileOpenEventPrivate::~QFileOpenEventPrivate() -{ -} - -/*! - \internal - - Constructs a file open event for the given \a file. -*/ -QFileOpenEvent::QFileOpenEvent(const QString &file) - : QEvent(FileOpen), f(file) -{ - d = reinterpret_cast(new QFileOpenEventPrivate(QUrl::fromLocalFile(file))); -} - -/*! - \internal - - Constructs a file open event for the given \a url. -*/ -QFileOpenEvent::QFileOpenEvent(const QUrl &url) - : QEvent(FileOpen) -{ - d = reinterpret_cast(new QFileOpenEventPrivate(url)); - f = url.toLocalFile(); -} - - -/*! \internal -*/ -QFileOpenEvent::~QFileOpenEvent() -{ - delete reinterpret_cast(d); -} - -/*! - \fn QString QFileOpenEvent::file() const - - Returns the file that is being opened. -*/ - -/*! - \fn QUrl QFileOpenEvent::url() const - - Returns the url that is being opened. - - \since 4.6 -*/ -QUrl QFileOpenEvent::url() const -{ - return reinterpret_cast(d)->url; -} - -/*! - \fn bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const - - Opens a QFile on the \a file referenced by this event in the mode specified - by \a flags. Returns true if successful; otherwise returns false. - - This is necessary as some files cannot be opened by name, but require specific - information stored in this event. - For example, if this QFileOpenEvent contains a request to open a Symbian data caged file, - the QFile could only be opened from the Symbian RFile used in the construction of this event. - - \since 4.8 -*/ -bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const -{ - file.setFileName(f); - return file.open(flags); -} - #ifndef QT_NO_TOOLBAR /*! \internal @@ -2332,8 +2251,6 @@ static const char *eventClassName(QEvent::Type t) return "QEnterEvent"; case QEvent::Close: return "QCloseEvent"; - case QEvent::FileOpen: - return "QFileOpenEvent"; #ifndef QT_NO_GESTURES case QEvent::NativeGesture: return "QNativeGestureEvent"; @@ -2368,6 +2285,7 @@ static const char *eventClassName(QEvent::Type t) case QEvent::GraphicsSceneHoverEnter: case QEvent::GraphicsSceneHoverMove: case QEvent::GraphicsSceneHoverLeave: + case QEvent::GraphicsSceneLeave: case QEvent::GraphicsSceneHelp: case QEvent::GraphicsSceneDragEnter: case QEvent::GraphicsSceneDragMove: @@ -2583,10 +2501,9 @@ QDebug operator<<(QDebug dbg, const QEvent *e) { \sa QClipboard */ -QClipboardEvent::QClipboardEvent(QEventPrivate *data) - : QEvent(QEvent::Clipboard) +QClipboardEvent::QClipboardEvent(XEvent *event) + : QEvent(QEvent::Clipboard), m_event(event) { - d = data; } QClipboardEvent::~QClipboardEvent() @@ -2656,15 +2573,14 @@ QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s) QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s, bool isOverride) : QEvent(WindowStateChange), ostate(s) { - if (isOverride) - d = (QEventPrivate*)(this); + m_override = isOverride; } /*! \internal */ bool QWindowStateChangeEvent::isOverride() const { - return (d != 0); + return m_override; } /*! \internal @@ -3346,9 +3262,8 @@ QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::T Creates new QGestureEvent containing a list of \a gestures. */ QGestureEvent::QGestureEvent(const QList &gestures) - : QEvent(QEvent::Gesture) + : QEvent(QEvent::Gesture), m_gestures(gestures), m_widget(Q_NULLPTR) { - d = reinterpret_cast(new QGestureEventPrivate(gestures)); } /*! @@ -3356,7 +3271,6 @@ QGestureEvent::QGestureEvent(const QList &gestures) */ QGestureEvent::~QGestureEvent() { - delete reinterpret_cast(d); } /*! @@ -3364,7 +3278,7 @@ QGestureEvent::~QGestureEvent() */ QList QGestureEvent::gestures() const { - return d_func()->gestures; + return m_gestures; } /*! @@ -3372,10 +3286,9 @@ QList QGestureEvent::gestures() const */ QGesture *QGestureEvent::gesture(Qt::GestureType type) const { - const QGestureEventPrivate *d = d_func(); - for(int i = 0; i < d->gestures.size(); ++i) - if (d->gestures.at(i)->gestureType() == type) - return d->gestures.at(i); + for(int i = 0; i < m_gestures.size(); ++i) + if (m_gestures.at(i)->gestureType() == type) + return m_gestures.at(i); return 0; } @@ -3385,7 +3298,7 @@ QGesture *QGestureEvent::gesture(Qt::GestureType type) const QList QGestureEvent::activeGestures() const { QList gestures; - foreach (QGesture *gesture, d_func()->gestures) { + foreach (QGesture *gesture, m_gestures) { if (gesture->state() != Qt::GestureCanceled) gestures.append(gesture); } @@ -3398,7 +3311,7 @@ QList QGestureEvent::activeGestures() const QList QGestureEvent::canceledGestures() const { QList gestures; - foreach (QGesture *gesture, d_func()->gestures) { + foreach (QGesture *gesture, m_gestures) { if (gesture->state() == Qt::GestureCanceled) gestures.append(gesture); } @@ -3480,7 +3393,7 @@ bool QGestureEvent::isAccepted(QGesture *gesture) const void QGestureEvent::setAccepted(Qt::GestureType gestureType, bool value) { setAccepted(false); - d_func()->accepted[gestureType] = value; + m_accepted[gestureType] = value; } /*! @@ -3517,7 +3430,7 @@ void QGestureEvent::ignore(Qt::GestureType gestureType) */ bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const { - return d_func()->accepted.value(gestureType, true); + return m_accepted.value(gestureType, true); } /*! @@ -3527,7 +3440,7 @@ bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const */ void QGestureEvent::setWidget(QWidget *widget) { - d_func()->widget = widget; + m_widget = widget; } /*! @@ -3535,7 +3448,7 @@ void QGestureEvent::setWidget(QWidget *widget) */ QWidget *QGestureEvent::widget() const { - return d_func()->widget; + return m_widget; } #ifndef QT_NO_GRAPHICSVIEW @@ -3562,22 +3475,6 @@ QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const } #endif //QT_NO_GRAPHICSVIEW -/*! - \internal -*/ -QGestureEventPrivate *QGestureEvent::d_func() -{ - return reinterpret_cast(d); -} - -/*! - \internal -*/ -const QGestureEventPrivate *QGestureEvent::d_func() const -{ - return reinterpret_cast(d); -} - #ifdef Q_NO_USING_KEYWORD /*! \fn void QGestureEvent::setAccepted(bool accepted) diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index abb9b7deb..25fa7f21f 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -52,12 +51,6 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE - -class QAction; -#ifndef QT_NO_GESTURES -class QGesture; -#endif - class Q_GUI_EXPORT QInputEvent : public QEvent { public: @@ -74,28 +67,29 @@ class Q_GUI_EXPORT QMouseEvent : public QInputEvent public: QMouseEvent(Type type, const QPoint &pos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); + QMouseEvent(Type type, const QPointF &pos, Qt::MouseButton button, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); + QMouseEvent(Type type, const QPointF &pos, const QPointF &globalPos, + Qt::MouseButton button, Qt::MouseButtons buttons, + Qt::KeyboardModifiers modifiers); ~QMouseEvent(); - inline const QPoint &pos() const { return p; } - inline const QPoint &globalPos() const { return g; } - inline int x() const { return p.x(); } - inline int y() const { return p.y(); } - inline int globalX() const { return g.x(); } - inline int globalY() const { return g.y(); } + inline const QPoint pos() const { return p.toPoint(); } + inline const QPointF &posF() const { return p; } + inline const QPoint globalPos() const { return g.toPoint(); } + inline const QPointF &globalPoFs() const { return g; } + inline int x() const { return qRound(p.x()); } + inline int y() const { return qRound(p.y()); } + inline int globalX() const { return qRound(g.x()); } + inline int globalY() const { return qRound(g.y()); } inline Qt::MouseButton button() const { return b; } inline Qt::MouseButtons buttons() const { return mouseState; } - static QMouseEvent *createExtendedMouseEvent(Type type, const QPointF &pos, - const QPoint &globalPos, Qt::MouseButton button, - Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); - inline bool hasExtendedInfo() const { return reinterpret_cast(d) == this; } - QPointF posF() const; - protected: - QPoint p, g; + QPointF p, g; Qt::MouseButton b; Qt::MouseButtons mouseState; }; @@ -104,13 +98,16 @@ class Q_GUI_EXPORT QHoverEvent : public QEvent { public: QHoverEvent(Type type, const QPoint &pos, const QPoint &oldPos); + QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos); ~QHoverEvent(); - inline const QPoint &pos() const { return p; } - inline const QPoint &oldPos() const { return op; } + inline const QPoint pos() const { return p.toPoint(); } + inline const QPointF &posF() const { return p; } + inline const QPoint oldPos() const { return op.toPoint(); } + inline const QPointF &oldPosF() const { return op; } protected: - QPoint p, op; + QPointF p, op; }; #ifndef QT_NO_WHEELEVENT @@ -120,25 +117,32 @@ public: QWheelEvent(const QPoint &pos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient = Qt::Vertical); + QWheelEvent(const QPointF &pos, int delta, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, + Qt::Orientation orient = Qt::Vertical); QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient = Qt::Vertical); + QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, + Qt::Orientation orient = Qt::Vertical); ~QWheelEvent(); inline int delta() const { return d; } - inline const QPoint &pos() const { return p; } - inline const QPoint &globalPos() const { return g; } - inline int x() const { return p.x(); } - inline int y() const { return p.y(); } - inline int globalX() const { return g.x(); } - inline int globalY() const { return g.y(); } + inline const QPoint pos() const { return p.toPoint(); } + inline const QPointF &posF() const { return p; } + inline const QPoint globalPos() const { return g.toPoint(); } + inline const QPointF &globalPosF() const { return g; } + inline int x() const { return qRound(p.x()); } + inline int y() const { return qRound(p.y()); } + inline int globalX() const { return qRound(g.x()); } + inline int globalY() const { return qRound(g.y()); } inline Qt::MouseButtons buttons() const { return mouseState; } Qt::Orientation orientation() const { return o; } protected: - QPoint p; - QPoint g; + QPointF p, g; int d; Qt::MouseButtons mouseState; Qt::Orientation o; @@ -453,6 +457,9 @@ private: #endif #ifndef QT_NO_ACTION + +class QAction; + class Q_GUI_EXPORT QActionEvent : public QEvent { QAction *act, *bef; @@ -465,20 +472,6 @@ public: }; #endif -class Q_GUI_EXPORT QFileOpenEvent : public QEvent -{ -public: - QFileOpenEvent(const QString &file); - QFileOpenEvent(const QUrl &url); - ~QFileOpenEvent(); - - inline QString file() const { return f; } - QUrl url() const; - bool openFile(QFile &file, QIODevice::OpenMode flags) const; -private: - QString f; -}; - #ifndef QT_NO_TOOLBAR class Q_GUI_EXPORT QToolBarChangeEvent : public QEvent { @@ -509,17 +502,6 @@ protected: }; #endif -#ifndef QT_NO_CLIPBOARD -class Q_GUI_EXPORT QClipboardEvent : public QEvent -{ -public: - QClipboardEvent(QEventPrivate *data); - ~QClipboardEvent(); - - QEventPrivate *data() { return d; } -}; -#endif - class Q_GUI_EXPORT QWindowStateChangeEvent: public QEvent { public: @@ -531,6 +513,7 @@ public: bool isOverride() const; private: + bool m_override; Qt::WindowStates ostate; }; @@ -643,8 +626,10 @@ protected: }; #ifndef QT_NO_GESTURES + class QGesture; class QGestureEventPrivate; + class Q_GUI_EXPORT QGestureEvent : public QEvent { public: @@ -688,8 +673,10 @@ public: #endif private: - QGestureEventPrivate *d_func(); - const QGestureEventPrivate *d_func() const; + QList m_gestures; + QWidget *m_widget; + QMap m_accepted; + QMap m_targetWidgets; friend class QApplication; friend class QGestureManager; diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 47ba57fb5..3a59dd396 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -36,6 +36,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -50,20 +51,6 @@ QT_BEGIN_NAMESPACE // We mean it. // -// ### Qt 5: remove -class QMouseEventEx : public QMouseEvent -{ -public: - QMouseEventEx(Type type, const QPointF &pos, const QPoint &globalPos, - Qt::MouseButton button, Qt::MouseButtons buttons, - Qt::KeyboardModifiers modifiers); - ~QMouseEventEx(); - -protected: - QPointF posF; - friend class QMouseEvent; -}; - class QTouchEventTouchPointPrivate { public: @@ -117,33 +104,19 @@ public: QPoint position; float angle; }; - -class QGestureEventPrivate -{ -public: - inline QGestureEventPrivate(const QList &list) - : gestures(list), widget(0) - { - } - - QList gestures; - QWidget *widget; - QMap accepted; - QMap targetWidgets; -}; #endif // QT_NO_GESTURES -class QFileOpenEventPrivate + +#ifndef QT_NO_CLIPBOARD +class Q_GUI_EXPORT QClipboardEvent : public QEvent { public: - inline QFileOpenEventPrivate(const QUrl &url) - : url(url) - { - } - ~QFileOpenEventPrivate(); + QClipboardEvent(XEvent *event); + ~QClipboardEvent(); - QUrl url; + XEvent* m_event; }; +#endif QT_END_NAMESPACE diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index 8b6d3ff45..d9b57bfc4 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -639,7 +639,7 @@ void QGestureManager::deliverEvents(const QSet &gestures, bool eventAccepted = event.isAccepted(); foreach(QGesture *gesture, event.gestures()) { if (eventAccepted || event.isAccepted(gesture)) { - QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); + QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0); Q_ASSERT(w); DEBUG() << "override event: gesture was accepted:" << gesture << w; QList &gestures = normalStartedGestures[w]; @@ -666,7 +666,7 @@ void QGestureManager::deliverEvents(const QSet &gestures, foreach (QGesture *gesture, event.gestures()) { if (gesture->state() == Qt::GestureStarted && (eventAccepted || event.isAccepted(gesture))) { - QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); + QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0); Q_ASSERT(w); DEBUG() << "started gesture was delivered and accepted by" << w; m_gestureTargets[gesture] = w; diff --git a/src/shared/qclass_lib_map.h b/src/shared/qclass_lib_map.h index 9c0648fd8..f5cc9bdd6 100644 --- a/src/shared/qclass_lib_map.h +++ b/src/shared/qclass_lib_map.h @@ -415,10 +415,8 @@ static const ClassInfoEntry qclass_lib_map[] = { { "QStatusTipEvent", "QtGui/qevent.h"}, { "QWhatsThisClickedEvent", "QtGui/qevent.h"}, { "QActionEvent", "QtGui/qevent.h"}, - { "QFileOpenEvent", "QtGui/qevent.h"}, { "QToolBarChangeEvent", "QtGui/qevent.h"}, { "QShortcutEvent", "QtGui/qevent.h"}, - { "QClipboardEvent", "QtGui/qevent.h"}, { "QWindowStateChangeEvent", "QtGui/qevent.h"}, { "QTouchEvent", "QtGui/qevent.h"}, { "TouchPoint", "QtGui/qevent.h"}, @@ -696,6 +694,6 @@ static const ClassInfoEntry qclass_lib_map[] = { { "QFormBuilder", "QtUiTools/formbuilder.h"}, { "QUiLoader", "QtUiTools/quiloader.h"}, }; -static const int qclass_lib_count = 690; +static const int qclass_lib_count = 688; #endif diff --git a/src/tools/designer/qdesigner.cpp b/src/tools/designer/qdesigner.cpp index f10847e7b..d8fecd4eb 100644 --- a/src/tools/designer/qdesigner.cpp +++ b/src/tools/designer/qdesigner.cpp @@ -239,12 +239,6 @@ void QDesigner::initialize() bool QDesigner::event(QEvent *ev) { switch (ev->type()) { - case QEvent::FileOpen: - // Set it true first since, if it's a Qt 3 form, the messagebox from convert will fire the timer. - m_suppressNewFormShow = true; - if (!m_workbench->readInForm(static_cast(ev)->file())) - m_suppressNewFormShow = false; - return true; case QEvent::Close: { bool eaten = true; QCloseEvent *closeEvent = static_cast(ev); -- 2.11.0