1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef CONTROLSTESTUTILS_P_H |
5 | #define CONTROLSTESTUTILS_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtGui/qpa/qplatformtheme.h> |
19 | #include <QtQuickTestUtils/private/visualtestutils_p.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QQmlComponent; |
24 | class QQmlEngine; |
25 | class QQuickApplicationWindow; |
26 | class QQuickAbstractButton; |
27 | |
28 | namespace QQuickControlsTestUtils |
29 | { |
30 | class QQuickControlsApplicationHelper : public QQuickVisualTestUtils::QQuickApplicationHelper |
31 | { |
32 | public: |
33 | QQuickControlsApplicationHelper(QQmlDataTest *testCase, const QString &testFilePath, |
34 | const QVariantMap &initialProperties = {}, |
35 | const QStringList &qmlImportPaths = {}); |
36 | |
37 | QQuickApplicationWindow *appWindow = nullptr; |
38 | }; |
39 | |
40 | struct QQuickStyleHelper |
41 | { |
42 | [[nodiscard]] bool updateStyle(const QString &style); |
43 | |
44 | QString currentStyle; |
45 | QScopedPointer<QQmlEngine> engine; |
46 | }; |
47 | |
48 | typedef std::function<void(const QString &/*relativePath*/, const QUrl &/*absoluteUrl*/)> ForEachCallback; |
49 | |
50 | void forEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &sourcePath, |
51 | const QString &targetPath, const QStringList &skipList, ForEachCallback callback); |
52 | void addTestRowForEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &sourcePath, |
53 | const QString &targetPath, const QStringList &skipList = QStringList()); |
54 | |
55 | [[nodiscard]] bool verifyButtonClickable(QQuickAbstractButton *button); |
56 | [[nodiscard]] bool clickButton(QQuickAbstractButton *button); |
57 | [[nodiscard]] bool doubleClickButton(QQuickAbstractButton *button); |
58 | |
59 | class ComponentCreator : public QObject |
60 | { |
61 | Q_OBJECT |
62 | QML_ELEMENT |
63 | QML_SINGLETON |
64 | Q_MOC_INCLUDE(<QtQml/qqmlcomponent.h>) |
65 | |
66 | public: |
67 | Q_INVOKABLE QQmlComponent *createComponent(const QByteArray &data); |
68 | }; |
69 | |
70 | class StyleInfo : public QObject |
71 | { |
72 | Q_OBJECT |
73 | Q_PROPERTY(QString styleName READ styleName CONSTANT FINAL) |
74 | QML_ELEMENT |
75 | QML_SINGLETON |
76 | |
77 | public: |
78 | QString styleName() const; |
79 | }; |
80 | |
81 | class MockPlatformTheme : public QPlatformTheme |
82 | { |
83 | Qt::ColorScheme colorScheme() const override |
84 | { |
85 | return m_colorScheme; |
86 | } |
87 | void requestColorScheme(Qt::ColorScheme theme) override |
88 | { |
89 | m_colorScheme = theme; |
90 | QWindowSystemInterfacePrivate::ThemeChangeEvent tce{nullptr}; |
91 | QGuiApplicationPrivate::processThemeChanged(tce: &tce); |
92 | } |
93 | |
94 | private: |
95 | Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown; |
96 | }; |
97 | } |
98 | |
99 | QT_END_NAMESPACE |
100 | |
101 | #endif // CONTROLSTESTUTILS_P_H |
102 | |