diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-10-15 06:26:19 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-10-15 06:49:48 (GMT) |
commit | 8b568a5afd24ecb343b7508bf6b27b27af59b226 (patch) | |
tree | e792a660a9dac1c514ef31b29080e84907671871 /src | |
parent | 1f73b205ec57be6327f62ef39099358425a7f0a8 (diff) | |
download | Qt-8b568a5afd24ecb343b7508bf6b27b27af59b226.zip Qt-8b568a5afd24ecb343b7508bf6b27b27af59b226.tar.gz Qt-8b568a5afd24ecb343b7508bf6b27b27af59b226.tar.bz2 |
qt_paint_device_metric() for fetching metrics
Custom window surfaces, graphics systems, and Qt/Embedded screen
drivers often need to access QPaintDevice::metric(), but it is
protected. Hence the growing number of friends in QWidget and
QImage. The qt_paint_device_metric() function provides a more
future-proof approach that doesn't require lots of friends.
Reviewed-by: Gunnar
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qwidget.h | 3 | ||||
-rw-r--r-- | src/gui/painting/qpaintdevice.cpp | 5 | ||||
-rw-r--r-- | src/gui/painting/qpaintdevice.h | 1 | ||||
-rw-r--r-- | src/gui/painting/qpaintengine_raster.cpp | 9 | ||||
-rw-r--r-- | src/opengl/qglpaintdevice_qws.cpp | 9 | ||||
-rw-r--r-- | src/opengl/qwindowsurface_gl.cpp | 2 | ||||
-rw-r--r-- | src/openvg/qwindowsurface_vg.cpp | 2 | ||||
-rw-r--r-- | src/plugins/graphicssystems/shivavg/shivavgwindowsurface.cpp | 14 |
8 files changed, 11 insertions, 34 deletions
diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index 3501c6e..3cc3093 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -726,14 +726,11 @@ private: friend class QGLContext; friend class QGLWidget; friend class QGLWindowSurface; - friend class QGLWindowSurfaceGLPaintDevice; - friend class QVGWindowSurface; friend class QX11PaintEngine; friend class QWin32PaintEngine; friend class QShortcutPrivate; friend class QShortcutMap; friend class QWindowSurface; - friend class QD3DWindowSurface; friend class QGraphicsProxyWidget; friend class QGraphicsProxyWidgetPrivate; friend class QStyleSheetStyle; diff --git a/src/gui/painting/qpaintdevice.cpp b/src/gui/painting/qpaintdevice.cpp index 95c0b44..6114938 100644 --- a/src/gui/painting/qpaintdevice.cpp +++ b/src/gui/painting/qpaintdevice.cpp @@ -65,4 +65,9 @@ int QPaintDevice::metric(PaintDeviceMetric) const return 0; } +Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, QPaintDevice::PaintDeviceMetric metric) +{ + return device->metric(metric); +} + QT_END_NAMESPACE diff --git a/src/gui/painting/qpaintdevice.h b/src/gui/painting/qpaintdevice.h index 92aa3cb..c8e86b8 100644 --- a/src/gui/painting/qpaintdevice.h +++ b/src/gui/painting/qpaintdevice.h @@ -137,6 +137,7 @@ public: friend class QPainter; friend class QFontEngineMac; friend class QX11PaintEngine; + friend Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, PaintDeviceMetric metric); }; #ifdef QT3_SUPPORT diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 6037bd5..240403d 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -4213,13 +4213,6 @@ void QRasterBuffer::prepare(QCustomRasterPaintDevice *device) drawHelper = qDrawHelper + format; } -class MetricAccessor : public QWidget { -public: - int metric(PaintDeviceMetric m) { - return QWidget::metric(m); - } -}; - int QCustomRasterPaintDevice::metric(PaintDeviceMetric m) const { switch (m) { @@ -4231,7 +4224,7 @@ int QCustomRasterPaintDevice::metric(PaintDeviceMetric m) const break; } - return (static_cast<MetricAccessor*>(widget)->metric(m)); + return qt_paint_device_metric(widget, m); } int QCustomRasterPaintDevice::bytesPerLine() const diff --git a/src/opengl/qglpaintdevice_qws.cpp b/src/opengl/qglpaintdevice_qws.cpp index 8c2f27d..1512278 100644 --- a/src/opengl/qglpaintdevice_qws.cpp +++ b/src/opengl/qglpaintdevice_qws.cpp @@ -52,13 +52,6 @@ public: QWidget *widget; }; -class QMetricAccessor : public QWidget { -public: - int metric(PaintDeviceMetric m) { - return QWidget::metric(m); - } -}; - QWSGLPaintDevice::QWSGLPaintDevice(QWidget *widget) : d_ptr(new QWSGLPaintDevicePrivate) { @@ -80,7 +73,7 @@ int QWSGLPaintDevice::metric(PaintDeviceMetric m) const Q_D(const QWSGLPaintDevice); Q_ASSERT(d->widget); - return ((QMetricAccessor *) d->widget)->metric(m); + return qt_paint_device_metric(d->widget, m); } QWSGLWindowSurface* QWSGLPaintDevice::windowSurface() const diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index b341243..df84a76 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -280,7 +280,7 @@ QGLContext* QGLWindowSurfaceGLPaintDevice::context() const int QGLWindowSurfaceGLPaintDevice::metric(PaintDeviceMetric m) const { - return d->q_ptr->window()->metric(m); + return qt_paint_device_metric(d->q_ptr->window(), m); } QPaintEngine *QGLWindowSurfaceGLPaintDevice::paintEngine() const diff --git a/src/openvg/qwindowsurface_vg.cpp b/src/openvg/qwindowsurface_vg.cpp index 6cc2e27..661e06a 100644 --- a/src/openvg/qwindowsurface_vg.cpp +++ b/src/openvg/qwindowsurface_vg.cpp @@ -111,7 +111,7 @@ QPaintEngine *QVGWindowSurface::paintEngine() const int QVGWindowSurface::metric(PaintDeviceMetric met) const { - return window()->metric(met); + return qt_paint_device_metric(window(), met); } QT_END_NAMESPACE diff --git a/src/plugins/graphicssystems/shivavg/shivavgwindowsurface.cpp b/src/plugins/graphicssystems/shivavg/shivavgwindowsurface.cpp index df623ba..955aa55 100644 --- a/src/plugins/graphicssystems/shivavg/shivavgwindowsurface.cpp +++ b/src/plugins/graphicssystems/shivavg/shivavgwindowsurface.cpp @@ -350,21 +350,9 @@ QPaintEngine *ShivaVGWindowSurface::paintEngine() const return d_ptr->engine; } -// We need to get access to QWidget::metric() from ShivaVGWindowSurface::metric, -// but it is not a friend of QWidget. To get around this, we create a -// fake QX11PaintEngine class, which is a friend. -class QX11PaintEngine -{ -public: - static int metric(const QWidget *widget, QPaintDevice::PaintDeviceMetric met) - { - return widget->metric(met); - } -}; - int ShivaVGWindowSurface::metric(PaintDeviceMetric met) const { - return QX11PaintEngine::metric(window(), met); + return qt_paint_device_metric(window(), met); } QT_END_NAMESPACE |