Remove QWidget dependency in QPainter::initFrom().

bb10
Samuel Rødal 2011-05-04 09:18:59 +02:00
parent ea6c6d711b
commit 862263b0ab
6 changed files with 25 additions and 10 deletions

View 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

View File

@ -702,6 +702,7 @@ protected:
virtual void changeEvent(QEvent *);
int metric(PaintDeviceMetric) const;
void init(QPainter *painter) const;
virtual void inputMethodEvent(QInputMethodEvent *);
public:

View 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);

View File

@ -105,6 +105,7 @@ public:
protected:
QPaintDevice();
virtual int metric(PaintDeviceMetric metric) const;
virtual void init(QPainter *painter) const;
ushort painters; // refcount

View 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) {

View 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;