1// Copyright (C) 2016 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
4#ifndef QSTYLE_P_H
5#define QSTYLE_P_H
6
7#include "private/qobject_p.h"
8#include <QtWidgets/qstyle.h>
9
10QT_BEGIN_NAMESPACE
11
12//
13// W A R N I N G
14// -------------
15//
16// This file is not part of the Qt API. It exists for the convenience
17// of qstyle_*.cpp. This header file may change from version to version
18// without notice, or even be removed.
19//
20// We mean it.
21//
22
23// Private class
24
25class QStyle;
26
27class QStylePrivate: public QObjectPrivate
28{
29 Q_DECLARE_PUBLIC(QStyle)
30public:
31 static QStylePrivate *get(QStyle *s) { return s ? s->d_func() : nullptr; }
32 static const QStylePrivate *get(const QStyle *s) { return s ? s->d_func() : nullptr; }
33
34 static bool useFullScreenForPopup();
35
36 QStyle *proxyStyle;
37 QString name;
38};
39
40inline QPixmap styleCachePixmap(const QSize &size, qreal pixelRatio)
41{
42 QPixmap cachePixmap = QPixmap(size * pixelRatio);
43 cachePixmap.setDevicePixelRatio(pixelRatio);
44 cachePixmap.fill(fillColor: Qt::transparent);
45 return cachePixmap;
46}
47
48// small helper to read out the pixmap to paint from QPixmapCache or re-draw
49// it and put it into the QPixmapCache for later usage
50class Q_WIDGETS_EXPORT QCachedPainter
51{
52public:
53 QCachedPainter(QPainter *painter, const QString &cachePrefix,
54 const QStyleOption *option, QSize size = {}, QRect paintRect = {});
55 ~QCachedPainter();
56 void finish();
57 bool needsPainting() const
58 {
59 return !m_alreadyCached;
60 }
61 QRect pixmapRect() const
62 {
63 const auto sz = m_pixmap.deviceIndependentSize();
64 return QRect(0, 0, sz.width(), sz.height());
65 }
66 QPainter *operator->()
67 {
68 return painter();
69 }
70 QPainter *painter()
71 {
72 Q_ASSERT_X(m_pixmapPainter, "painter()", "Must only be called when painting on a pixmap to cache");
73 return m_pixmapPainter.get();
74 }
75
76 // clean pixmap cache from all cached pixmaps (e.g. due to palette change)
77 // to make sure the widgets are painted correctly afterwards
78 static void cleanupPixmapCache();
79private:
80 QPainter *m_painter = nullptr;
81 const QStyleOption *m_option = nullptr;
82 std::unique_ptr<QPainter> m_pixmapPainter;
83 QString m_pixmapName;
84 QPixmap m_pixmap;
85 QRect m_paintRect;
86 bool m_alreadyCached;
87 bool m_pixmapDrawn = false;
88 static QSet<QString> s_pixmapCacheKeys;
89};
90
91QT_END_NAMESPACE
92
93#endif //QSTYLE_P_H
94

source code of qtbase/src/widgets/styles/qstyle_p.h