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
4#ifndef QSTYLE_P_H
5#define QSTYLE_P_H
6
7#include "qquickstyle.h"
8
9#include <QtCore/private/qobject_p.h>
10#include <QtGui/qguiapplication.h>
11
12QT_BEGIN_NAMESPACE
13
14//
15// W A R N I N G
16// -------------
17//
18// This file is not part of the Qt API. It exists for the convenience
19// of qstyle_*.cpp. This header file may change from version to version
20// without notice, or even be removed.
21//
22// We mean it.
23//
24
25// Private class
26
27namespace QQC2 {
28
29class QStylePrivate: public QObjectPrivate
30{
31 Q_DECLARE_PUBLIC(QStyle)
32
33public:
34 static bool useFullScreenForPopup();
35 mutable int layoutSpacingIndex = -1;
36 QStyle *proxyStyle;
37};
38
39inline QImage styleCacheImage(const QSize &size)
40{
41 const qreal pixelRatio = qApp->devicePixelRatio();
42 QImage cacheImage = QImage(size * pixelRatio, QImage::Format_ARGB32_Premultiplied);
43 cacheImage.setDevicePixelRatio(pixelRatio);
44 return cacheImage;
45}
46
47inline QPixmap styleCachePixmap(const QSize &size)
48{
49 const qreal pixelRatio = qApp->devicePixelRatio();
50 QPixmap cachePixmap = QPixmap(size * pixelRatio);
51 cachePixmap.setDevicePixelRatio(pixelRatio);
52 return cachePixmap;
53}
54
55#define BEGIN_STYLE_PIXMAPCACHE(a) \
56 QRect rect = option->rect; \
57 QPixmap internalPixmapCache; \
58 QImage imageCache; \
59 QPainter *p = painter; \
60 QString unique = QStyleHelper::uniqueName((a), option, option->rect.size()); \
61 int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \
62 bool doPixmapCache = (!option->rect.isEmpty()) \
63 && ((txType <= QTransform::TxTranslate) || (painter->deviceTransform().type() == QTransform::TxScale)); \
64 if (doPixmapCache && QPixmapCache::find(unique, &internalPixmapCache)) { \
65 painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \
66 } else { \
67 if (doPixmapCache) { \
68 rect.setRect(0, 0, option->rect.width(), option->rect.height()); \
69 imageCache = styleCacheImage(option->rect.size()); \
70 imageCache.fill(0); \
71 p = new QPainter(&imageCache); \
72 }
73
74#define END_STYLE_PIXMAPCACHE \
75 if (doPixmapCache) { \
76 p->end(); \
77 delete p; \
78 internalPixmapCache = QPixmap::fromImage(imageCache); \
79 painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \
80 QPixmapCache::insert(unique, internalPixmapCache); \
81 } \
82 }
83
84} // namespace QQC2
85
86QT_END_NAMESPACE
87
88#endif //QSTYLE_P_H
89

source code of qtdeclarative/src/quicknativestyle/qstyle/qquickstyle_p.h