summaryrefslogtreecommitdiffstats
path: root/examples/graphicsview/elasticnodes
diff options
context:
space:
mode:
authorDavid Boddie <david.boddie@nokia.com>2011-04-27 19:16:41 +0200
committerDavid Boddie <david.boddie@nokia.com>2011-05-23 14:24:07 +0200
commit0748751c9f097d9d866605306bbdd4b96e2a5c4e (patch)
tree1838365e6ad6592a26e193289d2136cb89319972 /examples/graphicsview/elasticnodes
parent5feefb0c039dae04290d1fca7c2f24276b6f7582 (diff)
Squashed commit of the changes from the mobile-examples repository
(4.7-generated-declarative branch).
Diffstat (limited to 'examples/graphicsview/elasticnodes')
-rw-r--r--examples/graphicsview/elasticnodes/edge.cpp2
-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
6 files changed, 59 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.pro b/examples/graphicsview/elasticnodes/elasticnodes.pro
index 208c849d13..7a58dd162b 100644
--- a/examples/graphicsview/elasticnodes/elasticnodes.pro
+++ b/examples/graphicsview/elasticnodes/elasticnodes.pro
@@ -21,3 +21,6 @@ symbian {
TARGET.UID3 = 0xA000A642
CONFIG += qt_example
}
+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 c875b6551d..f6bf05de31 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 764bb3f0b9..524ef67b8a 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 ab7e7cf7c7..d653da5355 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);
}