diff options
Diffstat (limited to 'examples/tools')
-rw-r--r-- | examples/tools/customtype/customtype.pro | 3 | ||||
-rw-r--r-- | examples/tools/customtype/main.cpp | 74 | ||||
-rw-r--r-- | examples/tools/customtype/message.cpp | 90 | ||||
-rw-r--r-- | examples/tools/customtype/message.h | 76 | ||||
-rw-r--r-- | examples/tools/customtypesending/customtypesending.pro | 5 | ||||
-rw-r--r-- | examples/tools/customtypesending/main.cpp | 68 | ||||
-rw-r--r-- | examples/tools/customtypesending/message.cpp | 72 | ||||
-rw-r--r-- | examples/tools/customtypesending/message.h | 72 | ||||
-rw-r--r-- | examples/tools/customtypesending/window.cpp | 80 | ||||
-rw-r--r-- | examples/tools/customtypesending/window.h | 73 |
10 files changed, 613 insertions, 0 deletions
diff --git a/examples/tools/customtype/customtype.pro b/examples/tools/customtype/customtype.pro new file mode 100644 index 0000000..3079964 --- /dev/null +++ b/examples/tools/customtype/customtype.pro @@ -0,0 +1,3 @@ +HEADERS = message.h +SOURCES = main.cpp \ + message.cpp diff --git a/examples/tools/customtype/main.cpp b/examples/tools/customtype/main.cpp new file mode 100644 index 0000000..e8f4265 --- /dev/null +++ b/examples/tools/customtype/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QCoreApplication> +#include <QVariant> +#include "message.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + QStringList headers; + headers << "Subject: Hello World" + << "From: qt-info@nokia.com"; + QString body = "This is a test.\r\n"; + +//! [printing a custom type] + Message message(body, headers); + qDebug() << "Original:" << message; +//! [printing a custom type] + +//! [storing a custom value] + QVariant stored; + stored.setValue(message); +//! [storing a custom value] + + qDebug() << "Stored:" << stored; + +//! [retrieving a custom value] + Message retrieved = stored.value<Message>(); + qDebug() << "Retrieved:" << retrieved; + retrieved = qVariantValue<Message>(stored); + qDebug() << "Retrieved:" << retrieved; +//! [retrieving a custom value] + + return 0; +} diff --git a/examples/tools/customtype/message.cpp b/examples/tools/customtype/message.cpp new file mode 100644 index 0000000..b6fd536 --- /dev/null +++ b/examples/tools/customtype/message.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "message.h" + +//! [Message class implementation] +Message::Message() +{ +} + +Message::Message(const Message &other) +{ + m_body = other.m_body; + m_headers = other.m_headers; +} + +Message::~Message() +{ +} +//! [Message class implementation] + +Message::Message(const QString &body, const QStringList &headers) +{ + m_body = body; + m_headers = headers; +} + +//! [custom type streaming operator] +QDebug &operator<<(QDebug &dbg, const Message &message) +{ + QStringList pieces = message.body().split("\r\n", QString::SkipEmptyParts); + if (pieces.isEmpty()) + dbg.nospace() << "Message()"; + else if (pieces.size() == 1) + dbg.nospace() << "Message(" << pieces.first() << ")"; + else + dbg.nospace() << "Message(" << pieces.first() << " ...)"; + return dbg.maybeSpace(); +} +//! [custom type streaming operator] + +//! [getter functions] +QString Message::body() const +{ + return m_body; +} + +QStringList Message::headers() const +{ + return m_headers; +} +//! [getter functions] diff --git a/examples/tools/customtype/message.h b/examples/tools/customtype/message.h new file mode 100644 index 0000000..2620557 --- /dev/null +++ b/examples/tools/customtype/message.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MESSAGE_H +#define MESSAGE_H + +#include <QDebug> +#include <QMetaType> +#include <QStringList> + +//! [custom type definition] +class Message +{ +public: + Message(); + Message(const Message &other); + ~Message(); + + Message(const QString &body, const QStringList &headers); + + QString body() const; + QStringList headers() const; + +private: + QString m_body; + QStringList m_headers; +}; +//! [custom type definition] + +//! [custom type meta-type declaration] +Q_DECLARE_METATYPE(Message); +//! [custom type meta-type declaration] + +//! [custom type streaming operator] +QDebug &operator<<(QDebug &dbg, const Message &message); +//! [custom type streaming operator] + +#endif diff --git a/examples/tools/customtypesending/customtypesending.pro b/examples/tools/customtypesending/customtypesending.pro new file mode 100644 index 0000000..b8b2aaf --- /dev/null +++ b/examples/tools/customtypesending/customtypesending.pro @@ -0,0 +1,5 @@ +HEADERS = message.h \ + window.h +SOURCES = main.cpp \ + message.cpp \ + window.cpp diff --git a/examples/tools/customtypesending/main.cpp b/examples/tools/customtypesending/main.cpp new file mode 100644 index 0000000..336f3d8 --- /dev/null +++ b/examples/tools/customtypesending/main.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include "message.h" +#include "window.h" + +//! [main function] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + Window window1; + QStringList headers; + headers << "Subject: Hello World" + << "From: qt-info@nokia.com"; + QString body = "This is a test.\r\n"; + Message message(body, headers); + window1.setMessage(message); + + Window window2; + QObject::connect(&window1, SIGNAL(messageSent(Message)), + &window2, SLOT(setMessage(Message))); + QObject::connect(&window2, SIGNAL(messageSent(Message)), + &window1, SLOT(setMessage(Message))); + window1.show(); + window2.show(); + return app.exec(); +} +//! [main function] diff --git a/examples/tools/customtypesending/message.cpp b/examples/tools/customtypesending/message.cpp new file mode 100644 index 0000000..6992804 --- /dev/null +++ b/examples/tools/customtypesending/message.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "message.h" + +Message::Message() +{ +} + +Message::Message(const Message &other) +{ + m_body = other.m_body; + m_headers = other.m_headers; +} + +Message::~Message() +{ +} + +Message::Message(const QString &body, const QStringList &headers) +{ + m_body = body; + m_headers = headers; +} + +QString Message::body() const +{ + return m_body; +} + +QStringList Message::headers() const +{ + return m_headers; +} diff --git a/examples/tools/customtypesending/message.h b/examples/tools/customtypesending/message.h new file mode 100644 index 0000000..55f9568 --- /dev/null +++ b/examples/tools/customtypesending/message.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MESSAGE_H +#define MESSAGE_H + +#include <QDebug> +#include <QMetaType> +#include <QStringList> + +//! [custom type definition] +class Message +{ +public: + Message(); + Message(const Message &other); + ~Message(); + + Message(const QString &body, const QStringList &headers); + + QString body() const; + QStringList headers() const; + +private: + QString m_body; + QStringList m_headers; +}; +//! [custom type definition] + +//! [custom type meta-type declaration] +Q_DECLARE_METATYPE(Message); +//! [custom type meta-type declaration] + +#endif diff --git a/examples/tools/customtypesending/window.cpp b/examples/tools/customtypesending/window.cpp new file mode 100644 index 0000000..be79518 --- /dev/null +++ b/examples/tools/customtypesending/window.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include "window.h" + +//! [Window constructor] +Window::Window() +{ + editor = new QTextEdit(); + QPushButton *sendButton = new QPushButton(tr("&Send message")); + + connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMessage())); + + QHBoxLayout *buttonLayout = new QHBoxLayout(); + buttonLayout->addStretch(); + buttonLayout->addWidget(sendButton); + buttonLayout->addStretch(); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(editor); + layout->addLayout(buttonLayout); + + setWindowTitle(tr("Custom Type Sending")); +} +//! [Window constructor] + +//! [sending a message] +void Window::sendMessage() +{ + thisMessage = Message(editor->toPlainText(), thisMessage.headers()); + emit messageSent(thisMessage); +} +//! [sending a message] + +//! [receiving a message] +void Window::setMessage(const Message &message) +{ + thisMessage = message; + editor->setPlainText(thisMessage.body()); +} +//! [receiving a message] diff --git a/examples/tools/customtypesending/window.h b/examples/tools/customtypesending/window.h new file mode 100644 index 0000000..cbe9775 --- /dev/null +++ b/examples/tools/customtypesending/window.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> +#include "message.h" + +class QTextEdit; + +//! [Window class definition] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(); + +signals: + void messageSent(const Message &message); + +public slots: + void setMessage(const Message &message); + +private slots: + void sendMessage(); + +private: + Message thisMessage; + QTextEdit *editor; +}; +//! [Window class definition] + +#endif |