summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-11-02 16:10:04 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-11-02 16:10:04 (GMT)
commitc7386b14e0c9844db91ca0d2ae6bded6efa008aa (patch)
treef39a0e2b8c4d14b9947ffa6d5403fa229bb8fa17 /src/gui
parent915f20bb167aa09ca8c8db478a2a78d5e357b67e (diff)
parentab473d6a8e4fa619537c4cdaaf1b6a9d8544b30a (diff)
downloadQt-c7386b14e0c9844db91ca0d2ae6bded6efa008aa.zip
Qt-c7386b14e0c9844db91ca0d2ae6bded6efa008aa.tar.gz
Qt-c7386b14e0c9844db91ca0d2ae6bded6efa008aa.tar.bz2
Merge branch '4.6' of git@scm.dev.nokia.troll.no:qt/qt-graphics-team into 4.6
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/effects/qgraphicseffect.cpp64
-rw-r--r--src/gui/effects/qgraphicseffect.h14
-rw-r--r--src/gui/effects/qgraphicseffect_p.h2
-rw-r--r--src/gui/image/qpixmapfilter.cpp18
-rw-r--r--src/gui/image/qpixmapfilter_p.h5
-rw-r--r--src/gui/painting/qstroker.cpp23
-rw-r--r--src/gui/painting/qwindowsurface_x11.cpp6
7 files changed, 104 insertions, 28 deletions
diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp
index f24d424..3b94a5d 100644
--- a/src/gui/effects/qgraphicseffect.cpp
+++ b/src/gui/effects/qgraphicseffect.cpp
@@ -212,7 +212,23 @@ const QStyleOption *QGraphicsEffectSource::styleOption() const
*/
void QGraphicsEffectSource::draw(QPainter *painter)
{
- d_func()->draw(painter);
+ Q_D(const QGraphicsEffectSource);
+
+ QPixmap pm;
+ if (QPixmapCache::find(d->m_cacheKey, &pm)) {
+ QTransform restoreTransform;
+ if (d->m_cachedSystem == Qt::DeviceCoordinates) {
+ restoreTransform = painter->worldTransform();
+ painter->setWorldTransform(QTransform());
+ }
+
+ painter->drawPixmap(d->m_cachedOffset, pm);
+
+ if (d->m_cachedSystem == Qt::DeviceCoordinates)
+ painter->setWorldTransform(restoreTransform);
+ } else {
+ d_func()->draw(painter);
+ }
}
/*!
@@ -287,6 +303,13 @@ QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offse
return pm;
}
+void QGraphicsEffectSourcePrivate::invalidateCache(bool effectRectChanged) const
+{
+ if (effectRectChanged && m_cachedMode != QGraphicsEffectSource::ExpandToEffectRectPadMode)
+ return;
+ QPixmapCache::remove(m_cacheKey);
+}
+
/*!
Constructs a new QGraphicsEffect instance having the
specified \a parent.
@@ -426,7 +449,7 @@ void QGraphicsEffect::updateBoundingRect()
Q_D(QGraphicsEffect);
if (d->source) {
d->source->d_func()->effectBoundingRectChanged();
- d->source->d_func()->invalidateCache();
+ d->source->d_func()->invalidateCache(true);
}
}
@@ -614,6 +637,26 @@ void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *sou
*/
/*!
+ \enum QGraphicsBlurEffect::BlurHint
+ \since 4.6
+
+ This enum describes the possible hints that can be used to control how
+ blur effects are applied. The hints might not have an effect in all the
+ paint engines.
+
+ \value QualityHint Indicates that rendering quality is the most important factor,
+ at the potential cost of lower performance.
+
+ \value PerformanceHint Indicates that rendering performance is the most important factor,
+ at the potential cost of lower quality.
+
+ \value AnimationHint Indicates that the blur radius is going to be animated, hinting
+ that the implementation can keep a cache of blurred verisons of the source pixmap.
+ Do not use this hint if the source item is going to be dynamically changing.
+*/
+
+
+/*!
Constructs a new QGraphicsBlurEffect instance.
The \a parent parameter is passed to QGraphicsEffect's constructor.
*/
@@ -621,7 +664,7 @@ QGraphicsBlurEffect::QGraphicsBlurEffect(QObject *parent)
: QGraphicsEffect(*new QGraphicsBlurEffectPrivate, parent)
{
Q_D(QGraphicsBlurEffect);
- d->filter->setBlurHint(Qt::PerformanceHint);
+ d->filter->setBlurHint(QGraphicsBlurEffect::PerformanceHint);
}
/*!
@@ -668,20 +711,19 @@ void QGraphicsBlurEffect::setBlurRadius(qreal radius)
\property QGraphicsBlurEffect::blurHint
\brief the blur hint of the effect.
- Use the Qt::PerformanceHint hint to say that you want a faster blur,
- and the Qt::QualityHint hint to say that you prefer a higher quality blur.
-
- When animating the blur radius it's recommended to use Qt::PerformanceHint.
+ Use the PerformanceHint hint to say that you want a faster blur,
+ the QualityHint hint to say that you prefer a higher quality blur,
+ or the AnimationHint when you want to animate the blur radius.
- By default, the blur hint is Qt::PerformanceHint.
+ By default, the blur hint is PerformanceHint.
*/
-Qt::RenderHint QGraphicsBlurEffect::blurHint() const
+QGraphicsBlurEffect::BlurHint QGraphicsBlurEffect::blurHint() const
{
Q_D(const QGraphicsBlurEffect);
return d->filter->blurHint();
}
-void QGraphicsBlurEffect::setBlurHint(Qt::RenderHint hint)
+void QGraphicsBlurEffect::setBlurHint(QGraphicsBlurEffect::BlurHint hint)
{
Q_D(QGraphicsBlurEffect);
if (d->filter->blurHint() == hint)
@@ -692,7 +734,7 @@ void QGraphicsBlurEffect::setBlurHint(Qt::RenderHint hint)
}
/*!
- \fn void QGraphicsBlurEffect::blurHintChanged(Qt::RenderHint hint)
+ \fn void QGraphicsBlurEffect::blurHintChanged(Qt::BlurHint hint)
This signal is emitted whenever the effect's blur hint changes.
The \a hint parameter holds the effect's new blur hint.
diff --git a/src/gui/effects/qgraphicseffect.h b/src/gui/effects/qgraphicseffect.h
index bf18581..7335a25 100644
--- a/src/gui/effects/qgraphicseffect.h
+++ b/src/gui/effects/qgraphicseffect.h
@@ -183,22 +183,28 @@ class Q_GUI_EXPORT QGraphicsBlurEffect: public QGraphicsEffect
{
Q_OBJECT
Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
- Q_PROPERTY(Qt::RenderHint blurHint READ blurHint WRITE setBlurHint NOTIFY blurHintChanged)
+ Q_PROPERTY(BlurHint blurHint READ blurHint WRITE setBlurHint NOTIFY blurHintChanged)
public:
+ enum BlurHint {
+ QualityHint,
+ PerformanceHint,
+ AnimationHint
+ };
+
QGraphicsBlurEffect(QObject *parent = 0);
~QGraphicsBlurEffect();
QRectF boundingRectFor(const QRectF &rect) const;
qreal blurRadius() const;
- Qt::RenderHint blurHint() const;
+ BlurHint blurHint() const;
public Q_SLOTS:
void setBlurRadius(qreal blurRadius);
- void setBlurHint(Qt::RenderHint hint);
+ void setBlurHint(BlurHint hint);
Q_SIGNALS:
void blurRadiusChanged(qreal blurRadius);
- void blurHintChanged(Qt::RenderHint hint);
+ void blurHintChanged(BlurHint hint);
protected:
void draw(QPainter *painter, QGraphicsEffectSource *source);
diff --git a/src/gui/effects/qgraphicseffect_p.h b/src/gui/effects/qgraphicseffect_p.h
index 1ed7103..0ff5794 100644
--- a/src/gui/effects/qgraphicseffect_p.h
+++ b/src/gui/effects/qgraphicseffect_p.h
@@ -85,7 +85,7 @@ public:
virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = 0,
QGraphicsEffectSource::PixmapPadMode mode = QGraphicsEffectSource::ExpandToTransparentBorderPadMode) const = 0;
virtual void effectBoundingRectChanged() = 0;
- void invalidateCache() const { QPixmapCache::remove(m_cacheKey); }
+ void invalidateCache(bool effectRectChanged = false) const;
friend class QGraphicsScenePrivate;
friend class QGraphicsItem;
diff --git a/src/gui/image/qpixmapfilter.cpp b/src/gui/image/qpixmapfilter.cpp
index d0de03e..e50cc8b 100644
--- a/src/gui/image/qpixmapfilter.cpp
+++ b/src/gui/image/qpixmapfilter.cpp
@@ -504,10 +504,10 @@ void QPixmapConvolutionFilter::draw(QPainter *painter, const QPointF &p, const Q
class QPixmapBlurFilterPrivate : public QPixmapFilterPrivate
{
public:
- QPixmapBlurFilterPrivate() : radius(5), hint(Qt::PerformanceHint) {}
+ QPixmapBlurFilterPrivate() : radius(5), hint(QGraphicsBlurEffect::PerformanceHint) {}
qreal radius;
- Qt::RenderHint hint;
+ QGraphicsBlurEffect::BlurHint hint;
};
@@ -556,12 +556,18 @@ qreal QPixmapBlurFilter::radius() const
Setting the blur hint to PerformanceHint causes the implementation
to trade off visual quality to blur the image faster. Setting the
blur hint to QualityHint causes the implementation to improve
- visual quality at the expense of speed. The implementation is free
- to ignore this value if it only has a single blur algorithm.
+ visual quality at the expense of speed.
+
+ AnimationHint causes the implementation to optimize for animating
+ the blur radius, possibly by caching blurred versions of the source
+ pixmap.
+
+ The implementation is free to ignore this value if it only has a single
+ blur algorithm.
\internal
*/
-void QPixmapBlurFilter::setBlurHint(Qt::RenderHint hint)
+void QPixmapBlurFilter::setBlurHint(QGraphicsBlurEffect::BlurHint hint)
{
Q_D(QPixmapBlurFilter);
d->hint = hint;
@@ -572,7 +578,7 @@ void QPixmapBlurFilter::setBlurHint(Qt::RenderHint hint)
\internal
*/
-Qt::RenderHint QPixmapBlurFilter::blurHint() const
+QGraphicsBlurEffect::BlurHint QPixmapBlurFilter::blurHint() const
{
Q_D(const QPixmapBlurFilter);
return d->hint;
diff --git a/src/gui/image/qpixmapfilter_p.h b/src/gui/image/qpixmapfilter_p.h
index fc70795..6a96676 100644
--- a/src/gui/image/qpixmapfilter_p.h
+++ b/src/gui/image/qpixmapfilter_p.h
@@ -55,6 +55,7 @@
#include <QtCore/qnamespace.h>
#include <QtGui/qpixmap.h>
+#include <QtGui/qgraphicseffect.h>
QT_BEGIN_HEADER
@@ -130,10 +131,10 @@ public:
~QPixmapBlurFilter();
void setRadius(qreal radius);
- void setBlurHint(Qt::RenderHint hint);
+ void setBlurHint(QGraphicsBlurEffect::BlurHint hint);
qreal radius() const;
- Qt::RenderHint blurHint() const;
+ QGraphicsBlurEffect::BlurHint blurHint() const;
QRectF boundingRectFor(const QRectF &rect) const;
void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const;
diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp
index c57b3c1..228a6b1 100644
--- a/src/gui/painting/qstroker.cpp
+++ b/src/gui/painting/qstroker.cpp
@@ -452,6 +452,17 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine
#endif
if (join == FlatJoin) {
+ QLineF prevLine(qt_fixed_to_real(m_back2X), qt_fixed_to_real(m_back2Y),
+ qt_fixed_to_real(m_back1X), qt_fixed_to_real(m_back1Y));
+ QPointF isect;
+ QLineF::IntersectType type = prevLine.intersect(nextLine, &isect);
+ QLineF shortCut(prevLine.p2(), nextLine.p1());
+ qreal angle = shortCut.angleTo(prevLine);
+ if (type == QLineF::BoundedIntersection || (angle > 90 && !qFuzzyCompare(angle, (qreal)90))) {
+ emitLineTo(focal_x, focal_y);
+ emitLineTo(qt_real_to_fixed(nextLine.x1()), qt_real_to_fixed(nextLine.y1()));
+ return;
+ }
emitLineTo(qt_real_to_fixed(nextLine.x1()),
qt_real_to_fixed(nextLine.y1()));
@@ -468,8 +479,8 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine
// If we are on the inside, do the short cut...
QLineF shortCut(prevLine.p2(), nextLine.p1());
qreal angle = shortCut.angleTo(prevLine);
-
if (type == QLineF::BoundedIntersection || (angle > 90 && !qFuzzyCompare(angle, (qreal)90))) {
+ emitLineTo(focal_x, focal_y);
emitLineTo(qt_real_to_fixed(nextLine.x1()), qt_real_to_fixed(nextLine.y1()));
return;
}
@@ -509,8 +520,9 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine
qfixed offset = m_strokeWidth / 2;
QLineF shortCut(prevLine.p2(), nextLine.p1());
- qreal angle = prevLine.angle(shortCut);
+ qreal angle = shortCut.angleTo(prevLine);
if (type == QLineF::BoundedIntersection || (angle > 90 && !qFuzzyCompare(angle, (qreal)90))) {
+ emitLineTo(focal_x, focal_y);
emitLineTo(qt_real_to_fixed(nextLine.x1()), qt_real_to_fixed(nextLine.y1()));
return;
}
@@ -581,6 +593,13 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine
qt_real_to_fixed(l1.x1()),
qt_real_to_fixed(l1.y1()));
} else if (join == SvgMiterJoin) {
+ QLineF shortCut(prevLine.p2(), nextLine.p1());
+ qreal angle = shortCut.angleTo(prevLine);
+ if (type == QLineF::BoundedIntersection || (angle > 90 && !qFuzzyCompare(angle, (qreal)90))) {
+ emitLineTo(focal_x, focal_y);
+ emitLineTo(qt_real_to_fixed(nextLine.x1()), qt_real_to_fixed(nextLine.y1()));
+ return;
+ }
QLineF miterLine(QPointF(qt_fixed_to_real(focal_x),
qt_fixed_to_real(focal_y)), isect);
if (miterLine.length() > qt_fixed_to_real(m_strokeWidth * m_miterLimit) / 2) {
diff --git a/src/gui/painting/qwindowsurface_x11.cpp b/src/gui/painting/qwindowsurface_x11.cpp
index 46c4c42..77e019c 100644
--- a/src/gui/painting/qwindowsurface_x11.cpp
+++ b/src/gui/painting/qwindowsurface_x11.cpp
@@ -94,6 +94,8 @@ QPaintDevice *QX11WindowSurface::paintDevice()
void QX11WindowSurface::beginPaint(const QRegion &rgn)
{
#ifndef QT_NO_XRENDER
+ Q_ASSERT(!d_ptr->device.isNull());
+
if (d_ptr->translucentBackground) {
if (d_ptr->device.depth() != 32)
static_cast<QX11PixmapData *>(d_ptr->device.data_ptr().data())->convertToARGB32();
@@ -157,8 +159,8 @@ void QX11WindowSurface::setGeometry(const QRect &rect)
QPixmap::x11SetDefaultScreen(d_ptr->widget->x11Info().screen());
QX11PixmapData *oldData = static_cast<QX11PixmapData *>(d_ptr->device.pixmapData());
- Q_ASSERT(oldData);
- if (!(oldData->flags & QX11PixmapData::Uninitialized) && hasStaticContents()) {
+
+ if (oldData && !(oldData->flags & QX11PixmapData::Uninitialized) && hasStaticContents()) {
// Copy the content of the old pixmap into the new one.
QX11PixmapData *newData = new QX11PixmapData(QPixmapData::PixmapType);
newData->resize(size.width(), size.height());