From e7c15a60ea787ffe5e5b2dcd0c0f7c875553b11c Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Tue, 8 Sep 2020 08:23:36 +0200 Subject: Doc: Clean up widget snippets project The main snippets project must be a subdirs project. Move some files and update the affected documentation. Task-number: QTBUG-86497 Pick-to: 5.15 Change-Id: I60073d1b8bd53aa09600eeccf06ba8457ac7c708 Reviewed-by: Venugopal Shivashankar --- src/widgets/doc/snippets/customviewstyle.cpp | 78 ----------- .../snippets/customviewstyle/customviewstyle.cpp | 78 +++++++++++ src/widgets/doc/snippets/filedialogurls.cpp | 69 ---------- .../doc/snippets/filedialogurls/filedialogurls.cpp | 69 ++++++++++ .../graphicssceneadditemsnippet.cpp | 81 +++++++++++ .../doc/snippets/graphicssceneadditemsnippet.cpp | 81 ----------- src/widgets/doc/snippets/graphicsview.cpp | 149 --------------------- .../doc/snippets/graphicsview/graphicsview.cpp | 149 +++++++++++++++++++++ .../snippets/graphicsview/graphicsview_snippet.cpp | 63 +++++++++ src/widgets/doc/snippets/graphicsview_snippet.cpp | 63 --------- .../doc/snippets/mdiarea/mdiareasnippets.cpp | 108 +++++++++++++++ src/widgets/doc/snippets/mdiareasnippets.cpp | 108 --------------- src/widgets/doc/snippets/myscrollarea.cpp | 125 ----------------- .../doc/snippets/myscrollarea/myscrollarea.cpp | 125 +++++++++++++++++ src/widgets/doc/snippets/snippets.pro | 12 +- src/widgets/doc/src/graphicsview.qdoc | 14 +- 16 files changed, 686 insertions(+), 686 deletions(-) delete mode 100644 src/widgets/doc/snippets/customviewstyle.cpp create mode 100644 src/widgets/doc/snippets/customviewstyle/customviewstyle.cpp delete mode 100644 src/widgets/doc/snippets/filedialogurls.cpp create mode 100644 src/widgets/doc/snippets/filedialogurls/filedialogurls.cpp create mode 100644 src/widgets/doc/snippets/graphicssceneadditem/graphicssceneadditemsnippet.cpp delete mode 100644 src/widgets/doc/snippets/graphicssceneadditemsnippet.cpp delete mode 100644 src/widgets/doc/snippets/graphicsview.cpp create mode 100644 src/widgets/doc/snippets/graphicsview/graphicsview.cpp create mode 100644 src/widgets/doc/snippets/graphicsview/graphicsview_snippet.cpp delete mode 100644 src/widgets/doc/snippets/graphicsview_snippet.cpp create mode 100644 src/widgets/doc/snippets/mdiarea/mdiareasnippets.cpp delete mode 100644 src/widgets/doc/snippets/mdiareasnippets.cpp delete mode 100644 src/widgets/doc/snippets/myscrollarea.cpp create mode 100644 src/widgets/doc/snippets/myscrollarea/myscrollarea.cpp (limited to 'src/widgets/doc') diff --git a/src/widgets/doc/snippets/customviewstyle.cpp b/src/widgets/doc/snippets/customviewstyle.cpp deleted file mode 100644 index 1e4cf2b711..0000000000 --- a/src/widgets/doc/snippets/customviewstyle.cpp +++ /dev/null @@ -1,78 +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$ -** -****************************************************************************/ - -#include - -#include "./customstyle/customstyle.h" - -void CustomStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, - QPainter *painter, const QWidget *widget) const -{ - -//![0] - switch (element) { - case (PE_PanelItemViewItem): { - painter->save(); - - QPoint topLeft = option->rect.topLeft(); - QPoint bottomRight = option->rect.topRight(); - QLinearGradient backgroundGradient(topLeft, bottomRight); - backgroundGradient.setColorAt(0.0, QColor(Qt::yellow).lighter(190)); - backgroundGradient.setColorAt(1.0, Qt::white); - painter->fillRect(option->rect, QBrush(backgroundGradient)); - - painter->restore(); - break; - } - default: - QProxyStyle::drawPrimitive(element, option, painter, widget); - } -//![0] -} diff --git a/src/widgets/doc/snippets/customviewstyle/customviewstyle.cpp b/src/widgets/doc/snippets/customviewstyle/customviewstyle.cpp new file mode 100644 index 0000000000..1e4cf2b711 --- /dev/null +++ b/src/widgets/doc/snippets/customviewstyle/customviewstyle.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include + +#include "./customstyle/customstyle.h" + +void CustomStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, + QPainter *painter, const QWidget *widget) const +{ + +//![0] + switch (element) { + case (PE_PanelItemViewItem): { + painter->save(); + + QPoint topLeft = option->rect.topLeft(); + QPoint bottomRight = option->rect.topRight(); + QLinearGradient backgroundGradient(topLeft, bottomRight); + backgroundGradient.setColorAt(0.0, QColor(Qt::yellow).lighter(190)); + backgroundGradient.setColorAt(1.0, Qt::white); + painter->fillRect(option->rect, QBrush(backgroundGradient)); + + painter->restore(); + break; + } + default: + QProxyStyle::drawPrimitive(element, option, painter, widget); + } +//![0] +} diff --git a/src/widgets/doc/snippets/filedialogurls.cpp b/src/widgets/doc/snippets/filedialogurls.cpp deleted file mode 100644 index 4b73a6c818..0000000000 --- a/src/widgets/doc/snippets/filedialogurls.cpp +++ /dev/null @@ -1,69 +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$ -** -****************************************************************************/ - -#include -#include - -int loadFileDialog() -{ -//![0] - QList urls; - urls << QUrl::fromLocalFile("/Users/foo/Code/qt5") - << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::MusicLocation).first()); - - QFileDialog dialog; - dialog.setSidebarUrls(urls); - dialog.setFileMode(QFileDialog::AnyFile); - if(dialog.exec()) { - // ... - } -//![0] - return 1; -} diff --git a/src/widgets/doc/snippets/filedialogurls/filedialogurls.cpp b/src/widgets/doc/snippets/filedialogurls/filedialogurls.cpp new file mode 100644 index 0000000000..f269ad3f20 --- /dev/null +++ b/src/widgets/doc/snippets/filedialogurls/filedialogurls.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include +#include + +int loadFileDialog() +{ +//![0] + QList urls; + urls << QUrl::fromLocalFile("/Users/foo/Code/qt5") + << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::MusicLocation).first()); + + QFileDialog dialog; + dialog.setSidebarUrls(urls); + dialog.setFileMode(QFileDialog::AnyFile); + if(dialog.exec()) { + // ... + } +//![0] + return 1; +} diff --git a/src/widgets/doc/snippets/graphicssceneadditem/graphicssceneadditemsnippet.cpp b/src/widgets/doc/snippets/graphicssceneadditem/graphicssceneadditemsnippet.cpp new file mode 100644 index 0000000000..3d5c172dca --- /dev/null +++ b/src/widgets/doc/snippets/graphicssceneadditem/graphicssceneadditemsnippet.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include +#include +#include +#include + +class CustomScene : public QGraphicsScene +{ +public: + CustomScene() + { addItem(new QGraphicsEllipseItem(QRect(10, 10, 30, 30))); } + + void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], + const QStyleOptionGraphicsItem options[], + QWidget *widget = 0) override; +}; + +//! [0] +void CustomScene::drawItems(QPainter *painter, int numItems, + QGraphicsItem *items[], + const QStyleOptionGraphicsItem options[], + QWidget *widget) +{ + for (int i = 0; i < numItems; ++i) { + // Draw the item + painter->save(); + painter->setTransform(items[i]->sceneTransform(), true); + items[i]->paint(painter, &options[i], widget); + painter->restore(); + } +} +//! [0] diff --git a/src/widgets/doc/snippets/graphicssceneadditemsnippet.cpp b/src/widgets/doc/snippets/graphicssceneadditemsnippet.cpp deleted file mode 100644 index 0ce135dc63..0000000000 --- a/src/widgets/doc/snippets/graphicssceneadditemsnippet.cpp +++ /dev/null @@ -1,81 +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$ -** -****************************************************************************/ - -#include -#include -#include -#include - -class CustomScene : public QGraphicsScene -{ -public: - CustomScene() - { addItem(new QGraphicsEllipseItem(QRect(10, 10, 30, 30))); } - - void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], - const QStyleOptionGraphicsItem options[], - QWidget *widget = 0) override; -}; - -//! [0] -void CustomScene::drawItems(QPainter *painter, int numItems, - QGraphicsItem *items[], - const QStyleOptionGraphicsItem options[], - QWidget *widget) -{ - for (int i = 0; i < numItems; ++i) { - // Draw the item - painter->save(); - painter->setTransform(items[i]->sceneTransform(), true); - items[i]->paint(painter, &options[i], widget); - painter->restore(); - } -} -//! [0] diff --git a/src/widgets/doc/snippets/graphicsview.cpp b/src/widgets/doc/snippets/graphicsview.cpp deleted file mode 100644 index 37947b4a35..0000000000 --- a/src/widgets/doc/snippets/graphicsview.cpp +++ /dev/null @@ -1,149 +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$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include - -void graphicsview_snippet_main() -{ -//! [0] -QGraphicsScene scene; -QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); - -QGraphicsItem *item = scene.itemAt(50, 50, QTransform()); -//! [0] -Q_UNUSED(rect); -Q_UNUSED(item); -} - -void myPopulateScene(QGraphicsScene *) -{ - // Intentionally left empty -} - -void snippetThatUsesMyPopulateScene() -{ -//! [1] -QGraphicsScene scene; -myPopulateScene(&scene); -QGraphicsView view(&scene); -view.show(); -//! [1] -} - -class CustomItem : public QStandardItem -{ -public: - using QStandardItem::QStandardItem; - - int type() const override { return UserType; } - void mousePressEvent(QGraphicsSceneMouseEvent *event); - QStandardItem *clone() const override { return new CustomItem; } -}; - - -void printScene() -{ -//! [3] -QGraphicsScene scene; -QPrinter printer; -scene.addRect(QRectF(0, 0, 100, 200), QPen(Qt::black), QBrush(Qt::green)); - -if (QPrintDialog(&printer).exec() == QDialog::Accepted) { - QPainter painter(&printer); - painter.setRenderHint(QPainter::Antialiasing); - scene.render(&painter); -} -//! [3] -} - -void pixmapScene() -{ -//! [4] -QGraphicsScene scene; -scene.addRect(QRectF(0, 0, 100, 200), QPen(Qt::black), QBrush(Qt::green)); - -QPixmap pixmap; -QPainter painter(&pixmap); -painter.setRenderHint(QPainter::Antialiasing); -scene.render(&painter); -painter.end(); - -pixmap.save("scene.png"); -//! [4] -} - -//! [5] -void CustomItem::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - QMimeData *data = new QMimeData; - QDrag *drag = new QDrag(event->widget()); - drag->setMimeData(data); - drag->exec(); -} -//! [5] - -void viewScene() -{ -QGraphicsScene scene; -//! [6] -QGraphicsView view(&scene); -QOpenGLWidget *gl = new QOpenGLWidget(); -QSurfaceFormat format; -format.setSamples(4); -gl->setFormat(format); -view.setViewport(gl); -//! [6] -} diff --git a/src/widgets/doc/snippets/graphicsview/graphicsview.cpp b/src/widgets/doc/snippets/graphicsview/graphicsview.cpp new file mode 100644 index 0000000000..29187ba326 --- /dev/null +++ b/src/widgets/doc/snippets/graphicsview/graphicsview.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + +void graphicsview_snippet_main() +{ +//! [0] +QGraphicsScene scene; +QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); + +QGraphicsItem *item = scene.itemAt(50, 50, QTransform()); +//! [0] +Q_UNUSED(rect); +Q_UNUSED(item); +} + +void myPopulateScene(QGraphicsScene *) +{ + // Intentionally left empty +} + +void snippetThatUsesMyPopulateScene() +{ +//! [1] +QGraphicsScene scene; +myPopulateScene(&scene); +QGraphicsView view(&scene); +view.show(); +//! [1] +} + +class CustomItem : public QStandardItem +{ +public: + using QStandardItem::QStandardItem; + + int type() const override { return UserType; } + void mousePressEvent(QGraphicsSceneMouseEvent *event); + QStandardItem *clone() const override { return new CustomItem; } +}; + + +void printScene() +{ +//! [3] +QGraphicsScene scene; +QPrinter printer; +scene.addRect(QRectF(0, 0, 100, 200), QPen(Qt::black), QBrush(Qt::green)); + +if (QPrintDialog(&printer).exec() == QDialog::Accepted) { + QPainter painter(&printer); + painter.setRenderHint(QPainter::Antialiasing); + scene.render(&painter); +} +//! [3] +} + +void pixmapScene() +{ +//! [4] +QGraphicsScene scene; +scene.addRect(QRectF(0, 0, 100, 200), QPen(Qt::black), QBrush(Qt::green)); + +QPixmap pixmap; +QPainter painter(&pixmap); +painter.setRenderHint(QPainter::Antialiasing); +scene.render(&painter); +painter.end(); + +pixmap.save("scene.png"); +//! [4] +} + +//! [5] +void CustomItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + QMimeData *data = new QMimeData; + QDrag *drag = new QDrag(event->widget()); + drag->setMimeData(data); + drag->exec(); +} +//! [5] + +void viewScene() +{ +QGraphicsScene scene; +//! [6] +QGraphicsView view(&scene); +QOpenGLWidget *gl = new QOpenGLWidget(); +QSurfaceFormat format; +format.setSamples(4); +gl->setFormat(format); +view.setViewport(gl); +//! [6] +} diff --git a/src/widgets/doc/snippets/graphicsview/graphicsview_snippet.cpp b/src/widgets/doc/snippets/graphicsview/graphicsview_snippet.cpp new file mode 100644 index 0000000000..9d058d0f6a --- /dev/null +++ b/src/widgets/doc/snippets/graphicsview/graphicsview_snippet.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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$ +** +****************************************************************************/ + +//! [2] +class View : public QGraphicsView +{ +Q_OBJECT + ... +public slots: + void zoomIn() { scale(1.2, 1.2); } + void zoomOut() { scale(1 / 1.2, 1 / 1.2); } + void rotateLeft() { rotate(-10); } + void rotateRight() { rotate(10); } + ... +}; +//! [2] diff --git a/src/widgets/doc/snippets/graphicsview_snippet.cpp b/src/widgets/doc/snippets/graphicsview_snippet.cpp deleted file mode 100644 index 9d058d0f6a..0000000000 --- a/src/widgets/doc/snippets/graphicsview_snippet.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2020 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$ -** -****************************************************************************/ - -//! [2] -class View : public QGraphicsView -{ -Q_OBJECT - ... -public slots: - void zoomIn() { scale(1.2, 1.2); } - void zoomOut() { scale(1 / 1.2, 1 / 1.2); } - void rotateLeft() { rotate(-10); } - void rotateRight() { rotate(10); } - ... -}; -//! [2] diff --git a/src/widgets/doc/snippets/mdiarea/mdiareasnippets.cpp b/src/widgets/doc/snippets/mdiarea/mdiareasnippets.cpp new file mode 100644 index 0000000000..c1e2d37ccb --- /dev/null +++ b/src/widgets/doc/snippets/mdiarea/mdiareasnippets.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include + +void mainWindowExample() +{ + QMdiArea *mdiArea = new QMdiArea; +//! [0] + QMainWindow *mainWindow = new QMainWindow; + mainWindow->setCentralWidget(mdiArea); +//! [0] + + mdiArea->addSubWindow(new QPushButton("Push Me Now!")); + + mainWindow->show(); +} + +void addingSubWindowsExample() +{ + QWidget *internalWidget1 = new QWidget; + QWidget *internalWidget2 = new QWidget; + +//! [1] + QMdiArea mdiArea; + QMdiSubWindow *subWindow1 = new QMdiSubWindow; + subWindow1->setWidget(internalWidget1); + subWindow1->setAttribute(Qt::WA_DeleteOnClose); + mdiArea.addSubWindow(subWindow1); + + QMdiSubWindow *subWindow2 = + mdiArea.addSubWindow(internalWidget2); + +//! [1] + subWindow1->show(); + subWindow2->show(); + + mdiArea.show(); +} + +/* +int main(int argv, char **args) +{ + QApplication app(argv, args); + + mainWindowExample(); + //addingSubWindowsExample(); + + QAction *act = new QAction(qApp); + act->setShortcut(Qt::ALT + Qt::Key_S); + act->setShortcutContext( Qt::ApplicationShortcut ); + QObject::connect(act, &QAction::triggered, qApp, &QApplication::aboutQt); + + QWidget widget5; + widget5.show(); + widget5.addAction(act); + + return app.exec(); +} +*/ + diff --git a/src/widgets/doc/snippets/mdiareasnippets.cpp b/src/widgets/doc/snippets/mdiareasnippets.cpp deleted file mode 100644 index c1e2d37ccb..0000000000 --- a/src/widgets/doc/snippets/mdiareasnippets.cpp +++ /dev/null @@ -1,108 +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$ -** -****************************************************************************/ - -#include - -void mainWindowExample() -{ - QMdiArea *mdiArea = new QMdiArea; -//! [0] - QMainWindow *mainWindow = new QMainWindow; - mainWindow->setCentralWidget(mdiArea); -//! [0] - - mdiArea->addSubWindow(new QPushButton("Push Me Now!")); - - mainWindow->show(); -} - -void addingSubWindowsExample() -{ - QWidget *internalWidget1 = new QWidget; - QWidget *internalWidget2 = new QWidget; - -//! [1] - QMdiArea mdiArea; - QMdiSubWindow *subWindow1 = new QMdiSubWindow; - subWindow1->setWidget(internalWidget1); - subWindow1->setAttribute(Qt::WA_DeleteOnClose); - mdiArea.addSubWindow(subWindow1); - - QMdiSubWindow *subWindow2 = - mdiArea.addSubWindow(internalWidget2); - -//! [1] - subWindow1->show(); - subWindow2->show(); - - mdiArea.show(); -} - -/* -int main(int argv, char **args) -{ - QApplication app(argv, args); - - mainWindowExample(); - //addingSubWindowsExample(); - - QAction *act = new QAction(qApp); - act->setShortcut(Qt::ALT + Qt::Key_S); - act->setShortcutContext( Qt::ApplicationShortcut ); - QObject::connect(act, &QAction::triggered, qApp, &QApplication::aboutQt); - - QWidget widget5; - widget5.show(); - widget5.addAction(act); - - return app.exec(); -} -*/ - diff --git a/src/widgets/doc/snippets/myscrollarea.cpp b/src/widgets/doc/snippets/myscrollarea.cpp deleted file mode 100644 index 8afe4a6834..0000000000 --- a/src/widgets/doc/snippets/myscrollarea.cpp +++ /dev/null @@ -1,125 +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$ -** -****************************************************************************/ - -#include - -class MyScrollArea : public QAbstractScrollArea -{ -public: - MyScrollArea(QWidget *w); - void setWidget(QWidget *w); - -protected: - void scrollContentsBy(int dx, int dy) override; - void resizeEvent(QResizeEvent *event) override; - -private: - void updateWidgetPosition(); - void updateArea(); - - QWidget *widget; -}; - -MyScrollArea::MyScrollArea(QWidget *widget) - : QAbstractScrollArea() -{ - setWidget(widget); -} - -void MyScrollArea::setWidget(QWidget *w) -{ - widget = w; - widget->setParent(viewport()); - if (!widget->testAttribute(Qt::WA_Resized)) - widget->resize(widget->sizeHint()); - - verticalScrollBar()->setValue(0); - verticalScrollBar()->setValue(0); - - updateArea(); -} - -void MyScrollArea::updateWidgetPosition() -{ -//! [0] - int hvalue = horizontalScrollBar()->value(); - int vvalue = verticalScrollBar()->value(); - QPoint topLeft = viewport()->rect().topLeft(); - - widget->move(topLeft.x() - hvalue, topLeft.y() - vvalue); -//! [0] -} - -void MyScrollArea::scrollContentsBy(int dx, int dy) -{ - Q_UNUSED(dx); - Q_UNUSED(dy); - updateWidgetPosition(); -} - -void MyScrollArea::updateArea() -{ -//! [1] - QSize areaSize = viewport()->size(); - QSize widgetSize = widget->size(); - - verticalScrollBar()->setPageStep(areaSize.height()); - horizontalScrollBar()->setPageStep(areaSize.width()); - verticalScrollBar()->setRange(0, widgetSize.height() - areaSize.height()); - horizontalScrollBar()->setRange(0, widgetSize.width() - areaSize.width()); - updateWidgetPosition(); -//! [1] -} - -void MyScrollArea::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event); - updateArea(); -} diff --git a/src/widgets/doc/snippets/myscrollarea/myscrollarea.cpp b/src/widgets/doc/snippets/myscrollarea/myscrollarea.cpp new file mode 100644 index 0000000000..8afe4a6834 --- /dev/null +++ b/src/widgets/doc/snippets/myscrollarea/myscrollarea.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include + +class MyScrollArea : public QAbstractScrollArea +{ +public: + MyScrollArea(QWidget *w); + void setWidget(QWidget *w); + +protected: + void scrollContentsBy(int dx, int dy) override; + void resizeEvent(QResizeEvent *event) override; + +private: + void updateWidgetPosition(); + void updateArea(); + + QWidget *widget; +}; + +MyScrollArea::MyScrollArea(QWidget *widget) + : QAbstractScrollArea() +{ + setWidget(widget); +} + +void MyScrollArea::setWidget(QWidget *w) +{ + widget = w; + widget->setParent(viewport()); + if (!widget->testAttribute(Qt::WA_Resized)) + widget->resize(widget->sizeHint()); + + verticalScrollBar()->setValue(0); + verticalScrollBar()->setValue(0); + + updateArea(); +} + +void MyScrollArea::updateWidgetPosition() +{ +//! [0] + int hvalue = horizontalScrollBar()->value(); + int vvalue = verticalScrollBar()->value(); + QPoint topLeft = viewport()->rect().topLeft(); + + widget->move(topLeft.x() - hvalue, topLeft.y() - vvalue); +//! [0] +} + +void MyScrollArea::scrollContentsBy(int dx, int dy) +{ + Q_UNUSED(dx); + Q_UNUSED(dy); + updateWidgetPosition(); +} + +void MyScrollArea::updateArea() +{ +//! [1] + QSize areaSize = viewport()->size(); + QSize widgetSize = widget->size(); + + verticalScrollBar()->setPageStep(areaSize.height()); + horizontalScrollBar()->setPageStep(areaSize.width()); + verticalScrollBar()->setRange(0, widgetSize.height() - areaSize.height()); + horizontalScrollBar()->setRange(0, widgetSize.width() - areaSize.width()); + updateWidgetPosition(); +//! [1] +} + +void MyScrollArea::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event); + updateArea(); +} diff --git a/src/widgets/doc/snippets/snippets.pro b/src/widgets/doc/snippets/snippets.pro index fcfd998373..55b690b469 100644 --- a/src/widgets/doc/snippets/snippets.pro +++ b/src/widgets/doc/snippets/snippets.pro @@ -8,11 +8,11 @@ QT += widgets QT += printsupport opengl openglwidgets -SOURCES += customviewstyle.cpp \ - filedialogurls.cpp \ - graphicssceneadditemsnippet.cpp \ - graphicsview.cpp \ - mdiareasnippets.cpp \ - myscrollarea.cpp +SOURCES += customviewstyle/customviewstyle.cpp \ + filedialogurls/filedialogurls.cpp \ + graphicssceneadditem/graphicssceneadditemsnippet.cpp \ + graphicsview/graphicsview.cpp \ + mdiarea/mdiareasnippets.cpp \ + myscrollarea/myscrollarea.cpp load(qt_common) diff --git a/src/widgets/doc/src/graphicsview.qdoc b/src/widgets/doc/src/graphicsview.qdoc index 2dfad442a3..bd95e88b20 100644 --- a/src/widgets/doc/src/graphicsview.qdoc +++ b/src/widgets/doc/src/graphicsview.qdoc @@ -89,7 +89,7 @@ descending stacking order (i.e., the first returned item is topmost, and the last item is bottom-most). - \snippet graphicsview.cpp 0 + \snippet graphicsview/graphicsview.cpp 0 QGraphicsScene's event propagation architecture schedules scene events for delivery to items, and also manages propagation between items. If @@ -120,7 +120,7 @@ enable OpenGL support, you can set a QOpenGLWidget as the viewport by calling QGraphicsView::setViewport(). - \snippet graphicsview.cpp 1 + \snippet graphicsview/graphicsview.cpp 1 The view receives input events from the keyboard and mouse, and translates these to scene events (converting the coordinates used @@ -327,7 +327,7 @@ Here is an example of how to implement zoom and rotate slots in a subclass of QGraphicsView: - \snippet graphicsview_snippet.cpp 2 + \snippet graphicsview/graphicsview_snippet.cpp 2 The slots could be connected to \l{QToolButton}{QToolButtons} with \l{QAbstractButton::autoRepeat}{autoRepeat} enabled. @@ -347,7 +347,7 @@ a QPainter to either of the rendering functions. This example shows how to print the whole scene into a full page, using QPrinter. - \snippet graphicsview.cpp 3 + \snippet graphicsview/graphicsview.cpp 3 The difference between the scene and view rendering functions is that one operates in scene coordinates, and the other in view coordinates. @@ -358,7 +358,7 @@ is to render the exact contents of the viewport using the provided painter. - \snippet graphicsview.cpp 4 + \snippet graphicsview/graphicsview.cpp 4 When the source and target areas' sizes do not match, the source contents are stretched to fit into the target area. By passing a @@ -384,7 +384,7 @@ so in mousePressEvent() or mouseMoveEvent(), you can get the originating widget pointer from the event. For example: - \snippet graphicsview.cpp 5 + \snippet graphicsview/graphicsview.cpp 5 To intercept drag and drop events for the scene, you reimplement QGraphicsScene::dragEnterEvent() and whichever event handlers your @@ -443,7 +443,7 @@ Example: - \snippet graphicsview.cpp 6 + \snippet graphicsview/graphicsview.cpp 6 \section2 Item Groups -- cgit v1.2.3