/src/qtbase/src/gui/painting/qpaintdevice.h
Line | Count | Source (jump to first uncovered line) |
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 QPAINTDEVICE_H |
5 | | #define QPAINTDEVICE_H |
6 | | |
7 | | #include <QtGui/qtguiglobal.h> |
8 | | #include <QtGui/qwindowdefs.h> |
9 | | #include <QtCore/qrect.h> |
10 | | |
11 | | QT_BEGIN_NAMESPACE |
12 | | |
13 | | |
14 | | |
15 | | class QPaintEngine; |
16 | | |
17 | | class Q_GUI_EXPORT QPaintDevice // device for QPainter |
18 | | { |
19 | | public: |
20 | | enum PaintDeviceMetric { |
21 | | PdmWidth = 1, |
22 | | PdmHeight, |
23 | | PdmWidthMM, |
24 | | PdmHeightMM, |
25 | | PdmNumColors, |
26 | | PdmDepth, |
27 | | PdmDpiX, |
28 | | PdmDpiY, |
29 | | PdmPhysicalDpiX, |
30 | | PdmPhysicalDpiY, |
31 | | PdmDevicePixelRatio, |
32 | | PdmDevicePixelRatioScaled, |
33 | | PdmDevicePixelRatioF_EncodedA, |
34 | | PdmDevicePixelRatioF_EncodedB, |
35 | | }; |
36 | | |
37 | | virtual ~QPaintDevice(); |
38 | | |
39 | | virtual int devType() const; |
40 | | bool paintingActive() const; |
41 | | virtual QPaintEngine *paintEngine() const = 0; |
42 | | |
43 | | int width() const { return metric(PdmWidth); } |
44 | | int height() const { return metric(PdmHeight); } |
45 | 0 | int widthMM() const { return metric(PdmWidthMM); } |
46 | 0 | int heightMM() const { return metric(PdmHeightMM); } |
47 | 0 | int logicalDpiX() const { return metric(PdmDpiX); } |
48 | | int logicalDpiY() const { return metric(PdmDpiY); } |
49 | 0 | int physicalDpiX() const { return metric(PdmPhysicalDpiX); } |
50 | 0 | int physicalDpiY() const { return metric(PdmPhysicalDpiY); } |
51 | | qreal devicePixelRatio() const; |
52 | 0 | qreal devicePixelRatioF() const { return devicePixelRatio(); } |
53 | 0 | int colorCount() const { return metric(PdmNumColors); } |
54 | | int depth() const { return metric(PdmDepth); } |
55 | | |
56 | | static inline qreal devicePixelRatioFScale() { return 0x10000; } |
57 | | static inline int encodeMetricF(PaintDeviceMetric metric, double value); |
58 | | protected: |
59 | | QPaintDevice() noexcept; |
60 | | virtual int metric(PaintDeviceMetric metric) const; |
61 | | virtual void initPainter(QPainter *painter) const; |
62 | | virtual QPaintDevice *redirected(QPoint *offset) const; |
63 | | virtual QPainter *sharedPainter() const; |
64 | | double getDecodedMetricF(PaintDeviceMetric metricA, PaintDeviceMetric metricB) const; |
65 | | |
66 | | ushort painters; // refcount |
67 | | private: |
68 | | Q_DISABLE_COPY(QPaintDevice) |
69 | | |
70 | | friend class QPainter; |
71 | | friend class QPainterPrivate; |
72 | | friend class QFontEngineMac; |
73 | | friend class QX11PaintEngine; |
74 | | friend Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, PaintDeviceMetric metric); |
75 | | }; |
76 | | |
77 | | /***************************************************************************** |
78 | | Inline functions |
79 | | *****************************************************************************/ |
80 | | |
81 | | inline int QPaintDevice::devType() const |
82 | 0 | { return QInternal::UnknownDevice; } |
83 | | |
84 | | inline bool QPaintDevice::paintingActive() const |
85 | | { return painters != 0; } |
86 | | |
87 | | inline int QPaintDevice::encodeMetricF(PaintDeviceMetric metric, double value) |
88 | 0 | { |
89 | 0 | qint32 buf[2]; |
90 | 0 | Q_STATIC_ASSERT(sizeof(buf) == sizeof(double)); |
91 | 0 | memcpy(buf, &value, sizeof(buf)); |
92 | 0 | return buf[metric & 1]; |
93 | 0 | } |
94 | | |
95 | | QT_END_NAMESPACE |
96 | | |
97 | | #endif // QPAINTDEVICE_H |