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 | static bool (); |
33 | |
34 | QStyle *proxyStyle; |
35 | QString name; |
36 | }; |
37 | |
38 | inline QPixmap styleCachePixmap(const QSize &size, qreal pixelRatio) |
39 | { |
40 | QPixmap cachePixmap = QPixmap(size * pixelRatio); |
41 | cachePixmap.setDevicePixelRatio(pixelRatio); |
42 | cachePixmap.fill(fillColor: Qt::transparent); |
43 | return cachePixmap; |
44 | } |
45 | |
46 | #define BEGIN_STYLE_PIXMAPCACHE(a) \ |
47 | QRect rect = option->rect; \ |
48 | QPixmap internalPixmapCache; \ |
49 | QPainter *p = painter; \ |
50 | const auto dpr = p->device()->devicePixelRatio(); \ |
51 | const QString unique = QStyleHelper::uniqueName((a), option, option->rect.size(), dpr); \ |
52 | int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \ |
53 | const bool doPixmapCache = (!option->rect.isEmpty()) \ |
54 | && ((txType <= QTransform::TxTranslate) || (painter->deviceTransform().type() == QTransform::TxScale)); \ |
55 | if (doPixmapCache && QPixmapCache::find(unique, &internalPixmapCache)) { \ |
56 | painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \ |
57 | } else { \ |
58 | if (doPixmapCache) { \ |
59 | rect.setRect(0, 0, option->rect.width(), option->rect.height()); \ |
60 | internalPixmapCache = styleCachePixmap(option->rect.size(), dpr); \ |
61 | p = new QPainter(&internalPixmapCache); \ |
62 | } |
63 | |
64 | |
65 | |
66 | #define END_STYLE_PIXMAPCACHE \ |
67 | if (doPixmapCache) { \ |
68 | p->end(); \ |
69 | delete p; \ |
70 | painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \ |
71 | QPixmapCache::insert(unique, internalPixmapCache); \ |
72 | } \ |
73 | } |
74 | |
75 | QT_END_NAMESPACE |
76 | |
77 | #endif //QSTYLE_P_H |
78 | |