summaryrefslogtreecommitdiffstats
path: root/tests/manual/examples/widgets/graphicsview/embeddeddialogs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/examples/widgets/graphicsview/embeddeddialogs')
-rw-r--r--tests/manual/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt50
-rw-r--r--tests/manual/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpgbin0 -> 30730 bytes
-rw-r--r--tests/manual/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp133
-rw-r--r--tests/manual/examples/widgets/graphicsview/embeddeddialogs/customproxy.h39
-rw-r--r--tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp70
-rw-r--r--tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h33
-rw-r--r--tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui88
-rw-r--r--tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro18
-rw-r--r--tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc5
-rw-r--r--tests/manual/examples/widgets/graphicsview/embeddeddialogs/main.cpp42
10 files changed, 478 insertions, 0 deletions
diff --git a/tests/manual/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt
new file mode 100644
index 0000000000..c25544166f
--- /dev/null
+++ b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt
@@ -0,0 +1,50 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(embeddeddialogs LANGUAGES CXX)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/embeddeddialogs")
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
+
+qt_standard_project_setup()
+
+qt_add_executable(embeddeddialogs
+ customproxy.cpp customproxy.h
+ embeddeddialog.cpp embeddeddialog.h embeddeddialog.ui
+ main.cpp
+)
+
+set_target_properties(embeddeddialogs PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(embeddeddialogs PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Widgets
+)
+
+# Resources:
+set(embeddeddialogs_resource_files
+ "No-Ones-Laughing-3.jpg"
+)
+
+qt_add_resources(embeddeddialogs "embeddeddialogs"
+ PREFIX
+ "/"
+ FILES
+ ${embeddeddialogs_resource_files}
+)
+
+install(TARGETS embeddeddialogs
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/tests/manual/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg
new file mode 100644
index 0000000000..445567fbda
--- /dev/null
+++ b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg
Binary files differ
diff --git a/tests/manual/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
new file mode 100644
index 0000000000..57a104f57d
--- /dev/null
+++ b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
@@ -0,0 +1,133 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "customproxy.h"
+
+#include <QGraphicsScene>
+#include <QPainter>
+#include <QStyleOptionGraphicsItem>
+
+CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
+ : QGraphicsProxyWidget(parent, wFlags), timeLine(new QTimeLine(250, this))
+{
+ connect(timeLine, &QTimeLine::valueChanged,
+ this, &CustomProxy::updateStep);
+ connect(timeLine, &QTimeLine::stateChanged,
+ this, &CustomProxy::stateChanged);
+}
+
+QRectF CustomProxy::boundingRect() const
+{
+ return QGraphicsProxyWidget::boundingRect().adjusted(0, 0, 10, 10);
+}
+
+void CustomProxy::paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+{
+ const QColor color(0, 0, 0, 64);
+
+ QRectF r = windowFrameRect();
+ QRectF right(r.right(), r.top() + 10, 10, r.height() - 10);
+ QRectF bottom(r.left() + 10, r.bottom(), r.width(), 10);
+ bool intersectsRight = right.intersects(option->exposedRect);
+ bool intersectsBottom = bottom.intersects(option->exposedRect);
+ if (intersectsRight && intersectsBottom) {
+ QPainterPath path;
+ path.addRect(right);
+ path.addRect(bottom);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(color);
+ painter->drawPath(path);
+ } else if (intersectsBottom) {
+ painter->fillRect(bottom, color);
+ } else if (intersectsRight) {
+ painter->fillRect(right, color);
+ }
+
+ QGraphicsProxyWidget::paintWindowFrame(painter, option, widget);
+}
+
+void CustomProxy::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
+{
+ QGraphicsProxyWidget::hoverEnterEvent(event);
+ scene()->setActiveWindow(this);
+ if (qFuzzyCompare(timeLine->currentValue(), 1))
+ zoomIn();
+}
+
+void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
+{
+ QGraphicsProxyWidget::hoverLeaveEvent(event);
+ if (!popupShown
+ && (timeLine->direction() != QTimeLine::Backward || qFuzzyIsNull(timeLine->currentValue()))) {
+ zoomOut();
+ }
+}
+
+bool CustomProxy::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+{
+ if (watched->isWindow()
+ && (event->type() == QEvent::UngrabMouse || event->type() == QEvent::GrabMouse)) {
+ popupShown = watched->isVisible();
+ if (!popupShown && !isUnderMouse())
+ zoomOut();
+ }
+ return QGraphicsProxyWidget::sceneEventFilter(watched, event);
+}
+
+QVariant CustomProxy::itemChange(GraphicsItemChange change, const QVariant &value)
+{
+ if (change == ItemChildAddedChange || change == ItemChildRemovedChange) {
+ if (change == ItemChildAddedChange) {
+ currentPopup = qvariant_cast<QGraphicsItem *>(value);
+ currentPopup->setCacheMode(ItemCoordinateCache);
+ if (scene())
+ currentPopup->installSceneEventFilter(this);
+ } else if (scene()) {
+ currentPopup->removeSceneEventFilter(this);
+ currentPopup = nullptr;
+ }
+ } else if (currentPopup && change == ItemSceneHasChanged) {
+ currentPopup->installSceneEventFilter(this);
+ }
+ return QGraphicsProxyWidget::itemChange(change, value);
+}
+
+void CustomProxy::updateStep(qreal step)
+{
+ QRectF r = boundingRect();
+ setTransform(QTransform()
+ .translate(r.width() / 2, r.height() / 2)
+ .rotate(step * 30, Qt::XAxis)
+ .rotate(step * 10, Qt::YAxis)
+ .rotate(step * 5, Qt::ZAxis)
+ .scale(1 + 1.5 * step, 1 + 1.5 * step)
+ .translate(-r.width() / 2, -r.height() / 2));
+}
+
+void CustomProxy::stateChanged(QTimeLine::State state)
+{
+ if (state == QTimeLine::Running) {
+ if (timeLine->direction() == QTimeLine::Forward)
+ setCacheMode(ItemCoordinateCache);
+ } else if (state == QTimeLine::NotRunning) {
+ if (timeLine->direction() == QTimeLine::Backward)
+ setCacheMode(DeviceCoordinateCache);
+ }
+}
+
+void CustomProxy::zoomIn()
+{
+ if (timeLine->direction() != QTimeLine::Forward)
+ timeLine->setDirection(QTimeLine::Forward);
+ if (timeLine->state() == QTimeLine::NotRunning)
+ timeLine->start();
+}
+
+void CustomProxy::zoomOut()
+{
+ if (timeLine->direction() != QTimeLine::Backward)
+ timeLine->setDirection(QTimeLine::Backward);
+ if (timeLine->state() == QTimeLine::NotRunning)
+ timeLine->start();
+}
diff --git a/tests/manual/examples/widgets/graphicsview/embeddeddialogs/customproxy.h b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
new file mode 100644
index 0000000000..444d39e73e
--- /dev/null
+++ b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
@@ -0,0 +1,39 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef CUSTOMPROXY_H
+#define CUSTOMPROXY_H
+
+#include <QTimeLine>
+#include <QGraphicsProxyWidget>
+
+class CustomProxy : public QGraphicsProxyWidget
+{
+ Q_OBJECT
+
+public:
+ explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = { });
+
+ QRectF boundingRect() const override;
+ void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget) override;
+
+protected:
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
+
+private slots:
+ void updateStep(qreal step);
+ void stateChanged(QTimeLine::State);
+ void zoomIn();
+ void zoomOut();
+
+private:
+ QTimeLine *timeLine;
+ QGraphicsItem *currentPopup = nullptr;
+ bool popupShown = false;
+};
+
+#endif // CUSTOMPROXY_H
diff --git a/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp
new file mode 100644
index 0000000000..43d7fbf1e9
--- /dev/null
+++ b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp
@@ -0,0 +1,70 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "embeddeddialog.h"
+#include "ui_embeddeddialog.h"
+
+#include <QStyleFactory>
+
+EmbeddedDialog::EmbeddedDialog(QWidget *parent)
+ : QDialog(parent)
+ , ui(new Ui::EmbeddedDialog)
+{
+ ui->setupUi(this);
+ ui->layoutDirection->setCurrentIndex(layoutDirection() != Qt::LeftToRight);
+
+ const QStringList styleKeys = QStyleFactory::keys();
+ for (const QString &styleName : styleKeys) {
+ ui->style->addItem(styleName);
+ if (style()->objectName().toLower() == styleName.toLower())
+ ui->style->setCurrentIndex(ui->style->count() - 1);
+ }
+
+ connect(ui->layoutDirection, &QComboBox::activated,
+ this, &EmbeddedDialog::layoutDirectionChanged);
+ connect(ui->spacing, &QSlider::valueChanged,
+ this, &EmbeddedDialog::spacingChanged);
+ connect(ui->fontComboBox, &QFontComboBox::currentFontChanged,
+ this, &EmbeddedDialog::fontChanged);
+ connect(ui->style, &QComboBox::textActivated,
+ this, &EmbeddedDialog::styleChanged);
+}
+
+EmbeddedDialog::~EmbeddedDialog()
+{
+ delete ui;
+}
+
+void EmbeddedDialog::layoutDirectionChanged(int index)
+{
+ setLayoutDirection(index == 0 ? Qt::LeftToRight : Qt::RightToLeft);
+}
+
+void EmbeddedDialog::spacingChanged(int spacing)
+{
+ layout()->setSpacing(spacing);
+ adjustSize();
+}
+
+void EmbeddedDialog::fontChanged(const QFont &font)
+{
+ setFont(font);
+}
+
+static void setStyleHelper(QWidget *widget, QStyle *style)
+{
+ widget->setStyle(style);
+ widget->setPalette(style->standardPalette());
+ const QObjectList children = widget->children();
+ for (QObject *child : children) {
+ if (QWidget *childWidget = qobject_cast<QWidget *>(child))
+ setStyleHelper(childWidget, style);
+ }
+}
+
+void EmbeddedDialog::styleChanged(const QString &styleName)
+{
+ QStyle *style = QStyleFactory::create(styleName);
+ if (style)
+ setStyleHelper(this, style);
+}
diff --git a/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
new file mode 100644
index 0000000000..d4c561799e
--- /dev/null
+++ b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
@@ -0,0 +1,33 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef EMBEDDEDDIALOG_H
+#define EMBEDDEDDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+namespace Ui {
+class EmbeddedDialog;
+}
+QT_END_NAMESPACE
+
+class EmbeddedDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ EmbeddedDialog(QWidget *parent = nullptr);
+ ~EmbeddedDialog();
+
+private slots:
+ void layoutDirectionChanged(int index);
+ void spacingChanged(int spacing);
+ void fontChanged(const QFont &font);
+ void styleChanged(const QString &styleName);
+
+private:
+ Ui::EmbeddedDialog *ui;
+};
+
+#endif // EMBEDDEDDIALOG_H
diff --git a/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui
new file mode 100644
index 0000000000..82aa5d7be3
--- /dev/null
+++ b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>EmbeddedDialog</class>
+ <widget class="QDialog" name="EmbeddedDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>407</width>
+ <height>134</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Embedded Dialog</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Layout Direction:</string>
+ </property>
+ <property name="buddy">
+ <cstring>layoutDirection</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="layoutDirection">
+ <item>
+ <property name="text">
+ <string>Left to Right</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Right to Left</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Select Font:</string>
+ </property>
+ <property name="buddy">
+ <cstring>fontComboBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QFontComboBox" name="fontComboBox"/>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Style:</string>
+ </property>
+ <property name="buddy">
+ <cstring>style</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QComboBox" name="style"/>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Layout spacing:</string>
+ </property>
+ <property name="buddy">
+ <cstring>spacing</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QSlider" name="spacing">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro
new file mode 100644
index 0000000000..60c507fc3d
--- /dev/null
+++ b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro
@@ -0,0 +1,18 @@
+QT += widgets
+requires(qtConfig(fontcombobox))
+
+SOURCES += main.cpp
+SOURCES += customproxy.cpp embeddeddialog.cpp
+HEADERS += customproxy.h embeddeddialog.h
+
+FORMS += embeddeddialog.ui
+RESOURCES += embeddeddialogs.qrc
+
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/graphicsview/embeddeddialogs
+INSTALLS += target
diff --git a/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc
new file mode 100644
index 0000000000..33be5038da
--- /dev/null
+++ b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource>
+ <file>No-Ones-Laughing-3.jpg</file>
+ </qresource>
+</RCC>
diff --git a/tests/manual/examples/widgets/graphicsview/embeddeddialogs/main.cpp b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/main.cpp
new file mode 100644
index 0000000000..700c6b1222
--- /dev/null
+++ b/tests/manual/examples/widgets/graphicsview/embeddeddialogs/main.cpp
@@ -0,0 +1,42 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "customproxy.h"
+#include "embeddeddialog.h"
+
+#include <QApplication>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QGraphicsScene scene;
+ scene.setStickyFocus(true);
+ const int gridSize = 10;
+
+ for (int y = 0; y < gridSize; ++y) {
+ for (int x = 0; x < gridSize; ++x) {
+ CustomProxy *proxy = new CustomProxy(nullptr, Qt::Window);
+ proxy->setWidget(new EmbeddedDialog);
+
+ QRectF rect = proxy->boundingRect();
+
+ proxy->setPos(x * rect.width() * 1.05, y * rect.height() * 1.05);
+ proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
+
+ scene.addItem(proxy);
+ }
+ }
+ scene.setSceneRect(scene.itemsBoundingRect());
+
+ QGraphicsView view(&scene);
+ view.scale(0.5, 0.5);
+ view.setRenderHints(view.renderHints() | QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
+ view.setBackgroundBrush(QPixmap(":/No-Ones-Laughing-3.jpg"));
+ view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+ view.show();
+ view.setWindowTitle("Embedded Dialogs Example");
+ return app.exec();
+}