diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-10-15 13:51:20 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-10-15 13:55:22 +0200 |
commit | 6f617349cf865ca3a7befc0dd472b7c2510fc431 (patch) | |
tree | 37e70da54a7f3101b82551ccd98508f8d9d64330 /src/quicktemplates2 | |
parent | 718e08392f34dc478ea010c08a4b9c77bb665dfc (diff) | |
parent | 8e2d1b1efe736760d27af17160f662454546b054 (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Removed dependencies.yaml.
Change-Id: I1e2b3f486e9ace4bc8dc0419a64848990b3a6b39
Diffstat (limited to 'src/quicktemplates2')
31 files changed, 270 insertions, 98 deletions
diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp index 0aa8ec28..2099f2db 100644 --- a/src/quicktemplates2/qquickabstractbutton.cpp +++ b/src/quicktemplates2/qquickabstractbutton.cpp @@ -105,6 +105,7 @@ QT_BEGIN_NAMESPACE \qmlsignal QtQuick.Controls::AbstractButton::pressAndHold() This signal is emitted when the button is interactively pressed and held down by the user via touch or mouse. + It is not emitted when \l autoRepeat is enabled. */ /*! @@ -658,6 +659,9 @@ void QQuickAbstractButton::setAutoExclusive(bool exclusive) This property holds whether the button repeats \l pressed(), \l released() and \l clicked() signals while the button is pressed and held down. + If this property is set to \c true, the \l pressAndHold() signal will not + be emitted. + The default value is \c false. The initial delay and the repetition interval are defined in milliseconds @@ -736,7 +740,7 @@ void QQuickAbstractButton::setIndicator(QQuickItem *indicator) \include qquickicon.qdocinc grouped-properties - \sa text, display, {Icons in Qt Quick Controls 2} + \sa text, display, {Icons in Qt Quick Controls} */ QQuickIcon QQuickAbstractButton::icon() const diff --git a/src/quicktemplates2/qquickapplicationwindow.cpp b/src/quicktemplates2/qquickapplicationwindow.cpp index acd98470..0d05bee7 100644 --- a/src/quicktemplates2/qquickapplicationwindow.cpp +++ b/src/quicktemplates2/qquickapplicationwindow.cpp @@ -113,7 +113,7 @@ QT_BEGIN_NAMESPACE attached properties works in any window regardless of its \c id. \sa {Customizing ApplicationWindow}, Overlay, Page, {Container Controls}, - {Focus Management in Qt Quick Controls 2} + {Focus Management in Qt Quick Controls} */ static const QQuickItemPrivate::ChangeTypes ItemChanges = QQuickItemPrivate::Visibility diff --git a/src/quicktemplates2/qquickbutton.cpp b/src/quicktemplates2/qquickbutton.cpp index fbce5225..b4188a95 100644 --- a/src/quicktemplates2/qquickbutton.cpp +++ b/src/quicktemplates2/qquickbutton.cpp @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE \e Yes, \e No, and \e Help. Button inherits its API from AbstractButton. For instance, you can set - \l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls 2}{icon}, + \l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls}{icon}, and react to \l {AbstractButton::clicked}{clicks} using the AbstractButton API. A button emits the signal \l {AbstractButton::}{clicked()} when it is activated by the user. diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp index 71b4eaf1..21eecfe1 100644 --- a/src/quicktemplates2/qquickcombobox.cpp +++ b/src/quicktemplates2/qquickcombobox.cpp @@ -43,6 +43,7 @@ #include <QtCore/qregularexpression.h> #include <QtCore/qabstractitemmodel.h> +#include <QtCore/qglobal.h> #include <QtGui/qinputmethod.h> #include <QtGui/qguiapplication.h> #include <QtGui/qpa/qplatformtheme.h> @@ -90,21 +91,7 @@ QT_BEGIN_NAMESPACE The following example demonstrates appending content to an editable combo box by reacting to the \l accepted signal. - \code - ComboBox { - editable: true - model: ListModel { - id: model - ListElement { text: "Banana" } - ListElement { text: "Apple" } - ListElement { text: "Coconut" } - } - onAccepted: { - if (find(editText) === -1) - model.append({text: editText}) - } - } - \endcode + \snippet qtquickcontrols2-combobox-accepted.qml combobox \section1 ComboBox Model Roles @@ -130,7 +117,7 @@ QT_BEGIN_NAMESPACE \l textRole is not defined, ComboBox is unable to visualize it and throws a \c {ReferenceError: modelData is not defined}. - \sa {Customizing ComboBox}, {Input Controls}, {Focus Management in Qt Quick Controls 2} + \sa {Customizing ComboBox}, {Input Controls}, {Focus Management in Qt Quick Controls} */ /*! @@ -163,9 +150,22 @@ QT_BEGIN_NAMESPACE \qmlsignal void QtQuick.Controls::ComboBox::accepted() This signal is emitted when the \uicontrol Return or \uicontrol Enter key is pressed - on an \l editable combo box. If the confirmed string is not currently in the model, - the \l currentIndex will be set to \c -1 and the \l currentText will be updated - accordingly. + on an \l editable combo box. + + You can handle this signal in order to add the newly entered + item to the model, for example: + + \snippet qtquickcontrols2-combobox-accepted.qml combobox + + Before the signal is emitted, a check is done to see if the string + exists in the model. If it does, \l currentIndex will be set to its index, + and \l currentText to the string itself. + + After the signal has been emitted, and if the first check failed (that is, + the item did not exist), another check will be done to see if the item was + added by the signal handler. If it was, the \l currentIndex and + \l currentText are updated accordingly. Otherwise, they will be set to + \c -1 and \c "", respectively. \note If there is a \l validator set on the combo box, the signal will only be emitted if the input is in an acceptable state. @@ -232,6 +232,13 @@ public: void updateEditText(); void updateCurrentText(); void updateCurrentValue(); + void updateCurrentText(bool hasDelegateModelObject); + void updateCurrentValue(bool hasDelegateModelObject); + void updateCurrentTextAndValue(); + + bool isValidIndex(int index) const; + QString fastTextAt(int index) const; + QVariant fastValueAt(int index) const; void acceptInput(); QString tryComplete(const QString &inputText); @@ -434,10 +441,34 @@ void QQuickComboBoxPrivate::updateEditText() q->setEditText(text); } +// We have these two rather than just using default arguments +// because QObjectPrivate::connect() doesn't accept lambdas. void QQuickComboBoxPrivate::updateCurrentText() { + updateCurrentText(false); +} + +void QQuickComboBoxPrivate::updateCurrentValue() +{ + updateCurrentValue(false); +} + +void QQuickComboBoxPrivate::updateCurrentText(bool hasDelegateModelObject) +{ Q_Q(QQuickComboBox); - QString text = q->textAt(currentIndex); + QString text; + // If a delegate model object was passed in, it means the calling code + // has decided to reuse it for several function calls to speed things up. + // So, use the faster (private) version in that case. + // For other cases, we use the version that creates the delegate model object + // itself in order to have neater, more convenient calling code. + if (isValidIndex(currentIndex)) { + if (hasDelegateModelObject) + text = fastTextAt(currentIndex); + else + text = q->textAt(currentIndex); + } + if (currentText != text) { currentText = text; if (!hasDisplayText) @@ -452,10 +483,19 @@ void QQuickComboBoxPrivate::updateCurrentText() q->setEditText(currentText); } -void QQuickComboBoxPrivate::updateCurrentValue() +void QQuickComboBoxPrivate::updateCurrentValue(bool hasDelegateModelObject) { Q_Q(QQuickComboBox); - const QVariant value = q->valueAt(currentIndex); + QVariant value; + // If a delegate model object was passed in, it means the calling code + // has decided to reuse it for several function calls to speed things up. + // So, use the faster (private) version in that case. + if (isValidIndex(currentIndex)) { + if (hasDelegateModelObject) + value = fastValueAt(currentIndex); + else + value = q->valueAt(currentIndex); + } if (currentValue == value) return; @@ -463,6 +503,38 @@ void QQuickComboBoxPrivate::updateCurrentValue() emit q->currentValueChanged(); } +void QQuickComboBoxPrivate::updateCurrentTextAndValue() +{ + QObject *object = nullptr; + // For performance reasons, we reuse the same delegate model object: QTBUG-76029. + if (isValidIndex(currentIndex)) + object = delegateModel->object(currentIndex); + const bool hasDelegateModelObject = object != nullptr; + updateCurrentText(hasDelegateModelObject); + updateCurrentValue(hasDelegateModelObject); + if (object) + delegateModel->release(object); +} + +bool QQuickComboBoxPrivate::isValidIndex(int index) const +{ + return delegateModel && index >= 0 && index < delegateModel->count(); +} + +// For performance reasons (QTBUG-76029), both this and valueAt assume that +// the index is valid and delegateModel->object(index) has been called. +QString QQuickComboBoxPrivate::fastTextAt(int index) const +{ + const QString effectiveTextRole = textRole.isEmpty() ? QStringLiteral("modelData") : textRole; + return delegateModel->stringValue(index, effectiveTextRole); +} + +QVariant QQuickComboBoxPrivate::fastValueAt(int index) const +{ + const QString effectiveValueRole = valueRole.isEmpty() ? QStringLiteral("modelData") : valueRole; + return delegateModel->variantValue(index, effectiveValueRole); +} + void QQuickComboBoxPrivate::acceptInput() { Q_Q(QQuickComboBox); @@ -509,10 +581,8 @@ void QQuickComboBoxPrivate::setCurrentIndex(int index, Activation activate) currentIndex = index; emit q->currentIndexChanged(); - if (componentComplete) { - updateCurrentText(); - updateCurrentValue(); - } + if (componentComplete) + updateCurrentTextAndValue(); if (activate) emit q->activated(index); @@ -833,10 +903,14 @@ void QQuickComboBox::setModel(const QVariant& m) if (d->model == model) return; - if (QAbstractItemModel* aim = qvariant_cast<QAbstractItemModel *>(d->model)) - QObjectPrivate::disconnect(aim, &QAbstractItemModel::dataChanged, d, &QQuickComboBoxPrivate::updateCurrentText); - if (QAbstractItemModel* aim = qvariant_cast<QAbstractItemModel *>(model)) - QObjectPrivate::connect(aim, &QAbstractItemModel::dataChanged, d, &QQuickComboBoxPrivate::updateCurrentText); + if (QAbstractItemModel* aim = qvariant_cast<QAbstractItemModel *>(d->model)) { + QObjectPrivate::disconnect(aim, &QAbstractItemModel::dataChanged, + d, QOverload<>::of(&QQuickComboBoxPrivate::updateCurrentText)); + } + if (QAbstractItemModel* aim = qvariant_cast<QAbstractItemModel *>(model)) { + QObjectPrivate::connect(aim, &QAbstractItemModel::dataChanged, + d, QOverload<>::of(&QQuickComboBoxPrivate::updateCurrentText)); + } d->model = model; d->createDelegateModel(); @@ -1506,15 +1580,13 @@ QVariant QQuickComboBox::currentValue() const QVariant QQuickComboBox::valueAt(int index) const { Q_D(const QQuickComboBox); - if (!d->delegateModel || index < 0 || index >= d->delegateModel->count()) + if (!d->isValidIndex(index)) return QVariant(); - // We use QVariant because the model API uses QVariant. - QVariant value; QObject *object = d->delegateModel->object(index); + QVariant value; if (object) { - const QString role = d->valueRole.isEmpty() ? QStringLiteral("modelData") : d->valueRole; - value = d->delegateModel->variantValue(index, role); + value = d->fastValueAt(index); d->delegateModel->release(object); } return value; @@ -1551,13 +1623,13 @@ int QQuickComboBox::indexOfValue(const QVariant &value) const QString QQuickComboBox::textAt(int index) const { Q_D(const QQuickComboBox); - if (!d->delegateModel || index < 0 || index >= d->delegateModel->count()) + if (!d->isValidIndex(index)) return QString(); - QString text; QObject *object = d->delegateModel->object(index); + QString text; if (object) { - text = d->delegateModel->stringValue(index, d->textRole.isEmpty() ? QStringLiteral("modelData") : d->textRole); + text = d->fastTextAt(index); d->delegateModel->release(object); } return text; @@ -1824,12 +1896,10 @@ void QQuickComboBox::componentComplete() static_cast<QQmlDelegateModel *>(d->delegateModel)->componentComplete(); if (count() > 0) { - if (!d->hasCurrentIndex && d->currentIndex == -1) { + if (!d->hasCurrentIndex && d->currentIndex == -1) setCurrentIndex(0); - } else { - d->updateCurrentText(); - d->updateCurrentValue(); - } + else + d->updateCurrentTextAndValue(); } } diff --git a/src/quicktemplates2/qquickcombobox_p.h b/src/quicktemplates2/qquickcombobox_p.h index a55541d4..c9063d6a 100644 --- a/src/quicktemplates2/qquickcombobox_p.h +++ b/src/quicktemplates2/qquickcombobox_p.h @@ -163,8 +163,8 @@ public: // 2.14 (Qt 5.14) QVariant currentValue() const; - Q_INVOKABLE QVariant valueAt(int index) const; - Q_INVOKABLE int indexOfValue(const QVariant &value) const; + Q_REVISION(14) Q_INVOKABLE QVariant valueAt(int index) const; + Q_REVISION(14) Q_INVOKABLE int indexOfValue(const QVariant &value) const; public Q_SLOTS: void incrementCurrentIndex(); diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index dd954b2b..e156fb57 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -1470,9 +1470,9 @@ void QQuickControl::setHovered(bool hovered) Setting this property propagates the value to all child controls that do not have \c hoverEnabled explicitly set. - You can also enable or disable hover effects for all Qt Quick Controls 2 applications + You can also enable or disable hover effects for all Qt Quick Controls applications by setting the \c QT_QUICK_CONTROLS_HOVER_ENABLED \l {Supported Environment Variables - in Qt Quick Controls 2}{environment variable}. + in Qt Quick Controls}{environment variable}. \sa hovered */ diff --git a/src/quicktemplates2/qquickdialogbuttonbox.cpp b/src/quicktemplates2/qquickdialogbuttonbox.cpp index 91fb41f2..10d80778 100644 --- a/src/quicktemplates2/qquickdialogbuttonbox.cpp +++ b/src/quicktemplates2/qquickdialogbuttonbox.cpp @@ -430,7 +430,8 @@ void QQuickDialogButtonBoxPrivate::removeStandardButtons() while (i >= 0) { QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(q->itemAt(i)); if (button) { - QQuickDialogButtonBoxAttached *attached = qobject_cast<QQuickDialogButtonBoxAttached *>(qmlAttachedPropertiesObject<QQuickDialogButtonBox>(button, false)); + QQuickDialogButtonBoxAttached *attached = qobject_cast<QQuickDialogButtonBoxAttached *>( + qmlAttachedPropertiesObject<QQuickDialogButtonBox>(button, false)); if (attached) { QQuickDialogButtonBoxAttachedPrivate *p = QQuickDialogButtonBoxAttachedPrivate::get(attached); if (p->standardButton != QPlatformDialogHelper::NoButton) { @@ -443,6 +444,24 @@ void QQuickDialogButtonBoxPrivate::removeStandardButtons() } } +void QQuickDialogButtonBoxPrivate::updateLanguage() +{ + Q_Q(QQuickDialogButtonBox); + int i = q->count() - 1; + while (i >= 0) { + QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(itemAt(i)); + if (button) { + QQuickDialogButtonBoxAttached *attached = qobject_cast<QQuickDialogButtonBoxAttached *>( + qmlAttachedPropertiesObject<QQuickDialogButtonBox>(button, true)); + const auto boxAttachedPrivate = QQuickDialogButtonBoxAttachedPrivate::get(attached); + const QPlatformDialogHelper::StandardButton standardButton = boxAttachedPrivate->standardButton; + const QString buttonText = QGuiApplicationPrivate::platformTheme()->standardButtonText(standardButton); + button->setText(QPlatformTheme::removeMnemonics(buttonText)); + } + --i; + } +} + QQuickDialogButtonBox::QQuickDialogButtonBox(QQuickItem *parent) : QQuickContainer(*(new QQuickDialogButtonBoxPrivate), parent) { @@ -684,11 +703,34 @@ void QQuickDialogButtonBox::updatePolish() d->updateLayout(); } +class LanguageEventFilter : public QObject +{ +public: + LanguageEventFilter(QQuickDialogButtonBoxPrivate *box) + : QObject(box->q_ptr) + , boxPrivate(box) + { + } + +protected: + bool eventFilter(QObject *, QEvent *event) + { + if (event->type() == QEvent::LanguageChange) + boxPrivate->updateLanguage(); + return false; + } + +private: + QQuickDialogButtonBoxPrivate *boxPrivate; +}; + void QQuickDialogButtonBox::componentComplete() { Q_D(QQuickDialogButtonBox); QQuickContainer::componentComplete(); d->updateLayout(); + // TODO: use the solution in QTBUG-78141 instead, when it's implemented. + qApp->installEventFilter(new LanguageEventFilter(d)); } void QQuickDialogButtonBox::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) diff --git a/src/quicktemplates2/qquickdialogbuttonbox_p_p.h b/src/quicktemplates2/qquickdialogbuttonbox_p_p.h index 66386911..6f9c9033 100644 --- a/src/quicktemplates2/qquickdialogbuttonbox_p_p.h +++ b/src/quicktemplates2/qquickdialogbuttonbox_p_p.h @@ -78,6 +78,8 @@ public: QQuickAbstractButton *createStandardButton(QPlatformDialogHelper::StandardButton button); void removeStandardButtons(); + void updateLanguage(); + Qt::Alignment alignment = 0; QQuickDialogButtonBox::Position position = QQuickDialogButtonBox::Footer; QPlatformDialogHelper::StandardButtons standardButtons = QPlatformDialogHelper::NoButton; diff --git a/src/quicktemplates2/qquickicon.cpp b/src/quicktemplates2/qquickicon.cpp index 5a689108..bf0a4658 100644 --- a/src/quicktemplates2/qquickicon.cpp +++ b/src/quicktemplates2/qquickicon.cpp @@ -112,12 +112,14 @@ void QQuickIcon::setName(const QString &name) if ((d->resolveMask & QQuickIconPrivate::NameResolved) && d->name == name) return; + d.detach(); d->name = name; d->resolveMask |= QQuickIconPrivate::NameResolved; } void QQuickIcon::resetName() { + d.detach(); d->name = QString(); d->resolveMask &= ~QQuickIconPrivate::NameResolved; } @@ -132,12 +134,14 @@ void QQuickIcon::setSource(const QUrl &source) if ((d->resolveMask & QQuickIconPrivate::SourceResolved) && d->source == source) return; + d.detach(); d->source = source; d->resolveMask |= QQuickIconPrivate::SourceResolved; } void QQuickIcon::resetSource() { + d.detach(); d->source = QString(); d->resolveMask &= ~QQuickIconPrivate::SourceResolved; } @@ -152,12 +156,14 @@ void QQuickIcon::setWidth(int width) if ((d->resolveMask & QQuickIconPrivate::WidthResolved) && d->width == width) return; + d.detach(); d->width = width; d->resolveMask |= QQuickIconPrivate::WidthResolved; } void QQuickIcon::resetWidth() { + d.detach(); d->width = 0; d->resolveMask &= ~QQuickIconPrivate::WidthResolved; } @@ -172,12 +178,14 @@ void QQuickIcon::setHeight(int height) if ((d->resolveMask & QQuickIconPrivate::HeightResolved) && d->height == height) return; + d.detach(); d->height = height; d->resolveMask |= QQuickIconPrivate::HeightResolved; } void QQuickIcon::resetHeight() { + d.detach(); d->height = 0; d->resolveMask &= ~QQuickIconPrivate::HeightResolved; } @@ -192,12 +200,14 @@ void QQuickIcon::setColor(const QColor &color) if ((d->resolveMask & QQuickIconPrivate::ColorResolved) && d->color == color) return; + d.detach(); d->color = color; d->resolveMask |= QQuickIconPrivate::ColorResolved; } void QQuickIcon::resetColor() { + d.detach(); d->color = Qt::transparent; d->resolveMask &= ~QQuickIconPrivate::ColorResolved; } @@ -212,12 +222,14 @@ void QQuickIcon::setCache(bool cache) if ((d->resolveMask & QQuickIconPrivate::CacheResolved) && d->cache == cache) return; + d.detach(); d->cache = cache; d->resolveMask |= QQuickIconPrivate::CacheResolved; } void QQuickIcon::resetCache() { + d.detach(); d->cache = true; d->resolveMask &= ~QQuickIconPrivate::CacheResolved; } @@ -225,24 +237,25 @@ void QQuickIcon::resetCache() QQuickIcon QQuickIcon::resolve(const QQuickIcon &other) const { QQuickIcon resolved = *this; + resolved.d.detach(); if (!(d->resolveMask & QQuickIconPrivate::NameResolved)) - resolved.setName(other.name()); + resolved.d->name = other.d->name; if (!(d->resolveMask & QQuickIconPrivate::SourceResolved)) - resolved.setSource(other.source()); + resolved.d->source = other.d->source; if (!(d->resolveMask & QQuickIconPrivate::WidthResolved)) - resolved.setWidth(other.width()); + resolved.d->width = other.d->width; if (!(d->resolveMask & QQuickIconPrivate::HeightResolved)) - resolved.setHeight(other.height()); + resolved.d->height = other.d->height; if (!(d->resolveMask & QQuickIconPrivate::ColorResolved)) - resolved.setColor(other.color()); + resolved.d->color = other.d->color; if (!(d->resolveMask & QQuickIconPrivate::CacheResolved)) - resolved.setCache(other.cache()); + resolved.d->cache = other.d->cache; return resolved; } diff --git a/src/quicktemplates2/qquickicon_p.h b/src/quicktemplates2/qquickicon_p.h index 57cab720..1835585d 100644 --- a/src/quicktemplates2/qquickicon_p.h +++ b/src/quicktemplates2/qquickicon_p.h @@ -107,7 +107,7 @@ public: QQuickIcon resolve(const QQuickIcon &other) const; private: - QSharedDataPointer<QQuickIconPrivate> d; + QExplicitlySharedDataPointer<QQuickIconPrivate> d; }; QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickitemdelegate.cpp b/src/quicktemplates2/qquickitemdelegate.cpp index ac409118..8156ab65 100644 --- a/src/quicktemplates2/qquickitemdelegate.cpp +++ b/src/quicktemplates2/qquickitemdelegate.cpp @@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE in various views and controls, such as \l ListView and \l ComboBox. ItemDelegate inherits its API from AbstractButton. For instance, you can set - \l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls 2}{icon}, + \l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls}{icon}, and react to \l {AbstractButton::clicked}{clicks} using the AbstractButton API. \snippet qtquickcontrols2-itemdelegate.qml 1 diff --git a/src/quicktemplates2/qquickmenu.cpp b/src/quicktemplates2/qquickmenu.cpp index 498c6d00..91372777 100644 --- a/src/quicktemplates2/qquickmenu.cpp +++ b/src/quicktemplates2/qquickmenu.cpp @@ -1487,7 +1487,9 @@ void QQuickMenu::timerEvent(QTimerEvent *event) if (QQuickMenu *subMenu = d->currentSubMenu()) subMenu->open(); d->stopHoverTimer(); + return; } + QQuickPopup::timerEvent(event); } QFont QQuickMenu::defaultFont() const diff --git a/src/quicktemplates2/qquickmenubar.cpp b/src/quicktemplates2/qquickmenubar.cpp index 6016e70d..1761d999 100644 --- a/src/quicktemplates2/qquickmenubar.cpp +++ b/src/quicktemplates2/qquickmenubar.cpp @@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE menus in a menu bar can be accessed using \l menuAt(). \sa {Customizing MenuBar}, Menu, MenuBarItem, {Menu Controls}, - {Focus Management in Qt Quick Controls 2} + {Focus Management in Qt Quick Controls} */ QQuickItem *QQuickMenuBarPrivate::beginCreateItem() diff --git a/src/quicktemplates2/qquickmenuitem.cpp b/src/quicktemplates2/qquickmenuitem.cpp index 22fe664a..a7fc63e8 100644 --- a/src/quicktemplates2/qquickmenuitem.cpp +++ b/src/quicktemplates2/qquickmenuitem.cpp @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE example. MenuItem inherits its API from AbstractButton. For instance, you can set - \l {AbstractButton::text}{text} and \l {Icons in Qt Quick Controls 2}{icon} + \l {AbstractButton::text}{text} and \l {Icons in Qt Quick Controls}{icon} using the AbstractButton API. \code diff --git a/src/quicktemplates2/qquickoverlay.cpp b/src/quicktemplates2/qquickoverlay.cpp index cf72c8a6..3f358706 100644 --- a/src/quicktemplates2/qquickoverlay.cpp +++ b/src/quicktemplates2/qquickoverlay.cpp @@ -126,11 +126,6 @@ bool QQuickOverlayPrivate::startDrag(QEvent *event, const QPointF &pos) return false; } -static bool isTouchEvent(QEvent *event) -{ - return event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd; -} - bool QQuickOverlayPrivate::handlePress(QQuickItem *source, QEvent *event, QQuickPopup *target) { if (target) { @@ -139,7 +134,18 @@ bool QQuickOverlayPrivate::handlePress(QQuickItem *source, QEvent *event, QQuick return true; } return false; - } else if (!mouseGrabberPopup || isTouchEvent(event)) { + } + + switch (event->type()) { + default: { + if (mouseGrabberPopup) + break; +#if QT_CONFIG(quicktemplates2_multitouch) + Q_FALLTHROUGH(); + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: +#endif // allow non-modal popups to close themselves, // and non-dimming modal popups to block the event const auto popups = stackingOrderPopups(); @@ -149,6 +155,8 @@ bool QQuickOverlayPrivate::handlePress(QQuickItem *source, QEvent *event, QQuick return true; } } + break; + } } event->ignore(); diff --git a/src/quicktemplates2/qquickoverlay_p.h b/src/quicktemplates2/qquickoverlay_p.h index 0d8bccf5..1d238163 100644 --- a/src/quicktemplates2/qquickoverlay_p.h +++ b/src/quicktemplates2/qquickoverlay_p.h @@ -86,7 +86,7 @@ Q_SIGNALS: protected: void itemChange(ItemChange change, const ItemChangeData &data) override; - void geometryChanged(const QRectF &oldGeometry, const QRectF &newGeometry) override; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; diff --git a/src/quicktemplates2/qquickpage.cpp b/src/quicktemplates2/qquickpage.cpp index cb90ac48..78bae921 100644 --- a/src/quicktemplates2/qquickpage.cpp +++ b/src/quicktemplates2/qquickpage.cpp @@ -83,7 +83,7 @@ QT_BEGIN_NAMESPACE \endqml \sa ApplicationWindow, {Container Controls}, - {Focus Management in Qt Quick Controls 2} + {Focus Management in Qt Quick Controls} */ static const QQuickItemPrivate::ChangeTypes LayoutChanges = QQuickItemPrivate::Geometry | QQuickItemPrivate::Visibility | QQuickItemPrivate::Destroyed diff --git a/src/quicktemplates2/qquickpane.cpp b/src/quicktemplates2/qquickpane.cpp index fd9d2cf0..18c8bd51 100644 --- a/src/quicktemplates2/qquickpane.cpp +++ b/src/quicktemplates2/qquickpane.cpp @@ -120,7 +120,7 @@ QT_BEGIN_NAMESPACE \endcode \sa {Customizing Pane}, {Container Controls}, - {Focus Management in Qt Quick Controls 2}, {Event Handling} + {Focus Management in Qt Quick Controls}, {Event Handling} */ void QQuickPanePrivate::init() diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index dd7dede6..f0cf1869 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -2582,6 +2582,7 @@ void QQuickPopup::itemChange(QQuickItem::ItemChange change, const QQuickItem::It else d->popupItem->ungrabShortcut(); } + break; default: break; } diff --git a/src/quicktemplates2/qquickpopup_p_p.h b/src/quicktemplates2/qquickpopup_p_p.h index e32fdb28..8a85f914 100644 --- a/src/quicktemplates2/qquickpopup_p_p.h +++ b/src/quicktemplates2/qquickpopup_p_p.h @@ -187,7 +187,7 @@ public: QQuickPopup::ClosePolicy closePolicy = DefaultClosePolicy; QQuickItem *parentItem = nullptr; QQuickItem *dimmer = nullptr; - QQuickWindow *window = nullptr; + QPointer<QQuickWindow> window; QQuickTransition *enter = nullptr; QQuickTransition *exit = nullptr; QQuickPopupItem *popupItem = nullptr; diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp index acf4dca3..378ece50 100644 --- a/src/quicktemplates2/qquickrangeslider.cpp +++ b/src/quicktemplates2/qquickrangeslider.cpp @@ -89,7 +89,7 @@ QT_BEGIN_NAMESPACE For a slider that allows the user to select a single value, see \l Slider. \sa {Customizing RangeSlider}, {Input Controls}, - {Focus Management in Qt Quick Controls 2} + {Focus Management in Qt Quick Controls} */ class QQuickRangeSliderNodePrivate : public QObjectPrivate diff --git a/src/quicktemplates2/qquickscrollview.cpp b/src/quicktemplates2/qquickscrollview.cpp index 98bd174e..70390351 100644 --- a/src/quicktemplates2/qquickscrollview.cpp +++ b/src/quicktemplates2/qquickscrollview.cpp @@ -113,7 +113,7 @@ QT_BEGIN_NAMESPACE \snippet qtquickcontrols2-scrollview-interactive.qml file \sa ScrollBar, ScrollIndicator, {Customizing ScrollView}, {Container Controls}, - {Focus Management in Qt Quick Controls 2} + {Focus Management in Qt Quick Controls} */ class QQuickScrollViewPrivate : public QQuickPanePrivate diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp index 274929b0..389e5c54 100644 --- a/src/quicktemplates2/qquickspinbox.cpp +++ b/src/quicktemplates2/qquickspinbox.cpp @@ -92,7 +92,7 @@ static const int AUTO_REPEAT_INTERVAL = 100; \snippet qtquickcontrols2-spinbox-double.qml 1 - \sa Tumbler, {Customizing SpinBox}, {Focus Management in Qt Quick Controls 2} + \sa Tumbler, {Customizing SpinBox}, {Focus Management in Qt Quick Controls} */ /*! diff --git a/src/quicktemplates2/qquickstackelement.cpp b/src/quicktemplates2/qquickstackelement.cpp index 7ae5c495..4c14022a 100644 --- a/src/quicktemplates2/qquickstackelement.cpp +++ b/src/quicktemplates2/qquickstackelement.cpp @@ -44,6 +44,7 @@ #include <QtQml/private/qv4qobjectwrapper_p.h> #include <QtQml/private/qqmlcomponent_p.h> #include <QtQml/private/qqmlengine_p.h> +#include <QtQml/private/qqmlapiversion_p.h> QT_BEGIN_NAMESPACE @@ -210,7 +211,12 @@ void QQuickStackElement::initialize() QV4::ScopedValue ipv(scope, properties.value()); QV4::Scoped<QV4::QmlContext> qmlContext(scope, qmlCallingContext.value()); QV4::ScopedValue qmlObject(scope, QV4::QObjectWrapper::wrap(v4, item)); +#if Q_QML_PRIVATE_API_VERSION >= 6 + RequiredProperties requiredPropertiesCurrentlyNotSupported; + QQmlComponentPrivate::setInitialProperties(v4, qmlContext, qmlObject, ipv, requiredPropertiesCurrentlyNotSupported, item); +#else QQmlComponentPrivate::setInitialProperties(v4, qmlContext, qmlObject, ipv); +#endif properties.clear(); } diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp index 18f65127..b2a95731 100644 --- a/src/quicktemplates2/qquickstackview.cpp +++ b/src/quicktemplates2/qquickstackview.cpp @@ -373,7 +373,7 @@ QT_BEGIN_NAMESPACE \endlist \sa {Customizing StackView}, {Navigation Controls}, {Container Controls}, - {Focus Management in Qt Quick Controls 2} + {Focus Management in Qt Quick Controls} */ QQuickStackView::QQuickStackView(QQuickItem *parent) diff --git a/src/quicktemplates2/qquickswipeview.cpp b/src/quicktemplates2/qquickswipeview.cpp index e6a88b47..3ba4f4d3 100644 --- a/src/quicktemplates2/qquickswipeview.cpp +++ b/src/quicktemplates2/qquickswipeview.cpp @@ -100,7 +100,7 @@ QT_BEGIN_NAMESPACE or using anchors for its children works as expected. \sa TabBar, PageIndicator, {Customizing SwipeView}, {Navigation Controls}, {Container Controls}, - {Focus Management in Qt Quick Controls 2} + {Focus Management in Qt Quick Controls} */ class QQuickSwipeViewPrivate : public QQuickContainerPrivate diff --git a/src/quicktemplates2/qquicktabbar.cpp b/src/quicktemplates2/qquicktabbar.cpp index 745023c3..5a439b4b 100644 --- a/src/quicktemplates2/qquicktabbar.cpp +++ b/src/quicktemplates2/qquicktabbar.cpp @@ -92,7 +92,7 @@ QT_BEGIN_NAMESPACE \snippet qtquickcontrols2-tabbar-flickable.qml 1 \sa TabButton, {Customizing TabBar}, {Navigation Controls}, {Container Controls}, - {Focus Management in Qt Quick Controls 2} + {Focus Management in Qt Quick Controls} */ class QQuickTabBarPrivate : public QQuickContainerPrivate diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp index 95bf5bb1..f7b8969c 100644 --- a/src/quicktemplates2/qquicktextarea.cpp +++ b/src/quicktemplates2/qquicktextarea.cpp @@ -369,6 +369,8 @@ void QQuickTextAreaPrivate::detachFlickable() QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentHeightChanged, this, &QQuickTextAreaPrivate::resizeFlickableControl); flickable = nullptr; + + resizeBackground(); } void QQuickTextAreaPrivate::ensureCursorVisible() @@ -433,11 +435,21 @@ void QQuickTextAreaPrivate::resizeFlickableContent() void QQuickTextAreaPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) { - Q_UNUSED(item); - Q_UNUSED(change); Q_UNUSED(diff); + if (!resizingBackground && item == background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(item); + // Only set hasBackgroundWidth/Height if it was a width/height change, + // otherwise we're prevented from setting a width/height in the future. + if (change.widthChange()) + extra.value().hasBackgroundWidth = p->widthValid; + if (change.heightChange()) + extra.value().hasBackgroundHeight = p->heightValid; + } - resizeFlickableControl(); + if (flickable) + resizeFlickableControl(); + else + resizeBackground(); } qreal QQuickTextAreaPrivate::getImplicitWidth() const @@ -512,11 +524,8 @@ void QQuickTextAreaPrivate::executeBackground(bool complete) if (!background || complete) quickBeginDeferred(q, backgroundName(), background); - if (complete) { + if (complete) quickCompleteDeferred(q, backgroundName(), background); - if (background) - QQuickControlPrivate::addImplicitSizeListener(background, this, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry); - } } void QQuickTextAreaPrivate::itemImplicitWidthChanged(QQuickItem *item) @@ -625,21 +634,20 @@ void QQuickTextArea::setBackground(QQuickItem *background) d->background = background; if (background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (p->widthValid || p->heightValid) { + d->extra.value().hasBackgroundWidth = p->widthValid; + d->extra.value().hasBackgroundHeight = p->heightValid; + } if (d->flickable) background->setParentItem(d->flickable); else background->setParentItem(this); if (qFuzzyIsNull(background->z())) background->setZ(-1); - QQuickItemPrivate *p = QQuickItemPrivate::get(background); - if (p->widthValid || p->heightValid) { - d->extra.value().hasBackgroundWidth = p->widthValid; - d->extra.value().hasBackgroundHeight = p->heightValid; - } - if (isComponentComplete()) { + if (isComponentComplete()) d->resizeBackground(); - QQuickControlPrivate::addImplicitSizeListener(background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry); - } + QQuickControlPrivate::addImplicitSizeListener(background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry); } if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth())) diff --git a/src/quicktemplates2/qquicktoolbutton.cpp b/src/quicktemplates2/qquicktoolbutton.cpp index eb70fbc4..b613e69b 100644 --- a/src/quicktemplates2/qquicktoolbutton.cpp +++ b/src/quicktemplates2/qquicktoolbutton.cpp @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE \snippet qtquickcontrols2-toolbar.qml 1 ToolButton inherits its API from AbstractButton. For instance, you can set - \l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls 2}{icon}, + \l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls}{icon}, and react to \l {AbstractButton::clicked}{clicks} using the AbstractButton API. \sa ToolBar, {Customizing ToolButton}, {Button Controls} diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index ddf434a2..0a36e0c7 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -238,12 +238,13 @@ void QQuickToolTip::setTimeout(int timeout) if (d->timeout == timeout) return; + d->timeout = timeout; + if (timeout <= 0) d->stopTimeout(); else if (isVisible()) d->startTimeout(); - d->timeout = timeout; emit timeoutChanged(); } @@ -327,10 +328,14 @@ void QQuickToolTip::timerEvent(QTimerEvent *event) if (event->timerId() == d->timeoutTimer.timerId()) { d->stopTimeout(); QQuickPopup::setVisible(false); - } else if (event->timerId() == d->delayTimer.timerId()) { + return; + } + if (event->timerId() == d->delayTimer.timerId()) { d->stopDelay(); QQuickPopup::setVisible(true); + return; } + QQuickPopup::timerEvent(event); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquicktumbler.cpp b/src/quicktemplates2/qquicktumbler.cpp index 8b702c60..85c70b1b 100644 --- a/src/quicktemplates2/qquicktumbler.cpp +++ b/src/quicktemplates2/qquicktumbler.cpp @@ -949,9 +949,20 @@ void QQuickTumblerAttachedPrivate::calculateDisplacement() const qreal contentY = tumblerPrivate->viewContentY; const qreal delegateH = delegateHeight(tumbler); const qreal preferredHighlightBegin = tumblerPrivate->view->property("preferredHighlightBegin").toReal(); - // Tumbler's displacement goes from negative at the top to positive towards the bottom, so we must switch this around. - const qreal reverseDisplacement = (contentY + preferredHighlightBegin) / delegateH; - displacement = reverseDisplacement - index; + const qreal itemY = qobject_cast<QQuickItem*>(parent)->y(); + qreal currentItemY = 0; + auto currentItem = tumblerPrivate->view->property("currentItem").value<QQuickItem*>(); + if (currentItem) + currentItemY = currentItem->y(); + // Start from the y position of the current item. + const qreal topOfCurrentItemInViewport = currentItemY - contentY; + // Then, calculate the distance between it and the preferredHighlightBegin. + const qreal relativePositionToPreferredHighlightBegin = topOfCurrentItemInViewport - preferredHighlightBegin; + // Next, calculate the distance between us and the current item. + const qreal distanceFromCurrentItem = currentItemY - itemY; + const qreal displacementInPixels = distanceFromCurrentItem - relativePositionToPreferredHighlightBegin; + // Convert it from pixels to a floating point index. + displacement = displacementInPixels / delegateH; } emitIfDisplacementChanged(previousDisplacement, displacement); |