summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJason Barron <jbarron@trolltech.com>2009-08-10 06:56:35 (GMT)
committerJason Barron <jbarron@trolltech.com>2009-08-10 06:56:35 (GMT)
commitf61ec84fc296c6f70011e30788ee511d6b6a18c6 (patch)
tree54b3b81ac83570e65dc9b44b6756005f6ba1efde /examples
parentcc0a411e5e874aa224c26298a109973cb15ea291 (diff)
parentd13418effc5f00474541ae513a30c9a42c2a1cb3 (diff)
downloadQt-f61ec84fc296c6f70011e30788ee511d6b6a18c6.zip
Qt-f61ec84fc296c6f70011e30788ee511d6b6a18c6.tar.gz
Qt-f61ec84fc296c6f70011e30788ee511d6b6a18c6.tar.bz2
Merge commit 'qt/master-stable'
Conflicts: src/corelib/kernel/qobject.cpp src/corelib/tools/qsharedpointer_impl.h src/gui/widgets/qdatetimeedit.cpp src/gui/widgets/qlinecontrol.cpp src/gui/widgets/qlineedit.cpp tests/auto/qcssparser/qcssparser.pro tests/auto/qicoimageformat/tst_qicoimageformat.cpp tests/auto/qmultiscreen/qmultiscreen.pro tests/auto/qresourceengine/qresourceengine.pro tests/auto/qresourceengine/tst_qresourceengine.cpp tests/auto/qscriptv8testsuite/tst_qscriptv8testsuite.cpp
Diffstat (limited to 'examples')
-rw-r--r--examples/gestures/imageviewer/imagewidget.cpp13
-rw-r--r--examples/gestures/imageviewer/tapandholdgesture.cpp33
-rw-r--r--examples/gestures/imageviewer/tapandholdgesture.h1
-rw-r--r--examples/script/calculator/calculator.js107
-rw-r--r--examples/script/customclass/bytearrayclass.cpp2
-rw-r--r--examples/statemachine/rogue/main.cpp55
-rw-r--r--examples/statemachine/rogue/movementtransition.h108
-rw-r--r--examples/statemachine/rogue/rogue.pro11
-rw-r--r--examples/statemachine/rogue/window.cpp201
-rw-r--r--examples/statemachine/rogue/window.h89
-rw-r--r--examples/statemachine/statemachine.pro1
-rw-r--r--examples/webkit/framecapture/framecapture.cpp121
-rw-r--r--examples/webkit/framecapture/framecapture.h70
-rw-r--r--examples/webkit/framecapture/framecapture.pro11
-rw-r--r--examples/webkit/framecapture/main.cpp76
15 files changed, 841 insertions, 58 deletions
diff --git a/examples/gestures/imageviewer/imagewidget.cpp b/examples/gestures/imageviewer/imagewidget.cpp
index 99889ed..c0d1e2d 100644
--- a/examples/gestures/imageviewer/imagewidget.cpp
+++ b/examples/gestures/imageviewer/imagewidget.cpp
@@ -67,6 +67,7 @@ ImageWidget::ImageWidget(QWidget *parent)
tapAndHoldGesture = new TapAndHoldGesture(this);
connect(tapAndHoldGesture, SIGNAL(triggered()), this, SLOT(gestureTriggered()));
+ connect(tapAndHoldGesture, SIGNAL(finished()), this, SLOT(gestureTriggered()));
}
void ImageWidget::paintEvent(QPaintEvent*)
@@ -112,7 +113,7 @@ void ImageWidget::paintEvent(QPaintEvent*)
touchFeedback.position + QPoint(-10, 10),
touchFeedback.position + QPoint(-15, 0)
};
- for (int i = 0; i < (touchFeedback.tapAndHoldState-20)/10; ++i)
+ for (int i = 0; i < touchFeedback.tapAndHoldState/5; ++i)
p.drawEllipse(pts[i], 3, 3);
}
} else if (touchFeedback.sliding) {
@@ -156,10 +157,9 @@ void ImageWidget::mouseDoubleClickEvent(QMouseEvent *event)
void ImageWidget::gestureTriggered()
{
- touchFeedback.tapped = false;
- touchFeedback.doubleTapped = false;
-
if (sender() == panGesture) {
+ touchFeedback.tapped = false;
+ touchFeedback.doubleTapped = false;
QPanGesture *pg = qobject_cast<QPanGesture*>(sender());
if (zoomedIn) {
#ifndef QT_NO_CURSOR
@@ -174,7 +174,6 @@ void ImageWidget::gestureTriggered()
#endif
horizontalOffset += pg->lastOffset().width();
verticalOffset += pg->lastOffset().height();
- update();
} else {
// only slide gesture should be accepted
if (pg->state() == Qt::GestureFinished) {
@@ -187,6 +186,7 @@ void ImageWidget::gestureTriggered()
updateImage();
}
}
+ update();
feedbackFadeOutTimer.start(500, this);
} else if (sender() == tapAndHoldGesture) {
if (tapAndHoldGesture->state() == Qt::GestureFinished) {
@@ -199,6 +199,9 @@ void ImageWidget::gestureTriggered()
menu.addAction("Action 2");
menu.addAction("Action 3");
menu.exec(mapToGlobal(tapAndHoldGesture->pos()));
+ } else {
+ ++touchFeedback.tapAndHoldState;
+ update();
}
feedbackFadeOutTimer.start(500, this);
}
diff --git a/examples/gestures/imageviewer/tapandholdgesture.cpp b/examples/gestures/imageviewer/tapandholdgesture.cpp
index ff5284e..5fe52cc 100644
--- a/examples/gestures/imageviewer/tapandholdgesture.cpp
+++ b/examples/gestures/imageviewer/tapandholdgesture.cpp
@@ -43,6 +43,8 @@
#include <QtGui/qevent.h>
+// #define TAPANDHOLD_USING_MOUSE
+
/*!
\class TapAndHoldGesture
\since 4.6
@@ -95,6 +97,26 @@ bool TapAndHoldGesture::filterEvent(QEvent *event)
case QEvent::TouchEnd:
reset();
break;
+#ifdef TAPANDHOLD_USING_MOUSE
+ case QEvent::MouseButtonPress: {
+ if (timer.isActive())
+ timer.stop();
+ timer.start(TapAndHoldGesture::iterationTimeout, this);
+ const QPoint p = static_cast<QMouseEvent*>(event)->pos();
+ position = startPosition = p;
+ break;
+ }
+ case QEvent::MouseMove: {
+ const QPoint startPos = startPosition;
+ const QPoint pos = static_cast<QMouseEvent*>(event)->pos();
+ if ((startPos - pos).manhattanLength() > 15)
+ reset();
+ break;
+ }
+ case QEvent::MouseButtonRelease:
+ reset();
+ break;
+#endif // TAPANDHOLD_USING_MOUSE
default:
break;
}
@@ -108,11 +130,9 @@ void TapAndHoldGesture::timerEvent(QTimerEvent *event)
return;
if (iteration == TapAndHoldGesture::iterationCount) {
timer.stop();
- setState(Qt::GestureFinished);
- emit triggered();
+ updateState(Qt::GestureFinished);
} else {
- setState(Qt::GestureStarted);
- emit triggered();
+ updateState(Qt::GestureUpdated);
}
++iteration;
}
@@ -120,11 +140,10 @@ void TapAndHoldGesture::timerEvent(QTimerEvent *event)
/*! \internal */
void TapAndHoldGesture::reset()
{
- if (state() != Qt::NoGesture)
- emit cancelled();
- setState(Qt::NoGesture);
timer.stop();
iteration = 0;
+ position = startPosition = QPoint();
+ updateState(Qt::NoGesture);
}
/*!
diff --git a/examples/gestures/imageviewer/tapandholdgesture.h b/examples/gestures/imageviewer/tapandholdgesture.h
index e0d50b5..61fabc2 100644
--- a/examples/gestures/imageviewer/tapandholdgesture.h
+++ b/examples/gestures/imageviewer/tapandholdgesture.h
@@ -66,6 +66,7 @@ private:
QBasicTimer timer;
int iteration;
QPoint position;
+ QPoint startPosition;
static const int iterationCount;
static const int iterationTimeout;
};
diff --git a/examples/script/calculator/calculator.js b/examples/script/calculator/calculator.js
index 62c2cba..ac3c1b6 100644
--- a/examples/script/calculator/calculator.js
+++ b/examples/script/calculator/calculator.js
@@ -1,10 +1,19 @@
+Function.prototype.bind = function() {
+ var func = this;
+ var thisObject = arguments[0];
+ var args = Array.prototype.slice.call(arguments, 1);
+ return function() {
+ return func.apply(thisObject, args);
+ }
+}
+
//! [0]
function Calculator(ui)
{
this.ui = ui;
- this.pendingAdditiveOperator = "";
- this.pendingMultiplicativeOperator = "";
+ this.pendingAdditiveOperator = Calculator.NO_OPERATOR;
+ this.pendingMultiplicativeOperator = Calculator.NO_OPERATOR;
this.sumInMemory = 0;
this.sumSoFar = 0;
this.factorSoFar = 0;
@@ -13,16 +22,16 @@ function Calculator(ui)
with (ui) {
display.text = "0";
- zeroButton.clicked.connect(this, this.digitClicked);
- oneButton.clicked.connect(this, "digitClicked");
- twoButton.clicked.connect(this, "digitClicked");
- threeButton.clicked.connect(this, "digitClicked");
- fourButton.clicked.connect(this, "digitClicked");
- fiveButton.clicked.connect(this, "digitClicked");
- sixButton.clicked.connect(this, "digitClicked");
- sevenButton.clicked.connect(this, "digitClicked");
- eightButton.clicked.connect(this, "digitClicked");
- nineButton.clicked.connect(this, "digitClicked");
+ zeroButton.clicked.connect(this.digitClicked.bind(this, 0));
+ oneButton.clicked.connect(this.digitClicked.bind(this, 1));
+ twoButton.clicked.connect(this.digitClicked.bind(this, 2));
+ threeButton.clicked.connect(this.digitClicked.bind(this, 3));
+ fourButton.clicked.connect(this.digitClicked.bind(this, 4));
+ fiveButton.clicked.connect(this.digitClicked.bind(this, 5));
+ sixButton.clicked.connect(this.digitClicked.bind(this, 6));
+ sevenButton.clicked.connect(this.digitClicked.bind(this, 7));
+ eightButton.clicked.connect(this.digitClicked.bind(this, 8));
+ nineButton.clicked.connect(this.digitClicked.bind(this, 9));
pointButton.clicked.connect(this, "pointClicked");
changeSignButton.clicked.connect(this, "changeSignClicked");
@@ -36,19 +45,28 @@ function Calculator(ui)
setMemoryButton.clicked.connect(this, "setMemory");
addToMemoryButton.clicked.connect(this, "addToMemory");
- divisionButton.clicked.connect(this, "multiplicativeOperatorClicked");
- timesButton.clicked.connect(this, "multiplicativeOperatorClicked");
- minusButton.clicked.connect(this, "additiveOperatorClicked");
- plusButton.clicked.connect(this, "additiveOperatorClicked");
-
- squareRootButton.clicked.connect(this, "unaryOperatorClicked");
- powerButton.clicked.connect(this, "unaryOperatorClicked");
- reciprocalButton.clicked.connect(this, "unaryOperatorClicked");
+ divisionButton.clicked.connect(this.multiplicativeOperatorClicked.bind(this, Calculator.DIVISION_OPERATOR));
+ timesButton.clicked.connect(this.multiplicativeOperatorClicked.bind(this, Calculator.TIMES_OPERATOR));
+ minusButton.clicked.connect(this.additiveOperatorClicked.bind(this, Calculator.MINUS_OPERATOR));
+ plusButton.clicked.connect(this.additiveOperatorClicked.bind(this, Calculator.PLUS_OPERATOR));
+
+ squareRootButton.clicked.connect(this.unaryOperatorClicked.bind(this, Calculator.SQUARE_OPERATOR));
+ powerButton.clicked.connect(this.unaryOperatorClicked.bind(this, Calculator.POWER_OPERATOR));
+ reciprocalButton.clicked.connect(this.unaryOperatorClicked.bind(this, Calculator.RECIPROCAL_OPERATOR));
equalButton.clicked.connect(this, "equalClicked");
}
}
//! [0]
+Calculator.NO_OPERATOR = 0;
+Calculator.SQUARE_OPERATOR = 1;
+Calculator.POWER_OPERATOR = 2;
+Calculator.RECIPROCAL_OPERATOR = 3;
+Calculator.DIVISION_OPERATOR = 4;
+Calculator.TIMES_OPERATOR = 5;
+Calculator.MINUS_OPERATOR = 6;
+Calculator.PLUS_OPERATOR = 7;
+
Calculator.prototype.abortOperation = function()
{
this.clearAll();
@@ -57,24 +75,23 @@ Calculator.prototype.abortOperation = function()
Calculator.prototype.calculate = function(rightOperand, pendingOperator)
{
- if (pendingOperator == "+") {
+ if (pendingOperator == Calculator.PLUS_OPERATOR) {
this.sumSoFar += rightOperand;
- } else if (pendingOperator == "-") {
+ } else if (pendingOperator == Calculator.MINUS_OPERATOR) {
this.sumSoFar -= rightOperand;
- } else if (pendingOperator == "*") {
+ } else if (pendingOperator == Calculator.TIMES_OPERATOR) {
this.factorSoFar *= rightOperand;
- } else if (pendingOperator == "/") {
+ } else if (pendingOperator == Calculator.DIVISION_OPERATOR) {
if (rightOperand == 0)
- return false;
+ return false;
this.factorSoFar /= rightOperand;
}
return true;
}
//! [1]
-Calculator.prototype.digitClicked = function()
+Calculator.prototype.digitClicked = function(digitValue)
{
- var digitValue = __qt_sender__.text - 0;
if ((digitValue == 0) && (this.ui.display.text == "0"))
return;
if (this.waitingForOperand) {
@@ -85,19 +102,19 @@ Calculator.prototype.digitClicked = function()
}
//! [1]
-Calculator.prototype.unaryOperatorClicked = function()
+Calculator.prototype.unaryOperatorClicked = function(op)
{
var operand = this.ui.display.text - 0;
var result = 0;
- if (__qt_sender__.text == "Sqrt") {
+ if (op == Calculator.SQUARE_OPERATOR) {
if (operand < 0) {
this.abortOperation();
return;
}
result = Math.sqrt(operand);
- } else if (__qt_sender__.text == "x^2") {
+ } else if (op == Calculator.POWER_OPERATOR) {
result = Math.pow(operand, 2);
- } else if (__qt_sender__.text == "1/x") {
+ } else if (op == Calculator.RECIPROCAL_OPERATOR) {
if (operand == 0.0) {
this.abortOperation();
return;
@@ -108,11 +125,11 @@ Calculator.prototype.unaryOperatorClicked = function()
this.waitingForOperand = true;
}
-Calculator.prototype.additiveOperatorClicked = function()
+Calculator.prototype.additiveOperatorClicked = function(op)
{
var operand = this.ui.display.text - 0;
- if (this.pendingMultiplicativeOperator.length != 0) {
+ if (this.pendingMultiplicativeOperator != Calculator.NO_OPERATOR) {
if (!this.calculate(operand, this.pendingMultiplicativeOperator)) {
this.abortOperation();
return;
@@ -120,10 +137,10 @@ Calculator.prototype.additiveOperatorClicked = function()
this.ui.display.text = this.factorSoFar + "";
operand = this.factorSoFar;
this.factorSoFar = 0;
- this.pendingMultiplicativeOperator = "";
+ this.pendingMultiplicativeOperator = Calculator.NO_OPERATOR;
}
- if (this.pendingAdditiveOperator.length != 0) {
+ if (this.pendingAdditiveOperator != Calculator.NO_OPERATOR) {
if (!this.calculate(operand, this.pendingAdditiveOperator)) {
this.abortOperation();
return;
@@ -133,15 +150,15 @@ Calculator.prototype.additiveOperatorClicked = function()
this.sumSoFar = operand;
}
- this.pendingAdditiveOperator = __qt_sender__.text;
+ this.pendingAdditiveOperator = op;
this.waitingForOperand = true;
}
-Calculator.prototype.multiplicativeOperatorClicked = function()
+Calculator.prototype.multiplicativeOperatorClicked = function(op)
{
var operand = this.ui.display.text - 0;
- if (this.pendingMultiplicativeOperator.length != 0) {
+ if (this.pendingMultiplicativeOperator != Calculator.NO_OPERATOR) {
if (!this.calculate(operand, this.pendingMultiplicativeOperator)) {
this.abortOperation();
return;
@@ -151,7 +168,7 @@ Calculator.prototype.multiplicativeOperatorClicked = function()
this.factorSoFar = operand;
}
- this.pendingMultiplicativeOperator = __qt_sender__.text;
+ this.pendingMultiplicativeOperator = op;
this.waitingForOperand = true;
}
@@ -159,21 +176,21 @@ Calculator.prototype.equalClicked = function()
{
var operand = this.ui.display.text - 0;
- if (this.pendingMultiplicativeOperator.length != 0) {
+ if (this.pendingMultiplicativeOperator != Calculator.NO_OPERATOR) {
if (!this.calculate(operand, this.pendingMultiplicativeOperator)) {
this.abortOperation();
return;
}
operand = this.factorSoFar;
this.factorSoFar = 0.0;
- this.pendingMultiplicativeOperator = "";
+ this.pendingMultiplicativeOperator = Calculator.NO_OPERATOR;
}
- if (this.pendingAdditiveOperator.length != 0) {
+ if (this.pendingAdditiveOperator != Calculator.NO_OPERATOR) {
if (!this.calculate(operand, this.pendingAdditiveOperator)) {
this.abortOperation();
return;
}
- this.pendingAdditiveOperator = "";
+ this.pendingAdditiveOperator = Calculator.NO_OPERATOR;
} else {
this.sumSoFar = operand;
}
@@ -234,8 +251,8 @@ Calculator.prototype.clearAll = function()
{
this.sumSoFar = 0.0;
this.factorSoFar = 0.0;
- this.pendingAdditiveOperator = "";
- this.pendingMultiplicativeOperator = "";
+ this.pendingAdditiveOperator = Calculator.NO_OPERATOR;
+ this.pendingMultiplicativeOperator = Calculator.NO_OPERATOR;
this.ui.display.text = "0";
this.waitingForOperand = true;
}
diff --git a/examples/script/customclass/bytearrayclass.cpp b/examples/script/customclass/bytearrayclass.cpp
index 2044a16..8fe1a96 100644
--- a/examples/script/customclass/bytearrayclass.cpp
+++ b/examples/script/customclass/bytearrayclass.cpp
@@ -297,7 +297,7 @@ void ByteArrayClassPropertyIterator::toBack()
QScriptString ByteArrayClassPropertyIterator::name() const
{
- return QScriptString();
+ return object().engine()->toStringHandle(QString::number(m_last));
}
uint ByteArrayClassPropertyIterator::id() const
diff --git a/examples/statemachine/rogue/main.cpp b/examples/statemachine/rogue/main.cpp
new file mode 100644
index 0000000..0c2fb2d
--- /dev/null
+++ b/examples/statemachine/rogue/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ Window window;
+ window.show();
+
+ return app.exec();
+}
+
diff --git a/examples/statemachine/rogue/movementtransition.h b/examples/statemachine/rogue/movementtransition.h
new file mode 100644
index 0000000..929077d
--- /dev/null
+++ b/examples/statemachine/rogue/movementtransition.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MOVEMENTTRANSITION_H
+#define MOVEMENTTRANSITION_H
+
+#include <QtGui>
+
+#include "window.h"
+
+//![0]
+class MovementTransition : public QEventTransition
+{
+ Q_OBJECT
+
+public:
+ MovementTransition(Window *window) :
+ QEventTransition(window, QEvent::KeyPress) {
+ this->window = window;
+ }
+//![0]
+
+//![1]
+protected:
+ bool eventTest(QEvent *event) {
+ if (event->type() == QEvent::Wrapped &&
+ static_cast<QWrappedEvent *>(event)->event()->type() == QEvent::KeyPress) {
+ QEvent *wrappedEvent = static_cast<QWrappedEvent *>(event)->event();
+
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(wrappedEvent);
+ int key = keyEvent->key();
+
+ return key == Qt::Key_2 || key == Qt::Key_8 || key == Qt::Key_6 ||
+ key == Qt::Key_4;
+ }
+ return false;
+ }
+//![1]
+
+//![2]
+ void onTransition(QEvent *event) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(
+ static_cast<QWrappedEvent *>(event)->event());
+
+ int key = keyEvent->key();
+ switch (key) {
+ case Qt::Key_4:
+ window->movePlayer(Window::Left);
+ break;
+ case Qt::Key_8:
+ window->movePlayer(Window::Up);
+ break;
+ case Qt::Key_6:
+ window->movePlayer(Window::Right);
+ break;
+ case Qt::Key_2:
+ window->movePlayer(Window::Down);
+ break;
+ default:
+ ;
+ }
+ }
+//![2]
+
+private:
+ Window *window;
+};
+
+#endif
+
diff --git a/examples/statemachine/rogue/rogue.pro b/examples/statemachine/rogue/rogue.pro
new file mode 100644
index 0000000..1571854
--- /dev/null
+++ b/examples/statemachine/rogue/rogue.pro
@@ -0,0 +1,11 @@
+HEADERS = window.h \
+ movementtransition.h
+SOURCES = main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/rogue
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/rogue
+INSTALLS += target sources
+
diff --git a/examples/statemachine/rogue/window.cpp b/examples/statemachine/rogue/window.cpp
new file mode 100644
index 0000000..39565a3
--- /dev/null
+++ b/examples/statemachine/rogue/window.cpp
@@ -0,0 +1,201 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+#include "movementtransition.h"
+
+//![0]
+Window::Window()
+{
+ pX = 5;
+ pY = 5;
+//![0]
+
+ QFontDatabase database;
+ QFont font;
+ if (database.families().contains("Monospace"))
+ font = QFont("Monospace", 12);
+ else {
+ foreach (QString family, database.families()) {
+ if (database.isFixedPitch(family)) {
+ font = QFont(family, 12);
+ break;
+ }
+ }
+ }
+ setFont(font);
+
+//![1]
+ setupMap();
+ buildMachine();
+}
+//![1]
+
+void Window::setStatus(const QString &status)
+{
+ myStatus = status;
+ repaint();
+}
+
+QString Window::status() const
+{
+ return myStatus;
+}
+
+void Window::paintEvent(QPaintEvent * /* event */)
+{
+ QFontMetrics metrics(font());
+ QPainter painter(this);
+ int fontHeight = metrics.height();
+ int fontWidth = metrics.width('X');
+ int yPos = fontHeight;
+ int xPos;
+
+ painter.fillRect(rect(), Qt::black);
+ painter.setPen(Qt::white);
+
+ painter.drawText(QPoint(0, yPos), status());
+
+ for (int y = 0; y < HEIGHT; ++y) {
+ yPos += fontHeight;
+ xPos = 0;
+
+ for (int x = 0; x < WIDTH; ++x) {
+ if (y == pY && x == pX) {
+ xPos += fontWidth;
+ continue;
+ }
+
+ painter.drawText(QPoint(xPos, yPos), map[x][y]);
+ xPos += fontWidth;
+ }
+ }
+ painter.drawText(QPoint(pX * fontWidth, (pY + 2) * fontHeight), QChar('@'));
+}
+
+QSize Window::sizeHint() const
+{
+ QFontMetrics metrics(font());
+
+ return QSize(metrics.width('X') * WIDTH, metrics.height() * (HEIGHT + 1));
+}
+
+//![2]
+void Window::buildMachine()
+{
+ machine = new QStateMachine;
+
+ QState *inputState = new QState(machine);
+ inputState->assignProperty(this, "status", "Move the rogue with 2, 4, 6, and 8");
+
+ MovementTransition *transition = new MovementTransition(this);
+ inputState->addTransition(transition);
+//![2]
+
+//![3]
+ QState *quitState = new QState(machine);
+ quitState->assignProperty(this, "status", "Really quit(y/n)?");
+
+ QKeyEventTransition *yesTransition = new
+ QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Y);
+ yesTransition->setTargetState(new QFinalState(machine));
+ quitState->addTransition(yesTransition);
+
+ QKeyEventTransition *noTransition =
+ new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_N);
+ noTransition->setTargetState(inputState);
+ quitState->addTransition(noTransition);
+//![3]
+
+//![4]
+ QKeyEventTransition *quitTransition =
+ new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Q);
+ quitTransition->setTargetState(quitState);
+ inputState->addTransition(quitTransition);
+//![4]
+
+//![5]
+ machine->setInitialState(inputState);
+
+ connect(machine, SIGNAL(finished()), qApp, SLOT(quit()));
+
+ machine->start();
+}
+//![5]
+
+void Window::movePlayer(Direction direction)
+{
+ switch (direction) {
+ case Left:
+ if (map[pX - 1][pY] != '#')
+ --pX;
+ break;
+ case Right:
+ if (map[pX + 1][pY] != '#')
+ ++pX;
+ break;
+ case Up:
+ if (map[pX][pY - 1] != '#')
+ --pY;
+ break;
+ case Down:
+ if (map[pX][pY + 1] != '#')
+ ++pY;
+ break;
+ }
+ repaint();
+}
+
+void Window::setupMap()
+{
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ for (int x = 0; x < WIDTH; ++x)
+ for (int y = 0; y < HEIGHT; ++y) {
+ if (x == 0 || x == WIDTH - 1 || y == 0 || y == HEIGHT - 1 || qrand() % 40 == 0)
+ map[x][y] = '#';
+ else
+ map[x][y] = '.';
+ }
+}
+
diff --git a/examples/statemachine/rogue/window.h b/examples/statemachine/rogue/window.h
new file mode 100644
index 0000000..bcd86bd
--- /dev/null
+++ b/examples/statemachine/rogue/window.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+class QState;
+class QStateMachine;
+class QTransition;
+
+#define WIDTH 35
+#define HEIGHT 20
+
+//![0]
+class Window : public QWidget
+{
+ Q_OBJECT
+ Q_PROPERTY(QString status READ status WRITE setStatus)
+
+public:
+ enum Direction { Up, Down, Left, Right };
+
+ Window();
+
+ void movePlayer(Direction direction);
+ void setStatus(const QString &status);
+ QString status() const;
+
+ QSize sizeHint() const;
+
+protected:
+ void paintEvent(QPaintEvent *event);
+//![0]
+
+//![1]
+private:
+ void buildMachine();
+ void setupMap();
+
+ QChar map[WIDTH][HEIGHT];
+ int pX, pY;
+
+ QStateMachine *machine;
+ QString myStatus;
+};
+//![1]
+
+#endif
+
diff --git a/examples/statemachine/statemachine.pro b/examples/statemachine/statemachine.pro
index ea3e7a8..298c0ae 100644
--- a/examples/statemachine/statemachine.pro
+++ b/examples/statemachine/statemachine.pro
@@ -3,6 +3,7 @@ SUBDIRS = \
eventtransitions \
factorial \
pingpong \
+ rogue \
trafficlight \
twowaybutton
diff --git a/examples/webkit/framecapture/framecapture.cpp b/examples/webkit/framecapture/framecapture.cpp
new file mode 100644
index 0000000..ef31f6d
--- /dev/null
+++ b/examples/webkit/framecapture/framecapture.cpp
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "framecapture.h"
+
+#include <iostream>
+#include <QtWebKit>
+
+FrameCapture::FrameCapture(): QObject(), m_percent(0)
+{
+ connect(&m_page, SIGNAL(loadProgress(int)), this, SLOT(printProgress(int)));
+ connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool)));
+}
+
+void FrameCapture::load(const QUrl &url, const QString &outputFileName)
+{
+ std::cout << "Loading " << qPrintable(url.toString()) << std::endl;
+ m_percent = 0;
+ int index = outputFileName.lastIndexOf('.');
+ m_fileName = (index == -1) ? outputFileName + ".png" : outputFileName;
+ m_page.mainFrame()->load(url);
+ m_page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
+ m_page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
+}
+
+void FrameCapture::printProgress(int percent)
+{
+ if (m_percent >= percent)
+ return;
+
+ while (m_percent++ < percent)
+ std::cout << "#" << std::flush;
+}
+
+void FrameCapture::saveResult(bool ok)
+{
+ std::cout << std::endl;
+
+ // crude error-checking
+ if (!ok) {
+ std::cerr << "Failed loading " << qPrintable(m_page.mainFrame()->url().toString()) << std::endl;
+ emit finished();
+ return;
+ }
+
+ // save each internal frame in different image files
+ int frameCounter = 0;
+ foreach(QWebFrame *frame, m_page.mainFrame()->childFrames()) {
+ QString fileName(m_fileName);
+ int index = m_fileName.lastIndexOf('.');
+ fileName = fileName.insert(index, "_frame" + QString::number(++frameCounter));
+
+ frame->setClipRenderToViewport(false);
+
+ QImage image(frame->contentsSize(), QImage::Format_ARGB32_Premultiplied);
+ image.fill(Qt::transparent);
+
+ saveFrame(frame, image, fileName);
+ }
+
+ // save the main frame
+ m_page.setViewportSize(m_page.mainFrame()->contentsSize());
+ QImage image(m_page.mainFrame()->contentsSize(), QImage::Format_ARGB32_Premultiplied);
+ image.fill(Qt::transparent);
+ saveFrame(m_page.mainFrame(), image, m_fileName);
+
+ emit finished();
+}
+
+void FrameCapture::saveFrame(QWebFrame *frame, QImage image, QString fileName)
+{
+ QPainter painter(&image);
+ painter.setRenderHint(QPainter::Antialiasing, true);
+ painter.setRenderHint(QPainter::TextAntialiasing, true);
+ painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
+
+ frame->render(&painter);
+
+ painter.end();
+
+ image.save(fileName);
+}
+
diff --git a/examples/webkit/framecapture/framecapture.h b/examples/webkit/framecapture/framecapture.h
new file mode 100644
index 0000000..ffc93ac
--- /dev/null
+++ b/examples/webkit/framecapture/framecapture.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FRAMECAPTURE_H
+#define FRAMECAPTURE_H
+
+#include <QtWebKit>
+
+class FrameCapture : public QObject
+{
+ Q_OBJECT
+
+public:
+ FrameCapture();
+ void load(const QUrl &url, const QString &outputFileName);
+
+signals:
+ void finished();
+
+private slots:
+ void printProgress(int percent);
+ void saveResult(bool ok);
+
+private:
+ QWebPage m_page;
+ QString m_fileName;
+ int m_percent;
+
+ void saveFrame(QWebFrame *frame, QImage image, QString fileName);
+};
+
+#endif
diff --git a/examples/webkit/framecapture/framecapture.pro b/examples/webkit/framecapture/framecapture.pro
new file mode 100644
index 0000000..6f2f093
--- /dev/null
+++ b/examples/webkit/framecapture/framecapture.pro
@@ -0,0 +1,11 @@
+QT += webkit
+
+HEADERS = framecapture.h
+SOURCES = main.cpp \
+ framecapture.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/webkit/framecapture
+sources.files = $$SOURCES $$HEADERS
+sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/framecapture
+INSTALLS += target sources
diff --git a/examples/webkit/framecapture/main.cpp b/examples/webkit/framecapture/main.cpp
new file mode 100644
index 0000000..fcdb62a
--- /dev/null
+++ b/examples/webkit/framecapture/main.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "framecapture.h"
+
+#include <iostream>
+#include <QtGui>
+
+int main(int argc, char * argv[])
+{
+ if (argc != 3) {
+ std::cout << "Capture a web page and save its internal frames in different images" << std::endl << std::endl;
+ std::cout << " framecapture <url> <outputfile>" << std::endl;
+ std::cout << std::endl;
+ std::cout << "Notes:" << std::endl;
+ std::cout << " 'url' is the URL of the web page to be captured" << std::endl;
+ std::cout << " 'outputfile' is the prefix of the image files to be generated" << std::endl;
+ std::cout << std::endl;
+ std::cout << "Example: " << std::endl;
+ std::cout << " framecapture www.trolltech.com trolltech.png" << std::endl;
+ std::cout << std::endl;
+ std::cout << "Result:" << std::endl;
+ std::cout << " trolltech.png (full page)" << std::endl;
+ std::cout << " trolltech_frame1.png (...) trolltech_frameN.png ('N' number of internal frames)" << std::endl;
+ return 0;
+ }
+
+ QUrl url = QWebView::guessUrlFromString(QString::fromLatin1(argv[1]));
+ QString fileName = QString::fromLatin1(argv[2]);
+
+ QApplication a(argc, argv);
+ FrameCapture capture;
+ QObject::connect(&capture, SIGNAL(finished()), QApplication::instance(), SLOT(quit()));
+ capture.load(url, fileName);
+
+ return a.exec();
+}
+