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 | class QQuickControl; |
28 | |
29 | namespace QQuickControlsTestUtils |
30 | { |
31 | class QQuickControlsApplicationHelper : public QQuickVisualTestUtils::QQuickApplicationHelper |
32 | { |
33 | public: |
34 | QQuickControlsApplicationHelper(QQmlDataTest *testCase, const QString &testFilePath, |
35 | const QVariantMap &initialProperties = {}, |
36 | const QStringList &qmlImportPaths = {}); |
37 | |
38 | QQuickApplicationWindow *appWindow = nullptr; |
39 | }; |
40 | |
41 | struct QQuickStyleHelper |
42 | { |
43 | [[nodiscard]] bool updateStyle(const QString &style); |
44 | |
45 | QString currentStyle; |
46 | QScopedPointer<QQmlEngine> engine; |
47 | }; |
48 | |
49 | typedef std::function<void(const QString &/*relativePath*/, const QUrl &/*absoluteUrl*/)> ForEachCallback; |
50 | |
51 | void forEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &sourcePath, |
52 | const QString &targetPath, const QStringList &skipList, ForEachCallback callback); |
53 | void addTestRowForEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &sourcePath, |
54 | const QString &targetPath, const QStringList &skipList = QStringList()); |
55 | |
56 | [[nodiscard]] bool verifyButtonClickable(QQuickAbstractButton *button); |
57 | [[nodiscard]] bool clickButton(QQuickAbstractButton *button); |
58 | [[nodiscard]] bool doubleClickButton(QQuickAbstractButton *button); |
59 | [[nodiscard]] QString visualFocusFailureMessage(QQuickControl *control); |
60 | |
61 | class ComponentCreator : public QObject |
62 | { |
63 | Q_OBJECT |
64 | QML_ELEMENT |
65 | QML_SINGLETON |
66 | Q_MOC_INCLUDE(<QtQml/qqmlcomponent.h>) |
67 | |
68 | public: |
69 | Q_INVOKABLE QQmlComponent *createComponent(const QByteArray &data); |
70 | }; |
71 | |
72 | class StyleInfo : public QObject |
73 | { |
74 | Q_OBJECT |
75 | Q_PROPERTY(QString styleName READ styleName CONSTANT FINAL) |
76 | QML_ELEMENT |
77 | QML_SINGLETON |
78 | |
79 | public: |
80 | QString styleName() const; |
81 | }; |
82 | |
83 | class MockPlatformTheme : public QPlatformTheme |
84 | { |
85 | Qt::ColorScheme colorScheme() const override |
86 | { |
87 | return m_colorScheme; |
88 | } |
89 | void requestColorScheme(Qt::ColorScheme theme) override |
90 | { |
91 | m_colorScheme = theme; |
92 | QWindowSystemInterfacePrivate::ThemeChangeEvent tce{nullptr}; |
93 | QGuiApplicationPrivate::processThemeChanged(tce: &tce); |
94 | } |
95 | |
96 | private: |
97 | Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown; |
98 | }; |
99 | } |
100 | |
101 | #define VERIFY_VISUAL_FOCUS(control) \ |
102 | do { \ |
103 | QVERIFY2(control->hasVisualFocus(), qUtf8Printable(visualFocusFailureMessage(control))); \ |
104 | } while (false) |
105 | |
106 | QT_END_NAMESPACE |
107 | |
108 | #endif // CONTROLSTESTUTILS_P_H |
109 | |