summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets
diff options
context:
space:
mode:
authorTobias Koenig <tokoe@kde.org>2009-06-04 18:44:12 (GMT)
committerTobias Koenig <tokoe@kde.org>2009-06-04 18:44:12 (GMT)
commit5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd (patch)
treea1fc7824b38c3b712893794cfe55fa285cd3c760 /doc/src/snippets
parentf7741b78c90abcb272345810d55e446a7f390032 (diff)
parentb1b09172aee658e085423ddf6abfea291a072c74 (diff)
downloadQt-5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd.zip
Qt-5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd.tar.gz
Qt-5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd.tar.bz2
Merge commit 'qt-mainline/master'
Diffstat (limited to 'doc/src/snippets')
-rw-r--r--doc/src/snippets/animation/sequential/icons.qrc6
-rw-r--r--doc/src/snippets/animation/sequential/icons/left.pngbin0 -> 413 bytes
-rw-r--r--doc/src/snippets/animation/sequential/icons/right.pngbin0 -> 414 bytes
-rw-r--r--doc/src/snippets/animation/sequential/main.cpp50
-rw-r--r--doc/src/snippets/animation/sequential/sequential.pro4
-rw-r--r--doc/src/snippets/animation/sequential/tracer.cpp25
-rw-r--r--doc/src/snippets/animation/sequential/tracer.h23
-rw-r--r--doc/src/snippets/code/doc_src_layout.qdoc45
-rw-r--r--doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp4
-rw-r--r--doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp2
-rw-r--r--doc/src/snippets/code/src_gui_image_qpixmapcache.cpp2
-rw-r--r--doc/src/snippets/picture/picture.cpp2
-rw-r--r--doc/src/snippets/sqldatabase/sqldatabase.cpp2
-rw-r--r--doc/src/snippets/widgets-tutorial/template.cpp14
14 files changed, 156 insertions, 23 deletions
diff --git a/doc/src/snippets/animation/sequential/icons.qrc b/doc/src/snippets/animation/sequential/icons.qrc
new file mode 100644
index 0000000..d55f797
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/icons.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>icons/left.png</file>
+ <file>icons/right.png</file>
+ </qresource>
+</RCC>
diff --git a/doc/src/snippets/animation/sequential/icons/left.png b/doc/src/snippets/animation/sequential/icons/left.png
new file mode 100644
index 0000000..5dd8da0
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/icons/left.png
Binary files differ
diff --git a/doc/src/snippets/animation/sequential/icons/right.png b/doc/src/snippets/animation/sequential/icons/right.png
new file mode 100644
index 0000000..ac61326
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/icons/right.png
Binary files differ
diff --git a/doc/src/snippets/animation/sequential/main.cpp b/doc/src/snippets/animation/sequential/main.cpp
new file mode 100644
index 0000000..aff8f29
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/main.cpp
@@ -0,0 +1,50 @@
+#include <QApplication>
+#include <QLabel>
+#include <QPropertyAnimation>
+#include <QSequentialAnimationGroup>
+#include "tracer.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QWidget window;
+ window.resize(720, 96);
+ window.show();
+
+ QLabel *label1 = new QLabel(&window);
+ label1->setPixmap(QPixmap(":/icons/left.png"));
+ label1->move(16, 16);
+ label1->show();
+
+ QLabel *label2 = new QLabel(&window);
+ label2->setPixmap(QPixmap(":/icons/right.png"));
+ label2->move(320, 16);
+ label2->show();
+
+ QPropertyAnimation *anim1 = new QPropertyAnimation(label1, "pos");
+ anim1->setDuration(2500);
+ anim1->setStartValue(QPoint(16, 16));
+ anim1->setEndValue(QPoint(320, 16));
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(label2, "pos");
+ anim2->setDuration(2500);
+ anim2->setStartValue(QPoint(320, 16));
+ anim2->setEndValue(QPoint(640, 16));
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(anim1);
+ group.addAnimation(anim2);
+
+ Tracer tracer(&window);
+
+ QObject::connect(anim1, SIGNAL(valueChanged(QVariant)),
+ &tracer, SLOT(recordValue(QVariant)));
+ QObject::connect(anim2, SIGNAL(valueChanged(QVariant)),
+ &tracer, SLOT(recordValue(QVariant)));
+ QObject::connect(anim1, SIGNAL(finished()), &tracer, SLOT(checkValue()));
+ QObject::connect(anim2, SIGNAL(finished()), &tracer, SLOT(checkValue()));
+
+ group.start();
+ return app.exec();
+}
diff --git a/doc/src/snippets/animation/sequential/sequential.pro b/doc/src/snippets/animation/sequential/sequential.pro
new file mode 100644
index 0000000..fcf017f
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/sequential.pro
@@ -0,0 +1,4 @@
+HEADERS = tracer.h
+RESOURCES = icons.qrc
+SOURCES = main.cpp \
+ tracer.cpp
diff --git a/doc/src/snippets/animation/sequential/tracer.cpp b/doc/src/snippets/animation/sequential/tracer.cpp
new file mode 100644
index 0000000..49bd51e
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/tracer.cpp
@@ -0,0 +1,25 @@
+#include <QAbstractAnimation>
+#include <QDebug>
+#include <QPoint>
+#include "tracer.h"
+
+Tracer::Tracer(QObject *parent)
+ : QObject(parent)
+{
+}
+
+void Tracer::checkValue()
+{
+ QAbstractAnimation *animation = static_cast<QAbstractAnimation *>(sender());
+ if (time != animation->duration()) {
+ qDebug() << "Animation's last recorded time" << time;
+ qDebug() << "Expected" << animation->duration();
+ }
+}
+
+void Tracer::recordValue(const QVariant &value)
+{
+ QAbstractAnimation *animation = static_cast<QAbstractAnimation *>(sender());
+ this->value = value;
+ time = animation->currentTime();
+}
diff --git a/doc/src/snippets/animation/sequential/tracer.h b/doc/src/snippets/animation/sequential/tracer.h
new file mode 100644
index 0000000..1adb018
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/tracer.h
@@ -0,0 +1,23 @@
+#ifndef TRACER_H
+#define TRACER_H
+
+#include <QObject>
+#include <QVariant>
+
+class Tracer : public QObject
+{
+ Q_OBJECT
+
+public:
+ Tracer(QObject *parent = 0);
+
+public slots:
+ void checkValue();
+ void recordValue(const QVariant &value);
+
+private:
+ QVariant value;
+ int time;
+};
+
+#endif
diff --git a/doc/src/snippets/code/doc_src_layout.qdoc b/doc/src/snippets/code/doc_src_layout.qdoc
index 48e10e9..60f36b0 100644
--- a/doc/src/snippets/code/doc_src_layout.qdoc
+++ b/doc/src/snippets/code/doc_src_layout.qdoc
@@ -2,23 +2,21 @@
#ifndef CARD_H
#define CARD_H
-#include <QLayout>
+#include <QtGui>
#include <QList>
class CardLayout : public QLayout
{
public:
- CardLayout(QWidget *parent, int dist)
- : QLayout(parent, 0, dist) {}
- CardLayout(QLayout *parent, int dist)
- : QLayout(parent, dist) {}
- CardLayout(int dist)
- : QLayout(dist) {}
+ CardLayout(QWidget *parent, int dist): QLayout(parent, 0, dist) {}
+ CardLayout(QLayout *parent, int dist): QLayout(parent, dist) {}
+ CardLayout(int dist): QLayout(dist) {}
~CardLayout();
void addItem(QLayoutItem *item);
QSize sizeHint() const;
QSize minimumSize() const;
+ QLayoutItem *count() const;
QLayoutItem *itemAt(int) const;
QLayoutItem *takeAt(int);
void setGeometry(const QRect &rect);
@@ -31,11 +29,18 @@ private:
//! [1]
-#include "card.h"
+//#include "card.h"
//! [1]
-
//! [2]
+QLayoutItem *CardLayout::count() const
+{
+ // QList::size() returns the number of QLayoutItems in the list
+ return list.size();
+}
+//! [2]
+
+//! [3]
QLayoutItem *CardLayout::itemAt(int idx) const
{
// QList::value() performs index checking, and returns 0 if we are
@@ -48,26 +53,28 @@ QLayoutItem *CardLayout::takeAt(int idx)
// QList::take does not do index checking
return idx >= 0 && idx < list.size() ? list.takeAt(idx) : 0;
}
-//! [2]
+//! [3]
-//! [3]
+//! [4]
void CardLayout::addItem(QLayoutItem *item)
{
list.append(item);
}
-//! [3]
+//! [4]
-//! [4]
+//! [5]
CardLayout::~CardLayout()
{
- deleteAllItems();
+ QLayoutItem *item;
+ while ((item = takeAt(0)))
+ delete item;
}
-//! [4]
+//! [5]
-//! [5]
+//! [6]
void CardLayout::setGeometry(const QRect &r)
{
QLayout::setGeometry(r);
@@ -85,10 +92,10 @@ void CardLayout::setGeometry(const QRect &r)
++i;
}
}
-//! [5]
+//! [6]
-//! [6]
+//! [7]
QSize CardLayout::sizeHint() const
{
QSize s(0,0);
@@ -116,4 +123,4 @@ QSize CardLayout::minimumSize() const
}
return s + n*QSize(spacing(), spacing());
}
-//! [6]
+//! [7]
diff --git a/doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp b/doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp
new file mode 100644
index 0000000..65358ea
--- /dev/null
+++ b/doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp
@@ -0,0 +1,4 @@
+//! [0]
+qreal myEasingFunction(qreal progress);
+//! [0]
+
diff --git a/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp b/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp
index a57de9d..d9e38ed 100644
--- a/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp
+++ b/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp
@@ -6,7 +6,7 @@ public:
{
qreal penWidth = 1;
return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
- 20 + penWidth / 2, 20 + penWidth / 2);
+ 20 + penWidth, 20 + penWidth);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
diff --git a/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp b/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp
index c4b6353..2a04f64 100644
--- a/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp
+++ b/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp
@@ -13,7 +13,7 @@ painter->drawPixmap(0, 0, p);
//! [1]
QPixmap pm;
-if (!QPixmapCache::find("my_big_image", pm)) {
+if (!QPixmapCache::find("my_big_image", &pm)) {
pm.load("bigimage.png");
QPixmapCache::insert("my_big_image", pm);
}
diff --git a/doc/src/snippets/picture/picture.cpp b/doc/src/snippets/picture/picture.cpp
index 07cedbf..be171c6 100644
--- a/doc/src/snippets/picture/picture.cpp
+++ b/doc/src/snippets/picture/picture.cpp
@@ -66,7 +66,7 @@ int main()
QPicture picture;
picture.load("drawing.pic"); // load picture
QPainter painter;
- painter.begin(&myWidget); // paint in myWidget
+ painter.begin(&myImage); // paint in myImage
painter.drawPicture(0, 0, picture); // draw the picture at (0,0)
painter.end(); // painting done
//! [1]
diff --git a/doc/src/snippets/sqldatabase/sqldatabase.cpp b/doc/src/snippets/sqldatabase/sqldatabase.cpp
index ae176ac..06afa0c 100644
--- a/doc/src/snippets/sqldatabase/sqldatabase.cpp
+++ b/doc/src/snippets/sqldatabase/sqldatabase.cpp
@@ -524,7 +524,7 @@ protected:
bool fetchLast() { return false; }
int size() { return 0; }
int numRowsAffected() { return 0; }
- QSqlRecord record() { return QSqlRecord(); }
+ QSqlRecord record() const { return QSqlRecord(); }
};
//! [47]
diff --git a/doc/src/snippets/widgets-tutorial/template.cpp b/doc/src/snippets/widgets-tutorial/template.cpp
new file mode 100644
index 0000000..5958676
--- /dev/null
+++ b/doc/src/snippets/widgets-tutorial/template.cpp
@@ -0,0 +1,14 @@
+#include <QtGui>
+
+// Include header files for application components.
+// ...
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ // Set up and show widgets.
+ // ...
+
+ return app.exec();
+}