(1)源码来自于头文件 qpaintdevice . h :
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QPAINTDEVICE_H
#define QPAINTDEVICE_H
#include <QtGui/qtguiglobal.h>
#include <QtGui/qwindowdefs.h>
#include <QtCore/qrect.h>
QT_BEGIN_NAMESPACE
class QPaintEngine;
// device for QPainter 本类很重要,是界面组件基类 QWidget 的父类
class Q_GUI_EXPORT QPaintDevice
{
private: //本类的私有部分,并没有定义数据成员
Q_DISABLE_COPY(QPaintDevice)
friend class QPainter;
friend class QPainterPrivate;
friend class QFontEngineMac;
friend class QX11PaintEngine;
friend Q_GUI_EXPORT
int qt_paint_device_metric(const QPaintDevice *device,
PaintDeviceMetric metric);
protected:
QPaintDevice() noexcept; //默认构造函数,只可以被子类调用
//Returns the metric information for the given paint device metric.
virtual int metric(PaintDeviceMetric metric) const;
virtual void initPainter(QPainter *painter) const;
virtual QPaintDevice *redirected(QPoint *offset) const;//重定向
virtual QPainter *sharedPainter() const;
ushort painters; // refcount 引用计数,本类的数据成员
public:
enum PaintDeviceMetric { //本枚举类的数据成员,可以直接被使用
PdmWidth = 1, //枚举量定义为从 1开始
PdmHeight, //看着像是定义喷涂的区域,遮挡属性,以及绘画颜色的,
PdmWidthMM, //以及缩放比例
PdmHeightMM,
PdmNumColors,
PdmDepth,
PdmDpiX,
PdmDpiY,
PdmPhysicalDpiX,
PdmPhysicalDpiY,
PdmDevicePixelRatio,
PdmDevicePixelRatioScaled
};
virtual ~QPaintDevice(); //本类的虚析构函数,可以被继承
virtual int devType() const; //不注释的就是无官方注释
//Returns true if the device is currently being painted on,
//i.e. someone has called QPainter::begin()
//but not yet called QPainter::end() for this device;
//otherwise returns false.
bool paintingActive() const; //这俩函数的实现都在本文下面
//Returns a pointer to the paint engine used for drawing on the device.
virtual QPaintEngine * paintEngine() const = 0;
//以下这些成员函数都是返回本对象的喷涂属性的值
//返回默认坐标系统单位(例如 QPixmap 和 QWidget 的像素)中的绘图设备的宽度。
//Returns the width of the paint device in default coordinate system units
//(e.g. pixels for QPixmap and QWidget).
int width() const { return metric(PdmWidth); }
//返回油漆设备的宽度(以毫米为单位)。
//由于平台限制,可能无法使用此函数来确定屏幕上小部件的实际物理大小。
//Returns the width of the paint device in millimeters.
//Due to platform limitations it may not be possible to use this function
//to determine the actual physical size of a widget on the screen.
int widthMM() const { return metric(PdmWidthMM); }
//Returns the height of the paint device in default coordinate system units
//(e.g. pixels for QPixmap and QWidget).
int height() const { return metric(PdmHeight); }
//Returns the height of the paint device in millimeters.
//Due to platform limitations it may not be possible to use this function
//to determine the actual physical size of a widget on the screen.
int heightMM() const { return metric(PdmHeightMM); }
//Returns the number of different colors available for the paint device.
//If the number of colors available is too great to be represented
//by the int data type, then INT_MAX will be returned instead.
int colorCount() const { return metric(PdmNumColors); }
//Returns the bit depth (number of bit planes) of the paint device.
//返回绘图设备的位深度(位平面数量)。
//位深度在数字图像中通常指每个像素用多少位二进制数来表示颜色信息。
//比如24位深度的话,红绿蓝各8位,总共有1677万种颜色。
int depth() const { return metric(PdmDepth); }
//Returns the horizontal resolution of the device in dots per inch,
//which is used when computing font sizes.
//For X11, this is usually the same as could be computed from widthMM().
//Note that if the logicalDpiX() doesn't equal the physicalDpiX(),
//the corresponding QPaintEngine must handle the resolution mapping.
//返回设备每英寸的横向分辨率,在计算字体大小时使用。
//对于X11,这通常与从widthMM可以计算出的相同。
//请注意,如果logicalDpiX()不等于 physicalDpiX(),
//则相应的 QPaintEngine 必须处理分辨率映射。
int logicalDpiX() const { return metric(PdmDpiX); }
//Returns the vertical resolution of the device in dots per inch,
//which is used when computing font sizes.
int logicalDpiY() const { return metric(PdmDpiY); }
//Returns the horizontal resolution of the device in dots per inch.
//For example, when printing, this resolution refers to
//the physical printer's resolution. The logical DPI on the other hand,
//refers to the resolution used by the actual paint engine.
int physicalDpiX() const { return metric(PdmPhysicalDpiX); }
int physicalDpiY() const { return metric(PdmPhysicalDpiY); }
//返回设备的设备像素比率。普通值对于正常dpi显示器为1,对于高dpi“视网膜”显示器为2。
//Returns the device pixel ratio for device. Common values are 1
//for normal-dpi displays and 2 for high-dpi "retina" displays.
qreal devicePixelRatio() const
{ return metric(PdmDevicePixelRatioScaled) / devicePixelRatioFScale(); }
//Returns the device pixel ratio for the device as a floating point number.
qreal devicePixelRatioF() const { return devicePixelRatio(); }
static inline qreal devicePixelRatioFScale() //无注释
{ return 0x10000; }
};
/*****************************************************************************
Inline functions 带 inline 修饰符的类成员函数
*****************************************************************************/
inline int QPaintDevice::devType() const
{ return QInternal::UnknownDevice; }
inline bool QPaintDevice::paintingActive() const
{ return painters != 0; }
QT_END_NAMESPACE
#endif // QPAINTDEVICE_H
(2)
谢谢