summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-04-27 10:32:45 (GMT)
committerRoberto Raggi <roberto.raggi@nokia.com>2009-04-27 10:32:45 (GMT)
commit1d01ff1e958a632e665084cf6dbf7c6bbaf4f0c5 (patch)
tree2e75dac2926f2f459fa8adc42febe1244c95ba8c
parente793ab29e651a7b07354224a82343d66c265f361 (diff)
parenteae3489b3f2fba9d733ca50eb89dc92a6e96e6f8 (diff)
downloadQt-1d01ff1e958a632e665084cf6dbf7c6bbaf4f0c5.zip
Qt-1d01ff1e958a632e665084cf6dbf7c6bbaf4f0c5.tar.gz
Qt-1d01ff1e958a632e665084cf6dbf7c6bbaf4f0c5.tar.bz2
Merge branch 'kinetic-declarativeui' of git://scm.dev.nokia.troll.no/qt/kinetic into kinetic-declarativeui-qfx
-rw-r--r--examples/declarative/connections/connections.qml6
-rw-r--r--examples/declarative/listview/listview.qml2
-rw-r--r--examples/declarative/mouseregion/mouse.qml12
-rw-r--r--src/declarative/fx/fx.pri2
-rw-r--r--src/declarative/fx/qfxevents.cpp72
-rw-r--r--src/declarative/fx/qfxevents_p.h127
-rw-r--r--src/declarative/fx/qfxflickable.cpp2
-rw-r--r--src/declarative/fx/qfxitem.cpp70
-rw-r--r--src/declarative/fx/qfxitem.h20
-rw-r--r--src/declarative/fx/qfxmouseregion.cpp59
-rw-r--r--src/declarative/fx/qfxmouseregion.h11
-rw-r--r--src/declarative/fx/qfxmouseregion_p.h11
-rw-r--r--src/declarative/fx/qfxpathview.cpp4
-rw-r--r--src/declarative/fx/qfxwebview.cpp97
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp31
-rw-r--r--src/declarative/qml/qmlmetaproperty.h8
16 files changed, 397 insertions, 137 deletions
diff --git a/examples/declarative/connections/connections.qml b/examples/declarative/connections/connections.qml
index 3146338..45c0e99 100644
--- a/examples/declarative/connections/connections.qml
+++ b/examples/declarative/connections/connections.qml
@@ -1,9 +1,9 @@
<Rect id="rect" color="blue" width="40" height="30">
<Rect id="dot" color="red" width="3" height="3" x="{rect.width/2}" y="{rect.height/2}"/>
<MouseRegion id="mr" anchors.fill="{rect}"/>
- <Connection sender="{mr}" signal="clicked(x,y)">
+ <Connection sender="{mr}" signal="clicked(mouse)">
color="green";
- dot.x = x-1;
- dot.y = y-1;
+ dot.x = mouse.x-1;
+ dot.y = mouse.y-1;
</Connection>
</Rect>
diff --git a/examples/declarative/listview/listview.qml b/examples/declarative/listview/listview.qml
index 08c8f18..6cacdd1 100644
--- a/examples/declarative/listview/listview.qml
+++ b/examples/declarative/listview/listview.qml
@@ -74,7 +74,7 @@
Note that we specify the 'children' property. This is because
the default property of a ListView is 'delegate'.
-->
- <Rect y="{List3.yPosition+125}" width="200" height="50" color="#FFFF88" z="0"/>
+ <Rect y="125" width="200" height="50" color="#FFFF88" z="-1"/>
</children>
</ListView>
diff --git a/examples/declarative/mouseregion/mouse.qml b/examples/declarative/mouseregion/mouse.qml
index f0f22ac..9581da2 100644
--- a/examples/declarative/mouseregion/mouse.qml
+++ b/examples/declarative/mouseregion/mouse.qml
@@ -1,10 +1,10 @@
<Rect color="white" width="200" height="200">
<Rect width="50" height="50" color="red">
<Text text="Click" anchors.centeredIn="{parent}"/>
- <MouseRegion onPressed="print('press (x: ' + x + ' y: ' + y + ')')"
- onReleased="print('release (x: ' + x + ' y: ' + y + ' isClick: ' + isClick + ' followsPressAndHold: ' + followsPressAndHold + ')')"
- onClicked="print('click (x: ' + x + ' y: ' + y + ' followsPressAndHold: ' + followsPressAndHold + ')')"
- onDoubleClicked="print('double click (x: ' + x + ' y: ' + y + ')')"
+ <MouseRegion onPressed="print('press (x: ' + mouse.x + ' y: ' + mouse.y + ')')"
+ onReleased="print('release (x: ' + mouse.x + ' y: ' + mouse.y + ' isClick: ' + mouse.isClick + ' wasHeld: ' + mouse.wasHeld + ')')"
+ onClicked="print('click (x: ' + mouse.x + ' y: ' + mouse.y + ' wasHeld: ' + mouse.wasHeld + ')')"
+ onDoubleClicked="print('double click (x: ' + mouse.x + ' y: ' + mouse.y + ')')"
onPressAndHold="print('press and hold')"
onExitedWhilePressed="print('exiting while pressed')"
onReenteredWhilePressed="print('reentering while pressed')" anchors.fill="{parent}"/>
@@ -14,8 +14,8 @@
<MouseRegion drag.target="{parent}"
drag.axis="x" drag.xmin="0" drag.xmax="150"
onPressed="print('press')"
- onReleased="print('release (isClick: ' + isClick + ') (followsPressAndHold: ' + followsPressAndHold + ')')"
- onClicked="print('click' + '(followsPressAndHold: ' + followsPressAndHold + ')')"
+ onReleased="print('release (isClick: ' + mouse.isClick + ') (wasHeld: ' + mouse.wasHeld + ')')"
+ onClicked="print('click' + '(wasHeld: ' + mouse.wasHeld + ')')"
onDoubleClicked="print('double click')"
onPressAndHold="print('press and hold')"
onExitedWhilePressed="print('exiting while pressed')"
diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri
index b8b62b9..7fe86fe 100644
--- a/src/declarative/fx/fx.pri
+++ b/src/declarative/fx/fx.pri
@@ -8,6 +8,7 @@ HEADERS += \
fx/qfxcomponentinstance_p.h \
fx/qfxcontentwrapper.h \
fx/qfxcontentwrapper_p.h \
+ fx/qfxevents_p.h \
fx/qfxflickable.h \
fx/qfxflickable_p.h \
fx/qfxfocuspanel.h \
@@ -57,6 +58,7 @@ SOURCES += \
fx/qfxblurfilter.cpp \
fx/qfxcomponentinstance.cpp \
fx/qfxcontentwrapper.cpp \
+ fx/qfxevents.cpp \
fx/qfxflickable.cpp \
fx/qfxfocuspanel.cpp \
fx/qfxfocusrealm.cpp \
diff --git a/src/declarative/fx/qfxevents.cpp b/src/declarative/fx/qfxevents.cpp
new file mode 100644
index 0000000..a3fa6af
--- /dev/null
+++ b/src/declarative/fx/qfxevents.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qfxevents_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmlclass MouseEvent QFxMouseEvent
+ \brief The MouseEvent element provides information about a mouse event.
+*/
+
+/*!
+ \internal
+ \class QFxMouseEvent
+*/
+
+/*!
+ \qmlproperty int x
+ \qmlproperty int y
+
+ These properties hold the position of the mouse event.
+*/
+
+/*!
+ \qmlproperty enum button
+
+ This property holds the button that caused the event.
+*/
+
+QML_DEFINE_NOCREATE_TYPE(QFxKeyEvent);
+QML_DEFINE_NOCREATE_TYPE(QFxMouseEvent);
+
+QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfxevents_p.h b/src/declarative/fx/qfxevents_p.h
new file mode 100644
index 0000000..d096a90
--- /dev/null
+++ b/src/declarative/fx/qfxevents_p.h
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QFXEVENTS_P_H
+#define QFXEVENTS_P_H
+
+#include <qfxglobal.h>
+#include <qml.h>
+#include <QtCore/qobject.h>
+#include <QtGui/qevent.h>
+
+QT_BEGIN_NAMESPACE
+
+class QFxKeyEvent : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int key READ key);
+ Q_PROPERTY(QString text READ text);
+ Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers);
+ Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat);
+ Q_PROPERTY(int count READ count);
+ Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted);
+
+public:
+ QFxKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text=QString(), bool autorep=false, ushort count=1)
+ : event(type, key, modifiers, text, autorep, count) { event.setAccepted(false); }
+ QFxKeyEvent(const QKeyEvent &ke)
+ : event(ke) { event.setAccepted(false); }
+
+ int key() const { return event.key(); }
+ QString text() const { return event.text(); }
+ Qt::KeyboardModifiers modifiers() const { return event.modifiers(); }
+ bool isAutoRepeat() const { return event.isAutoRepeat(); }
+ int count() const { return event.count(); }
+
+ bool isAccepted() { return event.isAccepted(); }
+ void setAccepted(bool accepted) { event.setAccepted(accepted); }
+
+private:
+ QKeyEvent event;
+};
+
+QML_DECLARE_TYPE(QFxKeyEvent);
+
+class QFxMouseEvent : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int x READ x);
+ Q_PROPERTY(int y READ y);
+ Q_PROPERTY(Qt::MouseButton button READ button);
+ Q_PROPERTY(Qt::MouseButtons buttons READ buttons);
+ Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers);
+ Q_PROPERTY(bool wasHeld READ wasHeld);
+ Q_PROPERTY(bool isClick READ isClick);
+ Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted);
+
+public:
+ QFxMouseEvent(int x, int y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers
+ , bool isClick=false, bool wasHeld=false)
+ : _x(x), _y(y), _button(button), _buttons(buttons), _modifiers(modifiers)
+ , _wasHeld(wasHeld), _isClick(isClick), _accepted(false) {}
+
+ int x() const { return _x; }
+ int y() const { return _y; }
+ Qt::MouseButton button() const { return _button; }
+ Qt::MouseButtons buttons() const { return _buttons; }
+ Qt::KeyboardModifiers modifiers() const { return _modifiers; }
+ bool wasHeld() const { return _wasHeld; }
+ bool isClick() const { return _isClick; }
+
+ bool isAccepted() { return _accepted; }
+ void setAccepted(bool accepted) { _accepted = accepted; }
+
+private:
+ int _x;
+ int _y;
+ Qt::MouseButton _button;
+ Qt::MouseButtons _buttons;
+ Qt::KeyboardModifiers _modifiers;
+ bool _wasHeld;
+ bool _isClick;
+ bool _accepted;
+};
+
+QML_DECLARE_TYPE(QFxMouseEvent);
+
+QT_END_NAMESPACE
+
+#endif // QFXEVENTS_P_H
diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp
index 04b4a3d..b6eaa8e 100644
--- a/src/declarative/fx/qfxflickable.cpp
+++ b/src/declarative/fx/qfxflickable.cpp
@@ -626,7 +626,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
lastPos = event->pos();
}
-void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *)
{
Q_Q(QFxFlickable);
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index 0ed46bc..644e812 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -60,6 +60,7 @@
#include "qfxitem_p.h"
#include "qfxitem.h"
+#include "qfxevents_p.h"
#include <qsimplecanvasfilter.h>
#include <qmlcomponent.h>
@@ -242,24 +243,20 @@ void QFxContents::setItem(QFxItem *item)
This signal is emitted when the baseline of the item changes.
- The baseline may change in response to a call to setBaselineOffset()
- or due to the geometry of the item changing.
-
- \sa baselineOffset(), setBaselineOffset()
+ The baseline may change in response to a change to the baselineOffset
+ property or due to the geometry of the item changing.
*/
/*!
\fn void QFxItem::baselineOffsetChanged()
This signal is emitted when the baseline of the item is changed
- via setBaselineOffset().
+ via the baselineOffset property.
The baseline corresponds to the baseline of the text contained in
the element. It is useful for aligning the text in items placed
beside each other. The default baseline is positioned at
2/3 of the height of the item.
-
- \sa baselineOffset(), setBaselineOffset()
*/
/*!
@@ -329,7 +326,7 @@ void QFxContents::setItem(QFxItem *item)
This signal is emitted when a key is pressed.
- The key event is available in QML via the QFxKeyEvent \c event
+ The key event is available in QML via the QFxKeyEvent \a event
property.
\qml
@@ -344,7 +341,7 @@ void QFxContents::setItem(QFxItem *item)
This signal is emitted when a key is released.
- The key event is available in QML via the QFxKeyEvent \c event
+ The key event is available in QML via the QFxKeyEvent \a event
property.
\qml
@@ -1120,34 +1117,13 @@ void QFxItem::setFlipHorizontally(bool v)
setFlip((QSimpleCanvasItem::Flip)(flip() & ~HorizontalFlip));
}
-class QFxKeyEvent : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(int key READ key);
- Q_PROPERTY(QString text READ text);
- Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted);
-public:
- QFxKeyEvent(int key, const QString &text=QString()) : _accepted(false), _key(key), _text(text) {}
-
- bool isAccepted() { return _accepted; }
- void setAccepted(bool accepted) { _accepted = accepted; }
-
- int key() const { return _key; }
-
- QString text() const { return _text; }
-
-private:
- bool _accepted;
- int _key;
- QString _text;
-};
/*!
\reimp
*/
void QFxItem::keyPressEvent(QKeyEvent *event)
{
- QFxKeyEvent ke(event->key(), event->text());
+ QFxKeyEvent ke(*event);
emit keyPress(&ke);
event->setAccepted(ke.isAccepted());
if (itemParent() && !ke.isAccepted())
@@ -1159,7 +1135,7 @@ void QFxItem::keyPressEvent(QKeyEvent *event)
*/
void QFxItem::keyReleaseEvent(QKeyEvent *event)
{
- QFxKeyEvent ke(event->key(), event->text());
+ QFxKeyEvent ke(*event);
emit keyRelease(&ke);
event->setAccepted(ke.isAccepted());
if (itemParent() && !ke.isAccepted())
@@ -1218,36 +1194,54 @@ void QFxItem::setId(const QString &id)
d->_id = id;
}
+/*!
+ \internal
+*/
QFxAnchorLine QFxItem::left() const
{
Q_D(const QFxItem);
return d->anchorLines()->left;
}
+/*!
+ \internal
+*/
QFxAnchorLine QFxItem::right() const
{
Q_D(const QFxItem);
return d->anchorLines()->right;
}
+/*!
+ \internal
+*/
QFxAnchorLine QFxItem::horizontalCenter() const
{
Q_D(const QFxItem);
return d->anchorLines()->hCenter;
}
+/*!
+ \internal
+*/
QFxAnchorLine QFxItem::top() const
{
Q_D(const QFxItem);
return d->anchorLines()->top;
}
+/*!
+ \internal
+*/
QFxAnchorLine QFxItem::bottom() const
{
Q_D(const QFxItem);
return d->anchorLines()->bottom;
}
+/*!
+ \internal
+*/
QFxAnchorLine QFxItem::verticalCenter() const
{
Q_D(const QFxItem);
@@ -1382,7 +1376,6 @@ QFxAnchorLine QFxItem::verticalCenter() const
For non-text items, a default baseline offset of two-thirds of the
item's height is used to determine the baseline.
*/
-
int QFxItem::baselineOffset() const
{
Q_D(const QFxItem);
@@ -1392,6 +1385,9 @@ int QFxItem::baselineOffset() const
return d->_baselineOffset;
}
+/*!
+ \internal
+*/
void QFxItem::setBaselineOffset(int offset)
{
Q_D(QFxItem);
@@ -1862,7 +1858,6 @@ void QFxItem::setVisible(bool visible)
*/
void QFxItem::dump(int depth)
{
- Q_D(QFxItem);
QByteArray ba(depth * 4, ' ');
qWarning() << ba.constData() << metaObject()->className() << "(" << (void *)static_cast<QFxItem*>(this) << ", " << (void *)static_cast<QSimpleCanvasItem*>(this) << "):" << x() << y() << width() << height() << (void *) itemParent();
}
@@ -1964,6 +1959,9 @@ void QFxItem::reparentItems()
qFatal("EEK");
}
+/*!
+ \internal
+*/
void QFxItem::updateTransform()
{
Q_D(QFxItem);
@@ -1978,6 +1976,9 @@ void QFxItem::updateTransform()
transformChanged(trans);
}
+/*!
+ \internal
+*/
void QFxItem::transformChanged(const QSimpleCanvas::Matrix &)
{
}
@@ -2012,5 +2013,4 @@ QFxItemPrivate::AnchorLines::AnchorLines(QFxItem *q)
vCenter.anchorLine = QFxAnchorLine::VCenter;
}
-#include "qfxitem.moc"
QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h
index e2a2ebd..b76235b 100644
--- a/src/declarative/fx/qfxitem.h
+++ b/src/declarative/fx/qfxitem.h
@@ -94,6 +94,7 @@ class QmlContext;
class QmlState;
class QmlTransition;
class QFxTransform;
+class QFxKeyEvent;
class QFxItemPrivate;
class Q_DECLARATIVE_EXPORT QFxItem : public QSimpleCanvasItem, public QmlParserStatus
{
@@ -181,13 +182,6 @@ public:
int baselineOffset() const;
void setBaselineOffset(int);
- QFxAnchorLine left() const;
- QFxAnchorLine right() const;
- QFxAnchorLine horizontalCenter() const;
- QFxAnchorLine top() const;
- QFxAnchorLine bottom() const;
- QFxAnchorLine verticalCenter() const;
-
qreal rotation() const;
void setRotation(qreal);
@@ -233,8 +227,8 @@ Q_SIGNALS:
void focusChanged();
void activeFocusChanged();
void parentChanged();
- void keyPress(QObject *event);
- void keyRelease(QObject *event);
+ void keyPress(QFxKeyEvent *event);
+ void keyRelease(QFxKeyEvent *event);
void rotationChanged();
void scaleChanged();
void opacityChanged();
@@ -264,8 +258,16 @@ protected:
QFxItem(QFxItemPrivate &dd, QFxItem *parent = 0);
private:
+ QFxAnchorLine left() const;
+ QFxAnchorLine right() const;
+ QFxAnchorLine horizontalCenter() const;
+ QFxAnchorLine top() const;
+ QFxAnchorLine bottom() const;
+ QFxAnchorLine verticalCenter() const;
+
void init(QFxItem *parent);
friend class QmlStatePrivate;
+ friend class QFxAnchors;
Q_DISABLE_COPY(QFxItem)
Q_DECLARE_PRIVATE(QFxItem)
};
diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp
index 0af3cea..be56786 100644
--- a/src/declarative/fx/qfxmouseregion.cpp
+++ b/src/declarative/fx/qfxmouseregion.cpp
@@ -41,6 +41,7 @@
#include "qfxmouseregion.h"
#include "qfxmouseregion_p.h"
+#include "qfxevents_p.h"
#include <QGraphicsSceneMouseEvent>
@@ -154,12 +155,15 @@ void QFxDrag::setYmax(int m)
</Rect>
\endcode
- For the mouse handlers the variable mouseButton is set to be one of 'Left', 'Right', 'Middle',
- or 'None'. This allows you to distinguish left and right clicking. Below we have the previous
+ Many MouseRegion signals pass a \l {qml-mouseevent}{mouse} parameter that contains
+ additional information about the mouse event, such as the position, button,
+ and any key modifiers.
+
+ Below we have the previous
example extended so as to give a different color when you right click.
\code
<Rect width="100" height="100">
- <MouseRegion anchors.fill="{parent}" onClick="if(mouseButton=='Right') { parent.color='blue';} else { parent.color = 'red';}"/>
+ <MouseRegion anchors.fill="{parent}" onClick="if(mouse.button=='Right') { parent.color='blue';} else { parent.color = 'red';}"/>
</Rect>
\endcode
@@ -197,46 +201,50 @@ void QFxDrag::setYmax(int m)
*/
/*!
- \qmlsignal MouseRegion::onClicked
+ \qmlsignal MouseRegion::onClicked(mouse)
This handler is called when there is a click. A click is defined as a press followed by a release,
both inside the MouseRegion (pressing, moving outside the MouseRegion, and then moving back inside and
releasing is also considered a click).
- The x and y parameters tell you the position of the release of the click. The followsPressAndHold parameter tells
- you whether or not the release portion of the click followed a long press.
+
+ The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y
+ position of the release of the click, and whether the click wasHeld.
*/
/*!
- \qmlsignal MouseRegion::onPressed
+ \qmlsignal MouseRegion::onPressed(mouse)
This handler is called when there is a press.
- The x and y parameters tell you the position of the press.
+ The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y
+ position of the release of the click, and whether the click wasHeld.
*/
/*!
- \qmlsignal MouseRegion::onReleased
+ \qmlsignal MouseRegion::onReleased(mouse)
This handler is called when there is a release.
- The x and y parameters tell you the position of the release. The isClick parameter tells you whether
- or not the release is part of a click. The followsPressAndHold parameter tells you whether or not the
- release followed a long press.
+ The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y
+ position of the release of the click, and whether the click wasHeld.
*/
/*!
- \qmlsignal MouseRegion::onPressAndHold
+ \qmlsignal MouseRegion::onPressAndHold(mouse)
This handler is called when there is a long press (currently 800ms).
- The x and y parameters tell you the position of the long press.
+ The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y
+ position of the release of the click, and whether the click wasHeld.
*/
/*!
- \qmlsignal MouseRegion::onDoubleClicked
+ \qmlsignal MouseRegion::onDoubleClicked(mouse)
This handler is called when there is a double-click (a press followed by a release followed by a press).
- The x and y parameters tell you the position of the double-click.
+ The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y
+ position of the release of the click, and whether the click wasHeld.
*/
QML_DEFINE_TYPE(QFxMouseRegion,MouseRegion);
+
/*!
\internal
\class QFxMouseRegion
@@ -331,7 +339,7 @@ void QFxMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event)
emit hoveredChanged();
}
d->longPress = false;
- d->lastPos = event->pos();
+ d->saveEvent(event);
d->dragX = drag()->axis().contains(QLatin1String("x"));
d->dragY = drag()->axis().contains(QLatin1String("y"));
d->dragged = false;
@@ -355,7 +363,7 @@ void QFxMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
return;
}
- d->lastPos = event->pos();
+ d->saveEvent(event);
// ### we should skip this if these signals aren't used
const QRect &bounds = itemBoundingRect();
@@ -427,6 +435,7 @@ void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
if(!d->absorb)
QFxItem::mouseReleaseEvent(event);
else {
+ d->saveEvent(event);
setPressed(false);
//d->inside = false;
//emit hoveredChanged();
@@ -442,8 +451,10 @@ void QFxMouseRegion::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
else {
//d->inside = true;
//emit hoveredChanged();
+ d->saveEvent(event);
setPressed(true);
- emit this->doubleClicked(d->lastPos.x(), d->lastPos.y());
+ QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false);
+ emit this->doubleClicked(&me);
event->accept();
}
}
@@ -491,7 +502,8 @@ void QFxMouseRegion::timerEvent(QTimerEvent *event)
d->pressAndHoldTimer.stop();
if (d->pressed && d->dragged == false && d->inside == true) {
d->longPress = true;
- emit pressAndHold(d->lastPos.x(), d->lastPos.y());
+ QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress);
+ emit pressAndHold(&me);
}
}
}
@@ -534,12 +546,13 @@ void QFxMouseRegion::setPressed(bool p)
if(d->pressed != p) {
d->pressed = p;
+ QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress);
if(d->pressed)
- emit pressed(d->lastPos.x(), d->lastPos.y());
+ emit pressed(&me);
else {
- emit released(d->lastPos.x(), d->lastPos.y(), isclick, d->longPress);
+ emit released(&me);
if (isclick)
- emit clicked(d->lastPos.x(), d->lastPos.y(), d->longPress);
+ emit clicked(&me);
}
emit pressedChanged();
diff --git a/src/declarative/fx/qfxmouseregion.h b/src/declarative/fx/qfxmouseregion.h
index ee8b577..2e2a1d4 100644
--- a/src/declarative/fx/qfxmouseregion.h
+++ b/src/declarative/fx/qfxmouseregion.h
@@ -88,6 +88,7 @@ private:
};
QML_DECLARE_TYPE(QFxDrag);
+class QFxMouseEvent;
class QFxMouseRegionPrivate;
class Q_DECLARATIVE_EXPORT QFxMouseRegion : public QFxItem
{
@@ -122,11 +123,11 @@ Q_SIGNALS:
void pressedChanged();
void positionChanged();
- void pressed(int x, int y);
- void pressAndHold(int x, int y);
- void released(int x, int y, bool isClick, bool followsPressAndHold);
- void clicked(int x, int y, bool followsPressAndHold);
- void doubleClicked(int x, int y);
+ void pressed(QFxMouseEvent *mouse);
+ void pressAndHold(QFxMouseEvent *mouse);
+ void released(QFxMouseEvent *mouse);
+ void clicked(QFxMouseEvent *mouse);
+ void doubleClicked(QFxMouseEvent *mouse);
void entered();
void exited();
void exitedWhilePressed();
diff --git a/src/declarative/fx/qfxmouseregion_p.h b/src/declarative/fx/qfxmouseregion_p.h
index 09e1b98..e9d1986 100644
--- a/src/declarative/fx/qfxmouseregion_p.h
+++ b/src/declarative/fx/qfxmouseregion_p.h
@@ -55,6 +55,7 @@
#include "qdatetime.h"
#include "qbasictimer.h"
+#include "qgraphicssceneevent.h"
#include "qfxitem_p.h"
QT_BEGIN_NAMESPACE
@@ -78,6 +79,13 @@ public:
void bindButtonValue(Qt::MouseButton);
+ void saveEvent(QGraphicsSceneMouseEvent *event) {
+ lastPos = event->pos();
+ lastButton = event->button();
+ lastButtons = event->buttons();
+ lastModifiers = event->modifiers();
+ }
+
bool absorb;
bool hovered;
bool inside;
@@ -93,6 +101,9 @@ public:
int startX;
int startY;
QPointF lastPos;
+ Qt::MouseButton lastButton;
+ Qt::MouseButtons lastButtons;
+ Qt::KeyboardModifiers lastModifiers;
QBasicTimer pressAndHoldTimer;
};
diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp
index b1cfaa5..1bf7dda 100644
--- a/src/declarative/fx/qfxpathview.cpp
+++ b/src/declarative/fx/qfxpathview.cpp
@@ -188,7 +188,7 @@ void QFxPathView::setModel(const QVariant &model)
d->model = m;
} else {
if (!d->ownModel) {
- d->model = new QFxVisualItemModel;
+ d->model = new QFxVisualItemModel(qmlContext(this));
d->ownModel = true;
}
d->model->setModel(model);
@@ -368,7 +368,7 @@ void QFxPathView::setDelegate(QmlComponent *c)
{
Q_D(QFxPathView);
if (!d->ownModel) {
- d->model = new QFxVisualItemModel;
+ d->model = new QFxVisualItemModel(qmlContext(this));
d->ownModel = true;
}
d->model->setDelegate(c);
diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp
index 147415d..293c72b 100644
--- a/src/declarative/fx/qfxwebview.cpp
+++ b/src/declarative/fx/qfxwebview.cpp
@@ -199,24 +199,13 @@ QFxWebView::~QFxWebView()
void QFxWebView::init()
{
+ Q_D(QFxWebView);
+
setAcceptedMouseButtons(Qt::LeftButton);
setOptions(HasContents | MouseEvents);
setFocusable(true);
- QWebPage *wp = new QFxWebPage(this);
-
- // QML elements don't default to having a background,
- // even though most we pages will set one anyway.
- QPalette pal = QApplication::palette();
- pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0));
- wp->setPalette(pal);
-
- // ### Need to delay this as qmlEngine() is not set yet
- wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager());
- setPage(wp);
-
- // XXX settable from QML?
- settings()->setAttribute(QWebSettings::PluginsEnabled, true);
+ d->page = 0;
}
void QFxWebView::componentComplete()
@@ -298,17 +287,16 @@ void QFxWebView::doLoadFinished(bool ok)
*/
QString QFxWebView::url() const
{
- Q_D(const QFxWebView);
- return d->page->mainFrame()->url().toString();
+ return page()->mainFrame()->url().toString();
}
void QFxWebView::setUrl(const QString &n)
{
Q_D(QFxWebView);
- if(n == d->page->mainFrame()->url().toString())
+ if(n == page()->mainFrame()->url().toString())
return;
- d->page->setViewportSize(QSize(
+ page()->setViewportSize(QSize(
d->idealwidth>0 ? d->idealwidth : width(),
d->idealheight>0 ? d->idealheight : height()));
@@ -317,7 +305,7 @@ void QFxWebView::setUrl(const QString &n)
url = qmlContext(this)->resolvedUrl(n);
if (isComponentComplete())
- d->page->mainFrame()->load(url);
+ page()->mainFrame()->load(url);
else {
d->pending = d->PendingUrl;
d->pending_url = url;
@@ -430,7 +418,7 @@ void QFxWebView::updateCacheForVisibility()
void QFxWebView::expandToWebPage()
{
Q_D(QFxWebView);
- QSize cs = d->page->mainFrame()->contentsSize();
+ QSize cs = page()->mainFrame()->contentsSize();
if (cs.width() < d->idealwidth)
cs.setWidth(d->idealwidth);
if (cs.height() < d->idealheight)
@@ -439,8 +427,8 @@ void QFxWebView::expandToWebPage()
cs.setWidth(width());
if (heightValid() && cs.height() < height())
cs.setHeight(height());
- if (cs != d->page->viewportSize()) {
- d->page->setViewportSize(cs);
+ if (cs != page()->viewportSize()) {
+ page()->setViewportSize(cs);
d->clearCache();
setImplicitWidth(cs.width());
setImplicitHeight(cs.height());
@@ -525,7 +513,7 @@ void QFxWebView::paintGLContents(GLPainter &p)
#endif
{
Q_D(QFxWebView);
- QWebFrame *frame = d->page->mainFrame();
+ QWebFrame *frame = page()->mainFrame();
const QRect content(QPoint(0,0),frame->contentsSize());
if (content.width() <= 0 || content.height() <= 0)
@@ -605,8 +593,7 @@ void QFxWebView::paintGLContents(GLPainter &p)
QString QFxWebView::propertyInfo() const
{
- Q_D(const QFxWebView);
- return d->page->mainFrame()->url().toString();
+ return page()->mainFrame()->url().toString();
}
static QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e)
@@ -639,12 +626,12 @@ void QFxWebView::timerEvent(QTimerEvent *event)
if (event->timerId() ==d->dcTimer.timerId()) {
d->dcTimer.stop();
if (d->lastPress) {
- d->page->event(d->lastPress);
+ page()->event(d->lastPress);
delete d->lastPress;
d->lastPress = 0;
}
if (d->lastRelease) {
- d->page->event(d->lastRelease);
+ page()->event(d->lastRelease);
delete d->lastRelease;
d->lastRelease = 0;
}
@@ -720,7 +707,7 @@ void QFxWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Q_D(const QFxWebView);
if (d->interactive && !d->dcTimer.isActive()) {
QMouseEvent *me = sceneMouseEventToMouseEvent(event);
- d->page->event(me);
+ page()->event(me);
event->setAccepted(
#if QT_VERSION <= 0x040500 // XXX see bug 230835
true
@@ -740,7 +727,7 @@ void QFxWebView::keyPressEvent(QKeyEvent* event)
{
Q_D(const QFxWebView);
if (d->interactive)
- d->page->event(event);
+ page()->event(event);
if (!event->isAccepted())
QFxItem::keyPressEvent(event);
}
@@ -749,7 +736,7 @@ void QFxWebView::keyReleaseEvent(QKeyEvent* event)
{
Q_D(const QFxWebView);
if (d->interactive)
- d->page->event(event);
+ page()->event(event);
if (!event->isAccepted())
QFxItem::keyReleaseEvent(event);
}
@@ -760,8 +747,7 @@ void QFxWebView::keyReleaseEvent(QKeyEvent* event)
*/
QAction *QFxWebView::backAction() const
{
- Q_D(const QFxWebView);
- return d->page->action(QWebPage::Back);
+ return page()->action(QWebPage::Back);
}
/*!
@@ -770,8 +756,7 @@ QAction *QFxWebView::backAction() const
*/
QAction *QFxWebView::forwardAction() const
{
- Q_D(const QFxWebView);
- return d->page->action(QWebPage::Forward);
+ return page()->action(QWebPage::Forward);
}
/*!
@@ -780,8 +765,7 @@ QAction *QFxWebView::forwardAction() const
*/
QAction *QFxWebView::reloadAction() const
{
- Q_D(const QFxWebView);
- return d->page->action(QWebPage::Reload);
+ return page()->action(QWebPage::Reload);
}
/*!
@@ -790,8 +774,7 @@ QAction *QFxWebView::reloadAction() const
*/
QAction *QFxWebView::stopAction() const
{
- Q_D(const QFxWebView);
- return d->page->action(QWebPage::Stop);
+ return page()->action(QWebPage::Stop);
}
/*!
@@ -810,10 +793,7 @@ QAction *QFxWebView::stopAction() const
*/
QString QFxWebView::title() const
{
- Q_D(const QFxWebView);
- if (d->page)
- return d->page->mainFrame()->title();
- return QString();
+ return page()->mainFrame()->title();
}
@@ -832,10 +812,7 @@ QString QFxWebView::title() const
*/
QPixmap QFxWebView::icon() const
{
- Q_D(const QFxWebView);
- if (d->page)
- return d->page->mainFrame()->icon().pixmap(QSize(256,256));
- return QPixmap();
+ return page()->mainFrame()->icon().pixmap(QSize(256,256));
}
@@ -849,8 +826,7 @@ QPixmap QFxWebView::icon() const
*/
void QFxWebView::setTextSizeMultiplier(qreal factor)
{
- Q_D(QFxWebView);
- d->page->mainFrame()->setTextSizeMultiplier(factor);
+ page()->mainFrame()->setTextSizeMultiplier(factor);
}
/*!
@@ -858,8 +834,7 @@ void QFxWebView::setTextSizeMultiplier(qreal factor)
*/
qreal QFxWebView::textSizeMultiplier() const
{
- Q_D(const QFxWebView);
- return d->page->mainFrame()->textSizeMultiplier();
+ return page()->mainFrame()->textSizeMultiplier();
}
void QFxWebView::setStatusBarMessage(const QString& s)
@@ -878,9 +853,31 @@ QString QFxWebView::status() const
QWebPage *QFxWebView::page() const
{
Q_D(const QFxWebView);
+
+ if (!d->page) {
+ QFxWebView *self = const_cast<QFxWebView*>(this);
+ QWebPage *wp = new QFxWebPage(self);
+
+ // QML elements don't default to having a background,
+ // even though most we pages will set one anyway.
+ QPalette pal = QApplication::palette();
+ pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0));
+ wp->setPalette(pal);
+
+ wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager());
+
+ // XXX settable from QML?
+ wp->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
+
+ self->setPage(wp);
+
+ return wp;
+ }
+
return d->page;
}
+
void QFxWebView::setPage(QWebPage *page)
{
Q_D(QFxWebView);
diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp
index 1218b99..e7f7cfb 100644
--- a/src/declarative/qml/qmlmetaproperty.cpp
+++ b/src/declarative/qml/qmlmetaproperty.cpp
@@ -103,7 +103,18 @@ QmlMetaProperty::~QmlMetaProperty()
// ### not thread safe
static QHash<const QMetaObject *, QMetaPropertyEx> qmlCacheDefProp;
+
+/*!
+ Creates a QmlMetaProperty for the default property of \a obj. If there is no
+ default property, an invalid QmlMetaProperty will be created.
+ */
+QmlMetaProperty::QmlMetaProperty(QObject *obj)
+{
+ initDefault(obj);
+}
+
/*!
+ \internal
Creates a QmlMetaProperty for the default property of \a obj. If there is no
default property, an invalid QmlMetaProperty will be created.
*/
@@ -111,6 +122,11 @@ QmlMetaProperty::QmlMetaProperty(QObject *obj, QmlContext *ctxt)
: d(new QmlMetaPropertyPrivate)
{
d->context = ctxt;
+ initDefault(obj);
+}
+
+void QmlMetaProperty::initDefault(QObject *obj)
+{
if(!obj)
return;
@@ -162,6 +178,16 @@ static QHash<const QMetaObject *, QHash<QString, QMetaPropertyEx> > qmlCacheProp
/*!
Creates a QmlMetaProperty for the property \a name of \a obj.
*/
+QmlMetaProperty::QmlMetaProperty(QObject *obj, const QString &name)
+: d(new QmlMetaPropertyPrivate)
+{
+ initProperty(obj, name);
+}
+
+/*!
+ \internal
+ Creates a QmlMetaProperty for the property \a name of \a obj.
+ */
QmlMetaProperty::QmlMetaProperty(QObject *obj, const QString &name, QmlContext *ctxt)
: d(new QmlMetaPropertyPrivate)
{
@@ -170,6 +196,11 @@ QmlMetaProperty::QmlMetaProperty(QObject *obj, const QString &name, QmlContext *
#endif
d->context = ctxt;
+ initProperty(obj, name);
+}
+
+void QmlMetaProperty::initProperty(QObject *obj, const QString &name)
+{
d->name = name;
d->object = obj;
if(name.isEmpty() || !obj)
diff --git a/src/declarative/qml/qmlmetaproperty.h b/src/declarative/qml/qmlmetaproperty.h
index a2939f9..4836038 100644
--- a/src/declarative/qml/qmlmetaproperty.h
+++ b/src/declarative/qml/qmlmetaproperty.h
@@ -72,8 +72,10 @@ public:
Normal
};
QmlMetaProperty();
- QmlMetaProperty(QObject *, QmlContext * = 0);
- QmlMetaProperty(QObject *, const QString &, QmlContext * = 0);
+ QmlMetaProperty(QObject *);
+ QmlMetaProperty(QObject *, const QString &);
+ QmlMetaProperty(QObject *, QmlContext *);
+ QmlMetaProperty(QObject *, const QString &, QmlContext *);
QmlMetaProperty(const QmlMetaProperty &);
QmlMetaProperty &operator=(const QmlMetaProperty &);
QmlMetaProperty(QObject *, int, PropertyCategory = Unknown, QmlContext * = 0);
@@ -125,6 +127,8 @@ public:
int coreIndex() const;
private:
+ void initDefault(QObject *obj);
+ void initProperty(QObject *obj, const QString &name);
friend class QmlEnginePrivate;
QmlMetaPropertyPrivate *d;
};