diff options
author | Marius Storm-Olsen <marius.storm-olsen@nokia.com> | 2012-05-10 09:11:17 +0200 |
---|---|---|
committer | Marius Storm-Olsen <marius.storm-olsen@nokia.com> | 2012-05-10 09:11:23 +0200 |
commit | 9456528aac80c6d4c41fa96d88696dc55414b710 (patch) | |
tree | f9fdcc9cd3c7468503590bec7ed082294a0cffde /src | |
parent | 75552c8f62dcfb8012c306b37c79ec629448d780 (diff) | |
parent | ee38dec6f3aff6f7f277323c5c8488d4cd385693 (diff) |
Merge branch 'docs-refactoring' into master
Change-Id: Iebd1966abace3cdf7f9428dcfc1ded5b124ab113
Diffstat (limited to 'src')
1108 files changed, 45537 insertions, 912 deletions
diff --git a/src/concurrent/concurrent.pro b/src/concurrent/concurrent.pro index 6bf16e6a0a..54359f7d3b 100644 --- a/src/concurrent/concurrent.pro +++ b/src/concurrent/concurrent.pro @@ -57,6 +57,9 @@ HEADERS += \ qfutureinterface_p.h \ qfuturewatcher_p.h +QMAKE_DOCS = $$PWD/doc/qtconcurrent.qdocconf +QMAKE_DOCS_INDEX = ../../doc + contains(QT_CONFIG, clock-gettime) { linux-*|hpux-*|solaris-*:LIBS *= -lrt } diff --git a/src/concurrent/doc/qtconcurrent.qdocconf b/src/concurrent/doc/qtconcurrent.qdocconf new file mode 100644 index 0000000000..d8d66a92c9 --- /dev/null +++ b/src/concurrent/doc/qtconcurrent.qdocconf @@ -0,0 +1,92 @@ +include(../../../doc/global/qt-cpp-ignore.qdocconf) + +project = QtConcurrent +description = Qt Concurrent Reference Documentation +url = http://qt-project.org/doc/qt-5.0/qtconcurrent +version = 5.0.0 + +sourceencoding = UTF-8 +outputencoding = UTF-8 +naturallanguage = en_US +qhp.projects = QtConcurrent + +qhp.QtConcurrent.file = qtconcurrent.qhp +qhp.QtConcurrent.namespace = org.qt-project.qtconcurrent.500 +qhp.QtConcurrent.virtualFolder = qdoc +qhp.QtConcurrent.indexTitle = Qt Concurrent Reference Documentation +qhp.QtConcurrent.indexRoot = + +qhp.QtConcurrent.filterAttributes = qtconcurrent 5.0.0 qtrefdoc +qhp.QtConcurrent.customFilters.Qt.name = QtConcurrent 5.0.0 +qhp.QtConcurrent.customFilters.Qt.filterAttributes = qtconcurrent 5.0.0 +qhp.QtConcurrent.subprojects = classes overviews examples +qhp.QtConcurrent.subprojects.classes.title = Classes +qhp.QtConcurrent.subprojects.classes.indexTitle = Qt Concurrent's Classes +qhp.QtConcurrent.subprojects.classes.selectors = class fake:headerfile +qhp.QtConcurrent.subprojects.classes.sortPages = true +qhp.QtConcurrent.subprojects.overviews.title = Overviews +qhp.QtConcurrent.subprojects.overviews.indexTitle = All Overviews and HOWTOs +qhp.QtConcurrent.subprojects.overviews.selectors = fake:page,group,module +qhp.QtConcurrent.subprojects.examples.title = Qt Concurrent Examples +qhp.QtConcurrent.subprojects.examples.indexTitle = Qt Concurrent Examples +qhp.QtConcurrent.subprojects.examples.selectors = fake:example + +dita.metadata.default.author = Qt Project +dita.metadata.default.permissions = all +dita.metadata.default.publisher = Qt Project +dita.metadata.default.copyryear = 2012 +dita.metadata.default.copyrholder = Nokia +dita.metadata.default.audience = programmer + +sources.fileextensions = "*.c++ *.cc *.cpp *.cxx *.mm *.qml *.qdoc" +headers.fileextensions = "*.ch *.h *.h++ *.hh *.hpp *.hxx" + +examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml *.css" +examples.imageextensions = "*.png" + +outputdir = ../../../doc/qtconcurrent +tagfile = ../../../doc/qtconcurrent/qtconcurrent.tags + +HTML.generatemacrefs = "true" +HTML.nobreadcrumbs = "true" + +HTML.templatedir = . + +HTML.stylesheets = ../../../doc/global/style/offline.css + +HTML.headerstyles = \ + " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/offline.css\" />\n" + +HTML.endheader = \ + "</head>\n" \ + +defines = Q_QDOC \ + QT_.*_SUPPORT \ + QT_.*_LIB \ + QT_COMPAT \ + QT_KEYPAD_NAVIGATION \ + QT_NO_EGL \ + Q_WS_.* \ + Q_OS_.* \ + Q_BYTE_ORDER \ + QT_DEPRECATED \ + QT_DEPRECATED_* \ + Q_NO_USING_KEYWORD \ + __cplusplus \ + Q_COMPILER_INITIALIZER_LISTS + +versionsym = QT_VERSION_STR + +codeindent = 1 + +depends += qtcore + +headerdirs += .. + +sourcedirs += .. + +exampledirs += ../../../examples \ + ../ \ + snippets + +imagedirs += images diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qfuture.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qfuture.cpp new file mode 100644 index 0000000000..ddf075b6ca --- /dev/null +++ b/src/concurrent/doc/snippets/code/src_concurrent_qfuture.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QFuture<QString> future = ...; + +QFuture<QString>::const_iterator i; +for (i = future.constBegin(); i != future.constEnd(); ++i) + cout << *i << endl; +//! [0] + + +//! [1] +QFuture<QString> future; +... +QFutureIterator<QString> i(future); +while (i.hasNext()) + qDebug() << i.next(); +//! [1] + + +//! [2] +QFutureIterator<QString> i(future); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [2] diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qfuturesynchronizer.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qfuturesynchronizer.cpp new file mode 100644 index 0000000000..77003791e9 --- /dev/null +++ b/src/concurrent/doc/snippets/code/src_concurrent_qfuturesynchronizer.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +void someFunction() +{ + QFutureSynchronizer<void> synchronizer; + + ... + + synchronizer.addFuture(QtConcurrent::run(anotherFunction)); + synchronizer.addFuture(QtConcurrent::map(list, mapFunction)); + + return; // QFutureSynchronizer waits for all futures to finish +} +//! [0] diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qfuturewatcher.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qfuturewatcher.cpp new file mode 100644 index 0000000000..703275bc7a --- /dev/null +++ b/src/concurrent/doc/snippets/code/src_concurrent_qfuturewatcher.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +// Instantiate the objects and connect to the finished signal. +MyClass myObject; +QFutureWatcher<int> watcher; +connect(&watcher, SIGNAL(finished()), &myObject, SLOT(handleFinished())); + +// Start the computation. +QFuture<int> future = QtConcurrent::run(...); +watcher.setFuture(future); +//! [0] diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentexception.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentexception.cpp new file mode 100644 index 0000000000..cf0257c45b --- /dev/null +++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentexception.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + +class MyException : public QtConcurrent::Exception +{ +public: + void raise() const { throw *this; } + Exception *clone() const { return new MyException(*this); } +}; + +//! [0] + + +//! [1] + +try { + QtConcurrent::blockingMap(list, throwFunction); // throwFunction throws MyException +} catch (MyException &e) { + // handle exception +} + +//! [1] + + +//! [2] + +void MyException::raise() const { throw *this; } + +//! [2] + + +//! [3] + +MyException *MyException::clone() const { return new MyException(*this); } + +//! [3] diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp new file mode 100644 index 0000000000..2acf467e9a --- /dev/null +++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp @@ -0,0 +1,171 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +bool function(const T &t); +//! [0] + + +//! [1] +bool allLowerCase(const QString &string) +{ + return string.lowered() == string; +} + +QStringList strings = ...; +QFuture<QString> lowerCaseStrings = QtConcurrent::filtered(strings, allLowerCase); +//! [1] + + +//! [2] +QStringList strings = ...; +QFuture<void> future = QtConcurrent::filter(strings, allLowerCase); +//! [2] + + +//! [3] +V function(T &result, const U &intermediate) +//! [3] + + +//! [4] +void addToDictionary(QSet<QString> &dictionary, const QString &string) +{ + dictionary.insert(string); +} + +QStringList strings = ...; +QFuture<QSet<QString> > dictionary = QtConcurrent::filteredReduced(strings, allLowerCase, addToDictionary); +//! [4] + + +//! [5] +QStringList strings = ...; +QFuture<QString> lowerCaseStrings = QtConcurrent::filtered(strings.constBegin(), strings.constEnd(), allLowerCase); + +// filter in-place only works on non-const iterators +QFuture<void> future = QtConcurrent::filter(strings.begin(), strings.end(), allLowerCase); + +QFuture<QSet<QString> > dictionary = QtConcurrent::filteredReduced(strings.constBegin(), strings.constEnd(), allLowerCase, addToDictionary); +//! [5] + + +//! [6] +QStringList strings = ...; + +// each call blocks until the entire operation is finished +QStringList lowerCaseStrings = QtConcurrent::blockingFiltered(strings, allLowerCase); + + +QtConcurrent::blockingFilter(strings, allLowerCase); + +QSet<QString> dictionary = QtConcurrent::blockingFilteredReduced(strings, allLowerCase, addToDictionary); +//! [6] + + +//! [7] +// keep only images with an alpha channel +QList<QImage> images = ...; +QFuture<void> alphaImages = QtConcurrent::filter(strings, &QImage::hasAlphaChannel); + +// keep only gray scale images +QList<QImage> images = ...; +QFuture<QImage> grayscaleImages = QtConcurrent::filtered(images, &QImage::isGrayscale); + +// create a set of all printable characters +QList<QChar> characters = ...; +QFuture<QSet<QChar> > set = QtConcurrent::filteredReduced(characters, &QChar::isPrint, &QSet<QChar>::insert); +//! [7] + + +//! [8] +// can mix normal functions and member functions with QtConcurrent::filteredReduced() + +// create a dictionary of all lower cased strings +extern bool allLowerCase(const QString &string); +QStringList strings = ...; +QFuture<QSet<int> > averageWordLength = QtConcurrent::filteredReduced(strings, allLowerCase, QSet<QString>::insert); + +// create a collage of all gray scale images +extern void addToCollage(QImage &collage, const QImage &grayscaleImage); +QList<QImage> images = ...; +QFuture<QImage> collage = QtConcurrent::filteredReduced(images, &QImage::isGrayscale, addToCollage); +//! [8] + + +//! [9] +bool QString::contains(const QRegExp ®exp) const; +//! [9] + + +//! [10] +boost::bind(&QString::contains, QRegExp("^\\S+$")); // matches strings without whitespace +//! [10] + + +//! [11] +bool contains(const QString &string) +//! [11] + + +//! [12] +QStringList strings = ...; +boost::bind(static_cast<bool(QString::*)(const QRegExp&)>( &QString::contains ), QRegExp("..." )); +//! [12] + +//! [13] +struct StartsWith +{ + StartsWith(const QString &string) + : m_string(string) { } + + typedef bool result_type; + + bool operator()(const QString &testString) + { + return testString.startsWith(m_string); + } + + QString m_string; +}; + +QList<QString> strings = ...; +QFuture<QString> fooString = QtConcurrent::filtered(images, StartsWith(QLatin1String("Foo"))); +//! [13] diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp new file mode 100644 index 0000000000..9b83ad5bef --- /dev/null +++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +U function(const T &t); +//! [0] + + +//! [1] +QImage scaled(const QImage &image) +{ + return image.scaled(100, 100); +} + +QList<QImage> images = ...; +QFuture<QImage> thumbnails = QtConcurrent::mapped(images, scaled); +//! [1] + + +//! [2] +U function(T &t); +//! [2] + + +//! [3] +void scale(QImage &image) +{ + image = image.scaled(100, 100); +} + +QList<QImage> images = ...; +QFuture<void> future = QtConcurrent::map(images, scale); +//! [3] + + +//! [4] +V function(T &result, const U &intermediate) +//! [4] + + +//! [5] +void addToCollage(QImage &collage, const QImage &thumbnail) +{ + QPainter p(&collage); + static QPoint offset = QPoint(0, 0); + p.drawImage(offset, thumbnail); + offset += ...; +} + +QList<QImage> images = ...; +QFuture<QImage> collage = QtConcurrent::mappedReduced(images, scaled, addToCollage); +//! [5] + + +//! [6] +QList<QImage> images = ...; + +QFuture<QImage> thumbnails = QtConcurrent::mapped(images.constBegin(), images.constEnd(), scaled); + +// map in-place only works on non-const iterators +QFuture<void> future = QtConcurrent::map(images.begin(), images.end(), scale); + +QFuture<QImage> collage = QtConcurrent::mappedReduced(images.constBegin(), images.constEnd(), scaled, addToCollage); +//! [6] + + +//! [7] +QList<QImage> images = ...; + +// each call blocks until the entire operation is finished +QList<QImage> future = QtConcurrent::blockingMapped(images, scaled); + +QtConcurrent::blockingMap(images, scale); + +QImage collage = QtConcurrent::blockingMappedReduced(images, scaled, addToCollage); +//! [7] + + +//! [8] +// squeeze all strings in a QStringList +QStringList strings = ...; +QFuture<void> squeezedStrings = QtConcurrent::map(strings, &QString::squeeze); + +// swap the rgb values of all pixels on a list of images +QList<QImage> images = ...; +QFuture<QImage> bgrImages = QtConcurrent::mapped(images, &QImage::rgbSwapped); + +// create a set of the lengths of all strings in a list +QStringList strings = ...; +QFuture<QSet<int> > wordLengths = QtConcurrent::mappedReduced(string, &QString::length, &QSet<int>::insert); +//! [8] + + +//! [9] +// can mix normal functions and member functions with QtConcurrent::mappedReduced() + +// compute the average length of a list of strings +extern void computeAverage(int &average, int length); +QStringList strings = ...; +QFuture<int> averageWordLength = QtConcurrent::mappedReduced(strings, &QString::length, computeAverage); + +// create a set of the color distribution of all images in a list +extern int colorDistribution(const QImage &string); +QList<QImage> images = ...; +QFuture<QSet<int> > totalColorDistribution = QtConcurrent::mappedReduced(images, colorDistribution, QSet<int>::insert); +//! [9] + + +//! [10] +QImage QImage::scaledToWidth(int width, Qt::TransformationMode) const; +//! [10] + + +//! [11] +boost::bind(&QImage::scaledToWidth, 100, Qt::SmoothTransformation) +//! [11] + + +//! [12] +QImage scaledToWith(const QImage &image) +//! [12] + + +//! [13] +QList<QImage> images = ...; +QFuture<QImage> thumbnails = QtConcurrent::mapped(images, boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation)); +//! [13] + +//! [14] +struct Scaled +{ + Scaled(int size) + : m_size(size) { } + + typedef QImage result_type; + + QImage operator()(const QImage &image) + { + return image.scaled(m_size, m_size); + } + + int m_size; +}; + +QList<QImage> images = ...; +QFuture<QImage> thumbnails = QtConcurrent::mapped(images, Scaled(100)); +//! [14] diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentrun.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentrun.cpp new file mode 100644 index 0000000000..362f084092 --- /dev/null +++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentrun.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +extern void aFunction(); +QFuture<void> future = QtConcurrent::run(aFunction); +//! [0] + + +//! [1] +extern void aFunctionWithArguments(int arg1, double arg2, const QString &string); + +int integer = ...; +double floatingPoint = ...; +QString string = ...; + +QFuture<void> future = QtConcurrent::run(aFunctionWithArguments, integer, floatingPoint, string); +//! [1] + + +//! [2] +extern QString functionReturningAString(); +QFuture<QString> future = QtConcurrent::run(functionReturningAString); +... +QString result = future.result(); +//! [2] + + +//! [3] +extern QString someFunction(const QByteArray &input); + +QByteArray bytearray = ...; + +QFuture<QString> future = QtConcurrent::run(someFunction, bytearray); +... +QString result = future.result(); +//! [3] + +//! [4] +// call 'QList<QByteArray> QByteArray::split(char sep) const' in a separate thread +QByteArray bytearray = "hello world"; +QFuture<QList<QByteArray> > future = QtConcurrent::run(bytearray, &QByteArray::split, ','); +... +QList<QByteArray> result = future.result(); +//! [4] + +//! [5] +// call 'void QImage::invertPixels(InvertMode mode)' in a separate thread +QImage image = ...; +QFuture<void> future = QtConcurrent::run(&image, &QImage::invertPixels, QImage::InvertRgba); +... +future.waitForFinished(); +// At this point, the pixels in 'image' have been inverted +//! [5] + + +//! [6] +void someFunction(int arg1, double arg2); +QFuture<void> future = QtConcurrent::run(boost::bind(someFunction, 1, 2.0)); +... +//! [6] diff --git a/src/concurrent/qfuture.cpp b/src/concurrent/qfuture.cpp index 9805454cb2..f8151f3228 100644 --- a/src/concurrent/qfuture.cpp +++ b/src/concurrent/qfuture.cpp @@ -374,7 +374,7 @@ QFuture::constBegin() or QFuture::constEnd() before you start iterating. Here's a typical loop that prints all the results available in a future: - \snippet doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp 0 + \snippet code/src_concurrent_qfuture.cpp 0 \sa QFutureIterator, QFuture */ @@ -555,7 +555,7 @@ list (i.e. before the first result). Here's how to iterate over all the results sequentially: - \snippet doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp 1 + \snippet code/src_concurrent_qfuture.cpp 1 The next() function returns the next result (waiting for it to become available, if necessary) from the future and advances the iterator. Unlike @@ -570,7 +570,7 @@ Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp 2 + \snippet code/src_concurrent_qfuture.cpp 2 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. diff --git a/src/concurrent/qfuturesynchronizer.cpp b/src/concurrent/qfuturesynchronizer.cpp index 34b00daf4f..3bb81e06c4 100644 --- a/src/concurrent/qfuturesynchronizer.cpp +++ b/src/concurrent/qfuturesynchronizer.cpp @@ -57,7 +57,7 @@ an easy way to ensure that all futures have finished before returning from a function: - \snippet doc/src/snippets/code/src_corelib_concurrent_qfuturesynchronizer.cpp 0 + \snippet code/src_concurrent_qfuturesynchronizer.cpp 0 The behavior of waitForFinished() can be changed using the setCancelOnWait() function. Calling setCancelOnWait(true) will cause diff --git a/src/concurrent/qfuturewatcher.cpp b/src/concurrent/qfuturewatcher.cpp index 9153fe5d40..eb5fb0e18d 100644 --- a/src/concurrent/qfuturewatcher.cpp +++ b/src/concurrent/qfuturewatcher.cpp @@ -86,7 +86,7 @@ QT_BEGIN_NAMESPACE Example: Starting a computation and getting a slot callback when it's finished: - \snippet doc/src/snippets/code/src_corelib_concurrent_qfuturewatcher.cpp 0 + \snippet code/src_concurrent_qfuturewatcher.cpp 0 Be aware that not all asynchronous computations can be canceled or paused. For example, the future returned by QtConcurrent::run() cannot be diff --git a/src/concurrent/qtconcurrentexception.cpp b/src/concurrent/qtconcurrentexception.cpp index 57eb604d39..a13ddb3173 100644 --- a/src/concurrent/qtconcurrentexception.cpp +++ b/src/concurrent/qtconcurrentexception.cpp @@ -56,12 +56,12 @@ QT_BEGIN_NAMESPACE boundaries, provided that the exception inherit from QtConcurrent::Exception and implement two helper functions: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp 0 + \snippet code/src_concurrent_qtconcurrentexception.cpp 0 QtConcurrent::Exception subclasses must be thrown by value and caught by reference: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp 1 + \snippet code/src_concurrent_qtconcurrentexception.cpp 1 If you throw an exception that is not a subclass of QtConcurrent::Exception, the Qt Concurrent functions will throw a QtConcurrent::UnhandledException @@ -80,14 +80,14 @@ QT_BEGIN_NAMESPACE \fn QtConcurrent::Exception::raise() const In your QtConcurrent::Exception subclass, reimplement raise() like this: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp 2 + \snippet code/src_concurrent_qtconcurrentexception.cpp 2 */ /*! \fn QtConcurrent::Exception::clone() const In your QtConcurrent::Exception subclass, reimplement clone() like this: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp 3 + \snippet code/src_concurrent_qtconcurrentexception.cpp 3 */ /*! diff --git a/src/concurrent/qtconcurrentfilter.cpp b/src/concurrent/qtconcurrentfilter.cpp index 76ce8ca659..8a87af2868 100644 --- a/src/concurrent/qtconcurrentfilter.cpp +++ b/src/concurrent/qtconcurrentfilter.cpp @@ -60,7 +60,7 @@ result instead of a QFuture. You use them in the same way as the asynchronous variants. - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 6 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 6 Note that the result types above are not QFuture objects, but real result types (in this case, QStringList and QSet<QString>). @@ -73,7 +73,7 @@ The filter function must be of the form: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 0 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 0 T must match the type stored in the sequence. The function returns true if the item should be kept, false if it should be discarded. @@ -81,7 +81,7 @@ This example shows how to keep strings that are all lower-case from a QStringList: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 1 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 1 The results of the filter are made available through QFuture. See the QFuture and QFutureWatcher documentation for more information on how to @@ -89,7 +89,7 @@ If you want to modify a sequence in-place, use QtConcurrent::filter(): - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 2 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 2 Since the sequence is modified in place, QtConcurrent::filter() does not return any results via QFuture. However, you can still use QFuture and @@ -103,7 +103,7 @@ The reduce function must be of the form: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 3 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 3 T is the type of the final result, U is the type of items being filtered. Note that the return value and return type of the reduce function are not @@ -111,7 +111,7 @@ Call QtConcurrent::filteredReduced() like this: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 4 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 4 The reduce function will be called once for each result kept by the filter function, and should merge the \e{intermediate} into the \e{result} @@ -128,7 +128,7 @@ instead of a sequence. You use them in the same way as the sequence variants: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 5 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 5 \section2 Using Member Functions @@ -137,12 +137,12 @@ QtConcurrent::filteredReduced() accept pointers to member functions. The member function class type must match the type stored in the sequence: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 7 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 7 Note that when using QtConcurrent::filteredReduced(), you can mix the use of normal and member functions freely: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 8 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 8 \section2 Using Function Objects @@ -151,7 +151,7 @@ add state to a function call. The result_type typedef must define the result type of the function call operator: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 13 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 13 \section2 Using Bound Function Arguments @@ -167,7 +167,7 @@ As an example, we use QString::contains(): - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 9 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 9 QString::contains() takes 2 arguments (including the "this" pointer) and can't be used with QtConcurrent::filtered() directly, because @@ -175,17 +175,17 @@ use QString::contains() with QtConcurrent::filtered() we have to provide a value for the \e regexp argument: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 10 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 10 The return value from boost::bind() is a function object (functor) with the following signature: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 11 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 11 This matches what QtConcurrent::filtered() expects, and the complete example becomes: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 12 + \snippet code/src_concurrent_qtconcurrentfilter.cpp 12 */ /*! diff --git a/src/concurrent/qtconcurrentmap.cpp b/src/concurrent/qtconcurrentmap.cpp index 1758cb9e95..c446064327 100644 --- a/src/concurrent/qtconcurrentmap.cpp +++ b/src/concurrent/qtconcurrentmap.cpp @@ -95,7 +95,7 @@ the final result instead of a QFuture. You use them in the same way as the asynchronous variants. - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 7 + \snippet code/src_concurrent_qtconcurrentmap.cpp 7 Note that the result types above are not QFuture objects, but real result types (in this case, QList<QImage> and QImage). @@ -108,7 +108,7 @@ The map function must be of the form: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 0 + \snippet code/src_concurrent_qtconcurrentmap.cpp 0 T and U can be any type (and they can even be the same type), but T must match the type stored in the sequence. The function returns the modified @@ -117,7 +117,7 @@ This example shows how to apply a scale function to all the items in a sequence: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 1 + \snippet code/src_concurrent_qtconcurrentmap.cpp 1 The results of the map are made available through QFuture. See the QFuture and QFutureWatcher documentation for more information on how to @@ -126,14 +126,14 @@ If you want to modify a sequence in-place, use QtConcurrent::map(). The map function must then be of the form: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 2 + \snippet code/src_concurrent_qtconcurrentmap.cpp 2 Note that the return value and return type of the map function are not used. Using QtConcurrent::map() is similar to using QtConcurrent::mapped(): - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 3 + \snippet code/src_concurrent_qtconcurrentmap.cpp 3 Since the sequence is modified in place, QtConcurrent::map() does not return any results via QFuture. However, you can still use QFuture and @@ -147,7 +147,7 @@ The reduce function must be of the form: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 4 + \snippet code/src_concurrent_qtconcurrentmap.cpp 4 T is the type of the final result, U is the return type of the map function. Note that the return value and return type of the reduce @@ -155,7 +155,7 @@ Call QtConcurrent::mappedReduced() like this: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 5 + \snippet code/src_concurrent_qtconcurrentmap.cpp 5 The reduce function will be called once for each result returned by the map function, and should merge the \e{intermediate} into the \e{result} @@ -175,7 +175,7 @@ instead of a sequence. You use them in the same way as the sequence variants: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 6 + \snippet code/src_concurrent_qtconcurrentmap.cpp 6 \section2 Blocking Variants @@ -183,7 +183,7 @@ the final result instead of a QFuture. You use them in the same way as the asynchronous variants. - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 7 + \snippet code/src_concurrent_qtconcurrentmap.cpp 7 Note that the result types above are not QFuture objects, but real result types (in this case, QList<QImage> and QImage). @@ -194,12 +194,12 @@ QtConcurrent::mappedReduced() accept pointers to member functions. The member function class type must match the type stored in the sequence: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 8 + \snippet code/src_concurrent_qtconcurrentmap.cpp 8 Note that when using QtConcurrent::mappedReduced(), you can mix the use of normal and member functions freely: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 9 + \snippet code/src_concurrent_qtconcurrentmap.cpp 9 \section2 Using Function Objects @@ -208,7 +208,7 @@ add state to a function call. The result_type typedef must define the result type of the function call operator: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 14 + \snippet code/src_concurrent_qtconcurrentmap.cpp 14 \section2 Using Bound Function Arguments @@ -224,7 +224,7 @@ As an example, we'll use QImage::scaledToWidth(): - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 10 + \snippet code/src_concurrent_qtconcurrentmap.cpp 10 scaledToWidth takes three arguments (including the "this" pointer) and can't be used with QtConcurrent::mapped() directly, because @@ -232,17 +232,17 @@ QImage::scaledToWidth() with QtConcurrent::mapped() we have to provide a value for the \e{width} and the \e{transformation mode}: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 11 + \snippet code/src_concurrent_qtconcurrentmap.cpp 11 The return value from boost::bind() is a function object (functor) with the following signature: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 12 + \snippet code/src_concurrent_qtconcurrentmap.cpp 12 This matches what QtConcurrent::mapped() expects, and the complete example becomes: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 13 + \snippet code/src_concurrent_qtconcurrentmap.cpp 13 */ /*! diff --git a/src/concurrent/qtconcurrentrun.cpp b/src/concurrent/qtconcurrentrun.cpp index 656ecf7370..2cf46ac5a1 100644 --- a/src/concurrent/qtconcurrentrun.cpp +++ b/src/concurrent/qtconcurrentrun.cpp @@ -57,7 +57,7 @@ To run a function in another thread, use QtConcurrent::run(): - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 0 + \snippet code/src_concurrent_qtconcurrentrun.cpp 0 This will run \e aFunction in a separate thread obtained from the default QThreadPool. You can use the QFuture and QFutureWatcher classes to monitor @@ -68,7 +68,7 @@ Passing arguments to the function is done by adding them to the QtConcurrent::run() call immediately after the function name. For example: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 1 + \snippet code/src_concurrent_qtconcurrentrun.cpp 1 A copy of each argument is made at the point where QtConcurrent::run() is called, and these values are passed to the thread when it begins executing @@ -79,11 +79,11 @@ Any return value from the function is available via QFuture: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 2 + \snippet code/src_concurrent_qtconcurrentrun.cpp 2 As documented above, passing arguments is done like this: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 3 + \snippet code/src_concurrent_qtconcurrentrun.cpp 3 Note that the QFuture::result() function blocks and waits for the result to become available. Use QFutureWatcher to get notification when the @@ -102,11 +102,11 @@ For example, calling QByteArray::split() (a const member function) in a separate thread is done like this: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 4 + \snippet code/src_concurrent_qtconcurrentrun.cpp 4 Calling a non-const member function is done like this: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 5 + \snippet code/src_concurrent_qtconcurrentrun.cpp 5 \section2 Using Bound Function Arguments @@ -131,7 +131,7 @@ Calling a bound function is done like this: - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 6 + \snippet code/src_concurrent_qtconcurrentrun.cpp 6 */ /*! diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro index d98cebb672..4856c1b5fb 100644 --- a/src/corelib/corelib.pro +++ b/src/corelib/corelib.pro @@ -16,6 +16,9 @@ load(qt_module_config) HEADERS += $$QT_SOURCE_TREE/src/corelib/qtcoreversion.h +QMAKE_DOCS = $$PWD/doc/qtcore.qdocconf +QMAKE_DOCS_INDEX = ../../doc + include(animation/animation.pri) include(arch/arch.pri) include(global/global.pri) @@ -30,7 +33,6 @@ include(codecs/codecs.pri) include(statemachine/statemachine.pri) include(mimetypes/mimetypes.pri) include(xml/xml.pri) -include(doc/doc.pri) mac|darwin { !ios { diff --git a/src/corelib/doc/doc.pri b/src/corelib/doc/doc.pri deleted file mode 100644 index ed970d7592..0000000000 --- a/src/corelib/doc/doc.pri +++ /dev/null @@ -1,3 +0,0 @@ -qtPrepareTool(QDOC, qdoc) -docs.commands += $$QDOC $$QT.core.sources/doc/qtcore.qdocconf -QMAKE_EXTRA_TARGETS += docs diff --git a/src/corelib/doc/images/resources.png b/src/corelib/doc/images/resources.png Binary files differnew file mode 100644 index 0000000000..eb7af96d77 --- /dev/null +++ b/src/corelib/doc/images/resources.png diff --git a/src/corelib/doc/snippets/code/doc_src_resources.cpp b/src/corelib/doc/snippets/code/doc_src_resources.cpp new file mode 100644 index 0000000000..f401add728 --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_resources.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [4] +QResource::registerResource("/path/to/myresource.rcc"); +//! [4] + + +//! [5] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Q_INIT_RESOURCE(graphlib); + ... + return app.exec(); +} +//! [5] diff --git a/src/corelib/doc/snippets/code/doc_src_resources.qdoc b/src/corelib/doc/snippets/code/doc_src_resources.qdoc new file mode 100644 index 0000000000..c51dbbcbf3 --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_resources.qdoc @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +<file alias="cut-img.png">images/cut.png</file> +//! [0] + + +//! [1] +<qresource prefix="/myresources"> + <file alias="cut-img.png">images/cut.png</file> +</qresource> +//! [1] + + +//! [2] +<qresource> + <file>cut.jpg</file> +</qresource> +<qresource lang="fr"> + <file alias="cut.jpg">cut_fr.jpg</file> +</qresource> +//! [2] + + +//! [3] +rcc -binary myresource.qrc -o myresource.rcc +//! [3] diff --git a/src/corelib/doc/src/io.qdoc b/src/corelib/doc/src/io.qdoc new file mode 100644 index 0000000000..dfe9be2b3c --- /dev/null +++ b/src/corelib/doc/src/io.qdoc @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \group io + \title Input/Output and Networking + \ingroup groups + + \brief Classes providing file input and output along with directory and + network handling. + + These classes are used to handle input and output to and from external + devices, processes, files etc. as well as manipulating files and directories. +*/ + diff --git a/src/corelib/doc/src/resource-system.qdoc b/src/corelib/doc/src/resource-system.qdoc new file mode 100644 index 0000000000..89a099a1c1 --- /dev/null +++ b/src/corelib/doc/src/resource-system.qdoc @@ -0,0 +1,202 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page resources.html + \title The Qt Resource System + \ingroup qt-network + \brief A platform-independent mechanism for storing binary files in an application. + + \keyword resource system + + The Qt resource system is a platform-independent mechanism for + storing binary files in the application's executable. This is + useful if your application always needs a certain set of files + (icons, translation files, etc.) and you don't want to run the + risk of losing the files. + + The resource system is based on tight cooperation between \l qmake, + \l rcc (Qt's resource compiler), and QFile. It obsoletes Qt 3's + \c qembed tool and the + \l{http://qt.nokia.com/doc/qq/qq05-iconography.html#imagestorage}{image + collection} mechanism. + + \section1 Resource Collection Files (\c{.qrc}) + + The resources associated with an application are specified in a + \c .qrc file, an XML-based file format that lists files on the + disk and optionally assigns them a resource name that the + application must use to access the resource. + + Here's an example \c .qrc file: + + \quotefile mainwindows/application/application.qrc + + The resource files listed in the \c .qrc file are files that are + part of the application's source tree. The specified paths are + relative to the directory containing the \c .qrc file. Note that + the listed resource files must be located in the same directory as + the \c .qrc file, or one of its subdirectories. + + Resource data can either be compiled into the binary and thus accessed + immediately in application code, or a binary resource can be created + and at a later point in application code registered with the resource + system. + + By default, resources are accessible in the application under the + same file name as they have in the source tree, with a \c :/ prefix, + or by a \link QUrl URL\endlink with a \c qrc scheme. + + For example, the file path \c :/images/cut.png or the URL + \c qrc:///images/cut.png would give access to the + \c cut.png file, whose location in the application's source tree + is \c images/cut.png. This can be changed using the \c file tag's + \c alias attribute: + + \snippet code/doc_src_resources.qdoc 0 + + The file is then accessible as \c :/cut-img.png from the + application. It is also possible to specify a path prefix for all + files in the \c .qrc file using the \c qresource tag's \c prefix + attribute: + + \snippet code/doc_src_resources.qdoc 1 + + In this case, the file is accessible as \c + :/myresources/cut-img.png. + + Some resources need to change based on the user's locale, + such as translation files or icons. This is done by adding a \c lang + attribute to the \c qresource tag, specifying a suitable locale + string. For example: + + \snippet code/doc_src_resources.qdoc 2 + + If the user's locale is French (i.e., QLocale::system().name() returns + "fr_FR"), \c :/cut.jpg becomes a reference to the \c cut_fr.jpg + image. For other locales, \c cut.jpg is used. + + See the QLocale documentation for a description of the format to use + for locale strings. + + + \section2 External Binary Resources + + For an external binary resource to be created you must create the resource + data (commonly given the \c .rcc extension) by passing the -binary switch to + \l rcc. Once the binary resource is created you can register the resource + with the QResource API. + + For example, a set of resource data specified in a \c .qrc file can be + compiled in the following way: + + \snippet code/doc_src_resources.qdoc 3 + + In the application, this resource would be registered with code like this: + + \snippet code/doc_src_resources.cpp 4 + + \section2 Compiled-In Resources + + For a resource to be compiled into the binary the \c .qrc file must be + mentioned in the application's \c .pro file so that \c qmake knows + about it. For example: + + \snippet mainwindows/application/application.pro 0 + + \c qmake will produce make rules to generate a file called \c + qrc_application.cpp that is linked into the application. This + file contains all the data for the images and other resources as + static C++ arrays of compressed binary data. The \c + qrc_application.cpp file is automatically regenerated whenever + the \c .qrc file changes or one of the files that it refers to + changes. If you don't use \c .pro files, you can either invoke + \c rcc manually or add build rules to your build system. + + \image resources.png Building resources into an application + + Currently, Qt always stores the data directly in the executable, + even on Windows and Mac OS X, where the operating system provides + native support for resources. This might change in a future Qt + release. + + \section1 Compression + + Resources are compressed by default (in the \c ZIP format). It is + possible to turn off compression. This can be useful if your + resources already contain a compressed format, such as \c .png + files. You do this by giving the \c {-no-compress} command line + argument. + + \code + rcc -no-compress myresources.qrc + \endcode + + \c rcc also gives you some control over the compression. You can + specify the compression level and the threshold level to consider + while compressing files, for example: + + \code + rcc -compress 2 -threshold 3 myresources.qrc + \endcode + + \section1 Using Resources in the Application + + In the application, resource paths can be used in most places + instead of ordinary file system paths. In particular, you can + pass a resource path instead of a file name to the QIcon, QImage, + or QPixmap constructor: + + \snippet mainwindows/application/mainwindow.cpp 21 + + See the \l{mainwindows/application}{Application} example for an + actual application that uses Qt's resource system to store its + icons. + + In memory, resources are represented by a tree of resource + objects. The tree is automatically built at startup and used by + QFile for resolving paths to resources. You can use a QDir initialized + with ":/" to navigate through the resource tree from the root. + + Qt's resources support the concept of a search path list. If you then + refer to a resource with \c : instead of \c :/ as the prefix, the + resource will be looked up using the search path list. The search + path list is empty at startup; call QDir::addSearchPath() to + add paths to it. + + If you have resources in a static library, you might need to + force initialization of your resources by calling \l + Q_INIT_RESOURCE() with the base name of the \c .qrc file. For + example: + + \snippet code/doc_src_resources.cpp 5 + + Similarly, if you must unload a set of resources explicitly + (because a plugin is being unloaded or the resources are not valid + any longer), you can force removal of your resources by calling + Q_CLEANUP_RESOURCE() with the same base name as above. +*/ diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 52ffae5f98..ed845745be 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -737,7 +737,7 @@ void qWinMessageHandler2(QtMsgType t, const QMessageLogContext &context, This is a typedef for a pointer to a function with the following signature: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 7 + \snippet code/src_corelib_global_qglobal.cpp 7 This typedef is deprecated, you should use QtMessageHandler instead. \sa QtMsgType, QtMessageHandler, qInstallMsgHandler(), qInstallMessageHandler() @@ -751,7 +751,7 @@ void qWinMessageHandler2(QtMsgType t, const QMessageLogContext &context, This is a typedef for a pointer to a function with the following signature: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 49 + \snippet code/src_corelib_global_qglobal.cpp 49 \sa QtMsgType, qInstallMessageHandler() */ @@ -785,7 +785,7 @@ void qWinMessageHandler2(QtMsgType t, const QMessageLogContext &context, Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 23 + \snippet code/src_corelib_global_qglobal.cpp 23 \sa QtMessageHandler, QtMsgType, qDebug(), qWarning(), qCritical(), qFatal(), {Debugging Techniques} diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp index 17eedb0bdd..e1f1db9ead 100644 --- a/src/corelib/io/qfiledevice.cpp +++ b/src/corelib/io/qfiledevice.cpp @@ -146,12 +146,12 @@ void QFileDevicePrivate::setError(QFileDevice::FileError err, int errNum) handling considerably. It is possible to force permission checking on NTFS by including the following code in your source: - \snippet doc/src/snippets/ntfsp.cpp 0 + \snippet ntfsp.cpp 0 Permission checking is then turned on and off by incrementing and decrementing \c qt_ntfs_permission_lookup by 1. - \snippet doc/src/snippets/ntfsp.cpp 1 + \snippet ntfsp.cpp 1 */ //************* QFileDevice diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp index 2e2db11558..5625aebd3c 100644 --- a/src/corelib/io/qurlquery.cpp +++ b/src/corelib/io/qurlquery.cpp @@ -511,7 +511,7 @@ QString QUrlQuery::query(QUrl::ComponentFormattingOptions encoding) const If \a valueDelimiter is set to '(' and \a pairDelimiter is ')', the above query string would instead be represented like this: - \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 4 + \snippet code/src_corelib_io_qurl.cpp 4 \note Non-standard delimiters should be chosen from among what RFC 3986 calls "sub-delimiters". They are: diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 10dcff92c7..3172014363 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -838,7 +838,7 @@ void QHashData::checkSanity() operator==() and a qHash() implementation. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 13 + \snippet code/src_corelib_tools_qhash.cpp 13 In the example above, we've relied on Qt's global qHash(const QString &, uint) to give us a hash value for the employee's name, and diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index c25d326b9d..0b0aeb50c0 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -404,8 +404,8 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegExp &r For example: - \snippet doc/src/snippets/qstringlist/main.cpp 5 - \snippet doc/src/snippets/qstringlist/main.cpp 16 + \snippet qstringlist/main.cpp 5 + \snippet qstringlist/main.cpp 16 For regular expressions that contain capturing groups, occurrences of \b{\\1}, \b{\\2}, ..., in \a after are @@ -413,8 +413,8 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegExp &r For example: - \snippet doc/src/snippets/qstringlist/main.cpp 5 - \snippet doc/src/snippets/qstringlist/main.cpp 17 + \snippet qstringlist/main.cpp 5 + \snippet qstringlist/main.cpp 17 */ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegularExpression &re, const QString &after) { diff --git a/src/dbus/dbus.pro b/src/dbus/dbus.pro index 100736252e..b1a3e12e1f 100644 --- a/src/dbus/dbus.pro +++ b/src/dbus/dbus.pro @@ -35,6 +35,9 @@ load(qt_module_config) HEADERS += $$QT_SOURCE_TREE/src/dbus/qtdbusversion.h +QMAKE_DOCS = $$PWD/doc/qtdbus.qdocconf +QMAKE_DOCS_INDEX = ../../doc + PUB_HEADERS = qdbusargument.h \ qdbusconnectioninterface.h \ qdbusmacros.h \ diff --git a/src/dbus/doc/qtdbus.qdocconf b/src/dbus/doc/qtdbus.qdocconf new file mode 100644 index 0000000000..d33c4370a3 --- /dev/null +++ b/src/dbus/doc/qtdbus.qdocconf @@ -0,0 +1,92 @@ +include(../../../doc/global/qt-cpp-ignore.qdocconf) + +project = QtDBus +description = Qt DBus Reference Documentation +url = http://qt-project.org/doc/qt-5.0/qtdbus +version = 5.0.0 + +sourceencoding = UTF-8 +outputencoding = UTF-8 +naturallanguage = en_US +qhp.projects = QtDBus + +qhp.QtDBus.file = qtdbus.qhp +qhp.QtDBus.namespace = org.qt-project.qtdbus.500 +qhp.QtDBus.virtualFolder = qdoc +qhp.QtDBus.indexTitle = Qt DBus Reference Documentation +qhp.QtDBus.indexRoot = + +qhp.QtDBus.filterAttributes = qtdbus 5.0.0 qtrefdoc +qhp.QtDBus.customFilters.Qt.name = QtDBus 5.0.0 +qhp.QtDBus.customFilters.Qt.filterAttributes = qtdbus 5.0.0 +qhp.QtDBus.subprojects = classes overviews examples +qhp.QtDBus.subprojects.classes.title = Classes +qhp.QtDBus.subprojects.classes.indexTitle = Qt DBus' Classes +qhp.QtDBus.subprojects.classes.selectors = class fake:headerfile +qhp.QtDBus.subprojects.classes.sortPages = true +qhp.QtDBus.subprojects.overviews.title = Overviews +qhp.QtDBus.subprojects.overviews.indexTitle = All Overviews and HOWTOs +qhp.QtDBus.subprojects.overviews.selectors = fake:page,group,module +qhp.QtDBus.subprojects.examples.title = Qt DBus Examples +qhp.QtDBus.subprojects.examples.indexTitle = Qt DBus Examples +qhp.QtDBus.subprojects.examples.selectors = fake:example + +dita.metadata.default.author = Qt Project +dita.metadata.default.permissions = all +dita.metadata.default.publisher = Qt Project +dita.metadata.default.copyryear = 2012 +dita.metadata.default.copyrholder = Nokia +dita.metadata.default.audience = programmer + +sources.fileextensions = "*.c++ *.cc *.cpp *.cxx *.mm *.qml *.qdoc" +headers.fileextensions = "*.ch *.h *.h++ *.hh *.hpp *.hxx" + +examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml *.css" +examples.imageextensions = "*.png" + +outputdir = ../../../doc/qtdbus +tagfile = ../../../doc/qtdbus/qtdbus.tags + +HTML.generatemacrefs = "true" +HTML.nobreadcrumbs = "true" + +HTML.templatedir = . + +HTML.stylesheets = ../../../doc/global/style/offline.css + +HTML.headerstyles = \ + " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/offline.css\" />\n" + +HTML.endheader = \ + "</head>\n" \ + +defines = Q_QDOC \ + QT_.*_SUPPORT \ + QT_.*_LIB \ + QT_COMPAT \ + QT_KEYPAD_NAVIGATION \ + QT_NO_EGL \ + Q_WS_.* \ + Q_OS_.* \ + Q_BYTE_ORDER \ + QT_DEPRECATED \ + QT_DEPRECATED_* \ + Q_NO_USING_KEYWORD \ + __cplusplus \ + Q_COMPILER_INITIALIZER_LISTS + +versionsym = QT_VERSION_STR + +codeindent = 1 + +depends += qtcore + +headerdirs += .. + +sourcedirs += .. + +exampledirs += ../../../examples \ + ../ \ + snippets + +imagedirs += images diff --git a/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc b/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc new file mode 100644 index 0000000000..5d8833cb16 --- /dev/null +++ b/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +org.freedesktop.DBus +//! [0] + +//! [QDBUS_DEBUG] +examples/dbus/remotecontrolledcar/controller/controller & +QDBUS_DEBUG=1 examples/dbus/remotecontrolledcar/car/car & +//! [QDBUS_DEBUG] diff --git a/src/dbus/doc/snippets/code/doc_src_qdbusadaptors.cpp b/src/dbus/doc/snippets/code/doc_src_qdbusadaptors.cpp new file mode 100644 index 0000000000..279c10f1e6 --- /dev/null +++ b/src/dbus/doc/snippets/code/doc_src_qdbusadaptors.cpp @@ -0,0 +1,293 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MainApplicationAdaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.DBus.MainApplication") + Q_PROPERTY(QString caption READ caption WRITE setCaption) + Q_PROPERTY(QString organizationName READ organizationName) + Q_PROPERTY(QString organizationDomain READ organizationDomain) + +private: + QApplication *app; + +public: + MainApplicationAdaptor(QApplication *application) + : QDBusAbstractAdaptor(application), app(application) + { + connect(application, SIGNAL(aboutToQuit()), SIGNAL(aboutToQuit())); + connect(application, SIGNAL(focusChanged(QWidget*, QWidget*)), + SLOT(focusChangedSlot(QWidget*, QWidget*))); + } + + QString caption() + { + if (app->hasMainWindow()) + return app->mainWindow()->caption(); + return QString(""); // must not return a null QString + } + + void setCaption(const QString &newCaption) + { + if (app->hasMainWindow()) + app->mainWindow()->setCaption(newCaption); + } + + QString organizationName() + { + return app->organizationName(); + } + + QString organizationDomain() + { + return app->organizationDomain(); + } + +public slots: + Q_NOREPLY void quit() + { app->quit(); } + + void reparseConfiguration() + { app->reparseConfiguration(); } + + QString mainWindowObject() + { + if (app->hasMainWindow()) + return QString("/%1/mainwindow").arg(app->applicationName()); + return QString(); + } + + void setSessionManagement(bool enable) + { + if (enable) + app->enableSessionManagement(); + else + app->disableSessionManagement(); + } + +private slots: + void focusChangedSlot(QWidget *, QWidget *now) + { + if (now == app->mainWindow()) + emit mainWindowHasFocus(); + } + +signals: + void aboutToQuit(); + void mainWindowHasFocus(); +}; +//! [0] + + +//! [1] +interface org.kde.DBus.MainApplication +{ + property readwrite STRING caption + property read STRING organizationName + property read STRING organizationDomain + + method quit() annotation("org.freedesktop.DBus.Method.NoReply", "true") + method reparseConfiguration() + method mainWindowObject(out STRING) + method disableSessionManagement(in BOOLEAN enable) + + signal aboutToQuit() + signal mainWindowHasFocus() +} +//! [1] + + +//! [2] +int main(int argc, char **argv) +{ + // create the QApplication object + QApplication app(argc, argv); + + // create the MainApplication adaptor: + new MainApplicationAdaptor(app); + + // connect to D-Bus and register as an object: + QDBusConnection::sessionBus().registerObject("/MainApplication", app); + + // add main window, etc. + [...] + + app.exec(); +} +//! [2] + + +//! [3] +class MainApplicationAdaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.DBus.MainApplication") +//! [3] + + +//! [4] + Q_PROPERTY(QString caption READ caption WRITE setCaption) + Q_PROPERTY(QString organizationName READ organizationName) + Q_PROPERTY(QString organizationDomain READ organizationDomain) +//! [4] + + +//! [5] +QString caption() +{ + if (app->hasMainWindow()) + return app->mainWindow()->caption(); + return QString(); +} + +void setCaption(const QString &newCaption) +{ + if (app->hasMainWindow()) + app->mainWindow()->setCaption(newCaption); +} + +QString organizationName() +{ + return app->organizationName(); +} + +QString organizationDomain() +{ + return app->organizationDomain(); +} +//! [5] + + +//! [6] +MyInterfaceAdaptor(QApplication *application) + : QDBusAbstractAdaptor(application), app(application) +{ + connect(application, SIGNAL(aboutToQuit()), SIGNAL(aboutToQuit()); + connect(application, SIGNAL(focusChanged(QWidget*, QWidget*)), + SLOT(focusChangedSlot(QWidget*, QWidget*))); +} +//! [6] + + +//! [7] +public slots: + Q_NOREPLY void quit() + { app->quit(); } + + void reparseConfiguration() + { app->reparseConfiguration(); } + + QString mainWindowObject() + { + if (app->hasMainWindow()) + return QString("/%1/mainwindow").arg(app->applicationName()); + return QString(); + } + + void setSessionManagement(bool enable) + { + if (enable) + app->enableSessionManagement(); + else + app->disableSessionManagement(); + } +//! [7] + + +//! [8] +signals: + void aboutToQuit(); + void mainWindowHasFocus(); +//! [8] + + +//! [9] +private slots: + void focusChangedSlot(QWidget *, QWidget *now) + { + if (now == app->mainWindow()) + emit mainWindowHasFocus(); + } +//! [9] + + +//! [10] +struct RequestData +{ + QString request; + QString processedData; + QDBusMessage reply; +}; + +QString processRequest(const QString &request, const QDBusMessage &message) +{ + RequestData *data = new RequestData; + data->request = request; + message.setDelayedReply(true); + data->reply = message.createReply(); + QDBusConnection::sessionBus().send(data->reply); + + appendRequest(data); + return QString(); +} +//! [10] + + +//! [11] +void sendReply(RequestData *data) +{ + // data->processedData has been initialized with the request's reply + QDBusMessage &reply = &data->reply; + + // send the reply over D-Bus: + reply << data->processedData; + QDBusConnection::sessionBus().send(reply); + + // dispose of the transaction data + delete data; +} +//! [11] + + +//! [12] +Q_NOREPLY void myMethod(); +//! [12] diff --git a/src/dbus/doc/snippets/code/doc_src_qtdbus.cpp b/src/dbus/doc/snippets/code/doc_src_qtdbus.cpp new file mode 100644 index 0000000000..65fc2e716b --- /dev/null +++ b/src/dbus/doc/snippets/code/doc_src_qtdbus.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include <QtDBus> +//! [0] diff --git a/src/dbus/doc/snippets/code/doc_src_qtdbus.pro b/src/dbus/doc/snippets/code/doc_src_qtdbus.pro new file mode 100644 index 0000000000..a1ba138a85 --- /dev/null +++ b/src/dbus/doc/snippets/code/doc_src_qtdbus.pro @@ -0,0 +1,3 @@ +#! [1] +QT += dbus +#! [1] diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp new file mode 100644 index 0000000000..c16380f569 --- /dev/null +++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QString value = retrieveValue(); +QDBusMessage reply; + +QDBusReply<int> api = interface->call(QLatin1String("GetAPIVersion")); +if (api >= 14) + reply = interface->call(QLatin1String("ProcessWorkUnicode"), value); +else + reply = interface->call(QLatin1String("ProcessWork"), QLatin1String("UTF-8"), value.toUtf8()); +//! [0] + +//! [1] +QString value = retrieveValue(); +QDBusPendingCall pcall = interface->asyncCall(QLatin1String("Process"), value); + +QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); + +QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*))); +//! [1] diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp new file mode 100644 index 0000000000..6fa0ec5fa3 --- /dev/null +++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +struct MyStructure +{ + int count; + QString name; +}; +Q_DECLARE_METATYPE(MyStructure) + +// Marshall the MyStructure data into a D-Bus argument +QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct) +{ + argument.beginStructure(); + argument << mystruct.count << mystruct.name; + argument.endStructure(); + return argument; +} + +// Retrieve the MyStructure data from the D-Bus argument +const QDBusArgument &operator>>(const QDBusArgument &argument, MyStructure &mystruct) +{ + argument.beginStructure(); + argument >> mystruct.count >> mystruct.name; + argument.endStructure(); + return argument; +} +//! [0] + + +//! [1] +qDBusRegisterMetaType<MyStructure>(); +//! [1] + + +//! [2] +MyType item = qdbus_cast<Type>(argument); +//! [2] + + +//! [3] +MyType item; +argument >> item; +//! [3] + + +//! [4] +QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct) +{ + argument.beginStructure(); + argument << mystruct.member1 << mystruct.member2 << ... ; + argument.endStructure(); + return argument; +} +//! [4] + + +//! [5] +QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct) +{ + argument.beginStructure(); + argument << mystruct.member1 << mystruct.member2; + + argument.beginStructure(); + argument << mystruct.member3.subMember1 << mystruct.member3.subMember2; + argument.endStructure(); + + argument << mystruct.member4; + argument.endStructure(); + return argument; +} +//! [5] + + +//! [6] +// append an array of MyElement types +QDBusArgument &operator<<(QDBusArgument &argument, const MyArray &myarray) +{ + argument.beginArray( qMetaTypeId<MyElement>() ); + for ( int i = 0; i < myarray.length; ++i ) + argument << myarray.elements[i]; + argument.endArray(); + return argument; +} +//! [6] + + +//! [7] +// append a dictionary that associates ints to MyValue types +QDBusArgument &operator<<(QDBusArgument &argument, const MyDictionary &mydict) +{ + argument.beginMap( QVariant::Int, qMetaTypeId<MyValue>() ); + for ( int i = 0; i < mydict.length; ++i ) { + argument.beginMapEntry(); + argument << mydict.data[i].key << mydict.data[i].value; + argument.endMapEntry(); + } + argument.endMap(); + return argument; +} +//! [7] + + +//! [8] +const QDBusArgument &operator>>(const QDBusArgument &argument, MyStructure &mystruct) +{ + argument.beginStructure() + argument >> mystruct.member1 >> mystruct.member2 >> mystruct.member3 >> ...; + argument.endStructure(); + return argument; +} +//! [8] + + +//! [9] +// extract a MyArray array of MyElement elements +const QDBusArgument &operator>>(const QDBusArgument &argument, MyArray &myarray) +{ + argument.beginArray(); + myarray.clear(); + + while ( !argument.atEnd() ) { + MyElement element; + argument >> element; + myarray.append( element ); + } + + argument.endArray(); + return argument; +} +//! [9] + + +//! [10] +// extract a MyDictionary map that associates ints to MyValue elements +const QDBusArgument &operator>>(const QDBusArgument &argument, MyDictionary &mydict) +{ + argument.beginMap(); + mydict.clear(); + + while ( !argMap.atEnd() ) { + int key; + MyValue value; + argument.beginMapEntry(); + argument >> key >> value; + argument.endMapEntry(); + mydict.append( key, value ); + } + + argument.endMap(); + return argument; +} +//! [10] diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp new file mode 100644 index 0000000000..9ea2038aab --- /dev/null +++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MyObject: public QObject, + protected QDBusContext +{ + Q_OBJECT + QDBusConnection conn; + QDBusMessage msg; + +... + +protected slots: + void process(); +public slots: + void methodWithError(); + QString methodWithDelayedReply(); +}; + +void MyObject::methodWithError() +{ + sendErrorReply(QDBusError::NotSupported, + "The method call 'methodWithError()' is not supported"); +} + +QString MyObject::methodWithDelayedReply() +{ + conn = connection(); + msg = message(); + setDelayedReply(true); + QMetaObject::invokeMethod(this, "process", Qt::QueuedConnection); + return QString(); +} +//! [0] diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusinterface.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusinterface.cpp new file mode 100644 index 0000000000..0bcc3deff3 --- /dev/null +++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusinterface.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QDBusInterface remoteApp( "com.example.Calculator", "/Calculator/Operations", + "org.mathematics.RPNCalculator" ); +remoteApp.call( "PushOperand", 2 ); +remoteApp.call( "PushOperand", 2 ); +remoteApp.call( "ExecuteOperation", "+" ); +QDBusReply<int> reply = remoteApp.call( "PopOperand" ); + +if ( reply.isValid() ) + printf( "%d", reply.value() ); // prints 4 +//! [0] diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp new file mode 100644 index 0000000000..6c12464b78 --- /dev/null +++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include <QDBusMetaType> +qDBusRegisterMetaType<MyClass>(); +//! [0] diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp new file mode 100644 index 0000000000..a5d46dccfe --- /dev/null +++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +{ +//! [0] + QDBusPendingCall async = iface->asyncCall("RemoteMethod", value1, value2); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*))); +//! [0] + +} + +//! [1] +void MyClass::callFinishedSlot(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply<QString, QByteArray> reply = *call; + if (reply.isError()) { + showError(); + } else { + QString text = reply.argumentAt<0>(); + QByteArray data = reply.argumentAt<1>(); + showReply(text, data); + } + call->deleteLater(); +} +//! [1] diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp new file mode 100644 index 0000000000..eac955a798 --- /dev/null +++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +{ +//! [0] + QDBusPendingReply<QString> reply = interface->asyncCall("RemoteMethod"); + reply.waitForFinished(); + if (reply.isError()) + // call failed. Show an error condition. + showError(reply.error()); + else + // use the returned value + useValue(reply.value()); +//! [0] + +//! [2] + QDBusPendingReply<bool, QString> reply = interface->asyncCall("RemoteMethod"); + reply.waitForFinished(); + if (!reply.isError()) { + if (reply.argumentAt<0>()) + showSuccess(reply.argumentAt<1>()); + else + showFailure(reply.argumentAt<1>()); + } +//! [2] +} diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp new file mode 100644 index 0000000000..326f395058 --- /dev/null +++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QDBusReply<QString> reply = interface->call("RemoteMethod"); +if (reply.isValid()) + // use the returned value + useValue(reply.value()); +else + // call failed. Show an error condition. + showError(reply.error()); +//! [0] + + +//! [1] +QString reply = interface->call("RemoteMethod"); +//! [1] diff --git a/src/dbus/doc/snippets/qdbusextratypes/qdbusextratypes.cpp b/src/dbus/doc/snippets/qdbusextratypes/qdbusextratypes.cpp new file mode 100644 index 0000000000..69c1d05cd5 --- /dev/null +++ b/src/dbus/doc/snippets/qdbusextratypes/qdbusextratypes.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <QtDBus> + +static QVariant callMyDBusFunction() { return QVariant(); } + +int main() +{ + QDBusMessage myDBusMessage; + +//! [0] + QList<QVariant> arguments; + arguments << QVariant(42) << QVariant::fromValue(QDBusVariant(43)) << QVariant("hello"); + myDBusMessage.setArguments(arguments); +//! [0] + +//! [1] + // call a D-Bus function that returns a D-Bus variant + QVariant v = callMyDBusFunction(); + // retrieve the D-Bus variant + QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(v); + // retrieve the actual value stored in the D-Bus variant + QVariant result = dbusVariant.variant(); +//! [1] + + return 0; +} diff --git a/src/dbus/doc/src/dbus-adaptors.qdoc b/src/dbus/doc/src/dbus-adaptors.qdoc new file mode 100644 index 0000000000..a41c874c8c --- /dev/null +++ b/src/dbus/doc/src/dbus-adaptors.qdoc @@ -0,0 +1,481 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page usingadaptors.html + \title Using QtDBus Adaptors + \brief How to create and use DBus adaptors in Qt. + + \ingroup best-practices + + Adaptors are special classes that are attached to any QObject-derived class + and provide the interface to the external world using D-Bus. Adaptors are + intended to be lightweight classes whose main purpose is to relay calls to + and from the real object, possibly validating or converting the input from + the external world and, thus, protecting the real object. + + Unlike multiple inheritance, adaptors can be added at any time to any object + (but not removed), which allows for greater flexibility when exporting + existing classes. Another advantage of adaptors is to provide similar but not + identical functionality in methods of the same name in different interfaces, + a case which can be quite common when adding a new version of a standard + interface to an object. + + In order to use an adaptor, one must create a class which inherits + QDBusAbstractAdaptor. Since that is a standard QObject-derived class, the + Q_OBJECT macro must appear in the declaration and the source file must be + processed with the \l {moc} tool. The class must also contain one + Q_CLASSINFO entry with the \c {"D-Bus Interface"} name, declaring which + interface it is exporting. Only one entry per class is supported. + + Any public slot in the class will be accessible through the bus over messages + of the MethodCall type. (See \l {Declaring Slots in D-Bus Adaptors} for more + information). Signals in the class will be automatically relayed over D-Bus. + However, not all types are allowed signals or slots' parameter lists: see + \l {The QtDBus Type System} for more information. + + Also, any property declared with Q_PROPERTY will be automatically exposed + over the Properties interface on D-Bus. Since the QObject property system + does not allow for non-readable properties, it is not possible to declare + write-only properties using adaptors. + + More information: + \list + \li \l{Declaring Slots in D-Bus Adaptors} + \li \l{Declaring Signals in D-Bus Adaptors} + \li \l{The QtDBus Type System} + \li \l{D-Bus Adaptor Example} + \endlist + + \sa QDBusAbstractAdaptor +*/ + +/*! + \page qdbusadaptorexample.html + \title D-Bus Adaptor Example + + \previouspage The QtDBus Type System + \contentspage Using QtDBus Adaptors + + The following example code shows how a D-Bus interface can be implemented + using an adaptor. + + A sample usage of QDBusAbstractAdaptor is as follows: + \snippet code/doc_src_qdbusadaptors.cpp 0 + + The code above would create an interface that could be represented more or less in the following + canonical representation: + \snippet code/doc_src_qdbusadaptors.cpp 1 + + This adaptor could be used in the application's main function as follows + \snippet code/doc_src_qdbusadaptors.cpp 2 + + Break-down analysis: + \tableofcontents + + \section1 The header + + The header of the example is: + \snippet code/doc_src_qdbusadaptors.cpp 3 + + The code does the following: + \list + \li it declares the adaptor MainApplicationAdaptor, which descends from QDBusAbstractAdaptor + \li it declares the Qt meta-object data using the Q_OBJECT macro + \li it declares the name of the D-Bus interface it implements. + \endlist + + \section1 The properties + + The properties are declared as follows: + \snippet code/doc_src_qdbusadaptors.cpp 4 + + And are implemented as follows: + \snippet code/doc_src_qdbusadaptors.cpp 5 + + The code declares three properties: one of them is a read-write property called "caption" of + string type. The other two are read-only, also of the string type. + + The properties organizationName and organizationDomain are simple relays of the app object's + organizationName and organizationDomain properties. However, the caption property requires + verifying if the application has a main window associated with it: if there isn't any, the + caption property is empty. Note how it is possible to access data defined in other objects + through the getter/setter functions. + + \section1 The constructor + + The constructor: + \snippet code/doc_src_qdbusadaptors.cpp 6 + + The constructor does the following: + \list + \li it initialises its base class (QDBusAbstractAdaptor) with the parent object it is related to. + \li it stores the app pointer in a member variable. Note that it would be possible to access the + same object using the QDBusAbstractAdaptor::object() function, but it would be necessary to + use \a static_cast<> to properly access the methods in QApplication that are not part of + QObject. + \li it connects the application's signal \a aboutToQuit to its own signal \a aboutToQuit. + \li it connects the application's signal \a focusChanged to a private slot to do some further + processing before emitting a D-Bus signal. + \endlist + + Note that there is no destructor in the example. An eventual destructor could be used to emit + one last signal before the object is destroyed, for instance. + + \section1 Slots/methods + + The public slots in the example (which will be exported as D-Bus methods) are the following: + \snippet code/doc_src_qdbusadaptors.cpp 7 + + This snippet of code defines 4 methods with different properties each: + \list 1 + \li \c quit: this method takes no parameters and is defined to be asynchronous. That is, callers + are expected to use "fire-and-forget" mechanism when calling this method, since it provides no + useful reply. This is represented in D-Bus by the use of the + org.freedesktop.DBus.Method.NoReply annotation. See \l Q_NOREPLY for more information on + asynchronous methods + + \li \c reparseConfiguration: this simple method, with no input or output arguments simply relays + the call to the application's reparseConfiguration member function. + + \li \c mainWindowObject: this method takes no input parameter, but returns one string output + argument, containing the path to the main window object (if the application has a main + window), or an empty string if it has no main window. Note that this method could have also + been written: void mainWindowObject(QString &path). + + \li \c setSessionManagement: this method takes one input argument (a boolean) and, depending on + its value, it calls one function or another in the application. + \endlist + + See also: \l Q_NOREPLY. + + \section1 Signals + + The signals in this example are defined as follows: + \snippet code/doc_src_qdbusadaptors.cpp 8 + + However, signal definition isn't enough: signals have to be emitted. One simple way of emitting + signals is to connect another signal to them, so that Qt's signal handling system chains them + automatically. This is what is done for the \a aboutToQuit signal. + + When this is the case, one can use the QDBusAbstractAdaptor::setAutoRelaySignals to + automatically connect every signal from the real object to the adaptor. + + When simple signal-to-signal connection isn't enough, one can use a private slot do do some + work. This is what was done for the mainWindowHasFocus signal: + \snippet code/doc_src_qdbusadaptors.cpp 9 + + This private slot (which will not be exported as a method via D-Bus) was connected to the + \c focusChanged signal in the adaptor's constructor. It is therefore able to shape the + application's signal into what the interface expects it to be. +*/ + +/*! + \page qdbusdeclaringslots.html + \title Declaring Slots in D-Bus Adaptors + + \contentspage Using QtDBus Adaptors + \nextpage Declaring Signals in D-Bus Adaptors + + Slots in D-Bus adaptors are declared just like normal, public slots, but their + parameters must follow certain rules (see \l{The QtDBus Type System} for more + information). Slots whose parameters do not follow those rules or that are not + public will not be accessible via D-Bus. + + Slots can have one parameter of type \c{const QDBusMessage &}, which must + appear at the end of the input parameter list, before any output parameters. + This parameter, if present, will be initialized with a copy of the + current message being processed, which allows the callee to obtain + information about the caller, such as its connection name. + + Slots can be of three kinds: + \list 1 + \li Asynchronous + \li Input-only + \li Input-and-output + \endlist + + \section1 Asynchronous Slots + Asynchronous slots are those that do not normally return any reply to the + caller. For that reason, they cannot take any output parameters. In most + cases, by the time the first line of the slot is run, the caller function + has already resumed working. + + However, slots must not rely on that behavior. Scheduling and message-dispatching + issues could change the order in which the slot is run. Code intending to + synchronize with the caller should provide its own method of synchronization. + + Asynchronous slots are marked by the keyword \l Q_NOREPLY in the method + signature, before the \c void return type and the slot name. (See the + \c quit() slot in the \l{D-Bus Adaptor Example}). + + \section1 Input-Only Slots + + Input-only slots are normal slots that take parameters passed by value or + by constant reference. However, unlike asynchronous slots, the caller is + usually waiting for completion of the callee before resuming operation. + Therefore, non-asynchronous slots should not block or should state it its + documentation that they may do so. + + Input-only slots have no special marking in their signature, except that + they take only parameters passed by value or by constant reference. + Optionally, slots can take a QDBusMessage parameter as a last parameter, + which can be used to perform additional analysis of the method call message. + + \section1 Input and Output Slots + + Like input-only slots, input-and-output slots are those that the caller is + waiting for a reply. Unlike input-only ones, though, this reply will contain + data. Slots that output data may contain non-constant references and may + return a value as well. However, the output parameters must all appear at + the end of the argument list and may not have input arguments interleaved. + Optionally, a QDBusMessage argument may appear between the input and the + output arguments. + + \section1 Automatic Replies + + Method replies are generated automatically with the contents of the output + parameters (if there were any) by the QtDBus implementation. Slots need not + worry about constructing proper QDBusMessage objects and sending them over + the connection. + + However, the possibility of doing so remains there. Should the slot find out + it needs to send a special reply or even an error, it can do so by using + QDBusMessage::createReply() or QDBusMessage::createErrorReply() on the + QDBusMessage parameter and send it with QDBusConnection::send(). The + QtDBus implementation will not generate any reply if the slot did so. + + \warning When a caller places a method call and waits for a reply, it will + only wait for a limited amount of time. Slots intending to take a long time + to complete should make that fact clear in documentation so that callers + properly set higher timeouts. + + \section1 Delayed Replies + + In some circumstances, the called slot may not be able to process + the request immediately. This is frequently the case when the + request involves an I/O or networking operation which may block. + + If this is the case, the slot should return control to the + application's main loop to avoid freezing the user interface, and + resume the process later. To accomplish this, it should make use + of the extra \c QDBusMessage parameter at the end of the input + parameter list and request a delayed reply. + + We do this by writing a slot that stores the request data in a + persistent structure, indicating to the caller using + \l{QDBusMessage::setDelayedReply()}{QDBusMessage::setDelayedReply(true)} + that the response will be sent later. + + \snippet code/doc_src_qdbusadaptors.cpp 10 + + The use of + \l{QDBusConnection::send()}{QDBusConnection::sessionBus().send(data->reply)} + is needed to explicitly inform the caller that the response will be delayed. + In this case, the return value is unimportant; we return an arbitrary value + to satisfy the compiler. + + When the request is processed and a reply is available, it should be sent + using the \c QDBusMessage object that was obtained. In our example, the + reply code could be something as follows: + + \snippet code/doc_src_qdbusadaptors.cpp 11 + + As can be seen in the example, when a delayed reply is in place, + the return value(s) from the slot will be ignored by QtDBus. They + are used only to determine the slot's signature when communicating + the adaptor's description to remote applications, or in case the + code in the slot decides not to use a delayed reply. + + The delayed reply itself is requested from QtDBus by calling + QDBusMessage::reply() on the original message. It then becomes the + resposibility of the called code to eventually send a reply to the + caller. + + \warning When a caller places a method call and waits for a reply, it will + only wait for a limited amount of time. Slots intending to take a long time + to complete should make that fact clear in documentation so that callers + properly set higher timeouts. + + \sa {Using QtDBus Adaptors}, {Declaring Signals in D-Bus Adaptors}, + {The QtDBus Type System}, QDBusConnection, QDBusMessage +*/ + +/*! + \page qdbusdeclaringsignals.html + \title Declaring Signals in D-Bus Adaptors + + \previouspage Declaring Slots in D-Bus Adaptors + \contentspage Using QtDBus Adaptors + \nextpage The QtDBus Type System + + Any signal in a class derived from QDBusAbstractAdaptor will be automatically + relayed into D-Bus, provided that the signal's parameters conform to certain + rules (see \l{The QtDBus Type System} for more information). No special code + is necessary to make this relay. + + However, signals must still be emitted. The easiest way to emit an adaptor + signal is to connect another signal to it, so that Qt's signals and slots + mechanism automatically emits the adaptor signal, too. This can be done in + the adaptor's constructor, as has been done in the + \l{D-Bus Adaptor Example}{D-Bus Adaptor example}. + + The QDBusAbstractAdaptor::setAutoRelaySignals() convenience function can also + be used to make and break connections between signals in the real object and + the corresponding signals in the adaptor. It will inspect the list of signals + in both classes and connect those whose parameters match exactly. + + \sa {Using QtDBus Adaptors}, + {Declaring Slots in D-Bus Adaptors}, + {The QtDBus Type System}, QDBusAbstractAdaptor +*/ + +/*! + \page qdbustypesystem.html + \title The QtDBus Type System + + \previouspage Declaring Signals in D-Bus Adaptors + \contentspage Using QtDBus Adaptors + \nextpage D-Bus Adaptor Example + + D-Bus has an extensible type system based on a few primitives and + composition of the primitives in arrays and structures. QtDBus + implements the interface to that type system through the + QDBusArgument class, allowing user programs to send and receive + practically every C++ type over the bus. + + \section1 Primitive Types + + The primitive types are supported natively by QDBusArgument and + need no special customization to be sent or received. They are + listed below, along with the C++ class they relate to: + + \table + \header + \li Qt type + \li D-Bus equivalent type + \row + \li uchar + \li BYTE + \row + \li bool + \li BOOLEAN + \row + \li short + \li INT16 + \row + \li ushort + \li UINT16 + \row + \li int + \li INT32 + \row + \li uint + \li UINT32 + \row + \li qlonglong + \li INT64 + \row + \li qulonglong + \li UINT64 + \row + \li double + \li DOUBLE + \row + \li QString + \li STRING + \row + \li QDBusVariant + \li VARIANT + \row + \li QDBusObjectPath + \li OBJECT_PATH + \row + \li QDBusSignature + \li SIGNATURE + \endtable + + Aside from the primitive types, QDBusArgument also supports two + non-primitive types natively, due to their widespread use in Qt + applications: QStringList and QByteArray. + + \section1 Compound Types + + D-Bus specifies three types of aggregations of primitive types + that allow one to create compound types. They are \c ARRAY, \c + STRUCT and maps/dictionaries. + + Arrays are sets of zero or more elements of the same type, while + structures are a set of a fixed number of elements, each of any + type. Maps or dictionaries are implemented as arrays of a pair of + elements, so there can be zero or more elements in one map. + + \section1 Extending the Type System + + In order to use one's own type with QtDBus, the type has to be + declared as a Qt meta-type with the Q_DECLARE_METATYPE() macro and + registered with the qDBusRegisterMetaType() function. The + streaming operators \c{operator>>} and \c{operator<<} will be + automatically found by the registration system. + + QtDBus provides template specializations for arrays and maps for + use with Qt's \l{Container classes}{container classes}, such as + QMap and QList, so it is not necessary to write the streaming + operator functions for those. For other types, and specially for + types implementing structures, the operators have to be explicitly + implemented. + + See the documentation for QDBusArgument for examples for + structures, arrays and maps. + + \section1 The Type System in Use + + All of the QtDBus types (primitives and user-defined alike) can be + used to send and receive messages of all types over the bus. + + \warning You may not use any type that is not on the list above, + including \a typedefs to the types listed. This also includes + QList<QVariant> and QMap<QString,QVariant>. +*/ + +/*! + \macro Q_NOREPLY + \relates QDBusAbstractAdaptor + \since 4.2 + + The Q_NOREPLY macro can be used to mark a method to be called and not wait for it to finish + processing before returning from QDBusInterface::call(). The called method cannot return any + output arguments and, if it does, any such arguments will be discarded. + + You can use this macro in your own adaptors by placing it before your method's return value + (which must be "void") in the class declaration, as shown in the example: + \snippet code/doc_src_qdbusadaptors.cpp 12 + + Its presence in the method implementation (outside the class declaration) is optional. + + \sa {Using QtDBus Adaptors} +*/ diff --git a/src/dbus/doc/src/dbus-intro.qdoc b/src/dbus/doc/src/dbus-intro.qdoc new file mode 100644 index 0000000000..b3cf29e129 --- /dev/null +++ b/src/dbus/doc/src/dbus-intro.qdoc @@ -0,0 +1,215 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page intro-to-dbus.html + \title D-Bus + \brief An introduction to Inter-Process Communication and Remote Procedure Calling with D-Bus. + + \keyword QtDBus + \ingroup technology-apis + + \section1 Introduction + + D-Bus is an Inter-Process Communication (IPC) and Remote Procedure + Calling (RPC) mechanism originally developed for Linux to replace + existing and competing IPC solutions with one unified protocol. It + has also been designed to allow communication between system-level + processes (such as printer and hardware driver services) and + normal user processes. + + It uses a fast, binary message-passing protocol, which is suitable + for same-machine communication due to its low latency and low + overhead. Its specification is currently defined by the + \tt{freedesktop.org} project, and is available to all parties. + + Communication in general happens through a central server + application, called the "bus" (hence the name), but direct + application-to-application communication is also possible. When + communicating on a bus, applications can query which other + applications and services are available, as well as activate one + on demand. + + \section1 The Buses + + D-Bus buses are used to when many-to-many communication is + desired. In order to achieve that, a central server is launched + before any applications can connect to the bus: this server is + responsible for keeping track of the applications that are + connected and for properly routing messages from their source to + their destination. + + In addition, D-Bus defines two well-known buses, called the + system bus and the session bus. These buses are special in the + sense that they have well-defined semantics: some services are + defined to be found in one or both of these buses. + + For example, an application wishing to query the list of hardware + devices attached to the computer will probably communicate to a + service available on the system bus, while the service providing + opening of the user's web browser will be probably found on the + session bus. + + On the system bus, one can also expect to find restrictions on + what services each application is allowed to offer. Therefore, one + can be reasonably certain that, if a certain service is present, + it is being offered by a trusted application. + + \section1 Concepts + + \section2 Messages + + On the low level, applications communicate over D-Bus by sending + messages to one another. Messages are used to relay the remote + procedure calls as well as the replies and errors associated + with them. When used over a bus, messages have a destination, + which means they are routed only to the interested parties, + avoiding congestion due to "swarming" or broadcasting. + + A special kind of message called a "signal message" + (a concept based on Qt's \l {Signals and Slots} mechanism), + however, does not have a pre-defined destination. Since its + purpose is to be used in a one-to-many context, signal messages + are designed to work over an "opt-in" mechanism. + + The QtDBus module fully encapsulates the low-level concept of + messages into a simpler, object-oriented approach familiar to Qt + developers. In most cases, the developer need not worry about + sending or receiving messages. + + \section2 Service Names + + When communicating over a bus, applications obtain what is + called a "service name": it is how that application chooses to be + known by other applications on the same bus. The service names + are brokered by the D-Bus bus daemon and are used to + route messages from one application to another. An analogous + concept to service names are IP addresses and hostnames: a + computer normally has one IP address and may have one or more + hostnames associated with it, according to the services that it + provides to the network. + + On the other hand, if a bus is not used, service names are also + not used. If we compare this to a computer network again, this + would equate to a point-to-point network: since the peer is + known, there is no need to use hostnames to find it or its IP + address. + + The format of a D-Bus service name is in fact very similar to a + host name: it is a dot-separated sequence of letters and + digits. The common practice is even to name one's service name + according to the domain name of the organization that defined + that service. + + For example, the D-Bus service is defined by + \tt{freedesktop.org} and can be found on the bus under the + service name: + + \snippet code/doc_src_introtodbus.qdoc 0 + + \section2 Object Paths + + Like network hosts, applications provide specific services to + other applications by exporting objects. Those objects are + hierarchically organised, much like the parent-child + relationship that classes derived from QObject possess. One + difference, however, is that there is the concept of "root + object", that all objects have as ultimate parent. + + If we continue our analogy with Web services, object paths + equate to the path part of a URL: + + \img qurl-ftppath.png + + Like them, object paths in D-Bus are formed resembling path + names on the filesystem: they are slash-separated labels, each + consisting of letters, digits and the underscore character + ("_"). They must always start with a slash and must not end with + one. + + \section2 Interfaces + + Interfaces are similar to C++ abstract classes and Java's + \c interface keyword and declare the "contract" that is + established between caller and callee. That is, they establish + the names of the methods, signals and properties that are + available as well as the behavior that is expected from either + side when communication is established. + + Qt uses a very similar mechanism in its \l {How to Create Qt + Plugins}{Plugin system}: Base classes in C++ are associated + with a unique identifier by way of the Q_DECLARE_INTERFACE() + macro. + + D-Bus interface names are, in fact, named in a manner similar to + what is suggested by the Qt Plugin System: an identifier usually + constructed from the domain name of the entity that defined that + interface. + + \section2 Cheat Sheet + + To facilitate remembering of the naming formats and their + purposes, the following table can be used: + + \table 90% + \header \li D-Bus Concept \li Analogy \li Name format + \row \li Service name \li Network hostnames \li Dot-separated + ("looks like a hostname") + \row \li Object path \li URL path component \li Slash-separated + ("looks like a path") + \row \li Interface \li Plugin identifier \li Dot-separated + \endtable + + \section1 Debugging + + When developing applications that use D-Bus, it is sometimes useful to be able + to see information about the messages that are sent and received across the + bus by each application. + + This feature can be enabled on a per-application basis by setting the + \c QDBUS_DEBUG environment variable before running each application. + For example, we can enable debugging only for the car in the + \l{D-Bus Remote Controlled Car Example} by running the controller and the + car in the following way: + + \snippet code/doc_src_introtodbus.qdoc QDBUS_DEBUG + + Information about the messages will be written to the console the application + was launched from. + + \section1 Further Reading + + The following documents contain information about Qt's D-Bus integration + features, and provide details about the mechanisms used to send and receive + type information over the bus: + + \list + \li \l{Using QtDBus Adaptors} + \li \l{The QtDBus Type System} + \li \l{QtDBus XML compiler (qdbusxml2cpp)} + \endlist +*/ diff --git a/src/dbus/doc/src/qdbusxml2cpp.qdoc b/src/dbus/doc/src/qdbusxml2cpp.qdoc new file mode 100644 index 0000000000..996b5c7820 --- /dev/null +++ b/src/dbus/doc/src/qdbusxml2cpp.qdoc @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page qdbusxml2cpp.html + \title QtDBus XML compiler (qdbusxml2cpp) + \keyword qdbusxml2cpp + + The QtDBus XML compiler is a tool that can be used to parse interface descriptions and produce + static code representing those interfaces, which can then be used to make calls to remote + objects or implement said interfaces. + + \c qdbusxml2cpp has two modes of operation, that correspond to the two possible outputs it can + produce: the interface (proxy) class or the adaptor class. The latter consists of both a C++ + header and a source file, which are meant to be edited and adapted to your needs. + + The \c qdbusxml2cpp tool is not meant to be run every time you compile your + application. Instead, it's meant to be used when developing the code or when the interface + changes. + + The adaptor classes generated by \c qdbusxml2cpp are just a skeleton that must be completed. It + generates, by default, calls to slots with the same name on the object the adaptor is attached + to. However, you may modify those slots or the property accessor functions to suit your needs. +*/ + diff --git a/src/dbus/doc/src/qtdbus.qdoc b/src/dbus/doc/src/qtdbus.qdoc new file mode 100644 index 0000000000..739502e1fc --- /dev/null +++ b/src/dbus/doc/src/qtdbus.qdoc @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \module QtDBus + \title QtDBus module + \ingroup modules + + \keyword QtDBus + \target The QDBus compiler + + \brief The QtDBus module is a Unix-only library that you can use + to perform Inter-Process Communication using the \l{D-Bus} protocol. + + Applications using the QtDBus module can provide services to + other, remote applications by exporting objects, as well as use + services exported by those applications by placing calls and + accessing properties. + + The QtDBus module provides an interface that extends the Qt \l + {signalsandslots.html}{Signals and Slots} mechanism, allowing one + to connect to a signal emitted remotely as well as to connect a + local signal to remote slot. + + To use this module, use the following code in your application: + + \snippet code/doc_src_qtdbus.cpp 0 + + If you're using qmake to build your application, you can add this + line to your .pro file to make it link against the QtDBus + libraries: + + \snippet code/doc_src_qtdbus.pro 1 + + \note The source code for this module is located in the \c{src/qdbus} + directory. When installing Qt from source, this module is built when Qt's + tools are built. + + See the \l {D-Bus} page for detailed information on + how to use this module. +*/ diff --git a/src/dbus/qdbusabstractinterface.cpp b/src/dbus/qdbusabstractinterface.cpp index ea32e6ead6..51b100839c 100644 --- a/src/dbus/qdbusabstractinterface.cpp +++ b/src/dbus/qdbusabstractinterface.cpp @@ -650,7 +650,7 @@ void QDBusAbstractInterface::internalPropSet(const char *propname, const QVarian It can be used the following way: - \snippet doc/src/snippets/code/src_qdbus_qdbusabstractinterface.cpp 0 + \snippet code/src_qdbus_qdbusabstractinterface.cpp 0 This example illustrates function calling with 0, 1 and 2 parameters and illustrates different parameter types passed in each (the first call to \c "ProcessWorkUnicode" will contain one @@ -742,7 +742,7 @@ QDBusMessage QDBusAbstractInterface::call(QDBus::CallMode mode, const QString &m It can be used the following way: - \snippet doc/src/snippets/code/src_qdbus_qdbusabstractinterface.cpp 1 + \snippet code/src_qdbus_qdbusabstractinterface.cpp 1 This example illustrates function calling with 0, 1 and 2 parameters and illustrates different parameter types passed in each (the first call to \c "ProcessWorkUnicode" will contain one diff --git a/src/dbus/qdbusargument.cpp b/src/dbus/qdbusargument.cpp index 6e6e676dae..0969aef83f 100644 --- a/src/dbus/qdbusargument.cpp +++ b/src/dbus/qdbusargument.cpp @@ -190,13 +190,13 @@ bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d) integer and a string can be constructed using the \l {qdbustypesystem.html}{QtDBus type system}: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 0 + \snippet code/src_qdbus_qdbusargument.cpp 0 The type has to be registered with qDBusRegisterMetaType() before it can be used with QDBusArgument. Therefore, somewhere in your program, you should add the following code: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 1 + \snippet code/src_qdbus_qdbusargument.cpp 1 Once registered, a type can be used in outgoing method calls (placed with QDBusAbstractInterface::call()), signal emissions @@ -275,11 +275,11 @@ bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d) Attempts to demarshall the contents of \a argument into the type \c{T}. For example: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 2 + \snippet code/src_qdbus_qdbusargument.cpp 2 Note that it is equivalent to the following: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 3 + \snippet code/src_qdbus_qdbusargument.cpp 3 */ /*! @@ -817,12 +817,12 @@ const QDBusArgument &QDBusArgument::operator>>(QByteArray &arg) const This function is used usually in \c{operator<<} streaming operators, as in the following example: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 4 + \snippet code/src_qdbus_qdbusargument.cpp 4 Structures can contain other structures, so the following code is also valid: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 5 + \snippet code/src_qdbus_qdbusargument.cpp 5 \sa endStructure(), beginArray(), beginMap() */ @@ -850,7 +850,7 @@ void QDBusArgument::endStructure() This function is used usually in \c{operator<<} streaming operators, as in the following example: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 6 + \snippet code/src_qdbus_qdbusargument.cpp 6 If the type you want to marshall is a QList, QVector or any of the Qt's \l {Container Classes} that take one template parameter, @@ -889,7 +889,7 @@ void QDBusArgument::endArray() This function is used usually in \c{operator<<} streaming operators, as in the following example: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 7 + \snippet code/src_qdbus_qdbusargument.cpp 7 If the type you want to marshall is a QMap or QHash, you need not declare an \c{operator<<} function for it, since QtDBus provides @@ -948,7 +948,7 @@ void QDBusArgument::endMapEntry() This function is used usually in \c{operator>>} streaming operators, as in the following example: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 8 + \snippet code/src_qdbus_qdbusargument.cpp 8 \sa endStructure(), beginArray(), beginMap() */ @@ -977,7 +977,7 @@ void QDBusArgument::endStructure() const This function is used usually in \c{operator>>} streaming operators, as in the following example: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 9 + \snippet code/src_qdbus_qdbusargument.cpp 9 If the type you want to demarshall is a QList, QVector or any of the Qt's \l {Container Classes} that take one template parameter, you @@ -1013,7 +1013,7 @@ void QDBusArgument::endArray() const This function is used usually in \c{operator>>} streaming operators, as in the following example: - \snippet doc/src/snippets/code/src_qdbus_qdbusargument.cpp 10 + \snippet code/src_qdbus_qdbusargument.cpp 10 If the type you want to demarshall is a QMap or QHash, you need not declare an \c{operator>>} function for it, since QtDBus provides diff --git a/src/dbus/qdbuscontext.cpp b/src/dbus/qdbuscontext.cpp index cc987d1410..0a13fce9ee 100644 --- a/src/dbus/qdbuscontext.cpp +++ b/src/dbus/qdbuscontext.cpp @@ -90,7 +90,7 @@ QDBusContextPrivate *QDBusContextPrivate::set(QObject *obj, QDBusContextPrivate exported using QDBusConnection::registerObject(). The following example illustrates the usage: - \snippet doc/src/snippets/code/src_qdbus_qdbuscontext.cpp 0 + \snippet code/src_qdbus_qdbuscontext.cpp 0 The example illustrates the two typical uses, that of sending error replies and that of delayed replies. diff --git a/src/dbus/qdbusextratypes.cpp b/src/dbus/qdbusextratypes.cpp index 4438e3c65f..4b2730c44a 100644 --- a/src/dbus/qdbusextratypes.cpp +++ b/src/dbus/qdbusextratypes.cpp @@ -73,11 +73,11 @@ void QDBusSignature::doCheck() A D-Bus function that takes an integer, a D-Bus variant and a string as parameters can be called with the following argument list (see QDBusMessage::setArguments()): - \snippet doc/src/snippets/qdbusextratypes/qdbusextratypes.cpp 0 + \snippet qdbusextratypes/qdbusextratypes.cpp 0 When a D-Bus function returns a D-Bus variant, it can be retrieved as follows: - \snippet doc/src/snippets/qdbusextratypes/qdbusextratypes.cpp 1 + \snippet qdbusextratypes/qdbusextratypes.cpp 1 The QVariant within a QDBusVariant is required to distinguish between a normal D-Bus value and a value within a D-Bus variant. diff --git a/src/dbus/qdbusinterface.cpp b/src/dbus/qdbusinterface.cpp index f6a84b9980..844b0b7a4c 100644 --- a/src/dbus/qdbusinterface.cpp +++ b/src/dbus/qdbusinterface.cpp @@ -196,7 +196,7 @@ QDBusInterfacePrivate::~QDBusInterfacePrivate() mathematical operation of \tt{"2 + 2"} in a remote application called \c com.example.Calculator, accessed via the session bus. - \snippet doc/src/snippets/code/src_qdbus_qdbusinterface.cpp 0 + \snippet code/src_qdbus_qdbusinterface.cpp 0 \sa {QtDBus XML compiler (qdbusxml2cpp)} */ diff --git a/src/dbus/qdbusmetatype.cpp b/src/dbus/qdbusmetatype.cpp index 0359b4da35..03cad1ee63 100644 --- a/src/dbus/qdbusmetatype.cpp +++ b/src/dbus/qdbusmetatype.cpp @@ -200,7 +200,7 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock) Q_DECLARE_METATYPE() macro, and then registered as in the following example: - \snippet doc/src/snippets/code/src_qdbus_qdbusmetatype.cpp 0 + \snippet code/src_qdbus_qdbusmetatype.cpp 0 If \c{T} isn't a type derived from one of Qt's \l{container classes}, the \c{operator<<} and diff --git a/src/dbus/qdbuspendingcall.cpp b/src/dbus/qdbuspendingcall.cpp index 3d5dc421d7..9ae68c7abc 100644 --- a/src/dbus/qdbuspendingcall.cpp +++ b/src/dbus/qdbuspendingcall.cpp @@ -97,7 +97,7 @@ QT_BEGIN_NAMESPACE It is usually used like the following example: - \snippet doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp 0 + \snippet code/src_qdbus_qdbuspendingcall.cpp 0 Note that it is not necessary to keep the original QDBusPendingCall object around since QDBusPendingCallWatcher inherits from that class @@ -106,7 +106,7 @@ QT_BEGIN_NAMESPACE The slot connected to by the above code could be something similar to the following: - \snippet doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp 1 + \snippet code/src_qdbus_qdbuspendingcall.cpp 1 Note the use of QDBusPendingReply to validate the argument types in the reply. If the reply did not contain exactly two arguments diff --git a/src/dbus/qdbuspendingreply.cpp b/src/dbus/qdbuspendingreply.cpp index b9694ca205..2fd219260d 100644 --- a/src/dbus/qdbuspendingreply.cpp +++ b/src/dbus/qdbuspendingreply.cpp @@ -69,22 +69,22 @@ Where with QDBusReply you would write: - \snippet doc/src/snippets/code/src_qdbus_qdbusreply.cpp 0 + \snippet code/src_qdbus_qdbusreply.cpp 0 with QDBusPendingReply, the equivalent code (including the blocking wait for the reply) would be: - \snippet doc/src/snippets/code/src.qdbus.qdbuspendingreply.cpp 0 + \snippet code/src_qdbus_qdbuspendingreply.cpp 0 For method calls that have more than one output argument, with QDBusReply, you would write: - \snippet doc/src/snippets/code/src_qdbus_qdbusreply.cpp 1 + \snippet code/src_qdbus_qdbusreply.cpp 1 whereas with QDBusPendingReply, all of the output arguments should be template parameters: - \snippet doc/src/snippets/code/src.qdbus.qdbuspendingreply.cpp 2 + \snippet code/src_qdbus_qdbuspendingreply.cpp 2 QDBusPendingReply objects can be associated with QDBusPendingCallWatcher objects, which emit signals when the reply diff --git a/src/dbus/qdbusreply.cpp b/src/dbus/qdbusreply.cpp index c891874d98..9875329a26 100644 --- a/src/dbus/qdbusreply.cpp +++ b/src/dbus/qdbusreply.cpp @@ -61,10 +61,10 @@ QT_BEGIN_NAMESPACE argument. It can be used in the following manner: - \snippet doc/src/snippets/code/src_qdbus_qdbusreply.cpp 0 + \snippet code/src_qdbus_qdbusreply.cpp 0 If the remote method call cannot fail, you can skip the error checking: - \snippet doc/src/snippets/code/src_qdbus_qdbusreply.cpp 1 + \snippet code/src_qdbus_qdbusreply.cpp 1 However, if it does fail under those conditions, the value returned by QDBusReply::value() is a default-constructed value. It may be indistinguishable from a valid return value. diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp index b84ecefd73..ec02086d74 100644 --- a/src/gui/accessible/qaccessible.cpp +++ b/src/gui/accessible/qaccessible.cpp @@ -460,7 +460,7 @@ static void qAccessibleCleanup() This is a typedef for a pointer to a function with the following signature: - \snippet doc/src/snippets/code/src_gui_accessible_qaccessible.cpp 1 + \snippet code/src_gui_accessible_qaccessible.cpp 1 The function receives a QString and a QObject pointer, where the QString is the key identifying the interface. The QObject is used diff --git a/src/gui/doc/images/brush-outline.png b/src/gui/doc/images/brush-outline.png Binary files differnew file mode 100644 index 0000000000..f560c9faf5 --- /dev/null +++ b/src/gui/doc/images/brush-outline.png diff --git a/src/gui/doc/images/brush-styles.png b/src/gui/doc/images/brush-styles.png Binary files differnew file mode 100644 index 0000000000..eecb006af1 --- /dev/null +++ b/src/gui/doc/images/brush-styles.png diff --git a/src/gui/doc/images/coordinatesystem-analogclock.png b/src/gui/doc/images/coordinatesystem-analogclock.png Binary files differnew file mode 100644 index 0000000000..16e3091b77 --- /dev/null +++ b/src/gui/doc/images/coordinatesystem-analogclock.png diff --git a/src/gui/doc/images/coordinatesystem-line-antialias.png b/src/gui/doc/images/coordinatesystem-line-antialias.png Binary files differnew file mode 100644 index 0000000000..90dfa8730e --- /dev/null +++ b/src/gui/doc/images/coordinatesystem-line-antialias.png diff --git a/src/gui/doc/images/coordinatesystem-line-raster.png b/src/gui/doc/images/coordinatesystem-line-raster.png Binary files differnew file mode 100644 index 0000000000..65201bde9f --- /dev/null +++ b/src/gui/doc/images/coordinatesystem-line-raster.png diff --git a/src/gui/doc/images/coordinatesystem-line.png b/src/gui/doc/images/coordinatesystem-line.png Binary files differnew file mode 100644 index 0000000000..fbf6873084 --- /dev/null +++ b/src/gui/doc/images/coordinatesystem-line.png diff --git a/src/gui/doc/images/coordinatesystem-rect-antialias.png b/src/gui/doc/images/coordinatesystem-rect-antialias.png Binary files differnew file mode 100644 index 0000000000..162e1df9cb --- /dev/null +++ b/src/gui/doc/images/coordinatesystem-rect-antialias.png diff --git a/src/gui/doc/images/coordinatesystem-rect-raster.png b/src/gui/doc/images/coordinatesystem-rect-raster.png Binary files differnew file mode 100644 index 0000000000..be3690d6ad --- /dev/null +++ b/src/gui/doc/images/coordinatesystem-rect-raster.png diff --git a/src/gui/doc/images/coordinatesystem-rect.png b/src/gui/doc/images/coordinatesystem-rect.png Binary files differnew file mode 100644 index 0000000000..76c06befd6 --- /dev/null +++ b/src/gui/doc/images/coordinatesystem-rect.png diff --git a/src/gui/doc/images/coordinatesystem-transformations.png b/src/gui/doc/images/coordinatesystem-transformations.png Binary files differnew file mode 100644 index 0000000000..2736213c07 --- /dev/null +++ b/src/gui/doc/images/coordinatesystem-transformations.png diff --git a/src/gui/doc/images/cursor-arrow.png b/src/gui/doc/images/cursor-arrow.png Binary files differnew file mode 100644 index 0000000000..a69ef4eb61 --- /dev/null +++ b/src/gui/doc/images/cursor-arrow.png diff --git a/src/gui/doc/images/cursor-busy.png b/src/gui/doc/images/cursor-busy.png Binary files differnew file mode 100644 index 0000000000..53717e4992 --- /dev/null +++ b/src/gui/doc/images/cursor-busy.png diff --git a/src/gui/doc/images/cursor-closedhand.png b/src/gui/doc/images/cursor-closedhand.png Binary files differnew file mode 100644 index 0000000000..b78dd1dac5 --- /dev/null +++ b/src/gui/doc/images/cursor-closedhand.png diff --git a/src/gui/doc/images/cursor-cross.png b/src/gui/doc/images/cursor-cross.png Binary files differnew file mode 100644 index 0000000000..fe38e74480 --- /dev/null +++ b/src/gui/doc/images/cursor-cross.png diff --git a/src/gui/doc/images/cursor-forbidden.png b/src/gui/doc/images/cursor-forbidden.png Binary files differnew file mode 100644 index 0000000000..2b08c4e2a3 --- /dev/null +++ b/src/gui/doc/images/cursor-forbidden.png diff --git a/src/gui/doc/images/cursor-hand.png b/src/gui/doc/images/cursor-hand.png Binary files differnew file mode 100644 index 0000000000..d2004aefa7 --- /dev/null +++ b/src/gui/doc/images/cursor-hand.png diff --git a/src/gui/doc/images/cursor-hsplit.png b/src/gui/doc/images/cursor-hsplit.png Binary files differnew file mode 100644 index 0000000000..a5667e3ffb --- /dev/null +++ b/src/gui/doc/images/cursor-hsplit.png diff --git a/src/gui/doc/images/cursor-ibeam.png b/src/gui/doc/images/cursor-ibeam.png Binary files differnew file mode 100644 index 0000000000..097fc5fa72 --- /dev/null +++ b/src/gui/doc/images/cursor-ibeam.png diff --git a/src/gui/doc/images/cursor-openhand.png b/src/gui/doc/images/cursor-openhand.png Binary files differnew file mode 100644 index 0000000000..9181c859ed --- /dev/null +++ b/src/gui/doc/images/cursor-openhand.png diff --git a/src/gui/doc/images/cursor-sizeall.png b/src/gui/doc/images/cursor-sizeall.png Binary files differnew file mode 100644 index 0000000000..69f13eb347 --- /dev/null +++ b/src/gui/doc/images/cursor-sizeall.png diff --git a/src/gui/doc/images/cursor-sizeb.png b/src/gui/doc/images/cursor-sizeb.png Binary files differnew file mode 100644 index 0000000000..f37d7b91e8 --- /dev/null +++ b/src/gui/doc/images/cursor-sizeb.png diff --git a/src/gui/doc/images/cursor-sizef.png b/src/gui/doc/images/cursor-sizef.png Binary files differnew file mode 100644 index 0000000000..3b127a05d3 --- /dev/null +++ b/src/gui/doc/images/cursor-sizef.png diff --git a/src/gui/doc/images/cursor-sizeh.png b/src/gui/doc/images/cursor-sizeh.png Binary files differnew file mode 100644 index 0000000000..a9f40cbc3d --- /dev/null +++ b/src/gui/doc/images/cursor-sizeh.png diff --git a/src/gui/doc/images/cursor-sizev.png b/src/gui/doc/images/cursor-sizev.png Binary files differnew file mode 100644 index 0000000000..1edbab27a5 --- /dev/null +++ b/src/gui/doc/images/cursor-sizev.png diff --git a/src/gui/doc/images/cursor-uparrow.png b/src/gui/doc/images/cursor-uparrow.png Binary files differnew file mode 100644 index 0000000000..d3e70ef4c2 --- /dev/null +++ b/src/gui/doc/images/cursor-uparrow.png diff --git a/src/gui/doc/images/cursor-vsplit.png b/src/gui/doc/images/cursor-vsplit.png Binary files differnew file mode 100644 index 0000000000..1beda2570e --- /dev/null +++ b/src/gui/doc/images/cursor-vsplit.png diff --git a/src/gui/doc/images/cursor-wait.png b/src/gui/doc/images/cursor-wait.png Binary files differnew file mode 100644 index 0000000000..69056c479e --- /dev/null +++ b/src/gui/doc/images/cursor-wait.png diff --git a/src/gui/doc/images/cursor-whatsthis.png b/src/gui/doc/images/cursor-whatsthis.png Binary files differnew file mode 100644 index 0000000000..b47601c378 --- /dev/null +++ b/src/gui/doc/images/cursor-whatsthis.png diff --git a/src/gui/doc/images/hoverevents.png b/src/gui/doc/images/hoverevents.png Binary files differnew file mode 100644 index 0000000000..ccc079bdf1 --- /dev/null +++ b/src/gui/doc/images/hoverevents.png diff --git a/src/gui/doc/images/paintsystem-antialiasing.png b/src/gui/doc/images/paintsystem-antialiasing.png Binary files differnew file mode 100644 index 0000000000..1275841b93 --- /dev/null +++ b/src/gui/doc/images/paintsystem-antialiasing.png diff --git a/src/gui/doc/images/paintsystem-core.png b/src/gui/doc/images/paintsystem-core.png Binary files differnew file mode 100644 index 0000000000..7d6a8e591b --- /dev/null +++ b/src/gui/doc/images/paintsystem-core.png diff --git a/src/gui/doc/images/paintsystem-devices.png b/src/gui/doc/images/paintsystem-devices.png Binary files differnew file mode 100644 index 0000000000..7b81b7cbb8 --- /dev/null +++ b/src/gui/doc/images/paintsystem-devices.png diff --git a/src/gui/doc/images/paintsystem-fancygradient.png b/src/gui/doc/images/paintsystem-fancygradient.png Binary files differnew file mode 100644 index 0000000000..701df29e42 --- /dev/null +++ b/src/gui/doc/images/paintsystem-fancygradient.png diff --git a/src/gui/doc/images/paintsystem-gradients.png b/src/gui/doc/images/paintsystem-gradients.png Binary files differnew file mode 100644 index 0000000000..50b2ed3671 --- /dev/null +++ b/src/gui/doc/images/paintsystem-gradients.png diff --git a/src/gui/doc/images/paintsystem-icon.png b/src/gui/doc/images/paintsystem-icon.png Binary files differnew file mode 100644 index 0000000000..4623db0761 --- /dev/null +++ b/src/gui/doc/images/paintsystem-icon.png diff --git a/src/gui/doc/images/paintsystem-movie.png b/src/gui/doc/images/paintsystem-movie.png Binary files differnew file mode 100644 index 0000000000..992ea9edd4 --- /dev/null +++ b/src/gui/doc/images/paintsystem-movie.png diff --git a/src/gui/doc/images/paintsystem-painterpath.png b/src/gui/doc/images/paintsystem-painterpath.png Binary files differnew file mode 100644 index 0000000000..f8154f2634 --- /dev/null +++ b/src/gui/doc/images/paintsystem-painterpath.png diff --git a/src/gui/doc/images/paintsystem-stylepainter.png b/src/gui/doc/images/paintsystem-stylepainter.png Binary files differnew file mode 100644 index 0000000000..a67c6c5afc --- /dev/null +++ b/src/gui/doc/images/paintsystem-stylepainter.png diff --git a/src/gui/doc/images/paintsystem-svg.png b/src/gui/doc/images/paintsystem-svg.png Binary files differnew file mode 100644 index 0000000000..ecc8ef8f97 --- /dev/null +++ b/src/gui/doc/images/paintsystem-svg.png diff --git a/src/gui/doc/images/qcolor-cmyk.png b/src/gui/doc/images/qcolor-cmyk.png Binary files differnew file mode 100644 index 0000000000..dfe8f67a31 --- /dev/null +++ b/src/gui/doc/images/qcolor-cmyk.png diff --git a/src/gui/doc/images/qcolor-hsv.png b/src/gui/doc/images/qcolor-hsv.png Binary files differnew file mode 100644 index 0000000000..49fdf77222 --- /dev/null +++ b/src/gui/doc/images/qcolor-hsv.png diff --git a/src/gui/doc/images/qcolor-hue.png b/src/gui/doc/images/qcolor-hue.png Binary files differnew file mode 100644 index 0000000000..144b27c87a --- /dev/null +++ b/src/gui/doc/images/qcolor-hue.png diff --git a/src/gui/doc/images/qcolor-rgb.png b/src/gui/doc/images/qcolor-rgb.png Binary files differnew file mode 100644 index 0000000000..fea4c63fd7 --- /dev/null +++ b/src/gui/doc/images/qcolor-rgb.png diff --git a/src/gui/doc/images/qcolor-saturation.png b/src/gui/doc/images/qcolor-saturation.png Binary files differnew file mode 100644 index 0000000000..f28776aff5 --- /dev/null +++ b/src/gui/doc/images/qcolor-saturation.png diff --git a/src/gui/doc/images/qcolor-value.png b/src/gui/doc/images/qcolor-value.png Binary files differnew file mode 100644 index 0000000000..0e069123a9 --- /dev/null +++ b/src/gui/doc/images/qcolor-value.png diff --git a/src/gui/doc/images/qconicalgradient.png b/src/gui/doc/images/qconicalgradient.png Binary files differnew file mode 100644 index 0000000000..82603066fb --- /dev/null +++ b/src/gui/doc/images/qconicalgradient.png diff --git a/src/gui/doc/images/qgradient-conical.png b/src/gui/doc/images/qgradient-conical.png Binary files differnew file mode 100644 index 0000000000..cf06b70db6 --- /dev/null +++ b/src/gui/doc/images/qgradient-conical.png diff --git a/src/gui/doc/images/qgradient-linear.png b/src/gui/doc/images/qgradient-linear.png Binary files differnew file mode 100644 index 0000000000..5a5e880de7 --- /dev/null +++ b/src/gui/doc/images/qgradient-linear.png diff --git a/src/gui/doc/images/qgradient-radial.png b/src/gui/doc/images/qgradient-radial.png Binary files differnew file mode 100644 index 0000000000..95b9e9c3c9 --- /dev/null +++ b/src/gui/doc/images/qgradient-radial.png diff --git a/src/gui/doc/images/qimage-32bit_scaled.png b/src/gui/doc/images/qimage-32bit_scaled.png Binary files differnew file mode 100644 index 0000000000..6932327456 --- /dev/null +++ b/src/gui/doc/images/qimage-32bit_scaled.png diff --git a/src/gui/doc/images/qimage-8bit_scaled.png b/src/gui/doc/images/qimage-8bit_scaled.png Binary files differnew file mode 100644 index 0000000000..7cbf0f1e29 --- /dev/null +++ b/src/gui/doc/images/qimage-8bit_scaled.png diff --git a/src/gui/doc/images/qimage-scaling.png b/src/gui/doc/images/qimage-scaling.png Binary files differnew file mode 100644 index 0000000000..fcd71448f0 --- /dev/null +++ b/src/gui/doc/images/qimage-scaling.png diff --git a/src/gui/doc/images/qlineargradient-pad.png b/src/gui/doc/images/qlineargradient-pad.png Binary files differnew file mode 100644 index 0000000000..d77eb3dc3d --- /dev/null +++ b/src/gui/doc/images/qlineargradient-pad.png diff --git a/src/gui/doc/images/qlineargradient-reflect.png b/src/gui/doc/images/qlineargradient-reflect.png Binary files differnew file mode 100644 index 0000000000..dd12665051 --- /dev/null +++ b/src/gui/doc/images/qlineargradient-reflect.png diff --git a/src/gui/doc/images/qlineargradient-repeat.png b/src/gui/doc/images/qlineargradient-repeat.png Binary files differnew file mode 100644 index 0000000000..e38203c438 --- /dev/null +++ b/src/gui/doc/images/qlineargradient-repeat.png diff --git a/src/gui/doc/images/qmatrix-combinedtransformation.png b/src/gui/doc/images/qmatrix-combinedtransformation.png Binary files differnew file mode 100644 index 0000000000..f791bfa917 --- /dev/null +++ b/src/gui/doc/images/qmatrix-combinedtransformation.png diff --git a/src/gui/doc/images/qmatrix-representation.png b/src/gui/doc/images/qmatrix-representation.png Binary files differnew file mode 100644 index 0000000000..2e3efd33fc --- /dev/null +++ b/src/gui/doc/images/qmatrix-representation.png diff --git a/src/gui/doc/images/qmatrix-simpletransformation.png b/src/gui/doc/images/qmatrix-simpletransformation.png Binary files differnew file mode 100644 index 0000000000..dde8f4bc58 --- /dev/null +++ b/src/gui/doc/images/qmatrix-simpletransformation.png diff --git a/src/gui/doc/images/qpainter-affinetransformations.png b/src/gui/doc/images/qpainter-affinetransformations.png Binary files differnew file mode 100644 index 0000000000..fe2f9a072b --- /dev/null +++ b/src/gui/doc/images/qpainter-affinetransformations.png diff --git a/src/gui/doc/images/qpainter-arc.png b/src/gui/doc/images/qpainter-arc.png Binary files differnew file mode 100644 index 0000000000..8cb9cec96b --- /dev/null +++ b/src/gui/doc/images/qpainter-arc.png diff --git a/src/gui/doc/images/qpainter-basicdrawing.png b/src/gui/doc/images/qpainter-basicdrawing.png Binary files differnew file mode 100644 index 0000000000..3be48c8737 --- /dev/null +++ b/src/gui/doc/images/qpainter-basicdrawing.png diff --git a/src/gui/doc/images/qpainter-chord.png b/src/gui/doc/images/qpainter-chord.png Binary files differnew file mode 100644 index 0000000000..a8090861a0 --- /dev/null +++ b/src/gui/doc/images/qpainter-chord.png diff --git a/src/gui/doc/images/qpainter-clock.png b/src/gui/doc/images/qpainter-clock.png Binary files differnew file mode 100644 index 0000000000..3634754161 --- /dev/null +++ b/src/gui/doc/images/qpainter-clock.png diff --git a/src/gui/doc/images/qpainter-compositiondemo.png b/src/gui/doc/images/qpainter-compositiondemo.png Binary files differnew file mode 100644 index 0000000000..40f62c75be --- /dev/null +++ b/src/gui/doc/images/qpainter-compositiondemo.png diff --git a/src/gui/doc/images/qpainter-compositionmode1.png b/src/gui/doc/images/qpainter-compositionmode1.png Binary files differnew file mode 100644 index 0000000000..6753093521 --- /dev/null +++ b/src/gui/doc/images/qpainter-compositionmode1.png diff --git a/src/gui/doc/images/qpainter-compositionmode2.png b/src/gui/doc/images/qpainter-compositionmode2.png Binary files differnew file mode 100644 index 0000000000..fc05afbd8c --- /dev/null +++ b/src/gui/doc/images/qpainter-compositionmode2.png diff --git a/src/gui/doc/images/qpainter-concentriccircles.png b/src/gui/doc/images/qpainter-concentriccircles.png Binary files differnew file mode 100644 index 0000000000..4889dcd76d --- /dev/null +++ b/src/gui/doc/images/qpainter-concentriccircles.png diff --git a/src/gui/doc/images/qpainter-ellipse.png b/src/gui/doc/images/qpainter-ellipse.png Binary files differnew file mode 100644 index 0000000000..e7e78c3dac --- /dev/null +++ b/src/gui/doc/images/qpainter-ellipse.png diff --git a/src/gui/doc/images/qpainter-gradients.png b/src/gui/doc/images/qpainter-gradients.png Binary files differnew file mode 100644 index 0000000000..b7bc6a3270 --- /dev/null +++ b/src/gui/doc/images/qpainter-gradients.png diff --git a/src/gui/doc/images/qpainter-line.png b/src/gui/doc/images/qpainter-line.png Binary files differnew file mode 100644 index 0000000000..5f1cd97eff --- /dev/null +++ b/src/gui/doc/images/qpainter-line.png diff --git a/src/gui/doc/images/qpainter-painterpaths.png b/src/gui/doc/images/qpainter-painterpaths.png Binary files differnew file mode 100644 index 0000000000..0762ca93f3 --- /dev/null +++ b/src/gui/doc/images/qpainter-painterpaths.png diff --git a/src/gui/doc/images/qpainter-path.png b/src/gui/doc/images/qpainter-path.png Binary files differnew file mode 100644 index 0000000000..3570b16d7a --- /dev/null +++ b/src/gui/doc/images/qpainter-path.png diff --git a/src/gui/doc/images/qpainter-pathstroking.png b/src/gui/doc/images/qpainter-pathstroking.png Binary files differnew file mode 100644 index 0000000000..ab73c6ae01 --- /dev/null +++ b/src/gui/doc/images/qpainter-pathstroking.png diff --git a/src/gui/doc/images/qpainter-pie.png b/src/gui/doc/images/qpainter-pie.png Binary files differnew file mode 100644 index 0000000000..78039013e0 --- /dev/null +++ b/src/gui/doc/images/qpainter-pie.png diff --git a/src/gui/doc/images/qpainter-polygon.png b/src/gui/doc/images/qpainter-polygon.png Binary files differnew file mode 100644 index 0000000000..3b6ea3c797 --- /dev/null +++ b/src/gui/doc/images/qpainter-polygon.png diff --git a/src/gui/doc/images/qpainter-rectangle.png b/src/gui/doc/images/qpainter-rectangle.png Binary files differnew file mode 100644 index 0000000000..05fdc88300 --- /dev/null +++ b/src/gui/doc/images/qpainter-rectangle.png diff --git a/src/gui/doc/images/qpainter-rotation.png b/src/gui/doc/images/qpainter-rotation.png Binary files differnew file mode 100644 index 0000000000..6e24a0e040 --- /dev/null +++ b/src/gui/doc/images/qpainter-rotation.png diff --git a/src/gui/doc/images/qpainter-roundrect.png b/src/gui/doc/images/qpainter-roundrect.png Binary files differnew file mode 100644 index 0000000000..876a277811 --- /dev/null +++ b/src/gui/doc/images/qpainter-roundrect.png diff --git a/src/gui/doc/images/qpainter-scale.png b/src/gui/doc/images/qpainter-scale.png Binary files differnew file mode 100644 index 0000000000..4fe582eb13 --- /dev/null +++ b/src/gui/doc/images/qpainter-scale.png diff --git a/src/gui/doc/images/qpainter-text.png b/src/gui/doc/images/qpainter-text.png Binary files differnew file mode 100644 index 0000000000..e95c965d7b --- /dev/null +++ b/src/gui/doc/images/qpainter-text.png diff --git a/src/gui/doc/images/qpainter-translation.png b/src/gui/doc/images/qpainter-translation.png Binary files differnew file mode 100644 index 0000000000..b3716ca3f6 --- /dev/null +++ b/src/gui/doc/images/qpainter-translation.png diff --git a/src/gui/doc/images/qpainter-vectordeformation.png b/src/gui/doc/images/qpainter-vectordeformation.png Binary files differnew file mode 100644 index 0000000000..aff95f404c --- /dev/null +++ b/src/gui/doc/images/qpainter-vectordeformation.png diff --git a/src/gui/doc/images/qpainterpath-addellipse.png b/src/gui/doc/images/qpainterpath-addellipse.png Binary files differnew file mode 100644 index 0000000000..98f85174ef --- /dev/null +++ b/src/gui/doc/images/qpainterpath-addellipse.png diff --git a/src/gui/doc/images/qpainterpath-addpolygon.png b/src/gui/doc/images/qpainterpath-addpolygon.png Binary files differnew file mode 100644 index 0000000000..d36bde8ada --- /dev/null +++ b/src/gui/doc/images/qpainterpath-addpolygon.png diff --git a/src/gui/doc/images/qpainterpath-addrectangle.png b/src/gui/doc/images/qpainterpath-addrectangle.png Binary files differnew file mode 100644 index 0000000000..be9283e46d --- /dev/null +++ b/src/gui/doc/images/qpainterpath-addrectangle.png diff --git a/src/gui/doc/images/qpainterpath-addtext.png b/src/gui/doc/images/qpainterpath-addtext.png Binary files differnew file mode 100644 index 0000000000..803a9581ac --- /dev/null +++ b/src/gui/doc/images/qpainterpath-addtext.png diff --git a/src/gui/doc/images/qpainterpath-arcto.png b/src/gui/doc/images/qpainterpath-arcto.png Binary files differnew file mode 100644 index 0000000000..fe60b08d31 --- /dev/null +++ b/src/gui/doc/images/qpainterpath-arcto.png diff --git a/src/gui/doc/images/qpainterpath-construction.png b/src/gui/doc/images/qpainterpath-construction.png Binary files differnew file mode 100644 index 0000000000..4beeba1dd8 --- /dev/null +++ b/src/gui/doc/images/qpainterpath-construction.png diff --git a/src/gui/doc/images/qpainterpath-cubicto.png b/src/gui/doc/images/qpainterpath-cubicto.png Binary files differnew file mode 100644 index 0000000000..465bfeca29 --- /dev/null +++ b/src/gui/doc/images/qpainterpath-cubicto.png diff --git a/src/gui/doc/images/qpainterpath-demo.png b/src/gui/doc/images/qpainterpath-demo.png Binary files differnew file mode 100644 index 0000000000..ceeed2f170 --- /dev/null +++ b/src/gui/doc/images/qpainterpath-demo.png diff --git a/src/gui/doc/images/qpainterpath-example.png b/src/gui/doc/images/qpainterpath-example.png Binary files differnew file mode 100644 index 0000000000..f2bd359aba --- /dev/null +++ b/src/gui/doc/images/qpainterpath-example.png diff --git a/src/gui/doc/images/qpen-bevel.png b/src/gui/doc/images/qpen-bevel.png Binary files differnew file mode 100644 index 0000000000..8a30779e3b --- /dev/null +++ b/src/gui/doc/images/qpen-bevel.png diff --git a/src/gui/doc/images/qpen-custom.png b/src/gui/doc/images/qpen-custom.png Binary files differnew file mode 100644 index 0000000000..a2a038abe0 --- /dev/null +++ b/src/gui/doc/images/qpen-custom.png diff --git a/src/gui/doc/images/qpen-dash.png b/src/gui/doc/images/qpen-dash.png Binary files differnew file mode 100644 index 0000000000..67082c3758 --- /dev/null +++ b/src/gui/doc/images/qpen-dash.png diff --git a/src/gui/doc/images/qpen-dashdot.png b/src/gui/doc/images/qpen-dashdot.png Binary files differnew file mode 100644 index 0000000000..64b384660f --- /dev/null +++ b/src/gui/doc/images/qpen-dashdot.png diff --git a/src/gui/doc/images/qpen-dashdotdot.png b/src/gui/doc/images/qpen-dashdotdot.png Binary files differnew file mode 100644 index 0000000000..ff1b2e69cd --- /dev/null +++ b/src/gui/doc/images/qpen-dashdotdot.png diff --git a/src/gui/doc/images/qpen-dashpattern.png b/src/gui/doc/images/qpen-dashpattern.png Binary files differnew file mode 100644 index 0000000000..e33cf58d49 --- /dev/null +++ b/src/gui/doc/images/qpen-dashpattern.png diff --git a/src/gui/doc/images/qpen-demo.png b/src/gui/doc/images/qpen-demo.png Binary files differnew file mode 100644 index 0000000000..3ea5108802 --- /dev/null +++ b/src/gui/doc/images/qpen-demo.png diff --git a/src/gui/doc/images/qpen-dot.png b/src/gui/doc/images/qpen-dot.png Binary files differnew file mode 100644 index 0000000000..54e81c9469 --- /dev/null +++ b/src/gui/doc/images/qpen-dot.png diff --git a/src/gui/doc/images/qpen-flat.png b/src/gui/doc/images/qpen-flat.png Binary files differnew file mode 100644 index 0000000000..06e2195f73 --- /dev/null +++ b/src/gui/doc/images/qpen-flat.png diff --git a/src/gui/doc/images/qpen-miter.png b/src/gui/doc/images/qpen-miter.png Binary files differnew file mode 100644 index 0000000000..025e003979 --- /dev/null +++ b/src/gui/doc/images/qpen-miter.png diff --git a/src/gui/doc/images/qpen-miterlimit.png b/src/gui/doc/images/qpen-miterlimit.png Binary files differnew file mode 100644 index 0000000000..17a90725fb --- /dev/null +++ b/src/gui/doc/images/qpen-miterlimit.png diff --git a/src/gui/doc/images/qpen-roundcap.png b/src/gui/doc/images/qpen-roundcap.png Binary files differnew file mode 100644 index 0000000000..77b22b2bab --- /dev/null +++ b/src/gui/doc/images/qpen-roundcap.png diff --git a/src/gui/doc/images/qpen-roundjoin.png b/src/gui/doc/images/qpen-roundjoin.png Binary files differnew file mode 100644 index 0000000000..155e2aa8cc --- /dev/null +++ b/src/gui/doc/images/qpen-roundjoin.png diff --git a/src/gui/doc/images/qpen-solid.png b/src/gui/doc/images/qpen-solid.png Binary files differnew file mode 100644 index 0000000000..e042b18017 --- /dev/null +++ b/src/gui/doc/images/qpen-solid.png diff --git a/src/gui/doc/images/qpen-square.png b/src/gui/doc/images/qpen-square.png Binary files differnew file mode 100644 index 0000000000..ebc5d1e329 --- /dev/null +++ b/src/gui/doc/images/qpen-square.png diff --git a/src/gui/doc/images/qradialgradient-pad.png b/src/gui/doc/images/qradialgradient-pad.png Binary files differnew file mode 100644 index 0000000000..6c1a6cb268 --- /dev/null +++ b/src/gui/doc/images/qradialgradient-pad.png diff --git a/src/gui/doc/images/qradialgradient-reflect.png b/src/gui/doc/images/qradialgradient-reflect.png Binary files differnew file mode 100644 index 0000000000..5122b180b1 --- /dev/null +++ b/src/gui/doc/images/qradialgradient-reflect.png diff --git a/src/gui/doc/images/qradialgradient-repeat.png b/src/gui/doc/images/qradialgradient-repeat.png Binary files differnew file mode 100644 index 0000000000..aa639b7779 --- /dev/null +++ b/src/gui/doc/images/qradialgradient-repeat.png diff --git a/src/gui/doc/images/qrect-diagram-zero.png b/src/gui/doc/images/qrect-diagram-zero.png Binary files differnew file mode 100644 index 0000000000..90e3db0c41 --- /dev/null +++ b/src/gui/doc/images/qrect-diagram-zero.png diff --git a/src/gui/doc/images/qrectf-diagram-one.png b/src/gui/doc/images/qrectf-diagram-one.png Binary files differnew file mode 100644 index 0000000000..842289ce07 --- /dev/null +++ b/src/gui/doc/images/qrectf-diagram-one.png diff --git a/src/gui/doc/images/qrectf-diagram-three.png b/src/gui/doc/images/qrectf-diagram-three.png Binary files differnew file mode 100644 index 0000000000..e05106a7e1 --- /dev/null +++ b/src/gui/doc/images/qrectf-diagram-three.png diff --git a/src/gui/doc/images/qrectf-diagram-two.png b/src/gui/doc/images/qrectf-diagram-two.png Binary files differnew file mode 100644 index 0000000000..192d00df79 --- /dev/null +++ b/src/gui/doc/images/qrectf-diagram-two.png diff --git a/src/gui/doc/images/qstatustipevent-action.png b/src/gui/doc/images/qstatustipevent-action.png Binary files differnew file mode 100644 index 0000000000..c5dcfd25f5 --- /dev/null +++ b/src/gui/doc/images/qstatustipevent-action.png diff --git a/src/gui/doc/images/qstatustipevent-widget.png b/src/gui/doc/images/qstatustipevent-widget.png Binary files differnew file mode 100644 index 0000000000..3cc0a1f01b --- /dev/null +++ b/src/gui/doc/images/qstatustipevent-widget.png diff --git a/src/gui/doc/images/qt-fillrule-oddeven.png b/src/gui/doc/images/qt-fillrule-oddeven.png Binary files differnew file mode 100644 index 0000000000..f39d1056f5 --- /dev/null +++ b/src/gui/doc/images/qt-fillrule-oddeven.png diff --git a/src/gui/doc/images/qt-fillrule-winding.png b/src/gui/doc/images/qt-fillrule-winding.png Binary files differnew file mode 100644 index 0000000000..8018248331 --- /dev/null +++ b/src/gui/doc/images/qt-fillrule-winding.png diff --git a/src/gui/doc/images/qtexttableformat-cell.png b/src/gui/doc/images/qtexttableformat-cell.png Binary files differnew file mode 100644 index 0000000000..bbf85ffe46 --- /dev/null +++ b/src/gui/doc/images/qtexttableformat-cell.png diff --git a/src/gui/doc/images/qtransform-combinedtransformation.png b/src/gui/doc/images/qtransform-combinedtransformation.png Binary files differnew file mode 100644 index 0000000000..df1e226746 --- /dev/null +++ b/src/gui/doc/images/qtransform-combinedtransformation.png diff --git a/src/gui/doc/images/qtransform-combinedtransformation2.png b/src/gui/doc/images/qtransform-combinedtransformation2.png Binary files differnew file mode 100644 index 0000000000..c037a0d565 --- /dev/null +++ b/src/gui/doc/images/qtransform-combinedtransformation2.png diff --git a/src/gui/doc/images/qtransform-representation.png b/src/gui/doc/images/qtransform-representation.png Binary files differnew file mode 100644 index 0000000000..883d5dc487 --- /dev/null +++ b/src/gui/doc/images/qtransform-representation.png diff --git a/src/gui/doc/images/qtransform-simpletransformation.png b/src/gui/doc/images/qtransform-simpletransformation.png Binary files differnew file mode 100644 index 0000000000..743e4e3e07 --- /dev/null +++ b/src/gui/doc/images/qtransform-simpletransformation.png diff --git a/src/gui/doc/images/texttable-merge.png b/src/gui/doc/images/texttable-merge.png Binary files differnew file mode 100644 index 0000000000..3b32239a42 --- /dev/null +++ b/src/gui/doc/images/texttable-merge.png diff --git a/src/gui/doc/images/texttable-split.png b/src/gui/doc/images/texttable-split.png Binary files differnew file mode 100644 index 0000000000..2fa17b85a3 --- /dev/null +++ b/src/gui/doc/images/texttable-split.png diff --git a/src/gui/doc/qtgui.qdocconf b/src/gui/doc/qtgui.qdocconf new file mode 100644 index 0000000000..85772bbc3e --- /dev/null +++ b/src/gui/doc/qtgui.qdocconf @@ -0,0 +1,92 @@ +include(../../../doc/global/qt-cpp-ignore.qdocconf) + +project = QtGui +description = Qt GUI Reference Documentation +url = http://qt-project.org/doc/qt-5.0/qtgui +version = 5.0.0 + +sourceencoding = UTF-8 +outputencoding = UTF-8 +naturallanguage = en_US +qhp.projects = QtGui + +qhp.QtGui.file = qtgui.qhp +qhp.QtGui.namespace = org.qt-project.qtgui.500 +qhp.QtGui.virtualFolder = qdoc +qhp.QtGui.indexTitle = Qt GUI Reference Documentation +qhp.QtGui.indexRoot = + +qhp.QtGui.filterAttributes = qtgui 5.0.0 qtrefdoc +qhp.QtGui.customFilters.Qt.name = Qtgui 5.0.0 +qhp.QtGui.customFilters.Qt.filterAttributes = qtgui 5.0.0 +qhp.QtGui.subprojects = classes overviews examples +qhp.QtGui.subprojects.classes.title = Classes +qhp.QtGui.subprojects.classes.indexTitle = Qt GUI's Classes +qhp.QtGui.subprojects.classes.selectors = class fake:headerfile +qhp.QtGui.subprojects.classes.sortPages = true +qhp.QtGui.subprojects.overviews.title = Overviews +qhp.QtGui.subprojects.overviews.indexTitle = All Overviews and HOWTOs +qhp.QtGui.subprojects.overviews.selectors = fake:page,group,module +qhp.QtGui.subprojects.examples.title = Qt GUI Examples +qhp.QtGui.subprojects.examples.indexTitle = Qt GUI Examples +qhp.QtGui.subprojects.examples.selectors = fake:example + +dita.metadata.default.author = Qt Project +dita.metadata.default.permissions = all +dita.metadata.default.publisher = Qt Project +dita.metadata.default.copyryear = 2012 +dita.metadata.default.copyrholder = Nokia +dita.metadata.default.audience = programmer + +sources.fileextensions = "*.c++ *.cc *.cpp *.cxx *.mm *.qml *.qdoc" +headers.fileextensions = "*.ch *.h *.h++ *.hh *.hpp *.hxx" + +examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml *.css" +examples.imageextensions = "*.png" + +outputdir = ../../../doc/qtgui +tagfile = ../../../doc/qtgui/qtgui.tags + +HTML.generatemacrefs = "true" +HTML.nobreadcrumbs = "true" + +HTML.templatedir = . + +HTML.stylesheets = ../../../doc/global/style/offline.css + +HTML.headerstyles = \ + " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/offline.css\" />\n" + +HTML.endheader = \ + "</head>\n" \ + +defines = Q_QDOC \ + QT_.*_SUPPORT \ + QT_.*_LIB \ + QT_COMPAT \ + QT_KEYPAD_NAVIGATION \ + QT_NO_EGL \ + Q_WS_.* \ + Q_OS_.* \ + Q_BYTE_ORDER \ + QT_DEPRECATED \ + QT_DEPRECATED_* \ + Q_NO_USING_KEYWORD \ + __cplusplus \ + Q_COMPILER_INITIALIZER_LISTS + +versionsym = QT_VERSION_STR + +codeindent = 1 + +depends += qtcore + +headerdirs += .. + +sourcedirs += .. + +exampledirs += ../../../examples \ + ../ \ + snippets + +imagedirs += images diff --git a/src/gui/doc/snippets/brush/brush.cpp b/src/gui/doc/snippets/brush/brush.cpp new file mode 100644 index 0000000000..a92223ee93 --- /dev/null +++ b/src/gui/doc/snippets/brush/brush.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +int main() +{ + QWidget anyPaintDevice; + { + // PEN SNIPPET + QPainter painter; + QPen pen(Qt::red, 2); // red solid line, 2 pixels wide + painter.begin(&anyPaintDevice); // paint something + painter.setPen(pen); // set the red, wide pen + painter.drawRect(40,30, 200,100); // draw a rectangle + painter.setPen(Qt::blue); // set blue pen, 0 pixel width + painter.drawLine(40,30, 240,130); // draw a diagonal in rectangle + painter.end(); // painting done + } + + { + // BRUSH SNIPPET + QPainter painter; + QBrush brush(Qt::yellow); // yellow solid pattern + painter.begin(&anyPaintDevice); // paint something + painter.setBrush(brush); // set the yellow brush + painter.setPen(Qt::NoPen); // do not draw outline + painter.drawRect(40,30, 200,100); // draw filled rectangle + painter.setBrush(Qt::NoBrush); // do not fill + painter.setPen(Qt::black); // set black pen, 0 pixel width + painter.drawRect(10,10, 30,20); // draw rectangle outline + painter.end(); // painting done + } + + // LINEAR +//! [0] + QLinearGradient linearGrad(QPointF(100, 100), QPointF(200, 200)); + linearGrad.setColorAt(0, Qt::black); + linearGrad.setColorAt(1, Qt::white); +//! [0] + + // RADIAL +//! [1] + QRadialGradient radialGrad(QPointF(100, 100), 100); + radialGrad.setColorAt(0, Qt::red); + radialGrad.setColorAt(0.5, Qt::blue); + radialGrad.setColorAt(1, Qt::green); +//! [1] +} diff --git a/src/gui/doc/snippets/brush/gradientcreationsnippet.cpp b/src/gui/doc/snippets/brush/gradientcreationsnippet.cpp new file mode 100644 index 0000000000..9ec8c3f07a --- /dev/null +++ b/src/gui/doc/snippets/brush/gradientcreationsnippet.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +int main(int argv, char **args) +{ + QApplication app(argv, args); + +//! [0] + QRadialGradient gradient(50, 50, 50, 50, 50); + gradient.setColorAt(0, QColor::fromRgbF(0, 1, 0, 1)); + gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0)); + + QBrush brush(gradient); +//! [0] + + QWidget widget; + QPalette palette; + palette.setBrush(widget.backgroundRole(), brush); + widget.setPalette(palette); + widget.show(); + + return app.exec(); +} diff --git a/src/gui/doc/snippets/code/doc_src_coordsys.cpp b/src/gui/doc/snippets/code/doc_src_coordsys.cpp new file mode 100644 index 0000000000..b677d28a50 --- /dev/null +++ b/src/gui/doc/snippets/code/doc_src_coordsys.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QPainter painter(this); + +painter.setPen(Qt::darkGreen); +painter.drawRect(1, 2, 6, 4); +//! [0] + + +//! [1] +QPainter painter(this); + +painter.setPen(Qt::darkGreen); +painter.drawLine(2, 7, 6, 1); +//! [1] + + +//! [2] +QPainter painter(this); +painter.setRenderHint( + QPainter::Antialiasing); +painter.setPen(Qt::darkGreen); +painter.drawRect(1, 2, 6, 4); +//! [2] + + +//! [3] +QPainter painter(this); +painter.setRenderHint( + QPainter::Antialiasing); +painter.setPen(Qt::darkGreen); +painter.drawLine(2, 7, 6, 1); +//! [3] + + +//! [4] +QPainter painter(this); +painter.setWindow(QRect(-50, -50, 100, 100)); +//! [4] + + +//! [5] +int side = qMin(width(), height()) +int x = (width() - side / 2); +int y = (height() - side / 2); + +painter.setViewport(x, y, side, side); +//! [5] diff --git a/src/gui/doc/snippets/code/doc_src_qtgui.pro b/src/gui/doc/snippets/code/doc_src_qtgui.pro new file mode 100644 index 0000000000..51bb6c74ff --- /dev/null +++ b/src/gui/doc/snippets/code/doc_src_qtgui.pro @@ -0,0 +1,3 @@ +#! [0] +#include <QtGui> +#! [0] diff --git a/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp b/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp new file mode 100644 index 0000000000..f12f55051e --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [1] +typedef QAccessibleInterface* myFactoryFunction(const QString &key, QObject *); +//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_image_qimage.cpp b/src/gui/doc/snippets/code/src_gui_image_qimage.cpp new file mode 100644 index 0000000000..0c39e22eb6 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_image_qimage.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QImage image(3, 3, QImage::Format_RGB32); +QRgb value; + +value = qRgb(189, 149, 39); // 0xffbd9527 +image.setPixel(1, 1, value); + +value = qRgb(122, 163, 39); // 0xff7aa327 +image.setPixel(0, 1, value); +image.setPixel(1, 0, value); + +value = qRgb(237, 187, 51); // 0xffedba31 +image.setPixel(2, 1, value); +//! [0] + + +//! [1] +QImage image(3, 3, QImage::Format_Indexed8); +QRgb value; + +value = qRgb(122, 163, 39); // 0xff7aa327 +image.setColor(0, value); + +value = qRgb(237, 187, 51); // 0xffedba31 +image.setColor(1, value); + +value = qRgb(189, 149, 39); // 0xffbd9527 +image.setColor(2, value); + +image.setPixel(0, 1, 0); +image.setPixel(1, 0, 0); +image.setPixel(1, 1, 2); +image.setPixel(2, 1, 1); +//! [1] + + +//! [2] +static const char * const start_xpm[] = { + "16 15 8 1", + "a c #cec6bd", +.... +//! [2] diff --git a/src/gui/doc/snippets/code/src_gui_image_qimagereader.cpp b/src/gui/doc/snippets/code/src_gui_image_qimagereader.cpp new file mode 100644 index 0000000000..92f528e6c0 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_image_qimagereader.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QImageReader reader; +reader.setFormat("png"); // same as reader.setFormat("PNG"); +//! [0] + + +//! [1] +QImageReader reader("image.png"); +// reader.format() == "png" +//! [1] + + +//! [2] +QImage icon(64, 64, QImage::Format_RGB32); +QImageReader reader("icon_64x64.bmp"); +if (reader.read(&icon)) { + // Display icon +} +//! [2] + + +//! [3] +QImageReader reader(":/image.png"); +if (reader.supportsOption(QImageIOHandler::Size)) + qDebug() << "Size:" << reader.size(); +//! [3] diff --git a/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp b/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp new file mode 100644 index 0000000000..d0f11929d3 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QImageWriter writer; +writer.setFormat("png"); // same as writer.setFormat("PNG"); +//! [0] + + +//! [1] +QImage image("some/image.jpeg"); +QImageWriter writer("images/outimage.png", "png"); +writer.setText("Author", "John Smith"); +writer.write(image); +//! [1] + + +//! [2] +QImageWriter writer(fileName); +if (writer.supportsOption(QImageIOHandler::Description)) + writer.setText("Author", "John Smith"); +//! [2] diff --git a/src/gui/doc/snippets/code/src_gui_image_qmovie.cpp b/src/gui/doc/snippets/code/src_gui_image_qmovie.cpp new file mode 100644 index 0000000000..5d57d19204 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_image_qmovie.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QLabel label; +QMovie *movie = new QMovie("animations/fire.gif"); + +label.setMovie(movie); +movie->start(); +//! [0] + + +//! [1] +QMovie movie("racecar.gif"); +movie.setSpeed(200); // 2x speed +//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_image_qpixmap.cpp b/src/gui/doc/snippets/code/src_gui_image_qpixmap.cpp new file mode 100644 index 0000000000..b8c0fcfbd5 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_image_qpixmap.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +static const char * const start_xpm[]={ + "16 15 8 1", + "a c #cec6bd", +.... +//! [0] + + +//! [1] +QPixmap myPixmap; +myPixmap->setMask(myPixmap->createHeuristicMask()); +//! [1] + +//! [2] +QPixmap pixmap("background.png"); +QRegion exposed; +pixmap.scroll(10, 10, pixmap.rect(), &exposed); +//! [2] diff --git a/src/gui/doc/snippets/code/src_gui_image_qpixmapcache.cpp b/src/gui/doc/snippets/code/src_gui_image_qpixmapcache.cpp new file mode 100644 index 0000000000..9d42f6b330 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_image_qpixmapcache.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QPixmap* pp; +QPixmap p; +if ((pp=QPixmapCache::find("my_big_image", pm))) { + p = *pp; +} else { + p.load("bigimage.png"); + QPixmapCache::insert("my_big_image", new QPixmap(p)); +} +painter->drawPixmap(0, 0, p); +//! [0] + + +//! [1] +QPixmap pm; +if (!QPixmapCache::find("my_big_image", &pm)) { + pm.load("bigimage.png"); + QPixmapCache::insert("my_big_image", pm); +} +painter->drawPixmap(0, 0, pm); +//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp new file mode 100644 index 0000000000..b32e8c3f39 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +int main(int argc, char **argv) +{ +#ifdef Q_WS_X11 + bool useGUI = getenv("DISPLAY") != 0; +#else + bool useGUI = true; +#endif + QApplication app(argc, argv, useGUI); + + if (useGUI) { + // start GUI version + ... + } else { + // start non-GUI version + ... + } + return app.exec(); +} +//! [0] + + +//! [1] +QApplication::setStyle(new QWindowsStyle); +//! [1] + + +//! [2] +int main(int argc, char *argv[]) +{ + QApplication::setColorSpec(QApplication::ManyColor); + QApplication app(argc, argv); + ... + return app.exec(); +} +//! [2] + + +//! [3] +QSize MyWidget::sizeHint() const +{ + return QSize(80, 25).expandedTo(QApplication::globalStrut()); +} +//! [3] + + +//! [4] +void showAllHiddenTopLevelWidgets() +{ + foreach (QWidget *widget, QApplication::topLevelWidgets()) { + if (widget->isHidden()) + widget->show(); + } +} +//! [4] + + +//! [5] +void updateAllWidgets() +{ + foreach (QWidget *widget, QApplication::allWidgets()) + widget->update(); +} +//! [5] + + +//! [6] +int main(int argc, char *argv[]) +{ + QApplication::setDesktopSettingsAware(false); + QApplication app(argc, argv); + ... + return app.exec(); +} +//! [6] + + +//! [7] +if ((startPos - currentPos).manhattanLength() >= + QApplication::startDragDistance()) + startTheDrag(); +//! [7] + + +//! [8] +void MyApplication::commitData(QSessionManager& manager) +{ + if (manager.allowsInteraction()) { + int ret = QMessageBox::warning( + mainWindow, + tr("My Application"), + tr("Save changes to document?"), + QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + + switch (ret) { + case QMessageBox::Save: + manager.release(); + if (!saveDocument()) + manager.cancel(); + break; + case QMessageBox::Discard: + break; + case QMessageBox::Cancel: + default: + manager.cancel(); + } + } else { + // we did not get permission to interact, then + // do something reasonable instead + } +} +//! [8] + + +//! [9] +appname -session id +//! [9] + + +//! [10] +foreach (const QString &command, mySession.restartCommand()) + do_something(command); +//! [10] + + +//! [11] +foreach (const QString &command, mySession.discardCommand()) + do_something(command); +//! [11] + + +//! [12] +QWidget *widget = qApp->widgetAt(x, y); +if (widget) + widget = widget->window(); +//! [12] + + +//! [13] +QWidget *widget = qApp->widgetAt(point); +if (widget) + widget = widget->window(); +//! [13] diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qapplication_x11.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qapplication_x11.cpp new file mode 100644 index 0000000000..1d37765e3c --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_kernel_qapplication_x11.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); +calculateHugeMandelbrot(); // lunch time... +QApplication::restoreOverrideCursor(); +//! [0] diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp new file mode 100644 index 0000000000..4cf8f33c02 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QClipboard *clipboard = QApplication::clipboard(); +QString originalText = clipboard->text(); +... +clipboard->setText(newText); +//! [0] + + +//! [1] +QMimeData *data = new QMimeData; +data->setImageData(image); +clipboard->setMimeData(data, mode); +//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp new file mode 100644 index 0000000000..d8bdeebe84 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +void MyWidget::wheelEvent(QWheelEvent *event) +{ + QPoint numPixels = envent->pixelDelta(); + QPoint numDegrees = envent->angleDelta() / 8; + + if (!numPixels.isNull()) { + scrollWithPixels(numpixels); + } else if (!numDegrees.isNull()) { + QPoint numSteps = numDegrees / 15; + scrollWithDegrees(numSteps); + } + + event->accept(); +} +//! [0] diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp new file mode 100644 index 0000000000..79dc967cf3 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QKeySequence(QKeySequence::Print); +QKeySequence(tr("Ctrl+P")); +QKeySequence(tr("Ctrl+p")); +QKeySequence(Qt::CTRL + Qt::Key_P); +//! [0] + + +//! [1] +QKeySequence(tr("Ctrl+X, Ctrl+C")); +QKeySequence(Qt::CTRL + Qt::Key_X, Qt::CTRL + Qt::Key_C); +//! [1] + + +//! [2] +QMenu *file = new QMenu(this); +file->addAction(tr("&Open..."), this, SLOT(open()), + QKeySequence(tr("Ctrl+O", "File|Open"))); +//! [2] diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp new file mode 100644 index 0000000000..d761e31d3d --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +key = QKeySequence(); +//! [0] diff --git a/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp b/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp new file mode 100644 index 0000000000..8678c48d62 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QPainter painter(this); + +painter.setBrush(Qt::cyan); +painter.setPen(Qt::darkCyan); +painter.drawRect(0, 0, 100,100); + +painter.setBrush(Qt::NoBrush); +painter.setPen(Qt::darkGreen); +painter.drawRect(40, 40, 100, 100); +//! [0] diff --git a/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp b/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp new file mode 100644 index 0000000000..8954fed604 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +// Specify semi-transparent red +painter.setBrush(QColor(255, 0, 0, 127)); +painter.drawRect(0, 0, width()/2, height()); + +// Specify semi-transparent blue +painter.setBrush(QColor(0, 0, 255, 127)); +painter.drawRect(0, 0, width(), height()/2); +//! [0] diff --git a/src/gui/doc/snippets/code/src_gui_painting_qmatrix.cpp b/src/gui/doc/snippets/code/src_gui_painting_qmatrix.cpp new file mode 100644 index 0000000000..d4e1b57b3c --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_painting_qmatrix.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [0] + + +//! [1] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [1] + + +//! [2] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [2] + + +//! [3] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [3] diff --git a/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp b/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp new file mode 100644 index 0000000000..8caffa46f4 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp @@ -0,0 +1,259 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +void SimpleExampleWidget::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setPen(Qt::blue); + painter.setFont(QFont("Arial", 30)); + painter.drawText(rect(), Qt::AlignCenter, "Qt"); +} +//! [0] + + +//! [1] +void MyWidget::paintEvent(QPaintEvent *) +{ + QPainter p; + p.begin(this); + p.drawLine(...); // drawing code + p.end(); +} +//! [1] + + +//! [2] +void MyWidget::paintEvent(QPaintEvent *) +{ + QPainter p(this); + p.drawLine(...); // drawing code +} +//! [2] + + +//! [3] +painter->begin(0); // impossible - paint device cannot be 0 + +QPixmap image(0, 0); +painter->begin(&image); // impossible - image.isNull() == true; + +painter->begin(myWidget); +painter2->begin(myWidget); // impossible - only one painter at a time +//! [3] + + +//! [4] +void QPainter::rotate(qreal angle) +{ + QMatrix matrix; + matrix.rotate(angle); + setWorldMatrix(matrix, true); +} +//! [4] + + +//! [5] +QPainterPath path; +path.moveTo(20, 80); +path.lineTo(20, 30); +path.cubicTo(80, 0, 50, 50, 80, 80); + +QPainter painter(this); +painter.drawPath(path); +//! [5] + + +//! [6] +QLineF line(10.0, 80.0, 90.0, 20.0); + +QPainter(this); +painter.drawLine(line); +//! [6] + + +//! [7] +QRectF rectangle(10.0, 20.0, 80.0, 60.0); + +QPainter painter(this); +painter.drawRect(rectangle); +//! [7] + + +//! [8] +QRectF rectangle(10.0, 20.0, 80.0, 60.0); + +QPainter painter(this); +painter.drawRoundedRect(rectangle, 20.0, 15.0); +//! [8] + + +//! [9] +QRectF rectangle(10.0, 20.0, 80.0, 60.0); + +QPainter painter(this); +painter.drawEllipse(rectangle); +//! [9] + + +//! [10] +QRectF rectangle(10.0, 20.0, 80.0, 60.0); +int startAngle = 30 * 16; +int spanAngle = 120 * 16; + +QPainter painter(this); +painter.drawArc(rectangle, startAngle, spanAngle); +//! [10] + + +//! [11] +QRectF rectangle(10.0, 20.0, 80.0, 60.0); +int startAngle = 30 * 16; +int spanAngle = 120 * 16; + +QPainter painter(this); +painter.drawPie(rectangle, startAngle, spanAngle); +//! [11] + + +//! [12] +QRectF rectangle(10.0, 20.0, 80.0, 60.0); +int startAngle = 30 * 16; +int spanAngle = 120 * 16; + +QPainter painter(this); +painter.drawChord(rect, startAngle, spanAngle); +//! [12] + + +//! [13] +static const QPointF points[3] = { + QPointF(10.0, 80.0), + QPointF(20.0, 10.0), + QPointF(80.0, 30.0), +}; + +QPainter painter(this); +painter.drawPolyline(points, 3); +//! [13] + + +//! [14] +static const QPointF points[4] = { + QPointF(10.0, 80.0), + QPointF(20.0, 10.0), + QPointF(80.0, 30.0), + QPointF(90.0, 70.0) +}; + +QPainter painter(this); +painter.drawPolygon(points, 4); +//! [14] + + +//! [15] +static const QPointF points[4] = { + QPointF(10.0, 80.0), + QPointF(20.0, 10.0), + QPointF(80.0, 30.0), + QPointF(90.0, 70.0) +}; + +QPainter painter(this); +painter.drawConvexPolygon(points, 4); +//! [15] + + +//! [16] +QRectF target(10.0, 20.0, 80.0, 60.0); +QRectF source(0.0, 0.0, 70.0, 40.0); +QPixmap pixmap(":myPixmap.png"); + +QPainter(this); +painter.drawPixmap(target, image, source); +//! [16] + + +//! [17] +QPainter painter(this); +painter.drawText(rect, Qt::AlignCenter, tr("Qt by\nNokia")); +//! [17] + + +//! [18] +QPicture picture; +QPointF point(10.0, 20.0) +picture.load("drawing.pic"); + +QPainter painter(this); +painter.drawPicture(0, 0, picture); +//! [18] + + +//! [19] +fillRect(rectangle, background()). +//! [19] + + +//! [20] +QRectF target(10.0, 20.0, 80.0, 60.0); +QRectF source(0.0, 0.0, 70.0, 40.0); +QImage image(":/images/myImage.png"); + +QPainter painter(this); +painter.drawImage(target, image, source); +//! [20] + + +//! [21] +QPainter painter(this); +painter.fillRect(0, 0, 128, 128, Qt::green); +painter.beginNativePainting(); + +glEnable(GL_SCISSOR_TEST); +glScissor(0, 0, 64, 64); + +glClearColor(1, 0, 0, 1); +glClear(GL_COLOR_BUFFER_BIT); + +glDisable(GL_SCISSOR_TEST); + +painter.endNativePainting(); +//! [21] diff --git a/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp b/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp new file mode 100644 index 0000000000..b23f8cea23 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QPainterPath path; +path.addRect(20, 20, 60, 60); + +path.moveTo(0, 0); +path.cubicTo(99, 0, 50, 50, 99, 99); +path.cubicTo(0, 99, 50, 50, 0, 0); + +QPainter painter(this); +painter.fillRect(0, 0, 100, 100, Qt::white); +painter.setPen(QPen(QColor(79, 106, 25), 1, Qt::SolidLine, + Qt::FlatCap, Qt::MiterJoin)); +painter.setBrush(QColor(122, 163, 39)); + +painter.drawPath(path); +//! [0] + + +//! [1] +QLinearGradient myGradient; +QPen myPen; + +QPainterPath myPath; +myPath.cubicTo(c1, c2, endPoint); + +QPainter painter(this); +painter.setBrush(myGradient); +painter.setPen(myPen); +painter.drawPath(myPath); +//! [1] + + +//! [2] +QLinearGradient myGradient; +QPen myPen; + +QPointF center, startPoint; + +QPainterPath myPath; +myPath.moveTo(center); +myPath.arcTo(boundingRect, startAngle, + sweepLength); + +QPainter painter(this); +painter.setBrush(myGradient); +painter.setPen(myPen); +painter.drawPath(myPath); +//! [2] + + +//! [3] +QLinearGradient myGradient; +QPen myPen; +QRectF myRectangle; + +QPainterPath myPath; +myPath.addRect(myRectangle); + +QPainter painter(this); +painter.setBrush(myGradient); +painter.setPen(myPen); +painter.drawPath(myPath); +//! [3] + + +//! [4] +QLinearGradient myGradient; +QPen myPen; +QPolygonF myPolygon; + +QPainterPath myPath; +myPath.addPolygon(myPolygon); + +QPainter painter(this); +painter.setBrush(myGradient); +painter.setPen(myPen); +painter.drawPath(myPath); +//! [4] + + +//! [5] +QLinearGradient myGradient; +QPen myPen; +QRectF boundingRectangle; + +QPainterPath myPath; +myPath.addEllipse(boundingRectangle); + +QPainter painter(this); +painter.setBrush(myGradient); +painter.setPen(myPen); +painter.drawPath(myPath); +//! [5] + + +//! [6] +QLinearGradient myGradient; +QPen myPen; +QFont myFont; +QPointF baseline(x, y); + +QPainterPath myPath; +myPath.addText(baseline, myFont, tr("Qt")); + +QPainter painter(this); +painter.setBrush(myGradient); +painter.setPen(myPen); +painter.drawPath(myPath); +//! [6] diff --git a/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp b/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp new file mode 100644 index 0000000000..4da729b88d --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QPainter painter(this); +QPen pen(Qt::green, 3, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin); +painter.setPen(pen); +//! [0] + + +//! [1] +QPainter painter(this); +QPen pen; // creates a default pen + +pen.setStyle(Qt::DashDotLine); +pen.setWidth(3); +pen.setBrush(Qt::green); +pen.setCapStyle(Qt::RoundCap); +pen.setJoinStyle(Qt::RoundJoin); + +painter.setPen(pen); +//! [1] + + +//! [2] +QPen pen; +QVector<qreal> dashes; +qreal space = 4; + +dashes << 1 << space << 3 << space << 9 << space + << 27 << space << 9 << space; + +pen.setDashPattern(dashes); +//! [2] + + +//! [3] +QPen pen; +QVector<qreal> dashes; +qreal space = 4; +dashes << 1 << space << 3 << space << 9 << space + << 27 << space << 9 << space; +pen.setDashPattern(dashes); +//! [3] diff --git a/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp b/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp new file mode 100644 index 0000000000..8f334c5695 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +void MyWidget::paintEvent(QPaintEvent *) +{ + QRegion r1(QRect(100, 100, 200, 80), // r1: elliptic region + QRegion::Ellipse); + QRegion r2(QRect(100, 120, 90, 30)); // r2: rectangular region + QRegion r3 = r1.intersected(r2); // r3: intersection + + QPainter painter(this); + painter.setClipRegion(r3); + ... // paint clipped graphics +} +//! [0] diff --git a/src/gui/doc/snippets/code/src_gui_painting_qregion_unix.cpp b/src/gui/doc/snippets/code/src_gui_painting_qregion_unix.cpp new file mode 100644 index 0000000000..63b9de19d1 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_painting_qregion_unix.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QRegion r1(10, 10, 20, 20); +r1.isEmpty(); // false + +QRegion r3; +r3.isEmpty(); // true + +QRegion r2(40, 40, 20, 20); +r3 = r1.intersected(r2); // r3: intersection of r1 and r2 +r3.isEmpty(); // true + +r3 = r1.united(r2); // r3: union of r1 and r2 +r3.isEmpty(); // false +//! [0] diff --git a/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp b/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp new file mode 100644 index 0000000000..f54e0a07ca --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if (is not affine) { + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +} +//! [0] + + +//! [1] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if (is not affine) { + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +} +//! [1] + + +//! [2] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if (is not affine) { + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +} +//! [2] + + +//! [3] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if (is not affine) { + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +} +//! [3] diff --git a/src/gui/doc/snippets/code/src_gui_qopenglshaderprogram.cpp b/src/gui/doc/snippets/code/src_gui_qopenglshaderprogram.cpp new file mode 100644 index 0000000000..637527036f --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_qopenglshaderprogram.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QOpenGLShader shader(QOpenGLShader::Vertex); +shader.compileSourceCode(code); + +QOpenGLShaderProgram program(context); +program.addShader(shader); +program.link(); + +program.bind(); +//! [0] + +//! [1] +program.addShaderFromSourceCode(QOpenGLShader::Vertex, + "attribute highp vec4 vertex;\n" + "uniform highp mat4 matrix;\n" + "void main(void)\n" + "{\n" + " gl_Position = matrix * vertex;\n" + "}"); +program.addShaderFromSourceCode(QOpenGLShader::Fragment, + "uniform mediump vec4 color;\n" + "void main(void)\n" + "{\n" + " gl_FragColor = color;\n" + "}"); +program.link(); +program.bind(); + +int vertexLocation = program.attributeLocation("vertex"); +int matrixLocation = program.uniformLocation("matrix"); +int colorLocation = program.uniformLocation("color"); +//! [1] + +//! [2] +static GLfloat const triangleVertices[] = { + 60.0f, 10.0f, 0.0f, + 110.0f, 110.0f, 0.0f, + 10.0f, 110.0f, 0.0f +}; + +QColor color(0, 255, 0, 255); + +QMatrix4x4 pmvMatrix; +pmvMatrix.ortho(rect()); + +program.enableAttributeArray(vertexLocation); +program.setAttributeArray(vertexLocation, triangleVertices, 3); +program.setUniformValue(matrixLocation, pmvMatrix); +program.setUniformValue(colorLocation, color); + +glDrawArrays(GL_TRIANGLES, 0, 3); + +program.disableAttributeArray(vertexLocation); +//! [2] diff --git a/src/gui/doc/snippets/code/src_gui_text_qfont.cpp b/src/gui/doc/snippets/code/src_gui_text_qfont.cpp new file mode 100644 index 0000000000..fab550cbc7 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_text_qfont.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QFont serifFont("Times", 10, QFont::Bold); +QFont sansFont("Helvetica [Cronyx]", 12); +//! [0] + + +//! [1] +QFont f("Helvetica"); +//! [1] + + +//! [2] +QFont f("Helvetica [Cronyx]"); +//! [2] + + +//! [3] +QFontInfo info(f1); +QString family = info.family(); +//! [3] + + +//! [4] +QFontMetrics fm(f1); +int textWidthInPixels = fm.width("How many pixels wide is this text?"); +int textHeightInPixels = fm.height(); +//! [4] diff --git a/src/gui/doc/snippets/code/src_gui_text_qfontmetrics.cpp b/src/gui/doc/snippets/code/src_gui_text_qfontmetrics.cpp new file mode 100644 index 0000000000..b864b4ddcc --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_text_qfontmetrics.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QFont font("times", 24); +QFontMetrics fm(font); +int pixelsWide = fm.width("What's the width of this text?"); +int pixelsHigh = fm.height(); +//! [0] + + +//! [1] +QFont font("times", 24); +QFontMetricsF fm(font); +qreal pixelsWide = fm.width("What's the width of this text?"); +qreal pixelsHigh = fm.height(); +//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_text_qsyntaxhighlighter.cpp b/src/gui/doc/snippets/code/src_gui_text_qsyntaxhighlighter.cpp new file mode 100644 index 0000000000..3fb6b35bb9 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_text_qsyntaxhighlighter.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QTextEdit *editor = new QTextEdit; +MyHighlighter *highlighter = new MyHighlighter(editor->document()); +//! [0] + + +//! [1] +void MyHighlighter::highlightBlock(const QString &text) +{ + QTextCharFormat myClassFormat; + myClassFormat.setFontWeight(QFont::Bold); + myClassFormat.setForeground(Qt::darkMagenta); + QString pattern = "\\bMy[A-Za-z]+\\b"; + + QRegExp expression(pattern); + int index = text.indexOf(expression); + while (index >= 0) { + int length = expression.matchedLength(); + setFormat(index, length, myClassFormat); + index = text.indexOf(expression, index + length); + } +} +//! [1] + + +//! [2] +QTextCharFormat multiLineCommentFormat; +multiLineCommentFormat.setForeground(Qt::red); + +QRegExp startExpression("/\\*"); +QRegExp endExpression("\\*/"); + +setCurrentBlockState(0); + +int startIndex = 0; +if (previousBlockState() != 1) + startIndex = text.indexOf(startExpression); + +while (startIndex >= 0) { + int endIndex = text.indexOf(endExpression, startIndex); + int commentLength; + if (endIndex == -1) { + setCurrentBlockState(1); + commentLength = text.length() - startIndex; + } else { + commentLength = endIndex - startIndex + + endExpression.matchedLength(); + } + setFormat(startIndex, commentLength, multiLineCommentFormat); + startIndex = text.indexOf(startExpression, + startIndex + commentLength); +} +//! [2] + + +//! [3] +void MyHighlighter::highlightBlock(const QString &text) +{ + QTextCharFormat myClassFormat; + myClassFormat.setFontWeight(QFont::Bold); + myClassFormat.setForeground(Qt::darkMagenta); + QString pattern = "\\bMy[A-Za-z]+\\b"; + + QRegExp expression(pattern); + int index = text.indexOf(expression); + while (index >= 0) { + int length = expression.matchedLength(); + setFormat(index, length, myClassFormat); + index = text.indexOf(expression, index + length); + } + } +//! [3] + + +//! [4] +struct ParenthesisInfo +{ + QChar char; + int position; +}; + +struct BlockData : public QTextBlockUserData +{ + QVector<ParenthesisInfo> parentheses; +}; +//! [4] diff --git a/src/gui/doc/snippets/code/src_gui_text_qtextcursor.cpp b/src/gui/doc/snippets/code/src_gui_text_qtextcursor.cpp new file mode 100644 index 0000000000..7954f66cbd --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_text_qtextcursor.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +cursor.clearSelection(); +cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); +cursor.insertText("Hello World"); +//! [0] + + +//! [1] +QImage img = ... +textDocument->addResource(QTextDocument::ImageResource, QUrl("myimage"), img); +cursor.insertImage("myimage"); +//! [1] + + +//! [2] +QTextCursor cursor(textDocument); +cursor.beginEditBlock(); +cursor.insertText("Hello"); +cursor.insertText("World"); +cursor.endEditBlock(); + +textDocument->undo(); +//! [2] + + +//! [3] +QTextCursor cursor(textDocument); +cursor.beginEditBlock(); +cursor.insertText("Hello"); +cursor.insertText("World"); +cursor.endEditBlock(); + +... + +cursor.joinPreviousEditBlock(); +cursor.insertText("Hey"); +cursor.endEditBlock(); + +textDocument->undo(); +//! [3] diff --git a/src/gui/doc/snippets/code/src_gui_text_qtextdocument.cpp b/src/gui/doc/snippets/code/src_gui_text_qtextdocument.cpp new file mode 100644 index 0000000000..23ebf8b2d2 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_text_qtextdocument.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>... +//! [0] diff --git a/src/gui/doc/snippets/code/src_gui_text_qtextdocumentwriter.cpp b/src/gui/doc/snippets/code/src_gui_text_qtextdocumentwriter.cpp new file mode 100644 index 0000000000..59ef46c422 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_text_qtextdocumentwriter.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QTextDocumentWriter writer; + writer.setFormat("odf"); // same as writer.setFormat("ODF"); +//! [0] + diff --git a/src/gui/doc/snippets/code/src_gui_text_qtextlayout.cpp b/src/gui/doc/snippets/code/src_gui_text_qtextlayout.cpp new file mode 100644 index 0000000000..c8e1d2e010 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_text_qtextlayout.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +int leading = fontMetrics.leading(); +qreal height = 0; +textLayout.beginLayout(); +while (1) { + QTextLine line = textLayout.createLine(); + if (!line.isValid()) + break; + + line.setLineWidth(lineWidth); + height += leading; + line.setPosition(QPointF(0, height)); + height += line.height(); +} +textLayout.endLayout(); +//! [0] + + +//! [1] +QPainter painter(this); +textLayout.draw(&painter, QPoint(0, 0)); +//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp b/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp new file mode 100644 index 0000000000..0b4739841b --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MyHelpHandler : public QObject +{ + Q_OBJECT +public: + ... +public slots: + void showHelp(const QUrl &url); +}; + +QDesktopServices::setUrlHandler("help", helpInstance, "showHelp"); +//! [0] + +//! [1] +mailto:user@foo.com?subject=Test&body=Just a test +//! [1] + +//! [2] +QDesktopServices::openUrl(QUrl("file:///C:/Documents and Settings/All Users/Desktop", QUrl::TolerantMode)); +//! [2] diff --git a/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp b/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp new file mode 100644 index 0000000000..2f769c5860 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QValidator *validator = new QIntValidator(100, 999, this); +QLineEdit *edit = new QLineEdit(this); + +// the edit lineedit will only accept integers between 100 and 999 +edit->setValidator(validator); +//! [0] + + +//! [1] +QString str; +int pos = 0; +QIntValidator v(100, 900, this); + +str = "1"; +v.validate(str, pos); // returns Intermediate +str = "012"; +v.validate(str, pos); // returns Intermediate + +str = "123"; +v.validate(str, pos); // returns Acceptable +str = "678"; +v.validate(str, pos); // returns Acceptable + +str = "999"; +v.validate(str, pos); // returns Intermediate + +str = "1234"; +v.validate(str, pos); // returns Invalid +str = "-123"; +v.validate(str, pos); // returns Invalid +str = "abc"; +v.validate(str, pos); // returns Invalid +str = "12cm"; +v.validate(str, pos); // returns Invalid +//! [1] + + +//! [2] +int pos = 0; + +s = "abc"; +v.validate(s, pos); // returns Invalid + +s = "5"; +v.validate(s, pos); // returns Intermediate + +s = "50"; +v.validate(s, pos); // returns Acceptable +//! [2] + + +//! [3] +// regexp: optional '-' followed by between 1 and 3 digits +QRegExp rx("-?\\d{1,3}"); +QValidator *validator = new QRegExpValidator(rx, this); + +QLineEdit *edit = new QLineEdit(this); +edit->setValidator(validator); +//! [3] + + +//! [4] +// integers 1 to 9999 +QRegExp rx("[1-9]\\d{0,3}"); +// the validator treats the regexp as "^[1-9]\\d{0,3}$" +QRegExpValidator v(rx, 0); +QString s; +int pos = 0; + +s = "0"; v.validate(s, pos); // returns Invalid +s = "12345"; v.validate(s, pos); // returns Invalid +s = "1"; v.validate(s, pos); // returns Acceptable + +rx.setPattern("\\S+"); // one or more non-whitespace characters +v.setRegExp(rx); +s = "myfile.txt"; v.validate(s, pos); // Returns Acceptable +s = "my file.txt"; v.validate(s, pos); // Returns Invalid + +// A, B or C followed by exactly five digits followed by W, X, Y or Z +rx.setPattern("[A-C]\\d{5}[W-Z]"); +v.setRegExp(rx); +s = "a12345Z"; v.validate(s, pos); // Returns Invalid +s = "A12345Z"; v.validate(s, pos); // Returns Acceptable +s = "B12"; v.validate(s, pos); // Returns Intermediate + +// match most 'readme' files +rx.setPattern("read\\S?me(\.(txt|asc|1st))?"); +rx.setCaseSensitive(false); +v.setRegExp(rx); +s = "readme"; v.validate(s, pos); // Returns Acceptable +s = "README.1ST"; v.validate(s, pos); // Returns Acceptable +s = "read me.txt"; v.validate(s, pos); // Returns Invalid +s = "readm"; v.validate(s, pos); // Returns Intermediate +//! [4] diff --git a/src/gui/doc/snippets/dragging/mainwindow.cpp b/src/gui/doc/snippets/dragging/mainwindow.cpp new file mode 100644 index 0000000000..57f1abc22d --- /dev/null +++ b/src/gui/doc/snippets/dragging/mainwindow.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + QFrame *centralFrame = new QFrame(this); + + QLabel *nameLabel = new QLabel(tr("Comment:"), centralFrame); + commentEdit = new QTextEdit(centralFrame); + QLabel *dragLabel = new QLabel(tr("<p>Drag the icon to a filer " + "window or the desktop background:</p>"), + centralFrame); + iconLabel = new QLabel(centralFrame); + iconPixmap.load(":/images/file.png"); + iconLabel->setPixmap(iconPixmap); + + QGridLayout *grid = new QGridLayout(centralFrame); + grid->addWidget(nameLabel, 0, 0); + grid->addWidget(commentEdit, 1, 0, 1, 2); + grid->addWidget(dragLabel, 2, 0); + grid->addWidget(iconLabel, 2, 1); + + statusBar(); + setCentralWidget(centralFrame); + setWindowTitle(tr("Dragging")); +} + +//! [0] +void MainWindow::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton + && iconLabel->geometry().contains(event->pos())) { + +//! [1] + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + mimeData->setText(commentEdit->toPlainText()); + drag->setMimeData(mimeData); +//! [1] + drag->setPixmap(iconPixmap); + + Qt::DropAction dropAction = drag->exec(); +//! [0] + + QString actionText; + switch (dropAction) { + case Qt::CopyAction: + actionText = tr("The text was copied."); + break; + case Qt::MoveAction: + actionText = tr("The text was moved."); + break; + case Qt::LinkAction: + actionText = tr("The text was linked."); + break; + case Qt::IgnoreAction: + actionText = tr("The drag was ignored."); + break; + default: + actionText = tr("Unknown action."); + break; + } + statusBar()->showMessage(actionText); +//! [2] + } +} +//! [2] diff --git a/src/gui/doc/snippets/droparea.cpp b/src/gui/doc/snippets/droparea.cpp new file mode 100644 index 0000000000..27d52d1b89 --- /dev/null +++ b/src/gui/doc/snippets/droparea.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "droparea.h" + +DropArea::DropArea(QWidget *parent) + : QLabel(parent) +{ + setMinimumSize(200, 200); + setFrameStyle(QFrame::Sunken | QFrame::StyledPanel); + setAlignment(Qt::AlignCenter); + setAcceptDrops(true); + setAutoFillBackground(true); + clear(); +} + +void DropArea::dragEnterEvent(QDragEnterEvent *event) +{ + setText(tr("<drop content>")); + setBackgroundRole(QPalette::Highlight); + + event->acceptProposedAction(); + emit changed(event->mimeData()); +} + +void DropArea::dragMoveEvent(QDragMoveEvent *event) +{ + event->acceptProposedAction(); +} + +void DropArea::dropEvent(QDropEvent *event) +{ + const QMimeData *mimeData = event->mimeData(); + + if (mimeData->hasImage()) { + setPixmap(qvariant_cast<QPixmap>(mimeData->imageData())); + } else if (mimeData->hasHtml()) { + setText(mimeData->html()); + setTextFormat(Qt::RichText); + } else if (mimeData->hasText()) { + setText(mimeData->text()); + setTextFormat(Qt::PlainText); + } else { + setText(tr("Cannot display data")); + } + + setBackgroundRole(QPalette::Dark); + event->acceptProposedAction(); +} + +//![0] +void DropArea::paste() +{ + const QClipboard *clipboard = QApplication::clipboard(); + const QMimeData *mimeData = clipboard->mimeData(); + + if (mimeData->hasImage()) { + setPixmap(qvariant_cast<QPixmap>(mimeData->imageData())); + } else if (mimeData->hasHtml()) { + setText(mimeData->html()); + setTextFormat(Qt::RichText); + } else if (mimeData->hasText()) { + setText(mimeData->text()); + setTextFormat(Qt::PlainText); + } else { + setText(tr("Cannot display data")); + } +//![0] + + emit changed(mimeData); + setBackgroundRole(QPalette::Dark); + //event->acceptProposedAction(); +} + +void DropArea::dragLeaveEvent(QDragLeaveEvent *event) +{ + clear(); + event->accept(); +} + +void DropArea::clear() +{ + setText(tr("<drop content>")); + setBackgroundRole(QPalette::Dark); + + emit changed(); +} + +QPixmap DropArea::extractPixmap(const QByteArray &data, const QString &format) +{ + QList<QByteArray> imageFormats = QImageReader::supportedImageFormats(); + QPixmap pixmap; + + foreach (const QByteArray &imageFormat, imageFormats) { + if (format.mid(6) == QString(imageFormat)) { + pixmap.loadFromData(data, imageFormat); + break; + } + } + return pixmap; +} diff --git a/src/gui/doc/snippets/image/image.cpp b/src/gui/doc/snippets/image/image.cpp new file mode 100644 index 0000000000..1dfe41f8cd --- /dev/null +++ b/src/gui/doc/snippets/image/image.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +int main() +{ + int x, y; + { + // BIT ACCESS + QImage image; + // sets bit at (x, y) to 1 + if (image.format() == QImage::Format_MonoLSB) + image.scanLine(y)[x >> 3] |= 1 << (x & 7); + else + image.scanLine(y)[x >> 3] |= 1 << (7 - (x & 7)); + } + + { + // 8-BIT ACCESS + QImage image; + // set entry 19 in the color table to yellow + image.setColor(19, qRgb(255, 255, 0)); + + // set 8 bit pixel at (x,y) to value yellow (in color table) + image.scanLine(y)[x] = 19; + } + + { + // 32-BIT + QImage image; + // sets 32 bit pixel at (x,y) to yellow. + uint *ptr = reinterpret_cast<uint *>(image.scanLine(y)) + x; + *ptr = qRgb(255, 255, 0); + } + + { + // SAVE +//! [0] + QImage image; + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "PNG"); // writes image into ba in PNG format +//! [0] + } + + { + // PIX SAVE +//! [1] + QPixmap pixmap; + QByteArray bytes; + QBuffer buffer(&bytes); + buffer.open(QIODevice::WriteOnly); + pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format +//! [1] + } + + { + // MASK +//! [2] + QPixmap alpha("image-with-alpha.png"); + QPixmap alphacopy = alpha; + alphacopy.setMask(alphacopy.mask()); +//! [2] + } +} diff --git a/src/gui/doc/snippets/image/supportedformat.cpp b/src/gui/doc/snippets/image/supportedformat.cpp new file mode 100644 index 0000000000..6d481908e8 --- /dev/null +++ b/src/gui/doc/snippets/image/supportedformat.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +int main(int argv, char **args) +{ +//! [0] + QImageWriter writer; + writer.setFormat("png"); + if (writer.supportsOption(QImageIOHandler::Description)) + qDebug() << "Png supports embedded text"; +//! [0] + return 0; +} diff --git a/src/gui/doc/snippets/matrix/matrix.cpp b/src/gui/doc/snippets/matrix/matrix.cpp new file mode 100644 index 0000000000..2aa2606fc6 --- /dev/null +++ b/src/gui/doc/snippets/matrix/matrix.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include <cmath> + +class SimpleTransformation : public QWidget +{ + void paintEvent(QPaintEvent *); +}; + +//! [0] +void SimpleTransformation::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setPen(QPen(Qt::blue, 1, Qt::DashLine)); + painter.drawRect(0, 0, 100, 100); + + painter.rotate(45); + + painter.setFont(QFont("Helvetica", 24)); + painter.setPen(QPen(Qt::black, 1)); + painter.drawText(20, 10, "QMatrix"); +} +//! [0] + +class CombinedTransformation : public QWidget +{ + void paintEvent(QPaintEvent *); +}; + +//! [1] +void CombinedTransformation::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setPen(QPen(Qt::blue, 1, Qt::DashLine)); + painter.drawRect(0, 0, 100, 100); + + QMatrix matrix; + matrix.translate(50, 50); + matrix.rotate(45); + matrix.scale(0.5, 1.0); + painter.setMatrix(matrix); + + painter.setFont(QFont("Helvetica", 24)); + painter.setPen(QPen(Qt::black, 1)); + painter.drawText(20, 10, "QMatrix"); +} +//! [1] + +class BasicOperations : public QWidget +{ + void paintEvent(QPaintEvent *); +}; + +//! [2] +void BasicOperations::paintEvent(QPaintEvent *) +{ + double pi = 3.14; + + double a = pi/180 * 45.0; + double sina = sin(a); + double cosa = cos(a); + + QMatrix translationMatrix(1, 0, 0, 1, 50.0, 50.0); + QMatrix rotationMatrix(cosa, sina, -sina, cosa, 0, 0); + QMatrix scalingMatrix(0.5, 0, 0, 1.0, 0, 0); + + QMatrix matrix; + matrix = scalingMatrix * rotationMatrix * translationMatrix; + + QPainter painter(this); + painter.setPen(QPen(Qt::blue, 1, Qt::DashLine)); + painter.drawRect(0, 0, 100, 100); + + painter.setMatrix(matrix); + + painter.setFont(QFont("Helvetica", 24)); + painter.setPen(QPen(Qt::black, 1)); + painter.drawText(20, 10, "QMatrix"); +} +//! [2] + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QWidget widget; + + SimpleTransformation *simpleWidget = new SimpleTransformation; + CombinedTransformation *combinedWidget = new CombinedTransformation; + BasicOperations *basicWidget = new BasicOperations; + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(simpleWidget); + layout->addWidget(combinedWidget); + layout->addWidget(basicWidget); + widget.setLayout(layout); + + widget.show(); + widget.resize(130, 350); + return app.exec(); +} diff --git a/src/gui/doc/snippets/picture/picture.cpp b/src/gui/doc/snippets/picture/picture.cpp new file mode 100644 index 0000000000..8de5e32323 --- /dev/null +++ b/src/gui/doc/snippets/picture/picture.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +void myProcessing(const QString &) +{ +} + +int main() +{ + QWidget myWidget; + { + // RECORD +//! [0] + QPicture picture; + QPainter painter; + painter.begin(&picture); // paint in picture + painter.drawEllipse(10,20, 80,70); // draw an ellipse + painter.end(); // painting done + picture.save("drawing.pic"); // save picture +//! [0] + } + + { + // REPLAY +//! [1] + QPicture picture; + picture.load("drawing.pic"); // load picture + QPainter painter; + painter.begin(&myImage); // paint in myImage + painter.drawPicture(0, 0, picture); // draw the picture at (0,0) + painter.end(); // painting done +//! [1] + } + + QPicture myPicture; + { + // FORMATS +//! [2] + QStringList list = QPicture::inputFormatList(); + foreach (const QString &string, list) + myProcessing(string); +//! [2] + } + + { + // OUTPUT +//! [3] + QStringList list = QPicture::outputFormatList(); + foreach (const QString &string, list) + myProcessing(string); +//! [3] + } + + { + // PIC READ +//! [4] + QPictureIO iio; + QPixmap pixmap; + iio.setFileName("vegeburger.pic"); + if (iio.read()) { // OK + QPicture picture = iio.picture(); + QPainter painter(&pixmap); + painter.drawPicture(0, 0, picture); + } +//! [4] + } + + { + QPixmap pixmap; + // PIC WRITE +//! [5] + QPictureIO iio; + QPicture picture; + QPainter painter(&picture); + painter.drawPixmap(0, 0, pixmap); + iio.setPicture(picture); + iio.setFileName("vegeburger.pic"); + iio.setFormat("PIC"); + if (iio.write()) + return true; // returned true if written successfully +//! [5] + } + +} + +// SVG READ +//! [6] +void readSVG(QPictureIO *picture) +{ + // read the picture using the picture->ioDevice() +} +//! [6] + +// SVG WRITE +//! [7] +void writeSVG(QPictureIO *picture) +{ + // write the picture using the picture->ioDevice() +} +//! [7] + +// USE SVG +void foo() { + +//! [8] + // add the SVG picture handler + // ... +//! [8] + QPictureIO::defineIOHandler("SVG", 0, 0, readSVG, writeSVG); + // ... + +} diff --git a/src/gui/doc/snippets/polygon/polygon.cpp b/src/gui/doc/snippets/polygon/polygon.cpp new file mode 100644 index 0000000000..432156f8e6 --- /dev/null +++ b/src/gui/doc/snippets/polygon/polygon.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +int main() +{ + { + // STREAM +//! [0] + QPolygon polygon; + polygon << QPoint(10, 20) << QPoint(20, 30); +//! [0] + } + + { + // STREAMF +//! [1] + QPolygonF polygon; + polygon << QPointF(10.4, 20.5) << QPointF(20.2, 30.2); +//! [1] + } + + { + // SETPOINTS +//! [2] + static const int points[] = { 10, 20, 30, 40 }; + QPolygon polygon; + polygon.setPoints(2, points); +//! [2] + } + + { + // SETPOINTS2 +//! [3] + QPolygon polygon; + polygon.setPoints(2, 10, 20, 30, 40); +//! [3] + } + + { + // PUTPOINTS +//! [4] + QPolygon polygon(1); + polygon[0] = QPoint(4, 5); + polygon.putPoints(1, 2, 6,7, 8,9); +//! [4] + } + + { + // PUTPOINTS2 +//! [5] + QPolygon polygon(3); + polygon.putPoints(0, 3, 4,5, 0,0, 8,9); + polygon.putPoints(1, 1, 6,7); +//! [5] + } + + { + // PUTPOINTS3 +//! [6] + QPolygon polygon1; + polygon1.putPoints(0, 3, 1,2, 0,0, 5,6); + // polygon1 is now the three-point polygon(1,2, 0,0, 5,6); + + QPolygon polygon2; + polygon2.putPoints(0, 3, 4,4, 5,5, 6,6); + // polygon2 is now (4,4, 5,5, 6,6); + + polygon1.putPoints(2, 3, polygon2); + // polygon1 is now the five-point polygon(1,2, 0,0, 4,4, 5,5, 6,6); +//! [6] + } + return 0; +} diff --git a/src/gui/doc/snippets/qfontdatabase/main.cpp b/src/gui/doc/snippets/qfontdatabase/main.cpp new file mode 100644 index 0000000000..8e98e309a0 --- /dev/null +++ b/src/gui/doc/snippets/qfontdatabase/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + +//! [0] + QFontDatabase database; + QTreeWidget fontTree; + fontTree.setColumnCount(2); + fontTree.setHeaderLabels(QStringList() << "Font" << "Smooth Sizes"); + + foreach (const QString &family, database.families()) { + QTreeWidgetItem *familyItem = new QTreeWidgetItem(&fontTree); + familyItem->setText(0, family); + + foreach (const QString &style, database.styles(family)) { + QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem); + styleItem->setText(0, style); + + QString sizes; + foreach (int points, database.smoothSizes(family, style)) + sizes += QString::number(points) + " "; + + styleItem->setText(1, sizes.trimmed()); + } +//! [0] //! [1] + } +//! [1] + + fontTree.resizeColumnToContents(0); + fontTree.show(); + return app.exec(); +} diff --git a/src/gui/doc/snippets/qstatustipevent/main.cpp b/src/gui/doc/snippets/qstatustipevent/main.cpp new file mode 100644 index 0000000000..9a1948f4e8 --- /dev/null +++ b/src/gui/doc/snippets/qstatustipevent/main.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include <QApplication> + +class MainWindow : public QMainWindow +{ +public: + MainWindow(QWidget *parent = 0); +}; + +//! [0] //! [1] +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ +//! [0] + QWidget *myWidget = new QWidget; + myWidget->setStatusTip(tr("This is my widget.")); + + setCentralWidget(myWidget); +//! [1] + +//! [2] + QMenu *fileMenu = menuBar()->addMenu(tr("File")); + + QAction *newAct = new QAction(tr("&New"), this); + newAct->setStatusTip(tr("Create a new file.")); + fileMenu->addAction(newAct); +//! [2] + + statusBar()->showMessage(tr("Ready")); + setWindowTitle(tr("QStatusTipEvent")); +//! [3] +} +//! [3] + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow window; + window.show(); + return app.exec(); +} + diff --git a/src/gui/doc/snippets/separations/finalwidget.cpp b/src/gui/doc/snippets/separations/finalwidget.cpp new file mode 100644 index 0000000000..81a4aa1c42 --- /dev/null +++ b/src/gui/doc/snippets/separations/finalwidget.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* +finalwidget.cpp + +A widget to display an image and a label containing a description. +*/ + +#include <QtGui> +#include "finalwidget.h" + +FinalWidget::FinalWidget(QWidget *parent, const QString &name, + const QSize &labelSize) + : QFrame(parent) +{ + hasImage = false; + imageLabel = new QLabel; + imageLabel->setFrameShadow(QFrame::Sunken); + imageLabel->setFrameShape(QFrame::StyledPanel); + imageLabel->setMinimumSize(labelSize); + nameLabel = new QLabel(name); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(imageLabel, 1); + layout->addWidget(nameLabel, 0); + setLayout(layout); +} + +/*! + If the mouse moves far enough when the left mouse button is held down, + start a drag and drop operation. +*/ + +void FinalWidget::mouseMoveEvent(QMouseEvent *event) +{ + if (!(event->buttons() & Qt::LeftButton)) + return; + if ((event->pos() - dragStartPosition).manhattanLength() + < QApplication::startDragDistance()) + return; + if (!hasImage) + return; + + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + +//! [0] + QByteArray output; + QBuffer outputBuffer(&output); + outputBuffer.open(QIODevice::WriteOnly); + imageLabel->pixmap()->toImage().save(&outputBuffer, "PNG"); + mimeData->setData("image/png", output); +//! [0] +/* +//! [1] + mimeData->setImageData(QVariant(*imageLabel->pixmap())); +//! [1] +*/ + drag->setMimeData(mimeData); + drag->setPixmap(imageLabel->pixmap()->scaled(64, 64, Qt::KeepAspectRatio)); +//! [2] + drag->setHotSpot(QPoint(drag->pixmap().width()/2, + drag->pixmap().height())); +//! [2] + + drag->start(); +} + +/*! + Check for left mouse button presses in order to enable drag and drop. +*/ + +void FinalWidget::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + dragStartPosition = event->pos(); +} + +const QPixmap* FinalWidget::pixmap() const +{ + return imageLabel->pixmap(); +} + +void FinalWidget::setPixmap(const QPixmap &pixmap) +{ + imageLabel->setPixmap(pixmap); + hasImage = true; +} diff --git a/src/gui/doc/snippets/textblock-fragments/xmlwriter.cpp b/src/gui/doc/snippets/textblock-fragments/xmlwriter.cpp new file mode 100644 index 0000000000..cd9beadd00 --- /dev/null +++ b/src/gui/doc/snippets/textblock-fragments/xmlwriter.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "xmlwriter.h" + +QDomDocument *XmlWriter::toXml() +{ + QDomImplementation implementation; + QDomDocumentType docType = implementation.createDocumentType( + "scribe-document", "scribe", "qt.nokia.com/scribe"); + + document = new QDomDocument(docType); + + // ### This processing instruction is required to ensure that any kind + // of encoding is given when the document is written. + QDomProcessingInstruction process = document->createProcessingInstruction( + "xml", "version=\"1.0\" encoding=\"utf-8\""); + document->appendChild(process); + + QDomElement documentElement = document->createElement("document"); + document->appendChild(documentElement); + +//! [0] + QTextBlock currentBlock = textDocument->begin(); + + while (currentBlock.isValid()) { +//! [0] + QDomElement blockElement = document->createElement("block"); + document->appendChild(blockElement); + + readFragment(currentBlock, blockElement, document); + +//! [1] + processBlock(currentBlock); +//! [1] + +//! [2] + currentBlock = currentBlock.next(); + } +//! [2] + + return document; +} + +void XmlWriter::readFragment(const QTextBlock ¤tBlock, + QDomElement blockElement, + QDomDocument *document) +{ +//! [3] //! [4] + QTextBlock::iterator it; + for (it = currentBlock.begin(); !(it.atEnd()); ++it) { + QTextFragment currentFragment = it.fragment(); + if (currentFragment.isValid()) +//! [3] //! [5] + processFragment(currentFragment); +//! [4] //! [5] + + if (currentFragment.isValid()) { + QDomElement fragmentElement = document->createElement("fragment"); + blockElement.appendChild(fragmentElement); + + fragmentElement.setAttribute("length", currentFragment.length()); + QDomText fragmentText = document->createTextNode(currentFragment.text()); + + fragmentElement.appendChild(fragmentText); + } +//! [6] //! [7] + } +//! [7] //! [6] +} + +void XmlWriter::processBlock(const QTextBlock ¤tBlock) +{ +} + +void XmlWriter::processFragment(const QTextFragment ¤tFragment) +{ +} diff --git a/src/gui/doc/snippets/textdocument-css/main.cpp b/src/gui/doc/snippets/textdocument-css/main.cpp new file mode 100644 index 0000000000..55b8571224 --- /dev/null +++ b/src/gui/doc/snippets/textdocument-css/main.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + +//! [0] + QTextBrowser browser; + QColor linkColor(Qt::red); + QString sheet = QString::fromLatin1("a { text-decoration: underline; color: %1 }").arg(linkColor.name()); + browser.document()->setDefaultStyleSheet(sheet); +//! [0] + browser.setSource(QUrl("../../../html/index.html")); + browser.resize(800, 600); + browser.show(); + + return app.exec(); +} + diff --git a/src/gui/doc/snippets/textdocument-listitemstyles/main.cpp b/src/gui/doc/snippets/textdocument-listitemstyles/main.cpp new file mode 100644 index 0000000000..223ec22bae --- /dev/null +++ b/src/gui/doc/snippets/textdocument-listitemstyles/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->resize(640, 480); + window->show(); + return app.exec(); +} diff --git a/src/gui/doc/snippets/textdocument-listitemstyles/mainwindow.cpp b/src/gui/doc/snippets/textdocument-listitemstyles/mainwindow.cpp new file mode 100644 index 0000000000..029695eca3 --- /dev/null +++ b/src/gui/doc/snippets/textdocument-listitemstyles/mainwindow.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + fileMenu->addAction(tr("E&xit"), this, SLOT(close()), + QKeySequence(tr("Ctrl+Q", "File|Exit"))); + + QMenu *insertMenu = new QMenu(tr("&Insert")); + + insertMenu->addAction(tr("&List"), this, SLOT(insertList()), + QKeySequence(tr("Ctrl+L", "Insert|List"))); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(insertMenu); + + editor = new QTextEdit(this); + document = new QTextDocument(this); + editor->setDocument(document); + + setCentralWidget(editor); + setWindowTitle(tr("Text Document List Item Styles")); +} + +void MainWindow::insertList() +{ + QTextCursor cursor = editor->textCursor(); + cursor.beginEditBlock(); + + //! [add a styled, ordered list] + QTextListFormat listFormat; + + listFormat.setStyle(QTextListFormat::ListDecimal); + listFormat.setNumberPrefix("("); + listFormat.setNumberSuffix(")"); + + cursor.insertList(listFormat); + //! [add a styled, ordered list] + + cursor.endEditBlock(); +} diff --git a/src/gui/doc/snippets/textdocument-listitemstyles/mainwindow.h b/src/gui/doc/snippets/textdocument-listitemstyles/mainwindow.h new file mode 100644 index 0000000000..fc5c6db2a7 --- /dev/null +++ b/src/gui/doc/snippets/textdocument-listitemstyles/mainwindow.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QMainWindow> + +class QTextDocument; +class QTextEdit; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void insertList(); + +private: + QString currentFile; + QTextEdit *editor; + QTextDocument *document; +}; + +#endif diff --git a/src/gui/doc/snippets/textdocument-listitemstyles/textdocument-listitemstyles.pro b/src/gui/doc/snippets/textdocument-listitemstyles/textdocument-listitemstyles.pro new file mode 100644 index 0000000000..5da8d6e1a1 --- /dev/null +++ b/src/gui/doc/snippets/textdocument-listitemstyles/textdocument-listitemstyles.pro @@ -0,0 +1,3 @@ +HEADERS = mainwindow.h +SOURCES = main.cpp \ + mainwindow.cpp diff --git a/src/gui/doc/snippets/textdocument-lists/mainwindow.cpp b/src/gui/doc/snippets/textdocument-lists/mainwindow.cpp new file mode 100644 index 0000000000..7ae36b0ced --- /dev/null +++ b/src/gui/doc/snippets/textdocument-lists/mainwindow.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + fileMenu->addAction(tr("E&xit"), this, SLOT(close()), + QKeySequence(tr("Ctrl+Q", "File|Exit"))); + + QMenu *editMenu = new QMenu(tr("&Edit")); + + cutAction = editMenu->addAction(tr("Cu&t"), this, SLOT(cutSelection()), + QKeySequence(tr("Ctrl+X", "Edit|Cut"))); + copyAction = editMenu->addAction(tr("&Copy"), this, SLOT(copySelection()), + QKeySequence(tr("Ctrl+C", "Edit|Copy"))); + pasteAction = editMenu->addAction(tr("&Paste"), this, + SLOT(pasteSelection()), QKeySequence(tr("Ctrl+V", "Edit|Paste"))); + + QMenu *selectMenu = new QMenu(tr("&Select")); + selectMenu->addAction(tr("&Word"), this, SLOT(selectWord())); + selectMenu->addAction(tr("&Line"), this, SLOT(selectLine())); + selectMenu->addAction(tr("&Block"), this, SLOT(selectBlock())); + selectMenu->addAction(tr("&Frame"), this, SLOT(selectFrame())); + + QMenu *insertMenu = new QMenu(tr("&Insert")); + + insertMenu->addAction(tr("&List"), this, SLOT(insertList()), + QKeySequence(tr("Ctrl+L", "Insert|List"))); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(editMenu); + menuBar()->addMenu(selectMenu); + menuBar()->addMenu(insertMenu); + + editor = new QTextEdit(this); + document = new QTextDocument(this); + editor->setDocument(document); + + connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus())); + + updateMenus(); + + setCentralWidget(editor); + setWindowTitle(tr("Text Document Writer")); +} + +void MainWindow::cutSelection() +{ + QTextCursor cursor = editor->textCursor(); + if (cursor.hasSelection()) { + selection = cursor.selection(); + cursor.removeSelectedText(); + } +} + +void MainWindow::copySelection() +{ + QTextCursor cursor = editor->textCursor(); + if (cursor.hasSelection()) { + selection = cursor.selection(); + cursor.clearSelection(); + } +} + +void MainWindow::pasteSelection() +{ + QTextCursor cursor = editor->textCursor(); + cursor.insertFragment(selection); +} + +void MainWindow::selectWord() +{ + QTextCursor cursor = editor->textCursor(); + QTextBlock block = cursor.block(); + + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::StartOfWord); + cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::selectLine() +{ + QTextCursor cursor = editor->textCursor(); + QTextBlock block = cursor.block(); + + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::StartOfLine); + cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::selectBlock() +{ + QTextCursor cursor = editor->textCursor(); + QTextBlock block = cursor.block(); + + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::StartOfBlock); + cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::selectFrame() +{ + QTextCursor cursor = editor->textCursor(); + QTextFrame *frame = cursor.currentFrame(); + + cursor.beginEditBlock(); + cursor.setPosition(frame->firstPosition()); + cursor.setPosition(frame->lastPosition(), QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::insertList() +{ + QTextCursor cursor = editor->textCursor(); + cursor.beginEditBlock(); + + QTextList *list = cursor.currentList(); +//! [0] + QTextListFormat listFormat; + if (list) { + listFormat = list->format(); + listFormat.setIndent(listFormat.indent() + 1); + } + + listFormat.setStyle(QTextListFormat::ListDisc); + cursor.insertList(listFormat); +//! [0] + + cursor.endEditBlock(); +} + +void MainWindow::updateMenus() +{ + QTextCursor cursor = editor->textCursor(); + cutAction->setEnabled(cursor.hasSelection()); + copyAction->setEnabled(cursor.hasSelection()); + + pasteAction->setEnabled(!selection.isEmpty()); +} diff --git a/src/gui/doc/snippets/textdocument-resources/main.cpp b/src/gui/doc/snippets/textdocument-resources/main.cpp new file mode 100644 index 0000000000..ed26793d78 --- /dev/null +++ b/src/gui/doc/snippets/textdocument-resources/main.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +QString tr(const char *text) +{ + return QApplication::translate(text, text); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QTextEdit *editor = new QTextEdit; + + QTextDocument *document = new QTextDocument(editor); + QTextCursor cursor(document); + + QImage image(64, 64, QImage::Format_RGB32); + image.fill(qRgb(255, 160, 128)); + +//! [Adding a resource] + document->addResource(QTextDocument::ImageResource, + QUrl("mydata://image.png"), QVariant(image)); +//! [Adding a resource] + +//! [Inserting an image with a cursor] + QTextImageFormat imageFormat; + imageFormat.setName("mydata://image.png"); + cursor.insertImage(imageFormat); +//! [Inserting an image with a cursor] + + cursor.insertBlock(); + cursor.insertText("Code less. Create more."); + + editor->setDocument(document); + editor->setWindowTitle(tr("Text Document Images")); + editor->resize(320, 480); + editor->show(); + +//! [Inserting an image using HTML] + editor->append("<img src=\"mydata://image.png\" />"); +//! [Inserting an image using HTML] + + return app.exec(); +} diff --git a/src/gui/doc/snippets/textdocument-resources/textdocument-resources.pro b/src/gui/doc/snippets/textdocument-resources/textdocument-resources.pro new file mode 100644 index 0000000000..16181f21cf --- /dev/null +++ b/src/gui/doc/snippets/textdocument-resources/textdocument-resources.pro @@ -0,0 +1 @@ +SOURCES = main.cpp diff --git a/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp b/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp new file mode 100644 index 0000000000..79e5f03df4 --- /dev/null +++ b/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" +#include "xmlwriter.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *saveAction = fileMenu->addAction(tr("&Save...")); + saveAction->setShortcut(tr("Ctrl+S")); + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + QMenu *showMenu = new QMenu(tr("&Show")); + + QAction *showTableAction = showMenu->addAction(tr("&Table")); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(showMenu); + + editor = new QTextEdit(); + +//! [0] //! [1] + QTextCursor cursor(editor->textCursor()); +//! [0] + cursor.movePosition(QTextCursor::Start); +//! [1] + + int rows = 11; + int columns = 4; + +//! [2] + QTextTableFormat tableFormat; + tableFormat.setBackground(QColor("#e0e0e0")); + QVector<QTextLength> constraints; + constraints << QTextLength(QTextLength::PercentageLength, 16); + constraints << QTextLength(QTextLength::PercentageLength, 28); + constraints << QTextLength(QTextLength::PercentageLength, 28); + constraints << QTextLength(QTextLength::PercentageLength, 28); + tableFormat.setColumnWidthConstraints(constraints); +//! [3] + QTextTable *table = cursor.insertTable(rows, columns, tableFormat); +//! [2] //! [3] + + int column; + int row; + QTextTableCell cell; + QTextCursor cellCursor; + + QTextCharFormat charFormat; + charFormat.setForeground(Qt::black); + +//! [4] + cell = table->cellAt(0, 0); + cellCursor = cell.firstCursorPosition(); + cellCursor.insertText(tr("Week"), charFormat); +//! [4] + +//! [5] + for (column = 1; column < columns; ++column) { + cell = table->cellAt(0, column); + cellCursor = cell.firstCursorPosition(); + cellCursor.insertText(tr("Team %1").arg(column), charFormat); + } + + for (row = 1; row < rows; ++row) { + cell = table->cellAt(row, 0); + cellCursor = cell.firstCursorPosition(); + cellCursor.insertText(tr("%1").arg(row), charFormat); + + for (column = 1; column < columns; ++column) { + if ((row-1) % 3 == column-1) { +//! [5] //! [6] + cell = table->cellAt(row, column); + QTextCursor cellCursor = cell.firstCursorPosition(); + cellCursor.insertText(tr("On duty"), charFormat); + } +//! [6] //! [7] + } +//! [7] //! [8] + } +//! [8] + + connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(showTableAction, SIGNAL(triggered()), this, SLOT(showTable())); + + setCentralWidget(editor); + setWindowTitle(tr("Text Document Tables")); +} + +void MainWindow::saveFile() +{ + QString fileName = QFileDialog::getSaveFileName(this, + tr("Save document as:"), "", tr("XML (*.xml)")); + + if (!fileName.isEmpty()) { + if (writeXml(fileName)) + setWindowTitle(fileName); + else + QMessageBox::warning(this, tr("Warning"), + tr("Failed to save the document."), QMessageBox::Cancel, + QMessageBox::NoButton); + } +} + +void MainWindow::showTable() +{ + QTextCursor cursor = editor->textCursor(); + QTextTable *table = cursor.currentTable(); + + if (!table) + return; + + QTableWidget *tableWidget = new QTableWidget(table->rows(), table->columns()); + +//! [9] + for (int row = 0; row < table->rows(); ++row) { + for (int column = 0; column < table->columns(); ++column) { + QTextTableCell tableCell = table->cellAt(row, column); +//! [9] + QTextFrame::iterator it; + QString text; + for (it = tableCell.begin(); !(it.atEnd()); ++it) { + QTextBlock childBlock = it.currentBlock(); + if (childBlock.isValid()) + text += childBlock.text(); + } + QTableWidgetItem *newItem = new QTableWidgetItem(text); + tableWidget->setItem(row, column, newItem); + /* +//! [10] + processTableCell(tableCell); +//! [10] + */ +//! [11] + } +//! [11] //! [12] + } +//! [12] + + tableWidget->setWindowTitle(tr("Table Contents")); + tableWidget->show(); +} + +bool MainWindow::writeXml(const QString &fileName) +{ + XmlWriter documentWriter(editor->document()); + + QDomDocument *domDocument = documentWriter.toXml(); + QFile file(fileName); + + if (file.open(QFile::WriteOnly)) { + QTextStream textStream(&file); + textStream.setCodec(QTextCodec::codecForName("UTF-8")); + + textStream << domDocument->toString(1).toUtf8(); + file.close(); + return true; + } + else + return false; +} diff --git a/src/gui/doc/snippets/textdocument-texttable/main.cpp b/src/gui/doc/snippets/textdocument-texttable/main.cpp new file mode 100644 index 0000000000..ca5338533c --- /dev/null +++ b/src/gui/doc/snippets/textdocument-texttable/main.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +int main(int argc, char * argv[]) +{ + int rows = 6; + int columns = 2; + + QApplication app(argc, argv); + QTextEdit *textEdit = new QTextEdit; + QTextCursor cursor(textEdit->textCursor()); + cursor.movePosition(QTextCursor::Start); + + QTextTableFormat tableFormat; + tableFormat.setAlignment(Qt::AlignHCenter); + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(2); + QTextTable *table = cursor.insertTable(rows, columns); + table->setFormat(tableFormat); + + QTextCharFormat boldFormat; + boldFormat.setFontWeight(QFont::Bold); + + QTextBlockFormat centerFormat; + centerFormat.setAlignment(Qt::AlignHCenter); + cursor.mergeBlockFormat(centerFormat); + + cursor = table->cellAt(0, 0).firstCursorPosition(); + cursor.insertText(("Details"), boldFormat); + + cursor = table->cellAt(1, 0).firstCursorPosition(); + cursor.insertText("Alan"); + + cursor = table->cellAt(1, 1).firstCursorPosition(); + cursor.insertText("5, Pickety Street"); + +//! [0] + table->mergeCells(0, 0, 1, 2); +//! [0] //! [1] + table->splitCell(0, 0, 1, 1); +//! [1] + + textEdit->show(); + return app.exec(); +} diff --git a/src/gui/doc/snippets/textdocumentendsnippet.cpp b/src/gui/doc/snippets/textdocumentendsnippet.cpp new file mode 100644 index 0000000000..caec20dc9b --- /dev/null +++ b/src/gui/doc/snippets/textdocumentendsnippet.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include <iostream.h> + +int main(int argv, char **args) +{ + QString contentString("One\nTwp\nThree"); + + QTextDocument *doc = new QTextDocument(contentString); + +//! [0] + for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next()) + cout << it.text().toStdString() << endl; +//! [0] + + return 0; +} diff --git a/src/gui/doc/snippets/transform/main.cpp b/src/gui/doc/snippets/transform/main.cpp new file mode 100644 index 0000000000..d1c600828d --- /dev/null +++ b/src/gui/doc/snippets/transform/main.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include <cmath> + +class SimpleTransformation : public QWidget +{ + void paintEvent(QPaintEvent *); +}; + +//! [0] +void SimpleTransformation::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setPen(QPen(Qt::blue, 1, Qt::DashLine)); + painter.drawRect(0, 0, 100, 100); + + painter.rotate(45); + + painter.setFont(QFont("Helvetica", 24)); + painter.setPen(QPen(Qt::black, 1)); + painter.drawText(20, 10, "QTransform"); +} +//! [0] + +class CombinedTransformation : public QWidget +{ + void paintEvent(QPaintEvent *); +}; + +//! [1] +void CombinedTransformation::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setPen(QPen(Qt::blue, 1, Qt::DashLine)); + painter.drawRect(0, 0, 100, 100); + + QTransform transform; + transform.translate(50, 50); + transform.rotate(45); + transform.scale(0.5, 1.0); + painter.setTransform(transform); + + painter.setFont(QFont("Helvetica", 24)); + painter.setPen(QPen(Qt::black, 1)); + painter.drawText(20, 10, "QTransform"); +} +//! [1] + +class BasicOperations : public QWidget +{ + void paintEvent(QPaintEvent *); +}; + +//! [2] +void BasicOperations::paintEvent(QPaintEvent *) +{ + double pi = 3.14; + + double a = pi/180 * 45.0; + double sina = sin(a); + double cosa = cos(a); + + QTransform translationTransform(1, 0, 0, 1, 50.0, 50.0); + QTransform rotationTransform(cosa, sina, -sina, cosa, 0, 0); + QTransform scalingTransform(0.5, 0, 0, 1.0, 0, 0); + + QTransform transform; + transform = scalingTransform * rotationTransform * translationTransform; + + QPainter painter(this); + painter.setPen(QPen(Qt::blue, 1, Qt::DashLine)); + painter.drawRect(0, 0, 100, 100); + + painter.setTransform(transform); + + painter.setFont(QFont("Helvetica", 24)); + painter.setPen(QPen(Qt::black, 1)); + painter.drawText(20, 10, "QTransform"); +} +//! [2] + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QWidget widget; + + SimpleTransformation *simpleWidget = new SimpleTransformation; + CombinedTransformation *combinedWidget = new CombinedTransformation; + BasicOperations *basicWidget = new BasicOperations; + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(simpleWidget); + layout->addWidget(combinedWidget); + layout->addWidget(basicWidget); + widget.setLayout(layout); + + widget.show(); + widget.resize(130, 350); + return app.exec(); +} diff --git a/src/gui/doc/src/coordsys.qdoc b/src/gui/doc/src/coordsys.qdoc new file mode 100644 index 0000000000..bfa046f7fb --- /dev/null +++ b/src/gui/doc/src/coordsys.qdoc @@ -0,0 +1,461 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page coordsys.html + \title Coordinate System + \ingroup qt-graphics + \ingroup best-practices + \b |