summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Vattekar <geir.vattekar@trolltech.com>2009-09-01 11:37:11 (GMT)
committerGeir Vattekar <geir.vattekar@trolltech.com>2009-09-01 11:37:11 (GMT)
commitdac400ea66c9342d2e5d4455141de64c9cd703dd (patch)
tree32492e660831d2532f49f8ca4bae0de3c5f3df5c
parent4f19cd391aa32b12b9f749af06ebe6836cd0cbae (diff)
parentd3cf11841763ab222ae0ca62468e83a695116514 (diff)
downloadQt-dac400ea66c9342d2e5d4455141de64c9cd703dd.zip
Qt-dac400ea66c9342d2e5d4455141de64c9cd703dd.tar.gz
Qt-dac400ea66c9342d2e5d4455141de64c9cd703dd.tar.bz2
Merge branch '4.6' of git@scm.dev.nokia.troll.no:qt/qt into 4.6
-rw-r--r--src/gui/effects/qgraphicseffect.cpp43
-rw-r--r--src/gui/effects/qgraphicseffect.h20
-rw-r--r--tests/benchmarks/qgraphicsanchorlayout/qgraphicsanchorlayout.pro6
-rw-r--r--tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp197
4 files changed, 264 insertions, 2 deletions
diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp
index ccbf7fc..2be6a49 100644
--- a/src/gui/effects/qgraphicseffect.cpp
+++ b/src/gui/effects/qgraphicseffect.cpp
@@ -349,6 +349,22 @@ void QGraphicsEffect::setEnabled(bool enable)
*/
/*!
+ Schedules a redraw of the source. Call this function whenever the source
+ needs to be redrawn.
+
+ This convenience function is equivalent to calling
+ QGraphicsEffectSource::update().
+
+ \sa updateBoundingRect(), QGraphicsEffectSource::update()
+*/
+void QGraphicsEffect::update()
+{
+ Q_D(QGraphicsEffect);
+ if (d->source)
+ d->source->update();
+}
+
+/*!
Returns a pointer to the source, which provides extra context information
that can be useful for the effect.
@@ -366,6 +382,8 @@ QGraphicsEffectSource *QGraphicsEffect::source() const
function whenever you change any parameters that will cause the virtual
boundingRectFor() function to return a different value.
+ This function will call update() if this is necessary.
+
\sa boundingRectFor(), boundingRect()
*/
void QGraphicsEffect::updateBoundingRect()
@@ -523,6 +541,7 @@ void QGraphicsColorizeEffect::setColor(const QColor &color)
return;
d->filter->setColor(color);
+ update();
emit colorChanged(color);
}
@@ -610,6 +629,7 @@ void QGraphicsPixelizeEffect::setPixelSize(int size)
return;
d->pixelSize = size;
+ update();
emit pixelSizeChanged(size);
}
@@ -820,7 +840,7 @@ QGraphicsDropShadowEffect::~QGraphicsDropShadowEffect()
By default, the offset is 8 pixels towards the lower right.
- \sa blurRadius(), color()
+ \sa xOffset(), yOffset(), blurRadius(), color()
*/
QPointF QGraphicsDropShadowEffect::offset() const
{
@@ -840,6 +860,24 @@ void QGraphicsDropShadowEffect::setOffset(const QPointF &offset)
}
/*!
+ \property QGraphicsDropShadowEffect::xOffset
+ \brief the horizontal shadow offset in pixels.
+
+ By default, the horizontal shadow offset is 8 pixels.
+
+ \sa yOffset(), offset()
+*/
+
+/*!
+ \property QGraphicsDropShadowEffect::yOffset
+ \brief the vertical shadow offset in pixels.
+
+ By default, the vertical shadow offset is 8 pixels.
+
+ \sa xOffset(), offset()
+*/
+
+/*!
\fn void QGraphicsDropShadowEffect::offsetChanged(const QPointF &offset)
This signal is emitted whenever the effect's shadow offset changes.
@@ -903,6 +941,7 @@ void QGraphicsDropShadowEffect::setColor(const QColor &color)
return;
d->filter->setColor(color);
+ update();
emit colorChanged(color);
}
@@ -1012,6 +1051,7 @@ void QGraphicsOpacityEffect::setOpacity(qreal opacity)
d->isFullyOpaque = 0;
else
d->isFullyOpaque = qFuzzyIsNull(d->opacity - 1);
+ update();
emit opacityChanged(opacity);
}
@@ -1050,6 +1090,7 @@ void QGraphicsOpacityEffect::setOpacityMask(const QBrush &mask)
d->opacityMask = mask;
d->hasOpacityMask = (mask.style() != Qt::NoBrush);
+ update();
emit opacityMaskChanged(mask);
}
diff --git a/src/gui/effects/qgraphicseffect.h b/src/gui/effects/qgraphicseffect.h
index 8e5384c..aee7834 100644
--- a/src/gui/effects/qgraphicseffect.h
+++ b/src/gui/effects/qgraphicseffect.h
@@ -118,7 +118,7 @@ public:
public Q_SLOTS:
void setEnabled(bool enable);
- // ### add update() slot
+ void update();
Q_SIGNALS:
void enabledChanged(bool enabled);
@@ -237,6 +237,8 @@ class Q_GUI_EXPORT QGraphicsDropShadowEffect: public QGraphicsEffect
{
Q_OBJECT
Q_PROPERTY(QPointF offset READ offset WRITE setOffset NOTIFY offsetChanged)
+ Q_PROPERTY(qreal xOffset READ xOffset WRITE setXOffset NOTIFY offsetChanged)
+ Q_PROPERTY(qreal yOffset READ yOffset WRITE setYOffset NOTIFY offsetChanged)
Q_PROPERTY(int blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
public:
@@ -245,15 +247,31 @@ public:
QRectF boundingRectFor(const QRectF &rect) const;
QPointF offset() const;
+
+ inline qreal xOffset() const
+ { return offset().x(); }
+
+ inline qreal yOffset() const
+ { return offset().y(); }
+
int blurRadius() const;
QColor color() const;
public Q_SLOTS:
void setOffset(const QPointF &ofs);
+
inline void setOffset(qreal dx, qreal dy)
{ setOffset(QPointF(dx, dy)); }
+
inline void setOffset(qreal d)
{ setOffset(QPointF(d, d)); }
+
+ inline void setXOffset(qreal dx)
+ { setOffset(QPointF(dx, yOffset())); }
+
+ inline void setYOffset(qreal dy)
+ { setOffset(QPointF(xOffset(), dy)); }
+
void setBlurRadius(int blurRadius);
void setColor(const QColor &color);
diff --git a/tests/benchmarks/qgraphicsanchorlayout/qgraphicsanchorlayout.pro b/tests/benchmarks/qgraphicsanchorlayout/qgraphicsanchorlayout.pro
new file mode 100644
index 0000000..0d563b9
--- /dev/null
+++ b/tests/benchmarks/qgraphicsanchorlayout/qgraphicsanchorlayout.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qgraphicsanchorlayout
+
+SOURCES += tst_qgraphicsanchorlayout.cpp
+
diff --git a/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
new file mode 100644
index 0000000..e419bae
--- /dev/null
+++ b/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtGui/qgraphicsanchorlayout.h>
+#include <QtGui/qgraphicswidget.h>
+#include <QtGui/qgraphicsview.h>
+
+class tst_QGraphicsAnchorLayout : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QGraphicsAnchorLayout() {}
+ ~tst_QGraphicsAnchorLayout() {}
+
+private slots:
+ void s60_hard_complex_data();
+ void s60_hard_complex();
+};
+
+
+class RectWidget : public QGraphicsWidget
+{
+public:
+ RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent){}
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ {
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+ painter->drawRoundRect(rect());
+ painter->drawLine(rect().topLeft(), rect().bottomRight());
+ painter->drawLine(rect().bottomLeft(), rect().topRight());
+ }
+};
+
+static QGraphicsWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0),
+ const QSizeF &preferred = QSize(150.0, 100.0),
+ const QSizeF &maximum = QSizeF(200.0, 100.0),
+ const QString &name = QString())
+{
+ QGraphicsWidget *w = new RectWidget;
+ w->setMinimumSize(minimum);
+ w->setPreferredSize(preferred);
+ w->setMaximumSize(maximum);
+ w->setData(0, name);
+ return w;
+}
+
+static void setAnchor(QGraphicsAnchorLayout *l,
+ QGraphicsLayoutItem *firstItem,
+ Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem,
+ Qt::AnchorPoint secondEdge,
+ qreal spacing)
+{
+ l->addAnchor(firstItem, firstEdge, secondItem, secondEdge);
+ l->setAnchorSpacing(firstItem, firstEdge, secondItem, secondEdge, spacing);
+}
+
+void tst_QGraphicsAnchorLayout::s60_hard_complex_data()
+{
+ QTest::addColumn<int>("whichSizeHint");
+ QTest::newRow("minimumSizeHint")
+ << int(Qt::MinimumSize);
+ QTest::newRow("preferredSizeHint")
+ << int(Qt::PreferredSize);
+ QTest::newRow("maximumSizeHint")
+ << int(Qt::MaximumSize);
+ // Add it as a reference to see how much overhead the body of effectiveSizeHint takes.
+ QTest::newRow("noSizeHint")
+ << -1;
+}
+
+void tst_QGraphicsAnchorLayout::s60_hard_complex()
+{
+ QFETCH(int, whichSizeHint);
+
+ // Test for "hard" complex case, taken from wiki
+ // https://cwiki.nokia.com/S60QTUI/AnchorLayoutComplexCases
+ QSizeF min(0, 10);
+ QSizeF pref(50, 10);
+ QSizeF max(100, 10);
+
+ QGraphicsWidget *a = createItem(min, pref, max, "a");
+ QGraphicsWidget *b = createItem(min, pref, max, "b");
+ QGraphicsWidget *c = createItem(min, pref, max, "c");
+ QGraphicsWidget *d = createItem(min, pref, max, "d");
+ QGraphicsWidget *e = createItem(min, pref, max, "e");
+ QGraphicsWidget *f = createItem(min, pref, max, "f");
+ QGraphicsWidget *g = createItem(min, pref, max, "g");
+
+ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
+ l->setContentsMargins(0, 0, 0, 0);
+
+ //<!-- Trunk -->
+ setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 10);
+ setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 10);
+ setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 10);
+ setAnchor(l, c, Qt::AnchorRight, d, Qt::AnchorLeft, 10);
+ setAnchor(l, d, Qt::AnchorRight, l, Qt::AnchorRight, 10);
+
+ //<!-- Above trunk -->
+ setAnchor(l, b, Qt::AnchorLeft, e, Qt::AnchorLeft, 10);
+ setAnchor(l, e, Qt::AnchorRight, d, Qt::AnchorLeft, 10);
+
+ //<!-- Below trunk -->
+ setAnchor(l, a, Qt::AnchorHorizontalCenter, g, Qt::AnchorLeft, 10);
+ setAnchor(l, g, Qt::AnchorRight, f, Qt::AnchorHorizontalCenter, 10);
+ setAnchor(l, c, Qt::AnchorLeft, f, Qt::AnchorLeft, 10);
+ setAnchor(l, f, Qt::AnchorRight, d, Qt::AnchorRight, 10);
+
+ //<!-- vertical is simpler -->
+ setAnchor(l, l, Qt::AnchorTop, e, Qt::AnchorTop, 0);
+ setAnchor(l, e, Qt::AnchorBottom, a, Qt::AnchorTop, 0);
+ setAnchor(l, e, Qt::AnchorBottom, b, Qt::AnchorTop, 0);
+ setAnchor(l, e, Qt::AnchorBottom, c, Qt::AnchorTop, 0);
+ setAnchor(l, e, Qt::AnchorBottom, d, Qt::AnchorTop, 0);
+ setAnchor(l, a, Qt::AnchorBottom, f, Qt::AnchorTop, 0);
+ setAnchor(l, a, Qt::AnchorBottom, b, Qt::AnchorBottom, 0);
+ setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorBottom, 0);
+ setAnchor(l, a, Qt::AnchorBottom, d, Qt::AnchorBottom, 0);
+ setAnchor(l, f, Qt::AnchorBottom, g, Qt::AnchorTop, 0);
+ setAnchor(l, g, Qt::AnchorBottom, l, Qt::AnchorBottom, 0);
+
+ // It won't query the size hint if it already has a size set.
+ // If only one of the sizes is unset it will query sizeHint only of for that hint type.
+ l->setMinimumSize(60,40);
+ l->setPreferredSize(220,40);
+ l->setMaximumSize(240,40);
+
+ switch (whichSizeHint) {
+ case Qt::MinimumSize:
+ l->setMinimumSize(-1, -1);
+ break;
+ case Qt::PreferredSize:
+ l->setPreferredSize(-1, -1);
+ break;
+ case Qt::MaximumSize:
+ l->setMaximumSize(-1, -1);
+ break;
+ default:
+ break;
+ }
+
+ QSizeF sizeHint;
+ // warm up instruction cache
+ l->invalidate();
+ sizeHint = l->effectiveSizeHint((Qt::SizeHint)whichSizeHint);
+ // ...then measure...
+ QBENCHMARK {
+ l->invalidate();
+ sizeHint = l->effectiveSizeHint((Qt::SizeHint)whichSizeHint);
+ }
+}
+
+QTEST_MAIN(tst_QGraphicsAnchorLayout)
+
+#include "tst_qgraphicsanchorlayout.moc"