summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-05-19 08:08:09 (GMT)
committerRoberto Raggi <roberto.raggi@nokia.com>2009-05-19 08:08:09 (GMT)
commit23c781b67c838b120e7fba42bc9008d38f191330 (patch)
tree4254e4dfd099ad7066b4b02330c1edbee8398086 /src/declarative
parent6e8f112492dec917cdcd9bc50b992eca5d41b998 (diff)
parent6db78166ddfe935a0c968a6e6205a10253d50138 (diff)
downloadQt-23c781b67c838b120e7fba42bc9008d38f191330.zip
Qt-23c781b67c838b120e7fba42bc9008d38f191330.tar.gz
Qt-23c781b67c838b120e7fba42bc9008d38f191330.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/canvas/qsimplecanvasitem.cpp10
-rw-r--r--src/declarative/canvas/qsimplecanvasitem.h1
-rw-r--r--src/declarative/canvas/qsimplecanvasitem_p.h3
-rw-r--r--src/declarative/fx/qfxanchors.cpp5
-rw-r--r--src/declarative/fx/qfxflipable.cpp8
-rw-r--r--src/declarative/fx/qfxparticles.cpp96
-rw-r--r--src/declarative/fx/qfxrect.cpp276
-rw-r--r--src/declarative/fx/qfxrect.h4
-rw-r--r--src/declarative/fx/qfxtransform.cpp28
-rw-r--r--src/declarative/fx/qfxtransform.h5
-rw-r--r--src/declarative/qml/qmlengine.cpp29
-rw-r--r--src/declarative/qml/qmlengine.h2
12 files changed, 341 insertions, 126 deletions
diff --git a/src/declarative/canvas/qsimplecanvasitem.cpp b/src/declarative/canvas/qsimplecanvasitem.cpp
index dfe02c0..fb20e95 100644
--- a/src/declarative/canvas/qsimplecanvasitem.cpp
+++ b/src/declarative/canvas/qsimplecanvasitem.cpp
@@ -181,10 +181,18 @@ void QSimpleCanvasItem::childrenChanged()
{
}
+int QSimpleCanvasItem::setPaintMargin(qreal margin)
+{
+ Q_D(QSimpleCanvasItem);
+ if (margin < d->paintmargin)
+ update(); // schedule repaint of old boundingRect
+ d->paintmargin = margin;
+}
+
QRectF QSimpleCanvasItem::boundingRect() const
{
Q_D(const QSimpleCanvasItem);
- return QRectF(0., 0., d->width, d->height);
+ return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2);
}
void QSimpleCanvasItem::paintContents(QPainter &)
diff --git a/src/declarative/canvas/qsimplecanvasitem.h b/src/declarative/canvas/qsimplecanvasitem.h
index 63be27b..2d65469 100644
--- a/src/declarative/canvas/qsimplecanvasitem.h
+++ b/src/declarative/canvas/qsimplecanvasitem.h
@@ -183,6 +183,7 @@ public:
};
+ int setPaintMargin(qreal margin);
QRectF boundingRect() const;
virtual void paintContents(QPainter &);
virtual void paintGLContents(GLPainter &);
diff --git a/src/declarative/canvas/qsimplecanvasitem_p.h b/src/declarative/canvas/qsimplecanvasitem_p.h
index 34880f0..f0b44e0 100644
--- a/src/declarative/canvas/qsimplecanvasitem_p.h
+++ b/src/declarative/canvas/qsimplecanvasitem_p.h
@@ -142,7 +142,7 @@ public:
focusable(false), wantsActiveFocusPanelPendingCanvas(false),
hasBeenActiveFocusPanel(false),
hasFocus(false), hasActiveFocus(false), needsZOrder(false),
- widthValid(false), heightValid(false), width(0), height(0), scale(1),
+ widthValid(false), heightValid(false), width(0), height(0), paintmargin(0), scale(1),
graphicsItem(0), data_ptr(0)
{
}
@@ -176,6 +176,7 @@ public:
qreal width;
qreal height;
+ qreal paintmargin;
qreal scale;
QSimpleGraphicsItem *graphicsItem;
diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp
index 826d6c1..235511f 100644
--- a/src/declarative/fx/qfxanchors.cpp
+++ b/src/declarative/fx/qfxanchors.cpp
@@ -186,8 +186,10 @@ void QFxAnchorsPrivate::clearItem(QFxItem *item)
fill = 0;
if (centeredIn == item)
centeredIn = 0;
- if (left.item == item)
+ if (left.item == item) {
left.item = 0;
+ usedAnchors &= ~QFxAnchors::HasLeftAnchor;
+ }
if (right.item == item) {
right.item = 0;
usedAnchors &= ~QFxAnchors::HasRightAnchor;
@@ -232,7 +234,6 @@ void QFxAnchorsPrivate::remDepend(QFxItem *item)
bool QFxAnchorsPrivate::isItemComplete() const
{
- return true;
return item->isComponentComplete();
}
diff --git a/src/declarative/fx/qfxflipable.cpp b/src/declarative/fx/qfxflipable.cpp
index 9804004..edcc7cb 100644
--- a/src/declarative/fx/qfxflipable.cpp
+++ b/src/declarative/fx/qfxflipable.cpp
@@ -169,7 +169,6 @@ void QFxFlipable::setBack(QFxItem *back)
children()->append(d->back);
if (Front == d->current)
d->back->setOpacity(0.);
- d->setBackTransform();
}
/*!
@@ -203,8 +202,6 @@ void QFxFlipablePrivate::_q_updateAxis()
axisRotation.axis()->setEndX(axis->endX());
axisRotation.axis()->setEndY(axis->endY());
axisRotation.axis()->setEndZ(axis->endZ());
-
- setBackTransform();
}
void QFxFlipablePrivate::setBackTransform()
@@ -273,8 +270,10 @@ void QFxFlipable::setRotation(qreal angle)
d->current = newSide;
if (d->front)
d->front->setOpacity((d->current==Front)?1.:0.);
- if (d->back)
+ if (d->back) {
+ d->setBackTransform();
d->back->setOpacity((d->current==Back)?1.:0.);
+ }
emit sideChanged();
}
}
@@ -296,7 +295,6 @@ QFxFlipable::Side QFxFlipable::side() const
//(the logic here should be kept in sync with setBackTransform and setRotation)
void QFxFlipable::transformChanged(const QSimpleCanvas::Matrix &trans)
{
- qWarning("Transform changed");
Q_D(QFxFlipable);
QPointF p1(0, 0);
QPointF p2(1, 0);
diff --git a/src/declarative/fx/qfxparticles.cpp b/src/declarative/fx/qfxparticles.cpp
index 1aaf256..930d7a3 100644
--- a/src/declarative/fx/qfxparticles.cpp
+++ b/src/declarative/fx/qfxparticles.cpp
@@ -340,6 +340,32 @@ void QFxParticleMotionWander::destroy(QFxParticle &p)
}
//---------------------------------------------------------------------------
+class QFxParticlesPainter : public QFxItem
+{
+public:
+ QFxParticlesPainter(QFxParticlesPrivate *p, QFxItem* parent)
+ : QFxItem(parent), d(p)
+ {
+ setOptions(HasContents);
+ maxX = minX = maxY = minY = 0;
+ }
+
+#if defined(QFX_RENDER_QPAINTER)
+ void paintContents(QPainter &p);
+#elif defined(QFX_RENDER_OPENGL2)
+ void paintGLContents(GLPainter &);
+#endif
+
+ void updateSize();
+
+ qreal maxX;
+ qreal minX;
+ qreal maxY;
+ qreal minY;
+ QFxParticlesPrivate* d;
+};
+
+//---------------------------------------------------------------------------
class QFxParticlesPrivate : public QFxItemPrivate
{
Q_DECLARE_PUBLIC(QFxParticles)
@@ -359,7 +385,12 @@ public:
{
}
- void init() {}
+ void init()
+ {
+ Q_Q(QFxParticles);
+ paintItem = new QFxParticlesPainter(this, q);
+ }
+
void tick(int time);
void createParticle(int time);
void updateOpacity(QFxParticle &p, int age);
@@ -383,6 +414,7 @@ public:
int streamDelay;
bool emitting;
QFxParticleMotion *motion;
+ QFxParticlesPainter *paintItem;
QList<QFxParticle> particles;
QTickAnimationProxy<QFxParticlesPrivate, &QFxParticlesPrivate::tick> clock;
@@ -1040,28 +1072,76 @@ QString QFxParticles::propertyInfo() const
return d->url.toString();
}
+void QFxParticlesPainter::updateSize(){
+ setX(-500);
+ setY(-500);
+ setWidth(1000);
+ setHeight(1000);
+ return ;
+ const int parentX = parent()->x();
+ const int parentY = parent()->y();
+ //Have to use statistical approach to needed size as arbitrary particle
+ //motions make it impossible to calculate.
+ //max/min vars stored to give a never shrinking rect
+ for (int i = 0; i < d->particles.count(); ++i) {
+ const QFxParticle &particle = d->particles.at(i);
+ if(particle.x > maxX)
+ maxX = particle.x;
+ if(particle.x < minX)
+ minX = particle.x;
+ if(particle.y > maxY)
+ maxY = particle.y;
+ if(particle.y < minY)
+ minY = particle.y;
+ }
+
+ int myWidth = (int)(maxX-minX+0.5)+d->image.width();
+ int myX = (int)(minX - parentX);
+ int myHeight = (int)(maxY-minY+0.5)+d->image.height();
+ int myY = (int)(minY - parentY);
+ setWidth(myWidth);
+ setHeight(myHeight);
+ setX(myX);
+ setY(myY);
+}
+
#if defined(QFX_RENDER_QPAINTER)
void QFxParticles::paintContents(QPainter &p)
{
- Q_D(QFxParticles);
+ Q_UNUSED(p);
+ //painting is done by the ParticlesPainter, so it can have the right size
+}
+
+void QFxParticlesPainter::paintContents(QPainter &p)
+{
if (d->image.isNull())
return;
- const int myX = x();
- const int myY = y();
+ updateSize();
+ const int myX = x() + parent()->x();
+ const int myY = y() + parent()->y();
+
for (int i = 0; i < d->particles.count(); ++i) {
const QFxParticle &particle = d->particles.at(i);
p.setOpacity(particle.opacity);
- p.drawImage(particle.x-myX, particle.y-myY, d->image);
+ p.drawImage(particle.x - myX, particle.y - myY, d->image);
}
+ update();//Should I need this? (GV does)
}
#elif defined(QFX_RENDER_OPENGL2)
void QFxParticles::paintGLContents(GLPainter &p)
{
- Q_D(QFxParticles);
+ //painting is done by the ParticlesPainter, so it can have the right size
+}
+
+void QFxParticlesPainter::paintGLContents(GLPainter &p)
+{
+
if (d->image.isNull())
return;
+ updateSize();
+
if (d->texDirty && !d->image.isNull()) {
d->tex.setImage(d->image);
d->tex.setHorizontalWrap(GLTexture::Repeat);
@@ -1075,8 +1155,8 @@ void QFxParticles::paintGLContents(GLPainter &p)
glBindTexture(GL_TEXTURE_2D, d->tex.texture());
- const int myX = (int)x();
- const int myY = (int)y();
+ const int myX = (int)(x() + parent->x());
+ const int myY = (int)(y() + parent->y());
float widthV = d->image.width();
float heightV = d->image.height();
for (int i = 0; i < d->particles.count(); ++i) {
diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp
index d75a45a..b61baec 100644
--- a/src/declarative/fx/qfxrect.cpp
+++ b/src/declarative/fx/qfxrect.cpp
@@ -52,6 +52,11 @@ QML_DEFINE_TYPE(QFxPen,Pen);
\ingroup group_utility
\brief The QFxPen class provides a pen used for drawing rect borders on a QFxView.
+ By default, the pen is invalid and nothing is drawn. You must either set a color (then the default
+ width is 0) or a width (then the default color is black).
+
+ A width of 0 is a single-pixel line on the border of the item being painted.
+
Example:
\qml
Rect { pen.width: 2; pen.color: "red" ... }
@@ -61,8 +66,9 @@ QML_DEFINE_TYPE(QFxPen,Pen);
/*! \property QFxPen::width
\brief the width of the pen.
- The default width is 1. If the width is less than 1 the pen is considered invalid
- and won't be used.
+ A width of 0 is a single-pixel line on the border of the item being painted.
+
+ If the width is less than 0 the pen is considered invalid and won't be used.
*/
/*!
@@ -86,8 +92,28 @@ QML_DEFINE_TYPE(QFxPen,Pen);
void QFxPen::setColor(const QColor &c)
{
_color = c;
- emit updated();
_valid = _color.alpha() ? true : false;
+ emit updated();
+}
+
+/*!
+ \property QFxPen::width
+ \brief the width of the pen.
+
+ \qml
+ // rect with green border using hexidecimal notation
+ Rect { pen.width: 4 }
+ \endqml
+
+ A width of 0 creates a thin line. For no line, use a negative width or a transparent color.
+
+ Odd pen widths generally lead to half-pixel painting.
+*/
+void QFxPen::setWidth(int w)
+{
+ _width = w;
+ _valid = (_width < 0) ? false : true;
+ emit updated();
}
@@ -167,6 +193,8 @@ void QFxRect::doUpdate()
Q_D(QFxRect);
d->_rectTexture.clear();
#endif
+ const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0;
+ setPaintMargin((pw+1)/2);
update();
}
@@ -372,14 +400,19 @@ void QFxRect::generateRoundedRect()
{
Q_D(QFxRect);
if (d->_rectImage.isNull()) {
- d->_rectImage = QImage(d->_radius*2 + 1, d->_radius*2 + 1, QImage::Format_ARGB32_Premultiplied);
+ const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0;
+ d->_rectImage = QImage(d->_radius*2 + 1 + pw*2, d->_radius*2 + 1 + pw*2, QImage::Format_ARGB32_Premultiplied);
d->_rectImage.fill(0);
QPainter p(&(d->_rectImage));
- QPen pn(QColor(pen()->color()), pen()->width());
p.setRenderHint(QPainter::Antialiasing);
- p.setPen(pn);
+ if (d->_pen && d->_pen->isValid()) {
+ QPen pn(QColor(pen()->color()), pen()->width());
+ p.setPen(pn);
+ } else {
+ p.setPen(Qt::NoPen);
+ }
p.setBrush(d->_color);
- p.drawRoundedRect(0, 0, d->_rectImage.width(), d->_rectImage.height(), d->_radius, d->_radius);
+ p.drawRoundedRect((pw+1)/2, (pw+1)/2, d->_rectImage.width()-(pw+1)/2*2, d->_rectImage.height()-(pw+1)/2*2, d->_radius, d->_radius);
}
}
@@ -387,14 +420,19 @@ void QFxRect::generateBorderedRect()
{
Q_D(QFxRect);
if (d->_rectImage.isNull()) {
- d->_rectImage = QImage(d->pen()->width()*2 + 1, d->pen()->width()*2 + 1, QImage::Format_ARGB32_Premultiplied);
+ const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0;
+ d->_rectImage = QImage(d->pen()->width()*2 + 1 + pw*2, d->pen()->width()*2 + 1 + pw*2, QImage::Format_ARGB32_Premultiplied);
d->_rectImage.fill(0);
QPainter p(&(d->_rectImage));
- QPen pn(QColor(pen()->color()), pen()->width());
p.setRenderHint(QPainter::Antialiasing);
- p.setPen(pn);
+ if (d->_pen && d->_pen->isValid()) {
+ QPen pn(QColor(pen()->color()), pen()->width());
+ p.setPen(pn);
+ } else {
+ p.setPen(Qt::NoPen);
+ }
p.setBrush(d->_color);
- p.drawRect(0, 0, d->_rectImage.width(), d->_rectImage.height());
+ p.drawRect(qreal(pw+1)/2, qreal(pw+1)/2, d->_rectImage.width()-(pw+1)/2*2, d->_rectImage.height()-(pw+1)/2*2);
}
}
#elif defined(QFX_RENDER_OPENGL)
@@ -402,14 +440,19 @@ void QFxRect::generateRoundedRect()
{
Q_D(QFxRect);
if (d->_rectTexture.isNull()) {
- QImage roundRect(int(d->_radius*2 + 1), int(d->_radius*2 + 1), QImage::Format_ARGB32);
+ const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0;
+ QImage roundRect(d->_radius*2 + 4 + pw*2, d->_radius*2 + 4 + pw*2, QImage::Format_ARGB32_Premultiplied);
roundRect.fill(0);
QPainter p(&roundRect);
- QPen pn(QColor(pen()->color()), pen()->width());
p.setRenderHint(QPainter::Antialiasing);
- p.setPen(pn);
+ if (d->_pen && d->_pen->isValid()) {
+ QPen pn(QColor(pen()->color()), pen()->width());
+ p.setPen(pn);
+ } else {
+ p.setPen(Qt::NoPen);
+ }
p.setBrush(d->_color);
- p.drawRoundedRect(0, 0, roundRect.width(), roundRect.height(), d->_radius, d->_radius);
+ p.drawRoundedRect((pw+1)/2, (pw+1)/2, roundRect.width()-(pw+1)/2*2, roundRect.height()-(pw+1)/2*2, d->_radius, d->_radius);
d->_rectTexture.setImage(roundRect);
}
}
@@ -418,14 +461,19 @@ void QFxRect::generateBorderedRect()
{
Q_D(QFxRect);
if (d->_rectTexture.isNull()) {
- QImage borderedRect(d->pen()->width()*2 + 1, d->pen()->width()*2 + 1, QImage::Format_ARGB32_Premultiplied);
+ const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0;
+ QImage borderedRect(pw*2 + 4, pw*2 + 4, QImage::Format_ARGB32_Premultiplied);
borderedRect.fill(0);
QPainter p(&(borderedRect));
- QPen pn(QColor(pen()->color()), pen()->width());
p.setRenderHint(QPainter::Antialiasing);
- p.setPen(pn);
+ if (d->_pen && d->_pen->isValid()) {
+ QPen pn(QColor(pen()->color()), pen()->width());
+ p.setPen(pn);
+ } else {
+ p.setPen(Qt::NoPen);
+ }
p.setBrush(d->_color);
- p.drawRect(0, 0, borderedRect.width(), borderedRect.height());
+ p.drawRect(qreal(pw+1)/2, qreal(pw+1)/2, borderedRect.width()-(pw+1)/2*2, borderedRect.height()-(pw+1)/2*2);
d->_rectTexture.setImage(borderedRect);
}
}
@@ -458,9 +506,13 @@ void QFxRect::drawRect(QPainter &p)
// XXX This path is still slower than the image path
// Image path won't work for gradients though
p.save();
- QPen pn(QColor(pen()->color()), pen()->width());
p.setRenderHint(QPainter::Antialiasing);
- p.setPen(pn);
+ if (d->_pen && d->_pen->isValid()) {
+ QPen pn(QColor(pen()->color()), pen()->width());
+ p.setPen(pn);
+ } else {
+ p.setPen(Qt::NoPen);
+ }
if (d->_gradcolor.isValid()){
QLinearGradient grad(0, 0, 0, height());
grad.setColorAt(0, d->_color);
@@ -476,67 +528,72 @@ void QFxRect::drawRect(QPainter &p)
p.restore();
} else {
int offset = 0;
+ const int pw = d->_pen && d->_pen->isValid() ? (d->_pen->width()+1)/2*2 : 0;
+
if (d->_radius > 0) {
generateRoundedRect();
//### implicit conversion to int
- offset = d->_radius;
+ offset = int(d->_radius+0.5+pw);
} else {
generateBorderedRect();
- offset = d->pen()->width();
+ offset = pw;
}
//basically same code as QFxImage uses to paint sci images
- int w = width();
- int h = height();
+ int w = width()+pw;
+ int h = height()+pw;
int xOffset = offset;
int xSide = xOffset * 2;
+ bool xMiddles=true;
if (xSide > w) {
- xOffset = w/2;
+ xMiddles=false;
+ xOffset = w/2 + 1;
xSide = xOffset * 2;
}
int yOffset = offset;
int ySide = yOffset * 2;
+ bool yMiddles=true;
if (ySide > h) {
- yOffset = h/2;
+ yMiddles = false;
+ yOffset = h/2 + 1;
ySide = yOffset * 2;
}
// Upper left
- p.drawImage(QRect(0, 0, xOffset, yOffset), d->_rectImage, QRect(0, 0, xOffset, yOffset));
+ p.drawImage(QRect(-pw/2, -pw/2, xOffset, yOffset), d->_rectImage, QRect(0, 0, xOffset, yOffset));
// Upper middle
- if (d->_rectImage.width() - xSide)
- p.drawImage(QRect(xOffset, 0, w - xSide, yOffset), d->_rectImage,
- QRect(xOffset, 0, d->_rectImage.width() - xSide, yOffset));
+ if (xMiddles)
+ p.drawImage(QRect(xOffset-pw/2, -pw/2, width() - xSide + pw, yOffset), d->_rectImage,
+ QRect(d->_rectImage.width()/2, 0, 1, yOffset));
// Upper right
- if (d->_rectImage.width() - xOffset) {
- p.drawImage(QPoint(w-xOffset, 0), d->_rectImage,
- QRect(d->_rectImage.width()-xOffset, 0, xOffset, yOffset));
- }
+ p.drawImage(QPoint(width()-xOffset+pw/2, -pw/2), d->_rectImage,
+ QRect(d->_rectImage.width()-xOffset, 0, xOffset, yOffset));
// Middle left
- if (d->_rectImage.height() - ySide)
- p.drawImage(QRect(0, yOffset, xOffset, height() - ySide), d->_rectImage,
- QRect(0, yOffset, xOffset, d->_rectImage.height() - ySide));
+ if (yMiddles)
+ p.drawImage(QRect(-pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage,
+ QRect(0, d->_rectImage.height()/2, xOffset, 1));
// Middle
- if (d->_rectImage.width() - xSide && d->_rectImage.height() - ySide)
- p.drawImage(QRect(xOffset, yOffset, w - xSide, height() - ySide), d->_rectImage,
- QRect(xOffset, yOffset, d->_rectImage.width() - xSide, d->_rectImage.height() - ySide));
- // Midlle right
- if (d->_rectImage.height() - ySide)
- p.drawImage(QRect(w-xOffset, yOffset, xOffset, height() - ySide), d->_rectImage,
- QRect(d->_rectImage.width()-xOffset, yOffset, xOffset, d->_rectImage.height() - ySide));
+ if (xMiddles && yMiddles)
+ // XXX paint errors in animation example
+ //p.fillRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw, d->getColor());
+ p.drawImage(QRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw), d->_rectImage,
+ QRect(d->_rectImage.width()/2, d->_rectImage.height()/2, 1, 1));
+ // Middle right
+ if (yMiddles)
+ p.drawImage(QRect(width()-xOffset+pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage,
+ QRect(d->_rectImage.width()-xOffset, d->_rectImage.height()/2, xOffset, 1));
// Lower left
- p.drawImage(QPoint(0, height() - yOffset), d->_rectImage, QRect(0, d->_rectImage.height() - yOffset, xOffset, yOffset));
+ p.drawImage(QPoint(-pw/2, height() - yOffset + pw/2), d->_rectImage, QRect(0, d->_rectImage.height() - yOffset, xOffset, yOffset));
// Lower Middle
- if (d->_rectImage.width() - xSide)
- p.drawImage(QRect(xOffset, height() - yOffset, w - xSide, yOffset), d->_rectImage,
- QRect(xOffset, d->_rectImage.height() - yOffset, d->_rectImage.width() - xSide, yOffset));
+ if (xMiddles)
+ p.drawImage(QRect(xOffset-pw/2, height() - yOffset +pw/2, width() - xSide + pw, yOffset), d->_rectImage,
+ QRect(d->_rectImage.width()/2, d->_rectImage.height() - yOffset, 1, yOffset));
// Lower Right
- if (d->_rectImage.width() - xOffset)
- p.drawImage(QPoint(w-xOffset, height() - yOffset), d->_rectImage,
- QRect(d->_rectImage.width()-xOffset, d->_rectImage.height() - yOffset, xOffset, yOffset));
+ p.drawImage(QPoint(width()-xOffset+pw/2, height() - yOffset+pw/2), d->_rectImage,
+ QRect(d->_rectImage.width()-xOffset, d->_rectImage.height() - yOffset, xOffset, yOffset));
}
}
#endif
@@ -598,53 +655,60 @@ void QFxRect::paintGLContents(GLPainter &p)
}
} else {
qreal offset = 0;
+ qreal pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0.0;
+
if (d->_radius > 0) {
generateRoundedRect();
- offset = d->_radius;
+ offset = d->_radius + pw+1.5;
} else {
generateBorderedRect();
- offset = d->pen()->width();
+ offset = pw+1.5;
}
QGLShaderProgram *shader = p.useTextureShader();
- float imgWidth = d->_rectTexture.width();
- float imgHeight = d->_rectTexture.height();
- if (!imgWidth || !imgHeight)
+ float texWidth = d->_rectTexture.width();
+ float texHeight = d->_rectTexture.height();
+ if (!texWidth || !texHeight)
return;
- float widthV = width();
- float heightV = height();
+ float widthV = qreal(width())+pw/2;
+ float heightV = qreal(height())+pw/2;
- float texleft = 0;
- float texright = 1;
- float textop = 1;
- float texbottom = 0;
- float imgleft = 0;
- float imgright = widthV;
- float imgtop = 0;
- float imgbottom = heightV;
+ float xOffset = offset;
+ bool xMiddles = true;
+ if (xOffset*2 > width()+pw) {
+ xMiddles = false;
+ xOffset = (width()+pw)/2;
+ }
+ float yOffset = offset;
+ bool yMiddles = true;
+ if (yOffset*2 > height()+pw) {
+ yMiddles = false;
+ yOffset = (height()+pw)/2;
+ }
- texleft = float(offset) / imgWidth;
- imgleft = offset;
- texright = 1. - float(offset) / imgWidth;
- imgright = widthV - offset;
- textop = 1. - float(offset) / imgHeight;
- imgtop = offset;
- texbottom = float(offset) / imgHeight;
- imgbottom = heightV - offset;
+ float texleft = xOffset / texWidth;
+ float imgleft = xOffset-pw/2;
+ float texright = (texWidth-xOffset) / texWidth;
+ float imgright = widthV - xOffset;
+
+ float textop = yOffset / texHeight;
+ float imgtop = yOffset-pw/2;
+ float texbottom = (texHeight-yOffset) / texHeight;
+ float imgbottom = heightV - yOffset;
//Bug 231768: Inappropriate interpolation was occuring on 3x3 textures
if (offset==1)
texleft=texright=textop=texbottom=0.5;
- float vert1[] = { 0, 0,
- 0, imgtop,
- imgleft, 0,
+ float vert1[] = { -pw/2, -pw/2,
+ -pw/2, imgtop,
+ imgleft, -pw/2,
imgleft, imgtop,
- imgright, 0,
+ imgright, -pw/2,
imgright, imgtop,
- widthV, 0,
+ widthV, -pw/2,
widthV, imgtop };
float tex1[] = { 0, 0,
0, textop,
@@ -654,8 +718,8 @@ void QFxRect::paintGLContents(GLPainter &p)
texright, textop,
1, 0,
1, textop };
- float vert2[] = { 0, imgtop,
- 0, imgbottom,
+ float vert2[] = { -pw/2, imgtop,
+ -pw/2, imgbottom,
imgleft, imgtop,
imgleft, imgbottom,
imgright, imgtop,
@@ -670,31 +734,31 @@ void QFxRect::paintGLContents(GLPainter &p)
texright, texbottom,
1, textop,
1, texbottom };
- float vert3[] = { 0, imgbottom,
- 0, heightV,
- imgleft, imgbottom,
+ float vert3[] = { -pw/2, heightV,
+ -pw/2, imgbottom,
imgleft, heightV,
- imgright, imgbottom,
+ imgleft, imgbottom,
imgright, heightV,
- widthV, imgbottom,
- widthV, heightV };
- float tex3[] = { 0, texbottom,
- 0, 0,
+ imgright, imgbottom,
+ widthV, heightV,
+ widthV, imgbottom };
+ float tex3[] = { 0, 1,
+ 0, texbottom,
+ texleft, 1,
texleft, texbottom,
- texleft, 0,
+ texright, 1,
texright, texbottom,
- texright, 0,
- 1, texbottom,
- 1, 0 };
-
- glBindTexture(GL_TEXTURE_2D, d->_rectTexture.texture());
+ 1, 1,
+ 1, texbottom };
shader->setAttributeArray(SingleTextureShader::Vertices, vert1, 2);
shader->setAttributeArray(SingleTextureShader::TextureCoords, tex1, 2);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
- shader->setAttributeArray(SingleTextureShader::Vertices, vert2, 2);
- shader->setAttributeArray(SingleTextureShader::TextureCoords, tex2, 2);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
+ if (yMiddles) {
+ shader->setAttributeArray(SingleTextureShader::Vertices, vert2, 2);
+ shader->setAttributeArray(SingleTextureShader::TextureCoords, tex2, 2);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
+ }
shader->setAttributeArray(SingleTextureShader::Vertices, vert3, 2);
shader->setAttributeArray(SingleTextureShader::TextureCoords, tex3, 2);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
@@ -773,9 +837,9 @@ void QFxRect::paintGLContents(GLPainter &p)
glColor4f(1, 1, 1, p.activeOpacity);
}
- float imgWidth = d->_rectTexture.width();
- float imgHeight = d->_rectTexture.height();
- if (!imgWidth || !imgHeight)
+ float texWidth = d->_rectTexture.width();
+ float texHeight = d->_rectTexture.height();
+ if (!texWidth || !texHeight)
return;
float widthV = width();
@@ -790,13 +854,13 @@ void QFxRect::paintGLContents(GLPainter &p)
float imgtop = 0;
float imgbottom = heightV;
- texleft = float(offset) / imgWidth;
+ texleft = float(offset) / texWidth;
imgleft = offset;
- texright = 1. - float(offset) / imgWidth;
+ texright = 1. - float(offset) / texWidth;
imgright = widthV - offset;
- textop = 1. - float(offset) / imgHeight;
+ textop = 1. - float(offset) / texHeight;
imgtop = offset;
- texbottom = float(offset) / imgHeight;
+ texbottom = float(offset) / texHeight;
imgbottom = heightV - offset;
float vert1[] = { 0, 0,
diff --git a/src/declarative/fx/qfxrect.h b/src/declarative/fx/qfxrect.h
index f8bff78..420ec44 100644
--- a/src/declarative/fx/qfxrect.h
+++ b/src/declarative/fx/qfxrect.h
@@ -58,11 +58,11 @@ class Q_DECLARATIVE_EXPORT QFxPen : public QObject
Q_PROPERTY(QColor color READ color WRITE setColor)
public:
QFxPen(QObject *parent=0)
- : QObject(parent), _width(1), _color("#000000"), _valid(false)
+ : QObject(parent), _width(0), _color("#000000"), _valid(false)
{}
int width() const { return _width; }
- void setWidth(int w) { _width = w; emit updated(); _valid = (_width < 1) ? false : true; }
+ void setWidth(int w);
QColor color() const { return _color; }
void setColor(const QColor &c);
diff --git a/src/declarative/fx/qfxtransform.cpp b/src/declarative/fx/qfxtransform.cpp
index 7b76367..bc59e0a 100644
--- a/src/declarative/fx/qfxtransform.cpp
+++ b/src/declarative/fx/qfxtransform.cpp
@@ -179,6 +179,20 @@ void QFxAxis::setEndZ(qreal z)
emit updated();
}
+/*!
+ \qmlclass Rotation
+ \brief A Rotation object provides a way to rotate an Item around a point.
+
+ The following example rotates a Rect around its interior point 25, 25:
+ \qml
+ Rect {
+ width: 100; height: 100
+ color: "blue"
+ transform: Rotation { originX: 25; originY: 25; angle: 45}
+ }
+ \endqml
+*/
+
QFxRotation::QFxRotation(QObject *parent)
: QFxTransform(parent), _originX(0), _originY(0), _angle(0), _dirty(true)
{
@@ -188,6 +202,12 @@ QFxRotation::~QFxRotation()
{
}
+/*!
+ \qmlproperty real Rotation::originX
+ \qmlproperty real Rotation::originY
+
+ The point to rotate around.
+*/
qreal QFxRotation::originX() const
{
return _originX;
@@ -210,6 +230,11 @@ void QFxRotation::setOriginY(qreal oy)
update();
}
+/*!
+ \qmlproperty real Rotation::angle
+
+ The angle, in degrees, to rotate.
+*/
qreal QFxRotation::angle() const
{
return _angle;
@@ -217,8 +242,11 @@ qreal QFxRotation::angle() const
void QFxRotation::setAngle(qreal angle)
{
+ if (_angle == angle)
+ return;
_angle = angle;
update();
+ emit angleChanged();
}
bool QFxRotation::isIdentity() const
diff --git a/src/declarative/fx/qfxtransform.h b/src/declarative/fx/qfxtransform.h
index 6d55cff..31374df 100644
--- a/src/declarative/fx/qfxtransform.h
+++ b/src/declarative/fx/qfxtransform.h
@@ -115,7 +115,7 @@ class Q_DECLARATIVE_EXPORT QFxRotation : public QFxTransform
Q_PROPERTY(qreal originX READ originX WRITE setOriginX)
Q_PROPERTY(qreal originY READ originY WRITE setOriginY)
- Q_PROPERTY(qreal angle READ angle WRITE setAngle)
+ Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged())
public:
QFxRotation(QObject *parent=0);
~QFxRotation();
@@ -132,6 +132,9 @@ public:
virtual bool isIdentity() const;
virtual QSimpleCanvas::Matrix transform() const;
+Q_SIGNALS:
+ void angleChanged();
+
private Q_SLOTS:
void update();
private:
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 0209c1d..425cba4 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -615,6 +615,35 @@ QUrl QmlEngine::componentUrl(const QUrl& src, const QUrl& baseUrl) const
}
/*!
+ Returns the list of base urls the engine browses to find sub-components.
+
+ The search path consists of the base of the \a url, and, in the case of local files,
+ the directories imported using the "import" statement in \a qml.
+ */
+QList<QUrl> QmlEngine::componentSearchPath(const QByteArray &qml, const QUrl &url) const
+{
+ QList<QUrl> searchPath;
+
+ searchPath << url.resolved(QUrl(QLatin1String(".")));
+
+ if (QFileInfo(url.toLocalFile()).exists()) {
+ QmlScriptParser parser;
+ if (parser.parse(qml, url)) {
+ for (int i = 0; i < parser.imports().size(); ++i) {
+ QUrl importUrl = QUrl(parser.imports().at(i).uri);
+ if (importUrl.isRelative()) {
+ searchPath << url.resolved(importUrl);
+ } else {
+ searchPath << importUrl;
+ }
+ }
+ }
+ }
+
+ return searchPath;
+}
+
+/*!
Sets the common QNetworkAccessManager, \a network, used by all QML elements instantiated
by this engine.
diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h
index fde84d4..9382389 100644
--- a/src/declarative/qml/qmlengine.h
+++ b/src/declarative/qml/qmlengine.h
@@ -78,6 +78,8 @@ public:
QMap<QString,QString> nameSpacePaths() const;
QUrl componentUrl(const QUrl& src, const QUrl& baseUrl) const;
+ QList<QUrl> componentSearchPath(const QByteArray &qml, const QUrl &url) const;
+
void setNetworkAccessManager(QNetworkAccessManager *);
QNetworkAccessManager *networkAccessManager() const;