summaryrefslogtreecommitdiffstats
path: root/src/declarative/fx
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-06-11 22:32:42 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-06-11 22:32:42 (GMT)
commit1e2409cf6acaa8b390e65745821d21f2a8bb344d (patch)
tree3962fbc0bf92e2826fe6ba488c16240e8d1cf2de /src/declarative/fx
parent9d9cf497c1d21fe80b5bdd0db2a2fa145ebe9ab0 (diff)
parentf10791eb1c45b090f60a2c2ecca3cc5fd237278e (diff)
downloadQt-1e2409cf6acaa8b390e65745821d21f2a8bb344d.zip
Qt-1e2409cf6acaa8b390e65745821d21f2a8bb344d.tar.gz
Qt-1e2409cf6acaa8b390e65745821d21f2a8bb344d.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/fx')
-rw-r--r--src/declarative/fx/qfxanimatedimageitem.cpp5
-rw-r--r--src/declarative/fx/qfxblendedimage.cpp34
-rw-r--r--src/declarative/fx/qfxblendedimage.h14
-rw-r--r--src/declarative/fx/qfxhighlightfilter.cpp12
-rw-r--r--src/declarative/fx/qfxhighlightfilter.h8
-rw-r--r--src/declarative/fx/qfximage.cpp533
-rw-r--r--src/declarative/fx/qfximage.h8
-rw-r--r--src/declarative/fx/qfximage_p.h29
-rw-r--r--src/declarative/fx/qfxitem.cpp26
-rw-r--r--src/declarative/fx/qfxitem.h6
-rw-r--r--src/declarative/fx/qfxitem_p.h3
-rw-r--r--src/declarative/fx/qfxparticles.cpp18
-rw-r--r--src/declarative/fx/qfxparticles.h6
-rw-r--r--src/declarative/fx/qfxrect.cpp545
-rw-r--r--src/declarative/fx/qfxrect_p.h31
-rw-r--r--src/declarative/fx/qfxtext.cpp110
-rw-r--r--src/declarative/fx/qfxwebview.cpp18
-rw-r--r--src/declarative/fx/qfxwebview.h6
18 files changed, 628 insertions, 784 deletions
diff --git a/src/declarative/fx/qfxanimatedimageitem.cpp b/src/declarative/fx/qfxanimatedimageitem.cpp
index 029206b..604481c 100644
--- a/src/declarative/fx/qfxanimatedimageitem.cpp
+++ b/src/declarative/fx/qfxanimatedimageitem.cpp
@@ -155,7 +155,7 @@ int QFxAnimatedImageItem::frameCount() const
void QFxAnimatedImageItem::setSource(const QString &url)
{
Q_D(QFxAnimatedImageItem);
- if (url == d->source)
+ if (url == d->url)
return;
delete d->_movie;
@@ -166,8 +166,7 @@ void QFxAnimatedImageItem::setSource(const QString &url)
d->reply = 0;
}
- d->source = url;
- d->url = qmlContext(this)->resolvedUrl(url);
+ d->url = url;
if (url.isEmpty()) {
delete d->_movie;
diff --git a/src/declarative/fx/qfxblendedimage.cpp b/src/declarative/fx/qfxblendedimage.cpp
index 4c6eb58..e216196 100644
--- a/src/declarative/fx/qfxblendedimage.cpp
+++ b/src/declarative/fx/qfxblendedimage.cpp
@@ -84,9 +84,9 @@ QFxBlendedImage::QFxBlendedImage(QFxItem *parent)
\qmlproperty string BlendedImage::primaryUrl
The URL of the first image to be displayed in this item.
*/
-QString QFxBlendedImage::primaryUrl() const
+QUrl QFxBlendedImage::primaryUrl() const
{
- return primSrc;
+ return primUrl;
}
void QFxBlendedImage::primaryLoaded()
@@ -96,15 +96,15 @@ void QFxBlendedImage::primaryLoaded()
update();
}
-void QFxBlendedImage::setPrimaryUrl(const QString &url)
+void QFxBlendedImage::setPrimaryUrl(const QUrl &url)
{
- if (primSrc == url)
+ if (primUrl == url)
return;
- if (!primSrc.isEmpty())
+ if (!primUrl.isEmpty())
QFxPixmap::cancelGet(primUrl,this);
- primSrc = url;
- primUrl = qmlContext(this)->resolvedUrl(url);
- if (!primSrc.isEmpty())
+ Q_ASSERT(!url.isRelative());
+ primUrl = url;
+ if (!primUrl.isEmpty())
QFxPixmap::get(qmlEngine(this), primUrl,this,SLOT(primaryLoaded()));
}
@@ -112,9 +112,9 @@ void QFxBlendedImage::setPrimaryUrl(const QString &url)
\qmlproperty string BlendedImage::secondaryUrl
The URL of the second image to be displayed in this item.
*/
-QString QFxBlendedImage::secondaryUrl() const
+QUrl QFxBlendedImage::secondaryUrl() const
{
- return secSrc;
+ return secUrl;
}
void QFxBlendedImage::secondaryLoaded()
@@ -124,15 +124,15 @@ void QFxBlendedImage::secondaryLoaded()
update();
}
-void QFxBlendedImage::setSecondaryUrl(const QString &url)
+void QFxBlendedImage::setSecondaryUrl(const QUrl &url)
{
- if (secSrc == url)
+ if (secUrl == url)
return;
- if (!secSrc.isEmpty())
+ if (!secUrl.isEmpty())
QFxPixmap::cancelGet(secUrl,this);
- secSrc = url;
- secUrl = qmlContext(this)->resolvedUrl(url);
- if (!secSrc.isEmpty())
+ Q_ASSERT(!url.isRelative());
+ secUrl = url;
+ if (!secUrl.isEmpty())
QFxPixmap::get(qmlEngine(this), secUrl,this,SLOT(secondaryLoaded()));
}
@@ -183,7 +183,7 @@ void QFxBlendedImage::setSmoothTransform(bool s)
void QFxBlendedImage::paintContents(QPainter &p)
{
- if (primSrc.isNull() && secSrc.isNull())
+ if (primUrl.isEmpty() && secUrl.isEmpty())
return;
if (_smooth) {
diff --git a/src/declarative/fx/qfxblendedimage.h b/src/declarative/fx/qfxblendedimage.h
index baf4b64..7169b92 100644
--- a/src/declarative/fx/qfxblendedimage.h
+++ b/src/declarative/fx/qfxblendedimage.h
@@ -57,18 +57,18 @@ class Q_DECLARATIVE_EXPORT QFxBlendedImage : public QFxItem
{
Q_OBJECT
- Q_PROPERTY(QString primaryUrl READ primaryUrl WRITE setPrimaryUrl)
- Q_PROPERTY(QString secondaryUrl READ secondaryUrl WRITE setSecondaryUrl)
+ Q_PROPERTY(QUrl primaryUrl READ primaryUrl WRITE setPrimaryUrl)
+ Q_PROPERTY(QUrl secondaryUrl READ secondaryUrl WRITE setSecondaryUrl)
Q_PROPERTY(qreal blend READ blend WRITE setBlend)
Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform)
public:
QFxBlendedImage(QFxItem *parent=0);
- QString primaryUrl() const;
- void setPrimaryUrl(const QString &);
+ QUrl primaryUrl() const;
+ void setPrimaryUrl(const QUrl &);
- QString secondaryUrl() const;
- void setSecondaryUrl(const QString &);
+ QUrl secondaryUrl() const;
+ void setSecondaryUrl(const QUrl &);
qreal blend() const;
void setBlend(qreal);
@@ -87,8 +87,6 @@ private Q_SLOTS:
void secondaryLoaded();
private:
- QString primSrc;
- QString secSrc;
QUrl primUrl;
QUrl secUrl;
diff --git a/src/declarative/fx/qfxhighlightfilter.cpp b/src/declarative/fx/qfxhighlightfilter.cpp
index 6bf3148..3d5f413 100644
--- a/src/declarative/fx/qfxhighlightfilter.cpp
+++ b/src/declarative/fx/qfxhighlightfilter.cpp
@@ -128,7 +128,7 @@ QFxHighlightFilter::~QFxHighlightFilter()
\property QFxHighlightFilter::source
\brief the URL of the image to be used as the highlight.
*/
-QString QFxHighlightFilter::source() const
+QUrl QFxHighlightFilter::source() const
{
return d->source;
}
@@ -144,14 +144,14 @@ void QFxHighlightFilter::imageLoaded()
update();
}
-void QFxHighlightFilter::setSource(const QString &f)
+void QFxHighlightFilter::setSource(const QUrl &f)
{
- if (d->source == f)
+ if (d->url == f)
return;
- if (!d->source.isEmpty())
+ if (!d->url.isEmpty())
QFxPixmap::cancelGet(d->url, this);
- d->source = f;
- d->url = qmlContext(this)->resolvedUrl(f);
+ Q_ASSERT(!f.isRelative());
+ d->url = f;
#if defined(QFX_RENDER_OPENGL2)
d->tex.clear();
#endif
diff --git a/src/declarative/fx/qfxhighlightfilter.h b/src/declarative/fx/qfxhighlightfilter.h
index 19e95ac..33f0963 100644
--- a/src/declarative/fx/qfxhighlightfilter.h
+++ b/src/declarative/fx/qfxhighlightfilter.h
@@ -56,7 +56,7 @@ class Q_DECLARATIVE_EXPORT QFxHighlightFilter : public QSimpleCanvasFilter
{
Q_OBJECT
- Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(bool tiled READ tiled WRITE setTiled NOTIFY tiledChanged)
Q_PROPERTY(int xOffset READ xOffset WRITE setXOffset NOTIFY offsetChanged)
Q_PROPERTY(int yOffset READ yOffset WRITE setYOffset NOTIFY offsetChanged)
@@ -64,8 +64,8 @@ public:
QFxHighlightFilter(QObject *parent=0);
virtual ~QFxHighlightFilter();
- QString source() const;
- void setSource(const QString &);
+ QUrl source() const;
+ void setSource(const QUrl &);
bool tiled() const;
void setTiled(bool);
@@ -76,7 +76,7 @@ public:
void setYOffset(int);
Q_SIGNALS:
- void sourceChanged(const QString &);
+ void sourceChanged(const QUrl &);
void offsetChanged(int x, int y);
void tiledChanged(bool);
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index 22e5d97..05738e3 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -124,9 +124,15 @@ QFxImage::QFxImage(QFxImagePrivate &dd, QFxItem *parent)
QFxImage::~QFxImage()
{
- Q_D(const QFxImage);
+ Q_D(QFxImage);
if (d->sciReply)
d->sciReply->deleteLater();
+#if defined(QFX_RENDER_OPENGL)
+ if (d->tex) {
+ d->tex->release();
+ d->tex = 0;
+ }
+#endif
}
/*!
@@ -141,22 +147,25 @@ QFxImage::~QFxImage()
QPixmap QFxImage::pixmap() const
{
Q_D(const QFxImage);
- return d->_pix;
+ return d->pix;
}
void QFxImage::setPixmap(const QPixmap &pix)
{
Q_D(QFxImage);
d->url = QUrl();
- d->_pix = pix;
- d->_opaque=false;
+ d->pix = pix;
+ d->opaque=false;
- setImplicitWidth(d->_pix.width());
- setImplicitHeight(d->_pix.height());
+ setImplicitWidth(d->pix.width());
+ setImplicitHeight(d->pix.height());
#if defined(QFX_RENDER_OPENGL)
- d->_texDirty = true;
- d->_tex.clear();
+ d->texDirty = true;
+ if (d->tex) {
+ d->tex->release();
+ d->tex = 0;
+ }
#endif
update();
}
@@ -189,7 +198,7 @@ void QFxImage::setPixmap(const QPixmap &pix)
QFxScaleGrid *QFxImage::scaleGrid()
{
Q_D(QFxImage);
- return d->scaleGrid();
+ return d->getScaleGrid();
}
/*!
@@ -213,13 +222,13 @@ QFxScaleGrid *QFxImage::scaleGrid()
bool QFxImage::isTiled() const
{
Q_D(const QFxImage);
- return d->_tiled;
+ return d->tiled;
}
void QFxImage::setTiled(bool tile)
{
Q_D(QFxImage);
- d->_tiled = tile;
+ d->tiled = tile;
}
/*!
@@ -245,15 +254,18 @@ void QFxImage::setTiled(bool tile)
bool QFxImage::isOpaque() const
{
Q_D(const QFxImage);
- return d->_opaque;
+ return d->opaque;
}
void QFxImage::setOpaque(bool o)
{
Q_D(QFxImage);
- if (o == d->_opaque)
+ if (o == d->opaque)
return;
- d->_opaque = o;
+ d->opaque = o;
+
+ setOptions(IsOpaque, o);
+
update();
}
@@ -293,15 +305,15 @@ void QFxImage::componentComplete()
bool QFxImage::smoothTransform() const
{
Q_D(const QFxImage);
- return d->_smooth;
+ return d->smooth;
}
void QFxImage::setSmoothTransform(bool s)
{
Q_D(QFxImage);
- if (d->_smooth == s)
+ if (d->smooth == s)
return;
- d->_smooth = s;
+ d->smooth = s;
update();
}
@@ -317,16 +329,16 @@ void QFxImage::dump(int depth)
void QFxImage::paintContents(QPainter &p)
{
Q_D(QFxImage);
- if (d->_pix.isNull())
+ if (d->pix.isNull())
return;
QPainter::RenderHints oldHints = p.renderHints();
- if (d->_smooth)
- p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->_smooth);
+ if (d->smooth)
+ p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth);
- QPixmap pix = d->_pix;
+ QPixmap pix = d->pix;
- if (d->_tiled) {
+ if (d->tiled) {
p.save();
p.setClipRect(0, 0, width(), height(), Qt::IntersectClip);
QRect me = QRect(0, 0, width(), height());
@@ -345,7 +357,7 @@ void QFxImage::paintContents(QPainter &p)
}
p.restore();
- } else if (!d->_scaleGrid || d->_scaleGrid->isNull()) {
+ } else if (!d->scaleGrid || d->scaleGrid->isNull()) {
if (width() != pix.width() || height() != pix.height()) {
QTransform scale;
scale.scale(width() / qreal(pix.width()),
@@ -358,10 +370,10 @@ void QFxImage::paintContents(QPainter &p)
p.drawPixmap(0, 0, pix);
}
} else {
- int sgl = d->_scaleGrid->left();
- int sgr = d->_scaleGrid->right();
- int sgt = d->_scaleGrid->top();
- int sgb = d->_scaleGrid->bottom();
+ int sgl = d->scaleGrid->left();
+ int sgr = d->scaleGrid->right();
+ int sgt = d->scaleGrid->top();
+ int sgb = d->scaleGrid->bottom();
int w = width();
int h = height();
@@ -412,7 +424,7 @@ void QFxImage::paintContents(QPainter &p)
QRect(pix.width()-sgr, pix.height() - sgb, sgr, sgb));
}
- if (d->_smooth)
+ if (d->smooth)
p.setRenderHints(oldHints);
}
#elif defined(QFX_RENDER_OPENGL)
@@ -421,7 +433,7 @@ uint QFxImage::glSimpleItemData(float *vertices, float *texVertices,
{
Q_D(QFxImage);
- if (d->_pix.isNull() || (d->_scaleGrid && !d->_scaleGrid->isNull()))
+ if (d->pix.isNull() || (d->scaleGrid && !d->scaleGrid->isNull()))
return 0;
if (count < 8)
@@ -437,20 +449,20 @@ uint QFxImage::glSimpleItemData(float *vertices, float *texVertices,
vertices[4] = 0; vertices[5] = 0;
vertices[6] = widthV; vertices[7] = 0;
- *texture = &d->_tex;
+ *texture = d->tex;
- if (d->_tiled) {
- float tileWidth = widthV / d->_pix.width();
- float tileHeight = heightV / d->_pix.height();
+ if (d->tiled) {
+ float tileWidth = widthV / d->pix.width();
+ float tileHeight = heightV / d->pix.height();
texVertices[0] = 0; texVertices[1] = 0;
texVertices[2] = tileWidth; texVertices[3] = 0;
texVertices[4] = 0; texVertices[5] = tileHeight;
texVertices[6] = tileWidth; texVertices[7] = tileHeight;
} else {
texVertices[0] = 0; texVertices[1] = 0;
- texVertices[2] = 1; texVertices[3] = 0;
- texVertices[4] = 0; texVertices[5] = 1;
- texVertices[6] = 1; texVertices[7] = 1;
+ texVertices[2] = d->tex->glWidth(); texVertices[3] = 0;
+ texVertices[4] = 0; texVertices[5] = d->tex->glHeight();
+ texVertices[6] = d->tex->glWidth(); texVertices[7] = d->tex->glHeight();
}
return 8;
@@ -458,51 +470,87 @@ uint QFxImage::glSimpleItemData(float *vertices, float *texVertices,
void QFxImagePrivate::checkDirty()
{
- if (_texDirty && !_pix.isNull()) {
- _tex.setImage(_pix.toImage());
- _tex.setHorizontalWrap(GLTexture::Repeat);
- _tex.setVerticalWrap(GLTexture::Repeat);
- }
- _texDirty = false;
+ Q_Q(QFxImage);
+ if (texDirty && !pix.isNull())
+ tex = q->cachedTexture(url.toString(), pix);
+ texDirty = false;
}
#if defined(QFX_RENDER_OPENGL2)
void QFxImage::paintGLContents(GLPainter &p)
{
Q_D(QFxImage);
- if (d->_pix.isNull())
+ if (d->pix.isNull())
return;
QGLShaderProgram *shader = p.useTextureShader();
bool restoreBlend = false;
- if (isOpaque() && p.activeOpacity == 1) {
+ if (p.blendEnabled && isOpaque() && p.activeOpacity == 1) {
glDisable(GL_BLEND);
restoreBlend = true;
}
- if (d->_tiled || (!d->_scaleGrid || d->_scaleGrid->isNull())) {
+ d->checkDirty();
+
+ if (d->tiled || (!d->scaleGrid || d->scaleGrid->isNull())) {
+
+ if (!d->tiled) {
- GLfloat vertices[8];
- GLfloat texVertices[8];
- GLTexture *tex = 0;
+ float widthV = width();
+ float heightV = height();
+ float glWidth = d->tex->glWidth();
+ float glHeight = d->tex->glHeight();
- QFxImage::glSimpleItemData(vertices, texVertices, &tex, 8);
+ float deltaX = 0.5 / qreal(d->tex->glSize().width());
+ float deltaY = 0.5 / qreal(d->tex->glSize().height());
+ glWidth -= deltaX;
+ glHeight -= deltaY;
+
- shader->setAttributeArray(SingleTextureShader::Vertices, vertices, 2);
- shader->setAttributeArray(SingleTextureShader::TextureCoords, texVertices, 2);
+ float vert[] = {
+ 0, heightV,
+ widthV, heightV,
+ 0, 0,
- glBindTexture(GL_TEXTURE_2D, tex->texture());
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ widthV, heightV,
+ 0, 0,
+ widthV, 0 };
- shader->disableAttributeArray(SingleTextureShader::Vertices);
- shader->disableAttributeArray(SingleTextureShader::TextureCoords);
+ float tex[] = {
+ deltaX, deltaY,
+ glWidth, deltaY,
+ deltaX, glHeight,
+
+ glWidth, deltaY,
+ deltaX, glHeight,
+ glWidth, glHeight
+ };
+
+ shader->setAttributeArray(SingleTextureShader::Vertices, vert, 2);
+ shader->setAttributeArray(SingleTextureShader::TextureCoords, tex, 2);
+ glBindTexture(GL_TEXTURE_2D, d->tex->texture());
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+
+ } else {
+
+ GLfloat vertices[8];
+ GLfloat texVertices[8];
+ GLTexture *tex = 0;
+
+ QFxImage::glSimpleItemData(vertices, texVertices, &tex, 8);
+
+ shader->setAttributeArray(SingleTextureShader::Vertices, vertices, 2);
+ shader->setAttributeArray(SingleTextureShader::TextureCoords, texVertices, 2);
+
+ glBindTexture(GL_TEXTURE_2D, tex->texture());
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ }
} else {
- d->checkDirty();
- float imgWidth = d->_pix.width();
- float imgHeight = d->_pix.height();
+ float imgWidth = d->pix.width();
+ float imgHeight = d->pix.height();
if (!imgWidth || !imgHeight) {
if (restoreBlend)
glEnable(GL_BLEND);
@@ -511,270 +559,196 @@ void QFxImage::paintGLContents(GLPainter &p)
float widthV = width();
float heightV = height();
-
- float texleft = 0;
- float texright = 1;
- float textop = 1;
- float texbottom = 0;
+ float glWidth = d->tex->glWidth();
+ float glHeight = d->tex->glHeight();
+ float deltaX = 0.5 / qreal(d->tex->glSize().width());
+ float deltaY = 0.5 / qreal(d->tex->glSize().height());
+ glHeight -= deltaY;
+ glWidth -= deltaX;
+
+ float texleft = deltaX;
+ float texright = glWidth;
+ float textop = glHeight;
+ float texbottom = deltaY;
float imgleft = 0;
float imgright = widthV;
float imgtop = 0;
float imgbottom = heightV;
- const int sgl = d->_scaleGrid->left();
- const int sgr = d->_scaleGrid->right();
- const int sgt = d->_scaleGrid->top();
- const int sgb = d->_scaleGrid->bottom();
+ const int sgl = d->scaleGrid->left();
+ const int sgr = d->scaleGrid->right();
+ const int sgt = d->scaleGrid->top();
+ const int sgb = d->scaleGrid->bottom();
if (sgl) {
- texleft = float(sgl) / imgWidth;
+ texleft = deltaX + d->tex->glWidth() * float(sgl) / imgWidth;
imgleft = sgl;
}
if (sgr) {
- texright = 1. - float(sgr) / imgWidth;
+ texright = d->tex->glWidth() - float(sgr) / imgWidth - deltaX;
imgright = widthV - sgr;
}
if (sgt) {
- textop = 1. - float(sgb) / imgHeight;
+ textop = d->tex->glHeight() - float(sgb) / imgHeight - deltaY;
imgtop = sgt;
}
if (sgb) {
- texbottom = float(sgt) / imgHeight;
+ texbottom = deltaY + d->tex->glHeight() * float(sgt) / imgHeight;
imgbottom = heightV - sgb;
}
float vert1[] = { 0, 0,
0, imgtop,
imgleft, 0,
+
+ 0, imgtop,
+ imgleft, 0,
+ imgleft, imgtop,
+
+ imgleft, 0,
imgleft, imgtop,
imgright, 0,
+
+ imgleft, imgtop,
+ imgright, 0,
+ imgright, imgtop,
+
+ imgright, 0,
imgright, imgtop,
widthV, 0,
- widthV, imgtop };
- float tex1[] = { 0, 1,
- 0, textop,
- texleft, 1,
- texleft, textop,
- texright, 1,
- texright, textop,
- 1, 1,
- 1, textop };
- float vert2[] = { 0, imgtop,
+
+ imgright, imgtop,
+ widthV, 0,
+ widthV, imgtop,
+
+ 0, imgtop,
+ 0, imgbottom,
+ imgleft, imgtop,
+
0, imgbottom,
imgleft, imgtop,
imgleft, imgbottom,
+
+ imgleft, imgtop,
+ imgleft, imgbottom,
+ imgright, imgtop,
+
+ imgleft, imgbottom,
+ imgright, imgtop,
+ imgright, imgbottom,
+
imgright, imgtop,
imgright, imgbottom,
widthV, imgtop,
- widthV, imgbottom };
- float tex2[] = { 0, textop,
- 0, texbottom,
- texleft, textop,
- texleft, texbottom,
- texright, textop,
- texright, texbottom,
- 1, textop,
- 1, texbottom };
- float vert3[] = { 0, imgbottom,
+
+ imgright, imgbottom,
+ widthV, imgtop,
+ widthV, imgbottom,
+
+ 0, imgbottom,
0, heightV,
imgleft, imgbottom,
+
+ 0, heightV,
+ imgleft, imgbottom,
+ imgleft, heightV,
+
+ imgleft, imgbottom,
+ imgleft, heightV,
+ imgright, imgbottom,
+
imgleft, heightV,
imgright, imgbottom,
imgright, heightV,
+
+ imgright, imgbottom,
+ imgright, heightV,
widthV, imgbottom,
- widthV, heightV };
- float tex3[] = { 0, texbottom,
- 0, 0,
- texleft, texbottom,
- texleft, 0,
- texright, texbottom,
- texright, 0,
- 1, texbottom,
- 1, 0 };
- glBindTexture(GL_TEXTURE_2D, d->_tex.texture());
+ imgright, heightV,
+ widthV, imgbottom,
+ widthV, heightV };
- 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);
- shader->setAttributeArray(SingleTextureShader::Vertices, vert3, 2);
- shader->setAttributeArray(SingleTextureShader::TextureCoords, tex3, 2);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
-
- shader->disableAttributeArray(SingleTextureShader::Vertices);
- shader->disableAttributeArray(SingleTextureShader::TextureCoords);
- }
+ float tex1[] = { deltaX, glHeight,
+ deltaX, textop,
+ texleft, glHeight,
- if (restoreBlend)
- glEnable(GL_BLEND);
-}
-#elif defined(QFX_RENDER_OPENGL1)
-void QFxImage::paintGLContents(GLPainter &p)
-{
- Q_D(QFxImage);
- if (d->_pix.isNull())
- return;
-
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(p.activeTransform.data());
+ deltaX, textop,
+ texleft, glHeight,
+ texleft, textop,
- bool restoreBlend = false;
- if (isOpaque() && p.activeOpacity == 1) {
- glDisable(GL_BLEND);
- restoreBlend = true;
- }
+ texleft, glHeight,
+ texleft, textop,
+ texright, glHeight,
- glEnable(GL_TEXTURE_2D);
- if (p.activeOpacity == 1.) {
- GLint i = GL_REPLACE;
- glTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &i);
- } else {
- GLint i = GL_MODULATE;
- glTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &i);
- glColor4f(1, 1, 1, p.activeOpacity);
- }
+ texleft, textop,
+ texright, glHeight,
+ texright, textop,
- if (d->_tiled || !d->_scaleGrid || d->_scaleGrid->isNull()) {
+ texright, glHeight,
+ texright, textop,
+ glWidth, glHeight,
- GLfloat vertices[8];
- GLfloat texVertices[8];
- GLTexture *tex = 0;
+ texright, textop,
+ glWidth, glHeight,
+ glWidth, textop,
- QFxImage::glSimpleItemData(vertices, texVertices, &tex, 8);
+ deltaX, textop,
+ deltaX, texbottom,
+ texleft, textop,
- glBindTexture(GL_TEXTURE_2D, tex->texture());
+ deltaX, texbottom,
+ texleft, textop,
+ texleft, texbottom,
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ texleft, textop,
+ texleft, texbottom,
+ texright, textop,
- glVertexPointer(2, GL_FLOAT, 0, vertices);
- glTexCoordPointer(2, GL_FLOAT, 0, texVertices);
+ texleft, texbottom,
+ texright, textop,
+ texright, texbottom,
+ texright, textop,
+ texright, texbottom,
+ glWidth, textop,
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ texright, texbottom,
+ glWidth, textop,
+ glWidth, texbottom,
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisable(GL_TEXTURE_2D);
+ deltaX, texbottom,
+ deltaX, deltaY,
+ texleft, texbottom,
- } else {
- d->checkDirty();
+ deltaX, deltaY,
+ texleft, texbottom,
+ texleft, deltaY,
- float imgWidth = d->_pix.width();
- float imgHeight = d->_pix.height();
- if (!imgWidth || !imgHeight) {
- if (restoreBlend)
- glEnable(GL_BLEND);
- return;
- }
+ texleft, texbottom,
+ texleft, deltaY,
+ texright, texbottom,
- float widthV = width();
- float heightV = height();
+ texleft, deltaY,
+ texright, texbottom,
+ texright, deltaY,
- float texleft = 0;
- float texright = 1;
- float textop = 1;
- float texbottom = 0;
- float imgleft = 0;
- float imgright = widthV;
- float imgtop = 0;
- float imgbottom = heightV;
+ texright, texbottom,
+ texright, deltaY,
+ glWidth, texbottom,
- const int sgl = d->_scaleGrid->left();
- const int sgr = d->_scaleGrid->right();
- const int sgt = d->_scaleGrid->top();
- const int sgb = d->_scaleGrid->bottom();
+ texright, deltaY,
+ glWidth, texbottom,
+ glWidth, deltaY };
- if (sgl) {
- texleft = float(sgl) / imgWidth;
- imgleft = sgl;
- }
- if (sgr) {
- texright = 1. - float(sgr) / imgWidth;
- imgright = widthV - sgr;
- }
- if (sgt) {
- textop = 1. - float(sgb) / imgHeight;
- imgtop = sgt;
- }
- if (sgb) {
- texbottom = float(sgt) / imgHeight;
- imgbottom = heightV - sgb;
- }
+ glBindTexture(GL_TEXTURE_2D, d->tex->texture());
- float vert1[] = { 0, 0,
- 0, imgtop,
- imgleft, 0,
- imgleft, imgtop,
- imgright, 0,
- imgright, imgtop,
- widthV, 0,
- widthV, imgtop };
- float tex1[] = { 0, 1,
- 0, textop,
- texleft, 1,
- texleft, textop,
- texright, 1,
- texright, textop,
- 1, 1,
- 1, textop };
- float vert2[] = { 0, imgtop,
- 0, imgbottom,
- imgleft, imgtop,
- imgleft, imgbottom,
- imgright, imgtop,
- imgright, imgbottom,
- widthV, imgtop,
- widthV, imgbottom };
- float tex2[] = { 0, textop,
- 0, texbottom,
- texleft, textop,
- texleft, texbottom,
- texright, textop,
- texright, texbottom,
- 1, textop,
- 1, texbottom };
- float vert3[] = { 0, imgbottom,
- 0, heightV,
- imgleft, imgbottom,
- imgleft, heightV,
- imgright, imgbottom,
- imgright, heightV,
- widthV, imgbottom,
- widthV, heightV };
- float tex3[] = { 0, texbottom,
- 0, 0,
- texleft, texbottom,
- texleft, 0,
- texright, texbottom,
- texright, 0,
- 1, texbottom,
- 1, 0 };
-
- glBindTexture(GL_TEXTURE_2D, d->_tex.texture());
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- glVertexPointer(2, GL_FLOAT, 0, vert1);
- glTexCoordPointer(2, GL_FLOAT, 0, tex1);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
- glVertexPointer(2, GL_FLOAT, 0, vert2);
- glTexCoordPointer(2, GL_FLOAT, 0, tex2);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
- glVertexPointer(2, GL_FLOAT, 0, vert3);
- glTexCoordPointer(2, GL_FLOAT, 0, tex3);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisable(GL_TEXTURE_2D);
+ shader->setAttributeArray(SingleTextureShader::Vertices, vert1, 2);
+ shader->setAttributeArray(SingleTextureShader::TextureCoords, tex1, 2);
+ glDrawArrays(GL_TRIANGLES, 0, 54);
}
- if (restoreBlend)
+ if (restoreBlend)
glEnable(GL_BLEND);
}
#endif
@@ -851,19 +825,19 @@ qreal QFxImage::progress() const
The content specified can be of any image type loadable by QImage. Alternatively,
you can specify an sci format file, which specifies both an image and it's scale grid.
*/
-QString QFxImage::source() const
+QUrl QFxImage::source() const
{
Q_D(const QFxImage);
- return d->source;
+ return d->url;
}
-void QFxImage::setSource(const QString &url)
+void QFxImage::setSource(const QUrl &url)
{
#ifdef Q_ENABLE_PERFORMANCE_LOG
QFxPerfTimer<QFxPerf::PixmapLoad> perf;
#endif
Q_D(QFxImage);
- if (url == d->source)
+ if (url == d->url)
return;
if (d->sciReply) {
@@ -876,8 +850,7 @@ void QFxImage::setSource(const QString &url)
if (!d->sciurl.isEmpty())
QFxPixmap::cancelGet(d->sciurl, this);
- d->source = url;
- d->url = qmlContext(this)->resolvedUrl(url);
+ d->url = url;
d->sciurl = QUrl();
if (d->progress != 0.0) {
d->progress = 0.0;
@@ -891,11 +864,14 @@ void QFxImage::setSource(const QString &url)
setImplicitWidth(0);
setImplicitHeight(0);
#if defined(QFX_RENDER_OPENGL)
- d->_texDirty = true;
- d->_tex.clear();
+ d->texDirty = true;
+ if (d->tex) {
+ d->tex->release();
+ d->tex = 0;
+ }
#endif
emit statusChanged(d->status);
- emit sourceChanged(d->source);
+ emit sourceChanged(d->url);
emit progressChanged(1.0);
update();
} else {
@@ -934,7 +910,7 @@ void QFxImage::requestFinished()
{
Q_D(QFxImage);
if (d->url.path().endsWith(QLatin1String(".sci"))) {
- d->_pix = QFxPixmap(d->sciurl);
+ d->pix = QFxPixmap(d->sciurl);
} else {
if (d->reply) {
disconnect(d->reply, SIGNAL(downloadProgress(qint64,qint64)),
@@ -942,21 +918,24 @@ void QFxImage::requestFinished()
if (d->reply->error() != QNetworkReply::NoError)
d->status = Error;
}
- d->_pix = QFxPixmap(d->url);
+ d->pix = QFxPixmap(d->url);
setOptions(QFxImage::SimpleItem, true);
}
- setImplicitWidth(d->_pix.width());
- setImplicitHeight(d->_pix.height());
+ setImplicitWidth(d->pix.width());
+ setImplicitHeight(d->pix.height());
if (d->status == Loading)
d->status = Idle;
d->progress = 1.0;
#if defined(QFX_RENDER_OPENGL)
- d->_texDirty = true;
- d->_tex.clear();
+ d->texDirty = true;
+ if (d->tex) {
+ d->tex->release();
+ d->tex = 0;
+ }
#endif
emit statusChanged(d->status);
- emit sourceChanged(d->source);
+ emit sourceChanged(d->url);
emit progressChanged(1.0);
update();
}
diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h
index 4d5f134..35b921a 100644
--- a/src/declarative/fx/qfximage.h
+++ b/src/declarative/fx/qfximage.h
@@ -58,7 +58,7 @@ class Q_DECLARATIVE_EXPORT QFxImage : public QFxItem
Q_ENUMS(Status)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
- Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
Q_PROPERTY(QFxScaleGrid *scaleGrid READ scaleGrid)
@@ -88,8 +88,8 @@ public:
Status status() const;
qreal progress() const;
- QString source() const;
- virtual void setSource(const QString &url);
+ QUrl source() const;
+ virtual void setSource(const QUrl &url);
virtual void dump(int depth);
virtual QString propertyInfo() const;
@@ -102,7 +102,7 @@ public:
#endif
Q_SIGNALS:
- void sourceChanged(const QString &);
+ void sourceChanged(const QUrl &);
void statusChanged(Status);
void progressChanged(qreal progress);
diff --git a/src/declarative/fx/qfximage_p.h b/src/declarative/fx/qfximage_p.h
index b3cccf9..1785abb 100644
--- a/src/declarative/fx/qfximage_p.h
+++ b/src/declarative/fx/qfximage_p.h
@@ -72,9 +72,9 @@ class QFxImagePrivate : public QFxItemPrivate
public:
QFxImagePrivate()
- : _scaleGrid(0), _tiled(false), _smooth(false), _opaque(false),
+ : scaleGrid(0), tiled(false), smooth(false), opaque(false),
#if defined(QFX_RENDER_OPENGL)
- _texDirty(true),
+ texDirty(true), tex(0),
#endif
status(QFxImage::Idle), sciReply(0), progress(0.0)
{
@@ -82,31 +82,30 @@ public:
~QFxImagePrivate()
{
- delete _scaleGrid;
+ delete scaleGrid;
}
void setContent(QIODevice* dev, const QString &url);
- QFxScaleGrid *scaleGrid()
+ QFxScaleGrid *getScaleGrid()
{
- if (!_scaleGrid)
- _scaleGrid = new QFxScaleGrid;
- return _scaleGrid;
+ if (!scaleGrid)
+ scaleGrid = new QFxScaleGrid;
+ return scaleGrid;
}
- QFxScaleGrid *_scaleGrid;
- QPixmap _pix;
- bool _tiled : 1;
- bool _smooth : 1;
- bool _opaque : 1;
+ QFxScaleGrid *scaleGrid;
+ QPixmap pix;
+ bool tiled : 1;
+ bool smooth : 1;
+ bool opaque : 1;
#if defined(QFX_RENDER_OPENGL)
+ bool texDirty : 1;
void checkDirty();
- bool _texDirty;
- GLTexture _tex;
+ QSimpleCanvasItem::CachedTexture *tex;
#endif
QFxImage::Status status;
- QString source;
QUrl url;
QUrl sciurl;
QNetworkReply *sciReply;
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index 7129757..648b0fb 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -792,12 +792,12 @@ QFxItem *QFxItem::qmlItem() const
}
/*!
- \qmlproperty string Item::qml
- This property holds the dynamic QML for the item.
+ \qmlproperty url Item::qml
+ This property holds the dynamic URL of the QML for the item.
This property is used for dynamically loading QML into the
item. Querying for the QML only has meaning if the QML has been
- dynamically set; otherwise an empty string is returned.
+ dynamically set; otherwise an empty URL is returned.
*/
/*! \fn void QFxItem::qmlChanged()
@@ -809,32 +809,31 @@ QFxItem *QFxItem::qmlItem() const
/*!
\property QFxItem::qml
- This property holds the dynamic QML for the item.
+ This property holds the dynamic URL of the QML for the item.
This property is used for dynamically loading QML into the
item. Querying for the QML only has meaning if the QML has been
- dynamically set; otherwise an empty string is returned.
+ dynamically set; otherwise an empty URL is returned.
*/
-QString QFxItem::qml() const
+QUrl QFxItem::qml() const
{
Q_D(const QFxItem);
return d->_qml;
}
-void QFxItem::setQml(const QString &qml)
+void QFxItem::setQml(const QUrl &qml)
{
Q_D(QFxItem);
if (d->_qml == qml)
return;
if (!d->_qml.isEmpty()) {
- QmlChildren::Iterator iter = d->_qmlChildren.find(d->_qml);
+ QmlChildren::Iterator iter = d->_qmlChildren.find(d->_qml.toString());
if (iter != d->_qmlChildren.end())
(*iter)->setOpacity(0.);
}
d->_qml = qml;
- d->_qmlurl = qmlContext(this)->resolvedUri(qml);
d->qmlItem = 0;
if (d->_qml.isEmpty()) {
@@ -842,14 +841,14 @@ void QFxItem::setQml(const QString &qml)
return;
}
- QmlChildren::Iterator iter = d->_qmlChildren.find(d->_qml);
+ QmlChildren::Iterator iter = d->_qmlChildren.find(d->_qml.toString());
if (iter != d->_qmlChildren.end()) {
(*iter)->setOpacity(1.);
d->qmlItem = (*iter);
emit qmlChanged();
} else {
d->_qmlcomp =
- new QmlComponent(qmlEngine(this), d->_qmlurl, this);
+ new QmlComponent(qmlEngine(this), d->_qml, this);
if (!d->_qmlcomp->isLoading())
qmlLoaded();
else
@@ -1491,9 +1490,8 @@ void QFxItem::setRotation(qreal rotation)
trans.rotate(d->_rotation, 0, 0, 1);
trans.translate(-to.x(), -to.y());
#else
- QTransform trans;
- QPointF to = transformOriginPoint();
- trans.translate(to.x(), to.y());
+ QPointF to = d->transformOrigin();
+ QTransform trans = QTransform::fromTranslate(to.x(), to.y());
trans.rotate(d->_rotation);
trans.translate(-to.x(), -to.y());
#endif
diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h
index 8ca1f9e..3c872e1 100644
--- a/src/declarative/fx/qfxitem.h
+++ b/src/declarative/fx/qfxitem.h
@@ -111,7 +111,7 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QSimpleCanvasItem, public QmlParserS
Q_PROPERTY(QmlList<QmlState *>* states READ states DESIGNABLE false)
Q_PROPERTY(QmlList<QmlTransition *>* transitions READ transitions DESIGNABLE false)
Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
- Q_PROPERTY(QString qml READ qml WRITE setQml NOTIFY qmlChanged)
+ Q_PROPERTY(QUrl qml READ qml WRITE setQml NOTIFY qmlChanged)
Q_PROPERTY(QFxItem *qmlItem READ qmlItem NOTIFY qmlChanged)
Q_PROPERTY(qreal x READ x WRITE setX NOTIFY leftChanged)
Q_PROPERTY(qreal y READ y WRITE setY NOTIFY topChanged)
@@ -171,8 +171,8 @@ public:
void setState(const QString &);
QFxItem *qmlItem() const;
- QString qml() const;
- void setQml(const QString &);
+ QUrl qml() const;
+ void setQml(const QUrl &);
bool flipVertically() const;
void setFlipVertically(bool);
diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h
index a54f523..b38d877 100644
--- a/src/declarative/fx/qfxitem_p.h
+++ b/src/declarative/fx/qfxitem_p.h
@@ -133,9 +133,8 @@ public:
QFxAnchors *_anchors;
QFxContents *_contents;
QFxItem *qmlItem;
- QUrl _qmlurl;
QmlComponent *_qmlcomp;
- QString _qml;
+ QUrl _qml;
QList<QUrl> _qmlnewloading;
QList<QmlComponent*> _qmlnewcomp;
diff --git a/src/declarative/fx/qfxparticles.cpp b/src/declarative/fx/qfxparticles.cpp
index 41fb5bc..25e359d 100644
--- a/src/declarative/fx/qfxparticles.cpp
+++ b/src/declarative/fx/qfxparticles.cpp
@@ -395,7 +395,6 @@ public:
void createParticle(int time);
void updateOpacity(QFxParticle &p, int age);
- QString source;
QUrl url;
QPixmap image;
int count;
@@ -642,10 +641,10 @@ QFxParticles::~QFxParticles()
\property QFxParticles::source
\brief the URL of the particle image.
*/
-QString QFxParticles::source() const
+QUrl QFxParticles::source() const
{
Q_D(const QFxParticles);
- return d->source;
+ return d->url;
}
void QFxParticles::imageLoaded()
@@ -659,18 +658,17 @@ void QFxParticles::imageLoaded()
update();
}
-void QFxParticles::setSource(const QString &name)
+void QFxParticles::setSource(const QUrl &name)
{
Q_D(QFxParticles);
- if (name == d->source)
+ if (name == d->url)
return;
- if (!d->source.isEmpty())
+ if (!d->url.isEmpty())
QFxPixmap::cancelGet(d->url, this);
if (name.isEmpty()) {
- d->source = name;
- d->url = QUrl();
+ d->url = name;
d->image = QPixmap();
#if defined(QFX_RENDER_OPENGL)
d->texDirty = true;
@@ -678,8 +676,8 @@ void QFxParticles::setSource(const QString &name)
#endif
update();
} else {
- d->source = name;
- d->url = qmlContext(this)->resolvedUrl(name);
+ d->url = name;
+ Q_ASSERT(!name.isRelative());
QFxPixmap::get(qmlEngine(this), d->url, this, SLOT(imageLoaded()));
}
}
diff --git a/src/declarative/fx/qfxparticles.h b/src/declarative/fx/qfxparticles.h
index 6ef2582..b3a569b 100644
--- a/src/declarative/fx/qfxparticles.h
+++ b/src/declarative/fx/qfxparticles.h
@@ -153,7 +153,7 @@ class Q_DECLARATIVE_EXPORT QFxParticles : public QFxItem
{
Q_OBJECT
- Q_PROPERTY(QString source READ source WRITE setSource)
+ Q_PROPERTY(QUrl source READ source WRITE setSource)
Q_PROPERTY(int count READ count WRITE setCount)
Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan)
Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation)
@@ -172,8 +172,8 @@ public:
QFxParticles(QFxItem *parent=0);
~QFxParticles();
- QString source() const;
- void setSource(const QString &);
+ QUrl source() const;
+ void setSource(const QUrl &);
int count() const;
void setCount(int cnt);
diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp
index c156753..f55357f 100644
--- a/src/declarative/fx/qfxrect.cpp
+++ b/src/declarative/fx/qfxrect.cpp
@@ -253,13 +253,16 @@ void QFxRect::doUpdate()
{
#if defined(QFX_RENDER_QPAINTER)
Q_D(QFxRect);
- d->_rectImage = QPixmap();
+ d->rectImage = QPixmap();
#endif
#if defined(QFX_RENDER_OPENGL)
Q_D(QFxRect);
- d->_rectTexture.clear();
+ if (d->rectTexture) {
+ d->rectTexture->release();
+ d->rectTexture = 0;
+ }
#endif
- const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0;
+ const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0;
setPaintMargin((pw+1)/2);
update();
}
@@ -277,7 +280,7 @@ void QFxRect::doUpdate()
QFxPen *QFxRect::pen()
{
Q_D(QFxRect);
- return d->pen();
+ return d->getPen();
}
/*!
@@ -348,20 +351,23 @@ void QFxRect::setGradient(QFxGradient *gradient)
qreal QFxRect::radius() const
{
Q_D(const QFxRect);
- return d->_radius;
+ return d->radius;
}
void QFxRect::setRadius(qreal radius)
{
Q_D(QFxRect);
- if (d->_radius == radius)
+ if (d->radius == radius)
return;
- d->_radius = radius;
+ d->radius = radius;
#if defined(QFX_RENDER_QPAINTER)
- d->_rectImage = QPixmap();
+ d->rectImage = QPixmap();
#elif defined(QFX_RENDER_OPENGL)
- d->_rectTexture.clear();
+ if (d->rectTexture) {
+ d->rectTexture->release();
+ d->rectTexture = 0;
+ }
#endif
update();
}
@@ -370,7 +376,7 @@ void QFxRect::dump(int depth)
{
Q_D(QFxRect);
QByteArray ba(depth * 4, ' ');
- qWarning() << ba.constData() << "QFxRect:" << d->_color;
+ qWarning() << ba.constData() << "QFxRect:" << d->color;
QFxItem::dump(depth);
}
@@ -394,21 +400,24 @@ void QFxRect::dump(int depth)
QColor QFxRect::color() const
{
Q_D(const QFxRect);
- return d->_color;
+ return d->color;
}
void QFxRect::setColor(const QColor &c)
{
Q_D(QFxRect);
- if (d->_color == c)
+ if (d->color == c)
return;
- d->_color = c;
+ d->color = c;
#if defined(QFX_RENDER_QPAINTER)
- d->_rectImage = QPixmap();
+ d->rectImage = QPixmap();
#endif
#if defined(QFX_RENDER_OPENGL)
- d->_rectTexture.clear();
+ if (d->rectTexture) {
+ d->rectTexture->release();
+ d->rectTexture = 0;
+ }
#endif
update();
}
@@ -437,30 +446,30 @@ void QFxRect::setColor(const QColor &c)
QColor QFxRect::tintColor() const
{
Q_D(const QFxRect);
- return d->_tintColor;
+ return d->tintColor;
}
void QFxRect::setTintColor(const QColor &c)
{
Q_D(QFxRect);
- if (d->_tintColor == c)
+ if (d->tintColor == c)
return;
- d->_tintColor = c;
+ d->tintColor = c;
update();
}
QColor QFxRectPrivate::getColor()
{
- if (_tintColor.isValid()) {
- int a = _tintColor.alpha();
+ if (tintColor.isValid()) {
+ int a = tintColor.alpha();
if (a == 0xFF)
- return _tintColor;
+ return tintColor;
else if (a == 0x00)
- return _color;
+ return color;
else {
- uint src = _tintColor.rgba();
- uint dest = _color.rgba();
+ uint src = tintColor.rgba();
+ uint dest = color.rgba();
uint res = (((a * (src & 0xFF00FF)) +
((0xFF - a) * (dest & 0xFF00FF))) >> 8) & 0xFF00FF;
@@ -472,7 +481,7 @@ QColor QFxRectPrivate::getColor()
return QColor::fromRgba(res);
}
} else {
- return _color;
+ return color;
}
}
@@ -481,82 +490,95 @@ QColor QFxRectPrivate::getColor()
void QFxRect::generateRoundedRect()
{
Q_D(QFxRect);
- if (d->_rectImage.isNull()) {
- const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0;
- d->_rectImage = QPixmap(d->_radius*2 + 3 + pw*2, d->_radius*2 + 3 + pw*2);
- d->_rectImage.fill(Qt::transparent);
- QPainter p(&(d->_rectImage));
+ if (d->rectImage.isNull()) {
+ const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0;
+ d->rectImage = QPixmap(d->radius*2 + 3 + pw*2, d->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(pen()->color()), pen()->width());
+ 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);
- 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);
+ p.setBrush(d->color);
+ 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);
}
}
void QFxRect::generateBorderedRect()
{
Q_D(QFxRect);
- if (d->_rectImage.isNull()) {
- const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0;
- d->_rectImage = QPixmap(d->pen()->width()*2 + 3 + pw*2, d->pen()->width()*2 + 3 + pw*2);
- d->_rectImage.fill(Qt::transparent);
- QPainter p(&(d->_rectImage));
+ if (d->rectImage.isNull()) {
+ const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0;
+ d->rectImage = QPixmap(d->getPen()->width()*2 + 3 + pw*2, d->getPen()->width()*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(pen()->color()), pen()->width());
+ 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);
- p.drawRect(qreal(pw+1)/2, qreal(pw+1)/2, d->_rectImage.width()-(pw+1)/2*2, d->_rectImage.height()-(pw+1)/2*2);
+ p.setBrush(d->color);
+ 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)
void QFxRect::generateRoundedRect()
{
Q_D(QFxRect);
- if (d->_rectTexture.isNull()) {
- 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);
- p.setRenderHint(QPainter::Antialiasing);
- if (d->_pen && d->_pen->isValid()) {
- QPen pn(QColor(pen()->color()), pen()->width());
- p.setPen(pn);
- } else {
- p.setPen(Qt::NoPen);
+ if (!d->rectTexture) {
+ const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0;
+ QString key = QString("QFxRect://r_%1_%2_%3_%4").arg(pw).arg(d->radius).arg((d->pen && d->pen->isValid())?d->pen->color().name():QString()).arg(d->color.name());
+
+ d->rectTexture = cachedTexture(key);
+
+ if (!d->rectTexture) {
+ QPixmap roundRect(d->radius*2 + 4 + pw*2, d->radius*2 + 4 + pw*2);
+ roundRect.fill(Qt::transparent);
+ QPainter p(&roundRect);
+ p.setRenderHint(QPainter::Antialiasing);
+ 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((pw+1)/2, (pw+1)/2, roundRect.width()-(pw+1)/2*2, roundRect.height()-(pw+1)/2*2, d->radius, d->radius);
+
+ d->rectTexture = cachedTexture(key, roundRect);
}
- p.setBrush(d->_color);
- 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);
}
}
void QFxRect::generateBorderedRect()
{
Q_D(QFxRect);
- if (d->_rectTexture.isNull()) {
- 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));
- p.setRenderHint(QPainter::Antialiasing);
- if (d->_pen && d->_pen->isValid()) {
- QPen pn(QColor(pen()->color()), pen()->width());
- p.setPen(pn);
- } else {
- p.setPen(Qt::NoPen);
+ if (!d->rectTexture) {
+ const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0;
+ QString key = QString("QFxRect://b_%1_%2_%3_%4").arg(pw).arg(d->radius).arg((d->pen && d->pen->isValid())?d->pen->color().name():QString()).arg(d->color.name());
+
+ d->rectTexture = cachedTexture(key);
+
+ if (!d->rectTexture) {
+ QPixmap borderedRect(pw*2 + 4, pw*2 + 4);
+ borderedRect.fill(Qt::transparent);
+ QPainter p(&(borderedRect));
+ p.setRenderHint(QPainter::Antialiasing);
+ 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(qreal(pw+1)/2, qreal(pw+1)/2, borderedRect.width()-(pw+1)/2*2, borderedRect.height()-(pw+1)/2*2);
+ d->rectTexture = cachedTexture(key, borderedRect);
}
- p.setBrush(d->_color);
- 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);
}
}
#endif
@@ -566,7 +588,7 @@ void QFxRect::generateBorderedRect()
void QFxRect::paintContents(QPainter &p)
{
Q_D(QFxRect);
- if (d->_radius > 0 || (d->_pen && d->_pen->isValid())
+ if (d->radius > 0 || (d->pen && d->pen->isValid())
|| (d->gradient && d->gradient->gradient()) )
drawRect(p);
else
@@ -581,26 +603,26 @@ void QFxRect::drawRect(QPainter &p)
// Image path won't work for gradients though
QPainter::RenderHints oldHints = p.renderHints();
p.setRenderHint(QPainter::Antialiasing);
- if (d->_pen && d->_pen->isValid()) {
- QPen pn(QColor(pen()->color()), pen()->width());
+ 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);
+ if (d->radius > 0.)
+ p.drawRoundedRect(0, 0, width(), height(), d->radius, d->radius);
else
p.drawRect(0, 0, width(), height());
p.setRenderHints(oldHints);
} else {
int offset = 0;
- const int pw = d->_pen && d->_pen->isValid() ? (d->_pen->width()+1)/2*2 : 0;
+ const int pw = d->pen && d->pen->isValid() ? (d->pen->width()+1)/2*2 : 0;
- if (d->_radius > 0) {
+ if (d->radius > 0) {
generateRoundedRect();
//### implicit conversion to int
- offset = int(d->_radius+1.5+pw);
+ offset = int(d->radius+1.5+pw);
} else {
generateBorderedRect();
offset = pw+1;
@@ -627,40 +649,40 @@ void QFxRect::drawRect(QPainter &p)
}
// Upper left
- p.drawPixmap(QRect(-pw/2, -pw/2, xOffset, yOffset), d->_rectImage, QRect(0, 0, xOffset, yOffset));
+ p.drawPixmap(QRect(-pw/2, -pw/2, xOffset, yOffset), d->rectImage, QRect(0, 0, xOffset, yOffset));
// Upper middle
if (xMiddles)
- p.drawPixmap(QRect(xOffset-pw/2, -pw/2, width() - xSide + pw, yOffset), d->_rectImage,
- QRect(d->_rectImage.width()/2, 0, 1, yOffset));
+ p.drawPixmap(QRect(xOffset-pw/2, -pw/2, width() - xSide + pw, yOffset), d->rectImage,
+ QRect(d->rectImage.width()/2, 0, 1, yOffset));
// Upper right
- p.drawPixmap(QPoint(width()-xOffset+pw/2, -pw/2), d->_rectImage,
- QRect(d->_rectImage.width()-xOffset, 0, xOffset, yOffset));
+ p.drawPixmap(QPoint(width()-xOffset+pw/2, -pw/2), d->rectImage,
+ QRect(d->rectImage.width()-xOffset, 0, xOffset, yOffset));
// Middle left
if (yMiddles)
- p.drawPixmap(QRect(-pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage,
- QRect(0, d->_rectImage.height()/2, xOffset, 1));
+ p.drawPixmap(QRect(-pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->rectImage,
+ QRect(0, d->rectImage.height()/2, xOffset, 1));
// Middle
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.drawPixmap(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));
+ p.drawPixmap(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.drawPixmap(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));
+ p.drawPixmap(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.drawPixmap(QPoint(-pw/2, height() - yOffset + pw/2), d->_rectImage, QRect(0, d->_rectImage.height() - yOffset, xOffset, yOffset));
+ p.drawPixmap(QPoint(-pw/2, height() - yOffset + pw/2), d->rectImage, QRect(0, d->rectImage.height() - yOffset, xOffset, yOffset));
// Lower Middle
if (xMiddles)
- p.drawPixmap(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));
+ p.drawPixmap(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
- p.drawPixmap(QPoint(width()-xOffset+pw/2, height() - yOffset+pw/2), d->_rectImage,
- QRect(d->_rectImage.width()-xOffset, d->_rectImage.height() - yOffset, xOffset, yOffset));
+ p.drawPixmap(QPoint(width()-xOffset+pw/2, height() - yOffset+pw/2), d->rectImage,
+ QRect(d->rectImage.width()-xOffset, d->rectImage.height() - yOffset, xOffset, yOffset));
}
}
#endif
@@ -671,7 +693,7 @@ void QFxRect::drawRect(QPainter &p)
void QFxRect::paintGLContents(GLPainter &p)
{
Q_D(QFxRect);
- if (d->_radius == 0 && (!d->_pen || !d->_pen->isValid())) {
+ if (d->radius == 0 && (!d->pen || !d->pen->isValid())) {
if (d->gradient) {
float widthV = width();
float heightV = height();
@@ -692,6 +714,7 @@ void QFxRect::paintGLContents(GLPainter &p)
colors[i+3] = c.alphaF() * p.activeOpacity; colors[i+7] = colors[i+3];
}
+ p.invalidate();
ColorShader *shader = basicShaders()->color();
shader->enable();
shader->setTransform(p.activeTransform);
@@ -702,27 +725,17 @@ void QFxRect::paintGLContents(GLPainter &p)
shader->disableAttributeArray(ColorShader::Vertices);
shader->disableAttributeArray(ColorShader::Colors);
} else {
- QGLShaderProgram *shader = p.useColorShader(d->getColor());
- float widthV = width();
- float heightV = height();
+ p.fillRect(QRectF(0, 0, width(), height()), d->getColor());
- GLfloat vertices[] = { 0, heightV,
- widthV, heightV,
- 0, 0,
- widthV, 0 };
-
- shader->setAttributeArray(ConstantColorShader::Vertices, vertices, 2);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- shader->disableAttributeArray(ConstantColorShader::Vertices);
}
} else {
qreal offset = 0;
- qreal pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0.0;
+ qreal pw = d->pen && d->pen->isValid() ? d->pen->width() : 0.0;
- if (d->_radius > 0) {
+ if (d->radius > 0) {
generateRoundedRect();
- offset = d->_radius + pw+1.5;
+ offset = d->radius + pw+1.5;
} else {
generateBorderedRect();
offset = pw+1.5;
@@ -730,8 +743,8 @@ void QFxRect::paintGLContents(GLPainter &p)
QGLShaderProgram *shader = p.useTextureShader();
- float texWidth = d->_rectTexture.width();
- float texHeight = d->_rectTexture.height();
+ float texWidth = d->rectTexture->width();
+ float texHeight = d->rectTexture->height();
if (!texWidth || !texHeight)
return;
@@ -765,239 +778,163 @@ void QFxRect::paintGLContents(GLPainter &p)
if (offset==1)
texleft=texright=textop=texbottom=0.5;
+ texleft *= d->rectTexture->glWidth();
+ texright *= d->rectTexture->glWidth();
+ textop *= d->rectTexture->glHeight();
+ texbottom *= d->rectTexture->glHeight();
+
float vert1[] = { -pw/2, -pw/2,
-pw/2, imgtop,
imgleft, -pw/2,
+
+ -pw/2, imgtop,
+ imgleft, -pw/2,
+ imgleft, imgtop,
+
+ imgleft, -pw/2,
+ imgleft, imgtop,
+ imgright, -pw/2,
+
imgleft, imgtop,
imgright, -pw/2,
imgright, imgtop,
+
+ imgright, -pw/2,
+ imgright, imgtop,
widthV, -pw/2,
- widthV, imgtop };
- float tex1[] = { 0, 0,
- 0, textop,
- texleft, 0,
- texleft, textop,
- texright, 0,
- texright, textop,
- 1, 0,
- 1, textop };
- float vert2[] = { -pw/2, imgtop,
- -pw/2, imgbottom,
- imgleft, imgtop,
- imgleft, imgbottom,
+
imgright, imgtop,
- imgright, imgbottom,
+ widthV, -pw/2,
widthV, imgtop,
- widthV, imgbottom };
- float tex2[] = { 0, textop,
- 0, texbottom,
- texleft, textop,
- texleft, texbottom,
- texright, textop,
- texright, texbottom,
- 1, textop,
- 1, texbottom };
- float vert3[] = { -pw/2, heightV,
+
+ -pw/2, heightV,
-pw/2, imgbottom,
imgleft, heightV,
+
+ -pw/2, imgbottom,
+ imgleft, heightV,
+ imgleft, imgbottom,
+
+ imgleft, heightV,
imgleft, imgbottom,
imgright, heightV,
+
+ imgleft, imgbottom,
+ imgright, heightV,
+ imgright, imgbottom,
+
+ imgright, heightV,
+ imgright, imgbottom,
+ widthV, heightV,
+
imgright, imgbottom,
widthV, heightV,
+ widthV, imgbottom,
+
+ -pw/2, imgtop,
+ -pw/2, imgbottom,
+ imgleft, imgtop,
+
+ -pw/2, imgbottom,
+ imgleft, imgtop,
+ imgleft, imgbottom,
+
+ imgleft, imgtop,
+ imgleft, imgbottom,
+ imgright, imgtop,
+
+ imgleft, imgbottom,
+ imgright, imgtop,
+ imgright, imgbottom,
+
+ imgright, imgtop,
+ imgright, imgbottom,
+ widthV, imgtop,
+
+ imgright, imgbottom,
+ widthV, imgtop,
widthV, imgbottom };
- float tex3[] = { 0, 1,
- 0, texbottom,
- texleft, 1,
- texleft, texbottom,
- texright, 1,
- texright, texbottom,
- 1, 1,
- 1, texbottom };
- glBindTexture(GL_TEXTURE_2D, d->_rectTexture.texture());
- shader->setAttributeArray(SingleTextureShader::Vertices, vert1, 2);
- shader->setAttributeArray(SingleTextureShader::TextureCoords, tex1, 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);
+ float tex1[] = { 0, 0,
+ 0, textop,
+ texleft, 0,
- shader->disableAttributeArray(SingleTextureShader::Vertices);
- shader->disableAttributeArray(SingleTextureShader::TextureCoords);
- }
-}
-#elif defined(QFX_RENDER_OPENGL1)
-void QFxRect::paintGLContents(GLPainter &p)
-{
- Q_D(QFxRect);
+ 0, textop,
+ texleft, 0,
+ texleft, textop,
- float widthV = width();
- float heightV = height();
-
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(p.activeTransform.data());
-
- if (d->_radius == 0 && (!d->_pen || !d->_pen->isValid())) {
- GLfloat vertices[] = { 0, heightV,
- widthV, heightV,
- 0, 0,
- widthV, 0 };
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2,GL_FLOAT,0,vertices);
-
- QColor c;
- if (d->_gradcolor.isValid())
- c = d->_color;
- else
- c = d->getColor();
- float r = c.redF();
- float g = c.greenF();
- float b = c.blueF();
- float a = c.alphaF() * p.activeOpacity;
-
- float r2 = r; float g2 = g; float b2 = b; float a2 = a;
-
- if (d->_gradcolor.isValid()) {
- r2 = d->_gradcolor.redF();
- g2 = d->_gradcolor.greenF();
- b2 = d->_gradcolor.blueF();
- a2 = d->_gradcolor.alphaF() * p.activeOpacity;
- }
+ texleft, 0,
+ texleft, textop,
+ texright, 0,
- GLfloat colors[] = { r2, g2, b2, a2,
- r2, g2, b2, a2,
- r, g, b, a,
- r, g, b, a };
+ texleft, textop,
+ texright, 0,
+ texright, textop,
- glEnableClientState(GL_COLOR_ARRAY);
- glColorPointer(4,GL_FLOAT,0,colors);
+ texright, 0,
+ texright, textop,
+ d->rectTexture->glWidth(), 0,
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ texright, textop,
+ d->rectTexture->glWidth(), 0,
+ d->rectTexture->glWidth(), textop,
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- } else {
- qreal offset = 0;
- if (d->_radius > 0) {
- generateRoundedRect();
- offset = d->_radius;
- } else {
- generateBorderedRect();
- offset = d->pen()->width();
- }
+ 0, d->rectTexture->glHeight(),
+ 0, texbottom,
+ texleft, d->rectTexture->glHeight(),
- if (p.activeOpacity == 1.) {
- GLint i = GL_REPLACE;
- glTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &i);
- } else {
- GLint i = GL_MODULATE;
- glTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &i);
- glColor4f(1, 1, 1, p.activeOpacity);
- }
+ 0, texbottom,
+ texleft, d->rectTexture->glHeight(),
+ texleft, texbottom,
- float texWidth = d->_rectTexture.width();
- float texHeight = d->_rectTexture.height();
- if (!texWidth || !texHeight)
- return;
+ texleft, d->rectTexture->glHeight(),
+ texleft, texbottom,
+ texright, d->rectTexture->glHeight(),
+
+ texleft, texbottom,
+ texright, d->rectTexture->glHeight(),
+ texright, texbottom,
+
+ texright, d->rectTexture->glHeight(),
+ texright, texbottom,
+ d->rectTexture->glWidth(), d->rectTexture->glHeight(),
+
+ texright, texbottom,
+ d->rectTexture->glWidth(), d->rectTexture->glHeight(),
+ d->rectTexture->glWidth(), texbottom,
- float widthV = width();
- float heightV = height();
-
- float texleft = 0;
- float texright = 1;
- float textop = 1;
- float texbottom = 0;
- float imgleft = 0;
- float imgright = widthV;
- float imgtop = 0;
- float imgbottom = heightV;
-
- texleft = float(offset) / texWidth;
- imgleft = offset;
- texright = 1. - float(offset) / texWidth;
- imgright = widthV - offset;
- textop = 1. - float(offset) / texHeight;
- imgtop = offset;
- texbottom = float(offset) / texHeight;
- imgbottom = heightV - offset;
-
- float vert1[] = { 0, 0,
- 0, imgtop,
- imgleft, 0,
- imgleft, imgtop,
- imgright, 0,
- imgright, imgtop,
- widthV, 0,
- widthV, imgtop };
- float tex1[] = { 0, 1,
0, textop,
- texleft, 1,
+ 0, texbottom,
texleft, textop,
- texright, 1,
- texright, textop,
- 1, 1,
- 1, textop };
- float vert2[] = { 0, imgtop,
- 0, imgbottom,
- imgleft, imgtop,
- imgleft, imgbottom,
- imgright, imgtop,
- imgright, imgbottom,
- widthV, imgtop,
- widthV, imgbottom };
- float tex2[] = { 0, textop,
+
0, texbottom,
texleft, textop,
texleft, texbottom,
+
+ texleft, textop,
+ texleft, texbottom,
texright, textop,
- texright, texbottom,
- 1, textop,
- 1, texbottom };
- float vert3[] = { 0, imgbottom,
- 0, heightV,
- imgleft, imgbottom,
- imgleft, heightV,
- imgright, imgbottom,
- imgright, heightV,
- widthV, imgbottom,
- widthV, heightV };
- float tex3[] = { 0, texbottom,
- 0, 0,
+
texleft, texbottom,
- texleft, 0,
+ texright, textop,
texright, texbottom,
- texright, 0,
- 1, texbottom,
- 1, 0 };
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, d->_rectTexture.texture());
+ texright, textop,
+ texright, texbottom,
+ d->rectTexture->glWidth(), textop,
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ texright, texbottom,
+ d->rectTexture->glWidth(), textop,
+ d->rectTexture->glWidth(), texbottom };
- glVertexPointer(2, GL_FLOAT, 0, vert1);
- glTexCoordPointer(2, GL_FLOAT, 0, tex1);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
- glVertexPointer(2, GL_FLOAT, 0, vert2);
- glTexCoordPointer(2, GL_FLOAT, 0, tex2);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
- glVertexPointer(2, GL_FLOAT, 0, vert3);
- glTexCoordPointer(2, GL_FLOAT, 0, tex3);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
+ glBindTexture(GL_TEXTURE_2D, d->rectTexture->texture());
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisable(GL_TEXTURE_2D);
+ shader->setAttributeArray(SingleTextureShader::Vertices, vert1, 2);
+ shader->setAttributeArray(SingleTextureShader::TextureCoords, tex1, 2);
+ glDrawArrays(GL_TRIANGLES, 0, 36 + (yMiddles?18:0));
}
}
#endif
diff --git a/src/declarative/fx/qfxrect_p.h b/src/declarative/fx/qfxrect_p.h
index 8cafcbb..f662fac 100644
--- a/src/declarative/fx/qfxrect_p.h
+++ b/src/declarative/fx/qfxrect_p.h
@@ -68,14 +68,17 @@ class QFxRectPrivate : public QFxItemPrivate
Q_DECLARE_PUBLIC(QFxRect)
public:
- QFxRectPrivate()
- : gradient(0), _pen(0), _radius(0)
+ QFxRectPrivate() :
+#if defined(QFX_RENDER_OPENGL)
+ rectTexture(0),
+#endif //QFX_RENDER_OPENGL
+ gradient(0), pen(0), radius(0)
{
}
~QFxRectPrivate()
{
- delete _pen;
+ delete pen;
}
void init()
@@ -83,24 +86,24 @@ public:
}
#if defined(QFX_RENDER_OPENGL)
- GLTexture _rectTexture;
+ QSimpleCanvasItem::CachedTexture *rectTexture;
#endif
QColor getColor();
- QColor _color;
+ QColor color;
QFxGradient *gradient;
- QColor _tintColor;
- QFxPen *pen() {
- if (!_pen) {
+ QColor tintColor;
+ QFxPen *getPen() {
+ if (!pen) {
Q_Q(QFxRect);
- _pen = new QFxPen;
- QObject::connect(_pen, SIGNAL(updated()), q, SLOT(doUpdate()));
+ pen = new QFxPen;
+ QObject::connect(pen, SIGNAL(updated()), q, SLOT(doUpdate()));
}
- return _pen;
+ return pen;
}
- QFxPen *_pen;
- qreal _radius;
+ QFxPen *pen;
+ qreal radius;
#if defined(QFX_RENDER_QPAINTER)
- QPixmap _rectImage;
+ QPixmap rectImage;
#endif
};
diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp
index 702ec81..031c0f8 100644
--- a/src/declarative/fx/qfxtext.cpp
+++ b/src/declarative/fx/qfxtext.cpp
@@ -696,7 +696,7 @@ void QFxTextPrivate::checkImgCache()
}
#if defined(QFX_RENDER_OPENGL)
- tex.setImage(imgCache.toImage());
+ tex.setImage(imgCache.toImage(), GLTexture::PowerOfTwo);
#endif
imgDirty = false;
@@ -755,6 +755,7 @@ void QFxText::paintContents(QPainter &p)
#elif defined(QFX_RENDER_OPENGL2)
void QFxText::paintGLContents(GLPainter &p)
{
+ //return;
Q_D(QFxText);
d->checkImgCache();
if (d->imgCache.isNull())
@@ -792,107 +793,42 @@ void QFxText::paintGLContents(GLPainter &p)
float widthV = d->imgCache.width();
float heightV = d->imgCache.height();
+ float glWidth = d->tex.glWidth();
+ float glHeight = d->tex.glHeight();
QGLShaderProgram *shader = p.useTextureShader();
+ float deltaX = 0.5 / qreal(d->tex.glSize().width());
+ float deltaY = 0.5 / qreal(d->tex.glSize().height());
+ glWidth -= deltaX;
+ glHeight -= deltaY;
+
GLfloat vertices[] = { x, y + heightV,
- x + widthV, y + heightV,
- x, y,
- x + widthV, y };
+ x + widthV, y + heightV,
+ x, y,
+
+ x + widthV, y + heightV,
+ x, y,
+ x + widthV, y };
- GLfloat texVertices[] = { 0, 0,
- 1, 0,
- 0, 1,
- 1, 1 };
+ GLfloat texVertices[] = { deltaX, deltaY,
+ glWidth, deltaY,
+ deltaX, glHeight,
+
+ glWidth, deltaY,
+ deltaX, glHeight,
+ glWidth, glHeight };
shader->setAttributeArray(SingleTextureShader::Vertices, vertices, 2);
shader->setAttributeArray(SingleTextureShader::TextureCoords, texVertices, 2);
glBindTexture(GL_TEXTURE_2D, d->tex.texture());
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ glDrawArrays(GL_TRIANGLES, 0, 6);
shader->disableAttributeArray(SingleTextureShader::Vertices);
shader->disableAttributeArray(SingleTextureShader::TextureCoords);
}
-#elif defined(QFX_RENDER_OPENGL)
-void QFxText::paintGLContents(GLPainter &p)
-{
- Q_D(QFxText);
- d->checkImgCache();
- if (d->imgCache.isNull())
- return;
-
- int w = width();
- int h = height();
-
- float x = 0;
- float y = 0;
-
- switch (d->hAlign) {
- case AlignLeft:
- x = 0;
- break;
- case AlignRight:
- x = w - d->imgCache.width();
- break;
- case AlignHCenter:
- x = (w - d->imgCache.width()) / 2;
- break;
- }
-
- switch (d->vAlign) {
- case AlignTop:
- y = 0;
- break;
- case AlignBottom:
- y = h - d->imgCache.height();
- break;
- case AlignVCenter:
- y = (h - d->imgCache.height()) / 2;
- break;
- }
-
- float widthV = d->imgCache.width();
- float heightV = d->imgCache.height();
-
- GLfloat vertices[] = { x, y + heightV,
- x + widthV, y + heightV,
- x, y,
- x + widthV, y };
-
- GLfloat texVertices[] = { 0, 0,
- 1, 0,
- 0, 1,
- 1, 1 };
-
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(p.activeTransform.data());
- glEnable(GL_TEXTURE_2D);
- if (p.activeOpacity == 1.) {
- GLint i = GL_REPLACE;
- glTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &i);
- } else {
- GLint i = GL_MODULATE;
- glTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &i);
- glColor4f(1, 1, 1, p.activeOpacity);
- }
-
- glBindTexture(GL_TEXTURE_2D, d->tex.texture());
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- glVertexPointer(2, GL_FLOAT, 0, vertices);
- glTexCoordPointer(2, GL_FLOAT, 0, texVertices);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisable(GL_TEXTURE_2D);
-}
-
#endif
void QFxText::componentComplete()
diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp
index bfccd34..d15502b 100644
--- a/src/declarative/fx/qfxwebview.cpp
+++ b/src/declarative/fx/qfxwebview.cpp
@@ -287,7 +287,7 @@ void QFxWebView::componentComplete()
Q_D(QFxWebView);
switch (d->pending) {
case QFxWebViewPrivate::PendingUrl:
- setUrl(d->pending_url.toString());
+ setUrl(d->pending_url);
break;
case QFxWebViewPrivate::PendingHtml:
setHtml(d->pending_string, d->pending_url);
@@ -339,7 +339,7 @@ void QFxWebView::doLoadFinished(bool ok)
}
/*!
- \qmlproperty string WebView::url
+ \qmlproperty url WebView::url
This property holds the URL to the page displayed in this item.
Note that after this property is set, it may take some time
@@ -358,24 +358,22 @@ void QFxWebView::doLoadFinished(bool ok)
Emitted when loading of the URL successfully starts after
setUrl() is called.
*/
-QString QFxWebView::url() const
+QUrl QFxWebView::url() const
{
- return page()->mainFrame()->url().toString();
+ return page()->mainFrame()->url();
}
-void QFxWebView::setUrl(const QString &n)
+void QFxWebView::setUrl(const QUrl &url)
{
Q_D(QFxWebView);
- if (n == page()->mainFrame()->url().toString())
+ if (url == page()->mainFrame()->url())
return;
page()->setViewportSize(QSize(
d->idealwidth>0 ? d->idealwidth : width(),
d->idealheight>0 ? d->idealheight : height()));
- QUrl url(n);
- if (url.isRelative())
- url = qmlContext(this)->resolvedUrl(n);
+ Q_ASSERT(!url.isRelative());
if (isComponentComplete())
page()->mainFrame()->load(url);
@@ -942,7 +940,7 @@ void QFxWebView::setHtml(const QString &html, const QUrl &baseUrl)
d->idealwidth>0 ? d->idealwidth : width(),
d->idealheight>0 ? d->idealheight : height()));
if (isComponentComplete())
- page()->mainFrame()->setHtml(html, qmlContext(this)->resolvedUrl(baseUrl));
+ page()->mainFrame()->setHtml(html, baseUrl);
else {
d->pending = d->PendingHtml;
d->pending_url = baseUrl;
diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h
index 28ef6c3..f30fd0d 100644
--- a/src/declarative/fx/qfxwebview.h
+++ b/src/declarative/fx/qfxwebview.h
@@ -90,7 +90,7 @@ class Q_DECLARATIVE_EXPORT QFxWebView : public QFxPaintedItem
Q_PROPERTY(int idealWidth READ idealWidth WRITE setIdealWidth NOTIFY idealWidthChanged)
Q_PROPERTY(int idealHeight READ idealHeight WRITE setIdealHeight NOTIFY idealHeightChanged)
- Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
+ Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
Q_PROPERTY(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged)
@@ -108,8 +108,8 @@ public:
QFxWebView(QFxItem *parent=0);
~QFxWebView();
- QString url() const;
- void setUrl(const QString &);
+ QUrl url() const;
+ void setUrl(const QUrl &);
QString title() const;