| 1 | // Copyright (C) 2020 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | #ifndef QQUICKPALETTECOLORPROVIDER_P_H |
| 4 | #define QQUICKPALETTECOLORPROVIDER_P_H |
| 5 | |
| 6 | // |
| 7 | // W A R N I N G |
| 8 | // ------------- |
| 9 | // |
| 10 | // This file is not part of the Qt API. It exists purely as an |
| 11 | // implementation detail. This header file may change from version to |
| 12 | // version without notice, or even be removed. |
| 13 | // |
| 14 | // We mean it. |
| 15 | // |
| 16 | |
| 17 | #include <QtGui/QPalette> |
| 18 | |
| 19 | #include <QtQuick/qtquickglobal.h> |
| 20 | |
| 21 | #include <QtQuick/private/qtquickglobal_p.h> |
| 22 | #include <private/qlazilyallocated_p.h> |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QQuickAbstractPaletteProvider; |
| 27 | |
| 28 | class Q_QUICK_EXPORT QQuickPaletteColorProvider |
| 29 | : public std::enable_shared_from_this<QQuickPaletteColorProvider> |
| 30 | { |
| 31 | public: |
| 32 | QQuickPaletteColorProvider(); |
| 33 | |
| 34 | const QColor &color(QPalette::ColorGroup group, QPalette::ColorRole role) const; |
| 35 | bool setColor(QPalette::ColorGroup group, QPalette::ColorRole role, QColor color); |
| 36 | bool resetColor(QPalette::ColorGroup group, QPalette::ColorRole role); |
| 37 | bool resetColor(QPalette::ColorGroup group); |
| 38 | |
| 39 | bool fromQPalette(QPalette p); |
| 40 | QPalette palette() const; |
| 41 | |
| 42 | const QQuickAbstractPaletteProvider *paletteProvider() const; |
| 43 | void setPaletteProvider(const QQuickAbstractPaletteProvider *paletteProvider); |
| 44 | |
| 45 | bool copyColorGroup(QPalette::ColorGroup cg, const QQuickPaletteColorProvider &p); |
| 46 | |
| 47 | bool reset(); |
| 48 | |
| 49 | bool inheritPalette(const QPalette &palette); |
| 50 | |
| 51 | private: |
| 52 | bool doInheritPalette(const QPalette &palette); |
| 53 | bool updateInheritedPalette(); |
| 54 | void ensureRequestedPalette(); |
| 55 | |
| 56 | QPalette m_resolvedPalette; |
| 57 | QLazilyAllocated<QPalette> m_requestedPalette; |
| 58 | QLazilyAllocated<QPalette> m_lastInheritedPalette; |
| 59 | |
| 60 | using Deleter = std::function<void(const QQuickAbstractPaletteProvider*)>; |
| 61 | using ProviderPtr = std::unique_ptr<const QQuickAbstractPaletteProvider, Deleter>; |
| 62 | ProviderPtr m_paletteProvider; |
| 63 | }; |
| 64 | |
| 65 | QT_END_NAMESPACE |
| 66 | |
| 67 | #endif // QQUICKPALETTECOLORPROVIDER_P_H |
| 68 |
