From ef771a0fd70f05d7204fb8cbd8789aa1ed6eff4b Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 2 Apr 2020 11:51:21 +0200 Subject: Stop using resolvedUrl() to resolve QML files This is necessary to move away from imperative type registration of QML files (i.e. qmlRegisterType()). A later patch will use qmlRegisterModuleImport() to register the QtQuick.Controls import with the style set by the user, which will require each style to have a qmldir listing the files that it provides. Note that some plugins still register QML files, but these registrations will have to stay for now until we can split out "impl" plugins in later patches where those files can be registered. tst_qquickstyleselector will be added back in some other form in a follow-up patch. Task-number: QTBUG-82922 Change-Id: I8182533d9912ed493efda6eb91c69fc064af07ee Reviewed-by: Ulf Hermann --- src/quickcontrols2/qquickstyleplugin.cpp | 42 +------ src/quickcontrols2/qquickstyleplugin_p.h | 6 +- src/quickcontrols2/qquickstyleselector.cpp | 163 --------------------------- src/quickcontrols2/qquickstyleselector_p.h | 86 -------------- src/quickcontrols2/qquickstyleselector_p_p.h | 70 ------------ src/quickcontrols2/quickcontrols2.pri | 7 +- 6 files changed, 9 insertions(+), 365 deletions(-) delete mode 100644 src/quickcontrols2/qquickstyleselector.cpp delete mode 100644 src/quickcontrols2/qquickstyleselector_p.h delete mode 100644 src/quickcontrols2/qquickstyleselector_p_p.h (limited to 'src/quickcontrols2') diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp index 9bbaad11..067d8dff 100644 --- a/src/quickcontrols2/qquickstyleplugin.cpp +++ b/src/quickcontrols2/qquickstyleplugin.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. @@ -37,18 +37,14 @@ #include "qquickstyleplugin_p.h" #include "qquickstyle.h" #include "qquickstyle_p.h" -#include "qquickstyleselector_p.h" -QT_BEGIN_NAMESPACE +#include +#include -class QQuickStylePluginPrivate -{ -public: - mutable QScopedPointer selector; -}; +QT_BEGIN_NAMESPACE QQuickStylePlugin::QQuickStylePlugin(QObject *parent) - : QQmlExtensionPlugin(parent), d_ptr(new QQuickStylePluginPrivate) + : QQmlExtensionPlugin(parent) { } @@ -66,34 +62,8 @@ void QQuickStylePlugin::initializeTheme(QQuickTheme *theme) Q_UNUSED(theme); } -void QQuickStylePlugin::unregisterTypes() +void QQuickStylePlugin::registerTypes(const char */*uri*/) { - Q_D(QQuickStylePlugin); - // Destroy the selector so that it is recreated in resolvedUrl() and - // any new style that has been set at runtime will be accounted for when selecting QML files. - d->selector.reset(); -} - -QUrl QQuickStylePlugin::resolvedUrl(const QString &fileName) const -{ - Q_D(const QQuickStylePlugin); - if (!d->selector) { - d->selector.reset(new QQuickStyleSelector); - const QString style = QQuickStyle::name(); - if (!style.isEmpty()) - d->selector->addSelector(style); - - const QString fallback = QQuickStylePrivate::fallbackStyle(); - if (!fallback.isEmpty() && fallback != style) - d->selector->addSelector(fallback); - - const QString theme = name(); - if (!theme.isEmpty() && theme != style) - d->selector->addSelector(theme); - - d->selector->setPaths(QQuickStylePrivate::stylePaths(true)); - } - return d->selector->select(fileName); } QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleplugin_p.h b/src/quickcontrols2/qquickstyleplugin_p.h index 67103e12..a9700c15 100644 --- a/src/quickcontrols2/qquickstyleplugin_p.h +++ b/src/quickcontrols2/qquickstyleplugin_p.h @@ -54,7 +54,6 @@ QT_BEGIN_NAMESPACE class QQuickTheme; -class QQuickStylePluginPrivate; class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePlugin : public QQmlExtensionPlugin { @@ -66,14 +65,11 @@ public: virtual QString name() const; virtual void initializeTheme(QQuickTheme *theme); - virtual void unregisterTypes() override; - QUrl resolvedUrl(const QString &fileName) const; + void registerTypes(const char *uri) override; private: Q_DISABLE_COPY(QQuickStylePlugin) - Q_DECLARE_PRIVATE(QQuickStylePlugin) - QScopedPointer d_ptr; }; QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleselector.cpp b/src/quickcontrols2/qquickstyleselector.cpp deleted file mode 100644 index 72e7af66..00000000 --- a/src/quickcontrols2/qquickstyleselector.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/*************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Copyright (C) 2013 BlackBerry Limited. All rights reserved. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickstyleselector_p.h" -#include "qquickstyleselector_p_p.h" - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcStyleSelectorSelect, "qt.quick.controls.styleSelector.select") -Q_LOGGING_CATEGORY(lcStyleSelectorSetPaths, "qt.quick.controls.styleSelector.setPaths") -Q_LOGGING_CATEGORY(lcStyleSelectorAddSelector, "qt.quick.controls.styleSelector.addSelector") - -static QString ensureSlash(const QString &path) -{ - if (path.isEmpty() || path.endsWith(QLatin1Char('/'))) - return path; - return path + QLatin1Char('/'); -} - -static QStringList prefixedPlatformSelectors(const QChar &prefix) -{ - QStringList selectors = QFileSelectorPrivate::platformSelectors(); - for (int i = 0; i < selectors.count(); ++i) - selectors[i].prepend(prefix); - return selectors; -} - -static QStringList allSelectors() -{ - static const QStringList platformSelectors = prefixedPlatformSelectors(QLatin1Char('+')); - QStringList selectors = platformSelectors; - const QString locale = QLocale().name(); - if (!locale.isEmpty()) - selectors += QLatin1Char('+') + locale; - return selectors; -} - -QUrl QQuickStyleSelectorPrivate::select(const QString &filePath) const -{ - QFileInfo fi(filePath); - // If file doesn't exist, don't select - if (!fi.exists()) - return QUrl(); - - const QString selected = QFileSelectorPrivate::selectionHelper(ensureSlash(fi.canonicalPath()), - fi.fileName(), allSelectors(), QChar()); - - if (selected.startsWith(QLatin1Char(':'))) - return QUrl(QLatin1String("qrc") + selected); - - return QUrl::fromLocalFile(selected.isEmpty() ? filePath : selected); -} - -QQuickStyleSelector::QQuickStyleSelector() : d_ptr(new QQuickStyleSelectorPrivate) -{ -} - -QQuickStyleSelector::~QQuickStyleSelector() -{ -} - -QStringList QQuickStyleSelector::selectors() const -{ - Q_D(const QQuickStyleSelector); - return d->selectors; -} - -void QQuickStyleSelector::addSelector(const QString &selector) -{ - Q_D(QQuickStyleSelector); - if (d->selectors.contains(selector)) - return; - - d->selectors += selector; - - qCDebug(lcStyleSelectorSetPaths).nospace() << "added selector " << selector - << "; full list is now: " << d->selectors; -} - -QStringList QQuickStyleSelector::paths() const -{ - Q_D(const QQuickStyleSelector); - return d->paths; -} - -void QQuickStyleSelector::setPaths(const QStringList &paths) -{ - Q_D(QQuickStyleSelector); - qCDebug(lcStyleSelectorSetPaths) << "setting paths to" << paths; - d->paths = paths; -} - -QUrl QQuickStyleSelector::select(const QString &fileName) const -{ - Q_D(const QQuickStyleSelector); - // The lookup order is - // 1) requested style (e.g. "MyStyle", included in d->selectors) - // 2) fallback style (e.g. "Material", included in d->selectors) - // 3) default style (empty selector, not in d->selectors) - qCDebug(lcStyleSelectorSelect) << "selecting" << fileName << "from" << d->paths << "with selectors" << d->selectors; - - int to = d->selectors.count() - 1; - if (d->selectors.isEmpty() || !d->selectors.first().isEmpty()) - ++to; // lookup #3 unless #1 is also empty (redundant) - - // NOTE: last iteration intentionally out of bounds => empty selector - for (int i = 0; i <= to; ++i) { - const QString selector = d->selectors.value(i); - for (const QString &path : d->paths) { - const QUrl selectedUrl = d->select(ensureSlash(path) + selector + QLatin1Char('/') + fileName); - if (selectedUrl.isValid()) { - qCDebug(lcStyleSelectorSelect) << "==>" << selectedUrl << "from" << path << "with selector" << selector; - return selectedUrl; - } - } - } - - return fileName; -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleselector_p.h b/src/quickcontrols2/qquickstyleselector_p.h deleted file mode 100644 index c4c0f540..00000000 --- a/src/quickcontrols2/qquickstyleselector_p.h +++ /dev/null @@ -1,86 +0,0 @@ -/*************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Copyright (C) 2013 BlackBerry Limited. All rights reserved. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKSTYLESELECTOR_P_H -#define QQUICKSTYLESELECTOR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickStyleSelectorPrivate; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStyleSelector -{ -public: - QQuickStyleSelector(); - ~QQuickStyleSelector(); - - QStringList selectors() const; - void addSelector(const QString &selector); - - QStringList paths() const; - void setPaths(const QStringList &paths); - - QUrl select(const QString &fileName) const; - -private: - Q_DISABLE_COPY(QQuickStyleSelector) - Q_DECLARE_PRIVATE(QQuickStyleSelector) - QScopedPointer d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QQUICKSTYLESELECTOR_P_H diff --git a/src/quickcontrols2/qquickstyleselector_p_p.h b/src/quickcontrols2/qquickstyleselector_p_p.h deleted file mode 100644 index e69e7db2..00000000 --- a/src/quickcontrols2/qquickstyleselector_p_p.h +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Copyright (C) 2013 BlackBerry Limited. All rights reserved. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKSTYLESELECTOR_P_P_H -#define QQUICKSTYLESELECTOR_P_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -QT_BEGIN_NAMESPACE - -class QQuickStyleSelectorPrivate -{ -public: - QUrl select(const QString &filePath) const; - - QStringList paths; - QStringList selectors; -}; - -QT_END_NAMESPACE - -#endif // QQUICKSTYLESELECTOR_P_P_H diff --git a/src/quickcontrols2/quickcontrols2.pri b/src/quickcontrols2/quickcontrols2.pri index 781658ef..2c28038f 100644 --- a/src/quickcontrols2/quickcontrols2.pri +++ b/src/quickcontrols2/quickcontrols2.pri @@ -15,9 +15,7 @@ HEADERS += \ $$PWD/qquickplaceholdertext_p.h \ $$PWD/qquickstyle.h \ $$PWD/qquickstyle_p.h \ - $$PWD/qquickstyleplugin_p.h \ - $$PWD/qquickstyleselector_p.h \ - $$PWD/qquickstyleselector_p_p.h + $$PWD/qquickstyleplugin_p.h SOURCES += \ $$PWD/qquickanimatednode.cpp \ @@ -33,8 +31,7 @@ SOURCES += \ $$PWD/qquickpaddedrectangle.cpp \ $$PWD/qquickplaceholdertext.cpp \ $$PWD/qquickstyle.cpp \ - $$PWD/qquickstyleplugin.cpp \ - $$PWD/qquickstyleselector.cpp + $$PWD/qquickstyleplugin.cpp qtConfig(quick-listview):qtConfig(quick-pathview) { HEADERS += \ -- cgit v1.2.3 From 9aafea810b8867fb31f9ec27a238628467e7ab56 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 1 Apr 2020 15:37:07 +0200 Subject: Move Default style out into its own plugin In upcoming patches, we start registering C++ types declaratively. A condition of doing so requires that each .pro corresponds to one QML module. This conflicts with the QtQuick.Controls import, which currently does quite a lot: - Registers (and selects) QML files for the style that was set - Registers private C++ utility types (such as IconLabel) that are useful for all styles under the QtQuick.Controls.impl import - Registers private C++ types that are only useful for the Default style (such as BusyIndicatorImpl). The reason it does so much can probably be explained by the intended usage of Qt Quick Controls 2; when you do import QtQuick.Controls 2.0 you get access to the QML types (e.g. Button) that the style you're using provides. So if you're using the Material style, you'll get a Material style button. API-wise, the button is identical to any other button, because the types in QtQuick.Templates are what we advertise as the public API. If we didn't have this functionality, users would need to import specific style imports to use controls, and the convenience of being able to simply start the application with a different style by e.g. passing an application argument would be lost. To support declarative registration of types while also supporting the existing use cases, we split out the Default-style-specific stuff into a QtQuick.Controls.Default import. Task-number: QTBUG-82922 Change-Id: Ib4f1620cae78d7acdc13d9ac0752a020bc22f3ea Reviewed-by: Ulf Hermann --- src/quickcontrols2/qquickstyleplugin.cpp | 9 --------- src/quickcontrols2/qquickstyleplugin_p.h | 2 +- src/quickcontrols2/quickcontrols2.pro | 7 +++++++ 3 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src/quickcontrols2') diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp index 067d8dff..b387b378 100644 --- a/src/quickcontrols2/qquickstyleplugin.cpp +++ b/src/quickcontrols2/qquickstyleplugin.cpp @@ -57,13 +57,4 @@ QString QQuickStylePlugin::name() const return QString(); } -void QQuickStylePlugin::initializeTheme(QQuickTheme *theme) -{ - Q_UNUSED(theme); -} - -void QQuickStylePlugin::registerTypes(const char */*uri*/) -{ -} - QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleplugin_p.h b/src/quickcontrols2/qquickstyleplugin_p.h index a9700c15..f5c5705c 100644 --- a/src/quickcontrols2/qquickstyleplugin_p.h +++ b/src/quickcontrols2/qquickstyleplugin_p.h @@ -64,7 +64,7 @@ public: ~QQuickStylePlugin(); virtual QString name() const; - virtual void initializeTheme(QQuickTheme *theme); + virtual void initializeTheme(QQuickTheme *theme) = 0; void registerTypes(const char *uri) override; diff --git a/src/quickcontrols2/quickcontrols2.pro b/src/quickcontrols2/quickcontrols2.pro index 8aec9953..5a11dcd2 100644 --- a/src/quickcontrols2/quickcontrols2.pro +++ b/src/quickcontrols2/quickcontrols2.pro @@ -11,4 +11,11 @@ HEADERS += \ $$PWD/qtquickcontrols2global_p.h include(quickcontrols2.pri) + +QMLTYPES_FILENAME = plugins.qmltypes +QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick/Controls.2 +QML_IMPORT_NAME = QtQuick.Controls +QML_IMPORT_VERSION = 2.15 +CONFIG += qmltypes install_qmltypes install_metatypes + load(qt_module) -- cgit v1.2.3 From 5246dd2de211ffb81313a5c29ae7894545a28c43 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 27 Mar 2020 11:17:35 +0100 Subject: Register C++ types declaratively Adapt to the new way of registering C++ types. The types need to be seen at compile time so that code can be generated that invokes them. This patch: - Adds QML_* macros where applicable. - Adapts the build system files to the new way of registering modules. - Splits up the QtQuick.Controls[.*].impl files into their own plugins, as we can only register one QML module per .pro file. - Removes C++ type registration calls in every plugin. - Moves private types from src/quickcontrols2/quickcontrols2.pro to src/quickcontrols2/impl/quickcontrols2-impl.pro. Some of these types need to be exposed to QML, but quickcontrols2.pro is already in use to declare the QtQuick.Controls import (and also provides the public C++ QQuickStyle API), and the new QML_IMPORT_NAME/VERSION syntax only allows one module per project. As some of the types that need to be exposed to QML are also referenced by some C++ code (e.g. tests, etc.), we just move all of the private types to the new library. Follow-up patches will register the QML types declaratively. Task-number: QTBUG-82922 Change-Id: Iaf9ee106237d61701d57a8896f3822304c8151a6 Reviewed-by: Ulf Hermann --- src/quickcontrols2/qquickanimatednode.cpp | 167 ------- src/quickcontrols2/qquickanimatednode_p.h | 112 ----- src/quickcontrols2/qquickattachedobject.cpp | 274 ----------- src/quickcontrols2/qquickattachedobject_p.h | 84 ---- src/quickcontrols2/qquickchecklabel.cpp | 49 -- src/quickcontrols2/qquickchecklabel_p.h | 68 --- src/quickcontrols2/qquickclippedtext.cpp | 116 ----- src/quickcontrols2/qquickclippedtext_p.h | 96 ---- src/quickcontrols2/qquickcolor.cpp | 66 --- src/quickcontrols2/qquickcolor_p.h | 70 --- src/quickcontrols2/qquickcolorimage.cpp | 103 ----- src/quickcontrols2/qquickcolorimage_p.h | 88 ---- src/quickcontrols2/qquickiconimage.cpp | 213 --------- src/quickcontrols2/qquickiconimage_p.h | 94 ---- src/quickcontrols2/qquickiconimage_p_p.h | 77 --- src/quickcontrols2/qquickiconlabel.cpp | 642 -------------------------- src/quickcontrols2/qquickiconlabel_p.h | 140 ------ src/quickcontrols2/qquickiconlabel_p_p.h | 111 ----- src/quickcontrols2/qquickitemgroup.cpp | 122 ----- src/quickcontrols2/qquickitemgroup_p.h | 83 ---- src/quickcontrols2/qquickmnemoniclabel.cpp | 132 ------ src/quickcontrols2/qquickmnemoniclabel_p.h | 82 ---- src/quickcontrols2/qquickpaddedrectangle.cpp | 211 --------- src/quickcontrols2/qquickpaddedrectangle_p.h | 119 ----- src/quickcontrols2/qquickplaceholdertext.cpp | 73 --- src/quickcontrols2/qquickplaceholdertext_p.h | 74 --- src/quickcontrols2/qquickstyle.cpp | 4 +- src/quickcontrols2/qquickstyle_p.h | 4 +- src/quickcontrols2/qquickstyleplugin.cpp | 3 +- src/quickcontrols2/qquickstyleplugin_p.h | 4 +- src/quickcontrols2/qquicktumblerview.cpp | 320 ------------- src/quickcontrols2/qquicktumblerview_p.h | 109 ----- src/quickcontrols2/qtquickcontrols2global_p.h | 56 --- src/quickcontrols2/quickcontrols2.pri | 41 -- src/quickcontrols2/quickcontrols2.pro | 10 +- 35 files changed, 14 insertions(+), 4003 deletions(-) delete mode 100644 src/quickcontrols2/qquickanimatednode.cpp delete mode 100644 src/quickcontrols2/qquickanimatednode_p.h delete mode 100644 src/quickcontrols2/qquickattachedobject.cpp delete mode 100644 src/quickcontrols2/qquickattachedobject_p.h delete mode 100644 src/quickcontrols2/qquickchecklabel.cpp delete mode 100644 src/quickcontrols2/qquickchecklabel_p.h delete mode 100644 src/quickcontrols2/qquickclippedtext.cpp delete mode 100644 src/quickcontrols2/qquickclippedtext_p.h delete mode 100644 src/quickcontrols2/qquickcolor.cpp delete mode 100644 src/quickcontrols2/qquickcolor_p.h delete mode 100644 src/quickcontrols2/qquickcolorimage.cpp delete mode 100644 src/quickcontrols2/qquickcolorimage_p.h delete mode 100644 src/quickcontrols2/qquickiconimage.cpp delete mode 100644 src/quickcontrols2/qquickiconimage_p.h delete mode 100644 src/quickcontrols2/qquickiconimage_p_p.h delete mode 100644 src/quickcontrols2/qquickiconlabel.cpp delete mode 100644 src/quickcontrols2/qquickiconlabel_p.h delete mode 100644 src/quickcontrols2/qquickiconlabel_p_p.h delete mode 100644 src/quickcontrols2/qquickitemgroup.cpp delete mode 100644 src/quickcontrols2/qquickitemgroup_p.h delete mode 100644 src/quickcontrols2/qquickmnemoniclabel.cpp delete mode 100644 src/quickcontrols2/qquickmnemoniclabel_p.h delete mode 100644 src/quickcontrols2/qquickpaddedrectangle.cpp delete mode 100644 src/quickcontrols2/qquickpaddedrectangle_p.h delete mode 100644 src/quickcontrols2/qquickplaceholdertext.cpp delete mode 100644 src/quickcontrols2/qquickplaceholdertext_p.h delete mode 100644 src/quickcontrols2/qquicktumblerview.cpp delete mode 100644 src/quickcontrols2/qquicktumblerview_p.h delete mode 100644 src/quickcontrols2/qtquickcontrols2global_p.h delete mode 100644 src/quickcontrols2/quickcontrols2.pri (limited to 'src/quickcontrols2') diff --git a/src/quickcontrols2/qquickanimatednode.cpp b/src/quickcontrols2/qquickanimatednode.cpp deleted file mode 100644 index b4e665de..00000000 --- a/src/quickcontrols2/qquickanimatednode.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickanimatednode_p.h" - -#include -#include - -// based on qtdeclarative/examples/quick/scenegraph/threadedanimation - -QT_BEGIN_NAMESPACE - -QQuickAnimatedNode::QQuickAnimatedNode(QQuickItem *target) - : m_window(target->window()) -{ -} - -bool QQuickAnimatedNode::isRunning() const -{ - return m_running; -} - -int QQuickAnimatedNode::currentTime() const -{ - int time = m_currentTime; - if (m_running) - time += m_timer.elapsed(); - return time; -} - -void QQuickAnimatedNode::setCurrentTime(int time) -{ - m_currentTime = time; - m_timer.restart(); -} - -int QQuickAnimatedNode::duration() const -{ - return m_duration; -} - -void QQuickAnimatedNode::setDuration(int duration) -{ - m_duration = duration; -} - -int QQuickAnimatedNode::loopCount() const -{ - return m_loopCount; -} - -void QQuickAnimatedNode::setLoopCount(int count) -{ - m_loopCount = count; -} - -void QQuickAnimatedNode::sync(QQuickItem *target) -{ - Q_UNUSED(target); -} - -QQuickWindow *QQuickAnimatedNode::window() const -{ - return m_window; -} - -void QQuickAnimatedNode::start(int duration) -{ - if (m_running) - return; - - m_running = true; - m_currentLoop = 0; - m_timer.restart(); - if (duration > 0) - m_duration = duration; - - connect(m_window, &QQuickWindow::beforeRendering, this, &QQuickAnimatedNode::advance, Qt::DirectConnection); - connect(m_window, &QQuickWindow::frameSwapped, this, &QQuickAnimatedNode::update, Qt::DirectConnection); - - // If we're inside a QQuickWidget, this call is necessary to ensure the widget - // gets updated for the first time. - m_window->update(); - - emit started(); -} - -void QQuickAnimatedNode::restart() -{ - stop(); - start(); -} - -void QQuickAnimatedNode::stop() -{ - if (!m_running) - return; - - m_running = false; - disconnect(m_window, &QQuickWindow::beforeRendering, this, &QQuickAnimatedNode::advance); - disconnect(m_window, &QQuickWindow::frameSwapped, this, &QQuickAnimatedNode::update); - emit stopped(); -} - -void QQuickAnimatedNode::updateCurrentTime(int time) -{ - Q_UNUSED(time); -} - -void QQuickAnimatedNode::advance() -{ - int time = currentTime(); - if (time > m_duration) { - time = 0; - setCurrentTime(0); - - if (m_loopCount > 0 && ++m_currentLoop >= m_loopCount) { - time = m_duration; // complete - stop(); - } - } - updateCurrentTime(time); - - // If we're inside a QQuickWidget, this call is necessary to ensure the widget gets updated. - m_window->update(); -} - -void QQuickAnimatedNode::update() -{ - if (m_running) - m_window->update(); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickanimatednode_p.h b/src/quickcontrols2/qquickanimatednode_p.h deleted file mode 100644 index d42d9319..00000000 --- a/src/quickcontrols2/qquickanimatednode_p.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKANIMATEDNODE_P_H -#define QQUICKANIMATEDNODE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickItem; -class QQuickWindow; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickAnimatedNode : public QObject, public QSGTransformNode -{ - Q_OBJECT - -public: - explicit QQuickAnimatedNode(QQuickItem *target); - - bool isRunning() const; - - int currentTime() const; - void setCurrentTime(int time); - - int duration() const; - void setDuration(int duration); - - enum LoopCount { Infinite = -1 }; - - int loopCount() const; - void setLoopCount(int count); - - virtual void sync(QQuickItem *target); - - QQuickWindow *window() const; - - // must be called from sync() or updatePaintNode() - void start(int duration = 0); - void restart(); - void stop(); - -Q_SIGNALS: - void started(); - void stopped(); - -protected: - virtual void updateCurrentTime(int time); - -private Q_SLOTS: - void advance(); - void update(); - -private: - bool m_running = false; - int m_duration = 0; - int m_loopCount = 1; - int m_currentTime = 0; - int m_currentLoop = 0; - QElapsedTimer m_timer; - QQuickWindow *m_window = nullptr; -}; - -QT_END_NAMESPACE - -#endif // QQUICKANIMATEDNODE_P_H diff --git a/src/quickcontrols2/qquickattachedobject.cpp b/src/quickcontrols2/qquickattachedobject.cpp deleted file mode 100644 index 722f22f9..00000000 --- a/src/quickcontrols2/qquickattachedobject.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickattachedobject_p.h" - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static QQuickAttachedObject *attachedObject(const QMetaObject *type, QObject *object, bool create = false) -{ - if (!object) - return nullptr; - auto func = qmlAttachedPropertiesFunction(object, type); - return qobject_cast(qmlAttachedPropertiesObject(object, func, create)); -} - -static QQuickAttachedObject *findAttachedParent(const QMetaObject *type, QObject *object) -{ - QQuickItem *item = qobject_cast(object); - if (item) { - // lookup parent items and popups - QQuickItem *parent = item->parentItem(); - while (parent) { - QQuickAttachedObject *attached = attachedObject(type, parent); - if (attached) - return attached; - - QQuickPopup *popup = qobject_cast(parent->parent()); - if (popup) - return attachedObject(type, popup); - - parent = parent->parentItem(); - } - - // fallback to item's window - QQuickAttachedObject *attached = attachedObject(type, item->window()); - if (attached) - return attached; - } else { - // lookup popup's window - QQuickPopup *popup = qobject_cast(object); - if (popup) - return attachedObject(type, popup->popupItem()->window()); - } - - // lookup parent window - QQuickWindow *window = qobject_cast(object); - if (window) { - QQuickWindow *parentWindow = qobject_cast(window->parent()); - if (parentWindow) { - QQuickAttachedObject *attached = attachedObject(type, window); - if (attached) - return attached; - } - } - - // fallback to engine (global) - if (object) { - QQmlEngine *engine = qmlEngine(object); - if (engine) { - QByteArray name = QByteArray("_q_") + type->className(); - QQuickAttachedObject *attached = engine->property(name).value(); - if (!attached) { - attached = attachedObject(type, engine, true); - engine->setProperty(name, QVariant::fromValue(attached)); - } - return attached; - } - } - - return nullptr; -} - -static QList findAttachedChildren(const QMetaObject *type, QObject *object) -{ - QList children; - - QQuickItem *item = qobject_cast(object); - if (!item) { - QQuickWindow *window = qobject_cast(object); - if (window) { - item = window->contentItem(); - - const auto &windowChildren = window->children(); - for (QObject *child : windowChildren) { - QQuickWindow *childWindow = qobject_cast(child); - if (childWindow) { - QQuickAttachedObject *attached = attachedObject(type, childWindow); - if (attached) - children += attached; - } - } - } - } - - if (item) { - const auto childItems = item->childItems(); - for (QQuickItem *child : childItems) { - QQuickAttachedObject *attached = attachedObject(type, child); - if (attached) - children += attached; - else - children += findAttachedChildren(type, child); - } - } - - return children; -} - -static QQuickItem *findAttachedItem(QObject *parent) -{ - QQuickItem *item = qobject_cast(parent); - if (!item) { - QQuickPopup *popup = qobject_cast(parent); - if (popup) - item = popup->popupItem(); - } - return item; -} - -class QQuickAttachedObjectPrivate : public QObjectPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickAttachedObject) - -public: - static QQuickAttachedObjectPrivate *get(QQuickAttachedObject *attachedObject) - { - return attachedObject->d_func(); - } - - void attachTo(QObject *object); - void detachFrom(QObject *object); - - void itemWindowChanged(QQuickWindow *window); - void itemParentChanged(QQuickItem *item, QQuickItem *parent) override; - - QList attachedChildren; - QPointer attachedParent; -}; - -void QQuickAttachedObjectPrivate::attachTo(QObject *object) -{ - QQuickItem *item = findAttachedItem(object); - if (item) { - connect(item, &QQuickItem::windowChanged, this, &QQuickAttachedObjectPrivate::itemWindowChanged); - QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent); - } -} - -void QQuickAttachedObjectPrivate::detachFrom(QObject *object) -{ - QQuickItem *item = findAttachedItem(object); - if (item) { - disconnect(item, &QQuickItem::windowChanged, this, &QQuickAttachedObjectPrivate::itemWindowChanged); - QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent); - } -} - -void QQuickAttachedObjectPrivate::itemWindowChanged(QQuickWindow *window) -{ - Q_Q(QQuickAttachedObject); - QQuickAttachedObject *attachedParent = nullptr; - QQuickItem *item = qobject_cast(q->sender()); - if (item) - attachedParent = findAttachedParent(q->metaObject(), item); - if (!attachedParent) - attachedParent = attachedObject(q->metaObject(), window); - q->setAttachedParent(attachedParent); -} - -void QQuickAttachedObjectPrivate::itemParentChanged(QQuickItem *item, QQuickItem *parent) -{ - Q_Q(QQuickAttachedObject); - Q_UNUSED(parent); - q->setAttachedParent(findAttachedParent(q->metaObject(), item)); -} - -QQuickAttachedObject::QQuickAttachedObject(QObject *parent) - : QObject(*(new QQuickAttachedObjectPrivate), parent) -{ - Q_D(QQuickAttachedObject); - d->attachTo(parent); -} - -QQuickAttachedObject::~QQuickAttachedObject() -{ - Q_D(QQuickAttachedObject); - d->detachFrom(parent()); - setAttachedParent(nullptr); -} - -QList QQuickAttachedObject::attachedChildren() const -{ - Q_D(const QQuickAttachedObject); - return d->attachedChildren; -} - -QQuickAttachedObject *QQuickAttachedObject::attachedParent() const -{ - Q_D(const QQuickAttachedObject); - return d->attachedParent; -} - -void QQuickAttachedObject::setAttachedParent(QQuickAttachedObject *parent) -{ - Q_D(QQuickAttachedObject); - if (d->attachedParent == parent) - return; - - QQuickAttachedObject *oldParent = d->attachedParent; - if (d->attachedParent) - QQuickAttachedObjectPrivate::get(d->attachedParent)->attachedChildren.removeOne(this); - d->attachedParent = parent; - if (parent) - QQuickAttachedObjectPrivate::get(parent)->attachedChildren.append(this); - attachedParentChange(parent, oldParent); -} - -void QQuickAttachedObject::init() -{ - QQuickAttachedObject *attachedParent = findAttachedParent(metaObject(), parent()); - if (attachedParent) - setAttachedParent(attachedParent); - - const QList attachedChildren = findAttachedChildren(metaObject(), parent()); - for (QQuickAttachedObject *child : attachedChildren) - child->setAttachedParent(this); -} - -void QQuickAttachedObject::attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) -{ - Q_UNUSED(newParent); - Q_UNUSED(oldParent); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickattachedobject_p.h b/src/quickcontrols2/qquickattachedobject_p.h deleted file mode 100644 index 1e90c082..00000000 --- a/src/quickcontrols2/qquickattachedobject_p.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKATTACHEDOBJECT_P_H -#define QQUICKATTACHEDOBJECT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickAttachedObjectPrivate; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickAttachedObject : public QObject -{ - Q_OBJECT - -public: - explicit QQuickAttachedObject(QObject *parent = nullptr); - ~QQuickAttachedObject(); - - QList attachedChildren() const; - - QQuickAttachedObject *attachedParent() const; - void setAttachedParent(QQuickAttachedObject *parent); - -protected: - void init(); - - virtual void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent); - -private: - Q_DISABLE_COPY(QQuickAttachedObject) - Q_DECLARE_PRIVATE(QQuickAttachedObject) -}; - -QT_END_NAMESPACE - -#endif // QQUICKATTACHEDOBJECT_P_H diff --git a/src/quickcontrols2/qquickchecklabel.cpp b/src/quickcontrols2/qquickchecklabel.cpp deleted file mode 100644 index dccbf77f..00000000 --- a/src/quickcontrols2/qquickchecklabel.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickchecklabel_p.h" - -QT_BEGIN_NAMESPACE - -QQuickCheckLabel::QQuickCheckLabel(QQuickItem *parent) : - QQuickText(parent) -{ - setHAlign(AlignLeft); - setVAlign(AlignVCenter); - setElideMode(ElideRight); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickchecklabel_p.h b/src/quickcontrols2/qquickchecklabel_p.h deleted file mode 100644 index 100ef48f..00000000 --- a/src/quickcontrols2/qquickchecklabel_p.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKCHECKLABEL_P_H -#define QQUICKCHECKLABEL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickCheckLabel : public QQuickText -{ - Q_OBJECT - -public: - explicit QQuickCheckLabel(QQuickItem *parent = nullptr); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickCheckLabel) - -#endif // QQUICKCHECKLABEL_P_H diff --git a/src/quickcontrols2/qquickclippedtext.cpp b/src/quickcontrols2/qquickclippedtext.cpp deleted file mode 100644 index 862197f3..00000000 --- a/src/quickcontrols2/qquickclippedtext.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickclippedtext_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickClippedText::QQuickClippedText(QQuickItem *parent) - : QQuickText(parent) -{ -} - -qreal QQuickClippedText::clipX() const -{ - return m_clipX; -} - -void QQuickClippedText::setClipX(qreal x) -{ - if (qFuzzyCompare(x, m_clipX)) - return; - - m_clipX = x; - markClipDirty(); -} - -qreal QQuickClippedText::clipY() const -{ - return m_clipY; -} - -void QQuickClippedText::setClipY(qreal y) -{ - if (qFuzzyCompare(y, m_clipY)) - return; - - m_clipY = y; - markClipDirty(); -} - -qreal QQuickClippedText::clipWidth() const -{ - return m_clipWidth ? m_clipWidth : width(); -} - -void QQuickClippedText::setClipWidth(qreal width) -{ - m_hasClipWidth = true; - if (qFuzzyCompare(width, m_clipWidth)) - return; - - m_clipWidth = width; - markClipDirty(); -} - -qreal QQuickClippedText::clipHeight() const -{ - return m_clipHeight ? m_clipHeight : height(); -} - -void QQuickClippedText::setClipHeight(qreal height) -{ - m_hasClipHeight = true; - if (qFuzzyCompare(height, m_clipHeight)) - return; - - m_clipHeight = height; - markClipDirty(); -} - -QRectF QQuickClippedText::clipRect() const -{ - return QRectF(clipX(), clipY(), clipWidth(), clipHeight()); -} - -void QQuickClippedText::markClipDirty() -{ - QQuickItemPrivate::get(this)->dirty(QQuickItemPrivate::Size); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickclippedtext_p.h b/src/quickcontrols2/qquickclippedtext_p.h deleted file mode 100644 index 486ac7c4..00000000 --- a/src/quickcontrols2/qquickclippedtext_p.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKCLIPPEDTEXT_P_H -#define QQUICKCLIPPEDTEXT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickClippedText : public QQuickText -{ - Q_OBJECT - Q_PROPERTY(qreal clipX READ clipX WRITE setClipX FINAL) - Q_PROPERTY(qreal clipY READ clipY WRITE setClipY FINAL) - Q_PROPERTY(qreal clipWidth READ clipWidth WRITE setClipWidth FINAL) - Q_PROPERTY(qreal clipHeight READ clipHeight WRITE setClipHeight FINAL) - -public: - explicit QQuickClippedText(QQuickItem *parent = nullptr); - - qreal clipX() const; - void setClipX(qreal x); - - qreal clipY() const; - void setClipY(qreal y); - - qreal clipWidth() const; - void setClipWidth(qreal width); - - qreal clipHeight() const; - void setClipHeight(qreal height); - - QRectF clipRect() const override; - -private: - void markClipDirty(); - - bool m_hasClipWidth = false; - bool m_hasClipHeight = false; - qreal m_clipX = 0; - qreal m_clipY = 0; - qreal m_clipWidth = 0; - qreal m_clipHeight = 0; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickClippedText) - -#endif // QQUICKCLIPPEDTEXT_P_H diff --git a/src/quickcontrols2/qquickcolor.cpp b/src/quickcontrols2/qquickcolor.cpp deleted file mode 100644 index 8ae568fc..00000000 --- a/src/quickcontrols2/qquickcolor.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickcolor_p.h" - -QT_BEGIN_NAMESPACE - -QQuickColor::QQuickColor(QObject *parent) : - QObject(parent) -{ -} - -QColor QQuickColor::transparent(const QColor &color, qreal opacity) const -{ - return QColor(color.red(), color.green(), color.blue(), - int(qreal(255) * qBound(qreal(0), opacity, qreal(1)))); -} - -QColor QQuickColor::blend(const QColor &a, const QColor &b, qreal factor) const -{ - if (factor <= 0.0) - return a; - if (factor >= 1.0) - return b; - - QColor color; - color.setRedF(a.redF() * (1.0 - factor) + b.redF() * factor); - color.setGreenF(a.greenF() * (1.0 - factor) + b.greenF() * factor); - color.setBlueF(a.blueF() * (1.0 - factor) + b.blueF() * factor); - return color; -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickcolor_p.h b/src/quickcontrols2/qquickcolor_p.h deleted file mode 100644 index 657a9fa4..00000000 --- a/src/quickcontrols2/qquickcolor_p.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKCOLOR_P_H -#define QQUICKCOLOR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColor : public QObject -{ - Q_OBJECT - -public: - explicit QQuickColor(QObject *parent = nullptr); - - Q_INVOKABLE QColor transparent(const QColor &color, qreal opacity) const; - Q_INVOKABLE QColor blend(const QColor &a, const QColor &b, qreal factor) const; -}; - -QT_END_NAMESPACE - -#endif // QQUICKCOLOR_P_H diff --git a/src/quickcontrols2/qquickcolorimage.cpp b/src/quickcontrols2/qquickcolorimage.cpp deleted file mode 100644 index 3afcef7e..00000000 --- a/src/quickcontrols2/qquickcolorimage.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickcolorimage_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickColorImage::QQuickColorImage(QQuickItem *parent) - : QQuickImage(parent) -{ -} - -QColor QQuickColorImage::color() const -{ - return m_color; -} - -void QQuickColorImage::setColor(const QColor &color) -{ - if (m_color == color) - return; - - m_color = color; - if (isComponentComplete()) - load(); - emit colorChanged(); -} - -void QQuickColorImage::resetColor() -{ - setColor(Qt::transparent); -} - -QColor QQuickColorImage::defaultColor() const -{ - return m_defaultColor; -} - -void QQuickColorImage::setDefaultColor(const QColor &color) -{ - if (m_defaultColor == color) - return; - - m_defaultColor = color; - emit defaultColorChanged(); -} - -void QQuickColorImage::resetDefaultColor() -{ - setDefaultColor(Qt::transparent); -} - -void QQuickColorImage::pixmapChange() -{ - QQuickImage::pixmapChange(); - if (m_color.alpha() > 0 && m_color != m_defaultColor) { - QQuickImageBasePrivate *d = static_cast(QQuickItemPrivate::get(this)); - QImage image = d->pix.image(); - if (!image.isNull()) { - QPainter painter(&image); - painter.setCompositionMode(QPainter::CompositionMode_SourceIn); - painter.fillRect(image.rect(), m_color); - d->pix.setImage(image); - } - } -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickcolorimage_p.h b/src/quickcontrols2/qquickcolorimage_p.h deleted file mode 100644 index 8227d068..00000000 --- a/src/quickcontrols2/qquickcolorimage_p.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKCOLORIMAGE_P_H -#define QQUICKCOLORIMAGE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColorImage : public QQuickImage -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor NOTIFY colorChanged FINAL) - Q_PROPERTY(QColor defaultColor READ defaultColor WRITE setDefaultColor RESET resetDefaultColor NOTIFY defaultColorChanged FINAL) - -public: - explicit QQuickColorImage(QQuickItem *parent = nullptr); - - QColor color() const; - void setColor(const QColor &color); - void resetColor(); - - QColor defaultColor() const; - void setDefaultColor(const QColor &color); - void resetDefaultColor(); - -Q_SIGNALS: - void colorChanged(); - void defaultColorChanged(); - -protected: - void pixmapChange() override; - -private: - QColor m_color = Qt::transparent; - QColor m_defaultColor = Qt::transparent; -}; - -QT_END_NAMESPACE - -#endif // QQUICKCOLORIMAGE_P_H diff --git a/src/quickcontrols2/qquickiconimage.cpp b/src/quickcontrols2/qquickiconimage.cpp deleted file mode 100644 index 1fc3abfc..00000000 --- a/src/quickcontrols2/qquickiconimage.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickiconimage_p.h" -#include "qquickiconimage_p_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -bool QQuickIconImagePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio) -{ - if (isThemeIcon) { - devicePixelRatio = calculateDevicePixelRatio(); - return true; - } - - return QQuickImagePrivate::updateDevicePixelRatio(targetDevicePixelRatio); -} - -void QQuickIconImagePrivate::updateIcon() -{ - Q_Q(QQuickIconImage); - // Both geometryChange() and QQuickImageBase::sourceSizeChanged() - // (which we connect to updateIcon() in the constructor) can be called as a result - // of updateIcon() changing the various sizes, so we must check that we're not recursing. - if (updatingIcon) - return; - - updatingIcon = true; - - QSize size = sourcesize; - // If no size is specified for theme icons, it will use the smallest available size. - if (size.width() <= 0) - size.setWidth(q->width()); - if (size.height() <= 0) - size.setHeight(q->height()); - - const qreal dpr = calculateDevicePixelRatio(); - const QIconLoaderEngineEntry *entry = QIconLoaderEngine::entryForSize(icon, size * dpr, qCeil(dpr)); - - if (entry) { - QQmlContext *context = qmlContext(q); - const QUrl entryUrl = QUrl::fromLocalFile(entry->filename); - url = context ? context->resolvedUrl(entryUrl) : entryUrl; - isThemeIcon = true; - } else { - url = source; - isThemeIcon = false; - } - q->load(); - - updatingIcon = false; -} - -void QQuickIconImagePrivate::updateFillMode() -{ - Q_Q(QQuickIconImage); - // If we start with a sourceSize of 28x28 and then set sourceSize.width to 24, the fillMode - // will change to PreserveAspectFit (because pixmapSize.width() > width()), which causes the - // pixmap to be reloaded at its original size of 28x28, which causes the fillMode to change - // to Pad (because pixmapSize.width() <= width()), and so on. - if (updatingFillMode) - return; - - updatingFillMode = true; - - const QSize pixmapSize = QSize(pix.width(), pix.height()) / calculateDevicePixelRatio(); - if (pixmapSize.width() > q->width() || pixmapSize.height() > q->height()) - q->setFillMode(QQuickImage::PreserveAspectFit); - else - q->setFillMode(QQuickImage::Pad); - - updatingFillMode = false; -} - -qreal QQuickIconImagePrivate::calculateDevicePixelRatio() const -{ - Q_Q(const QQuickIconImage); - return q->window() ? q->window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio(); -} - -QQuickIconImage::QQuickIconImage(QQuickItem *parent) - : QQuickImage(*(new QQuickIconImagePrivate), parent) -{ - setFillMode(Pad); -} - -QString QQuickIconImage::name() const -{ - Q_D(const QQuickIconImage); - return d->icon.iconName; -} - -void QQuickIconImage::setName(const QString &name) -{ - Q_D(QQuickIconImage); - if (d->icon.iconName == name) - return; - - d->icon = QIconLoader::instance()->loadIcon(name); - if (isComponentComplete()) - d->updateIcon(); - emit nameChanged(); -} - -QColor QQuickIconImage::color() const -{ - Q_D(const QQuickIconImage); - return d->color; -} - -void QQuickIconImage::setColor(const QColor &color) -{ - Q_D(QQuickIconImage); - if (d->color == color) - return; - - d->color = color; - if (isComponentComplete()) - d->updateIcon(); - emit colorChanged(); -} - -void QQuickIconImage::setSource(const QUrl &source) -{ - Q_D(QQuickIconImage); - if (d->source == source) - return; - - d->source = source; - if (isComponentComplete()) - d->updateIcon(); - emit sourceChanged(source); -} - -void QQuickIconImage::componentComplete() -{ - Q_D(QQuickIconImage); - QQuickImage::componentComplete(); - d->updateIcon(); - QObjectPrivate::connect(this, &QQuickImageBase::sourceSizeChanged, d, &QQuickIconImagePrivate::updateIcon); -} - -void QQuickIconImage::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickIconImage); - QQuickImage::geometryChange(newGeometry, oldGeometry); - if (isComponentComplete() && newGeometry.size() != oldGeometry.size()) - d->updateIcon(); -} - -void QQuickIconImage::itemChange(ItemChange change, const ItemChangeData &value) -{ - Q_D(QQuickIconImage); - if (change == ItemDevicePixelRatioHasChanged) - d->updateIcon(); - QQuickImage::itemChange(change, value); -} - -void QQuickIconImage::pixmapChange() -{ - Q_D(QQuickIconImage); - QQuickImage::pixmapChange(); - d->updateFillMode(); - - // Don't apply the color if we're recursing (updateFillMode() can cause us to recurse). - if (!d->updatingFillMode && d->color.alpha() > 0) { - QImage image = d->pix.image(); - if (!image.isNull()) { - QPainter painter(&image); - painter.setCompositionMode(QPainter::CompositionMode_SourceIn); - painter.fillRect(image.rect(), d->color); - d->pix.setImage(image); - } - } -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickiconimage_p.h b/src/quickcontrols2/qquickiconimage_p.h deleted file mode 100644 index 0aac08e6..00000000 --- a/src/quickcontrols2/qquickiconimage_p.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKICONIMAGE_P_H -#define QQUICKICONIMAGE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickIconImagePrivate; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconImage : public QQuickImage -{ - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL) - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) - -public: - explicit QQuickIconImage(QQuickItem *parent = nullptr); - - QString name() const; - void setName(const QString &name); - - QColor color() const; - void setColor(const QColor &color); - - void setSource(const QUrl &url) override; - -Q_SIGNALS: - void nameChanged(); - void colorChanged(); - -protected: - void componentComplete() override; - void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; - void itemChange(ItemChange change, const ItemChangeData &value) override; - void pixmapChange() override; - -private: - Q_DISABLE_COPY(QQuickIconImage) - Q_DECLARE_PRIVATE(QQuickIconImage) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickIconImage) - -#endif // QQUICKICONIMAGE_P_H diff --git a/src/quickcontrols2/qquickiconimage_p_p.h b/src/quickcontrols2/qquickiconimage_p_p.h deleted file mode 100644 index 0c755ff6..00000000 --- a/src/quickcontrols2/qquickiconimage_p_p.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKICONIMAGE_P_P_H -#define QQUICKICONIMAGE_P_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconImagePrivate : public QQuickImagePrivate -{ - Q_DECLARE_PUBLIC(QQuickIconImage) - -public: - void updateIcon(); - void updateFillMode(); - qreal calculateDevicePixelRatio() const; - bool updateDevicePixelRatio(qreal targetDevicePixelRatio) override; - - QUrl source; - QColor color = Qt::transparent; - QThemeIconInfo icon; - bool updatingIcon = false; - bool isThemeIcon = false; - bool updatingFillMode = false; -}; - -QT_END_NAMESPACE - -#endif // QQUICKICONIMAGE_P_P_H diff --git a/src/quickcontrols2/qquickiconlabel.cpp b/src/quickcontrols2/qquickiconlabel.cpp deleted file mode 100644 index d76da28f..00000000 --- a/src/quickcontrols2/qquickiconlabel.cpp +++ /dev/null @@ -1,642 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickiconlabel_p.h" -#include "qquickiconlabel_p_p.h" -#include "qquickiconimage_p.h" -#include "qquickmnemoniclabel_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static void beginClass(QQuickItem *item) -{ - if (QQmlParserStatus *parserStatus = qobject_cast(item)) - parserStatus->classBegin(); -} - -static void completeComponent(QQuickItem *item) -{ - if (QQmlParserStatus *parserStatus = qobject_cast(item)) - parserStatus->componentComplete(); -} - -bool QQuickIconLabelPrivate::hasIcon() const -{ - return display != QQuickIconLabel::TextOnly && !icon.isEmpty(); -} - -bool QQuickIconLabelPrivate::hasText() const -{ - return display != QQuickIconLabel::IconOnly && !text.isEmpty(); -} - -bool QQuickIconLabelPrivate::createImage() -{ - Q_Q(QQuickIconLabel); - if (image) - return false; - - image = new QQuickIconImage(q); - watchChanges(image); - beginClass(image); - image->setObjectName(QStringLiteral("image")); - image->setName(icon.name()); - image->setSource(icon.source()); - image->setSourceSize(QSize(icon.width(), icon.height())); - image->setColor(icon.color()); - image->setCache(icon.cache()); - QQmlEngine::setContextForObject(image, qmlContext(q)); - if (componentComplete) - completeComponent(image); - return true; -} - -bool QQuickIconLabelPrivate::destroyImage() -{ - if (!image) - return false; - - unwatchChanges(image); - delete image; - image = nullptr; - return true; -} - -bool QQuickIconLabelPrivate::updateImage() -{ - if (!hasIcon()) - return destroyImage(); - return createImage(); -} - -void QQuickIconLabelPrivate::syncImage() -{ - if (!image || icon.isEmpty()) - return; - - image->setName(icon.name()); - image->setSource(icon.source()); - image->setSourceSize(QSize(icon.width(), icon.height())); - image->setColor(icon.color()); - image->setCache(icon.cache()); - const int valign = alignment & Qt::AlignVertical_Mask; - image->setVerticalAlignment(static_cast(valign)); - const int halign = alignment & Qt::AlignHorizontal_Mask; - image->setHorizontalAlignment(static_cast(halign)); -} - -void QQuickIconLabelPrivate::updateOrSyncImage() -{ - if (updateImage()) { - if (componentComplete) { - updateImplicitSize(); - layout(); - } - } else { - syncImage(); - } -} - -bool QQuickIconLabelPrivate::createLabel() -{ - Q_Q(QQuickIconLabel); - if (label) - return false; - - label = new QQuickMnemonicLabel(q); - watchChanges(label); - beginClass(label); - label->setObjectName(QStringLiteral("label")); - label->setFont(font); - label->setColor(color); - label->setElideMode(QQuickText::ElideRight); - const int valign = alignment & Qt::AlignVertical_Mask; - label->setVAlign(static_cast(valign)); - const int halign = alignment & Qt::AlignHorizontal_Mask; - label->setHAlign(static_cast(halign)); - label->setText(text); - if (componentComplete) - completeComponent(label); - return true; -} - -bool QQuickIconLabelPrivate::destroyLabel() -{ - if (!label) - return false; - - unwatchChanges(label); - delete label; - label = nullptr; - return true; -} - -bool QQuickIconLabelPrivate::updateLabel() -{ - if (!hasText()) - return destroyLabel(); - return createLabel(); -} - -void QQuickIconLabelPrivate::syncLabel() -{ - if (!label) - return; - - label->setText(text); -} - -void QQuickIconLabelPrivate::updateOrSyncLabel() -{ - if (updateLabel()) { - if (componentComplete) { - updateImplicitSize(); - layout(); - } - } else { - syncLabel(); - } -} - -void QQuickIconLabelPrivate::updateImplicitSize() -{ - Q_Q(QQuickIconLabel); - const bool showIcon = image && hasIcon(); - const bool showText = label && hasText(); - const qreal horizontalPadding = leftPadding + rightPadding; - const qreal verticalPadding = topPadding + bottomPadding; - const qreal iconImplicitWidth = showIcon ? image->implicitWidth() : 0; - const qreal iconImplicitHeight = showIcon ? image->implicitHeight() : 0; - const qreal textImplicitWidth = showText ? label->implicitWidth() : 0; - const qreal textImplicitHeight = showText ? label->implicitHeight() : 0; - const qreal effectiveSpacing = showText && showIcon && image->implicitWidth() > 0 ? spacing : 0; - const qreal implicitWidth = display == QQuickIconLabel::TextBesideIcon ? iconImplicitWidth + textImplicitWidth + effectiveSpacing - : qMax(iconImplicitWidth, textImplicitWidth); - const qreal implicitHeight = display == QQuickIconLabel::TextUnderIcon ? iconImplicitHeight + textImplicitHeight + effectiveSpacing - : qMax(iconImplicitHeight, textImplicitHeight); - q->setImplicitSize(implicitWidth + horizontalPadding, implicitHeight + verticalPadding); -} - -// adapted from QStyle::alignedRect() -static QRectF alignedRect(bool mirrored, Qt::Alignment alignment, const QSizeF &size, const QRectF &rectangle) -{ - alignment = QGuiApplicationPrivate::visualAlignment(mirrored ? Qt::RightToLeft : Qt::LeftToRight, alignment); - qreal x = rectangle.x(); - qreal y = rectangle.y(); - const qreal w = size.width(); - const qreal h = size.height(); - if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter) - y += rectangle.height() / 2 - h / 2; - else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom) - y += rectangle.height() - h; - if ((alignment & Qt::AlignRight) == Qt::AlignRight) - x += rectangle.width() - w; - else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter) - x += rectangle.width() / 2 - w / 2; - return QRectF(x, y, w, h); -} - -void QQuickIconLabelPrivate::layout() -{ - Q_Q(QQuickIconLabel); - if (!componentComplete) - return; - - const qreal availableWidth = width - leftPadding - rightPadding; - const qreal availableHeight = height - topPadding - bottomPadding; - - switch (display) { - case QQuickIconLabel::IconOnly: - if (image) { - const QRectF iconRect = alignedRect(mirrored, alignment, - QSizeF(qMin(image->implicitWidth(), availableWidth), - qMin(image->implicitHeight(), availableHeight)), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - image->setSize(iconRect.size()); - image->setPosition(iconRect.topLeft()); - } - break; - case QQuickIconLabel::TextOnly: - if (label) { - const QRectF textRect = alignedRect(mirrored, alignment, - QSizeF(qMin(label->implicitWidth(), availableWidth), - qMin(label->implicitHeight(), availableHeight)), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - label->setSize(textRect.size()); - label->setPosition(textRect.topLeft()); - } - break; - - case QQuickIconLabel::TextUnderIcon: { - // Work out the sizes first, as the positions depend on them. - QSizeF iconSize; - QSizeF textSize; - if (image) { - iconSize.setWidth(qMin(image->implicitWidth(), availableWidth)); - iconSize.setHeight(qMin(image->implicitHeight(), availableHeight)); - } - qreal effectiveSpacing = 0; - if (label) { - if (!iconSize.isEmpty()) - effectiveSpacing = spacing; - textSize.setWidth(qMin(label->implicitWidth(), availableWidth)); - textSize.setHeight(qMin(label->implicitHeight(), availableHeight - iconSize.height() - effectiveSpacing)); - } - - QRectF combinedRect = alignedRect(mirrored, alignment, - QSizeF(qMax(iconSize.width(), textSize.width()), - iconSize.height() + effectiveSpacing + textSize.height()), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - if (image) { - QRectF iconRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignTop, iconSize, combinedRect); - image->setSize(iconRect.size()); - image->setPosition(iconRect.topLeft()); - } - if (label) { - QRectF textRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignBottom, textSize, combinedRect); - label->setSize(textRect.size()); - label->setPosition(textRect.topLeft()); - } - break; - } - - case QQuickIconLabel::TextBesideIcon: - default: - // Work out the sizes first, as the positions depend on them. - QSizeF iconSize(0, 0); - QSizeF textSize(0, 0); - if (image) { - iconSize.setWidth(qMin(image->implicitWidth(), availableWidth)); - iconSize.setHeight(qMin(image->implicitHeight(), availableHeight)); - } - qreal effectiveSpacing = 0; - if (label) { - if (!iconSize.isEmpty()) - effectiveSpacing = spacing; - textSize.setWidth(qMin(label->implicitWidth(), availableWidth - iconSize.width() - effectiveSpacing)); - textSize.setHeight(qMin(label->implicitHeight(), availableHeight)); - } - - const QRectF combinedRect = alignedRect(mirrored, alignment, - QSizeF(iconSize.width() + effectiveSpacing + textSize.width(), - qMax(iconSize.height(), textSize.height())), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - if (image) { - const QRectF iconRect = alignedRect(mirrored, Qt::AlignLeft | Qt::AlignVCenter, iconSize, combinedRect); - image->setSize(iconRect.size()); - image->setPosition(iconRect.topLeft()); - } - if (label) { - const QRectF textRect = alignedRect(mirrored, Qt::AlignRight | Qt::AlignVCenter, textSize, combinedRect); - label->setSize(textRect.size()); - label->setPosition(textRect.topLeft()); - } - break; - } - - q->setBaselineOffset(label ? label->y() + label->baselineOffset() : 0); -} - -static const QQuickItemPrivate::ChangeTypes itemChangeTypes = - QQuickItemPrivate::ImplicitWidth - | QQuickItemPrivate::ImplicitHeight - | QQuickItemPrivate::Destroyed; - -void QQuickIconLabelPrivate::watchChanges(QQuickItem *item) -{ - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - itemPrivate->addItemChangeListener(this, itemChangeTypes); -} - -void QQuickIconLabelPrivate::unwatchChanges(QQuickItem* item) -{ - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - itemPrivate->removeItemChangeListener(this, itemChangeTypes); -} - -void QQuickIconLabelPrivate::itemImplicitWidthChanged(QQuickItem *) -{ - updateImplicitSize(); - layout(); -} - -void QQuickIconLabelPrivate::itemImplicitHeightChanged(QQuickItem *) -{ - updateImplicitSize(); - layout(); -} - -void QQuickIconLabelPrivate::itemDestroyed(QQuickItem *item) -{ - unwatchChanges(item); - if (item == image) - image = nullptr; - else if (item == label) - label = nullptr; -} - -QQuickIconLabel::QQuickIconLabel(QQuickItem *parent) - : QQuickItem(*(new QQuickIconLabelPrivate), parent) -{ -} - -QQuickIconLabel::~QQuickIconLabel() -{ - Q_D(QQuickIconLabel); - if (d->image) - d->unwatchChanges(d->image); - if (d->label) - d->unwatchChanges(d->label); -} - -QQuickIcon QQuickIconLabel::icon() const -{ - Q_D(const QQuickIconLabel); - return d->icon; -} - -void QQuickIconLabel::setIcon(const QQuickIcon &icon) -{ - Q_D(QQuickIconLabel); - if (d->icon == icon) - return; - - d->icon = icon; - d->updateOrSyncImage(); -} - -QString QQuickIconLabel::text() const -{ - Q_D(const QQuickIconLabel); - return d->text; -} - -void QQuickIconLabel::setText(const QString &text) -{ - Q_D(QQuickIconLabel); - if (d->text == text) - return; - - d->text = text; - d->updateOrSyncLabel(); -} - -QFont QQuickIconLabel::font() const -{ - Q_D(const QQuickIconLabel); - return d->font; -} - -void QQuickIconLabel::setFont(const QFont &font) -{ - Q_D(QQuickIconLabel); - if (d->font == font) - return; - - d->font = font; - if (d->label) - d->label->setFont(font); -} - -QColor QQuickIconLabel::color() const -{ - Q_D(const QQuickIconLabel); - return d->color; -} - -void QQuickIconLabel::setColor(const QColor &color) -{ - Q_D(QQuickIconLabel); - if (d->color == color) - return; - - d->color = color; - if (d->label) - d->label->setColor(color); -} - -QQuickIconLabel::Display QQuickIconLabel::display() const -{ - Q_D(const QQuickIconLabel); - return d->display; -} - -void QQuickIconLabel::setDisplay(Display display) -{ - Q_D(QQuickIconLabel); - if (d->display == display) - return; - - d->display = display; - d->updateImage(); - d->updateLabel(); - d->updateImplicitSize(); - d->layout(); -} - -qreal QQuickIconLabel::spacing() const -{ - Q_D(const QQuickIconLabel); - return d->spacing; -} - -void QQuickIconLabel::setSpacing(qreal spacing) -{ - Q_D(QQuickIconLabel); - if (qFuzzyCompare(d->spacing, spacing)) - return; - - d->spacing = spacing; - if (d->image && d->label) { - d->updateImplicitSize(); - d->layout(); - } -} - -bool QQuickIconLabel::isMirrored() const -{ - Q_D(const QQuickIconLabel); - return d->mirrored; -} - -void QQuickIconLabel::setMirrored(bool mirrored) -{ - Q_D(QQuickIconLabel); - if (d->mirrored == mirrored) - return; - - d->mirrored = mirrored; - d->layout(); -} - -Qt::Alignment QQuickIconLabel::alignment() const -{ - Q_D(const QQuickIconLabel); - return d->alignment; -} - -void QQuickIconLabel::setAlignment(Qt::Alignment alignment) -{ - Q_D(QQuickIconLabel); - const int valign = alignment & Qt::AlignVertical_Mask; - const int halign = alignment & Qt::AlignHorizontal_Mask; - const uint align = (valign ? valign : Qt::AlignVCenter) | (halign ? halign : Qt::AlignHCenter); - if (d->alignment == align) - return; - - d->alignment = static_cast(align); - if (d->label) { - d->label->setVAlign(static_cast(valign)); - d->label->setHAlign(static_cast(halign)); - } - if (d->image) { - d->image->setVerticalAlignment(static_cast(valign)); - d->image->setHorizontalAlignment(static_cast(halign)); - } - d->layout(); -} - -qreal QQuickIconLabel::topPadding() const -{ - Q_D(const QQuickIconLabel); - return d->topPadding; -} - -void QQuickIconLabel::setTopPadding(qreal padding) -{ - Q_D(QQuickIconLabel); - if (qFuzzyCompare(d->topPadding, padding)) - return; - - d->topPadding = padding; - d->updateImplicitSize(); - d->layout(); -} - -void QQuickIconLabel::resetTopPadding() -{ - setTopPadding(0); -} - -qreal QQuickIconLabel::leftPadding() const -{ - Q_D(const QQuickIconLabel); - return d->leftPadding; -} - -void QQuickIconLabel::setLeftPadding(qreal padding) -{ - Q_D(QQuickIconLabel); - if (qFuzzyCompare(d->leftPadding, padding)) - return; - - d->leftPadding = padding; - d->updateImplicitSize(); - d->layout(); -} - -void QQuickIconLabel::resetLeftPadding() -{ - setLeftPadding(0); -} - -qreal QQuickIconLabel::rightPadding() const -{ - Q_D(const QQuickIconLabel); - return d->rightPadding; -} - -void QQuickIconLabel::setRightPadding(qreal padding) -{ - Q_D(QQuickIconLabel); - if (qFuzzyCompare(d->rightPadding, padding)) - return; - - d->rightPadding = padding; - d->updateImplicitSize(); - d->layout(); -} - -void QQuickIconLabel::resetRightPadding() -{ - setRightPadding(0); -} - -qreal QQuickIconLabel::bottomPadding() const -{ - Q_D(const QQuickIconLabel); - return d->bottomPadding; -} - -void QQuickIconLabel::setBottomPadding(qreal padding) -{ - Q_D(QQuickIconLabel); - if (qFuzzyCompare(d->bottomPadding, padding)) - return; - - d->bottomPadding = padding; - d->updateImplicitSize(); - d->layout(); -} - -void QQuickIconLabel::resetBottomPadding() -{ - setBottomPadding(0); -} - -void QQuickIconLabel::componentComplete() -{ - Q_D(QQuickIconLabel); - if (d->image) - completeComponent(d->image); - if (d->label) - completeComponent(d->label); - QQuickItem::componentComplete(); - d->layout(); -} - -void QQuickIconLabel::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickIconLabel); - QQuickItem::geometryChange(newGeometry, oldGeometry); - d->layout(); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickiconlabel_p.h b/src/quickcontrols2/qquickiconlabel_p.h deleted file mode 100644 index ecf2336e..00000000 --- a/src/quickcontrols2/qquickiconlabel_p.h +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKICONLABEL_P_H -#define QQUICKICONLABEL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickIconLabelPrivate; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconLabel : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon FINAL) - Q_PROPERTY(QString text READ text WRITE setText FINAL) - Q_PROPERTY(QFont font READ font WRITE setFont FINAL) - Q_PROPERTY(QColor color READ color WRITE setColor FINAL) - Q_PROPERTY(Display display READ display WRITE setDisplay FINAL) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing FINAL) - Q_PROPERTY(bool mirrored READ isMirrored WRITE setMirrored FINAL) - Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment FINAL) - Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding FINAL) - Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding FINAL) - Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding FINAL) - Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding FINAL) - -public: - enum Display { - IconOnly, - TextOnly, - TextBesideIcon, - TextUnderIcon - }; - Q_ENUM(Display) - - explicit QQuickIconLabel(QQuickItem *parent = nullptr); - ~QQuickIconLabel(); - - QQuickIcon icon() const; - void setIcon(const QQuickIcon &icon); - - QString text() const; - void setText(const QString &text); - - QFont font() const; - void setFont(const QFont &font); - - QColor color() const; - void setColor(const QColor &color); - - Display display() const; - void setDisplay(Display display); - - qreal spacing() const; - void setSpacing(qreal spacing); - - bool isMirrored() const; - void setMirrored(bool mirrored); - - Qt::Alignment alignment() const; - void setAlignment(Qt::Alignment alignment); - - qreal topPadding() const; - void setTopPadding(qreal padding); - void resetTopPadding(); - - qreal leftPadding() const; - void setLeftPadding(qreal padding); - void resetLeftPadding(); - - qreal rightPadding() const; - void setRightPadding(qreal padding); - void resetRightPadding(); - - qreal bottomPadding() const; - void setBottomPadding(qreal padding); - void resetBottomPadding(); - -protected: - void componentComplete() override; - void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; - -private: - Q_DISABLE_COPY(QQuickIconLabel) - Q_DECLARE_PRIVATE(QQuickIconLabel) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickIconLabel) - -#endif // QQUICKICONLABEL_P_H diff --git a/src/quickcontrols2/qquickiconlabel_p_p.h b/src/quickcontrols2/qquickiconlabel_p_p.h deleted file mode 100644 index 6a2a0f58..00000000 --- a/src/quickcontrols2/qquickiconlabel_p_p.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKICONLABEL_P_P_H -#define QQUICKICONLABEL_P_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickIconImage; -class QQuickMnemonicLabel; - -class QQuickIconLabelPrivate : public QQuickItemPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickIconLabel) - -public: - bool hasIcon() const; - bool hasText() const; - - bool createImage(); - bool destroyImage(); - bool updateImage(); - void syncImage(); - void updateOrSyncImage(); - - bool createLabel(); - bool destroyLabel(); - bool updateLabel(); - void syncLabel(); - void updateOrSyncLabel(); - - void updateImplicitSize(); - void layout(); - - void watchChanges(QQuickItem *item); - void unwatchChanges(QQuickItem *item); - void setPositioningDirty(); - - bool isLeftToRight() const; - - void itemImplicitWidthChanged(QQuickItem *) override; - void itemImplicitHeightChanged(QQuickItem *) override; - void itemDestroyed(QQuickItem *item) override; - - bool mirrored = false; - QQuickIconLabel::Display display = QQuickIconLabel::TextBesideIcon; - Qt::Alignment alignment = Qt::AlignCenter; - qreal spacing = 0; - qreal topPadding = 0; - qreal leftPadding = 0; - qreal rightPadding = 0; - qreal bottomPadding = 0; - QFont font; - QColor color; - QString text; - QQuickIcon icon; - QQuickIconImage *image = nullptr; - QQuickMnemonicLabel *label = nullptr; -}; - -QT_END_NAMESPACE - -#endif // QQUICKICONLABEL_P_P_H diff --git a/src/quickcontrols2/qquickitemgroup.cpp b/src/quickcontrols2/qquickitemgroup.cpp deleted file mode 100644 index c4307001..00000000 --- a/src/quickcontrols2/qquickitemgroup.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickitemgroup_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickItemGroup::QQuickItemGroup(QQuickItem *parent) - : QQuickImplicitSizeItem(*(new QQuickImplicitSizeItemPrivate), parent) -{ -} - -QQuickItemGroup::~QQuickItemGroup() -{ - const auto children = childItems(); - for (QQuickItem *child : children) - unwatch(child); -} - -void QQuickItemGroup::watch(QQuickItem *item) -{ - QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); -} - -void QQuickItemGroup::unwatch(QQuickItem *item) -{ - QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); -} - -QSizeF QQuickItemGroup::calculateImplicitSize() const -{ - qreal width = 0; - qreal height = 0; - const auto children = childItems(); - for (QQuickItem *child : children) { - width = qMax(width, child->implicitWidth()); - height = qMax(height, child->implicitHeight()); - } - return QSizeF(width, height); -} - -void QQuickItemGroup::updateImplicitSize() -{ - QSizeF size = calculateImplicitSize(); - setImplicitSize(size.width(), size.height()); -} - -void QQuickItemGroup::itemChange(ItemChange change, const ItemChangeData &data) -{ - QQuickImplicitSizeItem::itemChange(change, data); - switch (change) { - case ItemChildAddedChange: - watch(data.item); - data.item->setSize(QSizeF(width(), height())); - updateImplicitSize(); - break; - case ItemChildRemovedChange: - unwatch(data.item); - updateImplicitSize(); - break; - default: - break; - } -} - -void QQuickItemGroup::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - QQuickImplicitSizeItem::geometryChange(newGeometry, oldGeometry); - - if (newGeometry.size() != oldGeometry.size()) { - const auto children = childItems(); - for (QQuickItem *child : children) - child->setSize(newGeometry.size()); - } -} - -void QQuickItemGroup::itemImplicitWidthChanged(QQuickItem *) -{ - setImplicitWidth(calculateImplicitSize().width()); -} - -void QQuickItemGroup::itemImplicitHeightChanged(QQuickItem *) -{ - setImplicitHeight(calculateImplicitSize().height()); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickitemgroup_p.h b/src/quickcontrols2/qquickitemgroup_p.h deleted file mode 100644 index ab6306b4..00000000 --- a/src/quickcontrols2/qquickitemgroup_p.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKITEMGROUP_P_H -#define QQUICKITEMGROUP_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickItemGroup : public QQuickImplicitSizeItem, protected QQuickItemChangeListener -{ - Q_OBJECT - -public: - explicit QQuickItemGroup(QQuickItem *parent = nullptr); - ~QQuickItemGroup(); - -protected: - void watch(QQuickItem *item); - void unwatch(QQuickItem *item); - - QSizeF calculateImplicitSize() const; - void updateImplicitSize(); - - void itemChange(ItemChange change, const ItemChangeData &data) override; - void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; - - void itemImplicitWidthChanged(QQuickItem *item) override; - void itemImplicitHeightChanged(QQuickItem *item) override; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickItemGroup) - -#endif // QQUICKITEMGROUP_P_H diff --git a/src/quickcontrols2/qquickmnemoniclabel.cpp b/src/quickcontrols2/qquickmnemoniclabel.cpp deleted file mode 100644 index 309d076a..00000000 --- a/src/quickcontrols2/qquickmnemoniclabel.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickmnemoniclabel_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickMnemonicLabel::QQuickMnemonicLabel(QQuickItem *parent) - : QQuickText(parent) -{ -} - -QString QQuickMnemonicLabel::text() const -{ - return m_fullText; -} - -void QQuickMnemonicLabel::setText(const QString &text) -{ - if (m_fullText == text) - return; - - m_fullText = text; - updateMnemonic(); -} - -bool QQuickMnemonicLabel::isMnemonicVisible() const -{ - return m_mnemonicVisible; -} - -void QQuickMnemonicLabel::setMnemonicVisible(bool visible) -{ - if (m_mnemonicVisible == visible) - return; - - m_mnemonicVisible = visible; - updateMnemonic(); - - if (isComponentComplete()) - forceLayout(); -} - -static QTextLayout::FormatRange underlineRange(int start, int length = 1) -{ - QTextLayout::FormatRange range; - range.start = start; - range.length = length; - range.format.setFontUnderline(true); - return range; -} - -// based on QPlatformTheme::removeMnemonics() -void QQuickMnemonicLabel::updateMnemonic() -{ - QString text(m_fullText.size(), QChar::Null); - int idx = 0; - int pos = 0; - int len = m_fullText.length(); - QList formats; - while (len) { - if (m_fullText.at(pos) == QLatin1Char('&') && (len == 1 || m_fullText.at(pos + 1) != QLatin1Char('&'))) { - if (m_mnemonicVisible && (pos == 0 || m_fullText.at(pos - 1) != QLatin1Char('&'))) - formats += underlineRange(pos); - ++pos; - --len; - if (len == 0) - break; - } else if (m_fullText.at(pos) == QLatin1Char('(') && len >= 4 && - m_fullText.at(pos + 1) == QLatin1Char('&') && - m_fullText.at(pos + 2) != QLatin1Char('&') && - m_fullText.at(pos + 3) == QLatin1Char(')')) { - // a mnemonic with format "\s*(&X)" - if (m_mnemonicVisible) { - formats += underlineRange(pos + 1); - } else { - int n = 0; - while (idx > n && text.at(idx - n - 1).isSpace()) - ++n; - idx -= n; - pos += 4; - len -= 4; - continue; - } - } - text[idx] = m_fullText.at(pos); - ++pos; - ++idx; - --len; - } - text.truncate(idx); - - QQuickTextPrivate::get(this)->layout.setFormats(formats); - QQuickText::setText(text); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickmnemoniclabel_p.h b/src/quickcontrols2/qquickmnemoniclabel_p.h deleted file mode 100644 index da5a83db..00000000 --- a/src/quickcontrols2/qquickmnemoniclabel_p.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKMNEMONICLABEL_P_H -#define QQUICKMNEMONICLABEL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickMnemonicLabel : public QQuickText -{ - Q_OBJECT - Q_PROPERTY(QString text READ text WRITE setText FINAL) - Q_PROPERTY(bool mnemonicVisible READ isMnemonicVisible WRITE setMnemonicVisible FINAL) - -public: - explicit QQuickMnemonicLabel(QQuickItem *parent = nullptr); - - QString text() const; - void setText(const QString &text); - - bool isMnemonicVisible() const; - void setMnemonicVisible(bool visible); - -private: - void updateMnemonic(); - - bool m_mnemonicVisible = true; - QString m_fullText; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickMnemonicLabel) - -#endif // QQUICKMNEMONICLABEL_P_H diff --git a/src/quickcontrols2/qquickpaddedrectangle.cpp b/src/quickcontrols2/qquickpaddedrectangle.cpp deleted file mode 100644 index fd9e9d90..00000000 --- a/src/quickcontrols2/qquickpaddedrectangle.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickpaddedrectangle_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickPaddedRectangle::QQuickPaddedRectangle(QQuickItem *parent) : - QQuickRectangle(parent) -{ -} - -qreal QQuickPaddedRectangle::padding() const -{ - return m_padding; -} - -void QQuickPaddedRectangle::setPadding(qreal padding) -{ - if (!qFuzzyCompare(m_padding, padding)) { - m_padding = padding; - update(); - emit paddingChanged(); - if (m_hasTopPadding) - emit topPaddingChanged(); - if (!m_hasLeftPadding) - emit leftPaddingChanged(); - if (!m_hasRightPadding) - emit rightPaddingChanged(); - if (!m_hasBottomPadding) - emit bottomPaddingChanged(); - } -} - -void QQuickPaddedRectangle::resetPadding() -{ - setPadding(0); -} - -qreal QQuickPaddedRectangle::topPadding() const -{ - return m_hasTopPadding ? m_topPadding : m_padding; -} - -void QQuickPaddedRectangle::setTopPadding(qreal padding) -{ - setTopPadding(padding, true); -} - -void QQuickPaddedRectangle::resetTopPadding() -{ - setTopPadding(0, false); -} - -qreal QQuickPaddedRectangle::leftPadding() const -{ - return m_hasLeftPadding ? m_leftPadding : m_padding; -} - -void QQuickPaddedRectangle::setLeftPadding(qreal padding) -{ - setLeftPadding(padding, true); -} - -void QQuickPaddedRectangle::resetLeftPadding() -{ - setLeftPadding(0, false); -} - -qreal QQuickPaddedRectangle::rightPadding() const -{ - return m_hasRightPadding ? m_rightPadding : m_padding; -} - -void QQuickPaddedRectangle::setRightPadding(qreal padding) -{ - setRightPadding(padding, true); -} - -void QQuickPaddedRectangle::resetRightPadding() -{ - setRightPadding(0, false); -} - -qreal QQuickPaddedRectangle::bottomPadding() const -{ - return m_hasBottomPadding ? m_bottomPadding : m_padding; -} - -void QQuickPaddedRectangle::setBottomPadding(qreal padding) -{ - setBottomPadding(padding, true); -} - -void QQuickPaddedRectangle::resetBottomPadding() -{ - setBottomPadding(0, false); -} - -void QQuickPaddedRectangle::setTopPadding(qreal padding, bool has) -{ - qreal oldPadding = topPadding(); - m_hasTopPadding = has; - m_topPadding = padding; - if (!qFuzzyCompare(oldPadding, padding)) { - update(); - emit topPaddingChanged(); - } -} - -void QQuickPaddedRectangle::setLeftPadding(qreal padding, bool has) -{ - qreal oldPadding = leftPadding(); - m_hasLeftPadding = has; - m_leftPadding = padding; - if (!qFuzzyCompare(oldPadding, padding)) { - update(); - emit leftPaddingChanged(); - } -} - -void QQuickPaddedRectangle::setRightPadding(qreal padding, bool has) -{ - qreal oldPadding = rightPadding(); - m_hasRightPadding = has; - m_rightPadding = padding; - if (!qFuzzyCompare(oldPadding, padding)) { - update(); - emit rightPaddingChanged(); - } -} - -void QQuickPaddedRectangle::setBottomPadding(qreal padding, bool has) -{ - qreal oldPadding = bottomPadding(); - m_hasBottomPadding = has; - m_bottomPadding = padding; - if (!qFuzzyCompare(oldPadding, padding)) { - update(); - emit bottomPaddingChanged(); - } -} - -QSGNode *QQuickPaddedRectangle::updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) -{ - QSGTransformNode *transformNode = static_cast(node); - if (!transformNode) - transformNode = new QSGTransformNode; - - QSGInternalRectangleNode *rectNode = static_cast(QQuickRectangle::updatePaintNode(transformNode->firstChild(), data)); - - if (rectNode) { - if (!transformNode->firstChild()) - transformNode->appendChildNode(rectNode); - - qreal top = topPadding(); - qreal left = leftPadding(); - qreal right = rightPadding(); - qreal bottom = bottomPadding(); - - if (!qFuzzyIsNull(top) || !qFuzzyIsNull(left) || !qFuzzyIsNull(right) || !qFuzzyIsNull(bottom)) { - QMatrix4x4 m; - m.translate(left, top); - transformNode->setMatrix(m); - - qreal w = qMax(0.0, width() -left-right); - qreal h = qMax(0.0, height() -top-bottom); - - rectNode->setRect(QRectF(0, 0, w, h)); - rectNode->update(); - } - } - return transformNode; -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickpaddedrectangle_p.h b/src/quickcontrols2/qquickpaddedrectangle_p.h deleted file mode 100644 index c2e0ddef..00000000 --- a/src/quickcontrols2/qquickpaddedrectangle_p.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKPADDEDRECTANGLE_P_H -#define QQUICKPADDEDRECTANGLE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickPaddedRectangle : public QQuickRectangle -{ - Q_OBJECT - Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged FINAL) - Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged FINAL) - Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged FINAL) - Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged FINAL) - Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged FINAL) - -public: - QQuickPaddedRectangle(QQuickItem *parent = nullptr); - - qreal padding() const; - void setPadding(qreal padding); - void resetPadding(); - - qreal topPadding() const; - void setTopPadding(qreal padding); - void resetTopPadding(); - - qreal leftPadding() const; - void setLeftPadding(qreal padding); - void resetLeftPadding(); - - qreal rightPadding() const; - void setRightPadding(qreal padding); - void resetRightPadding(); - - qreal bottomPadding() const; - void setBottomPadding(qreal padding); - void resetBottomPadding(); - -Q_SIGNALS: - void paddingChanged(); - void topPaddingChanged(); - void leftPaddingChanged(); - void rightPaddingChanged(); - void bottomPaddingChanged(); - -protected: - QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; - -private: - void setTopPadding(qreal padding, bool has); - void setLeftPadding(qreal padding, bool has); - void setRightPadding(qreal padding, bool has); - void setBottomPadding(qreal padding, bool has); - - qreal m_padding = 0; - qreal m_topPadding = 0; - qreal m_leftPadding = 0; - qreal m_rightPadding = 0; - qreal m_bottomPadding = 0; - bool m_hasTopPadding = false; - bool m_hasLeftPadding = false; - bool m_hasRightPadding = false; - bool m_hasBottomPadding = false; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickPaddedRectangle) - -#endif // QQUICKPADDEDRECTANGLE_P_H diff --git a/src/quickcontrols2/qquickplaceholdertext.cpp b/src/quickcontrols2/qquickplaceholdertext.cpp deleted file mode 100644 index 2fe6be07..00000000 --- a/src/quickcontrols2/qquickplaceholdertext.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickplaceholdertext_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QQuickPlaceholderText::QQuickPlaceholderText(QQuickItem *parent) : QQuickText(parent) -{ -} - -void QQuickPlaceholderText::componentComplete() -{ - QQuickText::componentComplete(); - connect(parentItem(), SIGNAL(effectiveHorizontalAlignmentChanged()), this, SLOT(updateAlignment())); - updateAlignment(); -} - -void QQuickPlaceholderText::updateAlignment() -{ - if (QQuickTextInput *input = qobject_cast(parentItem())) { - if (QQuickTextInputPrivate::get(input)->hAlignImplicit) - resetHAlign(); - else - setHAlign(static_cast(input->hAlign())); - } else if (QQuickTextEdit *edit = qobject_cast(parentItem())) { - if (QQuickTextEditPrivate::get(edit)->hAlignImplicit) - resetHAlign(); - else - setHAlign(static_cast(edit->hAlign())); - } else { - resetHAlign(); - } -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickplaceholdertext_p.h b/src/quickcontrols2/qquickplaceholdertext_p.h deleted file mode 100644 index 1e49286c..00000000 --- a/src/quickcontrols2/qquickplaceholdertext_p.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKPLACEHOLDERTEXT_P_H -#define QQUICKPLACEHOLDERTEXT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickPlaceholderText : public QQuickText -{ - Q_OBJECT - -public: - explicit QQuickPlaceholderText(QQuickItem *parent = nullptr); - -protected: - void componentComplete() override; - -private Q_SLOTS: - void updateAlignment(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickPlaceholderText) - -#endif // QQUICKPLACEHOLDERTEXT_P_H diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index 6e1f17b1..836eb2f4 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -378,7 +378,7 @@ QStringList QQuickStylePrivate::stylePaths(bool resolve) paths += envPathList("QT_QUICK_CONTROLS_STYLE_PATH"); // built-in import paths - const QString targetPath = QStringLiteral("QtQuick/Controls.2"); + const QString targetPath = QStringLiteral("QtQuick/Controls"); const QStringList importPaths = defaultImportPathList(); for (const QString &importPath : importPaths) { QDir dir(importPath); @@ -648,7 +648,7 @@ QStringList QQuickStyle::availableStyles() Returns the list of directories where Qt Quick Controls 2 searches for available styles. By default, the list contains paths specified in the \c QT_QUICK_CONTROLS_STYLE_PATH - environment variable, and any existing \c QtQuick/Controls.2 sub-directories in + environment variable, and any existing \c QtQuick/Controls sub-directories in \l QQmlEngine::importPathList(). \sa addStylePath(), availableStyles() diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h index 205a4a11..7c837423 100644 --- a/src/quickcontrols2/qquickstyle_p.h +++ b/src/quickcontrols2/qquickstyle_p.h @@ -50,13 +50,13 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE class QSettings; -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePrivate +class Q_QUICKCONTROLS2_EXPORT QQuickStylePrivate { public: static QStringList stylePaths(bool resolve = false); diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp index b387b378..18f0d485 100644 --- a/src/quickcontrols2/qquickstyleplugin.cpp +++ b/src/quickcontrols2/qquickstyleplugin.cpp @@ -34,9 +34,8 @@ ** ****************************************************************************/ -#include "qquickstyleplugin_p.h" -#include "qquickstyle.h" #include "qquickstyle_p.h" +#include "qquickstyleplugin_p.h" #include #include diff --git a/src/quickcontrols2/qquickstyleplugin_p.h b/src/quickcontrols2/qquickstyleplugin_p.h index f5c5705c..7ae129d9 100644 --- a/src/quickcontrols2/qquickstyleplugin_p.h +++ b/src/quickcontrols2/qquickstyleplugin_p.h @@ -49,13 +49,13 @@ // #include -#include +#include QT_BEGIN_NAMESPACE class QQuickTheme; -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePlugin : public QQmlExtensionPlugin +class Q_QUICKCONTROLS2_EXPORT QQuickStylePlugin : public QQmlExtensionPlugin { Q_OBJECT diff --git a/src/quickcontrols2/qquicktumblerview.cpp b/src/quickcontrols2/qquicktumblerview.cpp deleted file mode 100644 index 911e2ae8..00000000 --- a/src/quickcontrols2/qquicktumblerview.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquicktumblerview_p.h" - -#include -#include -#include -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcTumblerView, "qt.quick.controls.tumblerview") - -QQuickTumblerView::QQuickTumblerView(QQuickItem *parent) : - QQuickItem(parent) -{ - // We don't call createView() here because we don't know what the wrap flag is set to - // yet, and we don't want to create a view that might never get used. -} - -QVariant QQuickTumblerView::model() const -{ - return m_model; -} - -void QQuickTumblerView::setModel(const QVariant &model) -{ - qCDebug(lcTumblerView) << "setting model to:" << model << "on" - << (m_pathView ? static_cast(m_pathView) : static_cast(m_listView)); - if (model == m_model) - return; - - m_model = model; - - if (m_pathView) { - m_pathView->setModel(m_model); - } else if (m_listView) { - // QQuickItemView::setModel() resets the current index, - // but if we're still creating the Tumbler, it should be maintained. - const int oldCurrentIndex = m_listView->currentIndex(); - m_listView->setModel(m_model); - if (!isComponentComplete()) - m_listView->setCurrentIndex(oldCurrentIndex); - } - - emit modelChanged(); -} - -QQmlComponent *QQuickTumblerView::delegate() const -{ - return m_delegate; -} - -void QQuickTumblerView::setDelegate(QQmlComponent *delegate) -{ - qCDebug(lcTumblerView) << "setting delegate to:" << delegate << "on" - << (m_pathView ? static_cast(m_pathView) : static_cast(m_listView)); - if (delegate == m_delegate) - return; - - m_delegate = delegate; - - if (m_pathView) - m_pathView->setDelegate(m_delegate); - else if (m_listView) - m_listView->setDelegate(m_delegate); - - emit delegateChanged(); -} - -QQuickPath *QQuickTumblerView::path() const -{ - return m_path; -} - -void QQuickTumblerView::setPath(QQuickPath *path) -{ - if (path == m_path) - return; - - m_path = path; - emit pathChanged(); -} - -void QQuickTumblerView::createView() -{ - Q_ASSERT(m_tumbler); - - // We create a view regardless of whether or not we know - // the count yet, because we rely on the view to tell us the count. - if (m_tumbler->wrap()) { - if (m_listView) { - // It's necessary to call deleteLater() rather than delete, - // as this code is most likely being run in rensponse to a signal - // emission somewhere in the list view's internals, so we need to - // wait until that has finished. - m_listView->deleteLater(); - QQml_setParent_noEvent(m_listView, nullptr); - // The auto tests pass with unparenting the list view alone, but - // just to be sure, we unset some other things as well. - m_listView->setParentItem(nullptr); - m_listView->setVisible(false); - m_listView->setModel(QVariant()); - m_listView = nullptr; - } - - if (!m_pathView) { - qCDebug(lcTumblerView) << "creating PathView"; - - m_pathView = new QQuickPathView; - QQmlEngine::setContextForObject(m_pathView, qmlContext(this)); - QQml_setParent_noEvent(m_pathView, this); - m_pathView->setParentItem(this); - m_pathView->setPath(m_path); - m_pathView->setDelegate(m_delegate); - m_pathView->setPreferredHighlightBegin(0.5); - m_pathView->setPreferredHighlightEnd(0.5); - m_pathView->setHighlightMoveDuration(1000); - m_pathView->setClip(true); - - // Give the view a size. - updateView(); - // Set the model. - updateModel(); - - qCDebug(lcTumblerView) << "finished creating PathView"; - } - } else { - if (m_pathView) { - m_pathView->deleteLater(); - QQml_setParent_noEvent(m_pathView, nullptr); - m_pathView->setParentItem(nullptr); - m_pathView->setVisible(false); - m_pathView->setModel(QVariant()); - m_pathView = nullptr; - } - - if (!m_listView) { - qCDebug(lcTumblerView) << "creating ListView"; - - m_listView = new QQuickListView; - QQmlEngine::setContextForObject(m_listView, qmlContext(this)); - QQml_setParent_noEvent(m_listView, this); - m_listView->setParentItem(this); - m_listView->setSnapMode(QQuickListView::SnapToItem); - m_listView->setClip(true); - - // Give the view a size. - updateView(); - // Set the model. - updateModel(); - - // Set these after the model is set so that the currentItem animation - // happens instantly on startup/after switching models. If we set them too early, - // the view animates any potential currentIndex change over one second, - // which we don't want when the contentItem has just been created. - m_listView->setDelegate(m_delegate); - // Set this after setting the delegate to avoid unexpected currentIndex changes: QTBUG-79150 - m_listView->setHighlightRangeMode(QQuickListView::StrictlyEnforceRange); - m_listView->setHighlightMoveDuration(1000); - - qCDebug(lcTumblerView) << "finished creating ListView"; - } - } -} - -// Called whenever the size or visibleItemCount changes. -void QQuickTumblerView::updateView() -{ - QQuickItem *theView = view(); - if (!theView) - return; - - theView->setSize(QSizeF(width(), height())); - - // Can be called in geometryChange when it might not have a parent item yet. - if (!m_tumbler) - return; - - // Set view-specific properties that have a dependency on the size, etc. - if (m_pathView) { - m_pathView->setPathItemCount(m_tumbler->visibleItemCount() + 1); - m_pathView->setDragMargin(width() / 2); - } else { - m_listView->setPreferredHighlightBegin(height() / 2 - (height() / m_tumbler->visibleItemCount() / 2)); - m_listView->setPreferredHighlightEnd(height() / 2 + (height() / m_tumbler->visibleItemCount() / 2)); - } -} - -void QQuickTumblerView::updateModel() -{ - if (m_pathView && !m_pathView->model().isValid() && m_model.isValid()) { - // QQuickPathView::setPathItemCount() resets the offset animation, - // so we just skip the animation while constructing the view. - const int oldHighlightMoveDuration = m_pathView->highlightMoveDuration(); - m_pathView->setHighlightMoveDuration(0); - - // Setting model can change the count, which can affect the wrap, which can cause - // the current view to be deleted before setModel() is finished, which causes a crash. - // Since QQuickTumbler can't know about QQuickTumblerView, we use its private API to - // inform it that it should delay setting wrap. - QQuickTumblerPrivate *tumblerPrivate = QQuickTumblerPrivate::get(m_tumbler); - tumblerPrivate->beginSetModel(); - m_pathView->setModel(m_model); - tumblerPrivate->endSetModel(); - - // The count-depends-on-wrap behavior could cause wrap to change after - // the call above, so we must check that we're still using a PathView. - if (m_pathView) - m_pathView->setHighlightMoveDuration(oldHighlightMoveDuration); - } else if (m_listView && !m_listView->model().isValid() && m_model.isValid()) { - const int currentIndex = m_tumbler->currentIndex(); - QQuickTumblerPrivate *tumblerPrivate = QQuickTumblerPrivate::get(m_tumbler); - - // setModel() causes QQuickTumblerPrivate::_q_onViewCountChanged() to - // be called, which calls QQuickTumbler::setCurrentIndex(), - // which results in QQuickItemViewPrivate::createHighlightItem() being - // called. When the highlight item is created, - // QQuickTumblerPrivate::itemChildAdded() is notified and - // QQuickTumblerPrivate::_q_updateItemHeights() is called, which causes - // a geometry change in the item and createHighlight() is called again. - // However, since the highlight item hadn't been assigned yet in the - // previous call frame, the "if (highlight) { delete highlight; }" - // check doesn't succeed, so the item is never deleted. - // - // To avoid this, we tell QQuickTumblerPrivate to ignore signals while - // setting the model, and manually call _q_onViewCountChanged() to - // ensure the correct sequence of calls happens (_q_onViewCountChanged() - // has to be within the ignoreSignals scope, because it also generates - // recursion otherwise). - tumblerPrivate->ignoreSignals = true; - m_listView->setModel(m_model); - m_listView->setCurrentIndex(currentIndex); - - tumblerPrivate->_q_onViewCountChanged(); - tumblerPrivate->ignoreSignals = false; - } -} - -void QQuickTumblerView::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - QQuickItem::geometryChange(newGeometry, oldGeometry); - updateView(); -} - -void QQuickTumblerView::componentComplete() -{ - QQuickItem::componentComplete(); - updateView(); -} - -void QQuickTumblerView::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) -{ - QQuickItem::itemChange(change, data); - - if (change == QQuickItem::ItemParentHasChanged && data.item) { - if (m_tumbler) - m_tumbler->disconnect(this); - - m_tumbler = qobject_cast(parentItem()); - - if (m_tumbler) { - // We assume that the parentChanged() signal of the tumbler will be emitted before its wrap property is set... - connect(m_tumbler, &QQuickTumbler::wrapChanged, this, &QQuickTumblerView::createView); - connect(m_tumbler, &QQuickTumbler::visibleItemCountChanged, this, &QQuickTumblerView::updateView); - } - } -} - -QQuickItem *QQuickTumblerView::view() -{ - if (!m_tumbler) - return nullptr; - - if (m_tumbler->wrap()) - return m_pathView; - - return m_listView; -} - -QT_END_NAMESPACE - -#include "moc_qquicktumblerview_p.cpp" diff --git a/src/quickcontrols2/qquicktumblerview_p.h b/src/quickcontrols2/qquicktumblerview_p.h deleted file mode 100644 index 4e67e69b..00000000 --- a/src/quickcontrols2/qquicktumblerview_p.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKTUMBLERVIEW_P_H -#define QQUICKTUMBLERVIEW_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickListView; -class QQuickPath; -class QQuickPathView; - -class QQuickTumbler; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickTumblerView : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) - Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) - Q_PROPERTY(QQuickPath *path READ path WRITE setPath NOTIFY pathChanged) - -public: - QQuickTumblerView(QQuickItem *parent = nullptr); - - QVariant model() const; - void setModel(const QVariant &model); - - QQmlComponent *delegate() const; - void setDelegate(QQmlComponent *delegate); - - QQuickPath *path() const; - void setPath(QQuickPath *path); - -Q_SIGNALS: - void modelChanged(); - void delegateChanged(); - void pathChanged(); - -protected: - void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; - void componentComplete() override; - void itemChange(ItemChange change, const ItemChangeData &data) override; - -private: - QQuickItem *view(); - void createView(); - void updateView(); - void updateModel(); - - void wrapChange(); - - QQuickTumbler *m_tumbler = nullptr; - QVariant m_model; - QQmlComponent *m_delegate = nullptr; - QQuickPathView *m_pathView = nullptr; - QQuickListView *m_listView = nullptr; - QQuickPath *m_path = nullptr; -}; - -QT_END_NAMESPACE - -#endif // TUMBLERVIEW_H diff --git a/src/quickcontrols2/qtquickcontrols2global_p.h b/src/quickcontrols2/qtquickcontrols2global_p.h deleted file mode 100644 index 7a54849e..00000000 --- a/src/quickcontrols2/qtquickcontrols2global_p.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTQUICKCONTROLS2GLOBAL_P_H -#define QTQUICKCONTROLS2GLOBAL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -#define Q_QUICKCONTROLS2_PRIVATE_EXPORT Q_QUICKCONTROLS2_EXPORT - -#endif // QTQUICKCONTROLS2GLOBAL_P_H diff --git a/src/quickcontrols2/quickcontrols2.pri b/src/quickcontrols2/quickcontrols2.pri deleted file mode 100644 index 2c28038f..00000000 --- a/src/quickcontrols2/quickcontrols2.pri +++ /dev/null @@ -1,41 +0,0 @@ -HEADERS += \ - $$PWD/qquickanimatednode_p.h \ - $$PWD/qquickattachedobject_p.h \ - $$PWD/qquickchecklabel_p.h \ - $$PWD/qquickclippedtext_p.h \ - $$PWD/qquickcolor_p.h \ - $$PWD/qquickcolorimage_p.h \ - $$PWD/qquickiconimage_p.h \ - $$PWD/qquickiconimage_p_p.h \ - $$PWD/qquickiconlabel_p.h \ - $$PWD/qquickiconlabel_p_p.h \ - $$PWD/qquickitemgroup_p.h \ - $$PWD/qquickmnemoniclabel_p.h \ - $$PWD/qquickpaddedrectangle_p.h \ - $$PWD/qquickplaceholdertext_p.h \ - $$PWD/qquickstyle.h \ - $$PWD/qquickstyle_p.h \ - $$PWD/qquickstyleplugin_p.h - -SOURCES += \ - $$PWD/qquickanimatednode.cpp \ - $$PWD/qquickattachedobject.cpp \ - $$PWD/qquickchecklabel.cpp \ - $$PWD/qquickclippedtext.cpp \ - $$PWD/qquickcolor.cpp \ - $$PWD/qquickcolorimage.cpp \ - $$PWD/qquickiconimage.cpp \ - $$PWD/qquickiconlabel.cpp \ - $$PWD/qquickitemgroup.cpp \ - $$PWD/qquickmnemoniclabel.cpp \ - $$PWD/qquickpaddedrectangle.cpp \ - $$PWD/qquickplaceholdertext.cpp \ - $$PWD/qquickstyle.cpp \ - $$PWD/qquickstyleplugin.cpp - -qtConfig(quick-listview):qtConfig(quick-pathview) { - HEADERS += \ - $$PWD/qquicktumblerview_p.h - SOURCES += \ - $$PWD/qquicktumblerview.cpp -} diff --git a/src/quickcontrols2/quickcontrols2.pro b/src/quickcontrols2/quickcontrols2.pro index 5a11dcd2..8c2f9cba 100644 --- a/src/quickcontrols2/quickcontrols2.pro +++ b/src/quickcontrols2/quickcontrols2.pro @@ -8,12 +8,16 @@ DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII HEADERS += \ $$PWD/qtquickcontrols2global.h \ - $$PWD/qtquickcontrols2global_p.h + $$PWD/qquickstyle.h \ + $$PWD/qquickstyle_p.h \ + $$PWD/qquickstyleplugin_p.h -include(quickcontrols2.pri) +SOURCES += \ + $$PWD/qquickstyle.cpp \ + $$PWD/qquickstyleplugin.cpp QMLTYPES_FILENAME = plugins.qmltypes -QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick/Controls.2 +QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick/Controls QML_IMPORT_NAME = QtQuick.Controls QML_IMPORT_VERSION = 2.15 CONFIG += qmltypes install_qmltypes install_metatypes -- cgit v1.2.3 From 501bc44bb006ee8021cbaaa7a696e7c9263395d3 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 17 Apr 2020 14:32:55 +0200 Subject: Use qmlRegisterModuleImport() to register styles This patch completes the cumulative work done in previous patches. - Uses qmlRegisterModuleImport() to register styles. This has some added requirements: - Each style must now be a QML module -- that is, it must have a qmldir file. - As a result of the above, the module must be available within the QML import path in order to be found. - The various forms of accepted style names have been reduced down to one ("Material", "MyStyle", etc). See below for an explanation of why. - The following API in QQuickStyle is removed: addStylePath(), availableStyles(), path(), stylePathList(). These no longer make sense now that we reuse the existing QML import system. - Adds the tst_qquickstyleselector auto test back as "styleimports". qmlRegisterModuleImport() vs resolvedUrl() Previously we would use QQuickStyleSelector to select individual QML files based on which style was set. We'd do this once when QtQuick.Controls was first imported. With Qt 6, and the requirement that each style be a proper QML module, qmlRegisterModuleImport() was introduced. This allows us to "link" one import with another. For an example of what this looks like in practice, suppose the style was set to "MyStyle", and the fallback to "Material". The "QtQuick.Controls" import will be linked to "MyStyle", "MyStyle" to "QtQuick.Controls.Material", and as a final fallback (for controls like Action which only the Default style implements), "QtQuick.Controls.Material" to "QtQuick.Controls.Default". This is the same behavior as in Qt 5 (see qquickstyleselector.cpp): // 1) requested style (e.g. "MyStyle", included in d->selectors) // 2) fallback style (e.g. "Material", included in d->selectors) // 3) default style (empty selector, not in d->selectors) This is a necessary step to enable compilation of QML to C++. Reducing the set of accepted style names The problem In QtQuickControls2Plugin() we need to call QQuickStylePrivate::init(baseUrl()) in order to detect if the style is a custom style in QQuickStyleSpec::resolve() (by checking if the style path starts with the base URL). In Qt 5, init() is called in QtQuickControls2Plugin::registerTypes(), but in Qt 6 that's too late, because we need to call qmlRegisterModuleImport() in the constructor. qmlRegisterModuleImport() itself requires the style to have already been set in order to create the correct import URI ("QtQuick.Controls.X" for built-in styles, "MyCustomStyle" for custom styles). The solution By reducing the valid forms for style names down to one: ./myapp -style MyStyle we solve the problem of needing baseUrl() to determine if the style is a custom style or not, but needing to call it too early (since we now call qmlRegisterModuleImport() in QtQuickControls2Plugin(), which itself requires the style to have already been set). baseUrl() can't have been set before the constructor is finished. All of the various forms for _setting_ a style are still valid; environment variables, qtquickcontrols2.conf, etc. [ChangeLog][Important Behavior Changes] Custom styles must now have a qmldir that lists the files that the style implements. For example, for a style that only implements Button: --- module MyStyle Button 1.0 Button.qml --- In addition, there is now only one valid, case-sensitive form for style names: "Material", "MyStyle", etc. These changes are done to help enable the compilation of QML code to C++, as well as improve tooling capabilities. [ChangeLog][Important Behavior Changes] The following API was removed: - QQuickStyle::addStylePath() - QQuickStyle::availableStyles() - QQuickStyle::path() - QQuickStyle::stylePathList() - QT_QUICK_CONTROLS_STYLE_PATH This API is no longer necessary and/or able to be provided now that styles are treated as regular QML modules. Task-number: QTBUG-82922 Change-Id: I3b281131903c7c3c1cf0616eb7486a872dccd730 Reviewed-by: Fabian Kosmale --- src/quickcontrols2/qquickstyle.cpp | 350 +++++-------------------------- src/quickcontrols2/qquickstyle.h | 4 - src/quickcontrols2/qquickstyle_p.h | 8 +- src/quickcontrols2/qquickstyleplugin.cpp | 16 ++ src/quickcontrols2/qquickstyleplugin_p.h | 2 +- 5 files changed, 70 insertions(+), 310 deletions(-) (limited to 'src/quickcontrols2') diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index 836eb2f4..72078a0e 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -92,54 +92,23 @@ Q_LOGGING_CATEGORY(lcQtQuickControlsStyle, "qt.quick.controls.style") Qt Quick Controls. It is not possible to change the style after the QML types have been registered. - The style can also be specified as a path to a custom style, such as - \c ":/mystyle". See \l {Creating a Custom Style} for more details about - building custom styles. Custom styles do not need to implement all controls. - By default, the styling system uses the \l {Default style} as a fallback - for controls that a custom style does not provide. It is possible to - specify a different fallback style to customize or extend one of the - built-in styles. + To create your own custom style, see \l {Creating a Custom Style}. Custom + styles do not need to implement all controls. By default, the styling + system uses the \l {Default style} as a fallback for controls that a custom + style does not provide. It is possible to specify a different fallback + style to customize or extend one of the built-in styles. \code - QQuickStyle::setStyle(":/mystyle"); + QQuickStyle::setStyle("MyStyle"); QQuickStyle::setFallbackStyle("Material"); \endcode \sa {Styling Qt Quick Controls} */ -static QStringList envPathList(const QByteArray &var) -{ - QStringList paths; - if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty(var))) { - const QByteArray value = qgetenv(var); - paths += QString::fromLocal8Bit(value).split(QDir::listSeparator(), Qt::SkipEmptyParts); - } - return paths; -} - -static QStringList defaultImportPathList() -{ - QStringList importPaths; - importPaths.reserve(3); -#ifdef Q_OS_ANDROID - // androiddeployqt puts the QML files inside a resource file and they are not - // showing up in the Qml2ImportsPath as a result - importPaths += QStringLiteral(":/android_rcc_bundle/qml"); -#else -# ifndef QT_STATIC - importPaths += QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath); -# endif -#endif - importPaths += envPathList("QML2_IMPORT_PATH"); - importPaths += QStringLiteral(":/qt-project.org/imports"); - importPaths += QCoreApplication::applicationDirPath(); - return importPaths; -} - struct QQuickStyleSpec { - QQuickStyleSpec() : custom(false), resolved(false) { } + QQuickStyleSpec() { } QString name() { @@ -160,6 +129,13 @@ struct QQuickStyleSpec void setStyle(const QString &s) { + qCDebug(lcQtQuickControlsStyle) << "style" << s << "set on QQuickStyleSpec"; + if (s.contains(QLatin1Char('/'))) { + qWarning() << "Style names must not contain paths; see the \"Definition of a Style\" documentation for more information"; + return; + } + + qCDebug(lcQtQuickControlsStyle) << "clearing resolved flag and resolving"; style = s; resolved = false; resolve(); @@ -171,27 +147,9 @@ struct QQuickStyleSpec fallbackMethod = method; } - static QString findStyle(const QString &path, const QString &name) + void resolve() { - QDir dir(path); - if (!dir.exists()) - return QString(); - - if (name.isEmpty()) - return dir.absolutePath() + QLatin1Char('/'); - - const QStringList entries = dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot); - for (const QString &entry : entries) { - if (entry.compare(name, Qt::CaseInsensitive) == 0) - return dir.absoluteFilePath(entry); - } - - return QString(); - } - - void resolve(const QUrl &baseUrl = QUrl()) - { - qCDebug(lcQtQuickControlsStyle) << "resolving style with baseUrl" << baseUrl; + qCDebug(lcQtQuickControlsStyle) << "resolving style"; if (style.isEmpty()) style = QGuiApplicationPrivate::styleOverride; @@ -211,53 +169,33 @@ struct QQuickStyleSpec } #endif - // resolve a path relative to the config - QString configPath = QFileInfo(resolveConfigFilePath()).path(); - QString stylePath = findStyle(configPath, style); - if (!stylePath.isEmpty()) { - style = stylePath; - resolved = true; + auto builtInStyleList = QQuickStylePrivate::builtInStyles(); + if (!fallbackStyle.isEmpty() && !builtInStyleList.contains(fallbackStyle)) { + qWarning().nospace().noquote() << fallbackMethod << ": the specified fallback style \"" << + fallbackStyle << "\" is not one of the built-in Qt Quick Controls 2 styles"; + fallbackStyle.clear(); } - custom = style.contains(QLatin1Char('/')); + // Find the config file. + resolveConfigFilePath(); - if (baseUrl.isValid()) { - QString path = QQmlFile::urlToLocalFileOrQrc(baseUrl); - QString stylePath = findStyle(path, style); - if (!stylePath.isEmpty()) { - style = stylePath; - resolved = true; - } - } + custom = !builtInStyleList.contains(QQuickStylePrivate::effectiveStyleName(style)); - if (QGuiApplication::instance()) { - if (!custom) { - const QStringList stylePaths = QQuickStylePrivate::stylePaths(); - for (const QString &path : stylePaths) { - QString stylePath = findStyle(path, style); - if (!stylePath.isEmpty()) { - custom = !stylePath.startsWith(QQmlFile::urlToLocalFileOrQrc(baseUrl)); - style = stylePath; - resolved = true; - break; - } - } - } - resolved = true; - } + resolved = true; qCDebug(lcQtQuickControlsStyle).nospace() << "done resolving:" + << "\n style=" << style << "\n custom=" << custom << "\n resolved=" << resolved - << "\n style=" << style << "\n fallbackStyle=" << fallbackStyle << "\n fallbackMethod=" << fallbackMethod - << "\n configFilePath=" << configFilePath - << "\n customStylePaths=" << customStylePaths; + << "\n configFilePath=" << configFilePath; } void reset() { + qCDebug(lcQtQuickControlsStyle) << "resetting values to their defaults"; + custom = false; resolved = false; style.clear(); @@ -281,10 +219,10 @@ struct QQuickStyleSpec } // Is this a custom style defined by the user and not "built-in" style? - bool custom; - // Did we manage to find a valid style path? - bool resolved; - // The full path to the style. + bool custom = false; + // Have we resolved the style yet? + bool resolved = false; + // The name of the style. QString style; // The built-in style to use if the requested style cannot be found. QString fallbackStyle; @@ -292,102 +230,13 @@ struct QQuickStyleSpec QByteArray fallbackMethod; // The path to the qtquickcontrols2.conf file. QString configFilePath; - // An extra list of directories where we search for available styles before any other directories. - QStringList customStylePaths; }; Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec) -static QStringList parseStylePathsWithColon(const QString &var) +QString QQuickStylePrivate::effectiveStyleName(const QString &styleName) { - QStringList paths; - const QChar colon = QLatin1Char(':'); - int currentIndex = 0; - - do { - int nextColonIndex = -1; - QString path; - - if (var.at(currentIndex) == colon) { - // This is either a list separator, or a qrc path. - if (var.at(currentIndex + 1) == colon) { - // It's a double colon (list separator followed by qrc path); - // find the end of the path. - nextColonIndex = var.indexOf(colon, currentIndex + 2); - path = var.mid(currentIndex + 1, - nextColonIndex == -1 ? -1 : nextColonIndex - currentIndex - 1); - } else { - // It's a single colon. - nextColonIndex = var.indexOf(colon, currentIndex + 1); - if (currentIndex == 0) { - // If we're at the start of the string, then it's a qrc path. - path = var.mid(currentIndex, - nextColonIndex == -1 ? -1 : nextColonIndex - currentIndex); - } else { - // Otherwise, it's a separator. - path = var.mid(currentIndex + 1, - nextColonIndex == -1 ? -1 : nextColonIndex - currentIndex - 1); - } - } - } else { - // It's a file path. - nextColonIndex = var.indexOf(colon, currentIndex); - path = var.mid(currentIndex, - nextColonIndex == -1 ? -1 : nextColonIndex - currentIndex); - } - - paths += path; - currentIndex = nextColonIndex; - - // Keep going until we can't find any more colons, - // or we're at the last character. - } while (currentIndex != -1 && currentIndex < var.size() - 1); - - return paths; -} - -QStringList QQuickStylePrivate::stylePaths(bool resolve) -{ - // user-requested style path - QStringList paths; - if (resolve) { - QString path = styleSpec()->path(); - if (path.endsWith(QLatin1Char('/'))) - path.chop(1); - if (!path.isEmpty()) - paths += path; - } - - if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE_PATH"))) { - const QString value = QString::fromLocal8Bit(qgetenv("QT_QUICK_CONTROLS_STYLE_PATH")); - const QChar listSeparator = QDir::listSeparator(); - if (listSeparator == QLatin1Char(':')) { - // Split manually to avoid breaking paths on systems where : is the list separator, - // since it's also used for qrc paths. - paths += parseStylePathsWithColon(value); - } else { - // Fast/simpler path for systems where something other than : is used as - // the list separator (such as ';'). - const QStringList customPaths = value.split(listSeparator, Qt::SkipEmptyParts); - paths += customPaths; - } - } - - // system/custom style paths - paths += styleSpec()->customStylePaths; - paths += envPathList("QT_QUICK_CONTROLS_STYLE_PATH"); - - // built-in import paths - const QString targetPath = QStringLiteral("QtQuick/Controls"); - const QStringList importPaths = defaultImportPathList(); - for (const QString &importPath : importPaths) { - QDir dir(importPath); - if (dir.cd(targetPath)) - paths += dir.absolutePath(); - } - - paths.removeDuplicates(); - return paths; + return !styleName.isEmpty() ? styleName : QLatin1String("Default"); } QString QQuickStylePrivate::fallbackStyle() @@ -400,27 +249,15 @@ bool QQuickStylePrivate::isCustomStyle() return styleSpec()->custom; } -void QQuickStylePrivate::init(const QUrl &baseUrl) +bool QQuickStylePrivate::isResolved() +{ + return styleSpec()->resolved; +} + +void QQuickStylePrivate::init() { QQuickStyleSpec *spec = styleSpec(); - spec->resolve(baseUrl); - - if (!spec->fallbackStyle.isEmpty()) { - QString fallbackStyle; - const QStringList stylePaths = QQuickStylePrivate::stylePaths(); - for (const QString &path : stylePaths) { - fallbackStyle = spec->findStyle(path, spec->fallbackStyle); - if (!fallbackStyle.isEmpty()) - break; - } - if (fallbackStyle.isEmpty()) { - if (spec->fallbackStyle.compare(QStringLiteral("Default")) != 0) { - qWarning() << "ERROR: unable to locate fallback style" << spec->fallbackStyle; - qInfo().nospace().noquote() << spec->fallbackMethod << ": the fallback style must be the name of one of the built-in Qt Quick Controls 2 styles."; - } - spec->fallbackStyle.clear(); - } - } + spec->resolve(); } void QQuickStylePrivate::reset() @@ -541,6 +378,12 @@ bool QQuickStylePrivate::isDarkSystemTheme() return dark; } +QStringList QQuickStylePrivate::builtInStyles() +{ + return { QLatin1String("Default"), QLatin1String("Fusion"), + QLatin1String("Imagine"), QLatin1String("Material"), QLatin1String("Universal") }; +} + /*! Returns the name of the application style. @@ -553,19 +396,6 @@ QString QQuickStyle::name() return styleSpec()->name(); } -/*! - Returns the path of an overridden application style, or an empty - string if the style is one of the built-in Qt Quick Controls 2 styles. - - \note The application style can be specified by passing a \c -style command - line argument. Therefore \c path() may not return a fully resolved - value if called before constructing a QGuiApplication. -*/ -QString QQuickStyle::path() -{ - return styleSpec()->path(); -} - /*! Sets the application style to \a style. @@ -612,88 +442,4 @@ void QQuickStyle::setFallbackStyle(const QString &style) styleSpec()->setFallbackStyle(style, "QQuickStyle::setFallbackStyle()"); } -/*! - \since 5.9 - Returns the names of the available styles. - - \note The method must be called \b after creating an instance of QGuiApplication. - - \sa stylePathList(), addStylePath() -*/ -QStringList QQuickStyle::availableStyles() -{ - QStringList styles; - if (!QGuiApplication::instance()) { - qWarning() << "ERROR: QQuickStyle::availableStyles() must be called after creating an instance of QGuiApplication."; - return styles; - } - - const QStringList stylePaths = QQuickStylePrivate::stylePaths(); - for (const QString &path : stylePaths) { - const QList entries = QDir(path).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); - for (const QFileInfo &entry : entries) { - const QString name = entry.fileName(); - if (!name.endsWith(QLatin1String(".dSYM")) && name != QLatin1String("designer")) - styles += name; - } - } - styles.prepend(QStringLiteral("Default")); - styles.removeDuplicates(); - return styles; -} - -/*! - \since 5.12 - - Returns the list of directories where Qt Quick Controls 2 searches for available styles. - - By default, the list contains paths specified in the \c QT_QUICK_CONTROLS_STYLE_PATH - environment variable, and any existing \c QtQuick/Controls sub-directories in - \l QQmlEngine::importPathList(). - - \sa addStylePath(), availableStyles() -*/ -QStringList QQuickStyle::stylePathList() -{ - return QQuickStylePrivate::stylePaths(); -} - -/*! - \since 5.12 - - Adds \a path as a directory where Qt Quick Controls 2 searches for available styles. - - The \a path may be any local filesystem directory or \l {The Qt Resource System}{Qt Resource} directory. - For example, the following paths are all valid: - - \list - \li \c {/path/to/styles/} - \li \c {file:///path/to/styles/} - \li \c {:/path/to/styles/} - \li \c {qrc:/path/to/styles/}) - \endlist - - The \a path will be converted into \l {QDir::canonicalPath}{canonical form} before it is added to - the style path list. - - The newly added \a path will be first in the stylePathList(). - - \sa stylePathList(), availableStyles() -*/ -void QQuickStyle::addStylePath(const QString &path) -{ - if (path.isEmpty()) - return; - - const QUrl url = QUrl(path); - if (url.isRelative() || url.scheme() == QLatin1String("file") - || (url.scheme().length() == 1 && QFile::exists(path)) ) { // windows path - styleSpec()->customStylePaths.prepend(QDir(path).canonicalPath()); - } else if (url.scheme() == QLatin1String("qrc")) { - styleSpec()->customStylePaths.prepend(QLatin1Char(':') + url.path()); - } else { - styleSpec()->customStylePaths.prepend(path); - } -} - QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyle.h b/src/quickcontrols2/qquickstyle.h index ce55b76b..e26ec90b 100644 --- a/src/quickcontrols2/qquickstyle.h +++ b/src/quickcontrols2/qquickstyle.h @@ -47,12 +47,8 @@ class Q_QUICKCONTROLS2_EXPORT QQuickStyle { public: static QString name(); - static QString path(); static void setStyle(const QString &style); static void setFallbackStyle(const QString &style); - static QStringList availableStyles(); - static QStringList stylePathList(); - static void addStylePath(const QString &path); }; QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h index 7c837423..e2db35d7 100644 --- a/src/quickcontrols2/qquickstyle_p.h +++ b/src/quickcontrols2/qquickstyle_p.h @@ -48,7 +48,6 @@ // We mean it. // -#include #include #include @@ -59,16 +58,19 @@ class QSettings; class Q_QUICKCONTROLS2_EXPORT QQuickStylePrivate { public: - static QStringList stylePaths(bool resolve = false); + static QString effectiveStyleName(const QString &styleName); static QString fallbackStyle(); static bool isCustomStyle(); - static void init(const QUrl &baseUrl); + static bool isResolved(); + static bool exists(); + static void init(); static void reset(); static QString configFilePath(); static QSharedPointer settings(const QString &group = QString()); static const QFont *readFont(const QSharedPointer &settings); static const QPalette *readPalette(const QSharedPointer &settings); static bool isDarkSystemTheme(); + static QStringList builtInStyles(); }; QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp index 18f0d485..1f1c3875 100644 --- a/src/quickcontrols2/qquickstyleplugin.cpp +++ b/src/quickcontrols2/qquickstyleplugin.cpp @@ -34,14 +34,20 @@ ** ****************************************************************************/ +#include "qquickstyle.h" #include "qquickstyle_p.h" #include "qquickstyleplugin_p.h" +#include #include #include +#include + QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(lcStylePlugin, "qt.quick.controls.styleplugin") + QQuickStylePlugin::QQuickStylePlugin(QObject *parent) : QQmlExtensionPlugin(parent) { @@ -56,4 +62,14 @@ QString QQuickStylePlugin::name() const return QString(); } +void QQuickStylePlugin::registerTypes(const char *uri) +{ + qCDebug(lcStylePlugin).nospace() << "registerTypes called with uri " << uri << "; plugin name is " << name(); +} + +void QQuickStylePlugin::unregisterTypes() +{ + qCDebug(lcStylePlugin) << "unregisterTypes called; plugin name is" << name(); +} + QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleplugin_p.h b/src/quickcontrols2/qquickstyleplugin_p.h index 7ae129d9..37d070db 100644 --- a/src/quickcontrols2/qquickstyleplugin_p.h +++ b/src/quickcontrols2/qquickstyleplugin_p.h @@ -64,9 +64,9 @@ public: ~QQuickStylePlugin(); virtual QString name() const; - virtual void initializeTheme(QQuickTheme *theme) = 0; void registerTypes(const char *uri) override; + void unregisterTypes() override; private: Q_DISABLE_COPY(QQuickStylePlugin) -- cgit v1.2.3 From 9824a71f1d1754485072d66fbac2c98854ace52a Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 15 Jul 2020 14:52:09 +0200 Subject: Bump import version to 6.0 Task-number: QTBUG-82922 Change-Id: I2eb924eaaaddbe75d342f59f5fb3cd30c4a84fef Reviewed-by: Ulf Hermann --- src/quickcontrols2/quickcontrols2.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/quickcontrols2') diff --git a/src/quickcontrols2/quickcontrols2.pro b/src/quickcontrols2/quickcontrols2.pro index 8c2f9cba..686eed7b 100644 --- a/src/quickcontrols2/quickcontrols2.pro +++ b/src/quickcontrols2/quickcontrols2.pro @@ -19,7 +19,7 @@ SOURCES += \ QMLTYPES_FILENAME = plugins.qmltypes QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick/Controls QML_IMPORT_NAME = QtQuick.Controls -QML_IMPORT_VERSION = 2.15 +QML_IMPORT_VERSION = $$QT_VERSION CONFIG += qmltypes install_qmltypes install_metatypes load(qt_module) -- cgit v1.2.3 From b47e26d29db05ecf87f74815e37e0bf7394d06ba Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 10 Aug 2020 16:25:26 +0200 Subject: Register QQuickDummyType as anonymous type This way we get to declare a QML_ADDED_IN_VERSION. This is necessary for version 2.x of the module to be found when version 6.x is registered. Task-number: QTBUG-85151 Change-Id: Ia156763ffa2ecc6a35f0421c68df85fba646cec7 Reviewed-by: Ulf Hermann --- src/quickcontrols2/qquickdummyregistration_p.h | 67 ++++++++++++++++++++++++++ src/quickcontrols2/quickcontrols2.pro | 1 + 2 files changed, 68 insertions(+) create mode 100644 src/quickcontrols2/qquickdummyregistration_p.h (limited to 'src/quickcontrols2') diff --git a/src/quickcontrols2/qquickdummyregistration_p.h b/src/quickcontrols2/qquickdummyregistration_p.h new file mode 100644 index 00000000..4d7fe5e4 --- /dev/null +++ b/src/quickcontrols2/qquickdummyregistration_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKDUMMYREGISTRATION_H +#define QQUICKDUMMYREGISTRATION_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_NAMESPACE + +// QtQuick.Controls has no types, so if we didn't have this dummy type, +// we'd have no way of specifying the version when the module was added, +// and 6.0 would be the only version that gets registered: QTBUG-85151 +struct QQuickDummyType +{ + Q_GADGET + QML_ANONYMOUS + QML_ADDED_IN_VERSION(2, 0) +}; + +QT_END_NAMESPACE + +#endif // QQUICKDUMMYREGISTRATION_H diff --git a/src/quickcontrols2/quickcontrols2.pro b/src/quickcontrols2/quickcontrols2.pro index 686eed7b..5383f8d8 100644 --- a/src/quickcontrols2/quickcontrols2.pro +++ b/src/quickcontrols2/quickcontrols2.pro @@ -8,6 +8,7 @@ DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII HEADERS += \ $$PWD/qtquickcontrols2global.h \ + $$PWD/qquickdummyregistration_p.h \ $$PWD/qquickstyle.h \ $$PWD/qquickstyle_p.h \ $$PWD/qquickstyleplugin_p.h -- cgit v1.2.3 From 80c5d0841e6f7c0c9aedfdc01b5d060ab2f66b7d Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 11 Aug 2020 11:57:24 +0200 Subject: Fix CMake build Task-number: QTBUG-82922 Change-Id: I75f4a553a6bb260f77bfa791f12fa42e80131e09 Reviewed-by: Fabian Kosmale --- src/quickcontrols2/CMakeLists.txt | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'src/quickcontrols2') diff --git a/src/quickcontrols2/CMakeLists.txt b/src/quickcontrols2/CMakeLists.txt index ec954c32..52e39cae 100644 --- a/src/quickcontrols2/CMakeLists.txt +++ b/src/quickcontrols2/CMakeLists.txt @@ -5,26 +5,12 @@ ##################################################################### qt_add_module(QuickControls2 + GENERATE_METATYPES SOURCES - qquickanimatednode.cpp qquickanimatednode_p.h - qquickattachedobject.cpp qquickattachedobject_p.h - qquickchecklabel.cpp qquickchecklabel_p.h - qquickclippedtext.cpp qquickclippedtext_p.h - qquickcolor.cpp qquickcolor_p.h - qquickcolorimage.cpp qquickcolorimage_p.h - qquickiconimage.cpp qquickiconimage_p.h - qquickiconimage_p_p.h - qquickiconlabel.cpp qquickiconlabel_p.h - qquickiconlabel_p_p.h - qquickitemgroup.cpp qquickitemgroup_p.h - qquickmnemoniclabel.cpp qquickmnemoniclabel_p.h - qquickpaddedrectangle.cpp qquickpaddedrectangle_p.h - qquickplaceholdertext.cpp qquickplaceholdertext_p.h + qquickdummyregistration_p.h qquickstyle.cpp qquickstyle.h qquickstyle_p.h qquickstyleplugin.cpp qquickstyleplugin_p.h - qquickstyleselector.cpp qquickstyleselector_p.h - qquickstyleselector_p_p.h - qtquickcontrols2global.h qtquickcontrols2global_p.h + qtquickcontrols2global.h DEFINES QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII @@ -42,11 +28,17 @@ qt_add_module(QuickControls2 #### Keys ignored in scope 1:.:.:quickcontrols2.pro:: # MODULE = "quickcontrols2" +# QMLTYPES_FILENAME = "plugins.qmltypes" +# QMLTYPES_INSTALL_DIR = "$$[QT_INSTALL_QML]/QtQuick/Controls" +# QML_IMPORT_NAME = "QtQuick.Controls" +# QML_IMPORT_VERSION = "$$QT_VERSION" -## Scopes: -##################################################################### - -qt_extend_target(QuickControls2 CONDITION QT_FEATURE_quick_listview AND QT_FEATURE_quick_pathview - SOURCES - qquicktumblerview.cpp qquicktumblerview_p.h +set_target_properties(QuickControls2 PROPERTIES + QT_QML_MODULE_INSTALL_QMLTYPES TRUE + QT_QML_MODULE_VERSION ${CMAKE_PROJECT_VERSION} + QT_QML_MODULE_URI QtQuick.Controls + QT_QMLTYPES_FILENAME plugins.qmltypes + QT_QML_MODULE_INSTALL_DIR "${INSTALL_QMLDIR}/QtQuick/Controls" ) + +qt6_qml_type_registration(QuickControls2) -- cgit v1.2.3