diff options
Diffstat (limited to 'src/gui/doc/snippets/code')
48 files changed, 1388 insertions, 2731 deletions
diff --git a/src/gui/doc/snippets/code/doc_src_coordsys.cpp b/src/gui/doc/snippets/code/doc_src_coordsys.cpp index 147c146b44..03da9ef31a 100644 --- a/src/gui/doc/snippets/code/doc_src_coordsys.cpp +++ b/src/gui/doc/snippets/code/doc_src_coordsys.cpp @@ -1,52 +1,20 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QPainter> +#include <QWidget> + +namespace doc_src_coordsys { +struct SnippetWrappers : public QWidget +{ + void wrapper0(); + void wrapper1(); + void wrapper2(); + void wrapper3(); + void wrapper4(); +}; + + +void SnippetWrappers::wrapper0() { //! [0] QPainter painter(this); @@ -56,6 +24,10 @@ painter.setPen(Qt::darkGreen); painter.drawRect(1, 2, 6, 4); //! [0] +} // wrapper0 + + +void SnippetWrappers::wrapper1() { //! [1] QPainter painter(this); @@ -64,6 +36,10 @@ painter.setPen(Qt::darkGreen); painter.drawLine(2, 7, 6, 1); //! [1] +} // wrapper2 + + +void SnippetWrappers::wrapper2() { //! [2] QPainter painter(this); @@ -74,6 +50,10 @@ painter.setPen(Qt::darkGreen); painter.drawRect(1, 2, 6, 4); //! [2] +} // wrapper2 + + +void SnippetWrappers::wrapper3() { //! [3] QPainter painter(this); @@ -83,6 +63,10 @@ painter.setPen(Qt::darkGreen); painter.drawLine(2, 7, 6, 1); //! [3] +} // wrapper3 + + +void SnippetWrappers::wrapper4() { //! [4] QPainter painter(this); @@ -91,9 +75,13 @@ painter.setWindow(QRect(-50, -50, 100, 100)); //! [5] -int side = qMin(width(), height()) +int side = qMin(width(), height()); int x = (width() - side / 2); int y = (height() - side / 2); painter.setViewport(x, y, side, side); //! [5] + +} // wrapper4 + +} // doc_src_coordsys diff --git a/src/gui/doc/snippets/code/doc_src_richtext.cpp b/src/gui/doc/snippets/code/doc_src_richtext.cpp index fb7ab1b571..8d7e76503a 100644 --- a/src/gui/doc/snippets/code/doc_src_richtext.cpp +++ b/src/gui/doc/snippets/code/doc_src_richtext.cpp @@ -1,53 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QTextDocument> +#include <QTextEdit> +namespace doc_src_richtext { + +void wrapper() { //! [0] QTextDocument *newDocument = new QTextDocument; //! [0] @@ -57,8 +15,13 @@ QTextDocument *newDocument = new QTextDocument; QTextEdit *editor = new QTextEdit; QTextDocument *editorDocument = editor->document(); //! [1] +Q_UNUSED(newDocument); +Q_UNUSED(editorDocument); +} // wrapper - +void wrapper2() { +auto parent = new QTextEdit(); +QString aStringContainingHTMLtext; //! [2] QTextEdit *editor = new QTextEdit(parent); editor->setHtml(aStringContainingHTMLtext); @@ -69,7 +32,7 @@ editor->show(); //! [3] QTextDocument *document = editor->document(); //! [3] - +Q_UNUSED(document); //! [4] QTextCursor cursor = editor->textCursor(); @@ -81,6 +44,9 @@ editor->setTextCursor(cursor); //! [5] +QTextEdit textEdit; +QTextCursor textCursor; +QString paragraphText; //! [6] textEdit.show(); @@ -93,3 +59,6 @@ for (int i = 0; i < 1000; ++i) { textCursor.endEditBlock(); //! [6] + +} // wrapper2 +} // doc_src_richtext diff --git a/src/gui/doc/snippets/code/doc_src_richtext.qdoc b/src/gui/doc/snippets/code/doc_src_richtext.qdoc index 17faf1ac86..0c69514210 100644 --- a/src/gui/doc/snippets/code/doc_src_richtext.qdoc +++ b/src/gui/doc/snippets/code/doc_src_richtext.qdoc @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only //! [7] <meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" /> diff --git a/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp b/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp index 2fd76d08c7..621d00a401 100644 --- a/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp +++ b/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp @@ -1,55 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QAccessible> + +namespace src_gui_accessible_qaccessible { +class MyWidget +{ + void setFocus(Qt::FocusReason reason); +}; +QAccessibleInterface *f = nullptr; //! [1] -typedef QAccessibleInterface* myFactoryFunction(const QString &key, QObject *); +typedef QAccessibleInterface *myFactoryFunction(const QString &key, QObject *); //! [1] //! [2] @@ -61,11 +22,4 @@ void MyWidget::setFocus(Qt::FocusReason reason) } //! [2] -//! [3] -void *QAccessibleLineEdit::interface_cast(QAccessible::InterfaceType t) -{ - if (t == QAccessible::TextInterface) - return static_cast<QAccessibleTextInterface*>(this); - return QAccessibleWidget::interface_cast(t); -} -//! [3] +} // src_gui_accessible_qaccessible diff --git a/src/gui/doc/snippets/code/src_gui_image_qicon.cpp b/src/gui/doc/snippets/code/src_gui_image_qicon.cpp index faad6574a7..a7f27a7fdd 100644 --- a/src/gui/doc/snippets/code/src_gui_image_qicon.cpp +++ b/src/gui/doc/snippets/code/src_gui_image_qicon.cpp @@ -1,84 +1,66 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QIcon> +#include <QPainter> +#include <QToolButton> + +namespace src_gui_image_qicon { + +struct MyWidget : public QWidget +{ + void drawIcon(QPainter *painter, const QRect &rect); + bool isChecked() { return true; } + QIcon icon; +}; + +void wrapper0() { //! [0] QToolButton *button = new QToolButton; -button->setIcon(QIcon("open.xpm")); +button->setIcon(QIcon("open.png")); //! [0] +//! [addFile] +QIcon openIcon("open.png"); +openIcon.addFile("open-disabled.png", QIcon::Disabled); +//! [addFile] //! [1] button->setIcon(QIcon()); //! [1] +} // wrapper0 + //! [2] -void MyWidget::drawIcon(QPainter *painter, QPoint pos) +void MyWidget::drawIcon(QPainter *painter, const QRect &rect) { - QPixmap pixmap = icon.pixmap(QSize(22, 22), - isEnabled() ? QIcon::Normal - : QIcon::Disabled, - isChecked() ? QIcon::On - : QIcon::Off); - painter->drawPixmap(pos, pixmap); + icon.paint(painter, rect, Qt::AlignCenter, isEnabled() ? QIcon::Normal + : QIcon::Disabled, + isChecked() ? QIcon::On + : QIcon::Off); } //! [2] -//! [3] - QIcon undoicon = QIcon::fromTheme("edit-undo"); -//! [3] + +void wrapper1() { + +//! [fromTheme] +QIcon undoicon = QIcon::fromTheme(QIcon::ThemeIcon::EditUndo); +//! [fromTheme] + +} // wrapper1 + //! [4] - QIcon undoicon = QIcon::fromTheme("edit-undo", QIcon(":/undo.png")); +QIcon undoicon = QIcon::fromTheme(QIcon::ThemeIcon::EditUndo, QIcon(":/undo.png")); //! [4] + +void wrapper2(){ //! [5] - QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << "my/search/path"); +QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << "my/search/path"); //! [5] + +} // wrapper2 +} // src_gui_image_qicon diff --git a/src/gui/doc/snippets/code/src_gui_image_qimage.cpp b/src/gui/doc/snippets/code/src_gui_image_qimage.cpp index e4e641a5e0..759b085be4 100644 --- a/src/gui/doc/snippets/code/src_gui_image_qimage.cpp +++ b/src/gui/doc/snippets/code/src_gui_image_qimage.cpp @@ -1,53 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QImage> +#include <QRgb> +namespace src_gui_image_qimage { +void wrapper0() { //! [0] QImage image(3, 3, QImage::Format_RGB32); QRgb value; @@ -63,6 +20,9 @@ value = qRgb(237, 187, 51); // 0xffedba31 image.setPixel(2, 1, value); //! [0] +} // wrapper0 +void wrapper1() { + //! [1] QImage image(3, 3, QImage::Format_Indexed8); @@ -88,5 +48,21 @@ image.setPixel(2, 1, 1); static const char * const start_xpm[] = { "16 15 8 1", "a c #cec6bd", -.... + // etc. +}; //! [2] + + +//! [scanLine] +for (int y = 0; y < image.height(); ++y) { + QRgb *line = reinterpret_cast<QRgb*>(image.scanLine(y)); + for (int x = 0; x < image.width(); ++x) { + QRgb &rgb = line[x]; + rgb = qRgba(qRed(rgb), qGreen(0), qBlue(rgb), qAlpha(rgb)); + } +} +//! [scanLine] + +Q_UNUSED(start_xpm); +} // wrapper1 +} // src_gui_image_qimage diff --git a/src/gui/doc/snippets/code/src_gui_image_qimagereader.cpp b/src/gui/doc/snippets/code/src_gui_image_qimagereader.cpp index ac26126758..c703cc580a 100644 --- a/src/gui/doc/snippets/code/src_gui_image_qimagereader.cpp +++ b/src/gui/doc/snippets/code/src_gui_image_qimagereader.cpp @@ -1,58 +1,18 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QImage> +#include <QImageReader> + +namespace src_gui_image_qimagereader { +void wrapper0() { //! [0] QImageReader reader; reader.setFormat("png"); // same as reader.setFormat("PNG"); //! [0] +} // wrapper0 + //! [1] QImageReader reader("image.png"); @@ -60,6 +20,8 @@ QImageReader reader("image.png"); //! [1] +void wrapper1() { + //! [2] QImage icon(64, 64, QImage::Format_RGB32); QImageReader reader("icon_64x64.bmp"); @@ -68,9 +30,16 @@ if (reader.read(&icon)) { } //! [2] +} // wrapper1 + + +void wrapper2() { //! [3] QImageReader reader(":/image.png"); if (reader.supportsOption(QImageIOHandler::Size)) qDebug() << "Size:" << reader.size(); //! [3] + +} // wrapper2 +} // src_gui_image_qimagereader diff --git a/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp b/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp index c0b2544858..98b1fcdc9d 100644 --- a/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp +++ b/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp @@ -1,58 +1,21 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QImage> +#include <QImageWriter> + +namespace src_gui_image_qimagewriter { + +void wrapper0() { //! [0] QImageWriter writer; writer.setFormat("png"); // same as writer.setFormat("PNG"); //! [0] +} // wrapper0 + + +void wrapper1() { //! [1] QImage image("some/image.jpeg"); @@ -61,6 +24,11 @@ writer.setText("Author", "John Smith"); writer.write(image); //! [1] +} // wrapper1 + + +void wrapper2() { +QString fileName; //! [2] QImageWriter writer(fileName); @@ -68,9 +36,18 @@ if (writer.supportsOption(QImageIOHandler::Description)) writer.setText("Author", "John Smith"); //! [2] +} // wrapper 2 + + +void wrapper3() { +QImage image; + //! [3] QImageWriter writer("some/image.dds"); if (writer.supportsOption(QImageIOHandler::SubType)) writer.setSubType("A8R8G8B8"); writer.write(image); //! [3] + +} // wrapper3 +} // src_gui_image_qimagewriter diff --git a/src/gui/doc/snippets/code/src_gui_image_qmovie.cpp b/src/gui/doc/snippets/code/src_gui_image_qmovie.cpp index 3ed458a3db..390f69a703 100644 --- a/src/gui/doc/snippets/code/src_gui_image_qmovie.cpp +++ b/src/gui/doc/snippets/code/src_gui_image_qmovie.cpp @@ -1,52 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QLabel> +#include <QMovie> + +namespace src_gui_image_qmovie { + +void wrapper0() { + //! [0] QLabel label; @@ -56,8 +16,15 @@ label.setMovie(movie); movie->start(); //! [0] +} // wrapper0 + + +void wrapper1() { //! [1] QMovie movie("racecar.gif"); movie.setSpeed(200); // 2x speed //! [1] + +} // wrapper1 +} // src_gui_image_qmovie diff --git a/src/gui/doc/snippets/code/src_gui_image_qpixmap.cpp b/src/gui/doc/snippets/code/src_gui_image_qpixmap.cpp index b76e7b6e8d..2ef59d8f24 100644 --- a/src/gui/doc/snippets/code/src_gui_image_qpixmap.cpp +++ b/src/gui/doc/snippets/code/src_gui_image_qpixmap.cpp @@ -1,68 +1,27 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QBitmap> +#include <QPixmap> -//! [0] -static const char * const start_xpm[]={ - "16 15 8 1", - "a c #cec6bd", -.... -//! [0] +namespace src_gui_image_qpixmap { +void wrapper0() { //! [1] QPixmap myPixmap; myPixmap.setMask(myPixmap.createHeuristicMask()); //! [1] +} // wrapper0 + + +void wrapper1() { + //! [2] QPixmap pixmap("background.png"); QRegion exposed; pixmap.scroll(10, 10, pixmap.rect(), &exposed); //! [2] + +} // wrapper1 +} // src_gui_image_qpixmap diff --git a/src/gui/doc/snippets/code/src_gui_image_qpixmapcache.cpp b/src/gui/doc/snippets/code/src_gui_image_qpixmapcache.cpp index 9043ee6361..9d2566c540 100644 --- a/src/gui/doc/snippets/code/src_gui_image_qpixmapcache.cpp +++ b/src/gui/doc/snippets/code/src_gui_image_qpixmapcache.cpp @@ -1,65 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 p; -if (QPixmap *pp = QPixmapCache::find("my_big_image"))) { - p = *pp; -} else { - p.load("bigimage.png"); - QPixmapCache::insert("my_big_image", new QPixmap(p)); -} -painter->drawPixmap(0, 0, p); -//! [0] +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QPainter> +#include <QPixmap> +#include <QPixmapCache> +namespace src_gui_image_qpixmapcache { +void wrapper0(QPainter *painter) { //! [1] QPixmap pm; if (!QPixmapCache::find("my_big_image", &pm)) { @@ -68,3 +15,6 @@ if (!QPixmapCache::find("my_big_image", &pm)) { } painter->drawPixmap(0, 0, pm); //! [1] + +} // wrapper0 +} // src_gui_image_qpixmapcache diff --git a/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp b/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp index a7e22e549d..a608312424 100644 --- a/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp +++ b/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp @@ -1,52 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QStandardItemModel> +#include <QTreeView> +#include <QWidget> + +namespace src_gui_itemviews_qstandarditemmodel { +struct MyWidget : public QWidget +{ + void wrapper2(); + void clicked(const QModelIndex &index); + QModelIndex index() { return QModelIndex(); } + QStandardItemModel *myStandardItemModel; +}; + +void wrapper0() { //! [0] QStandardItemModel model(4, 4); @@ -58,6 +25,10 @@ for (int row = 0; row < model.rowCount(); ++row) { } //! [0] +} // wrapper0 + + +void wrapper1() { //! [1] QStandardItemModel model; @@ -69,7 +40,10 @@ for (int i = 0; i < 4; ++i) { } //! [1] +} // wrapper1 + +void MyWidget::wrapper2() { //! [2] QTreeView *treeView = new QTreeView(this); treeView->setModel(myStandardItemModel); @@ -77,6 +51,8 @@ connect(treeView, &QTreeView::clicked, this, &MyWidget::clicked); //! [2] +} // wrapper2 + //! [3] void MyWidget::clicked(const QModelIndex &index) @@ -87,6 +63,12 @@ void MyWidget::clicked(const QModelIndex &index) //! [3] +void wrapper3() { +QTreeView *treeView = nullptr; +MyWidget *item = nullptr; //! [4] treeView->scrollTo(item->index()); //! [4] + +} // wrapper3 +} // src_gui_itemviews_qstandarditemmodel diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qaction.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qaction.cpp new file mode 100644 index 0000000000..054b40d7c0 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_kernel_qaction.cpp @@ -0,0 +1,12 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +//! [0] +QApplication app(argc, argv); +app.setAttribute(Qt::AA_DontShowIconsInMenus); // Icons are *no longer shown* in menus +// ... +QAction *myAction = new QAction(); +// ... +myAction->setIcon(SomeIcon); +myAction->setIconVisibleInMenu(true); // Icon *will* be shown in menus for *this* action. +//! [0] diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp index 138d0dfa1b..9455cacf1c 100644 --- a/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp +++ b/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp @@ -1,122 +1,30 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QApplication> +#include <QStyleFactory> +#include <QWidget> -//! [0] -QCoreApplication* createApplication(int &argc, char *argv[]) -{ - for (int i = 1; i < argc; ++i) - if (!qstrcmp(argv[i], "-no-gui")) - return new QCoreApplication(argc, argv); - return new QApplication(argc, argv); -} - -int main(int argc, char* argv[]) -{ - QScopedPointer<QCoreApplication> app(createApplication(argc, argv)); - - if (qobject_cast<QApplication *>(app.data())) { - // start GUI version... - } else { - // start non-GUI version... - } - - return app->exec(); -} -//! [0] - -//! [1] -QApplication::setStyle(QStyleFactory::create("fusion")); -//! [1] - - -//! [2] -int main(int argc, char *argv[]) +namespace src_gui_kernel_qapplication { +struct MyWidget { - QApplication::setColorSpec(QApplication::ManyColor); - QApplication app(argc, argv); - ... - return app.exec(); -} -//! [2] - - -//! [3] -QSize MyWidget::sizeHint() const -{ - return QSize(80, 25); -} -//! [3] - - -//! [4] -void showAllHiddenTopLevelWidgets() -{ - const auto topLevelWidgets = QApplication::topLevelWidgets(); - for (QWidget *widget : topLevelWidgets) { - if (widget->isHidden()) - widget->show(); - } -} -//! [4] - - -//! [5] -void updateAllWidgets() -{ - const auto topLevelWidgets = QApplication::topLevelWidgets(); - for (QWidget *widget : topLevelWidgets) - widget->update(); -} -//! [5] - + QSize sizeHint() const; + + int foo = 0; + MyWidget operator- (MyWidget& other) + { + MyWidget tmp = other; + return tmp; + }; + int manhattanLength() { return 0; } +}; + +void startTheDrag() {}; +void wrapper1() { +MyWidget startPos; +MyWidget currentPos; +int x = 0; +int y = 0; //! [6] if ((startPos - currentPos).manhattanLength() >= @@ -124,15 +32,6 @@ if ((startPos - currentPos).manhattanLength() >= startTheDrag(); //! [6] -//! [7] -QWidget *widget = qApp->widgetAt(x, y); -if (widget) - widget = widget->window(); -//! [7] - +} // wrapper1 -//! [8] -QWidget *widget = qApp->widgetAt(point); -if (widget) - widget = widget->window(); -//! [8] +} // src_gui_kernel_qapplication diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp index 8581510133..61792521ca 100644 --- a/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp +++ b/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp @@ -1,57 +1,20 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QClipboard> +#include <QGuiApplication> +#include <QMimeData> + +namespace src_gui_kernel_qclipboard { +void wrapper() { +QString newText; +QString image; +QClipboard::Mode mode = QClipboard::Mode::Clipboard; + //! [0] QClipboard *clipboard = QGuiApplication::clipboard(); QString originalText = clipboard->text(); -... +// etc. clipboard->setText(newText); //! [0] @@ -61,3 +24,7 @@ QMimeData *data = new QMimeData; data->setImageData(image); clipboard->setMimeData(data, mode); //! [1] + + +} // wrapper +} // src_gui_kernel_qclipboard diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp index 44ce54a9bb..c24e755e92 100644 --- a/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp +++ b/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp @@ -1,52 +1,15 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QWheelEvent> + +namespace src_gui_kernel_qevent { +class MyWidget //: public QWidget +{ + void wheelEvent(QWheelEvent *event); + void scrollWithPixels(QPoint point); + void scrollWithDegrees(QPoint point); +}; + //! [0] void MyWidget::wheelEvent(QWheelEvent *event) @@ -64,3 +27,6 @@ void MyWidget::wheelEvent(QWheelEvent *event) event->accept(); } //! [0] + + +} // src_gui_kernel_qevent diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp index a399d444e1..347b47403e 100644 --- a/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp +++ b/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp @@ -1,59 +1,29 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QApplication> +#include <QMessageBox> +#include <QSessionManager> +#include <QWidget> + +namespace src_gui_kernel_qguiapplication { +struct MyMainWidget : public QWidget +{ + MyMainWidget(QWidget *parent); + void commitData(QSessionManager& manager); + bool saveDocument() { return true; }; + QStringList restartCommand() { return QStringList(); }; + QStringList discardCommand() { return QStringList(); }; +}; +MyMainWidget *mainWindow = nullptr; +void do_something(QString command) { Q_UNUSED(command); }; +MyMainWidget mySession(nullptr); //! [0] int main(int argc, char *argv[]) { QApplication::setDesktopSettingsAware(false); QApplication app(argc, argv); - ... + // ... return app.exec(); } //! [0] @@ -61,9 +31,8 @@ int main(int argc, char *argv[]) //! [1] MyMainWidget::MyMainWidget(QWidget *parent) - :QWidget(parent) + : QWidget(parent) { - QGuiApplication::setFallbackSessionManagementEnabled(false); connect(qApp, &QGuiApplication::commitDataRequest, this, &MyMainWidget::commitData); } @@ -97,20 +66,12 @@ void MyMainWidget::commitData(QSessionManager& manager) //! [1] +/* wrap snippet 2 + //! [2] appname -session id //! [2] +*/ // wrap snippet 2 -//! [3] -const QStringList commands = mySession.restartCommand(); -for (const QString &command : commands) - do_something(command); -//! [3] - - -//! [4] -const QStringList commands = mySession.discardCommand(); -for (const QString &command : mySession.discardCommand()) - do_something(command); -//! [4] +} // src_gui_kernel_qguiapplication diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication_x11.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication_x11.cpp index 961ecd6cde..b73f887af2 100644 --- a/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication_x11.cpp +++ b/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication_x11.cpp @@ -1,55 +1,20 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QCursor> +#include <QGuiApplication> + +namespace src_gui_kernel_qguiapplication_x11 { +void calculateHugeMandelbrot(); + +void wrapper() { + //! [0] QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); calculateHugeMandelbrot(); // lunch time... QGuiApplication::restoreOverrideCursor(); //! [0] + + +} // wrapper +} // src_gui_kernel_qguiapplication_x11 diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp index 2c49dd2d3d..0f335dd0a0 100644 --- a/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp +++ b/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp @@ -1,69 +1,39 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QKeySequence> +#include <QMenu> +#include <QTranslator> + + +namespace src_gui_kernel_qkeysequence { +struct Wrapper : public QWidget +{ void wrapper(); }; + +/* Wrap non-compilable code snippet //! [0] QKeySequence(QKeySequence::Print); QKeySequence(tr("Ctrl+P")); QKeySequence(tr("Ctrl+p")); -QKeySequence(Qt::CTRL + Qt::Key_P); +QKeySequence(Qt::CTRL | Qt::Key_P); +QKeySequence(Qt::CTRL + Qt::Key_P); // deprecated //! [0] //! [1] QKeySequence(tr("Ctrl+X, Ctrl+C")); -QKeySequence(Qt::CTRL + Qt::Key_X, Qt::CTRL + Qt::Key_C); +QKeySequence(Qt::CTRL | Qt::Key_X, Qt::CTRL | Qt::Key_C); +QKeySequence(Qt::CTRL + Qt::Key_X, Qt::CTRL + Qt::Key_C); // deprecated //! [1] +*/ // Wrap non-compilable code snippet +void Wrapper::wrapper() { //! [2] QMenu *file = new QMenu(this); -file->addAction(tr("&Open..."), this, SLOT(open()), - QKeySequence(tr("Ctrl+O", "File|Open"))); +file->addAction(tr("&Open..."), QKeySequence(tr("Ctrl+O", "File|Open")), + this, &MainWindow::open); //! [2] + +} // Wrapper::wrapper +} // src_gui_kernel_qkeysequence diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qshortcut.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qshortcut.cpp new file mode 100644 index 0000000000..d67aea1288 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_kernel_qshortcut.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +//! [0] +shortcut = new QShortcut(QKeySequence(tr("Ctrl+O", "File|Open")), + parent); +//! [0] + + +//! [1] +setKey(0); // no signal emitted +setKey(QKeySequence()); // no signal emitted +setKey(0x3b1); // Greek letter alpha +setKey(Qt::Key_D); // 'd', e.g. to delete +setKey('q'); // 'q', e.g. to quit +setKey(Qt::CTRL | Qt::Key_P); // Ctrl+P, e.g. to print document +setKey("Ctrl+P"); // Ctrl+P, e.g. to print document +//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp index 8bb0726c77..c08b318a4d 100644 --- a/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp +++ b/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp @@ -1,53 +1,15 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QKeySequence> + +namespace src_gui_kernel_qshortcutmap { + +void wrapper() { +QKeySequence key; //! [0] key = QKeySequence(); //! [0] + +} // wrapper +} // src_gui_kernel_qshortcutmap diff --git a/src/gui/doc/snippets/code/src_gui_math3d_qquaternion.cpp b/src/gui/doc/snippets/code/src_gui_math3d_qquaternion.cpp index 8da438e3a7..6f27ba9db9 100644 --- a/src/gui/doc/snippets/code/src_gui_math3d_qquaternion.cpp +++ b/src/gui/doc/snippets/code/src_gui_math3d_qquaternion.cpp @@ -1,57 +1,28 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QQuaternion> +#include <QVector3D> + + +namespace src_gui_math3d_qquaternion { +QQuaternion q; +QVector3D vector; +void wrapper0() { //! [0] - QVector3D result = q.rotatedVector(vector); +QVector3D result = q.rotatedVector(vector); //! [0] +Q_UNUSED(result); +} // wrapper0 + + +void wrapper1() { + //! [1] - QVector3D result = (q * QQuaternion(0, vector) * q.conjugated()).vector(); +QVector3D result = (q * QQuaternion(0, vector) * q.conjugated()).vector(); //! [1] + +Q_UNUSED(result); +} // wrapper1 +} // src_gui_math3d_qquaternion diff --git a/src/gui/doc/snippets/code/src_gui_opengl_qopenglbuffer.cpp b/src/gui/doc/snippets/code/src_gui_opengl_qopenglbuffer.cpp deleted file mode 100644 index 57dc909598..0000000000 --- a/src/gui/doc/snippets/code/src_gui_opengl_qopenglbuffer.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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] - QOpenGLBuffer buffer1(QOpenGLBuffer::IndexBuffer); - buffer1.create(); - - QOpenGLBuffer buffer2 = buffer1; -//! [0] - -//! [1] - QOpenGLBuffer::release(QOpenGLBuffer::VertexBuffer); -//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_opengl_qopengldebug.cpp b/src/gui/doc/snippets/code/src_gui_opengl_qopengldebug.cpp deleted file mode 100644 index e82447a174..0000000000 --- a/src/gui/doc/snippets/code/src_gui_opengl_qopengldebug.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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] - GLenum error = GL_NO_ERROR; - do { - error = glGetError(); - if (error != GL_NO_ERROR) - // handle the error - } while (error != GL_NO_ERROR); -//! [0] - -//! [1] - QSurfaceFormat format; - // asks for a OpenGL 3.2 debug context using the Core profile - format.setMajorVersion(3); - format.setMinorVersion(2); - format.setProfile(QSurfaceFormat::CoreProfile); - format.setOption(QSurfaceFormat::DebugContext); - - QOpenGLContext *context = new QOpenGLContext; - context->setFormat(format); - context->create(); -//! [1] - -//! [2] - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this); - - logger->initialize(); // initializes in the current context, i.e. ctx -//! [2] - -//! [3] - ctx->hasExtension(QByteArrayLiteral("GL_KHR_debug")) -//! [3] - -//! [4] - const QList<QOpenGLDebugMessage> messages = logger->loggedMessages(); - for (const QOpenGLDebugMessage &message : messages) - qDebug() << message; -//! [4] - -//! [5] - connect(logger, &QOpenGLDebugLogger::messageLogged, receiver, &LogHandler::handleLoggedMessage); - logger->startLogging(); -//! [5] - -//! [6] - QOpenGLDebugMessage message = - QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("Custom message")); - - logger->logMessage(message); -//! [6] diff --git a/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp b/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp index e4255107d3..14531446a1 100644 --- a/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp +++ b/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp @@ -1,112 +1,86 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QOpenGLFunctions> +#include <QtOpenGL/QOpenGLWindow> + +#include <QSurface> +#include <QWidget> +#include <QWindow> + +namespace src_gui_opengl_qopenglfunctions { //! [0] - class MyGLWindow : public QWindow, protected QOpenGLFunctions - { - Q_OBJECT - public: - explicit MyGLWindow(QScreen *screen = nullptr); - - protected: - void initializeGL(); - void paintGL(); - - QOpenGLContext *m_context; - }; - - MyGLWindow(QScreen *screen) - : QWindow(screen), QOpenGLWidget(parent) - { - setSurfaceType(OpenGLSurface); - create(); - - // Create an OpenGL context - m_context = new QOpenGLContext; - m_context->create(); - - // Setup scene and render it - initializeGL(); - paintGL(); - } - - void MyGLWindow::initializeGL() - { - m_context->makeCurrent(this); - initializeOpenGLFunctions(); - } +class MyGLWindow : public QWindow, protected QOpenGLFunctions +{ + Q_OBJECT +public: + explicit MyGLWindow(QScreen *screen = nullptr); + +protected: + void initializeGL(); + void paintGL(); + + QOpenGLContext *m_context; +}; + +MyGLWindow::MyGLWindow(QScreen *screen) + : QWindow(screen) +{ + setSurfaceType(OpenGLSurface); + create(); + + // Create an OpenGL context + m_context = new QOpenGLContext; + m_context->create(); + + // Setup scene and render it + initializeGL(); + paintGL(); +}; + +void MyGLWindow::initializeGL() +{ + m_context->makeCurrent(this); + initializeOpenGLFunctions(); +} //! [0] + +int textureId = 0; + //! [1] - void MyGLWindow::paintGL() - { - m_context->makeCurrent(this); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, textureId); - ... - m_context->swapBuffers(this); - m_context->doneCurrent(); - } +void MyGLWindow::paintGL() +{ + m_context->makeCurrent(this); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, textureId); + // ... + m_context->swapBuffers(this); + m_context->doneCurrent(); +} //! [1] + +void wrapper0() { //! [2] - QOpenGLFunctions glFuncs(QOpenGLContext::currentContext()); - glFuncs.glActiveTexture(GL_TEXTURE1); +QOpenGLFunctions glFuncs(QOpenGLContext::currentContext()); +glFuncs.glActiveTexture(GL_TEXTURE1); //! [2] +} // wrapper0 + +void wrapper1() { //! [3] - QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); - glFuncs->glActiveTexture(GL_TEXTURE1); +QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); +glFuncs->glActiveTexture(GL_TEXTURE1); //! [3] + //! [4] - QOpenGLFunctions funcs(QOpenGLContext::currentContext()); - bool npot = funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures); +QOpenGLFunctions funcs(QOpenGLContext::currentContext()); +bool npot = funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures); //! [4] + +Q_UNUSED(npot); +} // wrapper1 +} // src_gui_opengl_qopenglfunctions diff --git a/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp b/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp index 786d6ca183..69eedff7d1 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp @@ -1,52 +1,14 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QPainter> + +namespace src_gui_painting_qbrush { + +struct Wrapper : public QPaintDevice { + void wrapper(); +}; +void Wrapper::wrapper() { + //! [0] QPainter painter(this); @@ -59,3 +21,7 @@ painter.setBrush(Qt::NoBrush); painter.setPen(Qt::darkGreen); painter.drawRect(40, 40, 100, 100); //! [0] + + +} // Wrapper::wrapper +} // src_gui_painting_qbrush diff --git a/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp b/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp index 5285a19a0a..0a2bc832ff 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp @@ -1,59 +1,32 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QPainter> + +namespace src_gui_painting_qcolor { +int width() { return 1; }; +int height() { return 1; }; +QPainter painter; +void wrapper() { + //! [0] // Specify semi-transparent red painter.setBrush(QColor(255, 0, 0, 127)); -painter.drawRect(0, 0, width()/2, height()); +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); +painter.drawRect(0, 0, width(), height() / 2); //! [0] + +//! [QRgb] +const QRgb rgb1 = 0x88112233; +const QRgb rgb2 = QColor("red").rgb(); +const QRgb rgb3 = qRgb(qRed(rgb1), qGreen(rgb2), qBlue(rgb2)); +const QRgb rgb4 = qRgba(qRed(rgb1), qGreen(rgb2), qBlue(rgb2), qAlpha(rgb1)); +//! [QRgb] +Q_UNUSED(rgb3); +Q_UNUSED(rgb4); + +} // wrapper +} // src_gui_painting_qcolor diff --git a/src/gui/doc/snippets/code/src_gui_painting_qmatrix.cpp b/src/gui/doc/snippets/code/src_gui_painting_qmatrix.cpp deleted file mode 100644 index 30beec799a..0000000000 --- a/src/gui/doc/snippets/code/src_gui_painting_qmatrix.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 index d1ee6bbdea..cfbf3e44a2 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp @@ -1,52 +1,25 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QOpenGLFunctions> +#include <QPaintEvent> +#include <QPainter> +#include <QPainterPath> +#include <QPicture> +#include <QRectF> +#include <QWidget> + + +namespace src_gui_painting_qpainter { +struct SimpleExampleWidget : public QPaintDevice { + void paintEvent(QPaintEvent *); + QRect rect(); +}; +struct MyWidget : public QWidget +{ + void paintEvent(QPaintEvent *); +}; +QLine drawingCode; + //! [0] void SimpleExampleWidget::paintEvent(QPaintEvent *) @@ -64,21 +37,49 @@ void MyWidget::paintEvent(QPaintEvent *) { QPainter p; p.begin(this); - p.drawLine(...); // drawing code + p.drawLine(drawingCode); // drawing code p.end(); } //! [1] +} // src_gui_painting_qpainter +namespace src_gui_painting_qpainter2 { +struct MyWidget : public QWidget +{ + void paintEvent(QPaintEvent *); + int background() { return 0; } + void wrapper1(); + void wrapper2(); + void wrapper3(); + void wrapper4(); + void wrapper5(); + void wrapper6(); + void wrapper7(); + void wrapper8(); + void wrapper9(); + void wrapper10(); + void wrapper11(); + void wrapper12(); + void wrapper13(); + void wrapper14(); + void wrapper15(); + void concentricCircles(); +}; +QLine drawingCode; //! [2] void MyWidget::paintEvent(QPaintEvent *) { QPainter p(this); - p.drawLine(...); // drawing code + p.drawLine(drawingCode); // drawing code } //! [2] +void wrapper0() { +QPainter *painter = nullptr; +QPainter *painter2 = nullptr; +QPaintDevice *myWidget = nullptr; //! [3] painter->begin(0); // impossible - paint device cannot be 0 @@ -89,17 +90,17 @@ painter->begin(myWidget); painter2->begin(myWidget); // impossible - only one painter at a time //! [3] +} // wrapper0 -//! [4] -void QPainter::rotate(qreal angle) -{ - QTransform matrix; - matrix.rotate(angle); - setWorldTransform(matrix, true); -} -//! [4] +namespace QPainterWrapper { +struct QPainter { + void rotate(qreal angle); + void setWorldTransform(QTransform matrix, bool); +}; +} // QPainterWrapper +void MyWidget::wrapper1() { //! [5] QPainterPath path; path.moveTo(20, 80); @@ -114,10 +115,13 @@ painter.drawPath(path); //! [6] QLineF line(10.0, 80.0, 90.0, 20.0); -QPainter(this); +QPainter painter(this); painter.drawLine(line); //! [6] +} // MyWidget::wrapper1() + +void MyWidget::wrapper2() { //! [7] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -126,6 +130,10 @@ QPainter painter(this); painter.drawRect(rectangle); //! [7] +} // MyWidget::wrapper2 + + +void MyWidget::wrapper3() { //! [8] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -134,6 +142,10 @@ QPainter painter(this); painter.drawRoundedRect(rectangle, 20.0, 15.0); //! [8] +} // MyWidget::wrapper3 + + +void MyWidget::wrapper4() { //! [9] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -142,6 +154,10 @@ QPainter painter(this); painter.drawEllipse(rectangle); //! [9] +} // MyWidget::wrapper4 + + +void MyWidget::wrapper5() { //! [10] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -152,6 +168,10 @@ QPainter painter(this); painter.drawArc(rectangle, startAngle, spanAngle); //! [10] +} // MyWidget::wrapper5 + + +void MyWidget::wrapper6() { //! [11] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -162,6 +182,11 @@ QPainter painter(this); painter.drawPie(rectangle, startAngle, spanAngle); //! [11] +} // MyWidget::wrapper6 + + +void MyWidget::wrapper7() { +QRect rect; //! [12] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -171,7 +196,11 @@ int spanAngle = 120 * 16; QPainter painter(this); painter.drawChord(rect, startAngle, spanAngle); //! [12] +Q_UNUSED(rectangle); +} // MyWidget::wrapper7 + +void MyWidget::wrapper8() { //! [13] static const QPointF points[3] = { @@ -184,7 +213,10 @@ QPainter painter(this); painter.drawPolyline(points, 3); //! [13] +} // MyWidget::wrapper8 + +void MyWidget::wrapper9() { //! [14] static const QPointF points[4] = { QPointF(10.0, 80.0), @@ -197,6 +229,10 @@ QPainter painter(this); painter.drawPolygon(points, 4); //! [14] +} // MyWidget::wrapper9 + + +void MyWidget::wrapper10() { //! [15] static const QPointF points[4] = { @@ -216,31 +252,52 @@ 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); +QPainter painter(this); painter.drawPixmap(target, pixmap, source); //! [16] +} // MyWidget::wrapper10 + + +void MyWidget::wrapper11() { +QRect rect; //! [17] QPainter painter(this); painter.drawText(rect, Qt::AlignCenter, tr("Qt\nProject")); //! [17] +} // MyWidget::wrapper11 + + +QRectF fillRect(QRect rect, int background) { + Q_UNUSED(rect); + Q_UNUSED(background); + return QRectF(); +}; +void MyWidget::wrapper12() { +QRect rectangle; //! [18] QPicture picture; -QPointF point(10.0, 20.0) +QPointF point(10.0, 20.0); picture.load("drawing.pic"); QPainter painter(this); painter.drawPicture(0, 0, picture); //! [18] +Q_UNUSED(point); + //! [19] -fillRect(rectangle, background()). +fillRect(rectangle, background()); //! [19] +} // MyWidget::wrapper12 + + +void MyWidget::wrapper13() { //! [20] QRectF target(10.0, 20.0, 80.0, 60.0); @@ -251,6 +308,10 @@ QPainter painter(this); painter.drawImage(target, image, source); //! [20] +} // MyWidget::wrapper13 + + +void MyWidget::wrapper14() { //! [21] QPainter painter(this); @@ -268,6 +329,11 @@ glDisable(GL_SCISSOR_TEST); painter.endNativePainting(); //! [21] +} // MyWidget::wrapper14 + + +void MyWidget::wrapper15() { + //! [drawText] QPainter painter(this); QFont font = painter.font(); @@ -287,3 +353,24 @@ pen.setStyle(Qt::DashLine); painter.setPen(pen); painter.drawRect(rectangle.adjusted(0, 0, -pen.width(), -pen.width())); //! [drawText] + + +} // MyWidget::wrapper15 + +void MyWidget::concentricCircles() +{ +//! [renderHint] + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing, true); +//! [renderHint] + int diameter = 50; +//! [floatBased] + painter.drawEllipse(QRectF(-diameter / 2.0, -diameter / 2.0, diameter, diameter)); +//! [floatBased] +//! [intBased] + painter.drawEllipse(QRect(-diameter / 2, -diameter / 2, diameter, diameter)); +//! [intBased] + +} // MyWidget::concentricCircles + +} // src_gui_painting_qpainter2
\ No newline at end of file diff --git a/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp b/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp index e6d72fce12..cd538b750c 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp @@ -1,52 +1,26 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QLinearGradient> +#include <QPainter> +#include <QPainterPath> +#include <QPen> + +namespace src_gui_painting_qpainterpath { +struct Wrapper : QPaintDevice +{ + Q_OBJECT + + void wrapper0(); + void wrapper1(); + void wrapper2(); + void wrapper3(); + void wrapper4(); + void wrapper5(); + void wrapper6(); + void wrapper7(); +}; + +void Wrapper::wrapper0() { //! [0] QPainterPath path; @@ -65,6 +39,13 @@ painter.setBrush(QColor(122, 163, 39)); painter.drawPath(path); //! [0] +} // Wrapper::wrapper0 + + +void Wrapper::wrapper1() { +const QPointF c1; +const QPointF c2; +const QPointF endPoint; //! [1] QLinearGradient myGradient; @@ -79,13 +60,17 @@ painter.setPen(myPen); painter.drawPath(myPath); //! [1] +} // Wrapper::wrapper1 -//! [2] + +void Wrapper::wrapper2() { +const QRectF boundingRect; +qreal startAngle = 0; +qreal sweepLength = 0; +QPointF center; QLinearGradient myGradient; QPen myPen; - -QPointF center, startPoint; - +//! [2] QPainterPath myPath; myPath.moveTo(center); myPath.arcTo(boundingRect, startAngle, @@ -97,6 +82,10 @@ painter.setPen(myPen); painter.drawPath(myPath); //! [2] +} // Wrapper::wrapper2 + + +void Wrapper::wrapper3() { //! [3] QLinearGradient myGradient; @@ -112,6 +101,10 @@ painter.setPen(myPen); painter.drawPath(myPath); //! [3] +} // Wrapper::wrapper3 + + +void Wrapper::wrapper4() { //! [4] QLinearGradient myGradient; @@ -127,6 +120,10 @@ painter.setPen(myPen); painter.drawPath(myPath); //! [4] +} // Wrapper::wrapper4 + + +void Wrapper::wrapper5() { //! [5] QLinearGradient myGradient; @@ -142,6 +139,12 @@ painter.setPen(myPen); painter.drawPath(myPath); //! [5] +} // Wrapper::wrapper5 + + +void Wrapper::wrapper6() { +qreal x = 0; +qreal y = 0; //! [6] QLinearGradient myGradient; @@ -157,3 +160,7 @@ painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath); //! [6] + + +} // Wrapper::wrapper6 +} // src_gui_painting_qpainterpath diff --git a/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp b/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp index d899418a3f..a9c21afb9f 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp @@ -1,52 +1,18 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QPainter> +#include <QPen> + +namespace src_gui_painting_qpen { +struct Wrapper : QPaintDevice +{ + void wrapper0(); + void wrapper1(); + void wrapper2(); + void wrapper3(); +}; + +void Wrapper::wrapper0() { //! [0] QPainter painter(this); @@ -54,6 +20,10 @@ QPen pen(Qt::green, 3, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin); painter.setPen(pen); //! [0] +} // Wrapper::wrapper0 + + +void Wrapper::wrapper1() { //! [1] QPainter painter(this); @@ -68,10 +38,14 @@ pen.setJoinStyle(Qt::RoundJoin); painter.setPen(pen); //! [1] +} // Wrapper::wrapper1 + + +void Wrapper::wrapper2() { //! [2] QPen pen; -QVector<qreal> dashes; +QList<qreal> dashes; qreal space = 4; dashes << 1 << space << 3 << space << 9 << space @@ -80,12 +54,18 @@ dashes << 1 << space << 3 << space << 9 << space pen.setDashPattern(dashes); //! [2] +} // Wrapper::wrapper2 + +void Wrapper::wrapper3() { //! [3] QPen pen; -QVector<qreal> dashes; +QList<qreal> dashes; qreal space = 4; dashes << 1 << space << 3 << space << 9 << space << 27 << space << 9 << space; pen.setDashPattern(dashes); //! [3] + +} // Wrapper::wrapper3 +} // src_gui_painting_qpen diff --git a/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp b/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp index 496791dc0f..6401c29de5 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp @@ -1,52 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QPaintEvent> +#include <QPainter> + +namespace src_gui_painting_qregion { +struct MyWidget : public QPaintDevice +{ + void paintEvent(QPaintEvent *); +}; //! [0] void MyWidget::paintEvent(QPaintEvent *) @@ -58,6 +19,8 @@ void MyWidget::paintEvent(QPaintEvent *) QPainter painter(this); painter.setClipRegion(r3); - ... // paint clipped graphics + // ... // paint clipped graphics } //! [0] + +} // src_gui_painting_qregion 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 index ab22507c4f..26a95566d4 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qregion_unix.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qregion_unix.cpp @@ -1,53 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QRegion> +namespace src_gui_painting_qregion_unix { + +void wrapper() { //! [0] QRegion r1(10, 10, 20, 20); r1.isEmpty(); // false @@ -62,3 +19,6 @@ r3.isEmpty(); // true r3 = r1.united(r2); // r3: union of r1 and r2 r3.isEmpty(); // false //! [0] + +} // wrapper +} // src_gui_painting_qregion_unix diff --git a/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp b/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp index 4acc2f12b7..fbc6d9add8 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp @@ -1,57 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +namespace src_gui_painting_qtransform { +/* wrap non-code snippets //! [0] x' = m11*x + m21*y + dx y' = m22*y + m12*x + dy -if (is not affine) { +if (!isAffine()) { w' = m13*x + m23*y + m33 x' /= w' y' /= w' @@ -62,7 +18,7 @@ if (is not affine) { //! [1] x' = m11*x + m21*y + dx y' = m22*y + m12*x + dy -if (is not affine) { +if (!isAffine()) { w' = m13*x + m23*y + m33 x' /= w' y' /= w' @@ -73,7 +29,7 @@ if (is not affine) { //! [2] x' = m11*x + m21*y + dx y' = m22*y + m12*x + dy -if (is not affine) { +if (!isAffine()) { w' = m13*x + m23*y + m33 x' /= w' y' /= w' @@ -84,9 +40,12 @@ if (is not affine) { //! [3] x' = m11*x + m21*y + dx y' = m22*y + m12*x + dy -if (is not affine) { +if (!isAffine()) { w' = m13*x + m23*y + m33 x' /= w' y' /= w' } //! [3] + +*/ // wrap non-code snippets +} // src_gui_painting_qtransform diff --git a/src/gui/doc/snippets/code/src_gui_qopenglshaderprogram.cpp b/src/gui/doc/snippets/code/src_gui_qopenglshaderprogram.cpp deleted file mode 100644 index 8e67a2270c..0000000000 --- a/src/gui/doc/snippets/code/src_gui_qopenglshaderprogram.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 index 1901ca9b10..d62730e918 100644 --- a/src/gui/doc/snippets/code/src_gui_text_qfont.cpp +++ b/src/gui/doc/snippets/code/src_gui_text_qfont.cpp @@ -1,53 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QFont> +#include <QFontInfo> +#include <QFontMetrics> +namespace src_gui_text_qfont { + +void wrapper0() { //! [0] QFont serifFont("Times", 10, QFont::Bold); QFont sansFont("Helvetica [Cronyx]", 12); @@ -58,7 +17,11 @@ QFont sansFont("Helvetica [Cronyx]", 12); QFont f("Helvetica"); //! [1] +} // wrapper0 + +void wrapper1() { +QFont f1; //! [2] QFont f("Helvetica [Cronyx]"); //! [2] @@ -75,3 +38,8 @@ QFontMetrics fm(f1); int textWidthInPixels = fm.horizontalAdvance("How many pixels wide is this text?"); int textHeightInPixels = fm.height(); //! [4] + +Q_UNUSED(textWidthInPixels); +Q_UNUSED(textHeightInPixels); +} // wrapper +} // src_gui_text_qfont diff --git a/src/gui/doc/snippets/code/src_gui_text_qfontmetrics.cpp b/src/gui/doc/snippets/code/src_gui_text_qfontmetrics.cpp index 6b478d3297..4650ad8d8f 100644 --- a/src/gui/doc/snippets/code/src_gui_text_qfontmetrics.cpp +++ b/src/gui/doc/snippets/code/src_gui_text_qfontmetrics.cpp @@ -1,64 +1,33 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QFont> +#include <QFontMetrics> +namespace src_gui_text_qfontmetrics { + +void wrapper0() { //! [0] QFont font("times", 24); QFontMetrics fm(font); -int pixelsWide = fm.horizontalAdvance("What's the width of this text?"); +int pixelsWide = fm.horizontalAdvance("What's the advance width of this text?"); int pixelsHigh = fm.height(); //! [0] +Q_UNUSED(pixelsWide); +Q_UNUSED(pixelsHigh); +} // wrapper0 + +void wrapper1() { //! [1] QFont font("times", 24); QFontMetricsF fm(font); -qreal pixelsWide = fm.horizontalAdvance("What's the width of this text?"); +qreal pixelsWide = fm.horizontalAdvance("What's the advance width of this text?"); qreal pixelsHigh = fm.height(); //! [1] + +Q_UNUSED(pixelsWide); +Q_UNUSED(pixelsHigh); +} // wrapper1 + +} //src_gui_text_qfontmetrics diff --git a/src/gui/doc/snippets/code/src_gui_text_qsyntaxhighlighter.cpp b/src/gui/doc/snippets/code/src_gui_text_qsyntaxhighlighter.cpp index bb27eb9612..fa4798ea04 100644 --- a/src/gui/doc/snippets/code/src_gui_text_qsyntaxhighlighter.cpp +++ b/src/gui/doc/snippets/code/src_gui_text_qsyntaxhighlighter.cpp @@ -1,52 +1,23 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QChar> +#include <QList> +#include <QRegularExpression> +#include <QSyntaxHighlighter> +#include <QTextBlockUserData> +#include <QTextEdit> +#include <QTextObject> + +namespace src_gui_text_qsyntaxhighlighter { +struct MyHighlighter : public QSyntaxHighlighter +{ + explicit MyHighlighter(QTextDocument *document) : QSyntaxHighlighter(document) { Q_UNUSED(document); } + + void highlightBlock(const QString &text); + void wrapper(); + + QString text; +}; //! [0] QTextEdit *editor = new QTextEdit; @@ -63,15 +34,14 @@ void MyHighlighter::highlightBlock(const QString &text) QRegularExpression expression("\\bMy[A-Za-z]+\\b"); QRegularExpressionMatchIterator i = expression.globalMatch(text); - while (i.hasNext()) - { - QRegularExpressionMatch match = i.next(); - setFormat(match.capturedStart(), match.capturedLength(), myClassFormat); + while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + setFormat(match.capturedStart(), match.capturedLength(), myClassFormat); } } //! [1] - +void MyHighlighter::wrapper() { //! [2] QTextCharFormat multiLineCommentFormat; multiLineCommentFormat.setForeground(Qt::red); @@ -86,32 +56,35 @@ if (previousBlockState() != 1) startIndex = text.indexOf(startExpression); while (startIndex >= 0) { - QRegularExpressionMatch endMatch; - int endIndex = text.indexOf(endExpression, startIndex, &endMatch); - int commentLength; - if (endIndex == -1) { - setCurrentBlockState(1); - commentLength = text.length() - startIndex; - } else { - commentLength = endIndex - startIndex - + endMatch.capturedLength(); - } - setFormat(startIndex, commentLength, multiLineCommentFormat); - startIndex = text.indexOf(startExpression, - startIndex + commentLength); + QRegularExpressionMatch endMatch; + int endIndex = text.indexOf(endExpression, startIndex, &endMatch); + int commentLength; + if (endIndex == -1) { + setCurrentBlockState(1); + commentLength = text.length() - startIndex; + } else { + commentLength = endIndex - startIndex + + endMatch.capturedLength(); + } + setFormat(startIndex, commentLength, multiLineCommentFormat); + startIndex = text.indexOf(startExpression, + startIndex + commentLength); } //! [2] +} // MyHighlighter::wrapper //! [3] struct ParenthesisInfo { - QChar char; + QChar character; int position; }; struct BlockData : public QTextBlockUserData { - QVector<ParenthesisInfo> parentheses; + QList<ParenthesisInfo> parentheses; }; //! [3] + +} // src_gui_text_qsyntaxhighlighter diff --git a/src/gui/doc/snippets/code/src_gui_text_qtextcursor.cpp b/src/gui/doc/snippets/code/src_gui_text_qtextcursor.cpp index d66cc1407f..1438474b98 100644 --- a/src/gui/doc/snippets/code/src_gui_text_qtextcursor.cpp +++ b/src/gui/doc/snippets/code/src_gui_text_qtextcursor.cpp @@ -1,52 +1,15 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QImage> +#include <QTextCursor> +#include <QTextDocument> + +namespace src_gui_text_qtextcursor { +QTextDocument *textDocument = nullptr; + +void wrapper0() { +QTextCursor cursor; + //! [0] cursor.clearSelection(); @@ -56,12 +19,15 @@ cursor.insertText("Hello World"); //! [1] -QImage img = ... +QImage img; textDocument->addResource(QTextDocument::ImageResource, QUrl("myimage"), img); cursor.insertImage("myimage"); //! [1] +} // wrapper0 + +void wrapper1() { //! [2] QTextCursor cursor(textDocument); cursor.beginEditBlock(); @@ -71,8 +37,10 @@ cursor.endEditBlock(); textDocument->undo(); //! [2] +} // wrapper1 +void wrapper2() { //! [3] QTextCursor cursor(textDocument); cursor.beginEditBlock(); @@ -80,7 +48,7 @@ cursor.insertText("Hello"); cursor.insertText("World"); cursor.endEditBlock(); -... +// ... cursor.joinPreviousEditBlock(); cursor.insertText("Hey"); @@ -88,3 +56,6 @@ cursor.endEditBlock(); textDocument->undo(); //! [3] +} // wrapper2 + +} // src_gui_text_qtextcursor diff --git a/src/gui/doc/snippets/code/src_gui_text_qtextdocument.cpp b/src/gui/doc/snippets/code/src_gui_text_qtextdocument.cpp deleted file mode 100644 index 66a8bc7b5e..0000000000 --- a/src/gui/doc/snippets/code/src_gui_text_qtextdocument.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 index 06aab74e10..a55857cb88 100644 --- a/src/gui/doc/snippets/code/src_gui_text_qtextdocumentwriter.cpp +++ b/src/gui/doc/snippets/code/src_gui_text_qtextdocumentwriter.cpp @@ -1,55 +1,14 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QTextDocumentWriter> +namespace src_gui_text_qtextdocumentwriter { + +void wrapper() { //! [0] QTextDocumentWriter writer; writer.setFormat("odf"); // same as writer.setFormat("ODF"); //! [0] +} // wrapper +} // src_gui_text_qtextdocumentwriter diff --git a/src/gui/doc/snippets/code/src_gui_text_qtextlayout.cpp b/src/gui/doc/snippets/code/src_gui_text_qtextlayout.cpp index 4244f0ce6d..70ec6b01ea 100644 --- a/src/gui/doc/snippets/code/src_gui_text_qtextlayout.cpp +++ b/src/gui/doc/snippets/code/src_gui_text_qtextlayout.cpp @@ -1,59 +1,31 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QFont> +#include <QFontMetrics> +#include <QPainter> +#include <QTextLayout> +#include <QTextLine> + +namespace src_gui_text_qtextlayout { +struct Wrapper : public QPaintDevice +{ + void wrapper1(); + void elided(); +}; +QTextLayout textLayout; + + +void wrapper0() { +qreal lineWidth = 0; +QFont aFont; +QFontMetrics fontMetrics(aFont); //! [0] int leading = fontMetrics.leading(); qreal height = 0; textLayout.setCacheEnabled(true); textLayout.beginLayout(); -while (1) { +while (true) { QTextLine line = textLayout.createLine(); if (!line.isValid()) break; @@ -66,8 +38,53 @@ while (1) { textLayout.endLayout(); //! [0] +} // wrapper0 + + +void Wrapper::wrapper1() { //! [1] QPainter painter(this); textLayout.draw(&painter, QPoint(0, 0)); //! [1] + +} // Wrapper::wrapper1 + +void Wrapper::elided() { + +QString content; + +//! [elided] +QPainter painter(this); +QFontMetrics fontMetrics = painter.fontMetrics(); + +int lineSpacing = fontMetrics.lineSpacing(); +int y = 0; + +QTextLayout textLayout(content, painter.font()); +textLayout.beginLayout(); +while (true) { + QTextLine line = textLayout.createLine(); + + if (!line.isValid()) + break; + + line.setLineWidth(width()); + const int nextLineY = y + lineSpacing; + + if (height() >= nextLineY + lineSpacing) { + line.draw(&painter, QPoint(0, y)); + y = nextLineY; + } else { + const QString lastLine = content.mid(line.textStart()); + const QString elidedLastLine = fontMetrics.elidedText(lastLine, Qt::ElideRight, width()); + painter.drawText(QPoint(0, y + fontMetrics.ascent()), elidedLastLine); + line = textLayout.createLine(); + break; + } +} +textLayout.endLayout(); +//! [elided] +} + +} // src_gui_text_qtextlayout diff --git a/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp b/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp index 6527021dd6..13deb88bc8 100644 --- a/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp +++ b/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp @@ -1,73 +1,48 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QDesktopServices> +#include <QObject> +#include <QStandardPaths> +#include <QUrl> + +namespace src_gui_util_qdesktopservices { //! [0] class MyHelpHandler : public QObject { Q_OBJECT public: - ... + // ... public slots: void showHelp(const QUrl &url); }; +//! [0] +void wrapper0() { +MyHelpHandler *helpInstance = nullptr; +//! [setUrlHandler] QDesktopServices::setUrlHandler("help", helpInstance, "showHelp"); -//! [0] +//! [setUrlHandler] +} // wrapper + + +/* comment wrapper 1 //! [1] mailto:user@foo.com?subject=Test&body=Just a test //! [1] +*/ // comment wrapper 1 + + +void wrapper1() { //! [2] -QDesktopServices::openUrl(QUrl("file:///C:/Documents and Settings/All Users/Desktop", QUrl::TolerantMode)); +QDesktopServices::openUrl(QUrl("file:///C:/Program Files", QUrl::TolerantMode)); //! [2] +} + + +/* comment wrapper 2 //! [3] <key>LSApplicationQueriesSchemes</key> @@ -88,15 +63,9 @@ QDesktopServices::openUrl(QUrl("file:///C:/Documents and Settings/All Users/Desk </array> //! [4] -//! [5] -QDesktopServices::storageLocation(QDesktopServices::DataLocation) -//! [5] - -//! [6] -QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + - "/data/organization/application" -//! [6] +*/ // comment wrapper 2 +/* comment wrapper 3 //! [7] <key>com.apple.developer.associated-domains</key> <array> @@ -118,3 +87,32 @@ QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + } } //! [8] + +//! [9] +<intent-filter> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + <data android:scheme="https" android:host="your.domain.com" android:port="1337" android:path="/help"/> +</intent-filter> +//! [9] + +//! [10] +<intent-filter android:autoVerify="true"> +//! [10] + +//! [11] +[{ + "relation": ["delegate_permission/common.handle_all_urls"], + "target": { + "namespace": "android_app", + "package_name": "com.example.app", + "sha256_cert_fingerprints": + ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"] + } +}] +//! [11] + +*/ // comment wrapper 3 + +} // src_gui_util_qdesktopservices diff --git a/src/gui/doc/snippets/code/src_gui_util_qundostack.cpp b/src/gui/doc/snippets/code/src_gui_util_qundostack.cpp new file mode 100644 index 0000000000..fe3ced1d02 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_util_qundostack.cpp @@ -0,0 +1,72 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +//! [0] +class AppendText : public QUndoCommand +{ +public: + AppendText(QString *doc, const QString &text) + : m_document(doc), m_text(text) { setText("append text"); } + void undo() override + { m_document->chop(m_text.length()); } + void redo() override + { m_document->append(m_text); } +private: + QString *m_document; + QString m_text; +}; +//! [0] + + +//! [1] +MyCommand *command1 = new MyCommand(); +stack->push(command1); +MyCommand *command2 = new MyCommand(); +stack->push(command2); + +stack->undo(); + +MyCommand *command3 = new MyCommand(); +stack->push(command3); // command2 gets deleted +//! [1] + + +//! [2] +QUndoCommand *insertRed = new QUndoCommand(); // an empty command +insertRed->setText("insert red text"); + +new InsertText(document, idx, text, insertRed); // becomes child of insertRed +new SetColor(document, idx, text.length(), Qt::red, insertRed); + +stack.push(insertRed); +//! [2] + + +//! [3] +bool AppendText::mergeWith(const QUndoCommand *other) +{ + if (other->id() != id()) // make sure other is also an AppendText command + return false; + m_text += static_cast<const AppendText*>(other)->m_text; + return true; +} +//! [3] + + +//! [4] +stack.beginMacro("insert red text"); +stack.push(new InsertText(document, idx, text)); +stack.push(new SetColor(document, idx, text.length(), Qt::red)); +stack.endMacro(); // indexChanged() is emitted +//! [4] + + +//! [5] +QUndoCommand *insertRed = new QUndoCommand(); // an empty command +insertRed->setText("insert red text"); + +new InsertText(document, idx, text, insertRed); // becomes child of insertRed +new SetColor(document, idx, text.length(), Qt::red, insertRed); + +stack.push(insertRed); +//! [5] diff --git a/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp b/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp index 1297ad8afe..f562126ffd 100644 --- a/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp +++ b/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp @@ -1,53 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ - +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QLineEdit> +#include <QValidator> +#include <QWidget> + +namespace src_gui_util_qvalidator { + +struct Wrapper : public QWidget { + void wrapper0(); + void wrapper1(); + void wrapper2(); + void wrapper3(); +}; + +void Wrapper::wrapper0() { //! [0] QValidator *validator = new QIntValidator(100, 999, this); QLineEdit *edit = new QLineEdit(this); @@ -84,7 +50,11 @@ v.validate(str, pos); // returns Invalid str = "12cm"; v.validate(str, pos); // returns Invalid //! [1] +} // Wrapper::wrapper0 +void Wrapper::wrapper1() { +QString s; +QIntValidator v(100, 900, this); //! [2] int pos = 0; @@ -98,6 +68,10 @@ v.validate(s, pos); // returns Intermediate s = "50"; v.validate(s, pos); // returns Acceptable //! [2] +} // Wrapper::wrapper1 + + +void Wrapper::wrapper2() { //! [5] // regexp: optional '-' followed by between 1 and 3 digits @@ -133,7 +107,7 @@ s = "A12345Z"; v.validate(s, pos); // Returns Acceptable s = "B12"; v.validate(s, pos); // Returns Intermediate // match most 'readme' files -re.setPattern("read\\S?me(\.(txt|asc|1st))?"); +re.setPattern("read\\S?me(\\.(txt|asc|1st))?"); re.setPatternOptions(QRegularExpression::CaseInsensitiveOption); v.setRegularExpression(re); s = "readme"; v.validate(s, pos); // Returns Acceptable @@ -141,3 +115,25 @@ 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 //! [6] + +} // Wrapper::wrapper2 + +void Wrapper::wrapper3() +{ +//! [7] +QString input = "0.98765e2"; +QDoubleValidator val; +val.setLocale(QLocale::C); +val.setNotation(QDoubleValidator::ScientificNotation); +val.fixup(input); // input == "9.8765e+01" +//! [7] +//! [8] +input = "-1234.6789"; +val.setDecimals(2); +val.setLocale(QLocale::C); +val.setNotation(QDoubleValidator::StandardNotation); +val.fixup(input); // input == "-1234.68" +//! [8] +} // Wrapper::wrapper3 + +} // src_gui_util_qvalidator diff --git a/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanfunctions.cpp b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanfunctions.cpp index 0d13873f38..700d933f43 100644 --- a/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanfunctions.cpp +++ b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanfunctions.cpp @@ -1,70 +1,49 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include <QVulkanDeviceFunctions> +#include <QVulkanFunctions> +#include <QVulkanInstance> + +namespace src_gui_vulkan_qvulkanfunctions { + +struct Window { + void init(); + QVulkanInstance *vulkanInstance() { return nullptr; } +}; //! [0] - void Window::render() - { - QVulkanInstance *inst = vulkanInstance(); - QVulkanFunctions *f = inst->functions(); - ... - VkResult err = f->vkAllocateCommandBuffers(device, &cmdBufInfo, &cmdBuf); - ... - } +void Window::init() +{ + QVulkanInstance *inst = vulkanInstance(); + QVulkanFunctions *f = inst->functions(); + // ... + uint32_t count = 0; + VkResult err = f->vkEnumeratePhysicalDevices(inst->vkInstance(), &count, nullptr); + // ... +} //! [0] +} // namespace src_gui_vulkan_qvulkanfunctions { + + +namespace src_gui_vulkan_qvulkanfunctions2 { +struct Window { + void render(); + QVulkanInstance *vulkanInstance() { return nullptr; } +}; +VkDevice_T *device = nullptr; +VkCommandBufferAllocateInfo cmdBufInfo; +VkCommandBuffer cmdBuf; + //! [1] - void Window::render() - { - QVulkanInstance *inst = vulkanInstance(); - QVulkanDeviceFunctions *df = inst->deviceFunctions(device); - VkResult err = df->vkAllocateCommandBuffers(device, &cmdBufInfo, &cmdBuf); - ... - } +void Window::render() +{ + QVulkanInstance *inst = vulkanInstance(); + QVulkanDeviceFunctions *df = inst->deviceFunctions(device); + VkResult err = df->vkAllocateCommandBuffers(device, &cmdBufInfo, &cmdBuf); + // ... +} //! [1] + +} // src_gui_vulkan_qvulkanfunctions2 diff --git a/src/gui/doc/snippets/code/src_gui_vulkan_qvulkaninstance.cpp b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkaninstance.cpp index 14ef9ed2d4..bfb7c7c3a4 100644 --- a/src/gui/doc/snippets/code/src_gui_vulkan_qvulkaninstance.cpp +++ b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkaninstance.cpp @@ -1,52 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include <QGuiApplication> +#include <QVulkanFunctions> +#include <QVulkanInstance> +#include <QWindow> + +namespace src_gui_vulkan_qvulkaninstance { + +struct Window { + void setVulkanInstance(QVulkanInstance *instance) { Q_UNUSED(instance); } + void show(); +}; +Window *window = nullptr; + //! [0] int main(int argc, char **argv) @@ -57,7 +24,7 @@ if (!inst.create()) return 1; - ... + // ... window->setVulkanInstance(&inst); window->show(); @@ -65,82 +32,100 @@ } //! [0] + +void wrapper0() { //! [1] QVulkanInstance inst; // Enable validation layer, if supported. Messages go to qDebug by default. - inst.setLayers(QByteArrayList() << "VK_LAYER_LUNARG_standard_validation"); + inst.setLayers({ "VK_LAYER_KHRONOS_validation" }); bool ok = inst.create(); - if (!ok) - ... // Vulkan not available - if (!inst.layers().contains("VK_LAYER_LUNARG_standard_validation")) - ... // validation layer not available + if (!ok) { + // ... Vulkan not available + } + + if (!inst.layers().contains("VK_LAYER_KHRONOS_validation")) { + // ... validation layer not available + } //! [1] +} + +void wrapper1() { //! [2] QVulkanInstance inst; - if (inst.supportedLayers().contains("VK_LAYER_LUNARG_standard_validation")) - ... - + if (inst.supportedLayers().contains("VK_LAYER_KHRONOS_validation")) { + // ... + } bool ok = inst.create(); - ... + // ... //! [2] +Q_UNUSED(ok); +} // wrapper1 +} // src_gui_vulkan_qvulkaninstance + + +namespace src_gui_vulkan_qvulkaninstance2 { + //! [3] - class VulkanWindow : public QWindow - { - public: - VulkanWindow() { - setSurfaceType(VulkanSurface); - } +class VulkanWindow : public QWindow +{ +public: + VulkanWindow() { + setSurfaceType(VulkanSurface); + } - void exposeEvent(QExposeEvent *) { - if (isExposed()) { - if (!m_initialized) { - m_initialized = true; - // initialize device, swapchain, etc. - QVulkanInstance *inst = vulkanInstance(); - QVulkanFunctions *f = inst->functions(); - uint32_t devCount = 0; - f->vkEnumeratePhysicalDevices(inst->vkInstance(), &devCount, nullptr); - ... - // build the first frame - render(); - } + void exposeEvent(QExposeEvent *) { + if (isExposed()) { + if (!m_initialized) { + m_initialized = true; + // initialize device, swapchain, etc. + QVulkanInstance *inst = vulkanInstance(); + QVulkanFunctions *f = inst->functions(); + uint32_t devCount = 0; + f->vkEnumeratePhysicalDevices(inst->vkInstance(), &devCount, nullptr); + // ... + // build the first frame + render(); } } + } - bool event(QEvent *e) { - if (e->type() == QEvent::UpdateRequest) - render(); - return QWindow::event(e); - } + bool event(QEvent *e) { + if (e->type() == QEvent::UpdateRequest) + render(); + return QWindow::event(e); + } - void render() { - ... - requestUpdate(); // render continuously - } + void render() { + // ... + requestUpdate(); // render continuously + } - private: - bool m_initialized = false; - }; +private: + bool m_initialized = false; +}; - int main(int argc, char **argv) - { - QGuiApplication app(argc, argv); +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); - QVulkanInstance inst; - if (!inst.create()) { - qWarning("Vulkan not available"); - return 1; - } + QVulkanInstance inst; + if (!inst.create()) { + qWarning("Vulkan not available"); + return 1; + } - VulkanWindow window; - window.showMaximized(); + VulkanWindow window; + window.showMaximized(); - return app.exec(); + return app.exec(); - } +} //! [3] + + +} // src_gui_vulkan_qvulkaninstance2 diff --git a/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanwindow.cpp b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanwindow.cpp index 81d51233a3..7f9abb638e 100644 --- a/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanwindow.cpp +++ b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanwindow.cpp @@ -1,132 +1,105 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QGuiApplication> +#include <QVulkanDeviceFunctions> +#include <QVulkanWindow> +namespace src_gui_vulkan_qvulkanwindow { +VkCommandBuffer commandBuffer; +const VkRenderPassBeginInfo *renderPassBegin = nullptr; +VkSubpassContents contents; //! [0] - class VulkanRenderer : public QVulkanWindowRenderer - { - public: - VulkanRenderer(QVulkanWindow *w) : m_window(w) { } - - void initResources() override - { - m_devFuncs = m_window->vulkanInstance()->deviceFunctions(m_window->device()); - ... - } - void initSwapChainResources() override { ... } - void releaseSwapChainResources() override { ... } - void releaseResources() override { ... } - - void startNextFrame() override - { - VkCommandBuffer cmdBuf = m_window->currentCommandBuffer(); - ... - m_devFuncs->vkCmdBeginRenderPass(...); - ... - m_window->frameReady(); - } - - private: - QVulkanWindow *m_window; - QVulkanDeviceFunctions *m_devFuncs; - }; - - class VulkanWindow : public QVulkanWindow - { - public: - QVulkanWindowRenderer *createRenderer() override { - return new VulkanRenderer(this); - } - }; - - int main(int argc, char *argv[]) - { - QGuiApplication app(argc, argv); - - QVulkanInstance inst; - // enable the standard validation layers, when available - inst.setLayers(QByteArrayList() << "VK_LAYER_LUNARG_standard_validation"); - if (!inst.create()) - qFatal("Failed to create Vulkan instance: %d", inst.errorCode()); - - VulkanWindow w; - w.setVulkanInstance(&inst); - w.showMaximized(); - - return app.exec(); - } +class VulkanRenderer : public QVulkanWindowRenderer +{ +public: + VulkanRenderer(QVulkanWindow *w) : m_window(w), m_devFuncs(nullptr) { } + + void initResources() override + { + m_devFuncs = m_window->vulkanInstance()->deviceFunctions(m_window->device()); + // .. + } + void initSwapChainResources() override { /* ... */ } + void releaseSwapChainResources() override { /* ... */ } + void releaseResources() override { /* ... */ } + + void startNextFrame() override + { + VkCommandBuffer cmdBuf = m_window->currentCommandBuffer(); + // ... + m_devFuncs->vkCmdBeginRenderPass(commandBuffer, renderPassBegin, contents); + // ... + m_window->frameReady(); + } + +private: + QVulkanWindow *m_window; + QVulkanDeviceFunctions *m_devFuncs; +}; + +class VulkanWindow : public QVulkanWindow +{ +public: + QVulkanWindowRenderer *createRenderer() override { + return new VulkanRenderer(this); + } +}; + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QVulkanInstance inst; + // enable the standard validation layers, when available + inst.setLayers({ "VK_LAYER_KHRONOS_validation" }); + if (!inst.create()) + qFatal("Failed to create Vulkan instance: %d", inst.errorCode()); + + VulkanWindow w; + w.setVulkanInstance(&inst); + w.showMaximized(); + + return app.exec(); +} //! [0] //! [1] class Renderer { - ... + void startNextFrame(); + // ... + VkDescriptorBufferInfo m_uniformBufInfo[QVulkanWindow::MAX_CONCURRENT_FRAME_COUNT]; + QVulkanWindow *m_window = nullptr; }; void Renderer::startNextFrame() { VkDescriptorBufferInfo &uniformBufInfo(m_uniformBufInfo[m_window->currentFrame()]); - ... + // ... } //! [1] +} // src_gui_vulkan_qvulkanwindow + + +namespace src_gui_vulkan_qvulkanwindow2 { + //! [2] class Renderer { - ... + void startNextFrame(); + // ... + VkDescriptorBufferInfo m_uniformBufInfo[QVulkanWindow::MAX_CONCURRENT_FRAME_COUNT]; + QVulkanWindow *m_window = nullptr; }; void Renderer::startNextFrame() { const int count = m_window->concurrentFrameCount(); - for (int i = 0; i < count; ++i) - m_uniformBufInfo[i] = ... - ... + // for (int i = 0; i < count; ++i) + // m_uniformBufInfo[i] = ... + // ... } //! [2] + +} // src_gui_vulkan_qvulkanwindow2 |