summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasper van Donderen <casper.vandonderen@nokia.com>2012-06-01 12:41:13 +0200
committerMarius Storm-Olsen <marius.storm-olsen@nokia.com>2012-06-07 14:45:52 +0200
commit08fa70bb5fb97b07f0e85a83352fefdf10e03800 (patch)
tree382c5cc10c622ddf08dbf47c5801c23d94cf5040
parent073c4e7ae33c64105f87f0362e915b480a23091a (diff)
Add more examples for DevNet and add license text.HEADmaster
-rw-r--r--FoldingCodeExample/FoldingCodeExample.pro5
-rw-r--r--FoldingCodeExample/editor.cpp146
-rw-r--r--FoldingCodeExample/editor.h46
-rw-r--r--FoldingCodeExample/main.cpp13
-rw-r--r--GeoServicesExample/README.txt68
-rw-r--r--GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.cpp90
-rw-r--r--GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.h78
-rw-r--r--GeoServicesExample/mapimageplugin/imggeomapreply.cpp71
-rw-r--r--GeoServicesExample/mapimageplugin/imggeomapreply.h71
-rw-r--r--GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.cpp88
-rw-r--r--GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.h74
-rw-r--r--GeoServicesExample/mapimageplugin/imggeotiledmapdata.cpp77
-rw-r--r--GeoServicesExample/mapimageplugin/imggeotiledmapdata.h65
-rw-r--r--GeoServicesExample/mapimageplugin/imgrunnable.cpp76
-rw-r--r--GeoServicesExample/mapimageplugin/imgrunnable.h68
-rw-r--r--GeoServicesExample/mapimageplugin/mapimageplugin.pro27
-rw-r--r--GeoServicesExample/mapimageplugin/mapimageplugin.qrc5
-rw-r--r--GeoServicesExample/services/main.cpp52
-rw-r--r--GeoServicesExample/services/mapwindow.cpp119
-rw-r--r--GeoServicesExample/services/mapwindow.h73
-rw-r--r--GeoServicesExample/services/services.pro6
-rwxr-xr-xGeoServicesExample/services/services.py126
-rw-r--r--LICENSE574
-rw-r--r--qtbotsim/main.cpp44
-rw-r--r--qtbotsim/qtbotsim.pro22
-rw-r--r--qtbotsim/robot.cpp212
-rw-r--r--qtbotsim/robot.h99
-rw-r--r--qtbotsim/robotwidget.cpp88
-rw-r--r--qtbotsim/robotwidget.h64
-rw-r--r--qtbotsim/widget.cpp101
-rw-r--r--qtbotsim/widget.h65
-rw-r--r--qtbotsim/widget.ui65
32 files changed, 2778 insertions, 0 deletions
diff --git a/FoldingCodeExample/FoldingCodeExample.pro b/FoldingCodeExample/FoldingCodeExample.pro
new file mode 100644
index 0000000..bad1cf7
--- /dev/null
+++ b/FoldingCodeExample/FoldingCodeExample.pro
@@ -0,0 +1,5 @@
+
+HEADERS += editor.h
+
+SOURCES += editor.cpp \
+ main.cpp
diff --git a/FoldingCodeExample/editor.cpp b/FoldingCodeExample/editor.cpp
new file mode 100644
index 0000000..4376486
--- /dev/null
+++ b/FoldingCodeExample/editor.cpp
@@ -0,0 +1,146 @@
+
+#include <QtGui>
+#include "editor.h"
+
+Editor::Editor() : QPlainTextEdit(),
+ folded(false)
+{
+ document()->setDocumentLayout(new EditorLayout(document()));
+
+ setPlainText(
+ "int main(int argc, char **args)\n"
+ "{\n"
+ "\tqDebug() << \"Folding Code Example\";\n"
+ "\treturn 0;\n"
+ "}\n"
+ "\n"
+ "#include main.moc"
+ );
+ connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition()));
+}
+
+void Editor::paintEvent(QPaintEvent *event)
+{
+ if (folded) {
+ QTextBlock foldedBlock = document()->findBlockByNumber(1);
+ if (!foldedBlock.isValid() || !foldedBlock.isVisible())
+ return;
+
+ qreal top = blockBoundingGeometry(foldedBlock).translated(contentOffset()).top();
+
+ QTextLayout *layout = foldedBlock.layout();
+ QTextLine line = layout->lineAt(layout->lineCount()-1);
+ QRectF lineRect = line.naturalTextRect().translated(0, top);
+
+ lineRect.adjust(0, 0, -1, -1);
+
+ QRectF collapseRect(lineRect.right() + 12,
+ lineRect.top(),
+ fontMetrics().width(QLatin1String(" ...} ")),
+ lineRect.height());
+
+ QPainter painter(viewport());
+ painter.setRenderHint(QPainter::Antialiasing, true);
+ painter.translate(.5, .5);
+ painter.drawRoundedRect(collapseRect.adjusted(0, 0, 0, -1), 3, 3);
+ painter.translate(-.5, -.5);
+ painter.drawText(collapseRect, Qt::AlignCenter, "...}");
+ }
+
+ QPlainTextEdit::paintEvent(event);
+}
+
+QTextBlock Editor::foldedBlockAt(const QPoint &pos)
+{
+ QTextBlock block = firstVisibleBlock();
+ qreal top = blockBoundingGeometry(block).translated(contentOffset()).top();
+ qreal bottom = top + blockBoundingRect(block).height();
+
+ int viewportHeight = viewport()->height();
+
+ while (block.isValid() && top <= viewportHeight) {
+ QTextBlock nextBlock = block.next();
+
+ if (block.isVisible() && bottom >= 0) {
+ if (nextBlock.isValid() && !nextBlock.isVisible()) {
+ QTextLayout *layout = block.layout();
+ QTextLine line = layout->lineAt(layout->lineCount()-1);
+ QRectF lineRect = line.naturalTextRect().translated(0, top);
+ lineRect.adjust(0, 0, -1, -1);
+
+ QRectF collapseRect(lineRect.right() + 12,
+ lineRect.top(),
+ fontMetrics().width(QLatin1String(" ...} ")),
+ lineRect.height());
+
+ if (collapseRect.contains(pos)) {
+ QTextBlock result = block;
+ return result;
+ } else {
+ block = nextBlock;
+ while (nextBlock.isValid() && !nextBlock.isVisible()) {
+ block = nextBlock;
+ nextBlock = block.next();
+ }
+ }
+ }
+ }
+
+ block = nextBlock;
+ top = bottom;
+ bottom = top + blockBoundingRect(block).height();
+ }
+ return QTextBlock();
+}
+
+void Editor::updateCursorPosition()
+{
+ QTextCursor cursor = textCursor();
+ QTextBlock block = cursor.block();
+
+ if (!block.isVisible()) {
+ while (!block.isVisible() && block.previous().isValid()) {
+ block.setVisible(true);
+ block.setLineCount(qMax(1, block.layout()->lineCount()));
+ block = block.previous();
+ }
+ EditorLayout *layout = static_cast<EditorLayout *>(document()->documentLayout());
+ layout->requestUpdate();
+ layout->emitDocumentSizeChanged();
+
+ folded = false;
+ QPlainTextEdit::ensureCursorVisible();
+ }
+}
+
+void Editor::mousePressEvent(QMouseEvent *event)
+{
+ if (folded) {
+ QTextBlock foldedBlock = foldedBlockAt(event->pos());
+ if (!foldedBlock.isValid()) {
+ QPlainTextEdit::mousePressEvent(event);
+ return;
+ }
+ } else {
+ QPlainTextEdit::mousePressEvent(event);
+ }
+
+ EditorLayout *layout = static_cast<EditorLayout *>(document()->documentLayout());
+
+ folded = !folded;
+ for (int i = 0; i < 3; ++i) {
+ QTextBlock block = document()->findBlockByNumber(i + 2);
+ block.setVisible(!folded);
+ block.setLineCount(folded ? 0 : qMax(1, block.layout()->lineCount()));
+ }
+
+ QTextCursor cursor = textCursor();
+ if (!cursor.block().isVisible()) {
+ cursor.setVisualNavigation(true);
+ cursor.movePosition(QTextCursor::Up);
+ setTextCursor(cursor);
+ }
+
+ layout->requestUpdate();
+ layout->emitDocumentSizeChanged();
+}
diff --git a/FoldingCodeExample/editor.h b/FoldingCodeExample/editor.h
new file mode 100644
index 0000000..97e176d
--- /dev/null
+++ b/FoldingCodeExample/editor.h
@@ -0,0 +1,46 @@
+#ifndef EDITOR_H
+#define EDITOR_H
+
+#include <QPlainTextEdit>
+#include <QPlainTextDocumentLayout>
+#include <QTextBlock>
+#include <QSize>
+#include <QDebug>
+
+class QPaintEvent;
+class QMouseEvent;
+
+class EditorLayout : public QPlainTextDocumentLayout
+{
+ Q_OBJECT
+
+public:
+ EditorLayout(QTextDocument *document) : QPlainTextDocumentLayout(document) {
+ }
+
+ void emitDocumentSizeChanged() {
+ emit documentSizeChanged(documentSize());
+ }
+};
+
+class Editor : public QPlainTextEdit
+{
+ Q_OBJECT
+
+public:
+ Editor();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+
+private slots:
+ void updateCursorPosition();
+
+private:
+ QTextBlock foldedBlockAt(const QPoint &point);
+
+ bool folded;
+};
+
+#endif
diff --git a/FoldingCodeExample/main.cpp b/FoldingCodeExample/main.cpp
new file mode 100644
index 0000000..6e1583d
--- /dev/null
+++ b/FoldingCodeExample/main.cpp
@@ -0,0 +1,13 @@
+
+#include <QtGui>
+#include "editor.h"
+
+int main(int argc, char **args)
+{
+ QApplication app(argc, args);
+
+ Editor editor;
+ editor.show();
+
+ return app.exec();
+}
diff --git a/GeoServicesExample/README.txt b/GeoServicesExample/README.txt
new file mode 100644
index 0000000..142d376
--- /dev/null
+++ b/GeoServicesExample/README.txt
@@ -0,0 +1,68 @@
+Different Views of the World Examples
+=====================================
+
+The C++ versions of these examples can be built using the qmake project
+files supplied. The plugins built by the osmplugin and mapimageplugin
+project files should be installed in the plugins/geoservices directory
+in your Qt installation. The project files provide installation rules
+for this that can be invoked with "make install" or similar.
+
+The mapimageplugin example requires a map.jpg file to be installed in
+the mapimageplugin/files directory before it can be built.
+
+The Python version of the services example has been tested with PyQt 4.8
+and PyQtMobility 1.0.
+
+About Qt Quarterly
+==================
+
+Qt Quarterly is a newsletter available to Qt developers. Every quarter we
+aim to publish an issue that we hope will bring added insight and pleasure
+to your Qt programming, with high-quality technical articles written by Qt
+experts.
+
+See http://doc.qt.nokia.com/qq for more information.
+
+License Information
+===================
+
+The examples contained in this package is provided under the following
+license:
+
+ Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ All rights reserved.
+ Contact: Nokia Corporation (qt-info@nokia.com)
+
+ This file is part of the documentation of Qt. It was originally
+ published as part of Qt Quarterly.
+
+ $QT_BEGIN_LICENSE:LGPL$
+ Commercial Usage
+ Licensees holding valid Qt Commercial licenses may use this file in
+ accordance with the Qt Commercial License Agreement provided with the
+ Software or, alternatively, in accordance with the terms contained in
+ a written agreement between you and Nokia.
+
+ 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.1, 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 have questions regarding the use of this file, please contact
+ Nokia at qt-info@nokia.com.
+ $QT_END_LICENSE$
diff --git a/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.cpp b/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.cpp
new file mode 100644
index 0000000..be58236
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "imggeomappingmanagerengine.h"
+#include "imggeotiledmapdata.h"
+
+MapImageGeoMappingManagerEngine::MapImageGeoMappingManagerEngine(
+ const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error, QString *errorString)
+: QGeoTiledMappingManagerEngine(parameters)
+{
+ Q_UNUSED(error)
+ Q_UNUSED(errorString)
+ Q_UNUSED(parameters)
+
+ setTileSize(QSize(256, 256));
+ setMinimumZoomLevel(0.0);
+ setMaximumZoomLevel(4.0);
+
+ QList<QGraphicsGeoMap::MapType> types;
+ types << QGraphicsGeoMap::SatelliteMapDay;
+ setSupportedMapTypes(types);
+
+ QList<QGraphicsGeoMap::ConnectivityMode> modes;
+ modes << QGraphicsGeoMap::OfflineMode;
+ setSupportedConnectivityModes(modes);
+
+ sourceImage.load(":files/map.jpg");
+}
+
+MapImageGeoMappingManagerEngine::~MapImageGeoMappingManagerEngine()
+{
+}
+
+QGeoMapData *MapImageGeoMappingManagerEngine::createMapData()
+{
+ QGeoMapData *data = new MapImageGeoTiledMapData(this);
+ if (!data)
+ return 0;
+
+ data->setConnectivityMode(QGraphicsGeoMap::OnlineMode);
+ return data;
+}
+
+QGeoTiledMapReply *MapImageGeoMappingManagerEngine::getTileImage(const QGeoTiledMapRequest &request)
+{
+ // Obtain the relevant part of the source image.
+ MapImageGeoMapReply *mapReply = new MapImageGeoMapReply(request, sourceImage);
+
+ return mapReply;
+}
diff --git a/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.h b/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.h
new file mode 100644
index 0000000..684633f
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMGGEOMAPPINGMANAGERENGINE_H
+#define IMGGEOMAPPINGMANAGERENGINE_H
+
+#include <QGeoServiceProvider>
+#include <QGeoTiledMappingManagerEngine>
+#include <QGeoTiledMapRequest>
+#include <QImage>
+
+#include "imggeoserviceproviderfactory.h"
+#include "imggeomapreply.h"
+
+class QNetworkAccessManager;
+class MapImageGeoMapReply;
+
+QTM_USE_NAMESPACE
+
+class MapImageGeoMappingManagerEngine : public QGeoTiledMappingManagerEngine
+{
+ Q_OBJECT
+
+public:
+ MapImageGeoMappingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString);
+ ~MapImageGeoMappingManagerEngine();
+
+ QGeoMapData *createMapData();
+ QGeoTiledMapReply *getTileImage(const QGeoTiledMapRequest &request);
+
+private:
+ Q_DISABLE_COPY(MapImageGeoMappingManagerEngine)
+
+ QImage sourceImage;
+};
+
+#endif
diff --git a/GeoServicesExample/mapimageplugin/imggeomapreply.cpp b/GeoServicesExample/mapimageplugin/imggeomapreply.cpp
new file mode 100644
index 0000000..40940cc
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/imggeomapreply.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QBuffer>
+#include <QThreadPool>
+#include "imggeomapreply.h"
+#include "imgrunnable.h"
+
+MapImageGeoMapReply::MapImageGeoMapReply(const QGeoTiledMapRequest &request,
+ const QImage &sourceImage, QObject *parent)
+ : QGeoTiledMapReply(request, parent),
+ m_sourceImage(sourceImage)
+{
+ MapImageRunnable *task = new MapImageRunnable(sourceImage,
+ request.zoomLevel(), request.row(), request.column());
+
+ connect(task, SIGNAL(finished(QByteArray)), this, SLOT(supplyData(QByteArray)));
+ QThreadPool::globalInstance()->start(task);
+}
+
+MapImageGeoMapReply::~MapImageGeoMapReply()
+{
+}
+
+void MapImageGeoMapReply::supplyData(QByteArray data)
+{
+ setMapImageData(data);
+ setMapImageFormat("PNG");
+ setFinished(true);
+
+ emit finished();
+}
diff --git a/GeoServicesExample/mapimageplugin/imggeomapreply.h b/GeoServicesExample/mapimageplugin/imggeomapreply.h
new file mode 100644
index 0000000..9a23641
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/imggeomapreply.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMGGEOMAPREPLY_H
+#define IMGGEOMAPREPLY_H
+
+#include <QGeoTiledMapRequest>
+#include <QGeoTiledMapReply>
+#include <QImage>
+
+QTM_USE_NAMESPACE
+
+class MapImageGeoMapReply : public QGeoTiledMapReply
+{
+ Q_OBJECT
+
+public:
+ MapImageGeoMapReply(const QGeoTiledMapRequest &request,
+ const QImage &sourceImage, QObject *parent = 0);
+ ~MapImageGeoMapReply();
+
+signals:
+ void finished();
+
+private slots:
+ void supplyData(QByteArray);
+
+private:
+ QImage m_sourceImage;
+};
+
+#endif
diff --git a/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.cpp b/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.cpp
new file mode 100644
index 0000000..4f72577
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "imggeoserviceproviderfactory.h"
+#include "imggeomappingmanagerengine.h"
+
+MapImageGeoServiceProviderFactory::MapImageGeoServiceProviderFactory() {}
+
+MapImageGeoServiceProviderFactory::~MapImageGeoServiceProviderFactory() {}
+
+QString MapImageGeoServiceProviderFactory::providerName() const
+{
+ return QLatin1String("mapimage");
+}
+
+int MapImageGeoServiceProviderFactory::providerVersion() const
+{
+ return 1;
+}
+
+QGeoSearchManagerEngine *MapImageGeoServiceProviderFactory::createSearchManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const
+{
+ Q_UNUSED(error)
+ Q_UNUSED(errorString)
+
+ return 0;
+}
+
+QGeoMappingManagerEngine *MapImageGeoServiceProviderFactory::createMappingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const
+{
+ return new MapImageGeoMappingManagerEngine(parameters, error, errorString);
+}
+
+QGeoRoutingManagerEngine *MapImageGeoServiceProviderFactory::createRoutingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const
+{
+ Q_UNUSED(parameters)
+ Q_UNUSED(error)
+ Q_UNUSED(errorString)
+
+ return 0;
+}
+
+Q_EXPORT_PLUGIN2(mapimagegeoservices, MapImageGeoServiceProviderFactory)
diff --git a/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.h b/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.h
new file mode 100644
index 0000000..71c76ed
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMGGEOSERVICEPROVIDERFACTORY_H
+#define IMGGEOSERVICEPROVIDERFACTORY_H
+
+#include <QGeoServiceProviderFactory>
+#include <QObject>
+
+QTM_USE_NAMESPACE
+
+class MapImageGeoServiceProviderFactory : public QObject, public QGeoServiceProviderFactory
+{
+ Q_OBJECT
+ Q_INTERFACES(QtMobility::QGeoServiceProviderFactory)
+
+public:
+ MapImageGeoServiceProviderFactory();
+ ~MapImageGeoServiceProviderFactory();
+
+ QString providerName() const;
+ int providerVersion() const;
+
+ QGeoMappingManagerEngine *createMappingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const;
+ QGeoRoutingManagerEngine *createRoutingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const;
+ QGeoSearchManagerEngine *createSearchManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const;
+};
+
+#endif
diff --git a/GeoServicesExample/mapimageplugin/imggeotiledmapdata.cpp b/GeoServicesExample/mapimageplugin/imggeotiledmapdata.cpp
new file mode 100644
index 0000000..a2d00f5
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/imggeotiledmapdata.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGeoMappingManagerEngine>
+#include <QGeoBoundingBox>
+#include <QGeoCoordinate>
+#include "imggeotiledmapdata.h"
+
+MapImageGeoTiledMapData::MapImageGeoTiledMapData(QGeoMappingManagerEngine *engine) :
+ QGeoTiledMapData(engine)
+{
+}
+
+MapImageGeoTiledMapData::~MapImageGeoTiledMapData()
+{
+}
+
+void MapImageGeoTiledMapData::paintProviderNotices(QPainter *painter, const QStyleOptionGraphicsItem *option)
+{
+ QRect viewport = painter->combinedTransform().inverted().mapRect(painter->viewport());
+
+ QLatin1String creditText = QLatin1String("www.mapaplanet.org");
+
+ QRect maxBoundingRect(QPoint(viewport.left()+10, viewport.top()), QPoint(viewport.right()-5, viewport.bottom()-5));
+ QRect textBoundingRect = painter->boundingRect(maxBoundingRect, Qt::AlignLeft | Qt::AlignBottom | Qt::TextWordWrap, creditText);
+ QRect lastCreditRect = textBoundingRect.adjusted(-2, -1, 2, 1);
+
+ QPixmap lastCredit = QPixmap(lastCreditRect.size());
+ lastCredit.fill(QColor(255, 255, 255, 160));
+
+ QPainter painter2(&lastCredit);
+
+ painter2.setPen(QColor(Qt::black));
+ painter2.drawText(QRect(QPoint(2, 1), textBoundingRect.size()),
+ Qt::TextWordWrap, creditText);
+
+ painter->drawPixmap(lastCreditRect, lastCredit);
+}
diff --git a/GeoServicesExample/mapimageplugin/imggeotiledmapdata.h b/GeoServicesExample/mapimageplugin/imggeotiledmapdata.h
new file mode 100644
index 0000000..3e151cb
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/imggeotiledmapdata.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMGGEOMAPDATA_H
+#define IMGGEOMAPDATA_H
+
+#include <QGeoTiledMapData>
+#include <QPixmap>
+
+QTM_USE_NAMESPACE
+
+class MapImageGeoMappingManagerEngine;
+
+class MapImageGeoTiledMapData: public QGeoTiledMapData
+{
+Q_OBJECT
+public:
+ MapImageGeoTiledMapData(QGeoMappingManagerEngine *engine);
+ virtual ~MapImageGeoTiledMapData();
+ void paintProviderNotices(QPainter *painter, const QStyleOptionGraphicsItem *option);
+
+private:
+ Q_DISABLE_COPY(MapImageGeoTiledMapData)
+};
+
+#endif
diff --git a/GeoServicesExample/mapimageplugin/imgrunnable.cpp b/GeoServicesExample/mapimageplugin/imgrunnable.cpp
new file mode 100644
index 0000000..04bffcd
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/imgrunnable.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QBuffer>
+#include "imgrunnable.h"
+
+MapImageRunnable::MapImageRunnable(const QImage &sourceImage, int zoom, int row,
+ int column)
+ : m_sourceImage(sourceImage), m_zoom(zoom), m_row(row), m_column(column)
+{
+}
+
+void MapImageRunnable::run()
+{
+ // The number of tiles along each axis is 2^zoom.
+ // zoom is a value from 0 to 4, so the number of tiles are 1 to 16.
+ int number = 1 << m_zoom;
+
+ // Divide the source image into 2^zoom by 2^zoom tiles.
+ int tileWidth = m_sourceImage.size().width() / number;
+ int tileHeight = m_sourceImage.size().height() / number;
+
+ // Calculate the coordinates for the top-left corner of the tile.
+ int tx = m_column * tileWidth;
+ int ty = m_row * tileHeight;
+
+ QImage tileImage = m_sourceImage.copy(tx, ty, tileWidth, tileHeight);
+ QImage scaledImage = tileImage.scaled(256, 256);
+
+ QByteArray data;
+ QBuffer buffer(&data);
+ buffer.open(QBuffer::WriteOnly);
+ scaledImage.save(&buffer, "PNG");
+ buffer.close();
+
+ emit finished(data);
+}
diff --git a/GeoServicesExample/mapimageplugin/imgrunnable.h b/GeoServicesExample/mapimageplugin/imgrunnable.h
new file mode 100644
index 0000000..e5c6fc5
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/imgrunnable.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMGRUNNABLE_H
+#define IMGRUNNABLE_H
+
+#include <QImage>
+#include <QObject>
+#include <QRunnable>
+
+class MapImageRunnable : public QObject, public QRunnable
+{
+ Q_OBJECT
+
+public:
+ MapImageRunnable(const QImage &sourceImage, int zoom, int row, int column);
+ void run();
+
+signals:
+ void finished(QByteArray);
+
+private:
+ QImage m_sourceImage;
+ int m_zoom;
+ int m_row;
+ int m_column;
+};
+
+#endif
diff --git a/GeoServicesExample/mapimageplugin/mapimageplugin.pro b/GeoServicesExample/mapimageplugin/mapimageplugin.pro
new file mode 100644
index 0000000..13ef0ea
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/mapimageplugin.pro
@@ -0,0 +1,27 @@
+TEMPLATE = lib
+CONFIG += plugin
+PLUGIN_TYPE = geoservices
+TARGET = mapimagegeoservices
+
+QT += network
+
+CONFIG += mobility
+MOBILITY = location
+
+HEADERS = imggeomappingmanagerengine.h \
+ imggeomapreply.h \
+ imggeoserviceproviderfactory.h \
+ imggeotiledmapdata.h \
+ imgrunnable.h
+
+SOURCES = imggeomappingmanagerengine.cpp \
+ imggeomapreply.cpp \
+ imggeoserviceproviderfactory.cpp \
+ imggeotiledmapdata.cpp \
+ imgrunnable.cpp
+
+RESOURCES = mapimageplugin.qrc
+
+target.path = $$[QT_INSTALL_PLUGINS]/$$PLUGIN_TYPE
+
+INSTALLS += target
diff --git a/GeoServicesExample/mapimageplugin/mapimageplugin.qrc b/GeoServicesExample/mapimageplugin/mapimageplugin.qrc
new file mode 100644
index 0000000..733bd55
--- /dev/null
+++ b/GeoServicesExample/mapimageplugin/mapimageplugin.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>files/map.jpg</file>
+</qresource>
+</RCC>
diff --git a/GeoServicesExample/services/main.cpp b/GeoServicesExample/services/main.cpp
new file mode 100644
index 0000000..2553a4f
--- /dev/null
+++ b/GeoServicesExample/services/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mapwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MapWindow window;
+ window.show();
+ return app.exec();
+}
diff --git a/GeoServicesExample/services/mapwindow.cpp b/GeoServicesExample/services/mapwindow.cpp
new file mode 100644
index 0000000..c32a5e8
--- /dev/null
+++ b/GeoServicesExample/services/mapwindow.cpp
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QGeoCoordinate>
+#include <QGeoMappingManagerEngine>
+#include <QGraphicsGeoMap>
+#include "mapwindow.h"
+
+using namespace QtMobility;
+
+MapWindow::MapWindow()
+{
+ scene = new QGraphicsScene(this);
+
+ findServices();
+
+ QGraphicsView *view = new QGraphicsView(this);
+ view->setScene(scene);
+ setCentralWidget(view);
+}
+
+void MapWindow::findServices()
+{
+ QMenu *serviceMenu = menuBar()->addMenu(tr("&Services"));
+
+ actionGroup = new QActionGroup(this);
+ actionGroup->setExclusive(true);
+ connect(actionGroup, SIGNAL(triggered(QAction *)),
+ this, SLOT(selectService(QAction *)));
+
+ foreach (const QString &name, QGeoServiceProvider::availableServiceProviders()) {
+
+ QGeoServiceProvider *service = new QGeoServiceProvider(name);
+ services[name] = service;
+ QAction *action = serviceMenu->addAction(name);
+ action->setCheckable(true);
+ actionGroup->addAction(action);
+ }
+
+ if (services.isEmpty()) {
+
+ QGraphicsTextItem *item = scene->addText(
+ tr("Failed to find any map services. Please ensure that "
+ "the location services plugins for Qt Mobility have "
+ "been built and, if necessary, set the QT_PLUGIN_PATH "
+ "environment variable to the location of the Qt Mobility "
+ "plugins directory."));
+ item->setTextWidth(300);
+ QAction *action = serviceMenu->addAction(tr("No services"));
+ action->setEnabled(false);
+ } else
+ actionGroup->actions()[0]->trigger();
+}
+
+void MapWindow::selectService(QAction *action)
+{
+ action->setChecked(true);
+ QString name = action->text();
+
+ scene->clear();
+
+ QGeoServiceProvider *service = services[name];
+ if (service->error() != QGeoServiceProvider::NoError) {
+
+ QGraphicsTextItem *item = scene->addText(
+ tr("The \"%1\" service failed with the following error:\n'"
+ "%2").arg(name).arg(service->errorString()));
+ item->setTextWidth(300);
+ } else {
+ QGeoMappingManager *manager = service->mappingManager();
+ QGraphicsGeoMap *geoMap = new QGraphicsGeoMap(manager);
+ scene->addItem(geoMap);
+
+ geoMap->resize(300, 300);
+ geoMap->setCenter(QGeoCoordinate(37.76, -25.675));
+ geoMap->setMapType(QGraphicsGeoMap::TerrainMap);
+ geoMap->setZoomLevel(12);
+ }
+}
diff --git a/GeoServicesExample/services/mapwindow.h b/GeoServicesExample/services/mapwindow.h
new file mode 100644
index 0000000..9a6ca0c
--- /dev/null
+++ b/GeoServicesExample/services/mapwindow.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of Qt. It was originally
+** published as part of Qt Quarterly.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.1, 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 have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAPWINDOW_H
+#define MAPWINDOW_H
+
+#include <QGeoServiceProvider>
+#include <QHash>
+#include <QMainWindow>
+
+using namespace QtMobility;
+
+class QActionGroup;
+class QGraphicsScene;
+
+class MapWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MapWindow();
+
+private slots:
+ void selectService(QAction *action);
+
+private:
+ void findServices();
+
+ QActionGroup *actionGroup;
+ QGraphicsScene *scene;
+ QHash<QString, QGeoServiceProvider *> services;
+};
+
+#endif
diff --git a/GeoServicesExample/services/services.pro b/GeoServicesExample/services/services.pro
new file mode 100644
index 0000000..13288a5
--- /dev/null
+++ b/GeoServicesExample/services/services.pro
@@ -0,0 +1,6 @@
+HEADERS = mapwindow.h
+SOURCES = main.cpp \
+ mapwindow.cpp
+QT += network
+CONFIG += mobility
+MOBILITY = location
diff --git a/GeoServicesExample/services/services.py b/GeoServicesExample/services/services.py
new file mode 100755
index 0000000..4812f20
--- /dev/null
+++ b/GeoServicesExample/services/services.py
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+
+#############################################################################
+##
+## Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+## All rights reserved.
+## Contact: Nokia Corporation (qt-info@nokia.com)
+##
+## This file is part of the documentation of Qt. It was originally
+## published as part of Qt Quarterly.
+##
+## $QT_BEGIN_LICENSE:LGPL$
+## Commercial Usage
+## Licensees holding valid Qt Commercial licenses may use this file in
+## accordance with the Qt Commercial License Agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and Nokia.
+##
+## 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.1, 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 have questions regarding the use of this file, please contact
+## Nokia at qt-info@nokia.com.
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+import sys
+
+from PyQt4.QtGui import QActionGroup, QApplication, QGraphicsScene, QGraphicsView, QMainWindow
+from PyQt4.QtMobility.QtLocation import *
+
+class MapWindow(QMainWindow):
+
+ def __init__(self):
+
+ QMainWindow.__init__(self)
+
+ self.scene = QGraphicsScene()
+
+ self.findServices()
+
+ view = QGraphicsView()
+ view.setScene(self.scene)
+ self.setCentralWidget(view)
+
+ def findServices(self):
+
+ serviceMenu = self.menuBar().addMenu(self.tr("&Services"))
+
+ self.services = {}
+ self.actionGroup = QActionGroup(self)
+ self.actionGroup.setExclusive(True)
+ self.actionGroup.triggered.connect(self.selectService)
+
+ for name in QGeoServiceProvider.availableServiceProviders():
+
+ service = QGeoServiceProvider(name)
+ self.services[name] = service
+ action = serviceMenu.addAction(name)
+ action.setCheckable(True)
+ self.actionGroup.addAction(action)
+
+ if not self.services:
+
+ item = self.scene.addText(
+ self.tr("Failed to find any map services. Please ensure that "
+ "the location services plugins for Qt Mobility have "
+ "been built and, if necessary, set the QT_PLUGIN_PATH "
+ "environment variable to the location of the Qt Mobility "
+ "plugins directory."))
+ item.setTextWidth(300)
+ action = serviceMenu.addAction(self.tr("No services"))
+ action.setEnabled(False)
+ else:
+ self.actionGroup.actions()[0].trigger()
+
+ def selectService(self, action):
+
+ action.setChecked(True)
+ name = action.text()
+
+ self.scene.clear()
+
+ service = self.services[name]
+ if service.error() != service.NoError:
+
+ item = self.scene.addText(
+ self.tr('The "%1" service failed with the following error:\n'
+ "%2").arg(name).arg(service.errorString()))
+ item.setTextWidth(300)
+
+ else:
+ self.manager = service.mappingManager()
+ self.geoMap = QGraphicsGeoMap(self.manager)
+ self.scene.addItem(self.geoMap)
+
+ self.geoMap.resize(300, 300)
+ self.geoMap.setCenter(QGeoCoordinate(37.76, -25.675))
+ self.geoMap.setMapType(self.geoMap.TerrainMap)
+ self.geoMap.setZoomLevel(12)
+
+
+if __name__ == "__main__":
+
+ app = QApplication(sys.argv)
+ window = MapWindow()
+ window.show()
+ sys.exit(app.exec_())
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..454e1fc
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,574 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+*************************************************************************
+
+
+Copyright (c) 2012, qt-project.org
+All rights reserved.
+
+Redistribution and use in source and binary forms, with
+or without modification, are permitted provided that the
+following conditions are met:
+
+- Redistributions of source code must retain the
+ above copyright notice, this list of conditions and
+ the following disclaimer.
+- Redistributions in binary form must reproduce
+ above copyright notice, this list of conditions and
+ the following disclaimer in the documentation and/or
+ other materials provided with the distribution.
+- Neither the name of the <ORGANIZATION> nor the
+ names of its contributors may be used to endorse or
+ promote products derived from this software without
+ specific rior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+
+
+*************************************************************************
+License for the qtbotsim example:
+
+
+Copyright (c) 2011, Johan Thelin <johan@thelins.se>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+Neither the name of Johan Thelin nor the names of its contributors may be
+used to endorse or promote products derived from this software without
+specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+
+----
diff --git a/qtbotsim/main.cpp b/qtbotsim/main.cpp
new file mode 100644
index 0000000..475d438
--- /dev/null
+++ b/qtbotsim/main.cpp
@@ -0,0 +1,44 @@
+/*
+ * In the original BSD license, both occurrences of the phrase "COPYRIGHT
+ * HOLDERS AND CONTRIBUTORS" in the disclaimer read "REGENTS AND CONTRIBUTORS".
+ *
+ * Here is the license template:
+ *
+ * Copyright (c) 2011, Johan Thelin <johan@thelins.se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of Johan Thelin nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <QtGui/QApplication>
+#include "widget.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ Widget w;
+ w.show();
+
+ return a.exec();
+}
diff --git a/qtbotsim/qtbotsim.pro b/qtbotsim/qtbotsim.pro
new file mode 100644
index 0000000..3c7ecf1
--- /dev/null
+++ b/qtbotsim/qtbotsim.pro
@@ -0,0 +1,22 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2011-11-13T15:52:13
+#
+#-------------------------------------------------
+
+QT += core gui declarative
+
+TARGET = qtbotsim
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+ widget.cpp \
+ robotwidget.cpp \
+ robot.cpp
+
+HEADERS += widget.h \
+ robotwidget.h \
+ robot.h
+
+FORMS += widget.ui
diff --git a/qtbotsim/robot.cpp b/qtbotsim/robot.cpp
new file mode 100644
index 0000000..8265a3b
--- /dev/null
+++ b/qtbotsim/robot.cpp
@@ -0,0 +1,212 @@
+/*
+ * In the original BSD license, both occurrences of the phrase "COPYRIGHT
+ * HOLDERS AND CONTRIBUTORS" in the disclaimer read "REGENTS AND CONTRIBUTORS".
+ *
+ * Here is the license template:
+ *
+ * Copyright (c) 2011, Johan Thelin <johan@thelins.se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of Johan Thelin nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "robot.h"
+
+#include <QPainterPath>
+#include <math.h>
+
+Robot::Robot(QObject *parent)
+ : QObject(parent)
+{
+ // All is reset in the reset method called first
+}
+
+void Robot::step(QPixmap *pixmap)
+{
+ QPointF start = position();
+ setPosition(position()+movementChange());
+ QPointF end = position();
+ setDirection(direction()+directionChange());
+
+ if (m_penActive)
+ {
+ QPainter p(pixmap);
+ p.setRenderHint(QPainter::Antialiasing);
+ p.setPen(Qt::red);
+ p.drawLine(start, end);
+ }
+
+ updateSensors(*pixmap);
+}
+
+void Robot::drawOverlay(QPainter &painter)
+{
+ QPainterPath path;
+
+ path.addRect(QRectF(-QPointF(10, 20), QSizeF(20, 40)));
+ path.addEllipse(QPointF(0, 15), 2, 2);
+
+ painter.setPen(Qt::black);
+ painter.setBrush(Qt::lightGray);
+
+ painter.translate(position());
+ painter.rotate(direction());
+
+ painter.drawPath(path);
+}
+
+bool Robot::brightForward() const
+{
+ return m_brightForward;
+}
+
+bool Robot::penActive() const
+{
+ return m_penActive;
+}
+
+qreal Robot::leftEngineSpeed() const
+{
+ return m_leftEngineSpeed;
+}
+
+qreal Robot::rightEngineSpeed() const
+{
+ return m_rightEngineSpeed;
+}
+
+void Robot::reset(const QPixmap &pixmap)
+{
+ setPenActive(true);
+ setLeftEngineSpeed(0);
+ setRightEngineSpeed(0);
+ setDirection(270);
+ setPosition(QPointF(pixmap.width()/2, pixmap.height()/2));
+ updateSensors(pixmap);
+}
+
+void Robot::setPenActive(bool pa)
+{
+ if (pa != m_penActive)
+ {
+ m_penActive = pa;
+ emit penActiveChanged(m_penActive);
+ }
+}
+
+void Robot::setLeftEngineSpeed(qreal s)
+{
+ s = qBound(-1.0, s, 1.0);
+
+ if (s != m_leftEngineSpeed)
+ {
+ m_leftEngineSpeed = s;
+ emit leftEngineSpeedChanged(m_leftEngineSpeed);
+ }
+}
+
+void Robot::setRightEngineSpeed(qreal s)
+{
+ s = qBound(-1.0, s, 1.0);
+
+ if (s != m_rightEngineSpeed)
+ {
+ m_rightEngineSpeed = s;
+ emit rightEngineSpeedChanged(m_rightEngineSpeed);
+ }
+}
+
+QPointF Robot::position() const
+{
+ return m_position;
+}
+
+void Robot::setPosition(const QPointF &p)
+{
+ m_position = p;
+}
+
+qreal Robot::direction() const
+{
+ return m_direction;
+}
+
+void Robot::setDirection(qreal d)
+{
+ while (d>360.0)
+ d -= 360.0;
+
+ m_direction = d;
+}
+
+void Robot::setBrightForward(bool value)
+{
+ if (value != m_brightForward)
+ {
+ m_brightForward = value;
+ emit brightForwardChanged(m_brightForward);
+ }
+}
+
+void Robot::updateSensors(const QPixmap &paper)
+{
+ QTransform t;
+ t.rotate(direction());
+ QPointF sensorPos = position() + t.map(QPointF(0, 15));
+
+ setBrightForward(qGray(paper.toImage().pixel(sensorPos.toPoint())) > 20);
+}
+
+QPointF Robot::movementChange() const
+{
+ QTransform t;
+ t.rotate(direction()+directionChange());
+
+ return t.map(QPointF(0, (leftEngineSpeed() + rightEngineSpeed())/2));
+}
+
+qreal Robot::directionChange() const
+{
+ /*
+
+ <----+----> lwS
+ | .
+ | .
+ | .
+ | .
+ |a x----------------------
+ |-. .... ) a
+ | . ....
+ |. ....
+ |. ....
+ <----+----> rwR
+
+
+ */
+
+ qreal tangens = (leftEngineSpeed()-rightEngineSpeed())/20.0;
+ qreal angle = atan(tangens);
+
+ return angle*180.0/M_PI;
+}
diff --git a/qtbotsim/robot.h b/qtbotsim/robot.h
new file mode 100644
index 0000000..4da6337
--- /dev/null
+++ b/qtbotsim/robot.h
@@ -0,0 +1,99 @@
+/*
+ * In the original BSD license, both occurrences of the phrase "COPYRIGHT
+ * HOLDERS AND CONTRIBUTORS" in the disclaimer read "REGENTS AND CONTRIBUTORS".
+ *
+ * Here is the license template:
+ *
+ * Copyright (c) 2011, Johan Thelin <johan@thelins.se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of Johan Thelin nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ROBOT_H
+#define ROBOT_H
+
+#include <QObject>
+
+#include <QPixmap>
+#include <QPainter>
+
+class Robot : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(bool penActive READ penActive WRITE setPenActive NOTIFY penActiveChanged)
+ Q_PROPERTY(bool brightForward READ brightForward NOTIFY brightForwardChanged)
+ Q_PROPERTY(qreal leftEngineSpeed READ leftEngineSpeed WRITE setLeftEngineSpeed NOTIFY leftEngineSpeedChanged)
+ Q_PROPERTY(qreal rightEngineSpeed READ rightEngineSpeed WRITE setRightEngineSpeed NOTIFY rightEngineSpeedChanged)
+
+public:
+ explicit Robot(QObject *parent = 0);
+
+ void step(QPixmap *pixmap);
+ void drawOverlay(QPainter &painter);
+
+ bool brightForward() const;
+ bool penActive() const;
+ qreal leftEngineSpeed() const;
+ qreal rightEngineSpeed() const;
+
+signals:
+ void brightForwardChanged(bool);
+ void penActiveChanged(bool);
+
+ void leftEngineSpeedChanged(qreal);
+ void rightEngineSpeedChanged(qreal);
+
+public slots:
+ void reset(const QPixmap &pixmap);
+
+ void setPenActive(bool);
+
+ void setLeftEngineSpeed(qreal);
+ void setRightEngineSpeed(qreal);
+
+private:
+ void setPosition(const QPointF &p);
+ QPointF position() const;
+
+ void setDirection(qreal d);
+ qreal direction() const;
+
+ void setBrightForward(bool);
+
+ void updateSensors(const QPixmap &);
+ QPointF movementChange() const;
+ qreal directionChange() const;
+
+ bool m_brightForward;
+ bool m_penActive;
+ qreal m_leftEngineSpeed;
+ qreal m_rightEngineSpeed;
+
+ QPointF m_position;
+ qreal m_direction;
+};
+
+#endif // ROBOT_H
diff --git a/qtbotsim/robotwidget.cpp b/qtbotsim/robotwidget.cpp
new file mode 100644
index 0000000..e0ef072
--- /dev/null
+++ b/qtbotsim/robotwidget.cpp
@@ -0,0 +1,88 @@
+/*
+ * In the original BSD license, both occurrences of the phrase "COPYRIGHT
+ * HOLDERS AND CONTRIBUTORS" in the disclaimer read "REGENTS AND CONTRIBUTORS".
+ *
+ * Here is the license template:
+ *
+ * Copyright (c) 2011, Johan Thelin <johan@thelins.se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of Johan Thelin nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "robotwidget.h"
+
+#include <QPainter>
+
+#include "robot.h"
+
+RobotWidget::RobotWidget(QWidget *parent)
+ : QWidget(parent)
+ , m_robot(0)
+{
+ m_paper = QPixmap(500, 500);
+ reset();
+
+ setMinimumSize(sizeHint());
+ setMaximumSize(sizeHint());
+}
+
+void RobotWidget::setRobot(Robot *robot)
+{
+ m_robot = robot;
+ reset();
+}
+
+QSize RobotWidget::sizeHint()
+{
+ return m_paper.size();
+}
+
+void RobotWidget::reset()
+{
+ m_paper.fill(Qt::white);
+ QPainter p(&m_paper);
+ QPen pen(Qt::black);
+ pen.setWidth(10);
+ p.setPen(pen);
+ p.drawEllipse(100, 100, 300, 300);
+ if (m_robot)
+ m_robot->reset(m_paper);
+ update();
+}
+
+void RobotWidget::step()
+{
+ m_robot->step(&m_paper);
+ update();
+}
+
+void RobotWidget::paintEvent(QPaintEvent *)
+{
+ QPainter p(this);
+ p.drawPixmap(0, 0, m_paper);
+ p.setRenderHint(QPainter::Antialiasing);
+ if (m_robot)
+ m_robot->drawOverlay(p);
+}
diff --git a/qtbotsim/robotwidget.h b/qtbotsim/robotwidget.h
new file mode 100644
index 0000000..46ae2b0
--- /dev/null
+++ b/qtbotsim/robotwidget.h
@@ -0,0 +1,64 @@
+/*
+ * In the original BSD license, both occurrences of the phrase "COPYRIGHT
+ * HOLDERS AND CONTRIBUTORS" in the disclaimer read "REGENTS AND CONTRIBUTORS".
+ *
+ * Here is the license template:
+ *
+ * Copyright (c) 2011, Johan Thelin <johan@thelins.se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of Johan Thelin nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ROBOTWIDGET_H
+#define ROBOTWIDGET_H
+
+#include <QWidget>
+#include <QPixmap>
+
+class Robot;
+
+class RobotWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ RobotWidget(QWidget *parent = 0);
+
+ void setRobot(Robot *m_robot);
+
+ QSize sizeHint();
+
+public slots:
+ void reset();
+ void step();
+
+protected:
+ void paintEvent(QPaintEvent*);
+
+private:
+ QPixmap m_paper;
+ Robot *m_robot;
+};
+
+#endif // ROBOTWIDGET_H
diff --git a/qtbotsim/widget.cpp b/qtbotsim/widget.cpp
new file mode 100644
index 0000000..8f180f7
--- /dev/null
+++ b/qtbotsim/widget.cpp
@@ -0,0 +1,101 @@
+/*
+ * In the original BSD license, both occurrences of the phrase "COPYRIGHT
+ * HOLDERS AND CONTRIBUTORS" in the disclaimer read "REGENTS AND CONTRIBUTORS".
+ *
+ * Here is the license template:
+ *
+ * Copyright (c) 2011, Johan Thelin <johan@thelins.se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of Johan Thelin nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "widget.h"
+#include "ui_widget.h"
+
+#include <QTimer>
+
+#include <QDeclarativeEngine>
+#include <QDeclarativeContext>
+#include <QDeclarativeComponent>
+
+#include "robot.h"
+
+Widget::Widget(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::Widget)
+{
+ m_timer = new QTimer(this);
+ m_timer->setInterval(50);
+
+ connect(m_timer, SIGNAL(timeout()), this, SLOT(on_stepButton_clicked()));
+
+ ui->setupUi(this);
+ m_robot = new Robot(this);
+
+ ui->widget->setRobot(m_robot);
+
+ QDeclarativeEngine *engine = new QDeclarativeEngine(this);
+ engine->rootContext()->setContextProperty("robot", m_robot);
+ QDeclarativeComponent component(engine);
+ component.setData("import QtQuick 1.0\n"
+ "StateGroup {\n"
+ " states: [State { name: \"turn\"\n"
+ " PropertyChanges { target: robot; leftEngineSpeed: -0.5; rightEngineSpeed: 1.0; } },\n"
+ " State { name: \"forward\"\n"
+ " PropertyChanges { target: robot; leftEngineSpeed: 0.5; rightEngineSpeed: 0.5; } } ]\n"
+ " state: robot.brightForward?\"forward\":\"turn\"\n"
+ "}\n"
+ , QUrl());
+ QObject *controller = component.create();
+
+ foreach(QDeclarativeError e, component.errors())
+ qDebug("ERROR: %d %s", e.line(), qPrintable(e.description()));
+
+ controller->setParent(this);
+}
+
+Widget::~Widget()
+{
+ delete ui;
+}
+
+void Widget::on_clearButton_clicked()
+{
+ m_timer->stop();
+ ui->widget->reset();
+}
+
+void Widget::on_stepButton_clicked()
+{
+ ui->widget->step();
+}
+
+void Widget::on_runButton_clicked()
+{
+ if (m_timer->isActive())
+ m_timer->stop();
+ else
+ m_timer->start();
+}
diff --git a/qtbotsim/widget.h b/qtbotsim/widget.h
new file mode 100644
index 0000000..ccf210a
--- /dev/null
+++ b/qtbotsim/widget.h
@@ -0,0 +1,65 @@
+/*
+ * In the original BSD license, both occurrences of the phrase "COPYRIGHT
+ * HOLDERS AND CONTRIBUTORS" in the disclaimer read "REGENTS AND CONTRIBUTORS".
+ *
+ * Here is the license template:
+ *
+ * Copyright (c) 2011, Johan Thelin <johan@thelins.se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of Johan Thelin nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WIDGET_H
+#define WIDGET_H
+
+#include <QWidget>
+
+class Robot;
+class QTimer;
+
+namespace Ui {
+class Widget;
+}
+
+class Widget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit Widget(QWidget *parent = 0);
+ ~Widget();
+
+private slots:
+ void on_clearButton_clicked();
+ void on_stepButton_clicked();
+ void on_runButton_clicked();
+
+private:
+ Ui::Widget *ui;
+ Robot *m_robot;
+ QTimer *m_timer;
+};
+
+#endif // WIDGET_H
diff --git a/qtbotsim/widget.ui b/qtbotsim/widget.ui
new file mode 100644
index 0000000..ee157da
--- /dev/null
+++ b/qtbotsim/widget.ui
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Widget</class>
+ <widget class="QWidget" name="Widget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Widget</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="RobotWidget" name="widget" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="clearButton">
+ <property name="text">
+ <string>Clear</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="stepButton">
+ <property name="text">
+ <string>Step</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="runButton">
+ <property name="text">
+ <string>Run/Stop</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>RobotWidget</class>
+ <extends>QWidget</extends>
+ <header location="global">robotwidget.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>