Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include "qpaintdevice.h"
5
7
9{
10 painters = 0;
11}
12
14{
15 if (paintingActive())
16 qWarning("QPaintDevice: Cannot destroy paint device that is being "
17 "painted");
18}
19
23// ### Qt 7: Replace this workaround mechanism: virtual devicePixelRatio() and virtual metricF()
25{
26 qint32 buf[2];
27 // The Encoded metric enum values come in pairs of one odd and one even value.
28 // We map those to the 0 and 1 indexes of buf by taking just the least significant bit.
29 // Same mapping here as in the encodeMetricF() function, to ensure correct order.
30 buf[metricA & 1] = metric(metricA);
31 buf[metricB & 1] = metric(metricB);
32 double res;
33 memcpy(&res, buf, sizeof(res));
34 return res;
35}
36
38{
40 double res;
41 int scaledDpr = metric(PdmDevicePixelRatioScaled);
42 if (scaledDpr == int(devicePixelRatioFScale())) {
43 res = 1; // Shortcut for common case
44 } else if (scaledDpr == 2 * int(devicePixelRatioFScale())) {
45 res = 2; // Shortcut for common case
46 } else {
48 if (res <= 0) // These metrics not implemented, fall back to PdmDevicePixelRatioScaled
49 res = scaledDpr / devicePixelRatioFScale();
50 }
51 return res;
52}
53
58{
59}
60
65{
66 return nullptr;
67}
68
73{
74 return nullptr;
75}
76
78{
79 return device->metric(metric);
80}
81
83{
84 // Fallback: A subclass has not implemented PdmDevicePixelRatioScaled but might
85 // have implemented PdmDevicePixelRatio.
88
89 qWarning("QPaintDevice::metrics: Device has no metric information");
90
91 if (m == PdmDpiX) {
92 return 72;
93 } else if (m == PdmDpiY) {
94 return 72;
95 } else if (m == PdmNumColors) {
96 // FIXME: does this need to be a real value?
97 return 256;
98 } else if (m == PdmDevicePixelRatio) {
99 return 1;
101 return 0;
102 } else {
103 qDebug("Unrecognised metric %d!",m);
104 return 0;
105 }
106}
107
IOBluetoothDevice * device
bool paintingActive() const
QPaintDevice() noexcept
qreal devicePixelRatio() const
virtual void initPainter(QPainter *painter) const
@ PdmDevicePixelRatioF_EncodedB
@ PdmDevicePixelRatioF_EncodedA
@ PdmDevicePixelRatioScaled
virtual ~QPaintDevice()
ushort painters
double getDecodedMetricF(PaintDeviceMetric metricA, PaintDeviceMetric metricB) const
virtual QPaintDevice * redirected(QPoint *offset) const
virtual QPainter * sharedPainter() const
virtual int metric(PaintDeviceMetric metric) const
static qreal devicePixelRatioFScale()
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qpoint.h:25
Combined button and popup list for selecting options.
#define Q_STATIC_ASSERT(Condition)
Definition qassert.h:108
#define qDebug
[1]
Definition qlogging.h:165
#define qWarning
Definition qlogging.h:167
const GLfloat * m
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint res
Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, QPaintDevice::PaintDeviceMetric metric)
int qint32
Definition qtypes.h:49
double qreal
Definition qtypes.h:187