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