diff options
Diffstat (limited to 'examples/widgets/graphicsview/elasticnodes/elasticnodes.py')
-rw-r--r-- | examples/widgets/graphicsview/elasticnodes/elasticnodes.py | 70 |
1 files changed, 15 insertions, 55 deletions
diff --git a/examples/widgets/graphicsview/elasticnodes/elasticnodes.py b/examples/widgets/graphicsview/elasticnodes/elasticnodes.py index 78f006285..90cb49626 100644 --- a/examples/widgets/graphicsview/elasticnodes/elasticnodes.py +++ b/examples/widgets/graphicsview/elasticnodes/elasticnodes.py @@ -1,44 +1,6 @@ - -############################################################################# -## -## Copyright (C) 2013 Riverbank Computing Limited. -## Copyright (C) 2021 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# +# Copyright (C) 2013 Riverbank Computing Limited. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import sys import weakref @@ -46,10 +8,10 @@ import math from PySide6.QtCore import (QLineF, QPointF, QRandomGenerator, QRectF, QSizeF, Qt, qAbs) -from PySide6.QtGui import (QColor, QBrush, QPainter, QPainterPath, QPen, +from PySide6.QtGui import (QColor, QBrush, QLinearGradient, QPainter, QPainterPath, QPen, QPolygonF, QRadialGradient) from PySide6.QtWidgets import (QApplication, QGraphicsItem, QGraphicsScene, - QGraphicsView, QStyle, QWidget) + QGraphicsView, QStyle) def random(boundary): @@ -58,8 +20,6 @@ def random(boundary): class Edge(QGraphicsItem): - item_type = QGraphicsItem.UserType + 2 - def __init__(self, sourceNode, destNode): super().__init__() @@ -74,7 +34,7 @@ class Edge(QGraphicsItem): self.adjust() def item_type(self): - return Edge.item_type + return QGraphicsItem.UserType + 2 def source_node(self): return self.source() @@ -157,7 +117,6 @@ class Edge(QGraphicsItem): class Node(QGraphicsItem): - item_type = QGraphicsItem.UserType + 1 def __init__(self, graphWidget): super().__init__() @@ -167,11 +126,11 @@ class Node(QGraphicsItem): self._new_pos = QPointF() self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) - self.setCacheMode(self.DeviceCoordinateCache) + self.setCacheMode(QGraphicsItem.DeviceCoordinateCache) self.setZValue(-1) def item_type(self): - return Node.item_type + return QGraphicsItem.UserType + 1 def add_edge(self, edge): self._edge_list.append(weakref.ref(edge)) @@ -195,7 +154,7 @@ class Node(QGraphicsItem): line = QLineF(self.mapFromItem(item, 0, 0), QPointF(0, 0)) dx = line.dx() dy = line.dy() - l = 2.0 * (dx * dx + dy * dy) + l = 2.0 * (dx * dx + dy * dy) # noqa: E741 if l > 0: xvel += (dx * 150.0) / l yvel += (dy * 150.0) / l @@ -230,7 +189,7 @@ class Node(QGraphicsItem): def boundingRect(self): adjust = 2.0 return QRectF(-10 - adjust, -10 - adjust, - 23 + adjust, 23 + adjust) + 23 + adjust, 23 + adjust) def shape(self): path = QPainterPath() @@ -386,9 +345,9 @@ class GraphWidget(QGraphicsView): bottom_shadow = QRectF(scene_rect.left() + 5, scene_rect.bottom(), scene_rect.width(), 5) if right_shadow.intersects(rect) or right_shadow.contains(rect): - painter.fillRect(right_shadow, Qt.darkGray) + painter.fillRect(right_shadow, Qt.darkGray) if bottom_shadow.intersects(rect) or bottom_shadow.contains(rect): - painter.fillRect(bottom_shadow, Qt.darkGray) + painter.fillRect(bottom_shadow, Qt.darkGray) # Fill. gradient = QLinearGradient(scene_rect.topLeft(), scene_rect.bottomRight()) @@ -400,7 +359,7 @@ class GraphWidget(QGraphicsView): # Text. text_rect = QRectF(scene_rect.left() + 4, scene_rect.top() + 4, - scene_rect.width() - 4, scene_rect.height() - 4) + scene_rect.width() - 4, scene_rect.height() - 4) message = self.tr("Click and drag the nodes around, and zoom with the " "mouse wheel or the '+' and '-' keys") @@ -414,7 +373,8 @@ class GraphWidget(QGraphicsView): painter.drawText(text_rect, message) def scale_view(self, scaleFactor): - factor = self.transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width() + factor = self.transform().scale(scaleFactor, scaleFactor).mapRect( + QRectF(0, 0, 1, 1)).width() if factor < 0.07 or factor > 100: return |