summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDavid Boddie <david.boddie@nokia.com>2010-09-30 13:25:45 (GMT)
committerDavid Boddie <david.boddie@nokia.com>2010-09-30 13:25:45 (GMT)
commit70fd09b335f60be7b68f258c47abe2bb092d5775 (patch)
treecef95cddc6adad7d7efb2adb74e423e43ba04322 /examples
parent6700a9f41692912f221fac55e4cae1809549fa13 (diff)
parent8c65dc25962e167237c2573979b1dfff88c29326 (diff)
downloadQt-70fd09b335f60be7b68f258c47abe2bb092d5775.zip
Qt-70fd09b335f60be7b68f258c47abe2bb092d5775.tar.gz
Qt-70fd09b335f60be7b68f258c47abe2bb092d5775.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-doc-team into 4.7
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/animation/easing/easing.qml2
-rw-r--r--examples/declarative/text/fonts/hello.qml3
-rw-r--r--examples/declarative/toys/corkboards/Day.qml15
-rw-r--r--examples/declarative/ui-components/searchbox/SearchBox.qml2
-rw-r--r--examples/multimedia/audiooutput/audiooutput.cpp4
-rw-r--r--examples/opengl/pbuffers/glwidget.cpp4
-rw-r--r--examples/xml/rsslisting/main.cpp1
-rw-r--r--examples/xml/rsslisting/rsslisting.cpp89
-rw-r--r--examples/xml/rsslisting/rsslisting.h16
9 files changed, 79 insertions, 57 deletions
diff --git a/examples/declarative/animation/easing/easing.qml b/examples/declarative/animation/easing/easing.qml
index ffb129d..9349a25 100644
--- a/examples/declarative/animation/easing/easing.qml
+++ b/examples/declarative/animation/easing/easing.qml
@@ -137,7 +137,7 @@ Rectangle {
Flickable {
anchors.fill: parent
- contentHeight: layout.height
+ contentHeight: layout.height+50
Rectangle {
id: titlePane
color: "#444444"
diff --git a/examples/declarative/text/fonts/hello.qml b/examples/declarative/text/fonts/hello.qml
index a396ff3..60bd919 100644
--- a/examples/declarative/text/fonts/hello.qml
+++ b/examples/declarative/text/fonts/hello.qml
@@ -56,10 +56,11 @@ Rectangle {
color: "white"
text: "Hello world!"
font.pixelSize: 60
+ smooth: true
SequentialAnimation on font.letterSpacing {
loops: Animation.Infinite;
- NumberAnimation { from: 100; to: 300; easing.type: Easing.InQuad; duration: 3000 }
+ NumberAnimation { from: 0; to: 150; easing.type: Easing.InQuad; duration: 3000 }
ScriptAction {
script: {
container.y = (screen.height / 4) + (Math.random() * screen.height / 2)
diff --git a/examples/declarative/toys/corkboards/Day.qml b/examples/declarative/toys/corkboards/Day.qml
index f406f7b..3525a5b 100644
--- a/examples/declarative/toys/corkboards/Day.qml
+++ b/examples/declarative/toys/corkboards/Day.qml
@@ -45,9 +45,16 @@ Component {
property variant stickies
id: page
- width: 840; height: 480
+ width: ListView.view.width+40; height: ListView.view.height
- Image { source: "cork.jpg" }
+
+ Image {
+ source: "cork.jpg"
+ width: page.ListView.view.width
+ height: page.ListView.view.height
+ fillMode: Image.PreserveAspectCrop
+ clip: true
+ }
MouseArea {
anchors.fill: parent
@@ -65,8 +72,8 @@ Component {
Item {
id: stickyPage
- property int randomX: Math.random() * 500 + 100
- property int randomY: Math.random() * 200 + 50
+ property int randomX: Math.random() * (page.ListView.view.width-0.5*stickyImage.width) +100
+ property int randomY: Math.random() * (page.ListView.view.height-0.5*stickyImage.height) +50
x: randomX; y: randomY
diff --git a/examples/declarative/ui-components/searchbox/SearchBox.qml b/examples/declarative/ui-components/searchbox/SearchBox.qml
index 60fa799..d000750 100644
--- a/examples/declarative/ui-components/searchbox/SearchBox.qml
+++ b/examples/declarative/ui-components/searchbox/SearchBox.qml
@@ -54,7 +54,7 @@ FocusScope {
source: "images/lineedit-bg-focus.png"
width: parent.width; height: parent.height
border { left: 4; top: 4; right: 4; bottom: 4 }
- visible: parent.wantsFocus ? true : false
+ visible: parent.activeFocus ? true : false
}
Text {
diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp
index bc2324e..451cc67 100644
--- a/examples/multimedia/audiooutput/audiooutput.cpp
+++ b/examples/multimedia/audiooutput/audiooutput.cpp
@@ -132,9 +132,9 @@ void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int
qint64 Generator::readData(char *data, qint64 len)
{
qint64 total = 0;
- while (len - total) {
+ while (len - total > 0) {
const qint64 chunk = qMin((m_buffer.size() - m_pos), len - total);
- memcpy(data, m_buffer.constData() + m_pos, chunk);
+ memcpy(data + total, m_buffer.constData() + m_pos, chunk);
m_pos = (m_pos + chunk) % m_buffer.size();
total += chunk;
}
diff --git a/examples/opengl/pbuffers/glwidget.cpp b/examples/opengl/pbuffers/glwidget.cpp
index 6f4f060..c57a510 100644
--- a/examples/opengl/pbuffers/glwidget.cpp
+++ b/examples/opengl/pbuffers/glwidget.cpp
@@ -62,7 +62,9 @@ GLWidget::GLWidget(QWidget *parent)
, cube(0)
{
// create the pbuffer
- pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
+ QGLFormat pbufferFormat = format();
+ pbufferFormat.setSampleBuffers(false);
+ pbuffer = new QGLPixelBuffer(QSize(512, 512), pbufferFormat, this);
setWindowTitle(tr("OpenGL pbuffers"));
initializeGeometry();
}
diff --git a/examples/xml/rsslisting/main.cpp b/examples/xml/rsslisting/main.cpp
index 95c8a89..71ae0eb 100644
--- a/examples/xml/rsslisting/main.cpp
+++ b/examples/xml/rsslisting/main.cpp
@@ -57,7 +57,6 @@ Provides the main function for the RSS news reader example.
int main(int argc, char **argv)
{
QApplication app(argc, argv);
- qWarning("The usage of QHttp is not recommended anymore, please use QNetworkAccessManager.");
RSSListing *rsslisting = new RSSListing;
rsslisting->show();
return app.exec();
diff --git a/examples/xml/rsslisting/rsslisting.cpp b/examples/xml/rsslisting/rsslisting.cpp
index b7c9eb0..48c3062 100644
--- a/examples/xml/rsslisting/rsslisting.cpp
+++ b/examples/xml/rsslisting/rsslisting.cpp
@@ -65,21 +65,19 @@ its operation, and also allows very large data sources to be read.
Constructs an RSSListing widget with a simple user interface, and sets
up the XML reader to use a custom handler class.
- The user interface consists of a line edit, two push buttons, and a
+ The user interface consists of a line edit, a push button, and a
list view widget. The line edit is used for entering the URLs of news
- sources; the push buttons start and abort the process of reading the
+ sources; the push button starts the process of reading the
news.
*/
RSSListing::RSSListing(QWidget *parent)
- : QWidget(parent)
+ : QWidget(parent), currentReply(0)
{
lineEdit = new QLineEdit(this);
lineEdit->setText("http://labs.qt.nokia.com/blogs/feed");
fetchButton = new QPushButton(tr("Fetch"), this);
- abortButton = new QPushButton(tr("Abort"), this);
- abortButton->setEnabled(false);
treeWidget = new QTreeWidget(this);
connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
@@ -89,15 +87,11 @@ RSSListing::RSSListing(QWidget *parent)
treeWidget->setHeaderLabels(headerLabels);
treeWidget->header()->setResizeMode(QHeaderView::ResizeToContents);
- connect(&http, SIGNAL(readyRead(QHttpResponseHeader)),
- this, SLOT(readData(QHttpResponseHeader)));
-
- connect(&http, SIGNAL(requestFinished(int,bool)),
- this, SLOT(finished(int,bool)));
+ connect(&manager, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(finished(QNetworkReply*)));
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(fetch()));
connect(fetchButton, SIGNAL(clicked()), this, SLOT(fetch()));
- connect(abortButton, SIGNAL(clicked()), &http, SLOT(abort()));
QVBoxLayout *layout = new QVBoxLayout(this);
@@ -105,7 +99,6 @@ RSSListing::RSSListing(QWidget *parent)
hboxLayout->addWidget(lineEdit);
hboxLayout->addWidget(fetchButton);
- hboxLayout->addWidget(abortButton);
layout->addLayout(hboxLayout);
layout->addWidget(treeWidget);
@@ -115,34 +108,53 @@ RSSListing::RSSListing(QWidget *parent)
}
/*
+ Starts the network request and connects the needed signals
+*/
+void RSSListing::get(const QUrl &url)
+{
+ QNetworkRequest request(url);
+ if (currentReply) {
+ currentReply->disconnect(this);
+ currentReply->deleteLater();
+ }
+ currentReply = manager.get(request);
+ connect(currentReply, SIGNAL(readyRead()), this, SLOT(readyRead()));
+ connect(currentReply, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged()));
+ connect(currentReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError)));
+}
+
+/*
Starts fetching data from a news source specified in the line
edit widget.
The line edit is made read only to prevent the user from modifying its
contents during the fetch; this is only for cosmetic purposes.
- The fetch button is disabled, and the abort button is enabled to allow
- the user to interrupt processing. The list view is cleared, and we
+ The fetch button is disabled, the list view is cleared, and we
define the last list view item to be 0, meaning that there are no
existing items in the list.
- The HTTP handler is supplied with the raw contents of the line edit and
- a fetch is initiated. We keep the ID value returned by the HTTP handler
- for future reference.
+ A URL is created with the raw contents of the line edit and
+ a get is initiated.
*/
void RSSListing::fetch()
{
lineEdit->setReadOnly(true);
fetchButton->setEnabled(false);
- abortButton->setEnabled(true);
treeWidget->clear();
xml.clear();
QUrl url(lineEdit->text());
+ get(url);
+}
- http.setHost(url.host());
- connectionId = http.get(url.path());
+void RSSListing::metaDataChanged()
+{
+ QUrl redirectionTarget = currentReply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
+ if (redirectionTarget.isValid()) {
+ get(redirectionTarget);
+ }
}
/*
@@ -150,16 +162,14 @@ void RSSListing::fetch()
We read all the available data, and pass it to the XML
stream reader. Then we call the XML parsing function.
-
- If parsing fails for any reason, we abort the fetch.
*/
-void RSSListing::readData(const QHttpResponseHeader &resp)
+void RSSListing::readyRead()
{
- if (resp.statusCode() != 200)
- http.abort();
- else {
- xml.addData(http.readAll());
+ int statusCode = currentReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ if (statusCode >= 200 && statusCode < 300) {
+ QByteArray data = currentReply->readAll();
+ xml.addData(data);
parseXml();
}
}
@@ -177,19 +187,11 @@ void RSSListing::readData(const QHttpResponseHeader &resp)
user interface available to the user for further input.
*/
-void RSSListing::finished(int id, bool error)
+void RSSListing::finished(QNetworkReply *reply)
{
- if (error) {
- qWarning("Received error during HTTP fetch.");
- lineEdit->setReadOnly(false);
- abortButton->setEnabled(false);
- fetchButton->setEnabled(true);
- }
- else if (id == connectionId) {
- lineEdit->setReadOnly(false);
- abortButton->setEnabled(false);
- fetchButton->setEnabled(true);
- }
+ Q_UNUSED(reply);
+ lineEdit->setReadOnly(false);
+ fetchButton->setEnabled(true);
}
@@ -225,7 +227,6 @@ void RSSListing::parseXml()
}
if (xml.error() && xml.error() != QXmlStreamReader::PrematureEndOfDocumentError) {
qWarning() << "XML ERROR:" << xml.lineNumber() << ": " << xml.errorString();
- http.abort();
}
}
@@ -236,3 +237,11 @@ void RSSListing::itemActivated(QTreeWidgetItem * item)
{
QDesktopServices::openUrl(QUrl(item->text(1)));
}
+
+void RSSListing::error(QNetworkReply::NetworkError)
+{
+ qWarning("error retrieving RSS feed");
+ currentReply->disconnect(this);
+ currentReply->deleteLater();
+ currentReply = 0;
+}
diff --git a/examples/xml/rsslisting/rsslisting.h b/examples/xml/rsslisting/rsslisting.h
index 8939dfd..9387222 100644
--- a/examples/xml/rsslisting/rsslisting.h
+++ b/examples/xml/rsslisting/rsslisting.h
@@ -41,10 +41,12 @@
#ifndef RSSLISTING_H
#define RSSLISTING_H
-#include <QHttp>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
#include <QWidget>
#include <QBuffer>
#include <QXmlStreamReader>
+#include <QUrl>
QT_BEGIN_NAMESPACE
class QLineEdit;
@@ -61,24 +63,26 @@ public:
public slots:
void fetch();
- void finished(int id, bool error);
- void readData(const QHttpResponseHeader &);
+ void finished(QNetworkReply *reply);
+ void readyRead();
+ void metaDataChanged();
void itemActivated(QTreeWidgetItem * item);
+ void error(QNetworkReply::NetworkError);
private:
void parseXml();
+ void get(const QUrl &url);
QXmlStreamReader xml;
QString currentTag;
QString linkString;
QString titleString;
- QHttp http;
- int connectionId;
+ QNetworkAccessManager manager;
+ QNetworkReply *currentReply;
QLineEdit *lineEdit;
QTreeWidget *treeWidget;
- QPushButton *abortButton;
QPushButton *fetchButton;
};