diff options
author | Jerome Pasion <jerome.pasion@digia.com> | 2012-09-25 15:20:41 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-09-27 14:43:52 +0200 |
commit | d8a179128c0fa8e9cc482df58b9334c696602be6 (patch) | |
tree | dd5032440aa87dfd63c973265adc9947db0918f6 /examples/nfc/annotatedurl | |
parent | 9d89c661395347bdda9362a77d38c86ad60f486b (diff) |
Qt Bluetooth: Modularized documentation
-moved documentation to src/bluetooth/doc
-added a qdocconf file for Qt Bluetooth
-fixed relative paths for snippets
-moved examples to examples/bluetooth
Change-Id: Id41bac50dca628400568d191f1c3ccfbaac790a1
Reviewed-by: Alex <ablasche@gmail.com>
Diffstat (limited to 'examples/nfc/annotatedurl')
-rw-r--r-- | examples/nfc/annotatedurl/annotatedurl.cpp | 119 | ||||
-rw-r--r-- | examples/nfc/annotatedurl/annotatedurl.h | 73 | ||||
-rw-r--r-- | examples/nfc/annotatedurl/annotatedurl.pro | 15 | ||||
-rw-r--r-- | examples/nfc/annotatedurl/doc/images/annotatedurl.png | bin | 0 -> 34341 bytes | |||
-rw-r--r-- | examples/nfc/annotatedurl/doc/src/annotatedurl.qdoc | 37 | ||||
-rw-r--r-- | examples/nfc/annotatedurl/main.cpp | 80 | ||||
-rw-r--r-- | examples/nfc/annotatedurl/mainwindow.cpp | 72 | ||||
-rw-r--r-- | examples/nfc/annotatedurl/mainwindow.h | 70 | ||||
-rw-r--r-- | examples/nfc/annotatedurl/mainwindow.ui | 61 |
9 files changed, 527 insertions, 0 deletions
diff --git a/examples/nfc/annotatedurl/annotatedurl.cpp b/examples/nfc/annotatedurl/annotatedurl.cpp new file mode 100644 index 00000000..f13f3235 --- /dev/null +++ b/examples/nfc/annotatedurl/annotatedurl.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtNfc module. +** +** $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 Digia Plc 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 "annotatedurl.h" + +#include <qnearfieldtarget.h> +#include <qndefmessage.h> +#include <qndefrecord.h> +#include <qndefnfctextrecord.h> +#include <qndefnfcurirecord.h> + +#include <QtCore/QUrl> +#include <QtCore/QLocale> + +#include <QGridLayout> +#include <QLabel> +#include <QMouseEvent> +#include <QDesktopServices> + +AnnotatedUrl::AnnotatedUrl(QObject *parent) +: QObject(parent) +{ +} + +AnnotatedUrl::~AnnotatedUrl() +{ +} + +void AnnotatedUrl::handleMessage(const QNdefMessage &message, QNearFieldTarget *target) +{ + Q_UNUSED(target); + + enum { + MatchedNone, + MatchedFirst, + MatchedEnglish, + MatchedLanguage, + MatchedLanguageAndCountry + } bestMatch = MatchedNone; + + QLocale defaultLocale; + + QString title; + QUrl url; + QPixmap pixmap; + + foreach (const QNdefRecord &record, message) { + if (record.isRecordType<QNdefNfcTextRecord>()) { + QNdefNfcTextRecord textRecord(record); + + QLocale locale(textRecord.locale()); + + // already found best match + if (bestMatch == MatchedLanguageAndCountry) { + // do nothing + } else if (bestMatch <= MatchedLanguage && locale == defaultLocale) { + title = textRecord.text(); + bestMatch = MatchedLanguageAndCountry; + } else if (bestMatch <= MatchedEnglish && + locale.language() == defaultLocale.language()) { + title = textRecord.text(); + bestMatch = MatchedLanguage; + } else if (bestMatch <= MatchedFirst && locale.language() == QLocale::English) { + title = textRecord.text(); + bestMatch = MatchedEnglish; + } else if (bestMatch == MatchedNone) { + title = textRecord.text(); + bestMatch = MatchedFirst; + } + } else if (record.isRecordType<QNdefNfcUriRecord>()) { + QNdefNfcUriRecord uriRecord(record); + + url = uriRecord.uri(); + } else if (record.typeNameFormat() == QNdefRecord::Mime && + record.type().startsWith("image/")) { + pixmap = QPixmap::fromImage(QImage::fromData(record.payload())); + } + } + + emit annotatedUrl(url, title, pixmap); +} + diff --git a/examples/nfc/annotatedurl/annotatedurl.h b/examples/nfc/annotatedurl/annotatedurl.h new file mode 100644 index 00000000..490539a2 --- /dev/null +++ b/examples/nfc/annotatedurl/annotatedurl.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtNfc module. +** +** $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 Digia Plc 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 ANNOTATEDURL_H +#define ANNOTATEDURL_H + +#include <qnfcglobal.h> + +#include <QtCore/QObject> + +QT_FORWARD_DECLARE_CLASS(QUrl) +QT_FORWARD_DECLARE_CLASS(QPixmap) + +QTNFC_BEGIN_NAMESPACE +class QNearFieldTarget; +class QNdefMessage; +QTNFC_END_NAMESPACE + +QTNFC_USE_NAMESPACE + +class AnnotatedUrl : public QObject +{ + Q_OBJECT + +public: + explicit AnnotatedUrl(QObject *parent = 0); + ~AnnotatedUrl(); + +signals: + void annotatedUrl(const QUrl &url, const QString &title, const QPixmap &pixmap); + +public slots: + void handleMessage(const QNdefMessage &message, QNearFieldTarget *target); +}; + +#endif // ANNOTATEDURL_H diff --git a/examples/nfc/annotatedurl/annotatedurl.pro b/examples/nfc/annotatedurl/annotatedurl.pro new file mode 100644 index 00000000..65ed7c8d --- /dev/null +++ b/examples/nfc/annotatedurl/annotatedurl.pro @@ -0,0 +1,15 @@ +QT += nfc widgets + +CONFIG += strict_flags + +TARGET = annotatedurl + +SOURCES += main.cpp \ + mainwindow.cpp \ + annotatedurl.cpp + +HEADERS += mainwindow.h \ + annotatedurl.h + +FORMS += mainwindow.ui + diff --git a/examples/nfc/annotatedurl/doc/images/annotatedurl.png b/examples/nfc/annotatedurl/doc/images/annotatedurl.png Binary files differnew file mode 100644 index 00000000..71739f50 --- /dev/null +++ b/examples/nfc/annotatedurl/doc/images/annotatedurl.png diff --git a/examples/nfc/annotatedurl/doc/src/annotatedurl.qdoc b/examples/nfc/annotatedurl/doc/src/annotatedurl.qdoc new file mode 100644 index 00000000..7aa706b6 --- /dev/null +++ b/examples/nfc/annotatedurl/doc/src/annotatedurl.qdoc @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2012 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 annotatedurl +\title Annotated URL Example + +The Annotated URL example displays the contents of specifically formated NDEF messages read from +an NFC Tag. The NDEF message should contain a URI record, an optional image/* MIME record and one +or more localized Text records. + +\image annotatedurl.png +*/ diff --git a/examples/nfc/annotatedurl/main.cpp b/examples/nfc/annotatedurl/main.cpp new file mode 100644 index 00000000..65be03c5 --- /dev/null +++ b/examples/nfc/annotatedurl/main.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtNfc module. +** +** $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 Digia Plc 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 "annotatedurl.h" +#include "mainwindow.h" + +#include <qnearfieldmanager.h> +#include <qndefnfctextrecord.h> +#include <qndefnfcurirecord.h> + +#include <QtCore/QLocale> + +#include <QApplication> + + +int main(int argc, char *argv[]) +{ + //QLocale::setDefault(QLocale(QLocale::Japanese)); + + QApplication a(argc, argv); + MainWindow mainWindow; + + QNearFieldManager manager; + AnnotatedUrl annotatedUrl; + + QNdefFilter filter; + filter.setOrderMatch(false); + filter.appendRecord<QNdefNfcTextRecord>(1, UINT_MAX); + filter.appendRecord<QNdefNfcUriRecord>(); + manager.registerNdefMessageHandler(filter, &annotatedUrl, + SLOT(handleMessage(QNdefMessage,QNearFieldTarget*))); + + QObject::connect(&annotatedUrl, SIGNAL(annotatedUrl(QUrl,QString,QPixmap)), + &mainWindow, SLOT(displayAnnotatedUrl(QUrl,QString,QPixmap))); + +#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_6) || defined(Q_WS_MEEGO) + mainWindow.showFullScreen(); +#else + mainWindow.show(); +#endif + + return a.exec(); +} diff --git a/examples/nfc/annotatedurl/mainwindow.cpp b/examples/nfc/annotatedurl/mainwindow.cpp new file mode 100644 index 00000000..7045a5dc --- /dev/null +++ b/examples/nfc/annotatedurl/mainwindow.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtNfc module. +** +** $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 Digia Plc 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 "mainwindow.h" +#include "ui_mainwindow.h" + +#include <QtCore/QUrl> +#include <QtGui/QMouseEvent> +#include <QtGui/QDesktopServices> + +MainWindow::MainWindow(QWidget *parent) +: QMainWindow(parent), ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::displayAnnotatedUrl(const QUrl &url, const QString &title, const QPixmap &pixmap) +{ + ui->m_help->setHidden(true); + + ui->m_url->setText(url.toString()); + ui->m_title->setText(title); + ui->m_image->setPixmap(pixmap); +} + +void MainWindow::mouseReleaseEvent(QMouseEvent *event) +{ + if (ui->centralWidget->rect().contains(event->pos())) + QDesktopServices::openUrl(QUrl(ui->m_url->text())); +} diff --git a/examples/nfc/annotatedurl/mainwindow.h b/examples/nfc/annotatedurl/mainwindow.h new file mode 100644 index 00000000..0786f8aa --- /dev/null +++ b/examples/nfc/annotatedurl/mainwindow.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtNfc module. +** +** $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 Digia Plc 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 MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +QT_FORWARD_DECLARE_CLASS(QUrl) + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +public slots: + void displayAnnotatedUrl(const QUrl &url, const QString &title, const QPixmap &pixmap); + +protected: + void mouseReleaseEvent(QMouseEvent *event); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/examples/nfc/annotatedurl/mainwindow.ui b/examples/nfc/annotatedurl/mainwindow.ui new file mode 100644 index 00000000..26e3b302 --- /dev/null +++ b/examples/nfc/annotatedurl/mainwindow.ui @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>590</width> + <height>420</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QGridLayout" name="gridLayout" rowstretch="1,0,1" columnstretch="0,0,0"> + <item row="0" column="1" colspan="2"> + <widget class="QLabel" name="m_title"> + <property name="font"> + <font> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="0" column="0" rowspan="3"> + <widget class="QLabel" name="m_image"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="m_help"> + <property name="text"> + <string>Touch a tag</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="2" column="1" colspan="2"> + <widget class="QLabel" name="m_url"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections/> +</ui> |