summaryrefslogtreecommitdiffstats
path: root/examples/graphicsview/elasticnodes
diff options
context:
space:
mode:
Diffstat (limited to 'examples/graphicsview/elasticnodes')
-rw-r--r--examples/graphicsview/elasticnodes/edge.cpp2
-rw-r--r--examples/graphicsview/elasticnodes/elasticnodes.desktop11
-rw-r--r--examples/graphicsview/elasticnodes/elasticnodes.pro3
-rw-r--r--examples/graphicsview/elasticnodes/graphwidget.cpp29
-rw-r--r--examples/graphicsview/elasticnodes/graphwidget.h5
-rw-r--r--examples/graphicsview/elasticnodes/main.cpp15
-rw-r--r--examples/graphicsview/elasticnodes/node.cpp15
7 files changed, 70 insertions, 10 deletions
diff --git a/examples/graphicsview/elasticnodes/edge.cpp b/examples/graphicsview/elasticnodes/edge.cpp
index 2b5cae5e1b..652ab737fc 100644
--- a/examples/graphicsview/elasticnodes/edge.cpp
+++ b/examples/graphicsview/elasticnodes/edge.cpp
@@ -144,6 +144,6 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
painter->setBrush(Qt::black);
painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2);
- painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2);
+ painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2);
}
//! [6]
diff --git a/examples/graphicsview/elasticnodes/elasticnodes.desktop b/examples/graphicsview/elasticnodes/elasticnodes.desktop
new file mode 100644
index 0000000000..64402d080f
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/elasticnodes.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Elastic Nodes
+Exec=/opt/usr/bin/elasticnodes
+Icon=elasticnodes
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/graphicsview/elasticnodes/elasticnodes.pro b/examples/graphicsview/elasticnodes/elasticnodes.pro
index be7ebe460b..6017b2c9d4 100644
--- a/examples/graphicsview/elasticnodes/elasticnodes.pro
+++ b/examples/graphicsview/elasticnodes/elasticnodes.pro
@@ -22,3 +22,6 @@ symbian {
CONFIG += qt_example
}
QT += widgets
+maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri)
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/graphicsview/elasticnodes/graphwidget.cpp b/examples/graphicsview/elasticnodes/graphwidget.cpp
index ce73a68b47..48a9784c54 100644
--- a/examples/graphicsview/elasticnodes/graphwidget.cpp
+++ b/examples/graphicsview/elasticnodes/graphwidget.cpp
@@ -132,17 +132,14 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
centerNode->moveBy(20, 0);
break;
case Qt::Key_Plus:
- scaleView(qreal(1.2));
+ zoomIn();
break;
case Qt::Key_Minus:
- scaleView(1 / qreal(1.2));
+ zoomOut();
break;
case Qt::Key_Space:
case Qt::Key_Enter:
- foreach (QGraphicsItem *item, scene()->items()) {
- if (qgraphicsitem_cast<Node *>(item))
- item->setPos(-150 + qrand() % 300, -150 + qrand() % 300);
- }
+ shuffle();
break;
default:
QGraphicsView::keyPressEvent(event);
@@ -206,6 +203,7 @@ void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
painter->setBrush(Qt::NoBrush);
painter->drawRect(sceneRect);
+#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5)
// Text
QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
sceneRect.width() - 4, sceneRect.height() - 4);
@@ -220,6 +218,7 @@ void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
painter->drawText(textRect.translated(2, 2), message);
painter->setPen(Qt::black);
painter->drawText(textRect, message);
+#endif
}
//! [6]
@@ -233,3 +232,21 @@ void GraphWidget::scaleView(qreal scaleFactor)
scale(scaleFactor, scaleFactor);
}
//! [7]
+
+void GraphWidget::shuffle()
+{
+ foreach (QGraphicsItem *item, scene()->items()) {
+ if (qgraphicsitem_cast<Node *>(item))
+ item->setPos(-150 + qrand() % 300, -150 + qrand() % 300);
+ }
+}
+
+void GraphWidget::zoomIn()
+{
+ scaleView(qreal(1.2));
+}
+
+void GraphWidget::zoomOut()
+{
+ scaleView(1 / qreal(1.2));
+}
diff --git a/examples/graphicsview/elasticnodes/graphwidget.h b/examples/graphicsview/elasticnodes/graphwidget.h
index f64f59e691..354967bdd2 100644
--- a/examples/graphicsview/elasticnodes/graphwidget.h
+++ b/examples/graphicsview/elasticnodes/graphwidget.h
@@ -55,6 +55,11 @@ public:
void itemMoved();
+public slots:
+ void shuffle();
+ void zoomIn();
+ void zoomOut();
+
protected:
void keyPressEvent(QKeyEvent *event);
void timerEvent(QTimerEvent *event);
diff --git a/examples/graphicsview/elasticnodes/main.cpp b/examples/graphicsview/elasticnodes/main.cpp
index 2cd3d2641f..9eb8ba11be 100644
--- a/examples/graphicsview/elasticnodes/main.cpp
+++ b/examples/graphicsview/elasticnodes/main.cpp
@@ -47,7 +47,18 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
- GraphWidget widget;
- widget.show();
+ GraphWidget *widget = new GraphWidget;
+
+ QMainWindow mainWindow;
+ mainWindow.setCentralWidget(widget);
+
+#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
+ mainWindow.menuBar()->addAction("Shuffle", widget, SLOT(shuffle()));
+ mainWindow.menuBar()->addAction("Zoom In", widget, SLOT(zoomIn()));
+ mainWindow.menuBar()->addAction("Zoom Out", widget, SLOT(zoomOut()));
+ mainWindow.showMaximized();
+#else
+ mainWindow.show();
+#endif
return app.exec();
}
diff --git a/examples/graphicsview/elasticnodes/node.cpp b/examples/graphicsview/elasticnodes/node.cpp
index 8d1daddc12..b345f83640 100644
--- a/examples/graphicsview/elasticnodes/node.cpp
+++ b/examples/graphicsview/elasticnodes/node.cpp
@@ -141,9 +141,16 @@ bool Node::advance()
//! [8]
QRectF Node::boundingRect() const
{
+#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
+ // Add some extra space around the circle for easier touching with finger
+ qreal adjust = 30;
+ return QRectF( -10 - adjust, -10 - adjust,
+ 20 + adjust * 2, 20 + adjust * 2);
+#else
qreal adjust = 2;
- return QRectF(-10 - adjust, -10 - adjust,
+ return QRectF( -10 - adjust, -10 - adjust,
23 + adjust, 23 + adjust);
+#endif
}
//! [8]
@@ -151,7 +158,12 @@ QRectF Node::boundingRect() const
QPainterPath Node::shape() const
{
QPainterPath path;
+#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
+ // Add some extra space around the circle for easier touching with finger
+ path.addEllipse( -40, -40, 80, 80);
+#else
path.addEllipse(-10, -10, 20, 20);
+#endif
return path;
}
//! [9]
@@ -174,6 +186,7 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
gradient.setColorAt(1, Qt::darkYellow);
}
painter->setBrush(gradient);
+
painter->setPen(QPen(Qt::black, 0));
painter->drawEllipse(-10, -10, 20, 20);
}