Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpaintdevice.cpp
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#include "qpaintdevice.h"
6
8
9QPaintDevice::QPaintDevice() noexcept
10{
11 painters = 0;
12}
13
14QPaintDevice::~QPaintDevice()
15{
16 if (paintingActive())
17 qWarning("QPaintDevice: Cannot destroy paint device that is being "
18 "painted");
19}
20
21/*!
22 \internal
23*/
24// ### Qt 7: Replace this workaround mechanism: virtual devicePixelRatio() and virtual metricF()
25double QPaintDevice::getDecodedMetricF(PaintDeviceMetric metricA, PaintDeviceMetric metricB) const
26{
27 qint32 buf[2];
28 // The Encoded metric enum values come in pairs of one odd and one even value.
29 // We map those to the 0 and 1 indexes of buf by taking just the least significant bit.
30 // Same mapping here as in the encodeMetricF() function, to ensure correct order.
31 buf[metricA & 1] = metric(metricA);
32 buf[metricB & 1] = metric(metricB);
33 double res;
34 memcpy(&res, buf, sizeof(res));
35 return res;
36}
37
38qreal QPaintDevice::devicePixelRatio() const
39{
40 Q_STATIC_ASSERT((PdmDevicePixelRatioF_EncodedA & 1) != (PdmDevicePixelRatioF_EncodedB & 1));
41 double res;
42 int scaledDpr = metric(PdmDevicePixelRatioScaled);
43 if (scaledDpr == int(devicePixelRatioFScale())) {
44 res = 1; // Shortcut for common case
45 } else if (scaledDpr == 2 * int(devicePixelRatioFScale())) {
46 res = 2; // Shortcut for common case
47 } else {
48 res = getDecodedMetricF(PdmDevicePixelRatioF_EncodedA, PdmDevicePixelRatioF_EncodedB);
49 if (res <= 0) // These metrics not implemented, fall back to PdmDevicePixelRatioScaled
50 res = scaledDpr / devicePixelRatioFScale();
51 }
52 return res;
53}
54
55/*!
56 \internal
57*/
58void QPaintDevice::initPainter(QPainter *) const
59{
60}
61
62/*!
63 \internal
64*/
65QPaintDevice *QPaintDevice::redirected(QPoint *) const
66{
67 return nullptr;
68}
69
70/*!
71 \internal
72*/
73QPainter *QPaintDevice::sharedPainter() const
74{
75 return nullptr;
76}
77
78Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, QPaintDevice::PaintDeviceMetric metric)
79{
80 return device->metric(metric);
81}
82
83int QPaintDevice::metric(PaintDeviceMetric m) const
84{
85 // Fallback: A subclass has not implemented PdmDevicePixelRatioScaled but might
86 // have implemented PdmDevicePixelRatio.
87 if (m == PdmDevicePixelRatioScaled)
88 return this->metric(PdmDevicePixelRatio) * devicePixelRatioFScale();
89 if (m == PdmNumColors)
90 return 0;
91 if (m == PdmDevicePixelRatio)
92 return 1;
93
94 qWarning("QPaintDevice::metrics: Device has no metric information");
95
96 switch (m) {
97 case PdmDevicePixelRatioScaled:
98 case PdmDevicePixelRatio:
99 case PdmNumColors:
100 Q_UNREACHABLE();
101 break;
102 case PdmDpiX:
103 case PdmDpiY:
104 return 72;
105 case PdmDevicePixelRatioF_EncodedA:
106 case PdmDevicePixelRatioF_EncodedB:
107 return 0;
108 case PdmWidth:
109 case PdmHeight:
110 case PdmWidthMM:
111 case PdmHeightMM:
112 case PdmDepth:
113 case PdmPhysicalDpiX:
114 case PdmPhysicalDpiY:
115 return 0;
116 }
117 qDebug("Unrecognized metric %d!", m);
118 return 0;
119}
120
121QT_END_NAMESPACE
Combined button and popup list for selecting options.
Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, QPaintDevice::PaintDeviceMetric metric)