From 38be0d13830efd2d98281c645c3a60afe05ffece Mon Sep 17 00:00:00 2001 From: Qt by Nokia Date: Wed, 27 Apr 2011 12:05:43 +0200 Subject: Initial import from the monolithic Qt. This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12 --- examples/dbus/remotecontrolledcar/car/car.cpp | 137 +++++++++++++++++++++ examples/dbus/remotecontrolledcar/car/car.h | 73 +++++++++++ examples/dbus/remotecontrolledcar/car/car.pro | 22 ++++ examples/dbus/remotecontrolledcar/car/car.xml | 11 ++ .../dbus/remotecontrolledcar/car/car_adaptor.cpp | 98 +++++++++++++++ .../dbus/remotecontrolledcar/car/car_adaptor.h | 96 +++++++++++++++ examples/dbus/remotecontrolledcar/car/main.cpp | 72 +++++++++++ .../dbus/remotecontrolledcar/controller/car.xml | 11 ++ .../controller/car_interface.cpp | 64 ++++++++++ .../remotecontrolledcar/controller/car_interface.h | 113 +++++++++++++++++ .../remotecontrolledcar/controller/controller.cpp | 82 ++++++++++++ .../remotecontrolledcar/controller/controller.h | 69 +++++++++++ .../remotecontrolledcar/controller/controller.pro | 23 ++++ .../remotecontrolledcar/controller/controller.ui | 64 ++++++++++ .../dbus/remotecontrolledcar/controller/main.cpp | 52 ++++++++ .../remotecontrolledcar/remotecontrolledcar.pro | 10 ++ 16 files changed, 997 insertions(+) create mode 100644 examples/dbus/remotecontrolledcar/car/car.cpp create mode 100644 examples/dbus/remotecontrolledcar/car/car.h create mode 100644 examples/dbus/remotecontrolledcar/car/car.pro create mode 100644 examples/dbus/remotecontrolledcar/car/car.xml create mode 100644 examples/dbus/remotecontrolledcar/car/car_adaptor.cpp create mode 100644 examples/dbus/remotecontrolledcar/car/car_adaptor.h create mode 100644 examples/dbus/remotecontrolledcar/car/main.cpp create mode 100644 examples/dbus/remotecontrolledcar/controller/car.xml create mode 100644 examples/dbus/remotecontrolledcar/controller/car_interface.cpp create mode 100644 examples/dbus/remotecontrolledcar/controller/car_interface.h create mode 100644 examples/dbus/remotecontrolledcar/controller/controller.cpp create mode 100644 examples/dbus/remotecontrolledcar/controller/controller.h create mode 100644 examples/dbus/remotecontrolledcar/controller/controller.pro create mode 100644 examples/dbus/remotecontrolledcar/controller/controller.ui create mode 100644 examples/dbus/remotecontrolledcar/controller/main.cpp create mode 100644 examples/dbus/remotecontrolledcar/remotecontrolledcar.pro (limited to 'examples/dbus/remotecontrolledcar') diff --git a/examples/dbus/remotecontrolledcar/car/car.cpp b/examples/dbus/remotecontrolledcar/car/car.cpp new file mode 100644 index 0000000000..50f8f24d3e --- /dev/null +++ b/examples/dbus/remotecontrolledcar/car/car.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "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 Nokia Corporation and its Subsidiary(-ies) 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 +** 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." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "car.h" +#include +#include + +static const double Pi = 3.14159265358979323846264338327950288419717; + +QRectF Car::boundingRect() const +{ + return QRectF(-35, -81, 70, 115); +} + +Car::Car() : color(Qt::green), wheelsAngle(0), speed(0) +{ + startTimer(1000 / 33); + setFlag(QGraphicsItem::ItemIsMovable, true); + setFlag(QGraphicsItem::ItemIsFocusable, true); +} + +void Car::accelerate() +{ + if (speed < 10) + ++speed; +} + +void Car::decelerate() +{ + if (speed > -10) + --speed; +} + +void Car::turnLeft() +{ + if (wheelsAngle > -30) + wheelsAngle -= 5; +} + +void Car::turnRight() +{ + if (wheelsAngle < 30) + wheelsAngle += 5; +} + +void Car::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + painter->setBrush(Qt::gray); + painter->drawRect(-20, -58, 40, 2); // front axel + painter->drawRect(-20, 7, 40, 2); // rear axel + + painter->setBrush(color); + painter->drawRect(-25, -79, 50, 10); // front wing + + painter->drawEllipse(-25, -48, 50, 20); // side pods + painter->drawRect(-25, -38, 50, 35); // side pods + painter->drawRect(-5, 9, 10, 10); // back pod + + painter->drawEllipse(-10, -81, 20, 100); // main body + + painter->drawRect(-17, 19, 34, 15); // rear wing + + painter->setBrush(Qt::black); + painter->drawPie(-5, -51, 10, 15, 0, 180 * 16); + painter->drawRect(-5, -44, 10, 10); // cocpit + + painter->save(); + painter->translate(-20, -58); + painter->rotate(wheelsAngle); + painter->drawRect(-10, -7, 10, 15); // front left + painter->restore(); + + painter->save(); + painter->translate(20, -58); + painter->rotate(wheelsAngle); + painter->drawRect(0, -7, 10, 15); // front left + painter->restore(); + + painter->drawRect(-30, 0, 12, 17); // rear left + painter->drawRect(19, 0, 12, 17); // rear right +} + +void Car::timerEvent(QTimerEvent *event) +{ + Q_UNUSED(event); + + const qreal axelDistance = 54; + qreal wheelsAngleRads = (wheelsAngle * Pi) / 180; + qreal turnDistance = ::cos(wheelsAngleRads) * axelDistance * 2; + qreal turnRateRads = wheelsAngleRads / turnDistance; // rough estimate + qreal turnRate = (turnRateRads * 180) / Pi; + qreal rotation = speed * turnRate; + + rotate(rotation); + translate(0, -speed); + update(); +} diff --git a/examples/dbus/remotecontrolledcar/car/car.h b/examples/dbus/remotecontrolledcar/car/car.h new file mode 100644 index 0000000000..3db41d7770 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/car/car.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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "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 Nokia Corporation and its Subsidiary(-ies) 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 +** 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." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CAR_H +#define CAR_H + +#include +#include + +class Car : public QGraphicsObject +{ + Q_OBJECT +public: + Car(); + QRectF boundingRect() const; + +public Q_SLOTS: + void accelerate(); + void decelerate(); + void turnLeft(); + void turnRight(); + +Q_SIGNALS: + void crashed(); + +protected: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + void timerEvent(QTimerEvent *event); + +private: + QBrush color; + qreal wheelsAngle; // used when applying rotation + qreal speed; // delta movement along the body axis +}; + +#endif // CAR_H diff --git a/examples/dbus/remotecontrolledcar/car/car.pro b/examples/dbus/remotecontrolledcar/car/car.pro new file mode 100644 index 0000000000..0d7971f9d7 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/car/car.pro @@ -0,0 +1,22 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Mon Aug 28 19:50:14 2006 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +CONFIG += qdbus + +# Input +# DBUS_ADAPTORS += car.xml +HEADERS += car.h car_adaptor.h +SOURCES += car.cpp main.cpp car_adaptor.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/remotecontrolledcar/car +sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.xml +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/remotecontrolledcar/car +INSTALLS += target sources + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/examples/dbus/remotecontrolledcar/car/car.xml b/examples/dbus/remotecontrolledcar/car/car.xml new file mode 100644 index 0000000000..641c6982d4 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/car/car.xml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/examples/dbus/remotecontrolledcar/car/car_adaptor.cpp b/examples/dbus/remotecontrolledcar/car/car_adaptor.cpp new file mode 100644 index 0000000000..4ced1f5a9c --- /dev/null +++ b/examples/dbus/remotecontrolledcar/car/car_adaptor.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "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 Nokia Corporation and its Subsidiary(-ies) 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 +** 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." +** $QT_END_LICENSE$ +** +** +** This file was generated by qdbusxml2cpp version 0.7 +** Command line was: qdbusxml2cpp -i car_adaptor.h -a :car_adaptor.cpp car.xml +** +** qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** This is an auto-generated file. +** Do not edit! All changes made to it will be lost. +** +****************************************************************************/ + +#include "car_adaptor.h" +#include +#include +#include +#include +#include +#include +#include + +/* + * Implementation of adaptor class CarInterfaceAdaptor + */ + +CarInterfaceAdaptor::CarInterfaceAdaptor(QObject *parent) + : QDBusAbstractAdaptor(parent) +{ + // constructor + setAutoRelaySignals(true); +} + +CarInterfaceAdaptor::~CarInterfaceAdaptor() +{ + // destructor +} + +void CarInterfaceAdaptor::accelerate() +{ + // handle method call com.trolltech.Examples.CarInterface.accelerate + QMetaObject::invokeMethod(parent(), "accelerate"); +} + +void CarInterfaceAdaptor::decelerate() +{ + // handle method call com.trolltech.Examples.CarInterface.decelerate + QMetaObject::invokeMethod(parent(), "decelerate"); +} + +void CarInterfaceAdaptor::turnLeft() +{ + // handle method call com.trolltech.Examples.CarInterface.turnLeft + QMetaObject::invokeMethod(parent(), "turnLeft"); +} + +void CarInterfaceAdaptor::turnRight() +{ + // handle method call com.trolltech.Examples.CarInterface.turnRight + QMetaObject::invokeMethod(parent(), "turnRight"); +} + diff --git a/examples/dbus/remotecontrolledcar/car/car_adaptor.h b/examples/dbus/remotecontrolledcar/car/car_adaptor.h new file mode 100644 index 0000000000..c31779fed0 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/car/car_adaptor.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "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 Nokia Corporation and its Subsidiary(-ies) 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 +** 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." +** $QT_END_LICENSE$ +** +** +** This file was generated by qdbusxml2cpp version 0.7 +** Command line was: qdbusxml2cpp -a car_adaptor.h: car.xml +** +** qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** This is an auto-generated file. +** This file may have been hand-edited. Look for HAND-EDIT comments +** before re-generating it. +** +****************************************************************************/ + +#ifndef CAR_ADAPTOR_H_1264773009 +#define CAR_ADAPTOR_H_1264773009 + +#include +#include + +QT_BEGIN_NAMESPACE +class QByteArray; +template class QList; +template class QMap; +class QString; +class QStringList; +class QVariant; +QT_END_NAMESPACE + +/* + * Adaptor class for interface com.trolltech.Examples.CarInterface + */ +class CarInterfaceAdaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "com.trolltech.Examples.CarInterface") + Q_CLASSINFO("D-Bus Introspection", "" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" + "") +public: + CarInterfaceAdaptor(QObject *parent); + virtual ~CarInterfaceAdaptor(); + +public: // PROPERTIES +public Q_SLOTS: // METHODS + void accelerate(); + void decelerate(); + void turnLeft(); + void turnRight(); +Q_SIGNALS: // SIGNALS + void crashed(); +}; + +#endif diff --git a/examples/dbus/remotecontrolledcar/car/main.cpp b/examples/dbus/remotecontrolledcar/car/main.cpp new file mode 100644 index 0000000000..342a2b0c5d --- /dev/null +++ b/examples/dbus/remotecontrolledcar/car/main.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "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 Nokia Corporation and its Subsidiary(-ies) 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 +** 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." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "car.h" +#include "car_adaptor.h" +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QGraphicsScene scene; + scene.setSceneRect(-500, -500, 1000, 1000); + scene.setItemIndexMethod(QGraphicsScene::NoIndex); + + Car *car = new Car(); + scene.addItem(car); + + QGraphicsView view(&scene); + view.setRenderHint(QPainter::Antialiasing); + view.setBackgroundBrush(Qt::darkGray); + view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Qt DBus Controlled Car")); + view.resize(400, 300); + view.show(); + + new CarInterfaceAdaptor(car); + QDBusConnection connection = QDBusConnection::sessionBus(); + connection.registerObject("/Car", car); + connection.registerService("com.trolltech.CarExample"); + + return app.exec(); +} diff --git a/examples/dbus/remotecontrolledcar/controller/car.xml b/examples/dbus/remotecontrolledcar/controller/car.xml new file mode 100644 index 0000000000..641c6982d4 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/controller/car.xml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/examples/dbus/remotecontrolledcar/controller/car_interface.cpp b/examples/dbus/remotecontrolledcar/controller/car_interface.cpp new file mode 100644 index 0000000000..e1e6ae4bec --- /dev/null +++ b/examples/dbus/remotecontrolledcar/controller/car_interface.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "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 Nokia Corporation and its Subsidiary(-ies) 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 +** 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." +** $QT_END_LICENSE$ +** +** +** This file was generated by qdbusxml2cpp version 0.7 +** Command line was: qdbusxml2cpp -i car_interface.h -p :car_interface.cpp car.xml +** +** qqdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** This is an auto-generated file. +** This file may have been hand-edited. Look for HAND-EDIT comments +** before re-generating it. +** +****************************************************************************/ + +#include "car_interface.h" +/* + * Implementation of interface class ComTrolltechExamplesCarInterfaceInterface + */ + +ComTrolltechExamplesCarInterfaceInterface::ComTrolltechExamplesCarInterfaceInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +ComTrolltechExamplesCarInterfaceInterface::~ComTrolltechExamplesCarInterfaceInterface() +{ +} + diff --git a/examples/dbus/remotecontrolledcar/controller/car_interface.h b/examples/dbus/remotecontrolledcar/controller/car_interface.h new file mode 100644 index 0000000000..e7e3774c17 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/controller/car_interface.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "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 Nokia Corporation and its Subsidiary(-ies) 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 +** 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." +** $QT_END_LICENSE$ +** +** +** This file was generated by qdbusxml2cpp version 0.7 +** Command line was: qdbusxml2cpp -p car_interface.h: car.xml +** +** qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** This is an auto-generated file. +** Do not edit! All changes made to it will be lost. +** +****************************************************************************/ + +#ifndef CAR_INTERFACE_H_1264772826 +#define CAR_INTERFACE_H_1264772826 + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface com.trolltech.Examples.CarInterface + */ +class ComTrolltechExamplesCarInterfaceInterface: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "com.trolltech.Examples.CarInterface"; } + +public: + ComTrolltechExamplesCarInterfaceInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~ComTrolltechExamplesCarInterfaceInterface(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> accelerate() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("accelerate"), argumentList); + } + + inline QDBusPendingReply<> decelerate() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("decelerate"), argumentList); + } + + inline QDBusPendingReply<> turnLeft() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("turnLeft"), argumentList); + } + + inline QDBusPendingReply<> turnRight() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("turnRight"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void crashed(); +}; + +namespace com { + namespace trolltech { + namespace Examples { + typedef ::ComTrolltechExamplesCarInterfaceInterface CarInterface; + } + } +} +#endif diff --git a/examples/dbus/remotecontrolledcar/controller/controller.cpp b/examples/dbus/remotecontrolledcar/controller/controller.cpp new file mode 100644 index 0000000000..8691aafa92 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/controller/controller.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "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 Nokia Corporation and its Subsidiary(-ies) 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 +** 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." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "controller.h" +#include "car_interface.h" + +Controller::Controller(QWidget *parent) + : QWidget(parent) +{ + ui.setupUi(this); + car = new com::trolltech::Examples::CarInterface("com.trolltech.CarExample", "/Car", + QDBusConnection::sessionBus(), this); + startTimer(1000); +} + +void Controller::timerEvent(QTimerEvent *event) +{ + Q_UNUSED(event); + if (car->isValid()) + ui.label->setText("connected"); + else + ui.label->setText("disconnected"); +} + +void Controller::on_accelerate_clicked() +{ + car->accelerate(); +} + +void Controller::on_decelerate_clicked() +{ + car->decelerate(); +} + +void Controller::on_left_clicked() +{ + car->turnLeft(); +} + +void Controller::on_right_clicked() +{ + car->turnRight(); +} diff --git a/examples/dbus/remotecontrolledcar/controller/controller.h b/examples/dbus/remotecontrolledcar/controller/controller.h new file mode 100644 index 0000000000..3fe172e2b7 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/controller/controller.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "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 Nokia Corporation and its Subsidiary(-ies) 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 +** 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." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CONTROLLER_H +#define CONTROLLER_H + +#include "ui_controller.h" +#include "car_interface.h" + +class Controller : public QWidget +{ + Q_OBJECT + +public: + Controller(QWidget *parent = 0); + +protected: + void timerEvent(QTimerEvent *event); + +private slots: + void on_accelerate_clicked(); + void on_decelerate_clicked(); + void on_left_clicked(); + void on_right_clicked(); + +private: + Ui::Controller ui; + com::trolltech::Examples::CarInterface *car; +}; + +#endif + diff --git a/examples/dbus/remotecontrolledcar/controller/controller.pro b/examples/dbus/remotecontrolledcar/controller/controller.pro new file mode 100644 index 0000000000..71cdb54b17 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/controller/controller.pro @@ -0,0 +1,23 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Tue Aug 29 12:28:05 2006 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +CONFIG += qdbus + +# Input +# DBUS_INTERFACES += car.xml +FORMS += controller.ui +HEADERS += car_interface.h controller.h +SOURCES += main.cpp car_interface.cpp controller.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/remotecontrolledcar/controller +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.xml +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/remotecontrolledcar/controller +INSTALLS += target sources + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/examples/dbus/remotecontrolledcar/controller/controller.ui b/examples/dbus/remotecontrolledcar/controller/controller.ui new file mode 100644 index 0000000000..379015bf30 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/controller/controller.ui @@ -0,0 +1,64 @@ + + Controller + + + + 0 + 0 + 255 + 111 + + + + Controller + + + + 9 + + + 6 + + + + + Controller + + + Qt::AlignCenter + + + + + + + Decelerate + + + + + + + Accelerate + + + + + + + Right + + + + + + + Left + + + + + + + + diff --git a/examples/dbus/remotecontrolledcar/controller/main.cpp b/examples/dbus/remotecontrolledcar/controller/main.cpp new file mode 100644 index 0000000000..5b536117c8 --- /dev/null +++ b/examples/dbus/remotecontrolledcar/controller/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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "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 Nokia Corporation and its Subsidiary(-ies) 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 +** 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." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "controller.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Controller controller; + controller.show(); + return app.exec(); +} diff --git a/examples/dbus/remotecontrolledcar/remotecontrolledcar.pro b/examples/dbus/remotecontrolledcar/remotecontrolledcar.pro new file mode 100644 index 0000000000..586507683c --- /dev/null +++ b/examples/dbus/remotecontrolledcar/remotecontrolledcar.pro @@ -0,0 +1,10 @@ +TEMPLATE = subdirs +SUBDIRS = car \ + controller + +# install +sources.files = *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/remotecontrolledcar +INSTALLS += sources + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) -- cgit v1.2.3