diff options
author | Casper van Donderen <casper.vandonderen@nokia.com> | 2012-05-07 15:50:31 +0200 |
---|---|---|
committer | Marius Storm-Olsen <marius.storm-olsen@nokia.com> | 2012-05-09 08:36:34 +0200 |
commit | cfdc5628b1fc2cbafa2aebca38995e5718fcb0de (patch) | |
tree | 67615dc74faa944bf7745c9db001efa3594a3249 /src/gui/doc/snippets | |
parent | 3b8e6027c2f79bde70f9415f0757df073ef75702 (diff) | |
download | qtbase-cfdc5628b1fc2cbafa2aebca38995e5718fcb0de.tar.gz |
Doc: Modularize QtGui documentation.
This change moves the snippets and images to the modularized
directories.
Change-Id: I5f86f598fbe7c47d632c613b85d94ced89ba2c29
Reviewed-by: Marius Storm-Olsen <marius.storm-olsen@nokia.com>
Diffstat (limited to 'src/gui/doc/snippets')
58 files changed, 4849 insertions, 0 deletions
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_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(); +} |