From 1b256167372734a5b84b5f657cf9d99c5128e505 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 2 Apr 2014 15:40:14 +0200 Subject: Remove old Bluetooth tennis example And update the documentation around the removal. The new ping pong game example is written in QML and much easier to maintain. Change-Id: I885d0c82b8f6eb8935c8f030ebb0adef9c1afc85 Reviewed-by: Fabian Bumberger --- examples/bluetooth/bluetooth.pro | 3 +- examples/bluetooth/bttennis/board.cpp | 250 ------------ examples/bluetooth/bttennis/board.h | 126 ------ examples/bluetooth/bttennis/bttennis.pro | 36 -- examples/bluetooth/bttennis/connect.png | Bin 11074 -> 0 bytes examples/bluetooth/bttennis/controller.cpp | 263 ------------- examples/bluetooth/bttennis/controller.h | 100 ----- .../bttennis/doc/images/bttennis-example.png | Bin 4890 -> 0 bytes examples/bluetooth/bttennis/doc/src/bttennis.qdoc | 40 -- examples/bluetooth/bttennis/handover.cpp | 130 ------ examples/bluetooth/bttennis/handover.h | 91 ----- examples/bluetooth/bttennis/main.cpp | 59 --- examples/bluetooth/bttennis/tennis.cpp | 435 --------------------- examples/bluetooth/bttennis/tennis.h | 138 ------- examples/bluetooth/bttennis/tennis.qrc | 5 - examples/bluetooth/bttennis/tennis.ui | 57 --- examples/bluetooth/bttennis/tennisclient.cpp | 200 ---------- examples/bluetooth/bttennis/tennisclient.h | 99 ----- examples/bluetooth/bttennis/tennisserver.cpp | 306 --------------- examples/bluetooth/bttennis/tennisserver.h | 104 ----- examples/bluetooth/bttennis/tennisview.cpp | 69 ---- examples/bluetooth/bttennis/tennisview.h | 69 ---- src/bluetooth/doc/src/bluetooth-index.qdoc | 1 - src/bluetooth/doc/src/examples.qdoc | 17 +- 24 files changed, 7 insertions(+), 2591 deletions(-) delete mode 100644 examples/bluetooth/bttennis/board.cpp delete mode 100644 examples/bluetooth/bttennis/board.h delete mode 100644 examples/bluetooth/bttennis/bttennis.pro delete mode 100644 examples/bluetooth/bttennis/connect.png delete mode 100644 examples/bluetooth/bttennis/controller.cpp delete mode 100644 examples/bluetooth/bttennis/controller.h delete mode 100644 examples/bluetooth/bttennis/doc/images/bttennis-example.png delete mode 100644 examples/bluetooth/bttennis/doc/src/bttennis.qdoc delete mode 100644 examples/bluetooth/bttennis/handover.cpp delete mode 100644 examples/bluetooth/bttennis/handover.h delete mode 100644 examples/bluetooth/bttennis/main.cpp delete mode 100644 examples/bluetooth/bttennis/tennis.cpp delete mode 100644 examples/bluetooth/bttennis/tennis.h delete mode 100644 examples/bluetooth/bttennis/tennis.qrc delete mode 100644 examples/bluetooth/bttennis/tennis.ui delete mode 100644 examples/bluetooth/bttennis/tennisclient.cpp delete mode 100644 examples/bluetooth/bttennis/tennisclient.h delete mode 100644 examples/bluetooth/bttennis/tennisserver.cpp delete mode 100644 examples/bluetooth/bttennis/tennisserver.h delete mode 100644 examples/bluetooth/bttennis/tennisview.cpp delete mode 100644 examples/bluetooth/bttennis/tennisview.h diff --git a/examples/bluetooth/bluetooth.pro b/examples/bluetooth/bluetooth.pro index 251d7dd1..a0379f6c 100644 --- a/examples/bluetooth/bluetooth.pro +++ b/examples/bluetooth/bluetooth.pro @@ -2,8 +2,7 @@ TEMPLATE = subdirs qtHaveModule(widgets) { SUBDIRS += btchat \ btscanner \ - btfiletransfer \ - bttennis + btfiletransfer } qtHaveModule(quick): SUBDIRS += scanner picturetransfer pingpong diff --git a/examples/bluetooth/bttennis/board.cpp b/examples/bluetooth/bttennis/board.cpp deleted file mode 100644 index eb3c88d8..00000000 --- a/examples/bluetooth/bttennis/board.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "board.h" - -#include -#include -#include -#include -#include -#include - -const QColor fg = Qt::white; -const QColor bg = Qt::black; - -Board::Board(QWidget *parent) : - QGraphicsView(parent) -{ - scene = new QGraphicsScene(QRect(0, 0, 640, 360), this); - - scene->setBackgroundBrush(QBrush(bg)); - - ball = scene->addRect(-6, -6, 12, 12, QPen(Qt::SolidLine), QBrush(fg)); - ball->setPos(Width/2-6, Height/2-6); - - // why is y -1...otherwise we have a gap... - topWall = scene->addRect(0, -1, Width, 12, QPen(Qt::SolidLine), QBrush(fg)); - bottomWall = scene->addRect(0, Height-12, Width, 12, QPen(Qt::SolidLine), QBrush(fg)); - - leftPaddle = scene->addRect(0, 12, 12, Paddle, QPen(Qt::SolidLine), QBrush(fg)); - rightPaddle = scene->addRect(Width-12, 12, 12, Paddle, QPen(Qt::SolidLine), QBrush(fg)); - - QPen p; - p.setWidth(2); - p.setStyle(Qt::DotLine); - p.setBrush(QBrush(fg)); - scene->addLine(Width/2, 0, Width/2, Height, p); - - QFont f; - f.setStyleHint(QFont::OldEnglish); - f.setPixelSize(50); - f.setBold(true); - leftScore = scene->addText(QString("0"), f); - leftScore->setDefaultTextColor(fg); -// leftScore->setPos(120, 50); - - rightScore = scene->addText(QString("0"), f); -// rightScore->setPos(Width-140, 50); - rightScore->setDefaultTextColor(fg); - setScore(0, 0); - - f.setPixelSize(25); - status = scene->addText(QString(), f); - status->setDefaultTextColor(fg); - - ball->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - leftPaddle->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - rightPaddle->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - - icon.load(QString(":/icons/connect.png")); - icon = icon.scaled(100, 100, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - qDebug() << "icon" << icon.isNull(); - connectIcon = scene->addPixmap(icon); - connectIcon->setPos(440,200); - connectIcon->setAcceptTouchEvents(true); - connectIcon->setTransformOriginPoint(50,50); - connectIcon->setTransformationMode(Qt::SmoothTransformation); - - connectAnimation = new QPropertyAnimation(this, "connectRotation"); - connectAnimation->setDuration(1000); - connectAnimation->setLoopCount(-1); - connectAnimation->setStartValue(0); - connectAnimation->setEndValue(360); - - setCacheMode(QGraphicsView::CacheBackground); - setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); - -// connect(scene, SIGNAL(changed(QList)), this, SLOT(sceneChanged(QList))); - -} -void Board::setBall(int x, int y) -{ - ball->setPos(x, y); - checkBall(x, y); -} - -void Board::setLeftPaddle(int y) -{ - leftPaddle->setPos(0, y); -} - -void Board::setRightPaddle(int y) -{ - rightPaddle->setPos(0, y); -} - -void Board::sceneChanged(const QList ®ion) -{ - Q_UNUSED(region); - - QListitems = scene->collidingItems(ball); - while (!items.empty()) { - QGraphicsItem *i = items.takeFirst(); - if (i == topWall) - emit ballCollision(Top); - if (i == bottomWall) - emit ballCollision(Bottom); - if (i == leftPaddle) - emit ballCollision(Left); - if (i == rightPaddle) - emit ballCollision(Right); - } - -} - -void Board::checkBall(int x, int y) -{ - int ly = leftPaddle->y(); - int ry = rightPaddle->y(); - - if (x > 646) - emit scored(Right); - else if (x < -6) - emit scored(Left); - - if (y < 18) - emit ballCollision(Top); - else if (y > 360-18) - emit ballCollision(Bottom); - - if ((x < 18) && - (y > ly-6) && - (y < ly+Paddle+6)) - emit ballCollision(Left); - - if ((x > 640-18) && - (y > ry-6) && - (y < ry+Paddle+6)) - emit ballCollision(Right); -} - -void Board::setScore(int l, int r) -{ - QString left = QString("%1").arg(l); - QString right = QString("%1").arg(r); - leftScore->document()->setPlainText(left); - rightScore->document()->setPlainText(right); - QFontMetrics fm(leftScore->font()); - leftScore->setPos(Width/4 - fm.width(left)/2, 50); - rightScore->setPos(3*Width/4 - fm.width(right)/2, 50); - -} - -void Board::setStatus(QString text, int opacity_start, int opacity_end) -{ - - status->document()->setPlainText(text); - status->setPos(24, Height-25-25); - QPropertyAnimation *a = new QPropertyAnimation(status, "opacity"); - a->setDuration(2000); - a->setStartValue(opacity_start/100.0); - a->setEndValue(opacity_end/100.0); - a->start(QAbstractAnimation::DeleteWhenStopped); -} - -void Board::setConnectRotation(int rot) -{ - connectIcon->setRotation(rot); -// QTransform t; -// t.rotate(rot); -// connectIcon->setPixmap(icon.scaled(100, 100).transformed(t, Qt::SmoothTransformation)); -} - -void Board::setConnectOpacity(qreal op) -{ - connectIcon->setOpacity(op); -} - -void Board::animateConnect(bool start) -{ - if (start) { - connectAnimation->start(); - } - else { - connectAnimation->stop(); - QPropertyAnimation *a = new QPropertyAnimation(this, "connectRotation"); -// qDebug() << "currentTime" << connectAnimation->currentLoopTime() << "rotation" << connectAnimation->currentValue(); - a->setDuration(connectAnimation->currentLoopTime()/2); - a->setStartValue(connectAnimation->currentValue().toInt( )); - a->setEndValue(0); -// a->setDirection(QAbstractAnimation::Backward); - a->start(QAbstractAnimation::DeleteWhenStopped); - } -} - - -void Board::fadeConnect(bool out) -{ - qreal start = 100.0; - qreal end = 0.0; - - if (!out) { - start = 0.0; - end = 100.0; - } - - QPropertyAnimation *a = new QPropertyAnimation(this, "connectOpacity"); - a->setDuration(2000); - a->setStartValue(start); - a->setEndValue(end); - a->start(QAbstractAnimation::DeleteWhenStopped); -} diff --git a/examples/bluetooth/bttennis/board.h b/examples/bluetooth/bttennis/board.h deleted file mode 100644 index d94a5b21..00000000 --- a/examples/bluetooth/bttennis/board.h +++ /dev/null @@ -1,126 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef BOARD_H -#define BOARD_H - -#include -#include -#include -#include -#include -#include - -class Board : public QGraphicsView -{ - Q_OBJECT - Q_PROPERTY(int connectRotation READ connectRotation WRITE setConnectRotation) - Q_PROPERTY(qreal connectOpacity READ connectOpacity WRITE setConnectOpacity) -public: - explicit Board(QWidget *parent = 0); - - enum Edge { - Top = 1, - Bottom, - Left, - Right - }; - - enum BoardSize { - Width = 640, - Height = 360, - Paddle = 50 - }; - - - QGraphicsScene *getScene() { - return scene; - } - - int connectRotation(){ - return connectIcon->rotation(); - } - - qreal connectOpacity(){ - return connectIcon->opacity(); - } - - void setConnectRotation(int rot); - void setConnectOpacity(qreal op); - -signals: - void ballCollision(Board::Edge pos); - void scored(Board::Edge pos); - -public slots: - void setBall(int x, int y); - void setLeftPaddle(int y); - void setRightPaddle(int y); - void setScore(int l, int r); - - void setStatus(QString text, int opacity_start, int opacity_end); - - void sceneChanged(const QList ®ion); - - void animateConnect(bool start = true); - void fadeConnect(bool out = true); - -private: - QGraphicsScene *scene; - QGraphicsRectItem *ball; - QGraphicsRectItem *topWall; - QGraphicsRectItem *bottomWall; - QGraphicsRectItem *leftPaddle; - QGraphicsRectItem *rightPaddle; - - QGraphicsTextItem *leftScore; - QGraphicsTextItem *rightScore; - - QGraphicsTextItem *status; - - QPixmap icon; - QGraphicsPixmapItem *connectIcon; - QPropertyAnimation *connectAnimation; - - void checkBall(int x, int y); -}; - -#endif // BOARD_H diff --git a/examples/bluetooth/bttennis/bttennis.pro b/examples/bluetooth/bttennis/bttennis.pro deleted file mode 100644 index 1c014784..00000000 --- a/examples/bluetooth/bttennis/bttennis.pro +++ /dev/null @@ -1,36 +0,0 @@ -TEMPLATE = app -TARGET = bttennis - -QT = core bluetooth widgets -#QT += nfc - -SOURCES = \ - main.cpp \ - board.cpp \ - tennis.cpp \ - controller.cpp \ - tennisserver.cpp \ - tennisclient.cpp \ - tennisview.cpp -# handover.cpp - -HEADERS = \ - board.h \ - tennis.h \ - controller.h \ - tennisserver.h \ - tennisclient.h \ - tennisview.h -# handover.h - -FORMS = \ - tennis.ui - -RESOURCES += \ - tennis.qrc - -OTHER_FILES = \ - connect.png - -target.path = $$[QT_INSTALL_EXAMPLES]/bluetooth/bttennis -INSTALLS += target diff --git a/examples/bluetooth/bttennis/connect.png b/examples/bluetooth/bttennis/connect.png deleted file mode 100644 index 70b64c6c..00000000 Binary files a/examples/bluetooth/bttennis/connect.png and /dev/null differ diff --git a/examples/bluetooth/bttennis/controller.cpp b/examples/bluetooth/bttennis/controller.cpp deleted file mode 100644 index 95163e66..00000000 --- a/examples/bluetooth/bttennis/controller.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "controller.h" - -#include -#include - -#define FRAME_RATE 60 - -Controller::Controller(QObject *parent) : - QObject(parent), timer(new QTimer), elapsed(new QTime), score_left(0), score_right(0), - col_x(0), col_y(0), - rightPaddleForce(0), leftPaddleForce(0), - rightPaddleLast(0), leftPaddleLast(0), - rightPowerUp(0), leftPowerUp(0) -{ - - qsrand(QDateTime::currentDateTime().time().msec()); - - - timer->setInterval(1000/FRAME_RATE); -// timer->setInterval(0); - connect(timer, SIGNAL(timeout()), SLOT(tick())); - srand(QDateTime::currentDateTime().time().msec()); - - fpscntr = new QTime; - frames = 0; - - timer->start(); - restart_ball(); -} - -void Controller::tick() -{ - if (col_x) - col_x--; - if (col_y) - col_y--; - -// frames++; -// if (fpscntr->elapsed() > 1000){ -// int f = frames/(fpscntr->elapsed()/1000.0); -// emit fps(QString("FPS %1").arg(f)); -// frames = 0; -// fpscntr->restart(); -// } - - int msec = elapsed->elapsed(); - elapsed->restart(); - - ball_x += speed_x*msec/1000; - ball_y += speed_y*msec/1000; - - - const int decay = 5; - - if (leftPaddleForce > decay) - leftPaddleForce-=decay; - else if (leftPaddleForce < -decay) - leftPaddleForce+=decay; - if (rightPaddleForce > decay) - rightPaddleForce-=decay; - else if (rightPaddleForce < -decay) - rightPaddleForce+=decay; - - if (rightPaddleForce <= decay) - rightPowerUp++; - - if (leftPaddleForce <= decay) - leftPowerUp++; - - -// ttf++; -// if (msec > 1000/FRAME_RATE+2 || msec < 1000/FRAME_RATE-2) -// dev++; - -// if (!(i++%120)) { -// qDebug() << "powerUp: " << leftPowerUp << rightPowerUp << leftPaddleForce << rightPaddleForce << speed_x*msec/1000 << speed_y*msec/1000 << msec << dev; -// ttf = dev =0; -// } - - emit moveBall(ball_x, ball_y); -} - - -static inline int paddle_boost(int force){ - if (force > 30) - return -3*FRAME_RATE; - else if (force > 20) - return -2*FRAME_RATE; - else if (force > 6) - return -1*FRAME_RATE; - else if (force < -30) - return 3*FRAME_RATE; - else if (force < -20) - return 2*FRAME_RATE; - else if (force < -6) - return 1*FRAME_RATE; - return 0; -} - -void Controller::ballCollision(Board::Edge pos) -{ - - if ((pos == Board::Top || pos == Board::Bottom) && !col_y) { - speed_y *= -1; - col_y = 10; - } - - if (pos == Board::Left && !col_x) { - speed_x *= -1; - speed_y += paddle_boost(leftPaddleForce); - col_x = 10; - - if (leftPowerUp > 75 && speed_x < 8*FRAME_RATE){ - speed_x *= 2; - leftPowerUp = 0; - } - } - else if (pos == Board::Right && !col_x) { - speed_x *= -1; - speed_y += paddle_boost(rightPaddleForce); - col_x = 10; - - if (rightPowerUp > 75 && speed_x > -8*FRAME_RATE){ - speed_x *= 2; - rightPowerUp = 0; - } - - } -// tick(); -// QMetaObject::invokeMethod(this, "moveBall", Qt::QueuedConnection, Q_ARG(int, ball_x), Q_ARG(int, ball_y)); -// emit moveBall(ball_x, ball_y); - -} - -void Controller::scored(Board::Edge pos) -{ - if (!timer->isActive()) - return; - - if (pos == Board::Left) - emit score(score_left, ++score_right); - else if (pos == Board::Right) - emit score(++score_left, score_right); - - restart_ball(); -} - -void Controller::restart_ball() -{ - if (!timer->isActive()) - return; - - elapsed->start(); - - ball_x = Board::Width/2; - ball_y = Board::Height/2; - -// ball_y = (qrand()%(Board::Height/2))+Board::Height/4; - ball_y = (qrand()%(Board::Height-48))+24; - - // Speed in in pixels/second - - const int max = 4*FRAME_RATE; - const int min_x = 2*FRAME_RATE; - const int min_y = 1.5*FRAME_RATE; - - - speed_y = min_y+qrand()%(max-min_y); - if (speed_y%2) - speed_y *= -1; - - - speed_x = min_x+qrand()%(max-min_y); - if (speed_x%2) - speed_x *= -1; - - leftPowerUp = rightPowerUp = 0; - - emit moveBall(ball_x, ball_y); -} - - -void Controller::resetBoard() -{ - if (!timer->isActive()) - return; - - score_left = score_right = 0; - restart_ball(); -} - -void Controller::stop() -{ - timer->stop(); -} - -void Controller::start() -{ - timer->start(); - fpscntr->restart(); - frames = 0; -} - -void Controller::moveLeftPaddle(int y) -{ - leftPaddleForce += leftPaddleLast-y; - leftPaddleLast = y; - leftPowerUp = 0; -} - -void Controller::moveRightPaddle(int y) -{ - rightPaddleForce += rightPaddleLast-y; - rightPaddleLast =y; - rightPowerUp = 0; -} - -void Controller::refresh() -{ - emit moveBall(ball_x, ball_y); - emit score(score_left, score_right); -} diff --git a/examples/bluetooth/bttennis/controller.h b/examples/bluetooth/bttennis/controller.h deleted file mode 100644 index 5146ce43..00000000 --- a/examples/bluetooth/bttennis/controller.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CONTROLLER_H -#define CONTROLLER_H - -#include -#include -#include -#include "board.h" - -class Controller : public QObject -{ - Q_OBJECT -public: - explicit Controller(QObject *parent = 0); - -signals: - void moveBall(int x, int y); - void score(int left, int right); - void fps(const QString &str); - -public slots: - void ballCollision(Board::Edge pos); - void scored(Board::Edge pos); - void resetBoard(); - void refresh(); - - void moveLeftPaddle(int y); - void moveRightPaddle(int y); - - void tick(); - - void start(); - void stop(); - -private: - QTimer *timer; - QTime *elapsed; - QTime *fpscntr; - int frames; - int ball_x; - int speed_x; - int ball_y; - int speed_y; - int score_left; - int score_right; - int col_x; - int col_y; - - int rightPaddleForce; - int leftPaddleForce; - int rightPaddleLast; - int leftPaddleLast; - int rightPowerUp; - int leftPowerUp; - - void restart_ball(); - -}; - -#endif // CONTROLLER_H diff --git a/examples/bluetooth/bttennis/doc/images/bttennis-example.png b/examples/bluetooth/bttennis/doc/images/bttennis-example.png deleted file mode 100644 index 53a5486b..00000000 Binary files a/examples/bluetooth/bttennis/doc/images/bttennis-example.png and /dev/null differ diff --git a/examples/bluetooth/bttennis/doc/src/bttennis.qdoc b/examples/bluetooth/bttennis/doc/src/bttennis.qdoc deleted file mode 100644 index 136b181d..00000000 --- a/examples/bluetooth/bttennis/doc/src/bttennis.qdoc +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the documentation of the Qt local connectivty modules. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example bttennis - \title Bluetooth Tennis Example - - The Bluetooth Tennis example shows how to use the Qt Connectivity Bluetooth API - to implement real-time data transfer for interactive applications. The example - establishes a \l {QBluetoothServiceInfo::L2capProtocol}{L2CP} socket connection. - Since this protocol type is not supported on Android and BlackBerry the example - does not work on those platforms. - - \image bttennis-example.png - -*/ diff --git a/examples/bluetooth/bttennis/handover.cpp b/examples/bluetooth/bttennis/handover.cpp deleted file mode 100644 index dbd6cdb4..00000000 --- a/examples/bluetooth/bttennis/handover.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "handover.h" - -#include -#include -#include -#include - -#include - -static const QLatin1String tennisUri("urn:nfc:sn:com.nokia.qtnfc.tennis"); - -Handover::Handover(quint16 serverPort, QObject *parent) -: QObject(parent), m_server(new QLlcpServer(this)), - m_client(new QLlcpSocket(this)), m_remote(0), m_serverPort(0), m_localServerPort(serverPort) -{ - connect(m_server, SIGNAL(newConnection()), this, SLOT(handleNewConnection())); - m_server->listen(tennisUri); - - connect(m_client, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); - connect(m_client, SIGNAL(readyRead()), this, SLOT(readBluetoothService())); - - m_client->connectToService(0, tennisUri); -} - -Handover::~Handover() -{ -} - -QBluetoothAddress Handover::bluetoothAddress() const -{ - return m_address; -} - -quint16 Handover::serverPort() const -{ - return m_serverPort; -} - -void Handover::handleNewConnection() -{ - if (m_remote) - m_remote->deleteLater(); - - m_remote = m_server->nextPendingConnection(); - - connect(m_remote, SIGNAL(disconnected()), this, SLOT(remoteDisconnected())); - - sendBluetoothService(); -} - -void Handover::remoteDisconnected() -{ - m_remote->deleteLater(); - m_remote = 0; -} - -void Handover::clientDisconnected() -{ - m_client->connectToService(0, tennisUri); -} - -void Handover::readBluetoothService() -{ - QByteArray rawData = m_client->readAll(); - QString data = QString::fromUtf8(rawData.constData(), rawData.size()); - QStringList split = data.split(QLatin1Char(' ')); - - QBluetoothAddress address = QBluetoothAddress(split.at(0)); - quint16 port = split.at(1).toUInt(); - - QBluetoothLocalDevice localDevice; - QBluetoothAddress localAddress = localDevice.address(); - - if (localAddress < address) { - m_address = address; - m_serverPort = port; - emit bluetoothServiceChanged(); - } -} - -void Handover::sendBluetoothService() -{ - QBluetoothLocalDevice localDevice; - const QString data = localDevice.address().toString() + QLatin1Char(' ') + - QString::number(m_localServerPort); - - m_remote->write(data.toUtf8()); -} - diff --git a/examples/bluetooth/bttennis/handover.h b/examples/bluetooth/bttennis/handover.h deleted file mode 100644 index 52d2fba6..00000000 --- a/examples/bluetooth/bttennis/handover.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef HANDOVER_H -#define HANDOVER_H - -#include - -#include -#include -#include - -QT_FORWARD_DECLARE_CLASS(QNearFieldManager) -QT_FORWARD_DECLARE_CLASS(QNearFieldTarget) -QT_FORWARD_DECLARE_CLASS(QLlcpServer) -QT_FORWARD_DECLARE_CLASS(QLlcpSocket) - -QT_USE_NAMESPACE - -class Handover : public QObject -{ - Q_OBJECT - -public: - explicit Handover(quint16 serverPort, QObject *parent = 0); - ~Handover(); - - QBluetoothAddress bluetoothAddress() const; - quint16 serverPort() const; - -private slots: - void handleNewConnection(); - void remoteDisconnected(); - - void clientDisconnected(); - - void readBluetoothService(); - void sendBluetoothService(); - -signals: - void bluetoothServiceChanged(); - -private: - QLlcpServer *m_server; - QLlcpSocket *m_client; - QLlcpSocket *m_remote; - - QBluetoothAddress m_address; - quint16 m_serverPort; - quint16 m_localServerPort; -}; - -#endif // HANDOVER_H diff --git a/examples/bluetooth/bttennis/main.cpp b/examples/bluetooth/bttennis/main.cpp deleted file mode 100644 index c90807bd..00000000 --- a/examples/bluetooth/bttennis/main.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "tennis.h" - -#include - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - Tennis d; - QObject::connect(&d, SIGNAL(accepted()), &app, SLOT(quit())); - - d.show(); - - app.exec(); - - return 0; -} - diff --git a/examples/bluetooth/bttennis/tennis.cpp b/examples/bluetooth/bttennis/tennis.cpp deleted file mode 100644 index acb58938..00000000 --- a/examples/bluetooth/bttennis/tennis.cpp +++ /dev/null @@ -1,435 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "tennis.h" - -#include -#include -#include - -#include - -#include -#include -#include - -#include "tennisserver.h" -#include "tennisclient.h" -//#include "handover.h" - -#include -#include -#include -#include -#include - -//#include -//#include -//#include - -Tennis::Tennis(QWidget *parent) -: QDialog(parent), ui(new Ui_Tennis), board(new Board), controller(new Controller), socket(0) - //, m_handover(0) -{ - // start Bluetooth if not started - QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); - device->powerOn(); - delete device; - device = 0; - - //Using default Bluetooth adapter - QBluetoothLocalDevice localDevice; - QBluetoothAddress adapterAddress = localDevice.address(); - - /* - * In case of multiple Bluetooth adapters it is possible to - * set which adapter will be used by providing MAC Address. - * Example code: - * - * QBluetoothAddress adapterAddress("XX:XX:XX:XX:XX:XX"); - * m_discoveryAgent = new QBluetoothServiceDiscoveryAgent(adapterAddress); - */ - - m_discoveryAgent = new QBluetoothServiceDiscoveryAgent(adapterAddress, this); - - //! [Construct UI] - ui->setupUi(this); - - isClient = false; - isConnected = false; - quickDiscovery = true; - - ui->pongView->setScene(board->getScene()); - - connect(ui->pongView, SIGNAL(mouseMove(int,int)), this, SLOT(mouseMove(int,int))); - ui->pongView->setMouseTracking(false); - - connect(board, SIGNAL(ballCollision(Board::Edge)), controller, SLOT(ballCollision(Board::Edge))); - connect(board, SIGNAL(scored(Board::Edge)), controller, SLOT(scored(Board::Edge))); - connect(controller, SIGNAL(moveBall(int,int)), board, SLOT(setBall(int,int))); - connect(this, SIGNAL(moveLeftPaddle(int)), board, SLOT(setLeftPaddle(int))); - connect(this, SIGNAL(moveRightPaddle(int)), board, SLOT(setRightPaddle(int))); - connect(controller, SIGNAL(score(int,int)), board, SLOT(setScore(int,int))); - connect(controller, SIGNAL(fps(QString)), this, SLOT(fps(QString))); - - setFocusPolicy(Qt::WheelFocus); - - paddle_pos = (Board::Height-12)/2-Board::Paddle/2; - endPaddlePos = paddle_pos; - - emit moveLeftPaddle(paddle_pos); - board->setRightPaddle(paddle_pos); - - server = new TennisServer(this); - - connect(controller, SIGNAL(moveBall(int,int)), server, SLOT(moveBall(int,int))); - connect(controller, SIGNAL(score(int,int)), server, SLOT(score(int,int))); - connect(this, SIGNAL(moveLeftPaddle(int)), server, SLOT(moveLeftPaddle(int))); - connect(server, SIGNAL(clientConnected(QString)), this, SLOT(serverConnected(QString))); - connect(server, SIGNAL(clientDisconnected(QString)), this, SLOT(serverDisconnected())); - connect(server, SIGNAL(moveRightPaddle(int)), board, SLOT(setRightPaddle(int))); - connect(server, SIGNAL(lag(int)), this, SLOT(lagReport(int))); - - connect(server, SIGNAL(clientConnected(QString)), controller, SLOT(refresh())); - - server->startServer(); - - client = new TennisClient(this); - - connect(client, SIGNAL(moveBall(int,int)), board, SLOT(setBall(int,int))); - connect(client, SIGNAL(moveLeftPaddle(int)), board, SLOT(setLeftPaddle(int))); - connect(client, SIGNAL(connected(QString)), this, SLOT(clientConnected(QString))); - connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); - connect(this, SIGNAL(moveRightPaddle(int)), client, SLOT(moveRightPaddle(int))); - connect(client, SIGNAL(score(int,int)), board, SLOT(setScore(int,int))); - connect(client, SIGNAL(lag(int)), this, SLOT(lagReport(int))); - - connect(this, SIGNAL(moveLeftPaddle(int)), controller, SLOT(moveLeftPaddle(int))); - connect(this, SIGNAL(moveRightPaddle(int)), controller, SLOT(moveRightPaddle(int))); - connect(server, SIGNAL(moveRightPaddle(int)), controller, SLOT(moveRightPaddle(int))); - - -// ui->pongView->setBackgroundBrush(QBrush(Qt::white)); - ui->pongView->setCacheMode(QGraphicsView::CacheBackground); - -/* QNearFieldManager nearFieldManager; - if (nearFieldManager.isAvailable()) { - m_handover = new Handover(server->serverPort(), this); - connect(m_handover, SIGNAL(bluetoothServiceChanged()), this, SLOT(nearFieldHandover())); - - connect(m_discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), - this, SLOT(serviceDiscovered(QBluetoothServiceInfo))); - connect(m_discoveryAgent, SIGNAL(finished()), this, SLOT(discoveryFinished())); - }*/ - - - m_discoveryAgent->setUuidFilter(QBluetoothUuid(serviceUuid)); - - - QString address; - QString port; - QStringList args = QCoreApplication::arguments(); - if (args.length() >= 2){ - address = args.at(1); - if (args.length() >= 3){ - port = args.at(2); - } - } - - if (address.isEmpty()){ - QSettings settings("QtDF", "bttennis"); - address = settings.value("lastclient").toString(); - } - - if (!address.isEmpty()){ - qDebug() << "Connect to" << address << port; - QBluetoothDeviceInfo device = QBluetoothDeviceInfo(QBluetoothAddress(address), "", QBluetoothDeviceInfo::ComputerDevice); - QBluetoothServiceInfo service; - if (!port.isEmpty()) { - QBluetoothServiceInfo::Sequence protocolDescriptorList; - QBluetoothServiceInfo::Sequence protocol; - protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)) - << QVariant::fromValue(port.toUShort()); - protocolDescriptorList.append(QVariant::fromValue(protocol)); - service.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, - protocolDescriptorList); - qDebug() << "port" << port.toUShort() << service.protocolServiceMultiplexer(); - } - else { - service.setServiceUuid(QBluetoothUuid(serviceUuid)); - } - service.setDevice(device); - client->startClient(service); - board->setStatus("Connecting", 100, 25); - } /*else if (nearFieldManager.isAvailable()) { - board->setStatus(tr("Touch to play"), 100, 25); - }*/ - - setEnabled(true); - - paddleAnimation = new QPropertyAnimation(this, "paddlePos", this); - paddleAnimation->setEasingCurve(QEasingCurve::InOutQuad); - - ui->pongView->installEventFilter(this); - -} - -Tennis::~Tennis() -{ -} - -void Tennis::keyPressEvent(QKeyEvent *event) -{ - if (event->matches(QKeySequence::MoveToNextLine)) { - moveDown(); - } - else if (event->matches(QKeySequence::MoveToPreviousLine)){ - moveUp(); - } -} - -void Tennis::wheelEvent(QWheelEvent *event) -{ - if (event->delta() > 0){ - moveUp(); - } - else { - moveDown(); - } -} - -void Tennis::moveUp(int px) -{ - endPaddlePos -= px; - if (endPaddlePos <= 0) - endPaddlePos = 0; - move(endPaddlePos); -} - -void Tennis::moveDown(int px) -{ - endPaddlePos += px; - if (endPaddlePos > Board::Height-Board::Paddle-24) - endPaddlePos = Board::Height-Board::Paddle-24; - move(endPaddlePos); - -} - -void Tennis::move(int px) -{ - int distance = abs(paddle_pos - endPaddlePos); - - paddleAnimation->stop(); - paddleAnimation->setStartValue(paddle_pos); - paddleAnimation->setEndValue(px); - paddleAnimation->setDuration((1000*distance)/350); - paddleAnimation->start(); -} - -void Tennis::setPaddlePos(int p) -{ - paddle_pos = p; - if (isClient) - emit moveRightPaddle(paddle_pos); - else - emit moveLeftPaddle(paddle_pos); -} - - -void Tennis::mouseMove(int x, int y) -{ - if (isConnected == false){ - // look for clicks in the bt connect icon - if (x > 440 && x < 540 && y > 200 && y < 300) { - qDebug() << "Got connect click!"; - if (m_discoveryAgent->isActive()) { - qDebug() << "stopping!"; - m_discoveryAgent->stop(); - board->animateConnect(false); - } - else { - qDebug() << "starting!"; - startDiscovery(); - } - } - - } - y-=12+Board::Paddle/2; - if (y <= 0) - y = 0; - else if (y > Board::Height-Board::Paddle-24) - y = Board::Height-Board::Paddle-24; - - endPaddlePos = y; - move(y); -} - -void Tennis::clientConnected(const QString &name) -{ - board->setStatus("Connected to " + name, 100, 0); - controller->stop(); - server->stopServer(); - isClient = true; - isConnected = true; - board->animateConnect(false); - board->fadeConnect(true); - emit moveRightPaddle(paddle_pos); -} - -void Tennis::clientDisconnected() -{ - board->setStatus("Disconnect", 100, 25); - controller->start(); - server->startServer(); - client->stopClient(); - isClient = false; - isConnected = false; - discoveryFinished(); -} - -void Tennis::serverConnected(const QString &name) -{ - board->setStatus("Server for " + name, 100, 0); - m_discoveryAgent->stop(); - isConnected = true; - board->animateConnect(false); - board->fadeConnect(true); - emit moveLeftPaddle(paddle_pos); -} - -void Tennis::serverDisconnected() -{ - board->setStatus("Disconnected", 100, 25); - isConnected = false; - discoveryFinished(); -} - -void Tennis::serviceDiscovered(const QBluetoothServiceInfo &serviceInfo) -{ - qDebug() << "***** Discovered! " << serviceInfo.device().name() << serviceInfo.serviceName() << serviceInfo.serviceUuid(); - qDebug() << "Found one!" << serviceInfo.protocolServiceMultiplexer(); - m_discoveryAgent->stop(); - client->startClient(serviceInfo); - QSettings settings("QtDF", "bttennis"); - settings.setValue("lastclient", serviceInfo.device().address().toString()); -} - -void Tennis::discoveryFinished() -{ - if (!m_discoveryAgent->isActive()) { - if (!isConnected) { - board->setStatus("Waiting", 100, 25); - // QTimer::singleShot(60000, this, SLOT(startDiscovery())); - board->animateConnect(false); - board->fadeConnect(false); - } - } -} - -void Tennis::startDiscovery() -{ - qDebug() << "startDiscovery() called"; - if (!isConnected) { - qDebug() << "Scanning!"; - board->setStatus("Scanning", 100, 25); - board->fadeConnect(false); - board->animateConnect(true); - m_discoveryAgent->start(QBluetoothServiceDiscoveryAgent::MinimalDiscovery); -// if (quickDiscovery) -// m_discoveryAgent->start(QBluetoothServiceDiscoveryAgent::MinimalDiscovery); -// else -// m_discoveryAgent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery); -// quickDiscovery = !quickDiscovery; - } - else { - qDebug() << "Stop scanning!"; - board->setStatus("", 0, 0); - board->animateConnect(false); - board->fadeConnect(true); - } -} - -void Tennis::resizeEvent(QResizeEvent *re) -{ - if (re->oldSize().height() > 0){ - qreal x, y; - x = (re->size().width())/qreal(re->oldSize().width()); - y = (re->size().height())/qreal(re->oldSize().height()); - ui->pongView->scale(x, y); - } - ui->pongView->resize(re->size()); -} - -void Tennis::lagReport(int ms) -{ - if (ms > 250){ - board->setStatus(QString("Caution Lag %1ms").arg(ms), 100, 0); - } -} - -/*void Tennis::nearFieldHandover() -{ - qDebug() << "Connecting to NFC provided address" << m_handover->bluetoothAddress().toString(); - - QBluetoothDeviceInfo device = QBluetoothDeviceInfo(m_handover->bluetoothAddress(), QString(), - QBluetoothDeviceInfo::ComputerDevice); - - QBluetoothServiceInfo service; - service.setServiceUuid(QBluetoothUuid(serviceUuid)); - service.setDevice(device); - - QBluetoothServiceInfo::Sequence protocolDescriptorList; - QBluetoothServiceInfo::Sequence protocol; - protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)) - << QVariant::fromValue(m_handover->serverPort()); - protocolDescriptorList.append(QVariant::fromValue(protocol)); - service.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, - protocolDescriptorList); - - client->startClient(service); - board->setStatus(tr("Connecting: %1 %2").arg(m_handover->bluetoothAddress().toString()).arg(m_handover->serverPort()), 100, 25); -}*/ - -void Tennis::fps(const QString &f) -{ - board->setStatus(f, 100, 100); -} - diff --git a/examples/bluetooth/bttennis/tennis.h b/examples/bluetooth/bttennis/tennis.h deleted file mode 100644 index 3b684dde..00000000 --- a/examples/bluetooth/bttennis/tennis.h +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "ui_tennis.h" - -#include - -#include -#include -#include -#include -#include -#include - -#include "board.h" -#include "controller.h" - -#include - -QT_FORWARD_DECLARE_CLASS(QBluetoothServiceDiscoveryAgent) - -QT_USE_NAMESPACE - -static const QLatin1String serviceUuid("e8e10f95-1a70-4b27-9ccf-02010264e9c9"); - -class TennisServer; -class TennisClient; -//class Handover; - -//! [declaration] -class Tennis : public QDialog -{ - Q_OBJECT - Q_PROPERTY(int paddlePos READ paddlePos WRITE setPaddlePos) - -public: - Tennis(QWidget *parent = 0); - ~Tennis(); - - int paddlePos() { return paddle_pos; } - void setPaddlePos(int p); - -signals: - void moveLeftPaddle(int y); - void moveRightPaddle(int y); - -protected: - void wheelEvent ( QWheelEvent * event ); - void keyPressEvent ( QKeyEvent * event ); - void resizeEvent(QResizeEvent *); - -private slots: - void serverConnected(const QString &name); - void serverDisconnected(); - - void clientConnected(const QString &name); - void clientDisconnected(); - - void serviceDiscovered(const QBluetoothServiceInfo &serviceInfo); - void discoveryFinished(); - - void startDiscovery(); - - void mouseMove(int x, int y); - - void lagReport(int ms); - -// void nearFieldHandover(); - - void fps(const QString &f); - -private: - - void moveUp(int px = 10); - void moveDown(int px = 10); - - void move(int px); - - Ui_Tennis *ui; - - Board *board; - Controller *controller; - - int paddle_pos; - int endPaddlePos; - - bool isClient; - bool isConnected; - bool quickDiscovery; - - QBluetoothSocket *socket; - TennisServer *server; - TennisClient *client; - - QPropertyAnimation *paddleAnimation; - - QBluetoothServiceDiscoveryAgent *m_discoveryAgent; -// Handover *m_handover; -}; -//! [declaration] diff --git a/examples/bluetooth/bttennis/tennis.qrc b/examples/bluetooth/bttennis/tennis.qrc deleted file mode 100644 index 12aa7464..00000000 --- a/examples/bluetooth/bttennis/tennis.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - connect.png - - diff --git a/examples/bluetooth/bttennis/tennis.ui b/examples/bluetooth/bttennis/tennis.ui deleted file mode 100644 index d6625fa8..00000000 --- a/examples/bluetooth/bttennis/tennis.ui +++ /dev/null @@ -1,57 +0,0 @@ - - - Tennis - - - - 0 - 0 - 640 - 360 - - - - Bluetooth Tennis - - - - - 0 - 0 - 640 - 366 - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - - - - TennisView - QGraphicsView -
tennisview.h
-
-
- - -
diff --git a/examples/bluetooth/bttennis/tennisclient.cpp b/examples/bluetooth/bttennis/tennisclient.cpp deleted file mode 100644 index 080c3a07..00000000 --- a/examples/bluetooth/bttennis/tennisclient.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "tennisclient.h" - -#include - -#include -#include - -#include - -TennisClient::TennisClient(QObject *parent) -: QObject(parent), socket(0), stream(0), elapsed(new QTime), lagTimeout(0) -{ - lagTimer.setInterval(1000); - connect(&lagTimer, SIGNAL(timeout()), this, SLOT(sendEcho())); -} - -TennisClient::~TennisClient() -{ - stopClient(); -} - -//! [startClient] -void TennisClient::startClient(const QBluetoothServiceInfo &remoteService) -{ - if (socket) - return; - - serviceInfo = remoteService; - - // Connect to service - socket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol); - qDebug() << "Create socket"; - socket->connectToService(remoteService); - qDebug() << "ConnecttoService done"; - - connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); - connect(socket, SIGNAL(connected()), this, SLOT(connected())); - connect(socket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); - connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); - connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(error(QBluetoothSocket::SocketError))); - - lagTimer.start(); -} -//! [startClient] - -//! [stopClient] -void TennisClient::stopClient() -{ - if (socket == 0) // already stopped - return; - - qDebug() << Q_FUNC_INFO << "closing client!"; - - lagTimer.stop(); - - delete stream; - stream = 0; - - socket->deleteLater(); - socket = 0; -} -//! [stopClient] - -//! [socketDisconnected] -void TennisClient::socketDisconnected() -{ - qDebug() << "Got socketDisconnected"; - stopClient(); -} -//! [socketDisconnected] - -//! [readSocket] -void TennisClient::readSocket() -{ - if (!socket) - return; - - while (socket->bytesAvailable()) { - QString str; - - *stream >> str; - - QStringList args = str.split(QChar(' ')); - QString s = args.takeFirst(); - - if (s == "m" && args.count() == 2) { - emit moveBall(args.at(0).toInt(), args.at(1).toInt()); - } - else if (s == "s" && args.count() == 2){ - emit score(args.at(0).toInt(), args.at(1).toInt()); - } - else if (s == "l" && args.count() == 1){ - emit moveLeftPaddle(args.at(0).toInt()); - } - else if (s == "e"){ // echo - QByteArray b; - QDataStream s(&b, QIODevice::WriteOnly); - s << str; - socket->write(b); - } - else if (s == "E"){ - lagTimeout = 0; - QTime then = QTime::fromString(args.at(0), "hh:mm:ss.zzz"); - if (then.isValid()) { - emit lag(then.msecsTo(QTime::currentTime())); -// qDebug() << "RTT: " << then.msecsTo(QTime::currentTime()) << "ms"; - } - } - else { - qDebug() << Q_FUNC_INFO << "Unknown command" << str; - } - } -} -//! [readSocket] - -//! [moveRightPaddle] -void TennisClient::moveRightPaddle(int y) -{ - int msec = elapsed->elapsed(); - - if (stream && msec > 50) { - QByteArray b; - QDataStream s(&b, QIODevice::WriteOnly); - s << QString("r %1").arg(y); - socket->write(b); - elapsed->restart(); - } -} -//! [moveRightPaddle] - -//! [connected] -void TennisClient::connected() -{ - stream = new QDataStream(socket); - emit connected(socket->peerName()); -} -//! [connected] - -void TennisClient::error(QBluetoothSocket::SocketError err) -{ - qDebug() << "Got socket error" <write(b); - lagTimeout = 10; - } -} diff --git a/examples/bluetooth/bttennis/tennisclient.h b/examples/bluetooth/bttennis/tennisclient.h deleted file mode 100644 index a6dd232e..00000000 --- a/examples/bluetooth/bttennis/tennisclient.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CHATCLIENT_H -#define CHATCLIENT_H - -#include -#include - -#include -#include -#include - -QT_FORWARD_DECLARE_CLASS(QBluetoothSocket) -QT_FORWARD_DECLARE_CLASS(QDataStream) - -QT_USE_NAMESPACE - -//! [declaration] -class TennisClient : public QObject -{ - Q_OBJECT - -public: - explicit TennisClient(QObject *parent = 0); - ~TennisClient(); - - void startClient(const QBluetoothServiceInfo &remoteService); - void stopClient(); - -public slots: - void moveRightPaddle(int y); - void error(QBluetoothSocket::SocketError); - -signals: - void moveBall(int x, int y); - void score(int left, int right); - void moveLeftPaddle(int y); - - void connected(const QString &name); - void disconnected(); - - void lag(int ms); - -private slots: - void readSocket(); - void connected(); - void sendEcho(); - void socketDisconnected(); - -private: - QBluetoothSocket *socket; - QDataStream *stream; - QBluetoothServiceInfo serviceInfo; - QTime *elapsed; - QTimer lagTimer; - int lagTimeout; -}; -//! [declaration] - -#endif // CHATCLIENT_H diff --git a/examples/bluetooth/bttennis/tennisserver.cpp b/examples/bluetooth/bttennis/tennisserver.cpp deleted file mode 100644 index be6a0370..00000000 --- a/examples/bluetooth/bttennis/tennisserver.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "tennisserver.h" -#include "tennis.h" - -#include -#include - -#include - -TennisServer::TennisServer(QObject *parent) -: QObject(parent), l2capServer(0), clientSocket(0), stream(0), lagReplyTimeout(0) -{ - elapsed.start(); - ballElapsed.start(); - lagTimer.setInterval(1000); - connect(&lagTimer, SIGNAL(timeout()), this, SLOT(sendEcho())); -} - -TennisServer::~TennisServer() -{ - if (stream){ - QByteArray b; - QDataStream s(&b, QIODevice::WriteOnly); - s << QString("D"); - clientSocket->write(b); - } - - stopServer(); -} - -void TennisServer::startServer() -{ - if (l2capServer) - return; - - //! [Create the server] - l2capServer = new QBluetoothServer(QBluetoothServiceInfo::L2capProtocol, this); - connect(l2capServer, SIGNAL(newConnection()), this, SLOT(clientConnected())); - l2capServer->listen(); - //! [Create the server] - - serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010); - - //! [Class ServiceClass must contain at least 1 entry] - QBluetoothServiceInfo::Sequence classId; -// classId << QVariant::fromValue(QBluetoothUuid(serviceUuid)); - classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort)); - serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); - //! [Class ServiceClass must contain at least 1 entry] - - - //! [Service name, description and provider] - serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, tr("Example Tennis Server")); - serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription, - tr("Example bluetooth tennis server")); - serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, tr("Nokia, QtDF")); - //! [Service name, description and provider] - - //! [Service UUID set] - serviceInfo.setServiceUuid(QBluetoothUuid(serviceUuid)); - //! [Service UUID set] - - //! [Service Discoverability] - serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, - QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup)); - //! [Service Discoverability] - - - //! [Protocol descriptor list] - QBluetoothServiceInfo::Sequence protocolDescriptorList; - QBluetoothServiceInfo::Sequence protocol; - protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)) - << QVariant::fromValue(quint16(l2capServer->serverPort())); - protocolDescriptorList.append(QVariant::fromValue(protocol)); - serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, - protocolDescriptorList); - //! [Protocol descriptor list] - - //! [Register service] - serviceInfo.registerService(); - //! [Register service] - -} - -//! [stopServer] -void TennisServer::stopServer() -{ - qDebug() <serverPort(); -} - -//! [moveBall] -void TennisServer::moveBall(int x, int y) -{ - int msec = ballElapsed.elapsed(); - - if (stream && msec > 30){ - QByteArray b; - QDataStream s(&b, QIODevice::WriteOnly); - s << QString("m %1 %2").arg(x).arg(y); - //s << QLatin1String("m") << x << y; - clientSocket->write(b); - ballElapsed.restart(); - } -} -//! [moveBall] - -void TennisServer::score(int left, int right) -{ - if (stream){ - QByteArray b; - QDataStream s(&b, QIODevice::WriteOnly); - s << QString("s %1 %2").arg(left).arg(right); -// s << QChar('s') << left << right; - clientSocket->write(b); - } -} - -void TennisServer::moveLeftPaddle(int y) -{ - - int msec = elapsed.elapsed(); - - if (stream && msec > 50) { - QByteArray b; - QDataStream s(&b, QIODevice::WriteOnly); - s << QString("l %1").arg(y); -// s << QChar('l') << y; - clientSocket->write(b); - elapsed.restart(); - } -} - -void TennisServer::readSocket() -{ - if (!clientSocket) - return; - - while (clientSocket->bytesAvailable()) { - - QString str; - *stream >> str; - QStringList args = str.split(QChar(' ')); - QString s = args.takeFirst(); - - if (s == "r" && args.count() == 1){ - emit moveRightPaddle(args.at(0).toInt()); - } - else if (s == "e" && args.count() == 1){ - lagReplyTimeout = 0; - QTime then = QTime::fromString(args.at(0), "hh:mm:ss.zzz"); - if (then.isValid()) { - emit lag(then.msecsTo(QTime::currentTime())); -// qDebug() << "RTT: " << then.msecsTo(QTime::currentTime()) << "ms"; - } - } - else if (s == "E"){ - QByteArray b; - QDataStream st(&b, QIODevice::WriteOnly); - st << str; - clientSocket->write(b); - } - else if (s == "D"){ - qDebug() << Q_FUNC_INFO << "closing!"; - clientSocket->deleteLater(); - clientSocket = 0; - } - else { - qDebug() << Q_FUNC_INFO << "Unknown command" << str; - } - } -} - -//! [clientConnected] -void TennisServer::clientConnected() -{ - qDebug() << Q_FUNC_INFO << "connect"; - - QBluetoothSocket *socket = l2capServer->nextPendingConnection(); - if (!socket) - return; - - if (clientSocket){ - qDebug() << Q_FUNC_INFO << "Closing socket!"; - delete socket; - return; - } - - connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); - connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); - connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(socketError(QBluetoothSocket::SocketError))); - - stream = new QDataStream(socket); - - clientSocket = socket; - - qDebug() << Q_FUNC_INFO << "started"; - - emit clientConnected(clientSocket->peerName()); - lagTimer.start(); -} -//! [clientConnected] - -void TennisServer::socketError(QBluetoothSocket::SocketError err) -{ - qDebug() << Q_FUNC_INFO << err; -} - -//! [sendEcho] -void TennisServer::sendEcho() -{ - if (lagReplyTimeout) { - lagReplyTimeout--; - return; - } - - if (stream) { - QByteArray b; - QDataStream s(&b, QIODevice::WriteOnly); - s << QString("e %1").arg(QTime::currentTime().toString("hh:mm:ss.zzz")); - clientSocket->write(b); - lagReplyTimeout = 10; - } -} -//! [sendEcho] - -//! [clientDisconnected] -void TennisServer::clientDisconnected() -{ - qDebug() << Q_FUNC_INFO << "client closing!"; - - lagTimer.stop(); - lagReplyTimeout = 0; - QBluetoothSocket *socket = qobject_cast(sender()); - if (!socket) - return; - - emit clientDisconnected(socket->peerName()); - - clientSocket->deleteLater(); - clientSocket = 0; - delete stream; - stream = 0; - -// socket->deleteLater(); -} -//! [clientDisconnected] - diff --git a/examples/bluetooth/bttennis/tennisserver.h b/examples/bluetooth/bttennis/tennisserver.h deleted file mode 100644 index 6bdb13cd..00000000 --- a/examples/bluetooth/bttennis/tennisserver.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef TENNISSERVER_H -#define TENNISSERVER_H - -#include -#include - -#include -#include -#include -#include -#include - -QT_FORWARD_DECLARE_CLASS(QBluetoothServer) -QT_FORWARD_DECLARE_CLASS(QBluetoothSocket) -QT_FORWARD_DECLARE_CLASS(QBluetoothServiceInfo) - -QT_USE_NAMESPACE - -//! [declaration] -class TennisServer : public QObject -{ - Q_OBJECT - -public: - explicit TennisServer(QObject *parent = 0); - ~TennisServer(); - - void startServer(); - void stopServer(); - - quint16 serverPort() const; - -public slots: - void moveBall(int x, int y); - void score(int left, int right); - void moveLeftPaddle(int y); - -signals: - void moveRightPaddle(int y); - void clientDisconnected(const QString &name); - void clientConnected(const QString &name); - void lag(int ms); - -private slots: - void clientConnected(); - void clientDisconnected(); - void readSocket(); - void sendEcho(); - void socketError(QBluetoothSocket::SocketError err); - -private: - QBluetoothServer *l2capServer; - QBluetoothServiceInfo serviceInfo; - QBluetoothSocket *clientSocket; - QDataStream *stream; - QTime elapsed; - QTime ballElapsed; - QTimer lagTimer; - int lagReplyTimeout; -}; -//! [declaration] - -#endif // CHATSERVER_H diff --git a/examples/bluetooth/bttennis/tennisview.cpp b/examples/bluetooth/bttennis/tennisview.cpp deleted file mode 100644 index 3ec75b84..00000000 --- a/examples/bluetooth/bttennis/tennisview.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "tennisview.h" - -#include - -TennisView::TennisView(QWidget *parent) : - QGraphicsView(parent) -{ -} - -void TennisView::mousePressEvent(QMouseEvent *event) -{ - QPointF p = mapToScene(event->x(), event->y()); - emit mousePress(p.x(), p.y()); - emit mouseMove(p.x(), p.y()); - last_y = p.y(); -} - -void TennisView::mouseMoveEvent(QMouseEvent *event) -{ - if (event->buttons()) { - QPointF p = mapToScene(event->x(), event->y()); - if (10 < abs(last_y - event->y())) { -// emit mouseMove(p.x(), p.y()); - last_y = p.y(); - } - } -} diff --git a/examples/bluetooth/bttennis/tennisview.h b/examples/bluetooth/bttennis/tennisview.h deleted file mode 100644 index 4f7f0027..00000000 --- a/examples/bluetooth/bttennis/tennisview.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef TENNISVIEW_H -#define TENNISVIEW_H - -#include - -class TennisView : public QGraphicsView -{ - Q_OBJECT -public: - explicit TennisView(QWidget *parent = 0); - -signals: - void mouseMove(int x, int y); - void mousePress(int x, int y); - -public slots: - -protected: - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *ev); - -private: - int last_y; - -}; - -#endif // TENNISVIEW_H diff --git a/src/bluetooth/doc/src/bluetooth-index.qdoc b/src/bluetooth/doc/src/bluetooth-index.qdoc index 078596cd..fe9322e9 100644 --- a/src/bluetooth/doc/src/bluetooth-index.qdoc +++ b/src/bluetooth/doc/src/bluetooth-index.qdoc @@ -82,7 +82,6 @@ import statement in your \c .qml file: \list \li \l {btchat}{Bluetooth Chat} \li \l {btscanner}{Bluetooth Scanner} - \li \l {bttennis}{Bluetooth Tennis} \li \l {btfiletransfer}{Bluetooth File Transfer} \endlist \endlist diff --git a/src/bluetooth/doc/src/examples.qdoc b/src/bluetooth/doc/src/examples.qdoc index 5ddb1ea3..f9965075 100644 --- a/src/bluetooth/doc/src/examples.qdoc +++ b/src/bluetooth/doc/src/examples.qdoc @@ -1,9 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the documentation of the Qt local connectivty modules. +** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:FDL$ ** Commercial License Usage @@ -45,18 +45,14 @@ \li Example \li Description \row - \li \l{bttennis}{Bluetooth Tennis} - \li The classic game of \l {http://en.wikipedia.org/wiki/Pong}{Pong}. Supports multiplayer - over Bluetooth and touch-to-play functionality on devices that support NFC. + \li \l{btchat}{Bluetooth Chat} + \li Simple chat server and client via Bluetooth. \row \li \l{btfiletransfer}{Bluetooth File Transfer} \li Transfer files between Bluetooth devices. \row \li \l{btscanner}{Bluetooth Scanner} \li Scan for Bluetooth devices. - \row - \li \l{pingpong}{QML Bluetooth PingPong} - \li The ping pong game demonstrates Bluetooth socket communication between two devices. \endtable \section2 QML Examples @@ -65,9 +61,8 @@ \li Example \li Description \row - \li \l{bttennis}{QML Bluetooth Tennis} - \li The tennis game using a QML interface to the Bluetooth API. It - must connect to an instance of the C++ \l{bttennis}{Bluetooth Tennis} game to play. + \li \l{pingpong}{QML Bluetooth PingPong} + \li A QML ping pong game demonstrating Bluetooth socket communication between two devices. \row \li \l{scanner}{QML Bluetooth Scanner} \li A QML implementation of the Bluetooth device scanner. -- cgit v1.2.3