From 806dda08d685bc5f9ed71dfe8b61f21848d48066 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 17 Aug 2012 13:23:19 +0200 Subject: Moving .qdoc files under examples/widgets/doc Updated those .qdoc files to refer to the new relative examples emplacement. Images and snippets to be moved later. Also grouped all widgets related examples under widgets. Change-Id: Ib29696e2d8948524537f53e8dda88f9ee26a597f Reviewed-by: J-P Nurmi --- .../embeddeddialogs/No-Ones-Laughing-3.jpg | Bin 0 -> 30730 bytes .../graphicsview/embeddeddialogs/customproxy.cpp | 167 +++++++++++++++++++++ .../graphicsview/embeddeddialogs/customproxy.h | 76 ++++++++++ .../embeddeddialogs/embeddeddialog.cpp | 106 +++++++++++++ .../graphicsview/embeddeddialogs/embeddeddialog.h | 66 ++++++++ .../graphicsview/embeddeddialogs/embeddeddialog.ui | 87 +++++++++++ .../embeddeddialogs/embeddeddialogs.pro | 19 +++ .../embeddeddialogs/embeddeddialogs.qrc | 5 + .../widgets/graphicsview/embeddeddialogs/main.cpp | 83 ++++++++++ 9 files changed, 609 insertions(+) create mode 100644 examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg create mode 100644 examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp create mode 100644 examples/widgets/graphicsview/embeddeddialogs/customproxy.h create mode 100644 examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp create mode 100644 examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h create mode 100644 examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui create mode 100644 examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro create mode 100644 examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc create mode 100644 examples/widgets/graphicsview/embeddeddialogs/main.cpp (limited to 'examples/widgets/graphicsview/embeddeddialogs') diff --git a/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg b/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg new file mode 100644 index 0000000000..445567fbda Binary files /dev/null and b/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg differ diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp new file mode 100644 index 0000000000..2aa2986014 --- /dev/null +++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "customproxy.h" + +#include + +CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags) + : QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(0) +{ + timeLine = new QTimeLine(250, this); + connect(timeLine, SIGNAL(valueChanged(qreal)), + this, SLOT(updateStep(qreal))); + connect(timeLine, SIGNAL(stateChanged(QTimeLine::State)), + this, SLOT(stateChanged(QTimeLine::State))); +} + +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 (timeLine->currentValue() != 1) + zoomIn(); +} + +void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + QGraphicsProxyWidget::hoverLeaveEvent(event); + if (!popupShown && (timeLine->direction() != QTimeLine::Backward || timeLine->currentValue() != 0)) + 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(value); + currentPopup->setCacheMode(ItemCoordinateCache); + if (scene()) + currentPopup->installSceneEventFilter(this); + } else if (scene()) { + currentPopup->removeSceneEventFilter(this); + currentPopup = 0; + } + } 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 new file mode 100644 index 0000000000..c85bbaccd3 --- /dev/null +++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CUSTOMPROXY_H +#define CUSTOMPROXY_H + +#include +#include + +class CustomProxy : public QGraphicsProxyWidget +{ + Q_OBJECT +public: + CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); + + QRectF boundingRect() const; + void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + +protected: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event); + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + +private slots: + void updateStep(qreal step); + void stateChanged(QTimeLine::State); + void zoomIn(); + void zoomOut(); + +private: + QTimeLine *timeLine; + bool popupShown; + QGraphicsItem *currentPopup; +}; + +#endif diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp new file mode 100644 index 0000000000..e306f32c71 --- /dev/null +++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "embeddeddialog.h" +#include "ui_embeddeddialog.h" + +#include + +EmbeddedDialog::EmbeddedDialog(QWidget *parent) + : QDialog(parent) +{ + ui = new Ui_embeddedDialog; + ui->setupUi(this); + ui->layoutDirection->setCurrentIndex(layoutDirection() != Qt::LeftToRight); + + foreach (QString styleName, QStyleFactory::keys()) { + ui->style->addItem(styleName); + if (style()->objectName().toLower() == styleName.toLower()) + ui->style->setCurrentIndex(ui->style->count() - 1); + } + + connect(ui->layoutDirection, SIGNAL(activated(int)), + this, SLOT(layoutDirectionChanged(int))); + connect(ui->spacing, SIGNAL(valueChanged(int)), + this, SLOT(spacingChanged(int))); + connect(ui->fontComboBox, SIGNAL(currentFontChanged(QFont)), + this, SLOT(fontChanged(QFont))); + connect(ui->style, SIGNAL(activated(QString)), + this, SLOT(styleChanged(QString))); +} + +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()); + foreach (QObject *child, widget->children()) { + if (QWidget *childWidget = qobject_cast(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 new file mode 100644 index 0000000000..59aa4c244a --- /dev/null +++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef EMBEDDEDDIALOG_H +#define EMBEDDEDDIALOG_H + +#include + +QT_FORWARD_DECLARE_CLASS(Ui_embeddedDialog); + +class EmbeddedDialog : public QDialog +{ + Q_OBJECT +public: + EmbeddedDialog(QWidget *parent = 0); + ~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 diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui new file mode 100644 index 0000000000..f967b10085 --- /dev/null +++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui @@ -0,0 +1,87 @@ + + embeddedDialog + + + + 0 + 0 + 407 + 134 + + + + Embedded Dialog + + + + + + Layout Direction: + + + layoutDirection + + + + + + + + Left to Right + + + + + Right to Left + + + + + + + + Select Font: + + + fontComboBox + + + + + + + + + + Style: + + + style + + + + + + + + + + Layout spacing: + + + spacing + + + + + + + Qt::Horizontal + + + + + + + + diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro new file mode 100644 index 0000000000..6244df4b68 --- /dev/null +++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro @@ -0,0 +1,19 @@ +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]/qtbase/graphicsview/embeddeddialogs +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.png *.jpg *.plist *.icns *.ico *.rc *.pro *.html *.doc images +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/embeddeddialogs +INSTALLS += target sources + +QT += widgets diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc new file mode 100644 index 0000000000..33be5038da --- /dev/null +++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc @@ -0,0 +1,5 @@ + + + No-Ones-Laughing-3.jpg + + diff --git a/examples/widgets/graphicsview/embeddeddialogs/main.cpp b/examples/widgets/graphicsview/embeddeddialogs/main.cpp new file mode 100644 index 0000000000..88b249e481 --- /dev/null +++ b/examples/widgets/graphicsview/embeddeddialogs/main.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "customproxy.h" +#include "embeddeddialog.h" + +#include + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(embeddeddialogs); + QApplication app(argc, argv); + + QGraphicsScene scene; + scene.setStickyFocus(true); +#ifndef Q_OS_WINCE + const int gridSize = 10; +#else + const int gridSize = 5; +#endif + + for (int y = 0; y < gridSize; ++y) { + for (int x = 0; x < gridSize; ++x) { + CustomProxy *proxy = new CustomProxy(0, 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(); +} -- cgit v1.2.3