From d073dfb82c02c1d0a9818525a2a4a4f1adbf44bf Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 2 Nov 2009 16:47:29 +1000 Subject: renaming QmlGraphicsRect -> QmlGraphicsRectangle --- src/declarative/graphicsitems/graphicsitems.pri | 6 +- src/declarative/graphicsitems/qmlgraphicsrect.cpp | 475 --------------------- src/declarative/graphicsitems/qmlgraphicsrect_p.h | 189 -------- .../graphicsitems/qmlgraphicsrect_p_p.h | 109 ----- .../graphicsitems/qmlgraphicsrectangle.cpp | 475 +++++++++++++++++++++ .../graphicsitems/qmlgraphicsrectangle_p.h | 189 ++++++++ .../graphicsitems/qmlgraphicsrectangle_p_p.h | 109 +++++ tests/auto/declarative/anchors/tst_anchors.cpp | 54 +-- .../auto/declarative/animations/tst_animations.cpp | 22 +- tests/auto/declarative/behaviors/tst_behaviors.cpp | 30 +- tests/auto/declarative/layouts/tst_layouts.cpp | 44 +- tests/auto/declarative/pathview/tst_pathview.cpp | 18 +- .../declarative/qmllanguage/tst_qmllanguage.cpp | 14 +- tests/auto/declarative/states/tst_states.cpp | 22 +- tests/benchmarks/qmlpainting/tst_qmlpainting.cpp | 6 +- 15 files changed, 881 insertions(+), 881 deletions(-) delete mode 100644 src/declarative/graphicsitems/qmlgraphicsrect.cpp delete mode 100644 src/declarative/graphicsitems/qmlgraphicsrect_p.h delete mode 100644 src/declarative/graphicsitems/qmlgraphicsrect_p_p.h create mode 100644 src/declarative/graphicsitems/qmlgraphicsrectangle.cpp create mode 100644 src/declarative/graphicsitems/qmlgraphicsrectangle_p.h create mode 100644 src/declarative/graphicsitems/qmlgraphicsrectangle_p_p.h diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index 8eac580..15d775c 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -28,8 +28,8 @@ HEADERS += \ graphicsitems/qmlgraphicspath_p_p.h \ graphicsitems/qmlgraphicspathview_p.h \ graphicsitems/qmlgraphicspathview_p_p.h \ - graphicsitems/qmlgraphicsrect_p.h \ - graphicsitems/qmlgraphicsrect_p_p.h \ + graphicsitems/qmlgraphicsrectangle_p.h \ + graphicsitems/qmlgraphicsrectangle_p_p.h \ graphicsitems/qmlgraphicsrepeater_p.h \ graphicsitems/qmlgraphicsrepeater_p_p.h \ graphicsitems/qmlgraphicsscalegrid_p_p.h \ @@ -64,7 +64,7 @@ SOURCES += \ graphicsitems/qmlgraphicsmouseregion.cpp \ graphicsitems/qmlgraphicspath.cpp \ graphicsitems/qmlgraphicspathview.cpp \ - graphicsitems/qmlgraphicsrect.cpp \ + graphicsitems/qmlgraphicsrectangle.cpp \ graphicsitems/qmlgraphicsrepeater.cpp \ graphicsitems/qmlgraphicsscalegrid.cpp \ graphicsitems/qmlgraphicstextinput.cpp \ diff --git a/src/declarative/graphicsitems/qmlgraphicsrect.cpp b/src/declarative/graphicsitems/qmlgraphicsrect.cpp deleted file mode 100644 index 605e82c..0000000 --- a/src/declarative/graphicsitems/qmlgraphicsrect.cpp +++ /dev/null @@ -1,475 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative 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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmlgraphicsrect_p.h" -#include "qmlgraphicsrect_p_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pen,QmlGraphicsPen) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GradientStop,QmlGraphicsGradientStop) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Gradient,QmlGraphicsGradient) - -/*! - \internal - \class QmlGraphicsPen - \brief The QmlGraphicsPen class provides a pen used for drawing rectangle borders on a QmlView. - - By default, the pen is invalid and nothing is drawn. You must either set a color (then the default - width is 1) or a width (then the default color is black). - - A width of 1 indicates is a single-pixel line on the border of the item being painted. - - Example: - \qml - Rectangle { border.width: 2; border.color: "red" ... } - \endqml -*/ - -void QmlGraphicsPen::setColor(const QColor &c) -{ - _color = c; - _valid = _color.alpha() ? true : false; - emit penChanged(); -} - -void QmlGraphicsPen::setWidth(int w) -{ - if (_width == w && _valid) - return; - - _width = w; - _valid = (_width < 1) ? false : true; - emit penChanged(); -} - - -/*! - \qmlclass GradientStop QmlGraphicsGradientStop - \brief The GradientStop item defines the color at a position in a Gradient - - \sa Gradient -*/ - -/*! - \qmlproperty real GradientStop::position - \qmlproperty color GradientStop::color - - Sets a \e color at a \e position in a gradient. -*/ - -void QmlGraphicsGradientStop::updateGradient() -{ - if (QmlGraphicsGradient *grad = qobject_cast(parent())) - grad->doUpdate(); -} - -/*! - \qmlclass Gradient QmlGraphicsGradient - \brief The Gradient item defines a gradient fill. - - A gradient is defined by two or more colors, which will be blended seemlessly. The - colors are specified at their position in the range 0.0 - 1.0 via - the GradientStop item. For example, the following code paints a - rectangle with a gradient starting with red, blending to yellow at 1/3 of the - size of the rectangle, and ending with Green: - - \table - \row - \o \image gradient.png - \o \quotefile doc/src/snippets/declarative/gradient.qml - \endtable - - \sa GradientStop -*/ - -/*! - \qmlproperty list Gradient::stops - This property holds the gradient stops describing the gradient. -*/ - -const QGradient *QmlGraphicsGradient::gradient() const -{ - if (!m_gradient && !m_stops.isEmpty()) { - m_gradient = new QLinearGradient(0,0,0,1.0); - for (int i = 0; i < m_stops.count(); ++i) { - const QmlGraphicsGradientStop *stop = m_stops.at(i); - m_gradient->setCoordinateMode(QGradient::ObjectBoundingMode); - m_gradient->setColorAt(stop->position(), stop->color()); - } - } - - return m_gradient; -} - -void QmlGraphicsGradient::doUpdate() -{ - delete m_gradient; - m_gradient = 0; - emit updated(); -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rectangle,QmlGraphicsRect) - -/*! - \qmlclass Rectangle QmlGraphicsRect - \brief The Rectangle item allows you to add rectangles to a scene. - \inherits Item - - A Rectangle is painted having a solid fill (color) and an optional border. - You can also create rounded rectangles using the radius property. - - \qml - Rectangle { - width: 100 - height: 100 - color: "red" - border.color: "black" - border.width: 5 - radius: 10 - } - \endqml - - \image declarative-rect.png -*/ - -/*! - \internal - \class QmlGraphicsRect - \brief The QmlGraphicsRect class provides a rectangle item that you can add to a QmlView. -*/ -QmlGraphicsRect::QmlGraphicsRect(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsRectPrivate), parent) -{ - Q_D(QmlGraphicsRect); - d->init(); - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QmlGraphicsRect::QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - Q_D(QmlGraphicsRect); - d->init(); - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -void QmlGraphicsRect::doUpdate() -{ - Q_D(QmlGraphicsRect); - d->rectImage = QPixmap(); - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - d->setPaintMargin((pw+1)/2); - update(); -} - -/*! - \qmlproperty int Rectangle::border.width - \qmlproperty color Rectangle::border.color - - The width and color used to draw the border of the rectangle. - - A width of 1 creates a thin line. For no line, use a width of 0 or a transparent color. - - To keep the border smooth (rather than blurry), odd widths cause the rectangle to be painted at - a half-pixel offset; -*/ -QmlGraphicsPen *QmlGraphicsRect::border() -{ - Q_D(QmlGraphicsRect); - return d->getPen(); -} - -/*! - \qmlproperty Gradient Rectangle::gradient - - The gradient to use to fill the rectangle. - - This property allows for the construction of simple vertical gradients. - Other gradients may by formed by adding rotation to the rectangle. - - \table - \row - \o \image declarative-rect_gradient.png - \o - \qml - Rectangle { y: 0; width: 80; height: 80; color: "lightsteelblue" } - Rectangle { y: 100; width: 80; height: 80 - gradient: Gradient { - GradientStop { position: 0.0; color: "lightsteelblue" } - GradientStop { position: 1.0; color: "blue" } - } - } - Rectangle { rotation: 90; x: 80; y: 200; width: 80; height: 80 - gradient: Gradient { - GradientStop { position: 0.0; color: "lightsteelblue" } - GradientStop { position: 1.0; color: "blue" } - } - } - // The x offset is needed because the rotation is from the top left corner - \endqml - \endtable - - If both a gradient and a color are specified, the gradient will be used. - - \sa Gradient, color -*/ -QmlGraphicsGradient *QmlGraphicsRect::gradient() const -{ - Q_D(const QmlGraphicsRect); - return d->gradient; -} - -void QmlGraphicsRect::setGradient(QmlGraphicsGradient *gradient) -{ - Q_D(QmlGraphicsRect); - if (d->gradient == gradient) - return; - if (d->gradient) - disconnect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); - d->gradient = gradient; - if (d->gradient) - connect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); - update(); -} - - -/*! - \qmlproperty real Rectangle::radius - This property holds the corner radius used to draw a rounded rectangle. - - If radius is non-zero, the rectangle will be painted as a rounded rectangle, otherwise it will be - painted as a normal rectangle. The same radius is used by all 4 corners; there is currently - no way to specify different radii for different corners. -*/ -qreal QmlGraphicsRect::radius() const -{ - Q_D(const QmlGraphicsRect); - return d->radius; -} - -void QmlGraphicsRect::setRadius(qreal radius) -{ - Q_D(QmlGraphicsRect); - if (d->radius == radius) - return; - - d->radius = radius; - d->rectImage = QPixmap(); - update(); - emit radiusChanged(); -} - -/*! - \qmlproperty color Rectangle::color - This property holds the color used to fill the rectangle. - - \qml - // green rectangle using hexidecimal notation - Rectangle { color: "#00FF00" } - - // steelblue rectangle using SVG color name - Rectangle { color: "steelblue" } - \endqml - - The default color is white. - - If both a gradient and a color are specified, the gradient will be used. -*/ -QColor QmlGraphicsRect::color() const -{ - Q_D(const QmlGraphicsRect); - return d->color; -} - -void QmlGraphicsRect::setColor(const QColor &c) -{ - Q_D(QmlGraphicsRect); - if (d->color == c) - return; - - d->color = c; - d->rectImage = QPixmap(); - update(); - emit colorChanged(); -} - -void QmlGraphicsRect::generateRoundedRect() -{ - Q_D(QmlGraphicsRect); - if (d->rectImage.isNull()) { - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - const int radius = qCeil(d->radius); //ensure odd numbered width/height so we get 1-pixel center - d->rectImage = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); - d->rectImage.fill(Qt::transparent); - QPainter p(&(d->rectImage)); - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(d->color); - if (pw%2) - p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)), d->radius, d->radius); - else - p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw), d->radius, d->radius); - } -} - -void QmlGraphicsRect::generateBorderedRect() -{ - Q_D(QmlGraphicsRect); - if (d->rectImage.isNull()) { - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); - d->rectImage.fill(Qt::transparent); - QPainter p(&(d->rectImage)); - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - pn.setJoinStyle(Qt::MiterJoin); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(d->color); - if (pw%2) - p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1))); - else - p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw)); - } -} - -void QmlGraphicsRect::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - Q_D(QmlGraphicsRect); - if (d->radius > 0 || (d->pen && d->pen->isValid()) - || (d->gradient && d->gradient->gradient()) ) { - drawRect(*p); - } - else { - bool oldAA = p->testRenderHint(QPainter::Antialiasing); - if (d->smooth) - p->setRenderHints(QPainter::Antialiasing, true); - p->fillRect(QRectF(0, 0, width(), height()), d->color); - if (d->smooth) - p->setRenderHint(QPainter::Antialiasing, oldAA); - } -} - -void QmlGraphicsRect::drawRect(QPainter &p) -{ - Q_D(QmlGraphicsRect); - if (d->gradient && d->gradient->gradient()) { - // XXX This path is still slower than the image path - // Image path won't work for gradients though - bool oldAA = p.testRenderHint(QPainter::Antialiasing); - if (d->smooth) - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(*d->gradient->gradient()); - if (d->radius > 0.) - p.drawRoundedRect(0, 0, width(), height(), d->radius, d->radius); - else - p.drawRect(0, 0, width(), height()); - if (d->smooth) - p.setRenderHint(QPainter::Antialiasing, oldAA); - } else { - bool oldAA = p.testRenderHint(QPainter::Antialiasing); - bool oldSmooth = p.testRenderHint(QPainter::SmoothPixmapTransform); - if (d->smooth) - p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); - - const int pw = d->pen && d->pen->isValid() ? (d->pen->width()+1)/2*2 : 0; - - if (d->radius > 0) - generateRoundedRect(); - else - generateBorderedRect(); - - int xOffset = (d->rectImage.width()-1)/2; - int yOffset = (d->rectImage.height()-1)/2; - Q_ASSERT(d->rectImage.width() == 2*xOffset + 1); - Q_ASSERT(d->rectImage.height() == 2*yOffset + 1); - - QMargins margins(xOffset, yOffset, xOffset, yOffset); - QTileRules rules(Qt::StretchTile, Qt::StretchTile); - //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects - qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width()+pw, height()+pw), margins, d->rectImage, d->rectImage.rect(), margins, rules); - - if (d->smooth) { - p.setRenderHint(QPainter::Antialiasing, oldAA); - p.setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); - } - } -} - -/*! - \qmlproperty bool Rectangle::smooth - - Set this property if you want the item to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the item is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the item is stationary on - the screen. A common pattern when animating an item is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. - - \image rect-smooth.png -*/ - -QRectF QmlGraphicsRect::boundingRect() const -{ - Q_D(const QmlGraphicsRect); - return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2); -} - -QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicsrect_p.h b/src/declarative/graphicsitems/qmlgraphicsrect_p.h deleted file mode 100644 index 97334fd..0000000 --- a/src/declarative/graphicsitems/qmlgraphicsrect_p.h +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative 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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLGRAPHICSRECT_H -#define QMLGRAPHICSRECT_H - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QmlGraphicsPen : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged) - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) -public: - QmlGraphicsPen(QObject *parent=0) - : QObject(parent), _width(1), _color("#000000"), _valid(false) - {} - - int width() const { return _width; } - void setWidth(int w); - - QColor color() const { return _color; } - void setColor(const QColor &c); - - bool isValid() { return _valid; }; - -Q_SIGNALS: - void penChanged(); - -private: - int _width; - QColor _color; - bool _valid; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGradientStop : public QObject -{ - Q_OBJECT - - Q_PROPERTY(qreal position READ position WRITE setPosition) - Q_PROPERTY(QColor color READ color WRITE setColor) - -public: - QmlGraphicsGradientStop(QObject *parent=0) : QObject(parent) {} - - qreal position() const { return m_position; } - void setPosition(qreal position) { m_position = position; updateGradient(); } - - QColor color() const { return m_color; } - void setColor(const QColor &color) { m_color = color; updateGradient(); } - -private: - void updateGradient(); - -private: - qreal m_position; - QColor m_color; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QList *stops READ stops) - Q_CLASSINFO("DefaultProperty", "stops") - -public: - QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} - ~QmlGraphicsGradient() { delete m_gradient; } - - QList *stops() { return &m_stops; } - - const QGradient *gradient() const; - -Q_SIGNALS: - void updated(); - -private: - void doUpdate(); - -private: - QList m_stops; - mutable QGradient *m_gradient; - friend class QmlGraphicsGradientStop; -}; - -class QmlGraphicsRectPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsRect : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - Q_PROPERTY(QmlGraphicsGradient *gradient READ gradient WRITE setGradient) - Q_PROPERTY(QmlGraphicsPen * border READ border CONSTANT) - Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) -public: - QmlGraphicsRect(QmlGraphicsItem *parent=0); - - QColor color() const; - void setColor(const QColor &); - - QmlGraphicsPen *border(); - - QmlGraphicsGradient *gradient() const; - void setGradient(QmlGraphicsGradient *gradient); - - qreal radius() const; - void setRadius(qreal radius); - - QRectF boundingRect() const; - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -Q_SIGNALS: - void colorChanged(); - void radiusChanged(); - -private Q_SLOTS: - void doUpdate(); - -private: - void generateRoundedRect(); - void generateBorderedRect(); - void drawRect(QPainter &painter); - -protected: - QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsRect) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRect) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsPen) -QML_DECLARE_TYPE(QmlGraphicsGradientStop) -QML_DECLARE_TYPE(QmlGraphicsGradient) -QML_DECLARE_TYPE(QmlGraphicsRect) - -QT_END_HEADER - -#endif // QMLGRAPHICSRECT_H diff --git a/src/declarative/graphicsitems/qmlgraphicsrect_p_p.h b/src/declarative/graphicsitems/qmlgraphicsrect_p_p.h deleted file mode 100644 index f44e8de..0000000 --- a/src/declarative/graphicsitems/qmlgraphicsrect_p_p.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLGRAPHICSRECT_P_H -#define QMLGRAPHICSRECT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qmlgraphicsitem_p.h" - -QT_BEGIN_NAMESPACE - -class QmlGraphicsGradient; -class QmlGraphicsRect; -class QmlGraphicsRectPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsRect) - -public: - QmlGraphicsRectPrivate() : - color(Qt::white), gradient(0), pen(0), radius(0), paintmargin(0) - { - } - - ~QmlGraphicsRectPrivate() - { - delete pen; - } - - void init() - { - } - - QColor getColor(); - QColor color; - QmlGraphicsGradient *gradient; - QmlGraphicsPen *getPen() { - if (!pen) { - Q_Q(QmlGraphicsRect); - pen = new QmlGraphicsPen; - QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); - } - return pen; - } - QmlGraphicsPen *pen; - qreal radius; - qreal paintmargin; - QPixmap rectImage; - - void setPaintMargin(qreal margin) - { - Q_Q(QmlGraphicsRect); - if (margin == paintmargin) - return; - q->prepareGeometryChange(); - paintmargin = margin; - } -}; - -QT_END_NAMESPACE - -#endif // QMLGRAPHICSRECT_P_H diff --git a/src/declarative/graphicsitems/qmlgraphicsrectangle.cpp b/src/declarative/graphicsitems/qmlgraphicsrectangle.cpp new file mode 100644 index 0000000..8ae40b7 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsrectangle.cpp @@ -0,0 +1,475 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlgraphicsrectangle_p.h" +#include "qmlgraphicsrectangle_p_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pen,QmlGraphicsPen) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GradientStop,QmlGraphicsGradientStop) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Gradient,QmlGraphicsGradient) + +/*! + \internal + \class QmlGraphicsPen + \brief The QmlGraphicsPen class provides a pen used for drawing rectangle borders on a QmlView. + + By default, the pen is invalid and nothing is drawn. You must either set a color (then the default + width is 1) or a width (then the default color is black). + + A width of 1 indicates is a single-pixel line on the border of the item being painted. + + Example: + \qml + Rectangle { border.width: 2; border.color: "red" ... } + \endqml +*/ + +void QmlGraphicsPen::setColor(const QColor &c) +{ + _color = c; + _valid = _color.alpha() ? true : false; + emit penChanged(); +} + +void QmlGraphicsPen::setWidth(int w) +{ + if (_width == w && _valid) + return; + + _width = w; + _valid = (_width < 1) ? false : true; + emit penChanged(); +} + + +/*! + \qmlclass GradientStop QmlGraphicsGradientStop + \brief The GradientStop item defines the color at a position in a Gradient + + \sa Gradient +*/ + +/*! + \qmlproperty real GradientStop::position + \qmlproperty color GradientStop::color + + Sets a \e color at a \e position in a gradient. +*/ + +void QmlGraphicsGradientStop::updateGradient() +{ + if (QmlGraphicsGradient *grad = qobject_cast(parent())) + grad->doUpdate(); +} + +/*! + \qmlclass Gradient QmlGraphicsGradient + \brief The Gradient item defines a gradient fill. + + A gradient is defined by two or more colors, which will be blended seemlessly. The + colors are specified at their position in the range 0.0 - 1.0 via + the GradientStop item. For example, the following code paints a + rectangle with a gradient starting with red, blending to yellow at 1/3 of the + size of the rectangle, and ending with Green: + + \table + \row + \o \image gradient.png + \o \quotefile doc/src/snippets/declarative/gradient.qml + \endtable + + \sa GradientStop +*/ + +/*! + \qmlproperty list Gradient::stops + This property holds the gradient stops describing the gradient. +*/ + +const QGradient *QmlGraphicsGradient::gradient() const +{ + if (!m_gradient && !m_stops.isEmpty()) { + m_gradient = new QLinearGradient(0,0,0,1.0); + for (int i = 0; i < m_stops.count(); ++i) { + const QmlGraphicsGradientStop *stop = m_stops.at(i); + m_gradient->setCoordinateMode(QGradient::ObjectBoundingMode); + m_gradient->setColorAt(stop->position(), stop->color()); + } + } + + return m_gradient; +} + +void QmlGraphicsGradient::doUpdate() +{ + delete m_gradient; + m_gradient = 0; + emit updated(); +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rectangle,QmlGraphicsRectangle) + +/*! + \qmlclass Rectangle QmlGraphicsRectangle + \brief The Rectangle item allows you to add rectangles to a scene. + \inherits Item + + A Rectangle is painted having a solid fill (color) and an optional border. + You can also create rounded rectangles using the radius property. + + \qml + Rectangle { + width: 100 + height: 100 + color: "red" + border.color: "black" + border.width: 5 + radius: 10 + } + \endqml + + \image declarative-rect.png +*/ + +/*! + \internal + \class QmlGraphicsRectangle + \brief The QmlGraphicsRectangle class provides a rectangle item that you can add to a QmlView. +*/ +QmlGraphicsRectangle::QmlGraphicsRectangle(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsRectanglePrivate), parent) +{ + Q_D(QmlGraphicsRectangle); + d->init(); + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QmlGraphicsRectangle::QmlGraphicsRectangle(QmlGraphicsRectanglePrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + Q_D(QmlGraphicsRectangle); + d->init(); + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +void QmlGraphicsRectangle::doUpdate() +{ + Q_D(QmlGraphicsRectangle); + d->rectImage = QPixmap(); + const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; + d->setPaintMargin((pw+1)/2); + update(); +} + +/*! + \qmlproperty int Rectangle::border.width + \qmlproperty color Rectangle::border.color + + The width and color used to draw the border of the rectangle. + + A width of 1 creates a thin line. For no line, use a width of 0 or a transparent color. + + To keep the border smooth (rather than blurry), odd widths cause the rectangle to be painted at + a half-pixel offset; +*/ +QmlGraphicsPen *QmlGraphicsRectangle::border() +{ + Q_D(QmlGraphicsRectangle); + return d->getPen(); +} + +/*! + \qmlproperty Gradient Rectangle::gradient + + The gradient to use to fill the rectangle. + + This property allows for the construction of simple vertical gradients. + Other gradients may by formed by adding rotation to the rectangle. + + \table + \row + \o \image declarative-rect_gradient.png + \o + \qml + Rectangle { y: 0; width: 80; height: 80; color: "lightsteelblue" } + Rectangle { y: 100; width: 80; height: 80 + gradient: Gradient { + GradientStop { position: 0.0; color: "lightsteelblue" } + GradientStop { position: 1.0; color: "blue" } + } + } + Rectangle { rotation: 90; x: 80; y: 200; width: 80; height: 80 + gradient: Gradient { + GradientStop { position: 0.0; color: "lightsteelblue" } + GradientStop { position: 1.0; color: "blue" } + } + } + // The x offset is needed because the rotation is from the top left corner + \endqml + \endtable + + If both a gradient and a color are specified, the gradient will be used. + + \sa Gradient, color +*/ +QmlGraphicsGradient *QmlGraphicsRectangle::gradient() const +{ + Q_D(const QmlGraphicsRectangle); + return d->gradient; +} + +void QmlGraphicsRectangle::setGradient(QmlGraphicsGradient *gradient) +{ + Q_D(QmlGraphicsRectangle); + if (d->gradient == gradient) + return; + if (d->gradient) + disconnect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + d->gradient = gradient; + if (d->gradient) + connect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + update(); +} + + +/*! + \qmlproperty real Rectangle::radius + This property holds the corner radius used to draw a rounded rectangle. + + If radius is non-zero, the rectangle will be painted as a rounded rectangle, otherwise it will be + painted as a normal rectangle. The same radius is used by all 4 corners; there is currently + no way to specify different radii for different corners. +*/ +qreal QmlGraphicsRectangle::radius() const +{ + Q_D(const QmlGraphicsRectangle); + return d->radius; +} + +void QmlGraphicsRectangle::setRadius(qreal radius) +{ + Q_D(QmlGraphicsRectangle); + if (d->radius == radius) + return; + + d->radius = radius; + d->rectImage = QPixmap(); + update(); + emit radiusChanged(); +} + +/*! + \qmlproperty color Rectangle::color + This property holds the color used to fill the rectangle. + + \qml + // green rectangle using hexidecimal notation + Rectangle { color: "#00FF00" } + + // steelblue rectangle using SVG color name + Rectangle { color: "steelblue" } + \endqml + + The default color is white. + + If both a gradient and a color are specified, the gradient will be used. +*/ +QColor QmlGraphicsRectangle::color() const +{ + Q_D(const QmlGraphicsRectangle); + return d->color; +} + +void QmlGraphicsRectangle::setColor(const QColor &c) +{ + Q_D(QmlGraphicsRectangle); + if (d->color == c) + return; + + d->color = c; + d->rectImage = QPixmap(); + update(); + emit colorChanged(); +} + +void QmlGraphicsRectangle::generateRoundedRect() +{ + Q_D(QmlGraphicsRectangle); + if (d->rectImage.isNull()) { + const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; + const int radius = qCeil(d->radius); //ensure odd numbered width/height so we get 1-pixel center + d->rectImage = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); + d->rectImage.fill(Qt::transparent); + QPainter p(&(d->rectImage)); + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(d->color); + if (pw%2) + p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)), d->radius, d->radius); + else + p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw), d->radius, d->radius); + } +} + +void QmlGraphicsRectangle::generateBorderedRect() +{ + Q_D(QmlGraphicsRectangle); + if (d->rectImage.isNull()) { + const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; + d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); + d->rectImage.fill(Qt::transparent); + QPainter p(&(d->rectImage)); + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + pn.setJoinStyle(Qt::MiterJoin); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(d->color); + if (pw%2) + p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1))); + else + p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw)); + } +} + +void QmlGraphicsRectangle::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + Q_D(QmlGraphicsRectangle); + if (d->radius > 0 || (d->pen && d->pen->isValid()) + || (d->gradient && d->gradient->gradient()) ) { + drawRect(*p); + } + else { + bool oldAA = p->testRenderHint(QPainter::Antialiasing); + if (d->smooth) + p->setRenderHints(QPainter::Antialiasing, true); + p->fillRect(QRectF(0, 0, width(), height()), d->color); + if (d->smooth) + p->setRenderHint(QPainter::Antialiasing, oldAA); + } +} + +void QmlGraphicsRectangle::drawRect(QPainter &p) +{ + Q_D(QmlGraphicsRectangle); + if (d->gradient && d->gradient->gradient()) { + // XXX This path is still slower than the image path + // Image path won't work for gradients though + bool oldAA = p.testRenderHint(QPainter::Antialiasing); + if (d->smooth) + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(*d->gradient->gradient()); + if (d->radius > 0.) + p.drawRoundedRect(0, 0, width(), height(), d->radius, d->radius); + else + p.drawRect(0, 0, width(), height()); + if (d->smooth) + p.setRenderHint(QPainter::Antialiasing, oldAA); + } else { + bool oldAA = p.testRenderHint(QPainter::Antialiasing); + bool oldSmooth = p.testRenderHint(QPainter::SmoothPixmapTransform); + if (d->smooth) + p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); + + const int pw = d->pen && d->pen->isValid() ? (d->pen->width()+1)/2*2 : 0; + + if (d->radius > 0) + generateRoundedRect(); + else + generateBorderedRect(); + + int xOffset = (d->rectImage.width()-1)/2; + int yOffset = (d->rectImage.height()-1)/2; + Q_ASSERT(d->rectImage.width() == 2*xOffset + 1); + Q_ASSERT(d->rectImage.height() == 2*yOffset + 1); + + QMargins margins(xOffset, yOffset, xOffset, yOffset); + QTileRules rules(Qt::StretchTile, Qt::StretchTile); + //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects + qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width()+pw, height()+pw), margins, d->rectImage, d->rectImage.rect(), margins, rules); + + if (d->smooth) { + p.setRenderHint(QPainter::Antialiasing, oldAA); + p.setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); + } + } +} + +/*! + \qmlproperty bool Rectangle::smooth + + Set this property if you want the item to be smoothly scaled or + transformed. Smooth filtering gives better visual quality, but is slower. If + the item is displayed at its natural size, this property has no visual or + performance effect. + + \note Generally scaling artifacts are only visible if the item is stationary on + the screen. A common pattern when animating an item is to disable smooth + filtering at the beginning of the animation and reenable it at the conclusion. + + \image rect-smooth.png +*/ + +QRectF QmlGraphicsRectangle::boundingRect() const +{ + Q_D(const QmlGraphicsRectangle); + return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2); +} + +QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h b/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h new file mode 100644 index 0000000..2a80619 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLGRAPHICSRECT_H +#define QMLGRAPHICSRECT_H + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class Q_DECLARATIVE_EXPORT QmlGraphicsPen : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) +public: + QmlGraphicsPen(QObject *parent=0) + : QObject(parent), _width(1), _color("#000000"), _valid(false) + {} + + int width() const { return _width; } + void setWidth(int w); + + QColor color() const { return _color; } + void setColor(const QColor &c); + + bool isValid() { return _valid; }; + +Q_SIGNALS: + void penChanged(); + +private: + int _width; + QColor _color; + bool _valid; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGradientStop : public QObject +{ + Q_OBJECT + + Q_PROPERTY(qreal position READ position WRITE setPosition) + Q_PROPERTY(QColor color READ color WRITE setColor) + +public: + QmlGraphicsGradientStop(QObject *parent=0) : QObject(parent) {} + + qreal position() const { return m_position; } + void setPosition(qreal position) { m_position = position; updateGradient(); } + + QColor color() const { return m_color; } + void setColor(const QColor &color) { m_color = color; updateGradient(); } + +private: + void updateGradient(); + +private: + qreal m_position; + QColor m_color; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QList *stops READ stops) + Q_CLASSINFO("DefaultProperty", "stops") + +public: + QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} + ~QmlGraphicsGradient() { delete m_gradient; } + + QList *stops() { return &m_stops; } + + const QGradient *gradient() const; + +Q_SIGNALS: + void updated(); + +private: + void doUpdate(); + +private: + QList m_stops; + mutable QGradient *m_gradient; + friend class QmlGraphicsGradientStop; +}; + +class QmlGraphicsRectanglePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsRectangle : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QmlGraphicsGradient *gradient READ gradient WRITE setGradient) + Q_PROPERTY(QmlGraphicsPen * border READ border CONSTANT) + Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) +public: + QmlGraphicsRectangle(QmlGraphicsItem *parent=0); + + QColor color() const; + void setColor(const QColor &); + + QmlGraphicsPen *border(); + + QmlGraphicsGradient *gradient() const; + void setGradient(QmlGraphicsGradient *gradient); + + qreal radius() const; + void setRadius(qreal radius); + + QRectF boundingRect() const; + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +Q_SIGNALS: + void colorChanged(); + void radiusChanged(); + +private Q_SLOTS: + void doUpdate(); + +private: + void generateRoundedRect(); + void generateBorderedRect(); + void drawRect(QPainter &painter); + +protected: + QmlGraphicsRectangle(QmlGraphicsRectanglePrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsRectangle) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRectangle) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsPen) +QML_DECLARE_TYPE(QmlGraphicsGradientStop) +QML_DECLARE_TYPE(QmlGraphicsGradient) +QML_DECLARE_TYPE(QmlGraphicsRectangle) + +QT_END_HEADER + +#endif // QMLGRAPHICSRECT_H diff --git a/src/declarative/graphicsitems/qmlgraphicsrectangle_p_p.h b/src/declarative/graphicsitems/qmlgraphicsrectangle_p_p.h new file mode 100644 index 0000000..cb914d6 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsrectangle_p_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLGRAPHICSRECT_P_H +#define QMLGRAPHICSRECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlgraphicsitem_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsGradient; +class QmlGraphicsRectangle; +class QmlGraphicsRectanglePrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsRectangle) + +public: + QmlGraphicsRectanglePrivate() : + color(Qt::white), gradient(0), pen(0), radius(0), paintmargin(0) + { + } + + ~QmlGraphicsRectanglePrivate() + { + delete pen; + } + + void init() + { + } + + QColor getColor(); + QColor color; + QmlGraphicsGradient *gradient; + QmlGraphicsPen *getPen() { + if (!pen) { + Q_Q(QmlGraphicsRectangle); + pen = new QmlGraphicsPen; + QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); + } + return pen; + } + QmlGraphicsPen *pen; + qreal radius; + qreal paintmargin; + QPixmap rectImage; + + void setPaintMargin(qreal margin) + { + Q_Q(QmlGraphicsRectangle); + if (margin == paintmargin) + return; + q->prepareGeometryChange(); + paintmargin = margin; + } +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSRECT_P_H diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 60c6b3d..2d81b21 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -95,41 +95,41 @@ void tst_anchors::basicAnchors() qApp->processEvents(); //sibling horizontal - QCOMPARE(findItem(view->root(), QLatin1String("Rect1"))->x(), 26.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect2"))->x(), 122.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect3"))->x(), 74.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect4"))->x(), 16.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect5"))->x(), 112.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect6"))->x(), 64.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect1"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect2"))->x(), 122.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect3"))->x(), 74.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect4"))->x(), 16.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect5"))->x(), 112.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect6"))->x(), 64.0); //parent horizontal - QCOMPARE(findItem(view->root(), QLatin1String("Rect7"))->x(), 0.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect8"))->x(), 240.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect9"))->x(), 120.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect10"))->x(), -10.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect11"))->x(), 230.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect12"))->x(), 110.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect7"))->x(), 0.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect8"))->x(), 240.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect9"))->x(), 120.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect10"))->x(), -10.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect11"))->x(), 230.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect12"))->x(), 110.0); //vertical - QCOMPARE(findItem(view->root(), QLatin1String("Rect13"))->y(), 20.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect14"))->y(), 155.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect13"))->y(), 20.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect14"))->y(), 155.0); //stretch - QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->x(), 26.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->width(), 96.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->x(), 26.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->width(), 192.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->x(), -70.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->width(), 192.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->width(), 96.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->width(), 192.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->x(), -70.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->width(), 192.0); //vertical stretch - QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->y(), 20.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->height(), 40.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->y(), 20.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->height(), 40.0); //more parent horizontal - QCOMPARE(findItem(view->root(), QLatin1String("Rect19"))->x(), 115.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect20"))->x(), 235.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect21"))->x(), -5.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect19"))->x(), 115.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect20"))->x(), 235.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect21"))->x(), -5.0); delete view; } @@ -173,7 +173,7 @@ void tst_anchors::illegalSets() view->setUrl(QUrl("file://" SRCDIR "/data/illegal1.qml")); - QString expect = "QML QmlGraphicsRect (" + view->url().toString() + ":7:5" + ") Can't specify left, right, and hcenter anchors."; + QString expect = "QML QmlGraphicsRectangle (" + view->url().toString() + ":7:5" + ") Can't specify left, right, and hcenter anchors."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); qApp->processEvents(); @@ -199,7 +199,7 @@ void tst_anchors::illegalSets() view->setUrl(QUrl("file://" SRCDIR "/data/illegal3.qml")); - QString expect = "QML QmlGraphicsRect (" + view->url().toString() + ":9:5" + ") Can't anchor to an item that isn't a parent or sibling."; + QString expect = "QML QmlGraphicsRectangle (" + view->url().toString() + ":9:5" + ") Can't anchor to an item that isn't a parent or sibling."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); //qApp->processEvents(); diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index 77a31e5..c0e26ca 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -72,7 +72,7 @@ private slots: void tst_animations::simpleNumber() { - QmlGraphicsRect rect; + QmlGraphicsRectangle rect; QmlNumberAnimation animation; animation.setTarget(&rect); animation.setProperty("x"); @@ -90,7 +90,7 @@ void tst_animations::simpleNumber() void tst_animations::simpleColor() { - QmlGraphicsRect rect; + QmlGraphicsRectangle rect; QmlColorAnimation animation; animation.setTarget(&rect); animation.setProperty("color"); @@ -108,7 +108,7 @@ void tst_animations::simpleColor() void tst_animations::alwaysRunToEnd() { - QmlGraphicsRect rect; + QmlGraphicsRectangle rect; QmlPropertyAnimation animation; animation.setTarget(&rect); animation.setProperty("x"); @@ -126,7 +126,7 @@ void tst_animations::alwaysRunToEnd() void tst_animations::dotProperty() { - QmlGraphicsRect rect; + QmlGraphicsRectangle rect; QmlNumberAnimation animation; animation.setTarget(&rect); animation.setProperty("border.width"); @@ -181,12 +181,12 @@ void tst_animations::badTypes() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badtype4.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("state1"); QTest::qWait(1000 + 50); - QmlGraphicsRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRectangle *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust QVERIFY(myRect); QCOMPARE(myRect->x(),qreal(200)); } @@ -198,7 +198,7 @@ void tst_animations::badProperties() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badproperty1.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); QTest::ignoreMessage(QtWarningMsg, "QML QmlColorAnimation (file://" SRCDIR "/data/badproperty1.qml:22:9) Cannot animate non-existant property \"pen.colr\""); @@ -214,12 +214,12 @@ void tst_animations::mixedTypes() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/mixedtype1.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("state1"); QTest::qWait(500); - QmlGraphicsRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRectangle *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust QVERIFY(myRect); //rather inexact -- is there a better way? @@ -230,12 +230,12 @@ void tst_animations::mixedTypes() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/mixedtype2.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("state1"); QTest::qWait(500); - QmlGraphicsRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRectangle *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust QVERIFY(myRect); //rather inexact -- is there a better way? diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index aea5604..449deb9 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -66,12 +66,12 @@ void tst_behaviors::simpleBehavior() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } @@ -79,12 +79,12 @@ void tst_behaviors::scriptTriggered() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/scripttrigger.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setColor(QColor("red")); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } @@ -92,10 +92,10 @@ void tst_behaviors::cppTriggered() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/cpptrigger.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - QmlGraphicsRect *innerRect = qobject_cast(rect->findChild("MyRect")); + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect); innerRect->setProperty("x", 200); @@ -108,7 +108,7 @@ void tst_behaviors::loop() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/loop.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); //don't crash @@ -119,12 +119,12 @@ void tst_behaviors::colorBehavior() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/color.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("red"); QTest::qWait(100); - QColor color = qobject_cast(rect->findChild("MyRect"))->color(); + QColor color = qobject_cast(rect->findChild("MyRect"))->color(); QVERIFY(color != QColor("red") && color != QColor("green")); //i.e. the behavior has been triggered } @@ -132,12 +132,12 @@ void tst_behaviors::replaceBinding() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/binding.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - QmlGraphicsRect *innerRect = qobject_cast(rect->findChild("MyRect")); + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect); qreal x = innerRect->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered @@ -167,24 +167,24 @@ void tst_behaviors::group() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/groupProperty.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/groupProperty2.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } } diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index fbcc904..ab675b8 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -73,13 +73,13 @@ void tst_QmlGraphicsLayouts::test_horizontal() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -97,13 +97,13 @@ void tst_QmlGraphicsLayouts::test_horizontal_spacing() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -121,13 +121,13 @@ void tst_QmlGraphicsLayouts::test_vertical() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -145,13 +145,13 @@ void tst_QmlGraphicsLayouts::test_vertical_spacing() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -169,15 +169,15 @@ void tst_QmlGraphicsLayouts::test_grid() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); - QmlGraphicsRect *four = canvas->root()->findChild("four"); + QmlGraphicsRectangle *four = canvas->root()->findChild("four"); QVERIFY(four != 0); - QmlGraphicsRect *five = canvas->root()->findChild("five"); + QmlGraphicsRectangle *five = canvas->root()->findChild("five"); QVERIFY(five != 0); QCOMPARE(one->x(), 0.0); @@ -199,15 +199,15 @@ void tst_QmlGraphicsLayouts::test_grid_spacing() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); - QmlGraphicsRect *four = canvas->root()->findChild("four"); + QmlGraphicsRectangle *four = canvas->root()->findChild("four"); QVERIFY(four != 0); - QmlGraphicsRect *five = canvas->root()->findChild("five"); + QmlGraphicsRectangle *five = canvas->root()->findChild("five"); QVERIFY(five != 0); QCOMPARE(one->x(), 0.0); diff --git a/tests/auto/declarative/pathview/tst_pathview.cpp b/tests/auto/declarative/pathview/tst_pathview.cpp index 41decb1..93e4754 100644 --- a/tests/auto/declarative/pathview/tst_pathview.cpp +++ b/tests/auto/declarative/pathview/tst_pathview.cpp @@ -190,7 +190,7 @@ void tst_QmlGraphicsPathView::pathMoved() QmlGraphicsPathView *pathview = findItem(canvas->root(), "view"); QVERIFY(pathview != 0); - QmlGraphicsRect *firstItem = findItem(pathview, "wrapper", 0); + QmlGraphicsRectangle *firstItem = findItem(pathview, "wrapper", 0); QVERIFY(firstItem); QmlGraphicsPath *path = qobject_cast(pathview->path()); QVERIFY(path); @@ -203,7 +203,7 @@ void tst_QmlGraphicsPathView::pathMoved() QTest::qWait(1000);//Moving is animated? for(int i=0; i(pathview, "wrapper", i); + QmlGraphicsRectangle *curItem = findItem(pathview, "wrapper", i); QCOMPARE(curItem->pos() + offset, path->pointAt(0.1 + i*0.25)); } @@ -234,22 +234,22 @@ void tst_QmlGraphicsPathView::limitedItems() pathview->setPathItemCount(10); QCOMPARE(pathview->pathItemCount(), 10); - QmlGraphicsRect *testItem = findItem(pathview, "wrapper", 0); + QmlGraphicsRectangle *testItem = findItem(pathview, "wrapper", 0); QVERIFY(testItem != 0); - testItem = findItem(pathview, "wrapper", 9); + testItem = findItem(pathview, "wrapper", 9); QVERIFY(testItem != 0); - testItem = findItem(pathview, "wrapper", 10); + testItem = findItem(pathview, "wrapper", 10); QVERIFY(testItem == 0); pathview->setCurrentIndex(50); QTest::qWait(5100);//Moving is animated and it's travelling far - should be reconsidered. - testItem = findItem(pathview, "wrapper", 0); + testItem = findItem(pathview, "wrapper", 0); QVERIFY(testItem == 0); - testItem = findItem(pathview, "wrapper", 1); + testItem = findItem(pathview, "wrapper", 1); QVERIFY(testItem == 0); - testItem = findItem(pathview, "wrapper", 9); + testItem = findItem(pathview, "wrapper", 9); QVERIFY(testItem == 0); - testItem = findItem(pathview, "wrapper", 50); + testItem = findItem(pathview, "wrapper", 50); QVERIFY(testItem != 0); } diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 7dfb0ff..128fa87 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -987,11 +987,11 @@ void tst_qmllanguage::importsLocal_data() QTest::newRow("local import") << "import \"subdir\"\n" // QT-613 "Test {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("local import as") << "import \"subdir\" as T\n" "T.Test {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("wrong local import as") << "import \"subdir\" as T\n" "Test {}" @@ -1019,7 +1019,7 @@ void tst_qmllanguage::importsRemote_data() + QtNetworkSettings::serverName() + "/qtest/declarative/qmllanguage"; - QTest::newRow("remote import") << "import \""+serverdir+"\"\nTest {}" << "QmlGraphicsRect"; + QTest::newRow("remote import") << "import \""+serverdir+"\"\nTest {}" << "QmlGraphicsRectangle"; QTest::newRow("remote import with subdir") << "import \""+serverdir+"\"\nTestSubDir {}" << "QmlGraphicsText"; QTest::newRow("remote import with local") << "import \""+serverdir+"\"\nTestLocal {}" << "QmlGraphicsImage"; } @@ -1042,7 +1042,7 @@ void tst_qmllanguage::importsInstalled_data() QTest::newRow("installed import 1") << "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("installed import 2") << "import com.nokia.installedtest 1.4\n" "InstalledTest {}" @@ -1075,7 +1075,7 @@ void tst_qmllanguage::importsOrder_data() "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("installed import re-overrides 1") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" @@ -1088,13 +1088,13 @@ void tst_qmllanguage::importsOrder_data() "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("installed import versus builtin 1") << "import com.nokia.installedtest 1.5\n" "import Qt 4.6\n" "Rectangle {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("installed import versus builtin 2") << "import Qt 4.6\n" "import com.nokia.installedtest 1.5\n" diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index 4425eac..e362050 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -62,7 +62,7 @@ void tst_states::basicChanges() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -76,7 +76,7 @@ void tst_states::basicChanges() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges2.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -96,7 +96,7 @@ void tst_states::basicChanges() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges3.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -132,7 +132,7 @@ void tst_states::basicExtension() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicExtension.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -165,7 +165,7 @@ void tst_states::basicExtension() { QmlComponent rectComponent(&engine, SRCDIR "/data/fakeExtension.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -196,7 +196,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -223,7 +223,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding2.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -253,7 +253,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding3.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -277,7 +277,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding4.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -303,7 +303,7 @@ void tst_states::basicBinding() } } -class MyRect : public QmlGraphicsRect +class MyRect : public QmlGraphicsRectangle { Q_OBJECT public: @@ -343,7 +343,7 @@ void tst_states::signalOverride() rect->doSomething(); QCOMPARE(rect->color(),QColor("blue")); - QmlGraphicsRect *innerRect = qobject_cast(rect->findChild("extendedRect")); + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("extendedRect")); innerRect->setState("green"); rect->doSomething(); diff --git a/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp b/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp index 0af4858..e268136 100644 --- a/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp +++ b/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp @@ -327,7 +327,7 @@ void tst_QmlPainting::drawTransformedImageRoundedRect() surface.save("ti.png"); } -//code from QmlGraphicsRect for drawing rounded rects +//code from QmlGraphicsRectangle for drawing rounded rects void tst_QmlPainting::drawScaleGridRoundedRect() { //setup image @@ -422,7 +422,7 @@ void tst_QmlPainting::drawScaledScaleGridRoundedRect_data() // QTest::newRow(QString(QLatin1String("scale=%1; imagetype=ARGB8565_Pre")).arg(i).toLatin1()) << i << (int)QImage::Format_ARGB8565_Premultiplied; } -//code from QmlGraphicsRect for drawing rounded rects +//code from QmlGraphicsRectangle for drawing rounded rects void tst_QmlPainting::drawScaledScaleGridRoundedRect() { QFETCH(float, scale); @@ -522,7 +522,7 @@ void tst_QmlPainting::drawTransformedScaleGridRoundedRect_data() } -//code from QmlGraphicsRect for drawing rounded rects +//code from QmlGraphicsRectangle for drawing rounded rects void tst_QmlPainting::drawTransformedScaleGridRoundedRect() { QFETCH(QTransform, transform); -- cgit v0.12