summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/declarative/elements.qdoc3
-rw-r--r--doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp1
-rw-r--r--examples/declarative/gestures/experimental-gestures.qml27
-rw-r--r--examples/qtconcurrent/map/main.cpp2
-rw-r--r--qmake/project.cpp15
-rw-r--r--src/dbus/qdbusserver.cpp2
-rw-r--r--src/declarative/qml/qdeclarativeparser_p.h2
-rw-r--r--src/gui/kernel/qeventdispatcher_mac.mm9
-rw-r--r--src/gui/styles/qgtkstyle_p.h5
-rw-r--r--src/gui/widgets/qmenu.cpp57
-rw-r--r--src/imports/gestures/gestures.pro27
-rw-r--r--src/imports/gestures/plugin.cpp66
-rw-r--r--src/imports/gestures/qdeclarativegesturearea.cpp266
-rw-r--r--src/imports/gestures/qdeclarativegesturearea_p.h100
-rw-r--r--src/imports/gestures/qmldir1
-rw-r--r--tests/auto/qmenu/tst_qmenu.cpp56
16 files changed, 605 insertions, 34 deletions
diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc
index 5eaaf7e..1bb739d 100644
--- a/doc/src/declarative/elements.qdoc
+++ b/doc/src/declarative/elements.qdoc
@@ -132,6 +132,7 @@ The following table lists the QML elements provided by the Qt Declarative module
\o \l FocusScope
\o \l Flickable
\o \l Flipable
+\o \l GestureArea (experimental)
\endlist
\o
@@ -194,7 +195,7 @@ The following table lists the QML elements provided by the Qt Declarative module
\o
\list
-\o \l Particles
+\o \l Particles (experimental)
\list
\o \l ParticleMotionLinear
\o \l ParticleMotionGravity
diff --git a/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp b/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp
index 94a9f68..2867bd5a 100644
--- a/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp
+++ b/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp
@@ -61,5 +61,6 @@ void MyClass::callFinishedSlot(QDBusPendingCallWatcher *call)
QByteArray data = reply.argumentAt<1>();
showReply(text, data);
}
+ call->deleteLater();
}
//! [1]
diff --git a/examples/declarative/gestures/experimental-gestures.qml b/examples/declarative/gestures/experimental-gestures.qml
new file mode 100644
index 0000000..914d403
--- /dev/null
+++ b/examples/declarative/gestures/experimental-gestures.qml
@@ -0,0 +1,27 @@
+import Qt 4.7
+import Qt.labs.gestures 1.0
+
+// Only works on platforms with Touch support.
+
+Rectangle {
+ id: rect
+
+ GestureArea {
+ anchors.fill: parent
+
+ // Only some of the many gesture properties are shown. See Gesture documentation.
+
+ onTap:
+ console.log("tap pos = (",gesture.position.x,",",gesture.position.y,")")
+ onTapAndHold:
+ console.log("tap and hold pos = (",gesture.position.x,",",gesture.position.y,")")
+ onPan:
+ console.log("pan delta = (",gesture.delta.x,",",gesture.delta.y,") acceleration = ",gesture.acceleration)
+ onPinch:
+ console.log("pinch center = (",gesture.centerPoint.x,",",gesture.centerPoint.y,") rotation =",gesture.rotationAngle," scale =",gesture.scaleFactor)
+ onSwipe:
+ console.log("swipe angle=",gesture.swipeAngle)
+ onGesture:
+ console.log("gesture hot spot = (",gesture.hotSpot.x,",",gesture.hotSpot.y,")")
+ }
+}
diff --git a/examples/qtconcurrent/map/main.cpp b/examples/qtconcurrent/map/main.cpp
index 6068d30..6afefca 100644
--- a/examples/qtconcurrent/map/main.cpp
+++ b/examples/qtconcurrent/map/main.cpp
@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
// Use QtConcurrentBlocking::mapped to apply the scale function to all the
// images in the list.
- QList<QImage> thumbnails = QtConcurrent::blockingMapped(images, scale);
+ QList<QImage> thumbnails = QtConcurrent::blockingMapped<QList<QImage> >(images, scale);
return 0;
}
diff --git a/qmake/project.cpp b/qmake/project.cpp
index 01a3843..56707cf 100644
--- a/qmake/project.cpp
+++ b/qmake/project.cpp
@@ -3148,6 +3148,21 @@ QStringList &QMakeProject::values(const QString &_var, QMap<QString, QStringList
if (place[var].isEmpty())
place[var] = QStringList(epocRoot());
}
+#if defined(Q_OS_WIN32) && defined(Q_CC_MSVC)
+ else if(var.startsWith(QLatin1String("QMAKE_TARGET."))) {
+ QString ret, type = var.mid(13);
+ if(type == "arch") {
+ QString paths = qgetenv("PATH");
+ QString vcBin64 = qgetenv("VCINSTALLDIR").append("\\bin\\amd64");
+ QString vcBinX86_64 = qgetenv("VCINSTALLDIR").append("\\bin\\x86_amd64");
+ if(paths.contains(vcBin64,Qt::CaseInsensitive) || paths.contains(vcBinX86_64,Qt::CaseInsensitive))
+ ret = "x86_64";
+ else
+ ret = "x86";
+ }
+ place[var] = QStringList(ret);
+ }
+#endif
//qDebug("REPLACE [%s]->[%s]", qPrintable(var), qPrintable(place[var].join("::")));
return place[var];
}
diff --git a/src/dbus/qdbusserver.cpp b/src/dbus/qdbusserver.cpp
index 8f9323a..13b18a6 100644
--- a/src/dbus/qdbusserver.cpp
+++ b/src/dbus/qdbusserver.cpp
@@ -47,7 +47,7 @@ QT_BEGIN_NAMESPACE
/*!
\class QDBusServer
\inmodule QtDBus
- \since 4.2
+ \internal
\brief The QDBusServer class provides peer-to-peer communication
between processes on the same computer.
diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h
index fd3e22f..57df04c 100644
--- a/src/declarative/qml/qdeclarativeparser_p.h
+++ b/src/declarative/qml/qdeclarativeparser_p.h
@@ -237,7 +237,7 @@ namespace QDeclarativeParser
QList<DynamicSlot> dynamicSlots;
};
- class Variant
+ class Q_DECLARATIVE_EXPORT Variant
{
public:
enum Type {
diff --git a/src/gui/kernel/qeventdispatcher_mac.mm b/src/gui/kernel/qeventdispatcher_mac.mm
index 62e1e81..a7f1224 100644
--- a/src/gui/kernel/qeventdispatcher_mac.mm
+++ b/src/gui/kernel/qeventdispatcher_mac.mm
@@ -831,7 +831,14 @@ NSModalSession QEventDispatcherMacPrivate::currentModalSession()
QBoolBlocker block1(blockSendPostedEvents, true);
info.nswindow = window;
[(NSWindow*) info.nswindow retain];
- info.session = [NSApp beginModalSessionForWindow:window];
+ // 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];
+ }
}
currentModalSessionCached = info.session;
}
diff --git a/src/gui/styles/qgtkstyle_p.h b/src/gui/styles/qgtkstyle_p.h
index 5bb7550..68a04e9 100644
--- a/src/gui/styles/qgtkstyle_p.h
+++ b/src/gui/styles/qgtkstyle_p.h
@@ -85,9 +85,14 @@ public:
int size() const { return m_size; }
const char *data() const { return m_data; }
+#ifdef __SUNPRO_CC
+ QHashableLatin1Literal(const char* str)
+ : m_size(strlen(str)), m_data(str) {}
+#else
template <int N>
QHashableLatin1Literal(const char (&str)[N])
: m_size(N - 1), m_data(str) {}
+#endif
QHashableLatin1Literal(const QHashableLatin1Literal &other)
: m_size(other.m_size), m_data(other.m_data)
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp
index 404d46e..b752ae2 100644
--- a/src/gui/widgets/qmenu.cpp
+++ b/src/gui/widgets/qmenu.cpp
@@ -1803,7 +1803,7 @@ QSize QMenu::sizeHint() const
void QMenu::popup(const QPoint &p, QAction *atAction)
{
Q_D(QMenu);
- if (d->scroll) { //reset scroll state from last popup
+ if (d->scroll) { // reset scroll state from last popup
d->scroll->scrollOffset = 0;
d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone;
}
@@ -1858,9 +1858,9 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
}
#endif
if (d->ncols > 1) {
- pos.setY(screen.top()+desktopFrame);
+ pos.setY(screen.top() + desktopFrame);
} else if (atAction) {
- for(int i = 0, above_height = 0; i < d->actions.count(); i++) {
+ for (int i = 0, above_height = 0; i < d->actions.count(); i++) {
QAction *action = d->actions.at(i);
if (action == atAction) {
int newY = pos.y() - above_height;
@@ -1875,7 +1875,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
if (d->scroll && d->scroll->scrollFlags != QMenuPrivate::QMenuScroller::ScrollNone
&& !style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, 0, this)) {
int below_height = above_height + d->scroll->scrollOffset;
- for(int i2 = i; i2 < d->actionRects.count(); i2++)
+ for (int i2 = i; i2 < d->actionRects.count(); i2++)
below_height += d->actionRects.at(i2).height();
size.setHeight(below_height);
}
@@ -1888,49 +1888,48 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
QPoint mouse = QCursor::pos();
d->mousePopupPos = mouse;
- const bool snapToMouse = (QRect(p.x()-3, p.y()-3, 6, 6).contains(mouse));
+ const bool snapToMouse = (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse));
if (adjustToDesktop) {
- //handle popup falling "off screen"
+ // handle popup falling "off screen"
if (isRightToLeft()) {
- if(snapToMouse) //position flowing left from the mouse
- pos.setX(mouse.x()-size.width());
+ if (snapToMouse) // position flowing left from the mouse
+ pos.setX(mouse.x() - size.width());
#ifndef QT_NO_MENUBAR
- //if in a menubar, it should be right-aligned
+ // if in a menubar, it should be right-aligned
if (qobject_cast<QMenuBar*>(d->causedPopup.widget))
pos.rx() -= size.width();
#endif //QT_NO_MENUBAR
- if (pos.x() < screen.left()+desktopFrame)
- pos.setX(qMax(p.x(), screen.left()+desktopFrame));
- if (pos.x()+size.width()-1 > screen.right()-desktopFrame)
- pos.setX(qMax(p.x()-size.width(), screen.right()-desktopFrame-size.width()+1));
+ if (pos.x() < screen.left() + desktopFrame)
+ pos.setX(qMax(p.x(), screen.left() + desktopFrame));
+ if (pos.x() + size.width() - 1 > screen.right() - desktopFrame)
+ pos.setX(qMax(p.x() - size.width(), screen.right() - desktopFrame - size.width() + 1));
} else {
- if (pos.x()+size.width()-1 > screen.right()-desktopFrame)
- pos.setX(screen.right()-desktopFrame-size.width()+1);
- if (pos.x() < screen.left()+desktopFrame)
+ if (pos.x() + size.width() - 1 > screen.right() - desktopFrame)
+ pos.setX(screen.right() - desktopFrame - size.width() + 1);
+ if (pos.x() < screen.left() + desktopFrame)
pos.setX(screen.left() + desktopFrame);
}
if (pos.y() + size.height() - 1 > screen.bottom() - desktopFrame) {
- if(snapToMouse)
- pos.setY(qMin(mouse.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height()+1));
- else
- pos.setY(qMax(p.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height()+1));
+ const int bestPos = (snapToMouse ? mouse.y() : p.y()) - desktopFrame - size.height() + 1;
+ const int fallbackPos = screen.bottom() - desktopFrame - size.height() + 1;
+ pos.setY(qMin(bestPos, fallbackPos));
} else if (pos.y() < screen.top() + desktopFrame) {
pos.setY(screen.top() + desktopFrame);
}
if (pos.y() < screen.top() + desktopFrame)
pos.setY(screen.top() + desktopFrame);
- if (pos.y()+size.height()-1 > screen.bottom() - desktopFrame) {
+ if (pos.y() + size.height() - 1 > screen.bottom() - desktopFrame) {
if (d->scroll) {
d->scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown);
int y = qMax(screen.y(),pos.y());
- size.setHeight(screen.bottom()-(desktopFrame*2)-y);
+ size.setHeight(screen.bottom() - (desktopFrame * 2) - y);
} else {
// Too big for screen, bias to see bottom of menu (for some reason)
- pos.setY(screen.bottom()-size.height()+1);
+ pos.setY(screen.bottom() - size.height() + 1);
}
}
}
@@ -1939,19 +1938,19 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
int hGuess = isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll;
int vGuess = QEffects::DownScroll;
if (isRightToLeft()) {
- if ((snapToMouse && (pos.x() + size.width()/2 > mouse.x())) ||
- (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width()/2 > d->causedPopup.widget->x()))
+ if ((snapToMouse && (pos.x() + size.width() / 2 > mouse.x())) ||
+ (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() / 2 > d->causedPopup.widget->x()))
hGuess = QEffects::RightScroll;
} else {
- if ((snapToMouse && (pos.x() + size.width()/2 < mouse.x())) ||
- (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width()/2 < d->causedPopup.widget->x()))
+ if ((snapToMouse && (pos.x() + size.width() / 2 < mouse.x())) ||
+ (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() / 2 < d->causedPopup.widget->x()))
hGuess = QEffects::LeftScroll;
}
#ifndef QT_NO_MENUBAR
- if ((snapToMouse && (pos.y() + size.height()/2 < mouse.y())) ||
+ if ((snapToMouse && (pos.y() + size.height() / 2 < mouse.y())) ||
(qobject_cast<QMenuBar*>(d->causedPopup.widget) &&
- pos.y() + size.width()/2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y()))
+ pos.y() + size.width() / 2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y()))
vGuess = QEffects::UpScroll;
#endif
if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu)) {
diff --git a/src/imports/gestures/gestures.pro b/src/imports/gestures/gestures.pro
new file mode 100644
index 0000000..b9c5b4e
--- /dev/null
+++ b/src/imports/gestures/gestures.pro
@@ -0,0 +1,27 @@
+TARGET = gesturesqmlplugin
+TARGETPATH = Qt/labs/gestures
+include(../qimportbase.pri)
+
+QT += declarative
+
+SOURCES += qdeclarativegesturearea.cpp plugin.cpp
+HEADERS += qdeclarativegesturearea_p.h
+
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/$$TARGETPATH
+target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+qmldir.files += $$PWD/qmldir
+qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+symbian:{
+ load(data_caging_paths)
+ include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri)
+
+ importFiles.sources = gesturesqmlplugin.dll \
+ qmldir
+ importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH
+
+ DEPLOYMENT = importFiles
+}
+
+INSTALLS += target qmldir
diff --git a/src/imports/gestures/plugin.cpp b/src/imports/gestures/plugin.cpp
new file mode 100644
index 0000000..9f5d923
--- /dev/null
+++ b/src/imports/gestures/plugin.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** 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 plugins 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 <QtDeclarative/qdeclarativeextensionplugin.h>
+#include <QtDeclarative/qdeclarative.h>
+
+#include "qdeclarativegesturearea_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class GestureAreaQmlPlugin : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+public:
+ virtual void registerTypes(const char *uri)
+ {
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.gestures"));
+ qmlRegisterCustomType<QDeclarativeGestureArea>(uri,1,0, "GestureArea", "QDeclarativeGestureArea",
+ new QDeclarativeGestureAreaParser);
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "plugin.moc"
+
+Q_EXPORT_PLUGIN2(gesturesqmlplugin, QT_PREPEND_NAMESPACE(GestureAreaQmlPlugin));
+
diff --git a/src/imports/gestures/qdeclarativegesturearea.cpp b/src/imports/gestures/qdeclarativegesturearea.cpp
new file mode 100644
index 0000000..b8c8f57
--- /dev/null
+++ b/src/imports/gestures/qdeclarativegesturearea.cpp
@@ -0,0 +1,266 @@
+/****************************************************************************
+**
+** 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 QtDeclarative module 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 "qdeclarativegesturearea_p.h"
+
+#include <qdeclarativeexpression.h>
+#include <qdeclarativecontext.h>
+#include <qdeclarativeinfo.h>
+
+#include <private/qdeclarativeproperty_p.h>
+#include <private/qdeclarativeitem_p.h>
+
+#include <QtCore/qdebug.h>
+#include <QtCore/qstringlist.h>
+
+#include <QtGui/qevent.h>
+
+#include <private/qobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QDeclarativeGestureAreaPrivate : public QDeclarativeItemPrivate
+{
+ Q_DECLARE_PUBLIC(QDeclarativeGestureArea)
+public:
+ QDeclarativeGestureAreaPrivate() : componentcomplete(false), gesture(0) {}
+
+ typedef QMap<Qt::GestureType,QDeclarativeExpression*> Bindings;
+ Bindings bindings;
+
+ bool componentcomplete;
+
+ QByteArray data;
+
+ QGesture *gesture;
+
+ bool gestureEvent(QGestureEvent *event);
+};
+
+/*!
+ \qmlclass GestureArea QDeclarativeGestureArea
+ \brief The GestureArea item enables simple gesture handling.
+ \inherits Item
+
+ A GestureArea is like a MouseArea, but it has signals for gesture events.
+
+ \e {This element is only functional on devices with touch input.}
+
+ \qml
+ import Qt.labs.gestures 0.1
+
+ GestureArea {
+ anchors.fill: parent
+ onPan: ... gesture.acceleration ...
+ onPinch: ... gesture.rotationAngle ...
+ onSwipe: ...
+ onTapAndHold: ...
+ onTap: ...
+ onGesture: ...
+ }
+ \endqml
+
+ Each signal has a \e gesture parameter that has the
+ properties of the gesture.
+
+ \table
+ \header \o Signal \o Type \o Property \o Description
+ \row \o onTap \o point \o position \o the position of the tap
+ \row \o onTapAndHold \o point \o position \o the position of the tap
+ \row \o onPan \o real \o acceleration \o the acceleration of the pan
+ \row \o onPan \o point \o delta \o the offset from the previous input position to the current input
+ \row \o onPan \o point \o offset \o the total offset from the first input position to the current input position
+ \row \o onPan \o point \o lastOffset \o the previous value of offset
+ \row \o onPinch \o point \o centerPoint \o the midpoint between the two input points
+ \row \o onPinch \o point \o lastCenterPoint \o the previous value of centerPoint
+ \row \o onPinch \o point \o startCenterPoint \o the first value of centerPoint
+ \row \o onPinch \o real \o rotationAngle \o the angle covered by the gesture motion
+ \row \o onPinch \o real \o lastRotationAngle \o the previous value of rotationAngle
+ \row \o onPinch \o real \o totalRotationAngle \o the complete angle covered by the gesture
+ \row \o onPinch \o real \o scaleFactor \o the change in distance between the two input points
+ \row \o onPinch \o real \o lastScaleFactor \o the previous value of scaleFactor
+ \row \o onPinch \o real \o totalScaleFactor \o the complete scale factor of the gesture
+ \row \o onSwipe \o real \o swipeAngle \o the angle of the swipe
+ \endtable
+
+ Custom gestures, handled by onGesture, will have custom properties.
+
+ GestureArea is an invisible item: it is never painted.
+
+ \sa Gesture, MouseArea
+*/
+
+/*!
+ \internal
+ \class QDeclarativeGestureArea
+ \brief The QDeclarativeGestureArea class provides simple gesture handling.
+
+*/
+QDeclarativeGestureArea::QDeclarativeGestureArea(QDeclarativeItem *parent) :
+ QDeclarativeItem(*(new QDeclarativeGestureAreaPrivate), parent)
+{
+ setAcceptedMouseButtons(Qt::LeftButton);
+ setAcceptTouchEvents(true);
+}
+
+QDeclarativeGestureArea::~QDeclarativeGestureArea()
+{
+}
+
+QByteArray
+QDeclarativeGestureAreaParser::compile(const QList<QDeclarativeCustomParserProperty> &props)
+{
+ QByteArray rv;
+ QDataStream ds(&rv, QIODevice::WriteOnly);
+
+ for(int ii = 0; ii < props.count(); ++ii)
+ {
+ QString propName = QString::fromUtf8(props.at(ii).name());
+ Qt::GestureType type;
+
+ if (propName == QLatin1String("onTap")) {
+ type = Qt::TapGesture;
+ } else if (propName == QLatin1String("onTapAndHold")) {
+ type = Qt::TapAndHoldGesture;
+ } else if (propName == QLatin1String("onPan")) {
+ type = Qt::PanGesture;
+ } else if (propName == QLatin1String("onPinch")) {
+ type = Qt::PinchGesture;
+ } else if (propName == QLatin1String("onSwipe")) {
+ type = Qt::SwipeGesture;
+ } else if (propName == QLatin1String("onGesture")) {
+ type = Qt::CustomGesture;
+ } else {
+ error(props.at(ii), QDeclarativeGestureArea::tr("Cannot assign to non-existent property \"%1\"").arg(propName));
+ return QByteArray();
+ }
+
+ QList<QVariant> values = props.at(ii).assignedValues();
+
+ for (int i = 0; i < values.count(); ++i) {
+ const QVariant &value = values.at(i);
+
+ if (value.userType() == qMetaTypeId<QDeclarativeCustomParserNode>()) {
+ error(props.at(ii), QDeclarativeGestureArea::tr("GestureArea: nested objects not allowed"));
+ return QByteArray();
+ } else if (value.userType() == qMetaTypeId<QDeclarativeCustomParserProperty>()) {
+ error(props.at(ii), QDeclarativeGestureArea::tr("GestureArea: syntax error"));
+ return QByteArray();
+ } else {
+ QDeclarativeParser::Variant v = qvariant_cast<QDeclarativeParser::Variant>(value);
+ if (v.isScript()) {
+ ds << propName;
+ ds << int(type);
+ ds << v.asScript();
+ } else {
+ error(props.at(ii), QDeclarativeGestureArea::tr("GestureArea: script expected"));
+ return QByteArray();
+ }
+ }
+ }
+ }
+
+ return rv;
+}
+
+void QDeclarativeGestureAreaParser::setCustomData(QObject *object,
+ const QByteArray &data)
+{
+ QDeclarativeGestureArea *ga = static_cast<QDeclarativeGestureArea*>(object);
+ ga->d_func()->data = data;
+}
+
+
+void QDeclarativeGestureArea::connectSignals()
+{
+ Q_D(QDeclarativeGestureArea);
+ if (!d->componentcomplete)
+ return;
+
+ QDataStream ds(d->data);
+ while (!ds.atEnd()) {
+ QString propName;
+ ds >> propName;
+ int gesturetype;
+ ds >> gesturetype;
+ QString script;
+ ds >> script;
+ QDeclarativeExpression *exp = new QDeclarativeExpression(qmlContext(this), script, 0);
+ d->bindings.insert(Qt::GestureType(gesturetype),exp);
+ grabGesture(Qt::GestureType(gesturetype));
+ }
+}
+
+void QDeclarativeGestureArea::componentComplete()
+{
+ QDeclarativeItem::componentComplete();
+ Q_D(QDeclarativeGestureArea);
+ d->componentcomplete=true;
+ connectSignals();
+}
+
+QGesture *QDeclarativeGestureArea::gesture() const
+{
+ Q_D(const QDeclarativeGestureArea);
+ return d->gesture;
+}
+
+bool QDeclarativeGestureArea::sceneEvent(QEvent *event)
+{
+ Q_D(QDeclarativeGestureArea);
+ if (event->type() == QEvent::Gesture)
+ return d->gestureEvent(static_cast<QGestureEvent*>(event));
+ return QDeclarativeItem::sceneEvent(event);
+}
+
+bool QDeclarativeGestureAreaPrivate::gestureEvent(QGestureEvent *event)
+{
+ bool accept = true;
+ for (Bindings::Iterator it = bindings.begin(); it != bindings.end(); ++it) {
+ if ((gesture = event->gesture(it.key()))) {
+ it.value()->value();
+ event->setAccepted(true); // XXX only if value returns true?
+ }
+ }
+ return accept;
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/gestures/qdeclarativegesturearea_p.h b/src/imports/gestures/qdeclarativegesturearea_p.h
new file mode 100644
index 0000000..8e2c066
--- /dev/null
+++ b/src/imports/gestures/qdeclarativegesturearea_p.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** 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 QtDeclarative module 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 QDECLARATIVEGESTUREAREA_H
+#define QDECLARATIVEGESTUREAREA_H
+
+#include <qdeclarativeitem.h>
+#include <qdeclarativescriptstring.h>
+#include <private/qdeclarativecustomparser_p.h>
+
+#include <QtCore/qobject.h>
+#include <QtCore/qstring.h>
+#include <QtGui/qgesture.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QDeclarativeBoundSignal;
+class QDeclarativeContext;
+class QDeclarativeGestureAreaPrivate;
+class Q_DECLARATIVE_EXPORT QDeclarativeGestureArea : public QDeclarativeItem
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QGesture *gesture READ gesture)
+
+public:
+ QDeclarativeGestureArea(QDeclarativeItem *parent=0);
+ ~QDeclarativeGestureArea();
+
+ QGesture *gesture() const;
+
+protected:
+ bool sceneEvent(QEvent *event);
+
+private:
+ void connectSignals();
+ void componentComplete();
+ friend class QDeclarativeGestureAreaParser;
+
+ Q_DISABLE_COPY(QDeclarativeGestureArea)
+ Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeGestureArea)
+};
+
+class QDeclarativeGestureAreaParser : public QDeclarativeCustomParser
+{
+public:
+ virtual QByteArray compile(const QList<QDeclarativeCustomParserProperty> &);
+ virtual void setCustomData(QObject *, const QByteArray &);
+};
+
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QDeclarativeGestureArea)
+
+QT_END_HEADER
+
+#endif
diff --git a/src/imports/gestures/qmldir b/src/imports/gestures/qmldir
new file mode 100644
index 0000000..9d9d587
--- /dev/null
+++ b/src/imports/gestures/qmldir
@@ -0,0 +1 @@
+plugin gesturesqmlplugin
diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp
index e10d7ee..4be6fdd 100644
--- a/tests/auto/qmenu/tst_qmenu.cpp
+++ b/tests/auto/qmenu/tst_qmenu.cpp
@@ -106,6 +106,8 @@ private slots:
void pushButtonPopulateOnAboutToShow();
void QTBUG7907_submenus_autoselect();
void QTBUG7411_submenus_activate();
+ void menuGeometry_data();
+ void menuGeometry();
protected slots:
void onActivated(QAction*);
void onHighlighted(QAction*);
@@ -967,6 +969,60 @@ void tst_QMenu::QTBUG7411_submenus_activate()
QTRY_VERIFY(sub1.isVisible());
}
+void tst_QMenu::menuGeometry_data()
+{
+ QTest::addColumn<QRect>("screen");
+ QTest::addColumn<QPoint>("pos");
+ QTest::addColumn<QPoint>("expectedPos");
+
+ QMenu menu("Test Menu");
+ for (int i = 0; i < 3; ++i)
+ menu.addAction("Hello World!");
+
+ menu.adjustSize();
+
+ const int screenCount = QApplication::desktop()->screenCount();
+ const int desktopFrame = menu.style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, &menu);
+
+ for (int i = 0; i < screenCount; ++i) {
+ const QRect screen = QApplication::desktop()->screenGeometry(i);
+
+ if (screen.width() < menu.width() || screen.height() < menu.height())
+ continue;
+
+ QTest::newRow("topLeft") << screen << screen.topLeft()
+ << QPoint(screen.left() + desktopFrame, screen.top() + desktopFrame);
+
+ QTest::newRow("topRight") << screen << screen.topRight()
+ << QPoint(screen.right() - desktopFrame - menu.width() + 1, screen.top() + desktopFrame);
+
+ QTest::newRow("bottomLeft") << screen << screen.bottomLeft()
+ << QPoint(screen.left() + desktopFrame, screen.bottom() - desktopFrame - menu.height() + 1);
+
+ QTest::newRow("bottomRight") << screen << screen.bottomRight()
+ << QPoint(screen.right() - desktopFrame - menu.width() + 1, screen.bottom() - desktopFrame - menu.height() + 1);
+
+ const QPoint pos = QPoint(screen.right() - qMax(desktopFrame, 20), screen.bottom() - qMax(desktopFrame, 20));
+ QTest::newRow("position") << screen << pos
+ << QPoint(screen.right() - menu.width() + 1, pos.y() - menu.height() + 1);
+ }
+}
+
+void tst_QMenu::menuGeometry()
+{
+ QFETCH(QRect, screen);
+ QFETCH(QPoint, pos);
+ QFETCH(QPoint, expectedPos);
+
+ QMenu menu("Test Menu");
+ for (int i = 0; i < 3; ++i)
+ menu.addAction("Hello World!");
+
+ menu.popup(pos);
+ QTest::qWaitForWindowShown(&menu);
+ QVERIFY(screen.contains(menu.geometry()));
+ QCOMPARE(menu.pos(), expectedPos);
+}
QTEST_MAIN(tst_QMenu)