From d12cc4f6b58ecb5f44458002fe9b74d0c84f10ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Tue, 7 May 2019 14:58:29 +0200 Subject: Don't overwrite states if role is assigned after a state We therefore need to keep track of which states have been explicitly set or not in order to know which ones should get initialized with their defaults. Change-Id: I49fdae82288f04ea4f50d45735a93434ac02abec Reviewed-by: Frederik Gladhorn --- src/quick/items/qquickaccessibleattached.cpp | 43 ++++++++++++++++++++++++++++ src/quick/items/qquickaccessibleattached_p.h | 38 ++---------------------- 2 files changed, 46 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/quick/items/qquickaccessibleattached.cpp b/src/quick/items/qquickaccessibleattached.cpp index 0168c3160c..c150e4efa2 100644 --- a/src/quick/items/qquickaccessibleattached.cpp +++ b/src/quick/items/qquickaccessibleattached.cpp @@ -390,6 +390,49 @@ QQuickAccessibleAttached::~QQuickAccessibleAttached() { } +void QQuickAccessibleAttached::setRole(QAccessible::Role role) +{ + if (role != m_role) { + m_role = role; + Q_EMIT roleChanged(); + // There is no way to signify role changes at the moment. + // QAccessible::updateAccessibility(parent(), 0, QAccessible::); + + switch (role) { + case QAccessible::CheckBox: + case QAccessible::RadioButton: + if (!m_stateExplicitlySet.focusable) + m_state.focusable = true; + if (!m_stateExplicitlySet.checkable) + m_state.checkable = true; + break; + case QAccessible::Button: + case QAccessible::MenuItem: + case QAccessible::PageTab: + case QAccessible::SpinBox: + case QAccessible::ComboBox: + case QAccessible::Terminal: + case QAccessible::ScrollBar: + if (!m_stateExplicitlySet.focusable) + m_state.focusable = true; + break; + case QAccessible::EditableText: + if (!m_stateExplicitlySet.editable) + m_state.editable = true; + if (!m_stateExplicitlySet.focusable) + m_state.focusable = true; + break; + case QAccessible::StaticText: + if (!m_stateExplicitlySet.readOnly) { + m_state.readOnly = true; + } + break; + default: + break; + } + } +} + QQuickAccessibleAttached *QQuickAccessibleAttached::qmlAttachedProperties(QObject *obj) { return new QQuickAccessibleAttached(obj); diff --git a/src/quick/items/qquickaccessibleattached_p.h b/src/quick/items/qquickaccessibleattached_p.h index e292c280df..f4194ef13d 100644 --- a/src/quick/items/qquickaccessibleattached_p.h +++ b/src/quick/items/qquickaccessibleattached_p.h @@ -69,6 +69,7 @@ QT_BEGIN_NAMESPACE bool P() const { return m_state.P ; } \ void set_ ## P(bool arg) \ { \ + m_stateExplicitlySet.P = true; \ if (m_state.P == arg) \ return; \ m_state.P = arg; \ @@ -111,41 +112,7 @@ public: ~QQuickAccessibleAttached(); QAccessible::Role role() const { return m_role; } - void setRole(QAccessible::Role role) - { - if (role != m_role) { - m_role = role; - Q_EMIT roleChanged(); - // There is no way to signify role changes at the moment. - // QAccessible::updateAccessibility(parent(), 0, QAccessible::); - - switch (role) { - case QAccessible::CheckBox: - case QAccessible::RadioButton: - m_state.focusable = true; - m_state.checkable = true; - break; - case QAccessible::Button: - case QAccessible::MenuItem: - case QAccessible::PageTab: - case QAccessible::SpinBox: - case QAccessible::ComboBox: - case QAccessible::Terminal: - case QAccessible::ScrollBar: - m_state.focusable = true; - break; - case QAccessible::EditableText: - m_state.editable = true; - m_state.focusable = true; - break; - case QAccessible::StaticText: - m_state.readOnly = true; - break; - default: - break; - } - } - } + void setRole(QAccessible::Role role); QString name() const { if (m_state.passwordEdit) return QString(); @@ -247,6 +214,7 @@ private: QAccessible::Role m_role; QAccessible::State m_state; + QAccessible::State m_stateExplicitlySet; QString m_name; QString m_description; -- cgit v1.2.3 From 17237efaefabe924599abe00e92d8b54032d7915 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 8 May 2019 14:56:24 +0200 Subject: Document TapHandler.tapped and [single|double]Tapped eventPoint argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Amends b8fd580cb3453b3850c36765c4b2537538d2f4f8 to add documentation. The eventPoint is important to get ephemeral state from the pointing device: which button was released (thus triggering the tap), which device it was, and where the release occurred. Users may expect to use the point property, but QQuickHandlerPoint::reset(QQuickEventPoint *) resets every property of the point at the same time, so the architecture currently does not allow for mixed state, i.e. having correct button state but still holding leftover position information. It may be surprising for users, but the changes to the point property are an atomic transaction that occurs before the signal. Task-number: QTBUG-61749 Task-number: QTBUG-64847 Change-Id: I33e0e232084beba8e10d8b02fa3bf85f36293358 Reviewed-by: Jan Arve Sæther --- .../pointerHandlers/tapHandlerOnTapped.qml | 64 ++++++++++++++++++++++ src/quick/handlers/qquicktaphandler.cpp | 27 +++++++-- 2 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 src/quick/doc/snippets/pointerHandlers/tapHandlerOnTapped.qml (limited to 'src') diff --git a/src/quick/doc/snippets/pointerHandlers/tapHandlerOnTapped.qml b/src/quick/doc/snippets/pointerHandlers/tapHandlerOnTapped.qml new file mode 100644 index 0000000000..f556c238da --- /dev/null +++ b/src/quick/doc/snippets/pointerHandlers/tapHandlerOnTapped.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![0] +import QtQuick 2.12 + +Rectangle { + width: 100 + height: 100 + + TapHandler { + acceptedButtons: Qt.LeftButton | Qt.RightButton + onTapped: console.log("tapped", eventPoint.event.device.name, + "button", eventPoint.event.button, + "@", eventPoint.scenePosition) + } +} +//![0] diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp index 41ac294df3..73c559c998 100644 --- a/src/quick/handlers/qquicktaphandler.cpp +++ b/src/quick/handlers/qquicktaphandler.cpp @@ -380,35 +380,50 @@ void QQuickTapHandler::updateTimeHeld() */ /*! - \qmlsignal QtQuick::TapHandler::tapped + \qmlsignal QtQuick::TapHandler::tapped(EventPoint eventPoint) This signal is emitted each time the \c parent Item is tapped. That is, if you press and release a touchpoint or button within a time period less than \l longPressThreshold, while any movement does not exceed the drag threshold, then the \c tapped signal will be emitted at the time - of release. + of release. The \c eventPoint signal parameter contains information + from the release event about the point that was tapped: + + \snippet pointerHandlers/tapHandlerOnTapped.qml 0 + + \note At the time this signal is emitted, \l point has been reset + (all coordinates are \c 0). */ /*! - \qmlsignal QtQuick::TapHandler::singleTapped + \qmlsignal QtQuick::TapHandler::singleTapped(EventPoint eventPoint) \since 5.11 This signal is emitted when the \c parent Item is tapped once. After an amount of time greater than QStyleHints::mouseDoubleClickInterval, it can be tapped again; but if the time until the next tap is less, - \l tapCount will increase. + \l tapCount will increase. The \c eventPoint signal parameter contains + information from the release event about the point that was tapped. + + \note At the time this signal is emitted, \l point has been reset + (all coordinates are \c 0). */ /*! - \qmlsignal QtQuick::TapHandler::doubleTapped + \qmlsignal QtQuick::TapHandler::doubleTapped(EventPoint eventPoint) \since 5.11 This signal is emitted when the \c parent Item is tapped twice within a short span of time (QStyleHints::mouseDoubleClickInterval) and distance (QPlatformTheme::MouseDoubleClickDistance or QPlatformTheme::TouchDoubleTapDistance). This signal always occurs after - \l singleTapped, \l tapped, and \l tapCountChanged. + \l singleTapped, \l tapped, and \l tapCountChanged. The \c eventPoint + signal parameter contains information from the release event about the + point that was tapped. + + \note At the time this signal is emitted, \l point has been reset + (all coordinates are \c 0). */ /*! -- cgit v1.2.3 From 24b286773ae5d47ad43f5e1810ebe6c5093a49da Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 13 May 2019 12:41:50 +0200 Subject: Elaborate on the meaning of values held by basic types Explicitly mention the copying semantics as well as how they are called in the JavaScript language. Task-number: QTBUG-75308 Change-Id: I82b8c6324133d3265b66325c6f67b19b344e0470 Reviewed-by: Kavindra Palaraja Reviewed-by: Paul Wicking --- src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc b/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc index c4c1b61693..5144fe219e 100644 --- a/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc +++ b/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc @@ -44,6 +44,10 @@ Basic types can be used to refer to: \li A value that contains a simple set of property-value pairs (e.g. \l size refers to a value with \c width and \c height attributes) \endlist +When a variable or property holds a basic type and it is assigned to another +variable or property, then a copy of the value is made. In JavaScript, this +value is called a primitive value. + \sa {qtqml-typesystem-topic.html}{The QML Type System} -- cgit v1.2.3 From 026edef351a73f75c0a0ce12c8afb9ef1aa19139 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 13 May 2019 15:52:05 +0200 Subject: Fix illegal downcast in QQuickStateGroup destruction One state hadn't the group unset and ended up with a non-null group pointer that was no longer a group. Change-Id: I916fdab577c90e859a49b97426396c78e7ff426f Reviewed-by: Simon Hausmann --- src/quick/util/qquickstategroup.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp index d8daec2f07..b53949d21c 100644 --- a/src/quick/util/qquickstategroup.cpp +++ b/src/quick/util/qquickstategroup.cpp @@ -130,6 +130,8 @@ QQuickStateGroup::~QQuickStateGroup() Q_D(const QQuickStateGroup); for (int i = 0; i < d->states.count(); ++i) d->states.at(i)->setStateGroup(nullptr); + if (d->nullState) + d->nullState->setStateGroup(nullptr); } QList QQuickStateGroup::states() const -- cgit v1.2.3 From c1829ea50bf5c99428f0a19887c503b4c7bd4b9a Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 13 May 2019 15:49:42 +0200 Subject: Fix illegal downcast on QQmlEngine destruction Make QQmlEnginePrivate::isEngineThread() legal to call during QQmlEngine destruction. Change-Id: I2bae9d70883cf8013f39f2046ebe83bb8dbcd46b Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlengine_p.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h index d05c945ae4..92e56cd957 100644 --- a/src/qml/qml/qqmlengine_p.h +++ b/src/qml/qml/qqmlengine_p.h @@ -309,8 +309,8 @@ Returns true if the calling thread is the QQmlEngine thread. */ bool QQmlEnginePrivate::isEngineThread() const { - Q_Q(const QQmlEngine); - return QThread::currentThread() == q->thread(); + + return QThread::currentThread() == q_ptr->thread(); } /*! @@ -335,8 +335,6 @@ the instance directly if not. template void QQmlEnginePrivate::deleteInEngineThread(T *value) { - Q_Q(QQmlEngine); - Q_ASSERT(value); if (isEngineThread()) { delete value; @@ -352,7 +350,7 @@ void QQmlEnginePrivate::deleteInEngineThread(T *value) toDeleteInEngineThread.append(i); mutex.unlock(); if (wasEmpty) - QCoreApplication::postEvent(q, new QEvent(QEvent::User)); + QCoreApplication::postEvent(q_ptr, new QEvent(QEvent::User)); } } -- cgit v1.2.3 From 078eb28e0c657b8107c5e8be873b3503fdea7ed2 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 13 May 2019 17:53:06 +0200 Subject: Do not take a reference of nullptr References are not allowed to be null, but we pass a nullptr as receiver in QQmlContextWrapper::resolveQmlContextPropertyLookupGetter. Detected with UBSAN. Change-Id: Iaa7945fb17e4b0e549e541e47589b2f47d32ea4e Reviewed-by: Simon Hausmann Reviewed-by: Ulf Hermann --- src/qml/jsruntime/qv4object.cpp | 9 +++++---- src/qml/jsruntime/qv4object_p.h | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 7dd0a247d6..02524b7da6 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -93,7 +93,7 @@ void Heap::Object::setUsedAsProto() internalClass.set(internalClass->engine, internalClass->asProtoClass()); } -ReturnedValue Object::getValueAccessor(const Value &thisObject, const Value &v, PropertyAttributes attrs) +ReturnedValue Object::getValueAccessor(const Value *thisObject, const Value &v, PropertyAttributes attrs) { if (!attrs.isAccessor()) return v.asReturnedValue(); @@ -103,7 +103,8 @@ ReturnedValue Object::getValueAccessor(const Value &thisObject, const Value &v, Scope scope(f->engine()); JSCallData jsCallData(scope); - *jsCallData->thisObject = thisObject; + if (thisObject) + *jsCallData->thisObject = *thisObject; return f->call(jsCallData); } @@ -415,7 +416,7 @@ ReturnedValue Object::internalGet(PropertyKey id, const Value *receiver, bool *h if (o->arrayData && o->arrayData->getProperty(index, pd, &attrs)) { if (hasProperty) *hasProperty = true; - return Object::getValue(*receiver, pd->value, attrs); + return Object::getValue(receiver, pd->value, attrs); } if (o->internalClass->vtable->type == Type_StringObject) { ScopedString str(scope, static_cast(o)->getIndex(index)); @@ -438,7 +439,7 @@ ReturnedValue Object::internalGet(PropertyKey id, const Value *receiver, bool *h if (idx.isValid()) { if (hasProperty) *hasProperty = true; - return Object::getValue(*receiver, *o->propertyData(idx.index), idx.attrs); + return Object::getValue(receiver, *o->propertyData(idx.index), idx.attrs); } o = o->prototype(); if (!o || o->internalClass->vtable->get != Object::virtualGet) diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index c3f1cb2c35..bee4aadafe 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -185,22 +185,22 @@ struct Q_QML_EXPORT Object: Managed { // // helpers // - static ReturnedValue getValue(const Value &thisObject, const Value &v, PropertyAttributes attrs) { + static ReturnedValue getValue(const Value *thisObject, const Value &v, PropertyAttributes attrs) { if (attrs.isData()) return v.asReturnedValue(); return getValueAccessor(thisObject, v, attrs); } ReturnedValue getValue(const Value &v, PropertyAttributes attrs) const { - return getValue(*this, v, attrs); + return getValue(this, v, attrs); } ReturnedValue getValueByIndex(uint propertyIndex) const { PropertyAttributes attrs = internalClass()->propertyData.at(propertyIndex); const Value *v = propertyData(propertyIndex); if (!attrs.isAccessor()) return v->asReturnedValue(); - return getValueAccessor(*this, *v, attrs); + return getValueAccessor(this, *v, attrs); } - static ReturnedValue getValueAccessor(const Value &thisObject, const Value &v, PropertyAttributes attrs); + static ReturnedValue getValueAccessor(const Value *thisObject, const Value &v, PropertyAttributes attrs); bool putValue(uint memberIndex, PropertyAttributes attrs, const Value &value); -- cgit v1.2.3 From 733adcf32c1cce288435940c66846a51ad29a464 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 13 May 2019 11:18:28 +0200 Subject: Compile fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It fixes the following issue: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare] Change-Id: I4b896f49ff753a5cf79cd1e40e76815f712eec89 Reviewed-by: Ulf Hermann --- src/imports/sharedimage/qsharedimageloader.cpp | 2 +- src/qml/jsruntime/qv4memberdata.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/imports/sharedimage/qsharedimageloader.cpp b/src/imports/sharedimage/qsharedimageloader.cpp index 4672ded376..c9e3ef3eb3 100644 --- a/src/imports/sharedimage/qsharedimageloader.cpp +++ b/src/imports/sharedimage/qsharedimageloader.cpp @@ -173,7 +173,7 @@ QImage QSharedImageLoaderPrivate::load(const QString &path, QSharedImageLoader:: if (img.isNull()) return nil; size_t size = sizeof(SharedImageHeader) + img.sizeInBytes(); - if (size > std::numeric_limits::max()) { + if (size > size_t(std::numeric_limits::max())) { qCDebug(lcSharedImage) << "Image" << path << "to large to load"; return nil; } else if (shm->create(int(size))) { diff --git a/src/qml/jsruntime/qv4memberdata.cpp b/src/qml/jsruntime/qv4memberdata.cpp index f327c85001..ffebe1b5da 100644 --- a/src/qml/jsruntime/qv4memberdata.cpp +++ b/src/qml/jsruntime/qv4memberdata.cpp @@ -72,8 +72,8 @@ Heap::MemberData *MemberData::allocate(ExecutionEngine *e, uint n, Heap::MemberD // The above code can overflow in a number of interesting ways. All of those are unsigned, // and therefore defined behavior. Still, apply some sane bounds. - if (alloc > std::numeric_limits::max()) - alloc = std::numeric_limits::max(); + if (alloc > size_t(std::numeric_limits::max())) + alloc = size_t(std::numeric_limits::max()); Heap::MemberData *m; if (old) { -- cgit v1.2.3 From 23f78b6b76fb9350a472485e34857e1a4842e5d3 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 1 Mar 2019 22:40:54 +0100 Subject: TextEdit: use I-beam cursor by default, pointing cursor for links But do not interfere with any custom cursor that user code sets: remember and restore it when the mouse is no longer hovering a link. Task-number: QTBUG-14769 Fixes: QTBUG-50482 Change-Id: Ia4633c22d0ad42d07203d4dc3e330b90a5f94a7c Reviewed-by: Mitch Curtis --- src/quick/items/qquicktextedit.cpp | 19 ++++++++++++++++++- src/quick/items/qquicktextedit_p.h | 1 + src/quick/items/qquicktextedit_p_p.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index 06a0fc396b..8551c008cb 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -2297,7 +2297,6 @@ void QQuickTextEditPrivate::init() qmlobject_connect(control, QQuickTextControl, SIGNAL(cursorPositionChanged()), q, QQuickTextEdit, SIGNAL(cursorPositionChanged())); qmlobject_connect(control, QQuickTextControl, SIGNAL(cursorRectangleChanged()), q, QQuickTextEdit, SLOT(moveCursorDelegate())); qmlobject_connect(control, QQuickTextControl, SIGNAL(linkActivated(QString)), q, QQuickTextEdit, SIGNAL(linkActivated(QString))); - qmlobject_connect(control, QQuickTextControl, SIGNAL(linkHovered(QString)), q, QQuickTextEdit, SIGNAL(linkHovered(QString))); qmlobject_connect(control, QQuickTextControl, SIGNAL(overwriteModeChanged(bool)), q, QQuickTextEdit, SIGNAL(overwriteModeChanged(bool))); qmlobject_connect(control, QQuickTextControl, SIGNAL(textChanged()), q, QQuickTextEdit, SLOT(q_textChanged())); qmlobject_connect(control, QQuickTextControl, SIGNAL(preeditTextChanged()), q, QQuickTextEdit, SIGNAL(preeditTextChanged())); @@ -2309,6 +2308,7 @@ void QQuickTextEditPrivate::init() qmlobject_connect(document, QQuickTextDocumentWithImageResources, SIGNAL(imagesLoaded()), q, QQuickTextEdit, SLOT(updateSize())); QObject::connect(document, &QQuickTextDocumentWithImageResources::contentsChange, q, &QQuickTextEdit::q_contentsChange); QObject::connect(document->documentLayout(), &QAbstractTextDocumentLayout::updateBlock, q, &QQuickTextEdit::invalidateBlock); + QObject::connect(control, &QQuickTextControl::linkHovered, q, &QQuickTextEdit::q_linkHovered); document->setDefaultFont(font); document->setDocumentMargin(textMargin); @@ -2316,6 +2316,9 @@ void QQuickTextEditPrivate::init() document->setUndoRedoEnabled(true); updateDefaultTextOption(); q->updateSize(); +#if QT_CONFIG(cursor) + q->setCursor(Qt::IBeamCursor); +#endif } void QQuickTextEditPrivate::resetInputMethod() @@ -2583,6 +2586,20 @@ void QQuickTextEdit::updateCursor() } } +void QQuickTextEdit::q_linkHovered(const QString &link) +{ + Q_D(QQuickTextEdit); + emit linkHovered(link); +#if QT_CONFIG(cursor) + if (link.isEmpty()) { + setCursor(d->cursorToRestoreAfterHover); + } else if (cursor().shape() != Qt::PointingHandCursor) { + d->cursorToRestoreAfterHover = cursor().shape(); + setCursor(Qt::PointingHandCursor); + } +#endif +} + void QQuickTextEdit::q_updateAlignment() { Q_D(QQuickTextEdit); diff --git a/src/quick/items/qquicktextedit_p.h b/src/quick/items/qquicktextedit_p.h index 7a847ffeae..259a614d6b 100644 --- a/src/quick/items/qquicktextedit_p.h +++ b/src/quick/items/qquicktextedit_p.h @@ -374,6 +374,7 @@ private Q_SLOTS: void updateWholeDocument(); void invalidateBlock(const QTextBlock &block); void updateCursor(); + void q_linkHovered(const QString &link); void q_updateAlignment(); void updateSize(); void triggerPreprocess(); diff --git a/src/quick/items/qquicktextedit_p_p.h b/src/quick/items/qquicktextedit_p_p.h index 46d3d5ff6b..389ce3175c 100644 --- a/src/quick/items/qquicktextedit_p_p.h +++ b/src/quick/items/qquicktextedit_p_p.h @@ -207,6 +207,7 @@ public: Qt::InputMethodHints inputMethodHints; #endif UpdateType updateType; + Qt::CursorShape cursorToRestoreAfterHover = Qt::IBeamCursor; bool dirty : 1; bool richText : 1; -- cgit v1.2.3 From 56fbc277a1acc49d9ead4c89edd250a021ef2a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Tue, 14 May 2019 12:13:01 +0200 Subject: Do not synthesize a double click event if the event point moved too far We need to respect QPlatformTheme::TouchDoubleTapDistance Fixes: QTBUG-75770 Change-Id: I2adc7097bb29cb93beb2609a8a806a666856a0c8 Reviewed-by: Shawn Rutledge --- src/quick/items/qquickwindow.cpp | 42 ++++++++++++++++++++++++++-------------- src/quick/items/qquickwindow_p.h | 3 ++- 2 files changed, 29 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index f705f132fc..c55db04566 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -632,25 +633,28 @@ static QMouseEvent *touchToMouseEvent(QEvent::Type type, const QTouchEvent::Touc return me; } -bool QQuickWindowPrivate::checkIfDoubleClicked(ulong newPressEventTimestamp) +bool QQuickWindowPrivate::checkIfDoubleTapped(ulong newPressEventTimestamp, QPoint newPressPos) { - bool doubleClicked; + bool doubleClicked = false; + + if (touchMousePressTimestamp > 0) { + QPoint distanceBetweenPresses = newPressPos - touchMousePressPos; + const int doubleTapDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt(); + doubleClicked = (qAbs(distanceBetweenPresses.x()) <= doubleTapDistance) && (qAbs(distanceBetweenPresses.y()) <= doubleTapDistance); - if (touchMousePressTimestamp == 0) { - // just initialize the variable - touchMousePressTimestamp = newPressEventTimestamp; - doubleClicked = false; - } else { - ulong timeBetweenPresses = newPressEventTimestamp - touchMousePressTimestamp; - ulong doubleClickInterval = static_cast(QGuiApplication::styleHints()-> - mouseDoubleClickInterval()); - doubleClicked = timeBetweenPresses < doubleClickInterval; if (doubleClicked) { - touchMousePressTimestamp = 0; - } else { - touchMousePressTimestamp = newPressEventTimestamp; + ulong timeBetweenPresses = newPressEventTimestamp - touchMousePressTimestamp; + ulong doubleClickInterval = static_cast(QGuiApplication::styleHints()-> + mouseDoubleClickInterval()); + doubleClicked = timeBetweenPresses < doubleClickInterval; } } + if (doubleClicked) { + touchMousePressTimestamp = 0; + } else { + touchMousePressTimestamp = newPressEventTimestamp; + touchMousePressPos = newPressPos; + } return doubleClicked; } @@ -707,7 +711,9 @@ bool QQuickWindowPrivate::deliverTouchAsMouse(QQuickItem *item, QQuickPointerEve if (auto pointerEventPoint = pointerEvent->pointById(p.id())) pointerEventPoint->setGrabberItem(item); - if (checkIfDoubleClicked(event->timestamp())) { + if (checkIfDoubleTapped(event->timestamp(), p.screenPos().toPoint())) { + // since we synth the mouse event from from touch, we respect the + // QPlatformTheme::TouchDoubleTapDistance instead of QPlatformTheme::MouseDoubleClickDistance QScopedPointer mouseDoubleClick(touchToMouseEvent(QEvent::MouseButtonDblClick, p, event.data(), item, false)); QCoreApplication::sendEvent(item, mouseDoubleClick.data()); event->setAccepted(mouseDoubleClick->isAccepted()); @@ -722,6 +728,12 @@ bool QQuickWindowPrivate::deliverTouchAsMouse(QQuickItem *item, QQuickPointerEve // Touch point was there before and moved } else if (touchMouseDevice == device && p.id() == touchMouseId) { if (p.state() & Qt::TouchPointMoved) { + if (touchMousePressTimestamp != 0) { + const int doubleTapDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt(); + const QPoint moveDelta = p.screenPos().toPoint() - touchMousePressPos; + if (moveDelta.x() >= doubleTapDistance || moveDelta.y() >= doubleTapDistance) + touchMousePressTimestamp = 0; // Got dragged too far, dismiss the double tap + } if (QQuickItem *mouseGrabberItem = q->mouseGrabberItem()) { QScopedPointer me(touchToMouseEvent(QEvent::MouseMove, p, event.data(), mouseGrabberItem, false)); QCoreApplication::sendEvent(item, me.data()); diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h index 5a3807b24f..63760a3b68 100644 --- a/src/quick/items/qquickwindow_p.h +++ b/src/quick/items/qquickwindow_p.h @@ -135,8 +135,9 @@ public: #endif int touchMouseId; QQuickPointerDevice *touchMouseDevice; - bool checkIfDoubleClicked(ulong newPressEventTimestamp); + bool checkIfDoubleTapped(ulong newPressEventTimestamp, QPoint newPressPos); ulong touchMousePressTimestamp; + QPoint touchMousePressPos; // in screen coordiantes void cancelTouchMouseSynthesis(); // Mouse positions are saved in widget coordinates -- cgit v1.2.3 From 9b36512b9453f429644b0c388d381f7a2fc0f825 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 13 May 2019 17:48:42 +0200 Subject: Avoid illegal downcasts in texture and shader handling Fixes bad type-cast during destruction when objects no longer has the full type they used to. Detected by UBSAN. Change-Id: I4867091901d70d5a882656834eb97a704def1751 Reviewed-by: Simon Hausmann --- src/quick/items/qquickopenglshadereffect.cpp | 7 +++---- src/quick/items/qquickopenglshadereffect_p.h | 2 +- src/quick/items/qquickopenglshadereffectnode.cpp | 8 ++++---- src/quick/items/qquickopenglshadereffectnode_p.h | 4 ++-- src/quick/items/qquickshadereffect.cpp | 3 ++- src/quick/scenegraph/qsgcontext.cpp | 2 +- src/quick/scenegraph/qsgcontext_p.h | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/quick/items/qquickopenglshadereffect.cpp b/src/quick/items/qquickopenglshadereffect.cpp index 3aa00340b2..76cb3ace5c 100644 --- a/src/quick/items/qquickopenglshadereffect.cpp +++ b/src/quick/items/qquickopenglshadereffect.cpp @@ -221,7 +221,7 @@ QQuickOpenGLShaderEffectCommon::~QQuickOpenGLShaderEffectCommon() clearSignalMappers(shaderType); } -void QQuickOpenGLShaderEffectCommon::disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType) +void QQuickOpenGLShaderEffectCommon::disconnectPropertySignals(QObject *obj, Key::ShaderType shaderType) { for (int i = 0; i < uniformData[shaderType].size(); ++i) { if (signalMappers[shaderType].at(i) == 0) @@ -229,12 +229,11 @@ void QQuickOpenGLShaderEffectCommon::disconnectPropertySignals(QQuickItem *item, const UniformData &d = uniformData[shaderType].at(i); auto mapper = signalMappers[shaderType].at(i); void *a = mapper; - QObjectPrivate::disconnect(item, mapper->signalIndex(), &a); + QObjectPrivate::disconnect(obj, mapper->signalIndex(), &a); if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) { QQuickItem *source = qobject_cast(qvariant_cast(d.value)); if (source) { - if (item->window()) - QQuickItemPrivate::get(source)->derefWindow(); + QQuickItemPrivate::get(source)->derefWindow(); QObject::disconnect(source, SIGNAL(destroyed(QObject*)), host, SLOT(sourceDestroyed(QObject*))); } } diff --git a/src/quick/items/qquickopenglshadereffect_p.h b/src/quick/items/qquickopenglshadereffect_p.h index 0c2adadc62..3087c1eb0b 100644 --- a/src/quick/items/qquickopenglshadereffect_p.h +++ b/src/quick/items/qquickopenglshadereffect_p.h @@ -89,7 +89,7 @@ struct Q_QUICK_PRIVATE_EXPORT QQuickOpenGLShaderEffectCommon ~QQuickOpenGLShaderEffectCommon(); - void disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType); + void disconnectPropertySignals(QObject *item, Key::ShaderType shaderType); void connectPropertySignals(QQuickItem *item, const QMetaObject *itemMetaObject, Key::ShaderType shaderType); void updateParseLog(bool ignoreAttributes); void lookThroughShaderCode(QQuickItem *item, const QMetaObject *itemMetaObject, Key::ShaderType shaderType, const QByteArray &code); diff --git a/src/quick/items/qquickopenglshadereffectnode.cpp b/src/quick/items/qquickopenglshadereffectnode.cpp index f32b32491b..f96ebebcd6 100644 --- a/src/quick/items/qquickopenglshadereffectnode.cpp +++ b/src/quick/items/qquickopenglshadereffectnode.cpp @@ -477,11 +477,11 @@ void QQuickOpenGLShaderEffectMaterial::updateTextures() const } } -void QQuickOpenGLShaderEffectMaterial::invalidateTextureProvider(QSGTextureProvider *provider) +void QQuickOpenGLShaderEffectMaterial::invalidateTextureProvider(const QObject *provider) { for (int i = 0; i < textureProviders.size(); ++i) { if (provider == textureProviders.at(i)) - textureProviders[i] = 0; + textureProviders[i] = nullptr; } } @@ -505,10 +505,10 @@ void QQuickOpenGLShaderEffectNode::markDirtyTexture() Q_EMIT dirtyTexture(); } -void QQuickOpenGLShaderEffectNode::textureProviderDestroyed(QObject *object) +void QQuickOpenGLShaderEffectNode::textureProviderDestroyed(const QObject *object) { Q_ASSERT(material()); - static_cast(material())->invalidateTextureProvider(static_cast(object)); + static_cast(material())->invalidateTextureProvider(object); } void QQuickOpenGLShaderEffectNode::preprocess() diff --git a/src/quick/items/qquickopenglshadereffectnode_p.h b/src/quick/items/qquickopenglshadereffectnode_p.h index 7c75bb3126..6d68ba87b9 100644 --- a/src/quick/items/qquickopenglshadereffectnode_p.h +++ b/src/quick/items/qquickopenglshadereffectnode_p.h @@ -122,7 +122,7 @@ public: void setProgramSource(const QQuickOpenGLShaderEffectMaterialKey &source); void updateTextures() const; - void invalidateTextureProvider(QSGTextureProvider *provider); + void invalidateTextureProvider(const QObject *provider); static void cleanupMaterialCache(); @@ -159,7 +159,7 @@ Q_SIGNALS: private Q_SLOTS: void markDirtyTexture(); - void textureProviderDestroyed(QObject *object); + void textureProviderDestroyed(const QObject *object); }; QT_END_NAMESPACE diff --git a/src/quick/items/qquickshadereffect.cpp b/src/quick/items/qquickshadereffect.cpp index ab79b69c8c..05d9e5e36d 100644 --- a/src/quick/items/qquickshadereffect.cpp +++ b/src/quick/items/qquickshadereffect.cpp @@ -795,7 +795,8 @@ bool QQuickShaderEffect::event(QEvent *e) return QQuickItem::event(e); } #endif - m_impl->handleEvent(e); + if (m_impl) + m_impl->handleEvent(e); return QQuickItem::event(e); } diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp index d9ed25c099..53648e352a 100644 --- a/src/quick/scenegraph/qsgcontext.cpp +++ b/src/quick/scenegraph/qsgcontext.cpp @@ -393,7 +393,7 @@ QSGTexture *QSGRenderContext::textureForFactory(QQuickTextureFactory *factory, Q void QSGRenderContext::textureFactoryDestroyed(QObject *o) { m_mutex.lock(); - m_texturesToDelete << m_textures.take(static_cast(o)); + m_texturesToDelete << m_textures.take(o); m_mutex.unlock(); } diff --git a/src/quick/scenegraph/qsgcontext_p.h b/src/quick/scenegraph/qsgcontext_p.h index 6d70d7ef6b..282ce828af 100644 --- a/src/quick/scenegraph/qsgcontext_p.h +++ b/src/quick/scenegraph/qsgcontext_p.h @@ -194,7 +194,7 @@ protected: QPointer m_sg; QMutex m_mutex; - QHash m_textures; + QHash m_textures; QSet m_texturesToDelete; QHash m_glyphCaches; -- cgit v1.2.3