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
24QT_BEGIN_NAMESPACE
25
26class QQuickAbstractPaletteProvider;
27
28class Q_QUICK_PRIVATE_EXPORT QQuickPaletteColorProvider
29 : public std::enable_shared_from_this<QQuickPaletteColorProvider>
30{
31public:
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
38 bool fromQPalette(QPalette p);
39 QPalette palette() const;
40
41 const QQuickAbstractPaletteProvider *paletteProvider() const;
42 void setPaletteProvider(const QQuickAbstractPaletteProvider *paletteProvider);
43
44 bool copyColorGroup(QPalette::ColorGroup cg, const QQuickPaletteColorProvider &p);
45
46 bool reset();
47
48 bool inheritPalette(const QPalette &palette);
49
50private:
51 bool doInheritPalette(const QPalette &palette);
52 bool updateInheritedPalette();
53 void ensureRequestedPalette();
54
55 QPalette m_resolvedPalette;
56 QLazilyAllocated<QPalette> m_requestedPalette;
57 QLazilyAllocated<QPalette> m_lastInheritedPalette;
58
59 using Deleter = std::function<void(const QQuickAbstractPaletteProvider*)>;
60 using ProviderPtr = std::unique_ptr<const QQuickAbstractPaletteProvider, Deleter>;
61 ProviderPtr m_paletteProvider;
62};
63
64QT_END_NAMESPACE
65
66#endif // QQUICKPALETTECOLORPROVIDER_P_H
67

source code of qtdeclarative/src/quick/items/qquickpalettecolorprovider_p.h