58 #include <QRandomGenerator>
73 setMinimumSize(400, 400);
74 setWindowTitle(
tr(
"Elastic Nodes"));
82 centerNode =
new Node(
this);
125 timerId = startTimer(1000 / 25);
132 switch (
event->key()) {
134 centerNode->
moveBy(0, -20);
137 centerNode->
moveBy(0, 20);
140 centerNode->
moveBy(-20, 0);
143 centerNode->
moveBy(20, 0);
174 node->calculateForces();
176 bool itemsMoved =
false;
177 for (
Node *
node : qAsConst(nodes)) {
178 if (
node->advancePosition())
189 #if QT_CONFIG(wheelevent)
191 void GraphWidget::wheelEvent(QWheelEvent *
event)
223 QString message(
tr(
"Click and drag the nodes around, and zoom with the mouse "
224 "wheel or the '+' and '-' keys"));
241 if (factor < 0.07 || factor > 100)
244 scale(scaleFactor, scaleFactor);
252 if (qgraphicsitem_cast<Node *>(
item))
The QFont class specifies a query for a font used for drawing text.
void setColorAt(qreal pos, const QColor &color)
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
void moveBy(qreal dx, qreal dy)
void setPos(const QPointF &pos)
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
QList< QGraphicsItem * > items(Qt::SortOrder order=Qt::DescendingOrder) const
void addItem(QGraphicsItem *item)
void setItemIndexMethod(ItemIndexMethod method)
void setSceneRect(const QRectF &rect)
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
QList< QGraphicsItem * > items() const
QTransform transform() const
QRectF sceneRect
the area of the scene visualized by this view.
void scale(qreal sx, qreal sy)
void setCacheMode(CacheMode mode)
void setRenderHint(QPainter::RenderHint hint, bool enabled=true)
void keyPressEvent(QKeyEvent *event) override
void setScene(QGraphicsScene *scene)
friend class QGraphicsScene
@ BoundingRectViewportUpdate
void setTransformationAnchor(ViewportAnchor anchor)
QGraphicsScene * scene() const
void setViewportUpdateMode(ViewportUpdateMode mode)
The QKeyEvent class describes a key event.
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush.
The QPainter class performs low-level painting on widgets and other paint devices.
void drawRect(const QRectF &rect)
void setPen(const QColor &color)
const QFont & font() const
void setFont(const QFont &f)
void drawText(const QPointF &p, const QString &s)
void setBrush(const QBrush &brush)
void fillRect(const QRectF &, const QBrush &)
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
The QRectF class defines a finite rectangle in the plane using floating point precision.
constexpr qreal bottom() const noexcept
constexpr qreal height() const noexcept
constexpr qreal width() const noexcept
bool contains(const QRectF &r) const noexcept
constexpr qreal left() const noexcept
bool intersects(const QRectF &r) const noexcept
constexpr QPointF topLeft() const noexcept
constexpr QPointF bottomRight() const noexcept
constexpr qreal top() const noexcept
constexpr qreal right() const noexcept
constexpr int width() const noexcept
constexpr QRect translated(int dx, int dy) const noexcept
The QString class provides a Unicode character string.
The QTimerEvent class contains parameters that describe a timer event.
QT_END_INCLUDE_NAMESPACE typedef double qreal
GLenum GLuint GLenum GLsizei const GLchar * message
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent