diff options
Diffstat (limited to 'examples/widgets/graphicsview/embeddeddialogs')
10 files changed, 0 insertions, 477 deletions
diff --git a/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt b/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt deleted file mode 100644 index d9684236ab..0000000000 --- a/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -cmake_minimum_required(VERSION 3.16) -project(embeddeddialogs LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTOUIC ON) - -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_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 PUBLIC - Qt::Core - Qt::Gui - Qt::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/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg b/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg Binary files differdeleted file mode 100644 index 445567fbda..0000000000 --- a/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg +++ /dev/null diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp deleted file mode 100644 index 57a104f57d..0000000000 --- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp +++ /dev/null @@ -1,133 +0,0 @@ -// 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/examples/widgets/graphicsview/embeddeddialogs/customproxy.h b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h deleted file mode 100644 index 444d39e73e..0000000000 --- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h +++ /dev/null @@ -1,39 +0,0 @@ -// 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/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp deleted file mode 100644 index 43d7fbf1e9..0000000000 --- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// 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/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h deleted file mode 100644 index d4c561799e..0000000000 --- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h +++ /dev/null @@ -1,33 +0,0 @@ -// 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/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui deleted file mode 100644 index 82aa5d7be3..0000000000 --- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui +++ /dev/null @@ -1,88 +0,0 @@ -<?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/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro deleted file mode 100644 index 60c507fc3d..0000000000 --- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro +++ /dev/null @@ -1,18 +0,0 @@ -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/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc deleted file mode 100644 index 33be5038da..0000000000 --- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource> - <file>No-Ones-Laughing-3.jpg</file> - </qresource> -</RCC> diff --git a/examples/widgets/graphicsview/embeddeddialogs/main.cpp b/examples/widgets/graphicsview/embeddeddialogs/main.cpp deleted file mode 100644 index f022b74814..0000000000 --- a/examples/widgets/graphicsview/embeddeddialogs/main.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// 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[]) -{ - Q_INIT_RESOURCE(embeddeddialogs); - 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(); -} |