summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-08-25 07:26:54 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-08-25 07:26:54 (GMT)
commit141c5ea5b14b1499bcfb5e2c39c917e94aa4e23f (patch)
tree6b080f34609bebf1cc049eeb1751d3b5141d5881 /src
parent57e6192785db1617e233fc4a321da82e5e06ec81 (diff)
parent185fabb154e387dce7e331558008f7ecaeb1ed50 (diff)
downloadQt-141c5ea5b14b1499bcfb5e2c39c917e94aa4e23f.zip
Qt-141c5ea5b14b1499bcfb5e2c39c917e94aa4e23f.tar.gz
Qt-141c5ea5b14b1499bcfb5e2c39c917e94aa4e23f.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase.cpp48
-rw-r--r--src/declarative/graphicsitems/qdeclarativepath.cpp1
-rw-r--r--src/declarative/graphicsitems/qdeclarativepath_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp6
-rw-r--r--src/declarative/qml/qdeclarativexmlhttprequest.cpp87
-rw-r--r--src/declarative/util/qdeclarativefontloader.cpp1
-rw-r--r--src/declarative/util/qdeclarativefontloader_p.h3
8 files changed, 107 insertions, 46 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp
index 47a410c..1cc5f81 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp
@@ -331,7 +331,7 @@ qreal QDeclarativeImage::paintedHeight() const
Unlike the \l {Item::}{width} and \l {Item::}{height} properties, which scale
the painting of the image, this property sets the actual number of pixels
stored for the loaded image so that large images do not use more
- memory than necessary. For example, this ensures the image is memory is no
+ memory than necessary. For example, this ensures the image in memory is no
larger than 1024x1024 pixels, regardless of the Image's \l {Item::}{width} and
\l {Item::}{height} values:
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
index ba40443..d6b935b 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
@@ -147,10 +147,15 @@ void QDeclarativeImageBase::load()
setImplicitWidth(0);
setImplicitHeight(0);
emit statusChanged(d->status);
+ d->sourcesize.setWidth(0);
+ d->sourcesize.setHeight(0);
+ emit sourceSizeChanged();
pixmapChange();
update();
} else {
+
d->status = Loading;
+ emit statusChanged(d->status);
d->pix.load(qmlEngine(this), d->url, d->sourcesize, d->async);
@@ -169,53 +174,34 @@ void QDeclarativeImageBase::load()
d->pix.connectDownloadProgress(this, thisRequestProgress);
} else {
- QSize impsize = d->pix.implicitSize();
- setImplicitWidth(impsize.width());
- setImplicitHeight(impsize.height());
-
- if (d->pix.isReady()) {
- d->status = Ready;
-
- if (!d->sourcesize.isValid())
- emit sourceSizeChanged();
-
- } else {
- d->status = Error;
- qmlInfo(this) << d->pix.error();
- }
- d->progress = 1.0;
- emit statusChanged(d->status);
- emit progressChanged(d->progress);
- pixmapChange();
- update();
+ requestFinished();
}
-
}
-
- emit statusChanged(d->status);
}
void QDeclarativeImageBase::requestFinished()
{
Q_D(QDeclarativeImageBase);
- QSize impsize = d->pix.implicitSize();
-
if (d->pix.isError()) {
d->status = Error;
qmlInfo(this) << d->pix.error();
+ } else {
+ d->status = Ready;
}
+ emit statusChanged(d->status);
- setImplicitWidth(impsize.width());
- setImplicitHeight(impsize.height());
+ setImplicitWidth(d->pix.width());
+ setImplicitHeight(d->pix.height());
- if (d->status == Loading)
- d->status = Ready;
d->progress = 1.0;
- emit statusChanged(d->status);
- emit progressChanged(1.0);
- if (!d->sourcesize.isValid())
+ emit progressChanged(d->progress);
+
+ if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) {
+ d->sourcesize.setWidth(d->pix.width());
+ d->sourcesize.setHeight(d->pix.height());
emit sourceSizeChanged();
+ }
pixmapChange();
update();
}
diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp
index 62e03e7..0c069ce 100644
--- a/src/declarative/graphicsitems/qdeclarativepath.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepath.cpp
@@ -893,6 +893,7 @@ void QDeclarativePathPercent::setValue(qreal value)
{
if (_value != value) {
_value = value;
+ emit valueChanged();
emit changed();
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h
index 195057c..21e1b24 100644
--- a/src/declarative/graphicsitems/qdeclarativepath_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepath_p.h
@@ -190,13 +190,16 @@ private:
class Q_AUTOTEST_EXPORT QDeclarativePathPercent : public QDeclarativePathElement
{
Q_OBJECT
- Q_PROPERTY(qreal value READ value WRITE setValue)
+ Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
public:
QDeclarativePathPercent(QObject *parent=0) : QDeclarativePathElement(parent) {}
qreal value() const;
void setValue(qreal value);
+signals:
+ void valueChanged();
+
private:
qreal _value;
};
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index b96b43c..e5ad743 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -1047,10 +1047,10 @@ QPixmap QDeclarativeTextPrivate::richTextImage(bool drawStyle)
QAbstractTextDocumentLayout::PaintContext context;
+ QTextOption oldOption(doc->defaultTextOption());
if (drawStyle) {
context.palette.setColor(QPalette::Text, styleColor);
- // ### Do we really want this?
- QTextOption colorOption;
+ QTextOption colorOption(doc->defaultTextOption());
colorOption.setFlags(QTextOption::SuppressColors);
doc->setDefaultTextOption(colorOption);
} else {
@@ -1058,7 +1058,7 @@ QPixmap QDeclarativeTextPrivate::richTextImage(bool drawStyle)
}
doc->documentLayout()->draw(&p, context);
if (drawStyle)
- doc->setDefaultTextOption(QTextOption());
+ doc->setDefaultTextOption(oldOption);
return img;
}
diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
index ff1a0e9..d832638 100644
--- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp
+++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
@@ -965,8 +965,9 @@ public:
QScriptValue send(QScriptValue *me, const QByteArray &);
QScriptValue abort(QScriptValue *me);
- QString responseBody() const;
+ QString responseBody();
const QByteArray & rawResponseBody() const;
+ bool receivedXml() const;
private slots:
void downloadProgress(qint64);
void error(QNetworkReply::NetworkError);
@@ -989,6 +990,15 @@ private:
HeadersList m_headersList;
void fillHeadersList();
+ bool m_gotXml;
+ QByteArray m_mime;
+ QByteArray m_charset;
+ QTextCodec *m_textCodec;
+#ifndef QT_NO_TEXTCODEC
+ QTextCodec* findTextCodec() const;
+#endif
+ void readEncoding();
+
QScriptValue m_me; // Set to the data object while a send() is ongoing (to access the callback)
QScriptValue dispatchCallback(QScriptValue *me);
@@ -1006,7 +1016,7 @@ private:
QDeclarativeXMLHttpRequest::QDeclarativeXMLHttpRequest(QNetworkAccessManager *manager)
: m_state(Unsent), m_errorFlag(false), m_sendFlag(false),
- m_redirectCount(0), m_network(0), m_nam(manager)
+ m_redirectCount(0), m_gotXml(false), m_textCodec(0), m_network(0), m_nam(manager)
{
}
@@ -1277,6 +1287,7 @@ void QDeclarativeXMLHttpRequest::finished()
if (cbv.isError()) printError(cbv);
}
m_responseEntityBody.append(m_network->readAll());
+ readEncoding();
if (xhrDump()) {
qWarning().nospace() << "XMLHttpRequest: RESPONSE " << qPrintable(m_url.toString());
@@ -1302,15 +1313,72 @@ void QDeclarativeXMLHttpRequest::finished()
}
-QString QDeclarativeXMLHttpRequest::responseBody() const
+void QDeclarativeXMLHttpRequest::readEncoding()
+{
+ foreach (const HeaderPair &header, m_headersList) {
+ if (header.first == "content-type") {
+ int separatorIdx = header.second.indexOf(';');
+ if (separatorIdx == -1) {
+ m_mime == header.second;
+ } else {
+ m_mime = header.second.mid(0, separatorIdx);
+ int charsetIdx = header.second.indexOf("charset=");
+ if (charsetIdx != -1) {
+ charsetIdx += 8;
+ separatorIdx = header.second.indexOf(';', charsetIdx);
+ m_charset = header.second.mid(charsetIdx, separatorIdx >= 0 ? separatorIdx : header.second.length());
+ }
+ }
+ break;
+ }
+ }
+
+ if (m_mime.isEmpty() || m_mime == "text/xml" || m_mime == "application/xml" || m_mime.endsWith("+xml"))
+ m_gotXml = true;
+}
+
+bool QDeclarativeXMLHttpRequest::receivedXml() const
+{
+ return m_gotXml;
+}
+
+
+#ifndef QT_NO_TEXTCODEC
+QTextCodec* QDeclarativeXMLHttpRequest::findTextCodec() const
+{
+ QTextCodec *codec = 0;
+
+ if (!m_charset.isEmpty())
+ codec = QTextCodec::codecForName(m_charset);
+
+ if (!codec && m_gotXml) {
+ QXmlStreamReader reader(m_responseEntityBody);
+ reader.readNext();
+ codec = QTextCodec::codecForName(reader.documentEncoding().toString().toUtf8());
+ }
+
+ if (!codec && m_mime == "text/html")
+ codec = QTextCodec::codecForHtml(m_responseEntityBody, 0);
+
+ if (!codec)
+ codec = QTextCodec::codecForUtfText(m_responseEntityBody, 0);
+
+ if (!codec)
+ codec = QTextCodec::codecForName("UTF-8");
+ return codec;
+}
+#endif
+
+
+QString QDeclarativeXMLHttpRequest::responseBody()
{
- QXmlStreamReader reader(m_responseEntityBody);
- reader.readNext();
#ifndef QT_NO_TEXTCODEC
- QTextCodec *codec = QTextCodec::codecForName(reader.documentEncoding().toString().toUtf8());
- if (codec)
- return codec->toUnicode(m_responseEntityBody);
+ if (!m_textCodec)
+ m_textCodec = findTextCodec();
+ if (m_textCodec)
+ return m_textCodec->toUnicode(m_responseEntityBody);
#endif
+
return QString::fromUtf8(m_responseEntityBody);
}
@@ -1571,7 +1639,8 @@ static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScri
if (!request)
THROW_REFERENCE("Not an XMLHttpRequest object");
- if (request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
+ if (!request->receivedXml() ||
+ request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
request->readyState() != QDeclarativeXMLHttpRequest::Done)
return engine->nullValue();
else
diff --git a/src/declarative/util/qdeclarativefontloader.cpp b/src/declarative/util/qdeclarativefontloader.cpp
index 291583c..1755855 100644
--- a/src/declarative/util/qdeclarativefontloader.cpp
+++ b/src/declarative/util/qdeclarativefontloader.cpp
@@ -130,6 +130,7 @@ void QDeclarativeFontLoader::setSource(const QUrl &url)
d->status = Loading;
emit statusChanged();
+ emit sourceChanged();
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(d->url);
if (!lf.isEmpty()) {
diff --git a/src/declarative/util/qdeclarativefontloader_p.h b/src/declarative/util/qdeclarativefontloader_p.h
index a5fbb8f..0344d99 100644
--- a/src/declarative/util/qdeclarativefontloader_p.h
+++ b/src/declarative/util/qdeclarativefontloader_p.h
@@ -60,7 +60,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeFontLoader : public QObject
Q_DECLARE_PRIVATE(QDeclarativeFontLoader)
Q_ENUMS(Status)
- Q_PROPERTY(QUrl source READ source WRITE setSource)
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
@@ -82,6 +82,7 @@ private Q_SLOTS:
void replyFinished();
Q_SIGNALS:
+ void sourceChanged();
void nameChanged();
void statusChanged();
};