Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:26:21

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QPAINTDEVICE_H
0005 #define QPAINTDEVICE_H
0006 
0007 #include <QtGui/qtguiglobal.h>
0008 #include <QtGui/qwindowdefs.h>
0009 #include <QtCore/qrect.h>
0010 
0011 QT_BEGIN_NAMESPACE
0012 
0013 
0014 
0015 class QPaintEngine;
0016 
0017 class Q_GUI_EXPORT QPaintDevice                                // device for QPainter
0018 {
0019 public:
0020     enum PaintDeviceMetric {
0021         PdmWidth = 1,
0022         PdmHeight,
0023         PdmWidthMM,
0024         PdmHeightMM,
0025         PdmNumColors,
0026         PdmDepth,
0027         PdmDpiX,
0028         PdmDpiY,
0029         PdmPhysicalDpiX,
0030         PdmPhysicalDpiY,
0031         PdmDevicePixelRatio,
0032         PdmDevicePixelRatioScaled,
0033         PdmDevicePixelRatioF_EncodedA,
0034         PdmDevicePixelRatioF_EncodedB,
0035     };
0036 
0037     virtual ~QPaintDevice();
0038 
0039     virtual int devType() const;
0040     bool paintingActive() const;
0041     virtual QPaintEngine *paintEngine() const = 0;
0042 
0043     int width() const { return metric(PdmWidth); }
0044     int height() const { return metric(PdmHeight); }
0045     int widthMM() const { return metric(PdmWidthMM); }
0046     int heightMM() const { return metric(PdmHeightMM); }
0047     int logicalDpiX() const { return metric(PdmDpiX); }
0048     int logicalDpiY() const { return metric(PdmDpiY); }
0049     int physicalDpiX() const { return metric(PdmPhysicalDpiX); }
0050     int physicalDpiY() const { return metric(PdmPhysicalDpiY); }
0051     qreal devicePixelRatio() const;
0052     qreal devicePixelRatioF()  const { return devicePixelRatio(); }
0053     int colorCount() const { return metric(PdmNumColors); }
0054     int depth() const { return metric(PdmDepth); }
0055 
0056     static inline qreal devicePixelRatioFScale() { return 0x10000; }
0057     static inline int encodeMetricF(PaintDeviceMetric metric, double value);
0058 protected:
0059     QPaintDevice() noexcept;
0060     virtual int metric(PaintDeviceMetric metric) const;
0061     virtual void initPainter(QPainter *painter) const;
0062     virtual QPaintDevice *redirected(QPoint *offset) const;
0063     virtual QPainter *sharedPainter() const;
0064     double getDecodedMetricF(PaintDeviceMetric metricA, PaintDeviceMetric metricB) const;
0065 
0066     ushort        painters;                        // refcount
0067 private:
0068     Q_DISABLE_COPY(QPaintDevice)
0069 
0070     friend class QPainter;
0071     friend class QPainterPrivate;
0072     friend class QFontEngineMac;
0073     friend class QX11PaintEngine;
0074     friend Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, PaintDeviceMetric metric);
0075 };
0076 
0077 /*****************************************************************************
0078   Inline functions
0079  *****************************************************************************/
0080 
0081 inline int QPaintDevice::devType() const
0082 { return QInternal::UnknownDevice; }
0083 
0084 inline bool QPaintDevice::paintingActive() const
0085 { return painters != 0; }
0086 
0087 inline int QPaintDevice::encodeMetricF(PaintDeviceMetric metric, double value)
0088 {
0089     qint32 buf[2];
0090     Q_STATIC_ASSERT(sizeof(buf) == sizeof(double));
0091     memcpy(buf, &value, sizeof(buf));
0092     return buf[metric & 1];
0093 }
0094 
0095 QT_END_NAMESPACE
0096 
0097 #endif // QPAINTDEVICE_H