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