diff options
author | Jan Arve Saether <jan-arve.saether@qt.io> | 2017-06-26 18:38:27 +0200 |
---|---|---|
committer | Jan Arve Saether <jan-arve.saether@qt.io> | 2017-07-11 16:44:33 +0200 |
commit | b6e6e737f1a4a7e48989a6a036e25c238304802f (patch) | |
tree | 8d4b5940b92ad1fc94e46c1742acd9355e19e1d4 /src/quick/items | |
parent | d5b3f5da9cfa90fc43f29f3bdeec01884a47d6ca (diff) | |
parent | 4beee1a6dcc1be57aa6fb2a175dadc6ff298545d (diff) |
Merge remote-tracking branch 'origin/dev' into wip/pointerhandler
Conflicts:
examples/quick/shared/LauncherList.qml
src/quick/items/qquickevents.cpp
src/quick/items/qquickevents_p_p.h
src/quick/items/qquickwindow.cpp
tests/auto/quick/touchmouse/tst_touchmouse.cpp
Change-Id: Id692d291455093fc72db61f1b854f3fc9190267b
Diffstat (limited to 'src/quick/items')
34 files changed, 372 insertions, 137 deletions
diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index ebfa6deb6f..9ac7422a39 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -40,6 +40,7 @@ #include "qquickcontext2d_p.h" #include "qquickcontext2dcommandbuffer_p.h" #include "qquickcanvasitem_p.h" +#include <private/qtquickglobal_p.h> #include <private/qquickcontext2dtexture_p.h> #include <private/qquickitem_p.h> #if QT_CONFIG(quick_shadereffect) @@ -136,7 +137,7 @@ Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok); THROW_GENERIC_ERROR("Not a Context2D object"); #define qClamp(val, min, max) qMin(qMax(val, min), max) #define CHECK_RGBA(c) (c == '-' || c == '.' || (c >=0 && c <= 9)) -QColor qt_color_from_string(const QV4::Value &name) +Q_QUICK_PRIVATE_EXPORT QColor qt_color_from_string(const QV4::Value &name) { QByteArray str = name.toQString().toUtf8(); diff --git a/src/quick/items/items.qrc b/src/quick/items/items.qrc index 6aaf757c29..da9bf0c828 100644 --- a/src/quick/items/items.qrc +++ b/src/quick/items/items.qrc @@ -8,5 +8,9 @@ <file>shaders/shadereffect_core.vert</file> <file>shaders/shadereffectfallback_core.frag</file> <file>shaders/shadereffectfallback_core.vert</file> + <file>shaders/lineargradient.vert</file> + <file>shaders/lineargradient.frag</file> + <file>shaders/lineargradient_core.vert</file> + <file>shaders/lineargradient_core.frag</file> </qresource> </RCC> diff --git a/src/quick/items/qquickanimatedimage_p.h b/src/quick/items/qquickanimatedimage_p.h index 143fe8904d..54da093259 100644 --- a/src/quick/items/qquickanimatedimage_p.h +++ b/src/quick/items/qquickanimatedimage_p.h @@ -97,7 +97,6 @@ Q_SIGNALS: void playingChanged(); void pausedChanged(); void frameChanged(); - void sourceSizeChanged(); private Q_SLOTS: void movieUpdate(); diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp index 830adc50b7..1e0d268f93 100644 --- a/src/quick/items/qquickevents.cpp +++ b/src/quick/items/qquickevents.cpp @@ -1293,8 +1293,8 @@ QTouchEvent *QQuickPointerTouchEvent::touchEventForItem(QQuickItem *item, bool i } parent = parent->parentItem(); } - bool filterRelevant = isFiltering && grabberIsChild; + bool filterRelevant = isFiltering && grabberIsChild; if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant)) continue; if ((p->state() == QQuickEventPoint::Pressed || p->state() == QQuickEventPoint::Released) && isInside) diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h index 19b2a6221e..b39e81d6e8 100644 --- a/src/quick/items/qquickevents_p_p.h +++ b/src/quick/items/qquickevents_p_p.h @@ -386,9 +386,9 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPointerEvent : public QObject Q_PROPERTY(Qt::MouseButtons buttons READ buttons) public: - QQuickPointerEvent(QObject *parent = nullptr) + QQuickPointerEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr) : QObject(parent) - , m_device(nullptr) + , m_device(device) , m_event(nullptr) , m_button(Qt::NoButton) , m_pressedButtons(Qt::NoButton) @@ -446,8 +446,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPointerMouseEvent : public QQuickPointerEvent { Q_OBJECT public: - QQuickPointerMouseEvent(QObject *parent = nullptr) - : QQuickPointerEvent(parent), m_mousePoint(new QQuickEventPoint(this)) { } + QQuickPointerMouseEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr) + : QQuickPointerEvent(parent, device), m_mousePoint(new QQuickEventPoint(this)) { } QQuickPointerEvent *reset(QEvent *) override; void localize(QQuickItem *target) override; @@ -479,8 +479,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPointerTouchEvent : public QQuickPointerEvent { Q_OBJECT public: - QQuickPointerTouchEvent(QObject *parent = nullptr) - : QQuickPointerEvent(parent) + QQuickPointerTouchEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr) + : QQuickPointerEvent(parent, device) , m_pointCount(0) , m_synthMouseEvent(QEvent::MouseMove, QPointF(), Qt::NoButton, Qt::NoButton, Qt::NoModifier) { } @@ -579,7 +579,6 @@ public: int buttonCount() const { return m_buttonCount; } QString name() const { return m_name; } QPointingDeviceUniqueId uniqueId() const { return m_uniqueId; } - QQuickPointerEvent *pointerEvent() const { return m_event; } static QQuickPointerDevice *touchDevice(QTouchDevice *d); static QList<QQuickPointerDevice *> touchDevices(); @@ -592,17 +591,10 @@ private: QQuickPointerDevice(DeviceType devType, PointerType pType, Capabilities caps, int maxPoints, int buttonCount, const QString &name, qint64 uniqueId = 0) : m_deviceType(devType), m_pointerType(pType), m_capabilities(caps) , m_maximumTouchPoints(maxPoints), m_buttonCount(buttonCount), m_name(name) - , m_uniqueId(QPointingDeviceUniqueId::fromNumericId(uniqueId)), m_event(nullptr) + , m_uniqueId(QPointingDeviceUniqueId::fromNumericId(uniqueId)) { - if (m_deviceType == Mouse) { - m_event = new QQuickPointerMouseEvent; - } else if (m_deviceType == TouchScreen || m_deviceType == TouchPad) { - m_event = new QQuickPointerTouchEvent; - } else { - Q_ASSERT(false); - } } - ~QQuickPointerDevice() { delete m_event; } + ~QQuickPointerDevice() { } private: DeviceType m_deviceType; @@ -612,8 +604,6 @@ private: int m_buttonCount; QString m_name; QPointingDeviceUniqueId m_uniqueId; - // the device-specific event instance which is reused during event delivery - QQuickPointerEvent *m_event; QVector<QQuickPointerHandler *> m_eventDeliveryTargets; // during delivery, handlers which have already seen the event Q_DISABLE_COPY(QQuickPointerDevice) diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index fd78c46a16..c570b95a21 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -495,9 +495,7 @@ bool QQuickGridViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal // We've jumped more than a page. Estimate which items are now // visible and fill from there. int count = (fillFrom - (rowPos + rowSize())) / (rowSize()) * columns; - for (FxViewItem *item : qAsConst(visibleItems)) - releaseItem(item); - visibleItems.clear(); + releaseVisibleItems(); modelIndex += count; if (modelIndex >= model->count()) modelIndex = model->count() - 1; diff --git a/src/quick/items/qquickimplicitsizeitem.cpp b/src/quick/items/qquickimplicitsizeitem.cpp index 1996fb9489..2569b2a224 100644 --- a/src/quick/items/qquickimplicitsizeitem.cpp +++ b/src/quick/items/qquickimplicitsizeitem.cpp @@ -45,29 +45,11 @@ QT_BEGIN_NAMESPACE /*! \internal - The purpose of QQuickImplicitSizeItem is not immediately clear, as both - the implicit size properties and signals exist on QQuickItem. However, - for some items - where the implicit size has an underlying meaning (such as - Image, where the implicit size represents the real size of the image) - having implicit size writable is an undesirable thing. - - QQuickImplicitSizeItem redefines the properties as being readonly. - Unfortunately, this also means they need to redefine the change signals. - See QTBUG-30258 for more information. + QQuickImplicitSizeItem redefines the implicitWidth and implicitHeight + properties as readonly, as some items (e.g. Image, where the implicit size + represents the real size of the image) should not be able to have their + implicit size modified. */ -void QQuickImplicitSizeItemPrivate::implicitWidthChanged() -{ - Q_Q(QQuickImplicitSizeItem); - QQuickItemPrivate::implicitWidthChanged(); - emit q->implicitWidthChanged2(); -} - -void QQuickImplicitSizeItemPrivate::implicitHeightChanged() -{ - Q_Q(QQuickImplicitSizeItem); - QQuickItemPrivate::implicitHeightChanged(); - emit q->implicitHeightChanged2(); -} QQuickImplicitSizeItem::QQuickImplicitSizeItem(QQuickImplicitSizeItemPrivate &dd, QQuickItem *parent) : QQuickItem(dd, parent) diff --git a/src/quick/items/qquickimplicitsizeitem_p.h b/src/quick/items/qquickimplicitsizeitem_p.h index 75b04449f8..8ae8f9f447 100644 --- a/src/quick/items/qquickimplicitsizeitem_p.h +++ b/src/quick/items/qquickimplicitsizeitem_p.h @@ -60,16 +60,12 @@ class QQuickImplicitSizeItemPrivate; class Q_QUICK_PRIVATE_EXPORT QQuickImplicitSizeItem : public QQuickItem { Q_OBJECT - Q_PROPERTY(qreal implicitWidth READ implicitWidth NOTIFY implicitWidthChanged2) - Q_PROPERTY(qreal implicitHeight READ implicitHeight NOTIFY implicitHeightChanged2) + Q_PROPERTY(qreal implicitWidth READ implicitWidth NOTIFY implicitWidthChanged) + Q_PROPERTY(qreal implicitHeight READ implicitHeight NOTIFY implicitHeightChanged) protected: QQuickImplicitSizeItem(QQuickImplicitSizeItemPrivate &dd, QQuickItem *parent); -Q_SIGNALS: - Q_REVISION(1) void implicitWidthChanged2(); - Q_REVISION(1) void implicitHeightChanged2(); - private: Q_DISABLE_COPY(QQuickImplicitSizeItem) Q_DECLARE_PRIVATE(QQuickImplicitSizeItem) diff --git a/src/quick/items/qquickimplicitsizeitem_p_p.h b/src/quick/items/qquickimplicitsizeitem_p_p.h index 2c42fa62f2..0495cf87e1 100644 --- a/src/quick/items/qquickimplicitsizeitem_p_p.h +++ b/src/quick/items/qquickimplicitsizeitem_p_p.h @@ -65,9 +65,6 @@ public: QQuickImplicitSizeItemPrivate() { } - - void implicitWidthChanged() Q_DECL_OVERRIDE; - void implicitHeightChanged() Q_DECL_OVERRIDE; }; QT_END_NAMESPACE diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index e959b51bc3..d923db6d68 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -147,8 +147,8 @@ QQuickTransform::QQuickTransform(QQuickTransformPrivate &dd, QObject *parent) QQuickTransform::~QQuickTransform() { Q_D(QQuickTransform); - for (QQuickItem *item : qAsConst(d->items)) { - QQuickItemPrivate *p = QQuickItemPrivate::get(item); + for (int ii = 0; ii < d->items.count(); ++ii) { + QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii)); p->transforms.removeOne(this); p->dirty(QQuickItemPrivate::Transform); } @@ -157,8 +157,8 @@ QQuickTransform::~QQuickTransform() void QQuickTransform::update() { Q_D(QQuickTransform); - for (QQuickItem *item : qAsConst(d->items)) { - QQuickItemPrivate *p = QQuickItemPrivate::get(item); + for (int ii = 0; ii < d->items.count(); ++ii) { + QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii)); p->dirty(QQuickItemPrivate::Transform); } } @@ -170,7 +170,9 @@ QQuickContents::QQuickContents(QQuickItem *item) QQuickContents::~QQuickContents() { - for (QQuickItem *child : m_item->childItems()) { + QList<QQuickItem *> children = m_item->childItems(); + for (int i = 0; i < children.count(); ++i) { + QQuickItem *child = children.at(i); QQuickItemPrivate::get(child)->removeItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed); } } @@ -193,8 +195,9 @@ bool QQuickContents::calcHeight(QQuickItem *changed) } else { qreal top = std::numeric_limits<qreal>::max(); qreal bottom = -std::numeric_limits<qreal>::max(); - const QList<QQuickItem*> children = m_item->childItems(); - for (QQuickItem *child : qAsConst(children)) { + QList<QQuickItem *> children = m_item->childItems(); + for (int i = 0; i < children.count(); ++i) { + QQuickItem *child = children.at(i); qreal y = child->y(); if (y + child->height() > bottom) bottom = y + child->height(); @@ -227,8 +230,9 @@ bool QQuickContents::calcWidth(QQuickItem *changed) } else { qreal left = std::numeric_limits<qreal>::max(); qreal right = -std::numeric_limits<qreal>::max(); - const QList<QQuickItem*> children = m_item->childItems(); - for (QQuickItem *child : qAsConst(children)) { + QList<QQuickItem *> children = m_item->childItems(); + for (int i = 0; i < children.count(); ++i) { + QQuickItem *child = children.at(i); qreal x = child->x(); if (x + child->width() > right) right = x + child->width(); @@ -247,7 +251,9 @@ void QQuickContents::complete() { QQuickItemPrivate::get(m_item)->addItemChangeListener(this, QQuickItemPrivate::Children); - for (QQuickItem *child : m_item->childItems()) { + QList<QQuickItem *> children = m_item->childItems(); + for (int i = 0; i < children.count(); ++i) { + QQuickItem *child = children.at(i); QQuickItemPrivate::get(child)->addItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed); //###what about changes to visibility? } @@ -1348,7 +1354,8 @@ void QQuickKeysAttached::componentComplete() #if QT_CONFIG(im) Q_D(QQuickKeysAttached); if (d->item) { - for (QQuickItem *targetItem : qAsConst(d->targets)) { + for (int ii = 0; ii < d->targets.count(); ++ii) { + QQuickItem *targetItem = d->targets.at(ii); if (targetItem && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) { d->item->setFlag(QQuickItem::ItemAcceptsInputMethod); break; @@ -1370,10 +1377,11 @@ void QQuickKeysAttached::keyPressed(QKeyEvent *event, bool post) // first process forwards if (d->item && d->item->window()) { d->inPress = true; - for (QQuickItem *targetItem : qAsConst(d->targets)) { - if (targetItem && targetItem->isVisible()) { + for (int ii = 0; ii < d->targets.count(); ++ii) { + QQuickItem *i = d->targets.at(ii); + if (i && i->isVisible()) { event->accept(); - QCoreApplication::sendEvent(targetItem, event); + QCoreApplication::sendEvent(i, event); if (event->isAccepted()) { d->inPress = false; return; @@ -1413,10 +1421,11 @@ void QQuickKeysAttached::keyReleased(QKeyEvent *event, bool post) if (d->item && d->item->window()) { d->inRelease = true; - for (QQuickItem *targetItem : qAsConst(d->targets)) { - if (targetItem && targetItem->isVisible()) { + for (int ii = 0; ii < d->targets.count(); ++ii) { + QQuickItem *i = d->targets.at(ii); + if (i && i->isVisible()) { event->accept(); - QCoreApplication::sendEvent(targetItem, event); + QCoreApplication::sendEvent(i, event); if (event->isAccepted()) { d->inRelease = false; return; @@ -1440,7 +1449,8 @@ void QQuickKeysAttached::inputMethodEvent(QInputMethodEvent *event, bool post) Q_D(QQuickKeysAttached); if (post == m_processPost && d->item && !d->inIM && d->item->window()) { d->inIM = true; - for (QQuickItem *targetItem : qAsConst(d->targets)) { + for (int ii = 0; ii < d->targets.count(); ++ii) { + QQuickItem *targetItem = d->targets.at(ii); if (targetItem && targetItem->isVisible() && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) { QCoreApplication::sendEvent(targetItem, event); if (event->isAccepted()) { @@ -1459,12 +1469,13 @@ QVariant QQuickKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const { Q_D(const QQuickKeysAttached); if (d->item) { - for (QQuickItem *targetItem : qAsConst(d->targets)) { - if (targetItem && targetItem->isVisible() && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod) && targetItem == d->imeItem) { - //### how robust is targetItem == d->imeItem check? - QVariant v = targetItem->inputMethodQuery(query); + for (int ii = 0; ii < d->targets.count(); ++ii) { + QQuickItem *i = d->targets.at(ii); + if (i && i->isVisible() && (i->flags() & QQuickItem::ItemAcceptsInputMethod) && i == d->imeItem) { + //### how robust is i == d->imeItem check? + QVariant v = i->inputMethodQuery(query); if (v.userType() == QVariant::RectF) - v = d->item->mapRectFromItem(targetItem, v.toRectF()); //### cost? + v = d->item->mapRectFromItem(i, v.toRectF()); //### cost? return v; } } @@ -1638,9 +1649,11 @@ void QQuickItemPrivate::setImplicitLayoutMirror(bool mirror, bool inherit) if (isMirrorImplicit) setLayoutMirror(inherit ? inheritedLayoutMirror : false); - for (QQuickItem *child : qAsConst(childItems)) { - QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child); - childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent); + for (int i = 0; i < childItems.count(); ++i) { + if (QQuickItem *child = qmlobject_cast<QQuickItem *>(childItems.at(i))) { + QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child); + childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent); + } } } @@ -2396,7 +2409,8 @@ QQuickItem::~QQuickItem() remove themselves from our list of transforms when that list has already been destroyed after ~QQuickItem() has run. */ - for (QQuickTransform *t : qAsConst(d->transforms)) { + for (int ii = 0; ii < d->transforms.count(); ++ii) { + QQuickTransform *t = d->transforms.at(ii); QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t); tp->items.removeOne(this); } @@ -2887,8 +2901,8 @@ QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems() const // If none of the items have set Z then the paint order list is the same as // the childItems list. This is by far the most common case. bool haveZ = false; - for (QQuickItem *childItem : qAsConst(childItems)) { - if (QQuickItemPrivate::get(childItem)->z() != 0.) { + for (int i = 0; i < childItems.count(); ++i) { + if (QQuickItemPrivate::get(childItems.at(i))->z() != 0.) { haveZ = true; break; } @@ -2989,7 +3003,8 @@ void QQuickItemPrivate::refWindow(QQuickWindow *c) if (!parentItem) QQuickWindowPrivate::get(window)->parentlessItems.insert(q); - for (QQuickItem *child : qAsConst(childItems)) { + for (int ii = 0; ii < childItems.count(); ++ii) { + QQuickItem *child = childItems.at(ii); QQuickItemPrivate::get(child)->refWindow(c); } @@ -3041,7 +3056,8 @@ void QQuickItemPrivate::derefWindow() paintNode = 0; - for (QQuickItem *child : qAsConst(childItems)) { + for (int ii = 0; ii < childItems.count(); ++ii) { + QQuickItem *child = childItems.at(ii); QQuickItemPrivate::get(child)->derefWindow(); } @@ -3498,7 +3514,8 @@ void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop) QQuickItem *that = static_cast<QQuickItem *>(prop->object); QQuickItemPrivate *p = QQuickItemPrivate::get(that); - for (QQuickTransform *t : qAsConst(p->transforms)) { + for (int ii = 0; ii < p->transforms.count(); ++ii) { + QQuickTransform *t = p->transforms.at(ii); QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t); tp->items.removeOne(that); } @@ -5885,9 +5902,8 @@ bool QQuickItemPrivate::setEffectiveVisibleRecur(bool newEffectiveVisible) } bool childVisibilityChanged = false; - for (QQuickItem *childItem : qAsConst(childItems)) { - childVisibilityChanged |= QQuickItemPrivate::get(childItem)->setEffectiveVisibleRecur(newEffectiveVisible); - } + for (int ii = 0; ii < childItems.count(); ++ii) + childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible); itemChange(QQuickItem::ItemVisibleHasChanged, effectiveVisible); #if QT_CONFIG(accessibility) @@ -5936,8 +5952,8 @@ void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope, bool newEffec } } - for (QQuickItem *childItem : qAsConst(childItems)) { - QQuickItemPrivate::get(childItem)->setEffectiveEnableRecur( + for (int ii = 0; ii < childItems.count(); ++ii) { + QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur( (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable); } @@ -6378,6 +6394,7 @@ void QQuickItem::setFlags(Flags flags) \qmlproperty real QtQuick::Item::height Defines the item's position and size. + The default value is \c 0. The (x,y) position is relative to the \l parent. diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index 13f23c918a..e6321e9365 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -376,6 +376,12 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType<QQuickFlickable, 9>(uri, 2, 9, "Flickable"); qmlRegisterType<QQuickMouseArea, 9>(uri, 2, 9, "MouseArea"); + +#if QT_CONFIG(quick_path) + qmlRegisterType<QQuickPathArc, 2>(uri, 2, 9, "PathArc"); + qmlRegisterType<QQuickPathMove>(uri, 2, 9, "PathMove"); +#endif + qmlRegisterType<QQuickText, 9>(uri, 2, 9, "Text"); qmlRegisterType<QQuickTextInput, 9>(uri, 2, 9, "TextInput"); qmlRegisterType<QQuickTouchPoint>(uri, 2, 9, "TouchPoint"); diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index 555db03962..084b1f197a 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -380,9 +380,7 @@ void QQuickItemView::setDelegate(QQmlComponent *delegate) int oldCount = dataModel->count(); dataModel->setDelegate(delegate); if (isComponentComplete()) { - for (FxViewItem *item : qAsConst(d->visibleItems)) - d->releaseItem(item); - d->visibleItems.clear(); + d->releaseVisibleItems(); d->releaseItem(d->currentItem); d->currentItem = 0; d->updateSectionCriteria(); @@ -1743,9 +1741,7 @@ void QQuickItemViewPrivate::clear() currentChanges.reset(); timeline.clear(); - for (FxViewItem *item : qAsConst(visibleItems)) - releaseItem(item); - visibleItems.clear(); + releaseVisibleItems(); visibleIndex = 0; for (FxViewItem *item : qAsConst(releasePendingTransition)) { diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h index 3087682ac7..b6353246e8 100644 --- a/src/quick/items/qquickitemview_p_p.h +++ b/src/quick/items/qquickitemview_p_p.h @@ -269,6 +269,15 @@ public: q->polish(); } + void releaseVisibleItems() { + // make a copy and clear the visibleItems first to avoid destroyed + // items being accessed during the loop (QTBUG-61294) + const QList<FxViewItem *> oldVisible = visibleItems; + visibleItems.clear(); + for (FxViewItem *item : oldVisible) + releaseItem(item); + } + QPointer<QQmlInstanceModel> model; QVariant modelVariant; int itemCount; diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index f739115e6b..18f9b8512d 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -660,9 +660,7 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal int newModelIdx = qBound(0, modelIndex + count, model->count()); count = newModelIdx - modelIndex; if (count) { - for (FxViewItem *item : qAsConst(visibleItems)) - releaseItem(item); - visibleItems.clear(); + releaseVisibleItems(); modelIndex = newModelIdx; visibleIndex = modelIndex; visiblePos = itemEnd + count * (averageSize + spacing); diff --git a/src/quick/items/qquickopenglshadereffect.cpp b/src/quick/items/qquickopenglshadereffect.cpp index 4fcfe04b55..c3e0ba05bd 100644 --- a/src/quick/items/qquickopenglshadereffect.cpp +++ b/src/quick/items/qquickopenglshadereffect.cpp @@ -230,7 +230,7 @@ void QQuickOpenGLShaderEffectCommon::disconnectPropertySignals(QQuickItem *item, auto mapper = signalMappers[shaderType].at(i); void *a = mapper; QObjectPrivate::disconnect(item, mapper->signalIndex(), &a); - if (d.specialType == UniformData::Sampler) { + if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) { QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); if (source) { if (item->window()) @@ -272,7 +272,7 @@ void QQuickOpenGLShaderEffectCommon::connectPropertySignals(QQuickItem *item, qWarning("QQuickOpenGLShaderEffect: '%s' does not have a matching property!", d.name.constData()); } - if (d.specialType == UniformData::Sampler) { + if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) { QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); if (source) { if (item->window()) @@ -335,6 +335,7 @@ void QQuickOpenGLShaderEffectCommon::lookThroughShaderCode(QQuickItem *item, Q_ASSERT(decl == UniformQualifier); const int sampLen = sizeof("sampler2D") - 1; + const int sampExtLen = sizeof("samplerExternalOES") - 1; const int opLen = sizeof("qt_Opacity") - 1; const int matLen = sizeof("qt_Matrix") - 1; const int srLen = sizeof("qt_SubRect_") - 1; @@ -357,8 +358,12 @@ void QQuickOpenGLShaderEffectCommon::lookThroughShaderCode(QQuickItem *item, mapper = new QtPrivate::MappedSlotObject([this, mappedId](){ this->mappedPropertyChanged(mappedId); }); - bool sampler = typeLength == sampLen && qstrncmp("sampler2D", s + typeIndex, sampLen) == 0; - d.specialType = sampler ? UniformData::Sampler : UniformData::None; + if (typeLength == sampLen && qstrncmp("sampler2D", s + typeIndex, sampLen) == 0) + d.specialType = UniformData::Sampler; + else if (typeLength == sampExtLen && qstrncmp("samplerExternalOES", s + typeIndex, sampExtLen) == 0) + d.specialType = UniformData::SamplerExternal; + else + d.specialType = UniformData::None; d.setValueFromProperty(item, itemMetaObject); } uniformData[shaderType].append(d); @@ -451,7 +456,8 @@ void QQuickOpenGLShaderEffectCommon::updateMaterial(QQuickOpenGLShaderEffectNode int textureProviderCount = 0; for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) { for (int i = 0; i < uniformData[shaderType].size(); ++i) { - if (uniformData[shaderType].at(i).specialType == UniformData::Sampler) + if (uniformData[shaderType].at(i).specialType == UniformData::Sampler || + uniformData[shaderType].at(i).specialType == UniformData::SamplerExternal) ++textureProviderCount; } material->uniforms[shaderType] = uniformData[shaderType]; @@ -474,7 +480,7 @@ void QQuickOpenGLShaderEffectCommon::updateMaterial(QQuickOpenGLShaderEffectNode for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) { for (int i = 0; i < uniformData[shaderType].size(); ++i) { const UniformData &d = uniformData[shaderType].at(i); - if (d.specialType != UniformData::Sampler) + if (d.specialType != UniformData::Sampler && d.specialType != UniformData::SamplerExternal) continue; QSGTextureProvider *oldProvider = material->textureProviders.at(index); QSGTextureProvider *newProvider = 0; @@ -513,7 +519,7 @@ void QQuickOpenGLShaderEffectCommon::updateWindow(QQuickWindow *window) for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) { for (int i = 0; i < uniformData[shaderType].size(); ++i) { const UniformData &d = uniformData[shaderType].at(i); - if (d.specialType == UniformData::Sampler) { + if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) { QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); if (source) QQuickItemPrivate::get(source)->refWindow(window); @@ -524,7 +530,7 @@ void QQuickOpenGLShaderEffectCommon::updateWindow(QQuickWindow *window) for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) { for (int i = 0; i < uniformData[shaderType].size(); ++i) { const UniformData &d = uniformData[shaderType].at(i); - if (d.specialType == UniformData::Sampler) { + if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) { QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); if (source) QQuickItemPrivate::get(source)->derefWindow(); @@ -539,7 +545,7 @@ void QQuickOpenGLShaderEffectCommon::sourceDestroyed(QObject *object) for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) { for (int i = 0; i < uniformData[shaderType].size(); ++i) { UniformData &d = uniformData[shaderType][i]; - if (d.specialType == UniformData::Sampler && d.value.canConvert<QObject *>()) { + if ((d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) && d.value.canConvert<QObject *>()) { if (qvariant_cast<QObject *>(d.value) == object) d.value = QVariant(); } @@ -554,7 +560,7 @@ static bool qquick_uniqueInUniformData(QQuickItem *source, const QVector<QQuickO if (s == typeToSkip && i == indexToSkip) continue; const QQuickOpenGLShaderEffectMaterial::UniformData &d = uniformData[s][i]; - if (d.specialType == QQuickOpenGLShaderEffectMaterial::UniformData::Sampler && qvariant_cast<QObject *>(d.value) == source) + if ((d.specialType == QQuickOpenGLShaderEffectMaterial::UniformData::Sampler || d.specialType == QQuickOpenGLShaderEffectMaterial::UniformData::SamplerExternal) && qvariant_cast<QObject *>(d.value) == source) return false; } } @@ -568,7 +574,7 @@ void QQuickOpenGLShaderEffectCommon::propertyChanged(QQuickItem *item, Key::ShaderType shaderType = Key::ShaderType(mappedId >> 16); int index = mappedId & 0xffff; UniformData &d = uniformData[shaderType][index]; - if (d.specialType == UniformData::Sampler) { + if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) { QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); if (source) { if (item->window()) diff --git a/src/quick/items/qquickopenglshadereffectnode.cpp b/src/quick/items/qquickopenglshadereffectnode.cpp index e1ea98641d..5dbfee73cb 100644 --- a/src/quick/items/qquickopenglshadereffectnode.cpp +++ b/src/quick/items/qquickopenglshadereffectnode.cpp @@ -47,6 +47,10 @@ #include <QtCore/qmutex.h> #include <QtGui/qopenglfunctions.h> +#ifndef GL_TEXTURE_EXTERNAL_OES +#define GL_TEXTURE_EXTERNAL_OES 0x8D65 +#endif + QT_BEGIN_NAMESPACE static bool hasAtlasTexture(const QVector<QSGTextureProvider *> &textureProviders) @@ -124,7 +128,7 @@ void QQuickCustomMaterialShader::updateState(const RenderState &state, QSGMateri for (int i = 0; i < material->uniforms[shaderType].size(); ++i) { const UniformData &d = material->uniforms[shaderType].at(i); QByteArray name = d.name; - if (d.specialType == UniformData::Sampler) { + if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) { program()->setUniformValue(d.name.constData(), textureProviderIndex++); // We don't need to store the sampler uniform locations, since their values // only need to be set once. Look for the "qt_SubRect_" uniforms instead. @@ -143,7 +147,7 @@ void QQuickCustomMaterialShader::updateState(const RenderState &state, QSGMateri for (int i = 0; i < material->uniforms[shaderType].size(); ++i) { const UniformData &d = material->uniforms[shaderType].at(i); int loc = m_uniformLocs[shaderType].at(i); - if (d.specialType == UniformData::Sampler) { + if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) { int idx = textureProviderIndex++; functions->glActiveTexture(GL_TEXTURE0 + idx); if (QSGTextureProvider *provider = material->textureProviders.at(idx)) { @@ -164,7 +168,10 @@ void QQuickCustomMaterialShader::updateState(const RenderState &state, QSGMateri continue; } } - functions->glBindTexture(GL_TEXTURE_2D, 0); + if (d.specialType == UniformData::Sampler) + functions->glBindTexture(GL_TEXTURE_2D, 0); + else if (d.specialType == UniformData::SamplerExternal) + functions->glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0); } else if (d.specialType == UniformData::Opacity) { program()->setUniformValue(loc, state.opacity()); } else if (d.specialType == UniformData::Matrix) { @@ -396,7 +403,7 @@ bool QQuickOpenGLShaderEffectMaterial::UniformData::operator == (const UniformDa if (name != other.name) return false; - if (specialType == UniformData::Sampler) { + if (specialType == UniformData::Sampler || specialType == UniformData::SamplerExternal) { // We can't check the source objects as these live in the GUI thread, // so return true here and rely on the textureProvider check for // equality of these.. diff --git a/src/quick/items/qquickopenglshadereffectnode_p.h b/src/quick/items/qquickopenglshadereffectnode_p.h index aea28e6612..784294d9eb 100644 --- a/src/quick/items/qquickopenglshadereffectnode_p.h +++ b/src/quick/items/qquickopenglshadereffectnode_p.h @@ -90,7 +90,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickOpenGLShaderEffectMaterial : public QSGMateri public: struct UniformData { - enum SpecialType { None, Sampler, SubRect, Opacity, Matrix }; + enum SpecialType { None, Sampler, SamplerExternal, SubRect, Opacity, Matrix }; QByteArray name; QVariant value; diff --git a/src/quick/items/qquickrectangle.cpp b/src/quick/items/qquickrectangle.cpp index 5ecca3c91d..9308553a79 100644 --- a/src/quick/items/qquickrectangle.cpp +++ b/src/quick/items/qquickrectangle.cpp @@ -1,6 +1,5 @@ /**************************************************************************** ** -** Copyright (C) 2017 Crimson AS <info@crimson.no> ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** @@ -270,9 +269,11 @@ QGradientStops QQuickGradient::gradientStops() const void QQuickGradient::doUpdate() { - static_cast<QQuickItem*>(parent())->update(); + emit updated(); } +int QQuickRectanglePrivate::doUpdateSlotIdx = -1; + /*! \qmltype Rectangle \instantiates QQuickRectangle @@ -329,6 +330,11 @@ QQuickRectangle::QQuickRectangle(QQuickItem *parent) #endif } +void QQuickRectangle::doUpdate() +{ + update(); +} + /*! \qmlproperty bool QtQuick::Rectangle::antialiasing @@ -393,7 +399,16 @@ void QQuickRectangle::setGradient(QQuickGradient *gradient) Q_D(QQuickRectangle); if (d->gradient == gradient) return; + static int updatedSignalIdx = -1; + if (updatedSignalIdx < 0) + updatedSignalIdx = QMetaMethod::fromSignal(&QQuickGradient::updated).methodIndex(); + if (d->doUpdateSlotIdx < 0) + d->doUpdateSlotIdx = QQuickRectangle::staticMetaObject.indexOfSlot("doUpdate()"); + if (d->gradient) + QMetaObject::disconnect(d->gradient, updatedSignalIdx, this, d->doUpdateSlotIdx); d->gradient = gradient; + if (d->gradient) + QMetaObject::connect(d->gradient, updatedSignalIdx, this, d->doUpdateSlotIdx); update(); } diff --git a/src/quick/items/qquickrectangle_p.h b/src/quick/items/qquickrectangle_p.h index 627f778e44..724a06013c 100644 --- a/src/quick/items/qquickrectangle_p.h +++ b/src/quick/items/qquickrectangle_p.h @@ -129,6 +129,9 @@ public: QGradientStops gradientStops() const; +Q_SIGNALS: + void updated(); + private: void doUpdate(); @@ -169,6 +172,9 @@ Q_SIGNALS: protected: QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) Q_DECL_OVERRIDE; +private Q_SLOTS: + void doUpdate(); + private: Q_DISABLE_COPY(QQuickRectangle) Q_DECLARE_PRIVATE(QQuickRectangle) diff --git a/src/quick/items/qquickrectangle_p_p.h b/src/quick/items/qquickrectangle_p_p.h index e771beec87..3c1aaf7661 100644 --- a/src/quick/items/qquickrectangle_p_p.h +++ b/src/quick/items/qquickrectangle_p_p.h @@ -76,6 +76,7 @@ public: QQuickGradient *gradient; QQuickPen *pen; qreal radius; + static int doUpdateSlotIdx; }; QT_END_NAMESPACE diff --git a/src/quick/items/qquickrepeater.cpp b/src/quick/items/qquickrepeater.cpp index 9ad7d27b18..6fc4c0553a 100644 --- a/src/quick/items/qquickrepeater.cpp +++ b/src/quick/items/qquickrepeater.cpp @@ -314,7 +314,11 @@ void QQuickRepeater::setDelegate(QQmlComponent *delegate) /*! \qmlproperty int QtQuick::Repeater::count - This property holds the number of items in the repeater. + This property holds the number of items in the model. + + \note The number of items in the model as reported by count may differ from + the number of created delegates if the Repeater is in the process of + instantiating delegates or is incorrectly set up. */ int QQuickRepeater::count() const { diff --git a/src/quick/items/qquickscreen.cpp b/src/quick/items/qquickscreen.cpp index 9b54b7fba9..6a3eab957e 100644 --- a/src/quick/items/qquickscreen.cpp +++ b/src/quick/items/qquickscreen.cpp @@ -100,6 +100,27 @@ QT_BEGIN_NAMESPACE The y coordinate of the screen within the virtual desktop. */ /*! + \qmlattachedproperty string Screen::manufacturer + \readonly + \since 5.10 + + The manufacturer of the screen. +*/ +/*! + \qmlattachedproperty string Screen::model + \readonly + \since 5.10 + + The model of the screen. +*/ +/*! + \qmlattachedproperty string Screen::serialNumber + \readonly + \since 5.10 + + The serial number of the screen. +*/ +/*! \qmlattachedproperty int Screen::width \readonly @@ -234,6 +255,27 @@ QString QQuickScreenInfo::name() const return m_screen->name(); } +QString QQuickScreenInfo::manufacturer() const +{ + if (!m_screen) + return QString(); + return m_screen->manufacturer(); +} + +QString QQuickScreenInfo::model() const +{ + if (!m_screen) + return QString(); + return m_screen->model(); +} + +QString QQuickScreenInfo::serialNumber() const +{ + if (!m_screen) + return QString(); + return m_screen->serialNumber(); +} + int QQuickScreenInfo::width() const { if (!m_screen) @@ -335,6 +377,12 @@ void QQuickScreenInfo::setWrappedScreen(QScreen *screen) } if (!oldScreen || screen->name() != oldScreen->name()) emit nameChanged(); + if (!oldScreen || screen->manufacturer() != oldScreen->manufacturer()) + emit manufacturerChanged(); + if (!oldScreen || screen->model() != oldScreen->model()) + emit modelChanged(); + if (!oldScreen || screen->serialNumber() != oldScreen->serialNumber()) + emit serialNumberChanged(); if (!oldScreen || screen->orientation() != oldScreen->orientation()) emit orientationChanged(); if (!oldScreen || screen->primaryOrientation() != oldScreen->primaryOrientation()) diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h index 99e1466631..e9db07d14c 100644 --- a/src/quick/items/qquickscreen_p.h +++ b/src/quick/items/qquickscreen_p.h @@ -68,6 +68,9 @@ class Q_AUTOTEST_EXPORT QQuickScreenInfo : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(QString manufacturer READ manufacturer NOTIFY manufacturerChanged REVISION 10) + Q_PROPERTY(QString model READ model NOTIFY modelChanged REVISION 10) + Q_PROPERTY(QString serialNumber READ serialNumber NOTIFY serialNumberChanged REVISION 10) Q_PROPERTY(int width READ width NOTIFY widthChanged) Q_PROPERTY(int height READ height NOTIFY heightChanged) Q_PROPERTY(int desktopAvailableWidth READ desktopAvailableWidth NOTIFY desktopGeometryChanged) @@ -87,6 +90,9 @@ public: QQuickScreenInfo(QObject *parent = nullptr, QScreen *wrappedScreen = nullptr); QString name() const; + QString manufacturer() const; + QString model() const; + QString serialNumber() const; int width() const; int height() const; int desktopAvailableWidth() const; @@ -104,6 +110,9 @@ public: Q_SIGNALS: void nameChanged(); + Q_REVISION(10) void manufacturerChanged(); + Q_REVISION(10) void modelChanged(); + Q_REVISION(10) void serialNumberChanged(); void widthChanged(); void heightChanged(); void desktopGeometryChanged(); diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 09371db66d..080cc9412e 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -384,6 +384,7 @@ void QQuickTextPrivate::updateSize() updateBaseline(fm.ascent(), q->height() - fontHeight - vPadding); q->setImplicitSize(hPadding, fontHeight + vPadding); layedOutTextRect = QRectF(0, 0, 0, fontHeight); + advance = QSizeF(); emit q->contentSizeChanged(); updateType = UpdatePaintNode; q->update(); @@ -457,8 +458,26 @@ void QQuickTextPrivate::updateSize() if (iWidth == -1) q->setImplicitHeight(size.height() + vPadding); + + QTextBlock firstBlock = extra->doc->firstBlock(); + while (firstBlock.layout()->lineCount() == 0) + firstBlock = firstBlock.next(); + + QTextBlock lastBlock = extra->doc->lastBlock(); + while (lastBlock.layout()->lineCount() == 0) + lastBlock = lastBlock.previous(); + + if (firstBlock.lineCount() > 0 && lastBlock.lineCount() > 0) { + QTextLine firstLine = firstBlock.layout()->lineAt(0); + QTextLine lastLine = lastBlock.layout()->lineAt(lastBlock.layout()->lineCount() - 1); + advance = QSizeF(lastLine.horizontalAdvance(), + (lastLine.y() + lastBlock.layout()->position().y()) - (firstLine.y() + firstBlock.layout()->position().y())); + } else { + advance = QSizeF(); + } } + if (layedOutTextRect.size() != previousSize) emit q->contentSizeChanged(); updateType = UpdatePaintNode; @@ -968,6 +987,16 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) br.moveTop(0); + // Find the advance of the text layout + if (layout.lineCount() > 0) { + QTextLine firstLine = layout.lineAt(0); + QTextLine lastLine = layout.lineAt(layout.lineCount() - 1); + advance = QSizeF(lastLine.horizontalAdvance(), + lastLine.y() - firstLine.y()); + } else { + advance = QSizeF(); + } + if (!horizontalFit && !verticalFit) break; @@ -3055,6 +3084,24 @@ QJSValue QQuickText::fontInfo() const return value; } +/*! + \qmlproperty size QtQuick::Text::advance + \since 5.10 + + The distance, in pixels, from the baseline origin of the first + character of the text item, to the baseline origin of the first + character in a text item occurring directly after this one + in a text flow. + + Note that the advance can be negative if the text flows from + the right to the left. +*/ +QSizeF QQuickText::advance() const +{ + Q_D(const QQuickText); + return d->advance; +} + QT_END_NAMESPACE #include "moc_qquicktext_p.cpp" diff --git a/src/quick/items/qquicktext_p.h b/src/quick/items/qquicktext_p.h index b190738cfb..a56bcdb87b 100644 --- a/src/quick/items/qquicktext_p.h +++ b/src/quick/items/qquicktext_p.h @@ -99,6 +99,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickText : public QQuickImplicitSizeItem Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION 6) Q_PROPERTY(QJSValue fontInfo READ fontInfo NOTIFY fontInfoChanged REVISION 9) + Q_PROPERTY(QSizeF advance READ advance NOTIFY contentSizeChanged REVISION 10) public: QQuickText(QQuickItem *parent=0); @@ -251,6 +252,7 @@ public: void resetBottomPadding(); QJSValue fontInfo() const; + QSizeF advance() const; Q_SIGNALS: void textChanged(const QString &text); diff --git a/src/quick/items/qquicktext_p_p.h b/src/quick/items/qquicktext_p_p.h index 6456750359..fde07eaf2e 100644 --- a/src/quick/items/qquicktext_p_p.h +++ b/src/quick/items/qquicktext_p_p.h @@ -89,6 +89,7 @@ public: void processHoverEvent(QHoverEvent *event); QRectF layedOutTextRect; + QSizeF advance; struct ExtraData { ExtraData(); diff --git a/src/quick/items/qquickview.cpp b/src/quick/items/qquickview.cpp index 8313b53a7d..fca1805fc9 100644 --- a/src/quick/items/qquickview.cpp +++ b/src/quick/items/qquickview.cpp @@ -496,6 +496,7 @@ void QQuickViewPrivate::setRootObject(QObject *obj) if (QQuickItem *sgItem = qobject_cast<QQuickItem *>(obj)) { root = sgItem; sgItem->setParentItem(q->QQuickWindow::contentItem()); + QQml_setParent_noEvent(sgItem, q->QQuickWindow::contentItem()); } else if (qobject_cast<QWindow *>(obj)) { qWarning() << "QQuickView does not support using windows as a root item." << endl << endl diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 713df4c500..b8b32b82be 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -529,6 +529,7 @@ void QQuickWindowPrivate::init(QQuickWindow *c, QQuickRenderControl *control) Q_Q(QQuickWindow); contentItem = new QQuickRootItem; + QQml_setParent_noEvent(contentItem, c); QQmlEngine::setObjectOwnership(contentItem, QQmlEngine::CppOwnership); QQuickItemPrivate *contentItemPrivate = QQuickItemPrivate::get(contentItem); contentItemPrivate->window = q; @@ -754,9 +755,9 @@ void QQuickWindowPrivate::setMouseGrabber(QQuickItem *grabber) if (grabber && touchMouseId != -1 && touchMouseDevice) { // update the touch item for mouse touch id to the new grabber qCDebug(DBG_TOUCH_TARGET) << "TP (mouse)" << hex << touchMouseId << "->" << q->mouseGrabberItem(); - auto point = touchMouseDevice->pointerEvent()->pointById(touchMouseId); + auto point = pointerEventInstance(touchMouseDevice)->pointById(touchMouseId); if (point) { - auto originalEvent = point->pointerEvent()->device()->pointerEvent(); + auto originalEvent = pointerEventInstance(point->pointerEvent()->device()); for (int i = 0; i < originalEvent->pointCount(); ++i) originalEvent->point(i)->cancelExclusiveGrab(); point->setGrabberItem(grabber); @@ -764,7 +765,7 @@ void QQuickWindowPrivate::setMouseGrabber(QQuickItem *grabber) point->cancelPassiveGrab(handler); } } else { - QQuickPointerEvent *event = QQuickPointerDevice::genericMouseDevice()->pointerEvent(); + QQuickPointerEvent *event = pointerEventInstance(QQuickPointerDevice::genericMouseDevice()); Q_ASSERT(event->pointCount() == 1); auto point = event->point(0); point->setGrabberItem(grabber); @@ -790,7 +791,7 @@ void QQuickWindowPrivate::grabTouchPoints(QObject *grabber, const QVector<int> & continue; } if (id == touchMouseId) { - auto point = touchMouseDevice->pointerEvent()->pointById(id); + auto point = pointerEventInstance(touchMouseDevice)->pointById(id); auto touchMouseGrabber = point->grabberItem(); if (touchMouseGrabber) { point->setExclusiveGrabber(nullptr); @@ -804,7 +805,7 @@ void QQuickWindowPrivate::grabTouchPoints(QObject *grabber, const QVector<int> & const auto touchDevices = QQuickPointerDevice::touchDevices(); for (auto device : touchDevices) { - auto point = device->pointerEvent()->pointById(id); + auto point = pointerEventInstance(device)->pointById(id); if (!point) continue; QObject *oldGrabber = point->exclusiveGrabber(); @@ -835,7 +836,7 @@ void QQuickWindowPrivate::removeGrabber(QQuickItem *grabber, bool mouse, bool to bool ungrab = false; const auto touchDevices = QQuickPointerDevice::touchDevices(); for (auto device : touchDevices) { - auto pointerEvent = device->pointerEvent(); + auto pointerEvent = pointerEventInstance(device); for (int i = 0; i < pointerEvent->pointCount(); ++i) { if (pointerEvent->point(i)->exclusiveGrabber() == grabber) { pointerEvent->point(i)->setGrabberItem(nullptr); @@ -1505,13 +1506,13 @@ QQuickItem *QQuickWindow::mouseGrabberItem() const Q_D(const QQuickWindow); if (d->touchMouseId != -1 && d->touchMouseDevice) { - QQuickPointerEvent *event = d->touchMouseDevice->pointerEvent(); + QQuickPointerEvent *event = d->pointerEventInstance(d->touchMouseDevice); auto point = event->pointById(d->touchMouseId); Q_ASSERT(point); return point->grabberItem(); } - QQuickPointerEvent *event = QQuickPointerDevice::genericMouseDevice()->pointerEvent(); + QQuickPointerEvent *event = d->pointerEventInstance(QQuickPointerDevice::genericMouseDevice()); Q_ASSERT(event->pointCount()); return event->point(0)->grabberItem(); } @@ -1934,7 +1935,7 @@ bool QQuickWindowPrivate::deliverTouchCancelEvent(QTouchEvent *event) // A TouchCancel event will typically not contain any points. // Deliver it to all items and handlers that have active touches. - QQuickPointerEvent *pointerEvent = QQuickPointerDevice::touchDevice(event->device())->pointerEvent(); + QQuickPointerEvent *pointerEvent = pointerEventInstance(QQuickPointerDevice::touchDevice(event->device())); for (int i = 0; i < pointerEvent->pointCount(); ++i) pointerEvent->point(i)->cancelExclusiveGrabImpl(event); touchMouseId = -1; @@ -2027,8 +2028,14 @@ bool QQuickWindowPrivate::compressTouchEvent(QTouchEvent *event) void QQuickWindowPrivate::handleTouchEvent(QTouchEvent *event) { translateTouchEvent(event); - if (event->touchPoints().size()) - lastMousePosition = event->touchPoints().at(0).pos(); + if (event->touchPoints().size()) { + auto point = event->touchPoints().at(0); + if (point.state() == Qt::TouchPointReleased) { + lastMousePosition = QPointF(); + } else { + lastMousePosition = point.pos(); + } + } qCDebug(DBG_TOUCH) << event; @@ -2106,7 +2113,7 @@ void QQuickWindowPrivate::handleMouseEvent(QMouseEvent *event) updateCursor(event->windowPos()); #endif - if (!QQuickPointerDevice::genericMouseDevice()->pointerEvent()->point(0)->exclusiveGrabber()) { + if (!pointerEventInstance(QQuickPointerDevice::genericMouseDevice())->point(0)->exclusiveGrabber()) { QPointF last = lastMousePosition.isNull() ? event->windowPos() : lastMousePosition; lastMousePosition = event->windowPos(); @@ -2153,6 +2160,32 @@ void QQuickWindowPrivate::flushFrameSynchronousEvents() } } +QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(QQuickPointerDevice *device) const +{ + // the list of devices should be very small so a linear search should be ok + for (QQuickPointerEvent *e: pointerEventInstances) { + if (e->device() == device) + return e; + } + + QQuickPointerEvent *ev = nullptr; + QQuickWindow *q = const_cast<QQuickWindow*>(q_func()); + switch (device->type()) { + case QQuickPointerDevice::Mouse: + ev = new QQuickPointerMouseEvent(q, device); + break; + case QQuickPointerDevice::TouchPad: + case QQuickPointerDevice::TouchScreen: + ev = new QQuickPointerTouchEvent(q, device); + break; + default: + // TODO tablet event types + break; + } + pointerEventInstances << ev; + return ev; +} + /*! \internal Returns a QQuickPointerEvent instance suitable for wrapping and delivering \a event. @@ -2163,25 +2196,29 @@ void QQuickWindowPrivate::flushFrameSynchronousEvents() QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(QEvent *event) const { QQuickPointerDevice *dev = nullptr; + QQuickPointerEvent *ev = nullptr; switch (event->type()) { case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseButtonDblClick: case QEvent::MouseMove: dev = QQuickPointerDevice::genericMouseDevice(); + ev = pointerEventInstance(dev); break; case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: case QEvent::TouchCancel: dev = QQuickPointerDevice::touchDevice(static_cast<QTouchEvent *>(event)->device()); + ev = pointerEventInstance(dev); break; // TODO tablet event types default: break; } - Q_ASSERT(dev); - return dev->pointerEvent()->reset(event); + + Q_ASSERT(ev); + return ev->reset(event); } void QQuickWindowPrivate::deliverPointerEvent(QQuickPointerEvent *event) @@ -2784,7 +2821,7 @@ bool QQuickWindowPrivate::sendFilteredPointerEvent(QQuickPointerEvent *event, QQ qCDebug(DBG_TOUCH) << "touch event intercepted as synth mouse event by childMouseEventFilter of " << filteringParent; if (t != QEvent::MouseButtonRelease) { qCDebug(DBG_TOUCH_TARGET) << "TP (mouse)" << hex << tp.id() << "->" << filteringParent; - touchMouseDevice->pointerEvent()->pointById(tp.id())->setGrabberItem(filteringParent); + pointerEventInstance(touchMouseDevice)->pointById(tp.id())->setGrabberItem(filteringParent); touchMouseUnset = false; // We want to leave touchMouseId and touchMouseDevice set filteringParent->grabMouse(); auto pointerEventPoint = pte->pointById(tp.id()); @@ -4042,7 +4079,7 @@ QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image, CreateText initialized or OpenGL is not in use. \note This function only has an effect when using the default OpenGL scene graph - adpation. + adaptation. \sa sceneGraphInitialized(), QSGTexture */ @@ -4150,7 +4187,7 @@ void QQuickWindow::setDefaultAlphaBuffer(bool useAlpha) graph renderer. Clear these manually on demand. \note This function only has an effect when using the default OpenGL scene graph - adpation. + adaptation. \sa QQuickWindow::beforeRendering() */ diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h index a40301bcfa..c2d2a7a8a4 100644 --- a/src/quick/items/qquickwindow_p.h +++ b/src/quick/items/qquickwindow_p.h @@ -163,6 +163,10 @@ public: void flushFrameSynchronousEvents(); void deliverDelayedTouchEvent(); + // the device-specific event instances which are reused during event delivery + mutable QVector<QQuickPointerEvent *> pointerEventInstances; + QQuickPointerEvent *pointerEventInstance(QQuickPointerDevice *device) const; + // delivery of pointer events: QQuickPointerEvent *pointerEventInstance(QEvent *ev) const; void deliverPointerEvent(QQuickPointerEvent *); diff --git a/src/quick/items/qquickwindowmodule.cpp b/src/quick/items/qquickwindowmodule.cpp index a5234d4f77..a7f45534c4 100644 --- a/src/quick/items/qquickwindowmodule.cpp +++ b/src/quick/items/qquickwindowmodule.cpp @@ -200,6 +200,7 @@ void QQuickWindowModule::defineModule() qmlRegisterUncreatableType<QQuickScreen>(uri, 2, 0, "Screen", QStringLiteral("Screen can only be used via the attached property.")); qmlRegisterUncreatableType<QQuickScreen,1>(uri, 2, 3, "Screen", QStringLiteral("Screen can only be used via the attached property.")); qmlRegisterUncreatableType<QQuickScreenInfo,2>(uri, 2, 3, "ScreenInfo", QStringLiteral("ScreenInfo can only be used via the attached property.")); + qmlRegisterUncreatableType<QQuickScreenInfo,10>(uri, 2, 10, "ScreenInfo", QStringLiteral("ScreenInfo can only be used via the attached property.")); } QT_END_NAMESPACE diff --git a/src/quick/items/shaders/lineargradient.frag b/src/quick/items/shaders/lineargradient.frag new file mode 100644 index 0000000000..7f4a739109 --- /dev/null +++ b/src/quick/items/shaders/lineargradient.frag @@ -0,0 +1,9 @@ +uniform sampler2D gradTabTexture; +uniform highp float opacity; + +varying highp float gradTabIndex; + +void main() +{ + gl_FragColor = texture2D(gradTabTexture, vec2(gradTabIndex, 0.5)) * opacity; +} diff --git a/src/quick/items/shaders/lineargradient.vert b/src/quick/items/shaders/lineargradient.vert new file mode 100644 index 0000000000..eb21b8886b --- /dev/null +++ b/src/quick/items/shaders/lineargradient.vert @@ -0,0 +1,15 @@ +attribute vec4 vertexCoord; +attribute vec4 vertexColor; + +uniform mat4 matrix; +uniform vec2 gradStart; +uniform vec2 gradEnd; + +varying float gradTabIndex; + +void main() +{ + vec2 gradVec = gradEnd - gradStart; + gradTabIndex = dot(gradVec, vertexCoord.xy - gradStart) / (gradVec.x * gradVec.x + gradVec.y * gradVec.y); + gl_Position = matrix * vertexCoord; +} diff --git a/src/quick/items/shaders/lineargradient_core.frag b/src/quick/items/shaders/lineargradient_core.frag new file mode 100644 index 0000000000..5908acfa67 --- /dev/null +++ b/src/quick/items/shaders/lineargradient_core.frag @@ -0,0 +1,12 @@ +#version 150 core + +uniform sampler2D gradTabTexture; +uniform float opacity; + +in float gradTabIndex; +out vec4 fragColor; + +void main() +{ + fragColor = texture(gradTabTexture, vec2(gradTabIndex, 0.5)) * opacity; +} diff --git a/src/quick/items/shaders/lineargradient_core.vert b/src/quick/items/shaders/lineargradient_core.vert new file mode 100644 index 0000000000..60b56f38e3 --- /dev/null +++ b/src/quick/items/shaders/lineargradient_core.vert @@ -0,0 +1,17 @@ +#version 150 core + +in vec4 vertexCoord; +in vec4 vertexColor; + +uniform mat4 matrix; +uniform vec2 gradStart; +uniform vec2 gradEnd; + +out float gradTabIndex; + +void main() +{ + vec2 gradVec = gradEnd - gradStart; + gradTabIndex = dot(gradVec, vertexCoord.xy - gradStart) / (gradVec.x * gradVec.x + gradVec.y * gradVec.y); + gl_Position = matrix * vertexCoord; +} |