Remove QWidget dependency in QPainter::initFrom().
authorSamuel Rødal <samuel.rodal@nokia.com>
Wed, 4 May 2011 07:18:59 +0000 (09:18 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Wed, 4 May 2011 08:02:56 +0000 (10:02 +0200)
src/gui/kernel/qwidget.cpp
src/gui/kernel/qwidget.h
src/gui/painting/qpaintdevice.cpp
src/gui/painting/qpaintdevice.h
src/gui/painting/qpainter.cpp
src/gui/painting/qpainter.h

index 58b52a7..171a3a7 100644 (file)
@@ -12506,6 +12506,16 @@ void QWidget::ungrabGesture(Qt::GestureType gesture)
     \a m is the metric to get.
 */
 
+void QWidget::init(QPainter *painter) const
+{
+    const QPalette &pal = palette();
+    painter->d_func()->state->pen = QPen(pal.brush(foregroundRole()), 0);
+    painter->d_func()->state->bgBrush = pal.brush(backgroundRole());
+    QFont f(font(), const_cast<QWidget *>(this));
+    painter->d_func()->state->deviceFont = f;
+    painter->d_func()->state->font = f;
+}
+
 /*!
     \fn void QWidget::setMask(const QRegion &region)
     \overload
index d3a08a8..d23baee 100644 (file)
@@ -702,6 +702,7 @@ protected:
     virtual void changeEvent(QEvent *);
 
     int metric(PaintDeviceMetric) const;
+    void init(QPainter *painter) const;
 
     virtual void inputMethodEvent(QInputMethodEvent *);
 public:
index f2ba7f0..65be030 100644 (file)
@@ -67,6 +67,10 @@ int QPaintDevice::metric(PaintDeviceMetric) const
 }
 #endif
 
+void QPaintDevice::init(QPainter *painter) const
+{
+}
+
 Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, QPaintDevice::PaintDeviceMetric metric)
 {
     return device->metric(metric);
index ad06048..24b6d81 100644 (file)
@@ -105,6 +105,7 @@ public:
 protected:
     QPaintDevice();
     virtual int metric(PaintDeviceMetric metric) const;
+    virtual void init(QPainter *painter) const;
 
     ushort        painters;                        // refcount
 
index 988a878..c14dff2 100644 (file)
@@ -1556,25 +1556,23 @@ bool QPainter::isActive() const
 
 /*!
     Initializes the painters pen, background and font to the same as
-    the given \a widget. This function is called automatically when the
-    painter is opened on a QWidget.
+    the given \a paint device.
+
+    \obsolete
 
     \sa begin(), {QPainter#Settings}{Settings}
 */
-void QPainter::initFrom(const QWidget *widget)
+void QPainter::initFrom(const QPaintDevice *device)
 {
-    Q_ASSERT_X(widget, "QPainter::initFrom(const QWidget *widget)", "Widget cannot be 0");
+    Q_ASSERT_X(device, "QPainter::initFrom(const QPaintDevice *device)", "QPaintDevice cannot be 0");
     Q_D(QPainter);
     if (!d->engine) {
         qWarning("QPainter::initFrom: Painter not active, aborted");
         return;
     }
 
-    const QPalette &pal = widget->palette();
-    d->state->pen = QPen(pal.brush(widget->foregroundRole()), 0);
-    d->state->bgBrush = pal.brush(widget->backgroundRole());
-    d->state->deviceFont = QFont(widget->font(), const_cast<QWidget*> (widget));
-    d->state->font = d->state->deviceFont;
+    device->init(this);
+
     if (d->extended) {
         d->extended->penChanged();
     } else if (d->engine) {
index 0ada62a..9ef39e8 100644 (file)
@@ -133,7 +133,7 @@ public:
     bool end();
     bool isActive() const;
 
-    void initFrom(const QWidget *widget);
+    void initFrom(const QPaintDevice *device);
 
     enum CompositionMode {
         CompositionMode_SourceOver,
@@ -470,6 +470,7 @@ private:
 
     QScopedPointer<QPainterPrivate> d_ptr;
 
+    friend class QWidget;
     friend class QFontEngine;
     friend class QFontEngineBox;
     friend class QFontEngineFT;