diff options
author | Martin Smith <msmith@trolltech.com> | 2010-04-07 11:25:33 (GMT) |
---|---|---|
committer | Martin Smith <msmith@trolltech.com> | 2010-04-07 11:25:33 (GMT) |
commit | f23160f2b8a76619a7e8721aec880be3cf25a7a0 (patch) | |
tree | 81d24cdec09cad50bd29dee3953b2371e2d4688b | |
parent | 3330356b3cc2403cb855808a424d19c764466981 (diff) | |
parent | bb838213a33c2f493ae9bd9a16cc4968d64dc2da (diff) | |
download | Qt-f23160f2b8a76619a7e8721aec880be3cf25a7a0.zip Qt-f23160f2b8a76619a7e8721aec880be3cf25a7a0.tar.gz Qt-f23160f2b8a76619a7e8721aec880be3cf25a7a0.tar.bz2 |
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7
22 files changed, 564 insertions, 169 deletions
diff --git a/qmake/option.cpp b/qmake/option.cpp index d7c5397..49030c3 100644 --- a/qmake/option.cpp +++ b/qmake/option.cpp @@ -613,7 +613,7 @@ bool Option::postProcessProject(QMakeProject *project) QString Option::fixString(QString string, uchar flags) { - const QString orig_string = string; + //const QString orig_string = string; static QHash<FixStringCacheKey, QString> *cache = 0; if(!cache) { cache = new QHash<FixStringCacheKey, QString>; diff --git a/qmake/qmake.pri b/qmake/qmake.pri index 0821f00..281417c 100644 --- a/qmake/qmake.pri +++ b/qmake/qmake.pri @@ -14,6 +14,7 @@ SOURCES += project.cpp property.cpp main.cpp generators/makefile.cpp \ generators/win32/msvc_nmake.cpp generators/projectgenerator.cpp \ generators/win32/msvc_vcproj.cpp \ generators/win32/msvc_objectmodel.cpp \ + generators/symbian/symbiancommon.cpp \ generators/symbian/symmake.cpp \ generators/symbian/symmake_abld.cpp \ generators/symbian/symmake_sbsv2.cpp \ @@ -28,6 +29,7 @@ HEADERS += project.h property.h generators/makefile.h \ generators/xmloutput.h generators/win32/borland_bmake.h generators/win32/msvc_nmake.h \ generators/win32/msvc_vcproj.h \ generators/win32/mingw_make.h generators/win32/msvc_objectmodel.h \ + generators/symbian/symbiancommon.h \ generators/symbian/symmake.h \ generators/symbian/symmake_abld.h \ generators/symbian/symmake_sbsv2.h \ diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp index 52d2cea..1ef513c 100644 --- a/src/corelib/tools/qsimd.cpp +++ b/src/corelib/tools/qsimd.cpp @@ -42,6 +42,10 @@ #include "qsimd_p.h" #include <QByteArray> +#if defined(Q_OS_WINCE) +#include <windows.h> +#endif + QT_BEGIN_NAMESPACE uint qDetectCPUFeatures() diff --git a/src/gui/egl/qegl.cpp b/src/gui/egl/qegl.cpp index 498245c..6f215cc 100644 --- a/src/gui/egl/qegl.cpp +++ b/src/gui/egl/qegl.cpp @@ -556,7 +556,7 @@ EGLDisplay QEgl::display() } // Resolve the egl extension function pointers: -#if !defined(EGL_KHR_image) && !defined(EGL_KHR_image_base) +#if (defined(EGL_KHR_image) || defined(EGL_KHR_image_base)) && !defined(EGL_EGLEXT_PROTOTYPES) if (QEgl::hasExtension("EGL_KHR_image") || QEgl::hasExtension("EGL_KHR_image_base")) { eglCreateImageKHR = (_eglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); eglDestroyImageKHR = (_eglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index f106b3d..d6daf4d 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -7112,7 +7112,8 @@ void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) // Root items that ignore transformations need to // calculate their diff by mapping viewport coordinates // directly to parent coordinates. - QTransform viewToParentTransform = (item->transform().translate(item->d_ptr->pos.x(), item->d_ptr->pos.y())) + // COMBINE + QTransform viewToParentTransform = (item->d_func()->transformData->computedFullTransform().translate(item->d_ptr->pos.x(), item->d_ptr->pos.y())) * (item->sceneTransform() * view->viewportTransform()).inverted(); currentParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->screenPos()))); buttonDownParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton)))); diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 233c58d..ce1d6d3 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -5704,9 +5704,10 @@ void QImage::setAlphaChannel(const QImage &alphaChannel) return; } - detach(); - - *this = convertToFormat(QImage::Format_ARGB32_Premultiplied); + if (d->format == QImage::Format_ARGB32_Premultiplied) + detach(); + else + *this = convertToFormat(QImage::Format_ARGB32_Premultiplied); // Slight optimization since alphachannels are returned as 8-bit grays. if (alphaChannel.d->depth == 8 && alphaChannel.isGrayscale()) { diff --git a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h index 129e0a5..ec00915 100644 --- a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h +++ b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h @@ -58,7 +58,6 @@ QT_BEGIN_NAMESPACE extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp extern const QStringList& qEnabledDraggedTypes(); // qmime_mac.cpp -extern bool qt_blockCocoaSettingModalWindowLevel; // qeventdispatcher_mac_p.h Q_GLOBAL_STATIC(QPointer<QWidget>, currentDragTarget); @@ -102,30 +101,6 @@ QT_END_NAMESPACE return !(isPopup || isToolTip || isTool); } -- (void)orderWindow:(NSWindowOrderingMode)orderingMode relativeTo:(NSInteger)otherWindowNumber -{ - if (qt_blockCocoaSettingModalWindowLevel) { - // To avoid windows popping in front while restoring modal sessions - // in the event dispatcher, we block cocoa from ordering this window - // to front. The result of not doing this can be seen if executing - // a native color dialog on top of another executing dialog. - return; - } - [super orderWindow:orderingMode relativeTo:otherWindowNumber]; -} - -- (void)setLevel:(NSInteger)windowLevel -{ - if (qt_blockCocoaSettingModalWindowLevel) { - // To avoid windows popping in front while restoring modal sessions - // in the event dispatcher, we block cocoa from ordering this window - // to front. The result of not doing this can be seen if executing - // a native color dialog on top of another executing dialog. - return; - } - [super setLevel:windowLevel]; -} - - (void)toggleToolbarShown:(id)sender { macSendToolbarChangeEvent([self QT_MANGLE_NAMESPACE(qt_qwidget)]); diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 06eb7ff..9c5380b 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -657,23 +657,33 @@ static int qCocoaViewCount = 0; { if (!qwidget) return; - if (qwidgetprivate->data.in_destructor) return; - QEvent enterEvent(QEvent::Enter); - NSPoint windowPoint = [event locationInWindow]; - NSPoint globalPoint = [[event window] convertBaseToScreen:windowPoint]; - NSPoint viewPoint = [self convertPoint:windowPoint fromView:nil]; + if (!qAppInstance()->activeModalWidget() || QApplicationPrivate::tryModalHelper(qwidget, 0)) { + QEvent enterEvent(QEvent::Enter); + NSPoint windowPoint = [event locationInWindow]; + NSPoint globalPoint = [[event window] convertBaseToScreen:windowPoint]; + NSPoint viewPoint = [self convertPoint:windowPoint fromView:nil]; QApplication::sendEvent(qwidget, &enterEvent); qt_mouseover = qwidget; - // Update cursor and dispatch hover events. + // Update cursor icon: qt_mac_update_cursor_at_global_pos(flipPoint(globalPoint).toPoint()); - if (qwidget->testAttribute(Qt::WA_Hover) && - (!qAppInstance()->activePopupWidget() || qAppInstance()->activePopupWidget() == qwidget->window())) { - QHoverEvent he(QEvent::HoverEnter, QPoint(viewPoint.x, viewPoint.y), QPoint(-1, -1)); - QApplicationPrivate::instance()->notify_helper(qwidget, &he); + + // Send mouse move and hover events as well: + if (!qAppInstance()->activePopupWidget() || qAppInstance()->activePopupWidget() == qwidget->window()) { + if (qwidget->testAttribute(Qt::WA_MouseTracking)) { + NSEvent *mouseEvent = [NSEvent mouseEventWithType:NSMouseMoved + location:windowPoint modifierFlags:[event modifierFlags] timestamp:[event timestamp] + windowNumber:[event windowNumber] context:[event context] eventNumber:[event eventNumber] + clickCount:0 pressure:0]; + qt_mac_handleMouseEvent(self, mouseEvent, QEvent::MouseMove, Qt::NoButton); + } + if (qwidget->testAttribute(Qt::WA_Hover)) { + QHoverEvent he(QEvent::HoverEnter, QPoint(viewPoint.x, viewPoint.y), QPoint(-1, -1)); + QApplicationPrivate::instance()->notify_helper(qwidget, &he); + } } } } diff --git a/src/gui/kernel/qeventdispatcher_mac.mm b/src/gui/kernel/qeventdispatcher_mac.mm index a7f1224..0d93b9f 100644 --- a/src/gui/kernel/qeventdispatcher_mac.mm +++ b/src/gui/kernel/qeventdispatcher_mac.mm @@ -97,11 +97,6 @@ QT_BEGIN_NAMESPACE QT_USE_NAMESPACE /***************************************************************************** - Internal variables and functions - *****************************************************************************/ -bool qt_blockCocoaSettingModalWindowLevel = false; - -/***************************************************************************** Externals *****************************************************************************/ extern void qt_event_request_timer(MacTimerInfo *); //qapplication_mac.cpp @@ -752,7 +747,6 @@ bool QEventDispatcherMacPrivate::interrupt = false; #ifdef QT_MAC_USE_COCOA QStack<QCocoaModalSessionInfo> QEventDispatcherMacPrivate::cocoaModalSessionStack; bool QEventDispatcherMacPrivate::currentExecIsNSAppRun = false; -bool QEventDispatcherMacPrivate::modalSessionsTemporarilyStopped = false; bool QEventDispatcherMacPrivate::nsAppRunCalledByQt = false; bool QEventDispatcherMacPrivate::cleanupModalSessionsNeeded = false; NSModalSession QEventDispatcherMacPrivate::currentModalSessionCached = 0; @@ -788,19 +782,14 @@ void QEventDispatcherMacPrivate::temporarilyStopAllModalSessions() // we need to stop all the modal session first. To avoid changing // the stacking order of the windows while doing so, we put // up a block that is used in QCocoaWindow and QCocoaPanel: - QBoolBlocker block1(blockSendPostedEvents, true); - QBoolBlocker block2(qt_blockCocoaSettingModalWindowLevel, true); - int stackSize = cocoaModalSessionStack.size(); for (int i=stackSize-1; i>=0; --i) { QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; if (info.session) { - [NSApp runModalSession:info.session]; [NSApp endModalSession:info.session]; info.session = 0; } } - modalSessionsTemporarilyStopped = true; currentModalSessionCached = 0; } @@ -834,29 +823,12 @@ NSModalSession QEventDispatcherMacPrivate::currentModalSession() // When creating a modal session cocoa will rearrange the windows. // In order to avoid windows to be put behind another we need to // keep the window level. - { - int level = [window level]; - info.session = [NSApp beginModalSessionForWindow:window]; - [window setLevel:level]; - } + int level = [window level]; + info.session = [NSApp beginModalSessionForWindow:window]; + [window setLevel:level]; } currentModalSessionCached = info.session; } - - if (modalSessionsTemporarilyStopped && currentModalSessionCached) { - // After a call to temporarilyStopAllModalSessions, cocoa have - // now posted events to restore ended modal session windows to - // the correct window level. Those events will be processed - // _after_ our new calls to beginModalSessionForWindow have - // taken effect, which will end up stacking the windows wrong on - // screen. To work around this, we block cocoa from changing the - // stacking order of the windows, and flush out the pending events - // (the block is used in QCocoaWindow and QCocoaPanel): - QBoolBlocker block1(blockSendPostedEvents, true); - QBoolBlocker block2(qt_blockCocoaSettingModalWindowLevel, true); - [NSApp runModalSession:currentModalSessionCached]; - } - modalSessionsTemporarilyStopped = false; return currentModalSessionCached; } diff --git a/src/gui/kernel/qeventdispatcher_mac_p.h b/src/gui/kernel/qeventdispatcher_mac_p.h index 8ac7c65..a0afb84 100644 --- a/src/gui/kernel/qeventdispatcher_mac_p.h +++ b/src/gui/kernel/qeventdispatcher_mac_p.h @@ -176,7 +176,6 @@ public: static bool currentExecIsNSAppRun; static bool nsAppRunCalledByQt; static bool cleanupModalSessionsNeeded; - static bool modalSessionsTemporarilyStopped; static NSModalSession currentModalSessionCached; static NSModalSession currentModalSession(); static void updateChildrenWorksWhenModal(); diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index b1e4c94..a05c7d5 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -882,7 +882,15 @@ void qt_mac_dispatchNCMouseMessage(void * /* NSWindow* */eventWindow, void * /* } } - QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, button, keyMods); + Qt::MouseButtons buttons = 0; + { + UInt32 mac_buttons; + if (GetEventParameter((EventRef)[event eventRef], kEventParamMouseChord, typeUInt32, 0, + sizeof(mac_buttons), 0, &mac_buttons) == noErr) + buttons = qt_mac_get_buttons(mac_buttons); + } + + QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, buttons, keyMods); qt_sendSpontaneousEvent(widgetToGetEvent, &qme); // We don't need to set the implicit grab widget here because we won't diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp index cf545be..9eda0ef 100644 --- a/src/gui/painting/qtextureglyphcache.cpp +++ b/src/gui/painting/qtextureglyphcache.cpp @@ -133,10 +133,13 @@ void QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const while (iter != listItemCoordinates.end()) { Coord c = iter.value(); + m_currentRowHeight = qMax(m_currentRowHeight, c.h + margin * 2); + if (m_cx + c.w > m_w) { // no room on the current line, start new glyph strip m_cx = 0; - m_cy += rowHeight; + m_cy += m_currentRowHeight; + m_currentRowHeight = 0; // New row } if (m_cy + c.h > m_h) { int new_height = m_h*2; @@ -153,14 +156,7 @@ void QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const fillTexture(c, iter.key()); coords.insert(iter.key(), c); - if (m_cx + c.w > m_w) { - m_cx = 0; - m_cy += rowHeight; - } else { - // for the Mono case, glyph_width is 8-bit aligned, - // and therefore so will m_cx - m_cx += c.w; - } + m_cx += c.w; ++iter; } diff --git a/src/gui/painting/qtextureglyphcache_p.h b/src/gui/painting/qtextureglyphcache_p.h index 803e71b..8c2f5b4 100644 --- a/src/gui/painting/qtextureglyphcache_p.h +++ b/src/gui/painting/qtextureglyphcache_p.h @@ -77,7 +77,7 @@ class Q_GUI_EXPORT QTextureGlyphCache : public QFontEngineGlyphCache public: QTextureGlyphCache(QFontEngineGlyphCache::Type type, const QTransform &matrix) : QFontEngineGlyphCache(matrix, type), m_current_fontengine(0), - m_w(0), m_h(0), m_cx(0), m_cy(0) + m_w(0), m_h(0), m_cx(0), m_cy(0), m_currentRowHeight(0) { } virtual ~QTextureGlyphCache() { } @@ -120,6 +120,7 @@ protected: int m_h; // image height int m_cx; // current x int m_cy; // current y + int m_currentRowHeight; // Height of last row }; diff --git a/tests/auto/macnativeevents/expectedeventlist.cpp b/tests/auto/macnativeevents/expectedeventlist.cpp new file mode 100644 index 0000000..b1fb9a6 --- /dev/null +++ b/tests/auto/macnativeevents/expectedeventlist.cpp @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "expectedeventlist.h" +#include <QDebug> +#include <QCoreApplication> +#include <QAbstractEventDispatcher> +#include <QtTest/QtTest> + +ExpectedEventList::ExpectedEventList(QObject *target) + : QObject(target), eventCount(0) +{ + target->installEventFilter(this); + debug = !qgetenv("NATIVEDEBUG").isEmpty(); +} + +ExpectedEventList::~ExpectedEventList() +{ + qDeleteAll(eventList); +} + +void ExpectedEventList::append(QEvent *e) +{ + eventList.append(e); + ++eventCount; +} + +void ExpectedEventList::timerEvent(QTimerEvent *) +{ + timer.stop(); + QAbstractEventDispatcher::instance()->interrupt(); +} + +bool ExpectedEventList::waitForAllEvents(int maxEventWaitTime) +{ + if (eventList.isEmpty()) + return true; + + int eventCount = eventList.size(); + timer.start(maxEventWaitTime, this); + + while (timer.isActive()) { + QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); + if (eventList.isEmpty()) + return true; + + if (eventCount < eventList.size()){ + eventCount = eventList.size(); + timer.start(maxEventWaitTime, this); + } + } + + int eventListNr = eventCount - eventList.size() + 1; + qWarning() << "Stopped waiting for expected event nr" << eventListNr; + return false; +} + +void ExpectedEventList::compareMouseEvents(QEvent *received, QEvent *expected) +{ + QMouseEvent *e1 = static_cast<QMouseEvent *>(received); + QMouseEvent *e2 = static_cast<QMouseEvent *>(expected); + if (e1->pos() == e2->pos() + && (e1->globalPos() == e2->globalPos()) + && (e1->button() == e2->button()) + && (e1->buttons() == e2->buttons()) + && (e1->modifiers() == e2->modifiers())) + return; // equal + + int eventListNr = eventCount - eventList.size(); + if (!debug) { + qWarning() << "Expected event" << eventListNr << "differs from received event:"; + QCOMPARE(e1->pos(), e2->pos()); + QCOMPARE(e1->globalPos(), e2->globalPos()); + QCOMPARE(e1->button(), e2->button()); + QCOMPARE(e1->buttons(), e2->buttons()); + QCOMPARE(e1->modifiers(), e2->modifiers()); + } else { + qWarning() << "*** FAIL *** : Expected event" << eventListNr << "differs from received event:"; + qWarning() << "Received:" << e1 << e1->globalPos(); + qWarning() << "Expected:" << e2 << e2->globalPos(); + } +} + +void ExpectedEventList::compareKeyEvents(QEvent *event1, QEvent *event2) +{ + QKeyEvent *e1 = static_cast<QKeyEvent *>(event1); + QKeyEvent *e2 = static_cast<QKeyEvent *>(event2); + Q_UNUSED(e1); + Q_UNUSED(e2); +} + +bool ExpectedEventList::eventFilter(QObject *, QEvent *received) +{ + if (debug) + qDebug() << received; + if (eventList.isEmpty()) + return false; + + QEvent *expected = eventList.first(); + if (expected->type() == received->type()) { + eventList.removeFirst(); + switch (received->type()) { + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseMove: + case QEvent::MouseButtonDblClick: + case QEvent::NonClientAreaMouseButtonPress: + case QEvent::NonClientAreaMouseButtonRelease: + case QEvent::NonClientAreaMouseButtonDblClick: + case QEvent::NonClientAreaMouseMove: { + compareMouseEvents(received, expected); + break; + } + case QEvent::KeyPress: { + break; + } + case QEvent::KeyRelease: { + break; + } + case QEvent::Resize: { + break; + } + case QEvent::WindowActivate: { + break; + } + case QEvent::WindowDeactivate: { + break; + } + default: + break; + } + if (eventList.isEmpty()) + QAbstractEventDispatcher::instance()->interrupt(); + } + + return false; +} + diff --git a/tests/auto/macnativeevents/expectedeventlist.h b/tests/auto/macnativeevents/expectedeventlist.h new file mode 100644 index 0000000..bd9f358 --- /dev/null +++ b/tests/auto/macnativeevents/expectedeventlist.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef EVENTFILTER +#define EVENTFILTER + +#include <QWidget> +#include <QList> +#include <QEvent> +#include <QBasicTimer> + +class ExpectedEventList : public QObject +{ + QList<QEvent *> eventList; + QBasicTimer timer; + bool debug; + int eventCount; + void timerEvent(QTimerEvent *); + +public: + ExpectedEventList(QObject *target); + ~ExpectedEventList(); + void append(QEvent *e); + bool waitForAllEvents(int timeoutPerEvent = 2000); + bool eventFilter(QObject *obj, QEvent *event); + +private: + void compareMouseEvents(QEvent *event1, QEvent *event2); + void compareKeyEvents(QEvent *event1, QEvent *event2); +}; + +#endif + diff --git a/tests/auto/macnativeevents/macnativeevents.pro b/tests/auto/macnativeevents/macnativeevents.pro index a0293d4..af34942 100644 --- a/tests/auto/macnativeevents/macnativeevents.pro +++ b/tests/auto/macnativeevents/macnativeevents.pro @@ -8,9 +8,9 @@ DEPENDPATH += . INCLUDEPATH += . LIBS += -framework Carbon -HEADERS += qnativeinput.h qnativeplayer.h -SOURCES += qnativeinput.cpp qnativeplayer.cpp qnativeinput_mac.cpp - +HEADERS += qnativeevents.h nativeeventlist.h expectedeventlist.h +SOURCES += qnativeevents.cpp qnativeevents_mac.cpp +SOURCES += expectedeventlist.cpp nativeeventlist.cpp SOURCES += tst_macnativeevents.cpp requires(mac) diff --git a/tests/auto/macnativeevents/qnativeplayer.cpp b/tests/auto/macnativeevents/nativeeventlist.cpp index 92298ef..d5d7b95 100644 --- a/tests/auto/macnativeevents/qnativeplayer.cpp +++ b/tests/auto/macnativeevents/nativeeventlist.cpp @@ -39,22 +39,26 @@ ** ****************************************************************************/ -#include "qnativeplayer.h" +#include "nativeeventlist.h" -QNativePlayer::QNativePlayer() +NativeEventList::NativeEventList(int defaultWaitMs) + : playbackMultiplier(1.0) + , currIndex(-1) + , wait(false) + , defaultWaitMs(defaultWaitMs) { - currIndex = -1; - playbackMultiplier = 1.0; - wait = false; + QString multiplier = qgetenv("NATIVEDEBUG"); + if (!multiplier.isEmpty()) + setTimeMultiplier(multiplier.toFloat()); } -QNativePlayer::~QNativePlayer() +NativeEventList::~NativeEventList() { for (int i=0; i<eventList.size(); i++) delete eventList.takeAt(i).second; } -void QNativePlayer::sendNextEvent() +void NativeEventList::sendNextEvent() { QNativeEvent *e = eventList.at(currIndex).second; if (e) @@ -62,7 +66,7 @@ void QNativePlayer::sendNextEvent() waitNextEvent(); } -void QNativePlayer::waitNextEvent() +void NativeEventList::waitNextEvent() { if (++currIndex >= eventList.size()){ emit done(); @@ -74,12 +78,22 @@ void QNativePlayer::waitNextEvent() QTimer::singleShot(interval * playbackMultiplier, this, SLOT(sendNextEvent())); } -void QNativePlayer::append(int waitMs, QNativeEvent *event) +void NativeEventList::append(QNativeEvent *event) +{ + eventList.append(QPair<int, QNativeEvent *>(defaultWaitMs, event)); +} + +void NativeEventList::append(int waitMs, QNativeEvent *event) { eventList.append(QPair<int, QNativeEvent *>(waitMs, event)); } -void QNativePlayer::play(Playback playback) +void NativeEventList::append(int waitMs) +{ + eventList.append(QPair<int, QNativeEvent *>(waitMs, 0)); +} + +void NativeEventList::play(Playback playback) { waitNextEvent(); @@ -88,52 +102,14 @@ void QNativePlayer::play(Playback playback) QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); } -void QNativePlayer::stop() +void NativeEventList::stop() { wait = false; QAbstractEventDispatcher::instance()->interrupt(); } -// ************************************************************************ - -QEventOutputList::QEventOutputList() -{ - wait = true; -} - -QEventOutputList::~QEventOutputList() +void NativeEventList::setTimeMultiplier(float multiplier) { - qDeleteAll(*this); + playbackMultiplier = multiplier; } -bool QEventOutputList::waitUntilEmpty(int maxEventWaitTime) -{ - int currSize = size(); - QTime time; - time.restart(); - while (wait){ - QCoreApplication::processEvents(QEventLoop::AllEvents, 50); - - if (isEmpty()){ - return true; - } - else if (currSize == size()){ - if (time.elapsed() > maxEventWaitTime){ - return false; - } - } - else{ - currSize = size(); - time.restart(); - } - } - return false; -} - -void QEventOutputList::sleep(int sleepTime) -{ - QTime time; - time.restart(); - while (time.elapsed() < sleepTime) - QCoreApplication::processEvents(QEventLoop::AllEvents, 50); -} diff --git a/tests/auto/macnativeevents/qnativeplayer.h b/tests/auto/macnativeevents/nativeeventlist.h index 61ee162..688665d 100644 --- a/tests/auto/macnativeevents/qnativeplayer.h +++ b/tests/auto/macnativeevents/nativeeventlist.h @@ -43,22 +43,25 @@ #define Q_NATIVE_PLAYBACK #include <QtCore> -#include "qnativeinput.h" +#include "qnativeevents.h" -class QNativePlayer : public QObject +class NativeEventList : public QObject { Q_OBJECT; public: enum Playback {ReturnImmediately, WaitUntilFinished}; - QNativePlayer(); - ~QNativePlayer(); + NativeEventList(int defaultWaitMs = 20); + ~NativeEventList(); + void append(QNativeEvent *event); void append(int waitMs, QNativeEvent *event = 0); + void append(int waitMs); + void play(Playback playback = WaitUntilFinished); void stop(); - float playbackMultiplier; + void setTimeMultiplier(float multiplier); signals: void done(); @@ -66,27 +69,14 @@ signals: private slots: void sendNextEvent(); - private: +private: void waitNextEvent(); QList<QPair<int, QNativeEvent *> > eventList; + float playbackMultiplier; int currIndex; bool wait; + int defaultWaitMs; }; -// ****************************************************************** - -class QEventOutputList : public QList<QEvent *> -{ -public: - QEventOutputList(); - ~QEventOutputList(); - bool waitUntilEmpty(int maxEventWaitTime = 1000); - bool wait; - - // Useful method. Just sleep and process events: - static void sleep(int sleepTime); -}; - - #endif diff --git a/tests/auto/macnativeevents/qnativeinput.cpp b/tests/auto/macnativeevents/qnativeevents.cpp index c9462a6..cb4b82e 100644 --- a/tests/auto/macnativeevents/qnativeinput.cpp +++ b/tests/auto/macnativeevents/qnativeevents.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qnativeinput.h" +#include "qnativeevents.h" QNativeInput::QNativeInput(bool subscribe) { diff --git a/tests/auto/macnativeevents/qnativeinput.h b/tests/auto/macnativeevents/qnativeevents.h index a98e4e4..a98e4e4 100644 --- a/tests/auto/macnativeevents/qnativeinput.h +++ b/tests/auto/macnativeevents/qnativeevents.h diff --git a/tests/auto/macnativeevents/qnativeinput_mac.cpp b/tests/auto/macnativeevents/qnativeevents_mac.cpp index 143a633..6c04bf3 100644 --- a/tests/auto/macnativeevents/qnativeinput_mac.cpp +++ b/tests/auto/macnativeevents/qnativeevents_mac.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qnativeinput.h" +#include "qnativeevents.h" #include <Carbon/Carbon.h> #include <QtCore> diff --git a/tests/auto/macnativeevents/tst_macnativeevents.cpp b/tests/auto/macnativeevents/tst_macnativeevents.cpp index ccadd54..08ab9e6 100644 --- a/tests/auto/macnativeevents/tst_macnativeevents.cpp +++ b/tests/auto/macnativeevents/tst_macnativeevents.cpp @@ -44,8 +44,9 @@ #include <QPushButton> #include <QtTest/QtTest> -#include "qnativeinput.h" -#include "qnativeplayer.h" +#include "qnativeevents.h" +#include "nativeeventlist.h" +#include "expectedeventlist.h" #ifdef Q_OS_MAC @@ -55,21 +56,233 @@ class tst_MacNativeEvents : public QObject { Q_OBJECT private slots: - void testLeftMousePressRelease(); + void testMouseMoveLocation(); + void testPushButtonPressRelease(); + void testMouseLeftDoubleClick(); + void stressTestMouseLeftDoubleClick(); + void testMouseDragInside(); + void testMouseDragOutside(); + void testMouseDragToNonClientArea(); + void testDragWindow(); + void testMouseEnter(); }; -void tst_MacNativeEvents::testLeftMousePressRelease() +void tst_MacNativeEvents::testMouseMoveLocation() { + QWidget w; + w.setMouseTracking(true); + w.show(); + QPoint p = w.geometry().center(); + + NativeEventList native; + native.append(new QNativeMouseMoveEvent(p, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(p), p, Qt::NoButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + +void tst_MacNativeEvents::testPushButtonPressRelease() +{ + // Check that a native mouse press and release generates the + // same qevents on a pushbutton: QPushButton w("click me"); w.show(); QPoint p = w.geometry().center(); - QNativePlayer player; - player.append(50, new QNativeMouseButtonEvent(p, Qt::LeftButton, 1, Qt::NoModifier)); - player.append(50, new QNativeMouseButtonEvent(p, Qt::LeftButton, 0, Qt::NoModifier)); - player.play(); + NativeEventList native; + native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 0, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QMouseEvent(QEvent::MouseButtonPress, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + +void tst_MacNativeEvents::testMouseLeftDoubleClick() +{ + // Check that a native double click makes + // the test widget receive a press-release-click-release: + QWidget w; + w.show(); + QPoint p = w.geometry().center(); + + NativeEventList native; + native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 0, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 2, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 0, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QMouseEvent(QEvent::MouseButtonPress, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonDblClick, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + +void tst_MacNativeEvents::stressTestMouseLeftDoubleClick() +{ + // Check that multiple, fast, double clicks makes + // the test widget receive correct click events + QWidget w; + w.show(); + QPoint p = w.geometry().center(); + + NativeEventList native; + ExpectedEventList expected(&w); + + for (int i=0; i<10; ++i){ + native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 0, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 2, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 0, Qt::NoModifier)); + + expected.append(new QMouseEvent(QEvent::MouseButtonPress, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonDblClick, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + } + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); } +void tst_MacNativeEvents::testMouseDragInside() +{ + // Check that a mouse drag inside a widget + // will cause press-move-release events to be delivered + QWidget w; + w.show(); + QPoint p1 = w.geometry().center(); + QPoint p2 = p1 - QPoint(10, 0); + QPoint p3 = p1 - QPoint(20, 0); + QPoint p4 = p1 - QPoint(30, 0); + + NativeEventList native; + native.append(new QNativeMouseButtonEvent(p1, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(p2, Qt::LeftButton, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(p3, Qt::LeftButton, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(p4, Qt::LeftButton, 0, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QMouseEvent(QEvent::MouseButtonPress, w.mapFromGlobal(p1), p1, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(p2), p2, Qt::NoButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(p3), p3, Qt::NoButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(p4), p4, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + +void tst_MacNativeEvents::testMouseDragOutside() +{ + // Check that if we drag the mouse from inside the + // widget, and release it outside, we still get mouse move + // and release events when the mouse is outside the widget. + QWidget w; + w.show(); + QPoint inside1 = w.geometry().center(); + QPoint inside2 = inside1 - QPoint(10, 0); + QPoint outside1 = w.geometry().topLeft() - QPoint(50, 0); + QPoint outside2 = outside1 - QPoint(10, 0); + + NativeEventList native; + native.append(new QNativeMouseButtonEvent(inside1, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(inside2, Qt::LeftButton, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(outside1, Qt::LeftButton, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(outside2, Qt::LeftButton, 0, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QMouseEvent(QEvent::MouseButtonPress, w.mapFromGlobal(inside1), inside1, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(inside2), inside2, Qt::NoButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(outside1), outside1, Qt::NoButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(outside2), outside2, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + +void tst_MacNativeEvents::testMouseDragToNonClientArea() +{ + // Check that if we drag the mouse from inside the + // widget, and release it on the title bar, we still get mouse move + // and release events when the mouse is on the title bar + QWidget w; + w.show(); + QPoint inside1 = w.geometry().center(); + QPoint inside2 = inside1 - QPoint(10, 0); + QPoint titlebar1 = w.geometry().topLeft() - QPoint(-100, 10); + QPoint titlebar2 = titlebar1 - QPoint(10, 0); + + NativeEventList native; + native.append(new QNativeMouseButtonEvent(inside1, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(inside2, Qt::LeftButton, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(titlebar1, Qt::LeftButton, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(titlebar2, Qt::LeftButton, 0, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QMouseEvent(QEvent::MouseButtonPress, w.mapFromGlobal(inside1), inside1, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(inside2), inside2, Qt::NoButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(titlebar1), titlebar1, Qt::NoButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(titlebar2), titlebar2, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + +void tst_MacNativeEvents::testDragWindow() +{ + // Check that if we drag the mouse from inside the + // widgets title bar, we get a move event on the window + QWidget w; + w.show(); + QPoint titlebar = w.geometry().topLeft() - QPoint(-100, 10); + QPoint moveTo = titlebar + QPoint(100, 0); + + NativeEventList native; + native.append(new QNativeMouseButtonEvent(titlebar, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(moveTo, Qt::LeftButton, Qt::NoModifier)); + native.append(500, new QNativeMouseButtonEvent(moveTo, Qt::LeftButton, 0, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QMouseEvent(QEvent::NonClientAreaMouseButtonPress, w.mapFromGlobal(titlebar), titlebar, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::NonClientAreaMouseButtonRelease, w.mapFromGlobal(titlebar), moveTo, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + +void tst_MacNativeEvents::testMouseEnter() +{ + // When a mouse enters a widget, both a mouse enter events and a + // mouse move event should be sendt. Lets test this: + QWidget w; + w.setMouseTracking(true); + w.show(); + QPoint outside = w.geometry().topLeft() - QPoint(50, 0); + QPoint inside = w.geometry().center(); + + NativeEventList native; + native.append(new QNativeMouseMoveEvent(outside, Qt::NoModifier)); + native.append(new QNativeMouseMoveEvent(inside, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QEvent(QEvent::Enter)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(inside), inside, Qt::NoButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + + #include "tst_macnativeevents.moc" QTEST_MAIN(tst_MacNativeEvents) |