From 83773bdfe37acd793d07c4a23202a4fd45a8d6f7 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 27 Apr 2009 11:01:09 +1000 Subject: Fix the highlight positioning. --- examples/declarative/listview/listview.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'. --> - + -- cgit v0.12 From 7b3bb2c188234aac63435ed563085ed392068be3 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 27 Apr 2009 12:54:45 +1000 Subject: Doc fixes. --- src/declarative/fx/qfxitem.cpp | 62 ++++++++++++++++++++++++++++-------------- src/declarative/fx/qfxitem.h | 15 +++++----- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 6b4c504..240aef6 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -237,24 +237,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() */ /*! @@ -324,7 +320,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 @@ -339,7 +335,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 @@ -1111,36 +1107,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); @@ -1216,18 +1230,9 @@ QFxAnchorLine QFxItem::verticalCenter() const For more information see \l {anchor-layout}{Anchor Layouts}. */ -/* - \property QFxItem::baseline - \brief The position of the item's baseline in global (scene) coordinates. - - The baseline of a Text item is the imaginary line on which the text - sits. Controls containing text usually set their baseline to the - baseline of their text. - - For non-text items, a default baseline offset of two-thirds of the - item's height is used to determine the baseline. +/*! + \internal */ - int QFxItem::baselineOffset() const { Q_D(const QFxItem); @@ -1237,6 +1242,9 @@ int QFxItem::baselineOffset() const return d->_baselineOffset; } +/*! + \internal +*/ void QFxItem::setBaselineOffset(int offset) { Q_D(QFxItem); @@ -1533,6 +1541,13 @@ QmlState *QFxItem::findState(const QString &name) const \sa {states-transitions}{States and Transitions} */ + +/*! + \property QFxItem::state + \brief the current state of the item. + + \sa {states-transitions}{States and Transitions} +*/ QString QFxItem::state() const { Q_D(const QFxItem); @@ -1598,7 +1613,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(this) << ", " << (void *)static_cast(this) << "):" << x() << y() << width() << height() << (void *) itemParent(); } @@ -1700,6 +1714,9 @@ void QFxItem::reparentItems() qFatal("EEK"); } +/*! + \internal +*/ void QFxItem::updateTransform() { Q_D(QFxItem); @@ -1714,6 +1731,9 @@ void QFxItem::updateTransform() transformChanged(trans); } +/*! + \internal +*/ void QFxItem::transformChanged(const QSimpleCanvas::Matrix &) { } diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index c47a1e1..7de0aae 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -181,13 +181,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); @@ -266,8 +259,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) }; -- cgit v0.12 From ddb7c72fae2c3acb7608c5979c6b425691cc14d3 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 27 Apr 2009 12:56:38 +1000 Subject: Add some constructors without QmlContext parameter. and mark the existing constructors internal. --- src/declarative/qml/qmlmetaproperty.cpp | 31 +++++++++++++++++++++++++++++++ src/declarative/qml/qmlmetaproperty.h | 8 ++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 30e0bbc..ef9e970 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -100,7 +100,18 @@ QmlMetaProperty::~QmlMetaProperty() // ### not thread safe static QHash 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. */ @@ -108,6 +119,11 @@ QmlMetaProperty::QmlMetaProperty(QObject *obj, QmlContext *ctxt) : d(new QmlMetaPropertyPrivate) { d->context = ctxt; + initDefault(obj); +} + +void QmlMetaProperty::initDefault(QObject *obj) +{ if(!obj) return; @@ -159,6 +175,16 @@ static QHash > 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) { @@ -167,6 +193,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; }; -- cgit v0.12 From c33403a2e6a567a1e9bae9c0384a70dcae7d9961 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 27 Apr 2009 12:57:49 +1000 Subject: Fix warning. --- src/declarative/fx/qfxflickable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 5715116..a27e04d 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -627,7 +627,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) lastPos = event->pos(); } -void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *) { Q_Q(QFxFlickable); -- cgit v0.12 From d62bc81491b4b3ef76d626fd56f736427ee1e20c Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 27 Apr 2009 17:22:05 +1000 Subject: Fix use of qmlContext() - move outside contructor. --- src/declarative/fx/qfxwebview.cpp | 97 +++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 50 deletions(-) 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(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); -- cgit v0.12 From d782ceee4de31bc4a11cd6cdeacc881bd1c118d8 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 27 Apr 2009 17:39:47 +1000 Subject: Make MouseRegion signals pass a mouse event as their parameter. --- examples/declarative/connections/connections.qml | 6 +- examples/declarative/mouseregion/mouse.qml | 12 +-- src/declarative/fx/fx.pri | 2 + src/declarative/fx/qfxevents.cpp | 72 +++++++++++++ src/declarative/fx/qfxevents_p.h | 127 +++++++++++++++++++++++ src/declarative/fx/qfxitem.cpp | 27 +---- src/declarative/fx/qfxitem.h | 5 +- src/declarative/fx/qfxmouseregion.cpp | 59 +++++++---- src/declarative/fx/qfxmouseregion.h | 11 +- src/declarative/fx/qfxmouseregion_p.h | 11 ++ 10 files changed, 269 insertions(+), 63 deletions(-) create mode 100644 src/declarative/fx/qfxevents.cpp create mode 100644 src/declarative/fx/qfxevents_p.h 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 @@ - + color="green"; - dot.x = x-1; - dot.y = y-1; + dot.x = mouse.x-1; + dot.y = mouse.y-1; 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 @@ - @@ -14,8 +14,8 @@ +#include +#include +#include + +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/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 240aef6..c2e35b9 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 #include @@ -1024,34 +1025,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()) @@ -1063,7 +1043,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()) @@ -1777,5 +1757,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 7de0aae..3f7784b 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 { @@ -228,8 +229,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(); diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp index c6a7f96..bfd03f7 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 @@ -154,12 +155,15 @@ void QFxDrag::setYmax(int m) \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 - + \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 @@ -330,7 +338,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; @@ -354,7 +362,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(); @@ -426,6 +434,7 @@ void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if(!d->absorb) QFxItem::mouseReleaseEvent(event); else { + d->saveEvent(event); setPressed(false); //d->inside = false; //emit hoveredChanged(); @@ -441,8 +450,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(); } } @@ -490,7 +501,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); } } } @@ -533,12 +545,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; }; -- cgit v0.12 From 768658b51ebabff535263efb0870b436beb00fcc Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 27 Apr 2009 17:44:25 +1000 Subject: Don't crash when not using QFxVisualItemModel with PathView PathView was creating its own internal QFxVisualItemModel but not correctly setting the context. --- src/declarative/fx/qfxpathview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); -- cgit v0.12