aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/qmljs/qmljsbind.cpp
blob: bc75da018856d7bdf5f1fc5b83b15e42697e2fb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
-rw-r--r--
src/gui/kernel/qevent.cpp82
-rw-r--r--src/gui/kernel/qevent.h7
-rw-r--r--src/gui/kernel/qguiapplication.cpp3
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp12
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h3
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h5
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm4
-rw-r--r--src/widgets/itemviews/qlistview.cpp2
-rw-r--r--src/widgets/kernel/qapplication.cpp2
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp2
-rw-r--r--src/widgets/widgets/qabstractslider.cpp2
11 files changed, 102 insertions, 22 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 98499c11ac..78a4dc4f35 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -702,6 +702,31 @@ QHoverEvent::~QHoverEvent()
*/
/*!
+ \fn bool QWheelEvent::inverted() const
+ \since 5.7
+
+ Returns whether the delta values delivered with the event are inverted.
+
+ Normally, a vertical wheel will produce a QWheelEvent with positive delta
+ values if the top of the wheel is rotating away from the hand operating it.
+ Similarly, a horizontal wheel movement will produce a QWheelEvent with
+ positive delta values if the top of the wheel is moved to the left.
+
+ However, on some platforms this is configurable, so that the same
+ operations described above will produce negative delta values (but with the
+ same magnitude). With the inverted property a wheel event consumer can
+ choose to always follow the direction of the wheel, regardless of the
+ system settings, but only for specific widgets. (One such use case could be
+ that the user is rotating the wheel in the same direction as a visual
+ Tumbler rotates. Another usecase is to make a slider handle follow the
+ direction of movement of fingers on a touchpad regardless of system
+ configuration.)
+
+ \note Many platforms provide no such information. On such platforms
+ \l inverted always returns false.
+*/
+
+/*!
\fn Qt::Orientation QWheelEvent::orientation() const
\obsolete
@@ -734,7 +759,7 @@ QWheelEvent::QWheelEvent(const QPointF &pos, int delta,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
Qt::Orientation orient)
: QInputEvent(Wheel, modifiers), p(pos), qt4D(delta), qt4O(orient), mouseState(buttons),
- ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized)
+ ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized), invertedScrolling(false)
{
g = QCursor::pos();
if (orient == Qt::Vertical)
@@ -769,7 +794,7 @@ 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), qt4D(delta), qt4O(orient), mouseState(buttons),
- ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized)
+ ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized), invertedScrolling(false)
{
if (orient == Qt::Vertical)
angleD = QPoint(0, delta);
@@ -806,7 +831,7 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
: QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta),
angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(Qt::NoScrollPhase),
- src(Qt::MouseEventNotSynthesized)
+ src(Qt::MouseEventNotSynthesized), invertedScrolling(false)
{}
/*!
@@ -837,15 +862,14 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase)
: QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta),
angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase),
- src(Qt::MouseEventNotSynthesized)
+ src(Qt::MouseEventNotSynthesized), invertedScrolling(false)
{}
/*!
Constructs a wheel event object.
- The \a pos provides the location of the mouse cursor
- within the window. The position in global coordinates is specified
- by \a globalPos.
+ The \a pos provides the location of the mouse cursor within the window. The
+ position in global coordinates is specified by \a globalPos.
\a pixelDelta contains the scrolling distance in pixels on screen, while
\a angleDelta contains the wheel rotation distance. \a pixelDelta is
@@ -873,7 +897,49 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source)
: QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta),
- angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase), src(source)
+ angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase), src(source),
+ invertedScrolling(false)
+{}
+
+/*!
+ Constructs a wheel event object.
+
+ The \a pos provides the location of the mouse cursor
+ within the window. The position in global coordinates is specified
+ by \a globalPos.
+
+ \a pixelDelta contains the scrolling distance in pixels on screen, while
+ \a angleDelta contains the wheel rotation distance. \a pixelDelta is
+ optional and can be null.
+
+ The mouse and keyboard states at the time of the event are specified by
+ \a buttons and \a modifiers.
+
+ For backwards compatibility, the event can also hold monodirectional wheel
+ event data: \a qt4Delta specifies the rotation, and \a qt4Orientation the
+ direction.
+
+ The scrolling phase of the event is specified by \a phase.
+
+ If the wheel event comes from a physical mouse wheel, \a source is set to
+ Qt::MouseEventNotSynthesized. If it comes from a gesture detected by the
+ operating system, or from a non-mouse hardware device, such that \a
+ pixelDelta is directly related to finger movement, \a source is set to
+ Qt::MouseEventSynthesizedBySystem. If it comes from Qt, source would be set
+ to Qt::MouseEventSynthesizedByQt.
+
+ If the system is configured to invert the delta values delivered with the
+ event (such as natural scrolling of the touchpad on OS X), \a inverted
+ should be \c true. Otherwise, \a inverted is \c false
+
+ \sa posF(), globalPosF(), angleDelta(), pixelDelta(), phase()
+*/
+QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
+ QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
+ Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source, bool inverted)
+ : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta),
+ angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase), src(source),
+ invertedScrolling(inverted)
{}
#endif // QT_NO_WHEELEVENT
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index 5752869cab..0a207667ad 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -187,6 +187,9 @@ public:
QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons,
Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source);
+ QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
+ int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons,
+ Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source, bool inverted);
~QWheelEvent();
@@ -210,6 +213,7 @@ public:
inline Qt::MouseButtons buttons() const { return mouseState; }
inline Qt::ScrollPhase phase() const { return Qt::ScrollPhase(ph); }
+ inline bool inverted() const { return invertedScrolling; }
Qt::MouseEventSource source() const { return Qt::MouseEventSource(src); }
@@ -223,7 +227,8 @@ protected:
Qt::MouseButtons mouseState;
uint ph : 2;
uint src: 2;
- int reserved : 28;
+ bool invertedScrolling : 1;
+ int reserved : 27;
friend class QApplication;
};
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 057450374d..3f3ed87944 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1974,7 +1974,8 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh
return;
}
- QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta, e->qt4Delta, e->qt4Orientation, buttons, e->modifiers, e->phase, e->source);
+ QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta, e->qt4Delta, e->qt4Orientation,
+ buttons, e->modifiers, e->phase, e->source, e->inverted);
ev.setTimestamp(e->timestamp);
QGuiApplication::sendSpontaneousEvent(window, &ev);
#endif /* ifndef QT_NO_WHEELEVENT */
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index 39bc161a7c..7547e58346 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -315,7 +315,8 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local,
handleWheelEvent(w, time, local, global, pixelDelta, angleDelta, mods, phase, source);
}
-void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source)
+void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
+ Qt::MouseEventSource source, bool invertedScrolling)
{
// Qt 4 sends two separate wheel events for horizontal and vertical
// deltas. For Qt 5 we want to send the deltas in one event, but at the
@@ -333,14 +334,15 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, con
// Simple case: vertical deltas only:
if (angleDelta.y() != 0 && angleDelta.x() == 0) {
- e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source);
+ e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical,
+ mods, phase, source, invertedScrolling);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
return;
}
// Simple case: horizontal deltas only:
if (angleDelta.y() == 0 && angleDelta.x() != 0) {
- e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source);
+ e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
return;
}
@@ -348,12 +350,12 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, con
// Both horizontal and vertical deltas: Send two wheel events.
// The first event contains the Qt 5 pixel and angle delta as points,
// and in addition the Qt 4 compatibility vertical angle delta.
- e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source);
+ e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
// The second event contains null pixel and angle points and the
// Qt 4 compatibility horizontal angle delta.
- e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source);
+ e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index 66a4afb085..eff3986788 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -109,7 +109,8 @@ public:
QPoint pixelDelta, QPoint angleDelta,
Qt::KeyboardModifiers mods = Qt::NoModifier,
Qt::ScrollPhase phase = Qt::NoScrollPhase,
- Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
+ Qt::MouseEventSource source = Qt::MouseEventNotSynthesized,
+ bool inverted = false);
// Wheel event compatibility functions. Will be removed: do not use.
static void handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier);
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index 523aa984a9..4bb0e83a97 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -242,8 +242,8 @@ public:
class WheelEvent : public InputEvent {
public:
WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
- Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized)
- : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src) { }
+ Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized, bool inverted = false)
+ : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted) { }
QPoint pixelDelta;
QPoint angleDelta;
int qt4Delta;
@@ -252,6 +252,7 @@ public:
QPointF globalPos;
Qt::ScrollPhase phase;
Qt::MouseEventSource source;
+ bool inverted;
};
class KeyEvent : public InputEvent {
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index fbcaf0b1d0..aaa00014dd 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -1413,8 +1413,10 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
} else if (phase == NSEventPhaseNone && momentumPhase == NSEventPhaseNone) {
ph = Qt::NoScrollPhase;
}
+ // "isInverted": natural OS X scrolling, inverted from the Qt/other platform/Jens perspective.
+ bool isInverted = [theEvent isDirectionInvertedFromDevice];
- QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_screenPoint, pixelDelta, angleDelta, currentWheelModifiers, ph, source);
+ QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_screenPoint, pixelDelta, angleDelta, currentWheelModifiers, ph, source, isInverted);
}
#endif //QT_NO_WHEELEVENT
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 646ab58e3d..1f33649668 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -822,7 +822,7 @@ void QListView::wheelEvent(QWheelEvent *e)
QPoint pixelDelta(e->pixelDelta().y(), e->pixelDelta().x());
QPoint angleDelta(e->angleDelta().y(), e->angleDelta().x());
QWheelEvent hwe(e->pos(), e->globalPos(), pixelDelta, angleDelta, e->delta(),
- Qt::Horizontal, e->buttons(), e->modifiers(), e->phase());
+ Qt::Horizontal, e->buttons(), e->modifiers(), e->phase(), e->source(), e->inverted());
if (e->spontaneous())
qt_sendSpontaneousEvent(d->hbar, &hwe);
else
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 2d23bb61a2..1d5bdc2db7 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -3331,7 +3331,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos);
QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(),
- wheel->modifiers(), phase, wheel->source());
+ wheel->modifiers(), phase, wheel->source(), wheel->inverted());
bool eventAccepted;
while (w) {
we.spont = spontaneous && w == receiver;
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index 6a3785ea03..def371c36e 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -776,7 +776,7 @@ void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
QPoint mapped = widget->mapFrom(rootWidget, pos);
- QWheelEvent translated(mapped, event->globalPos(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers(), event->phase(), event->source());
+ QWheelEvent translated(mapped, event->globalPos(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers(), event->phase(), event->source(), event->inverted());
QGuiApplication::sendSpontaneousEvent(widget, &translated);
}
diff --git a/src/widgets/widgets/qabstractslider.cpp b/src/widgets/widgets/qabstractslider.cpp
index d7d83c7821..13e7a6e5cf 100644
--- a/src/widgets/widgets/qabstractslider.cpp
+++ b/src/widgets/widgets/qabstractslider.cpp
@@ -758,6 +758,8 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e)
Q_D(QAbstractSlider);
e->ignore();
int delta = e->delta();
+ if (e->inverted())
+ delta = -delta;
if (d->scrollByDelta(e->orientation(), e->modifiers(), delta))
e->accept();
}
="color:#000000">) return true; } return false; } Interpreter::ObjectValue *Bind::findFunctionScope(AST::FunctionExpression *node) const { return _functionScopes.value(node); } bool Bind::isGroupedPropertyBinding(AST::Node *node) const { return _groupedPropertyBindings.contains(node); } ObjectValue *Bind::switchObjectValue(ObjectValue *newObjectValue) { ObjectValue *oldObjectValue = _currentObjectValue; _currentObjectValue = newObjectValue; return oldObjectValue; } QString Bind::toString(UiQualifiedId *qualifiedId, QChar delimiter) { QString result; for (UiQualifiedId *iter = qualifiedId; iter; iter = iter->next) { if (iter != qualifiedId) result += delimiter; if (iter->name) result += iter->name->asString(); } return result; } ObjectValue *Bind::bindObject(UiQualifiedId *qualifiedTypeNameId, UiObjectInitializer *initializer) { ObjectValue *parentObjectValue = 0; // normal component instance ASTObjectValue *objectValue = new ASTObjectValue(qualifiedTypeNameId, initializer, _doc, &_engine); QmlPrototypeReference *prototypeReference = new QmlPrototypeReference(qualifiedTypeNameId, _doc, &_engine); objectValue->setPrototype(prototypeReference); parentObjectValue = switchObjectValue(objectValue); if (parentObjectValue) objectValue->setProperty(QLatin1String("parent"), parentObjectValue); else { _rootObjectValue = objectValue; _rootObjectValue->setClassName(_doc->componentName()); } accept(initializer); return switchObjectValue(parentObjectValue); } void Bind::accept(Node *node) { Node::accept(node, this); } bool Bind::visit(AST::UiProgram *) { _idEnvironment = _engine.newObject(/*prototype =*/ 0); return true; } bool Bind::visit(AST::Program *) { _currentObjectValue = _engine.newObject(/*prototype =*/ 0); _rootObjectValue = _currentObjectValue; return true; } bool Bind::visit(UiImport *ast) { ComponentVersion version; ImportInfo::Type type = ImportInfo::InvalidImport; QString name; if (ast->versionToken.isValid()) { const QString versionString = _doc->source().mid(ast->versionToken.offset, ast->versionToken.length); version = ComponentVersion(versionString); if (!version.isValid()) { _diagnosticMessages->append( errorMessage(ast->versionToken, tr("expected two numbers separated by a dot"))); } } if (ast->importUri) { type = ImportInfo::LibraryImport; name = toString(ast->importUri, QDir::separator()); if (!version.isValid()) { _diagnosticMessages->append( errorMessage(ast, tr("package import requires a version number"))); } } else if (ast->fileName) { const QFileInfo importFileInfo(_doc->path() + QDir::separator() + ast->fileName->asString()); name = importFileInfo.absoluteFilePath(); if (importFileInfo.isFile()) type = ImportInfo::FileImport; else if (importFileInfo.isDir()) type = ImportInfo::DirectoryImport; else { _diagnosticMessages->append( errorMessage(ast, tr("file or directory not found"))); type = ImportInfo::UnknownFileImport; } } _imports += ImportInfo(type, name, version, ast); return false; } bool Bind::visit(UiPublicMember *) { // nothing to do. return true; } bool Bind::visit(UiObjectDefinition *ast) { // an UiObjectDefinition may be used to group property bindings // think anchors { ... } bool isGroupedBinding = false; for (UiQualifiedId *it = ast->qualifiedTypeNameId; it; it = it->next) { if (!it->next && it->name) isGroupedBinding = it->name->asString().at(0).isLower(); } if (!isGroupedBinding) { ObjectValue *value = bindObject(ast->qualifiedTypeNameId, ast->initializer); _qmlObjects.insert(ast, value); } else { _groupedPropertyBindings.insert(ast); } return false; } bool Bind::visit(UiObjectBinding *ast) { // const QString name = serialize(ast->qualifiedId); ObjectValue *value = bindObject(ast->qualifiedTypeNameId, ast->initializer); _qmlObjects.insert(ast, value); // ### FIXME: we don't handle dot-properties correctly (i.e. font.size) // _currentObjectValue->setProperty(name, value); return false; } bool Bind::visit(UiScriptBinding *ast) { if (toString(ast->qualifiedId) == QLatin1String("id")) { if (ExpressionStatement *e = cast<ExpressionStatement*>(ast->statement)) if (IdentifierExpression *i = cast<IdentifierExpression*>(e->expression)) if (i->name) _idEnvironment->setProperty(i->name->asString(), _currentObjectValue); } return true; } bool Bind::visit(UiArrayBinding *) { // ### FIXME: do we need to store the members into the property? Or, maybe the property type is an JS Array? return true; } bool Bind::visit(VariableDeclaration *ast) { if (! ast->name) return false; ASTVariableReference *ref = new ASTVariableReference(ast, &_engine); _currentObjectValue->setProperty(ast->name->asString(), ref); return true; } bool Bind::visit(FunctionExpression *ast) { // ### FIXME: the first declaration counts //if (_currentObjectValue->property(ast->name->asString(), 0)) // return false; ASTFunctionValue *function = new ASTFunctionValue(ast, _doc, &_engine); if (ast->name && cast<FunctionDeclaration *>(ast)) _currentObjectValue->setProperty(ast->name->asString(), function); // build function scope ObjectValue *functionScope = _engine.newObject(/*prototype=*/0); _functionScopes.insert(ast, functionScope); ObjectValue *parent = switchObjectValue(functionScope); // The order of the following is important. Example: A function with name "arguments" // overrides the arguments object, a variable doesn't. // 1. Function formal arguments for (FormalParameterList *it = ast->formals; it; it = it->next) { if (it->name) functionScope->setProperty(it->name->asString(), _engine.undefinedValue()); } // 2. Functions defined inside the function body // ### TODO, currently covered by the accept(body) // 3. Arguments object ObjectValue *arguments = _engine.newObject(/*prototype=*/0); arguments->setProperty(QLatin1String("callee"), function); arguments->setProperty(QLatin1String("length"), _engine.numberValue()); functionScope->setProperty(QLatin1String("arguments"), arguments); // 4. Variables defined inside the function body // ### TODO, currently covered by the accept(body) // visit body accept(ast->body); switchObjectValue(parent); return false; } bool Bind::visit(FunctionDeclaration *ast) { return visit(static_cast<FunctionExpression *>(ast)); }