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
11QT_BEGIN_NAMESPACE
12
13
14
15class QPaintEngine;
16
17class Q_GUI_EXPORT QPaintDevice // device for QPainter
18{
19public:
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 };
34
35 virtual ~QPaintDevice();
36
37 virtual int devType() const;
38 bool paintingActive() const;
39 virtual QPaintEngine *paintEngine() const = 0;
40
41 int width() const { return metric(metric: PdmWidth); }
42 int height() const { return metric(metric: PdmHeight); }
43 int widthMM() const { return metric(metric: PdmWidthMM); }
44 int heightMM() const { return metric(metric: PdmHeightMM); }
45 int logicalDpiX() const { return metric(metric: PdmDpiX); }
46 int logicalDpiY() const { return metric(metric: PdmDpiY); }
47 int physicalDpiX() const { return metric(metric: PdmPhysicalDpiX); }
48 int physicalDpiY() const { return metric(metric: PdmPhysicalDpiY); }
49 qreal devicePixelRatio() const { return metric(metric: PdmDevicePixelRatioScaled) / devicePixelRatioFScale(); }
50 qreal devicePixelRatioF() const { return devicePixelRatio(); }
51 int colorCount() const { return metric(metric: PdmNumColors); }
52 int depth() const { return metric(metric: PdmDepth); }
53
54 static inline qreal devicePixelRatioFScale() { return 0x10000; }
55protected:
56 QPaintDevice() noexcept;
57 virtual int metric(PaintDeviceMetric metric) const;
58 virtual void initPainter(QPainter *painter) const;
59 virtual QPaintDevice *redirected(QPoint *offset) const;
60 virtual QPainter *sharedPainter() const;
61
62 ushort painters; // refcount
63private:
64 Q_DISABLE_COPY(QPaintDevice)
65
66 friend class QPainter;
67 friend class QPainterPrivate;
68 friend class QFontEngineMac;
69 friend class QX11PaintEngine;
70 friend Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, PaintDeviceMetric metric);
71};
72
73/*****************************************************************************
74 Inline functions
75 *****************************************************************************/
76
77inline int QPaintDevice::devType() const
78{ return QInternal::UnknownDevice; }
79
80inline bool QPaintDevice::paintingActive() const
81{ return painters != 0; }
82
83QT_END_NAMESPACE
84
85#endif // QPAINTDEVICE_H
86

source code of qtbase/src/gui/painting/qpaintdevice.h