[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/office/zippl
From: Klaas Freitag <freitag () suse ! de>
Date: 2010-06-09 9:41:01
Message-ID: 20100609094101.9E2F9AC8CE () svn ! kde ! org
[Download RAW message or body]
SVN commit 1136237 by freitag:
Animated move from spot to spot
M +0 -21 graphwidget.cpp
M +15 -7 zippl.xml
M +40 -7 zipplcontroler.cpp
M +21 -10 zipplxmlreader.cpp
M +4 -0 zipplxmlreader.h
--- trunk/playground/office/zippl/graphwidget.cpp #1136236:1136237
@@ -95,29 +95,8 @@
void GraphWidget::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
-#if 0
- QList<Node *> nodes;
- foreach (QGraphicsItem *item, scene()->items()) {
- if (Node *node = qgraphicsitem_cast<Node *>(item))
- nodes << node;
}
- foreach (Node *node, nodes)
- node->calculateForces();
-
- bool itemsMoved = false;
- foreach (Node *node, nodes) {
- if (node->advance())
- itemsMoved = true;
- }
-
- if (!itemsMoved) {
- killTimer(timerId);
- timerId = 0;
- }
-#endif
-}
-
void GraphWidget::wheelEvent(QWheelEvent *event)
{
scaleView(pow((double)2, -event->delta() / 240.0));
--- trunk/playground/office/zippl/zippl.xml #1136236:1136237
@@ -8,23 +8,31 @@
<email>freitag@suse.de</email>
</author>
</meta>
- <presentation width="1000" height="2000">
- <spot x="-400" y="620">
+ <presentation width="10000" height="20000">
+ <spot x="-300" y="0">
<rect bgcolor="#eeaabb" border="1" bordercolor="#aaffbb">
- <text x="5" y="5">The text is very nice.</text>
+ <text x="5" y="5">Spot number 1</text>
<text x="12" y="17">Dies ist eine weitere Textzeile</text>
<img file="images/spot1.png"/>
</rect>
</spot>
- <spot x="250" y="30">
- <text x="5" y="85">The second text</text>
+ <spot x="100" y="0">
+ <rect bgcolor="#eeaabb" border="1" bordercolor="#aaffbb">
+ <text x="5" y="5">Spot number 2</text>
+ <text x="12" y="17">Dies ist eine weitere Textzeile</text>
+ <img file="images/spot1.png"/>
+ </rect>
+ </spot>
+
+ <spot x="0" y="400">
+ <text x="5" y="85">Spot number 3</text>
<circle x="75" y="50" r="12" />
<image x="20" y="0" width="100">images/zippl_logo.png</image>
</spot>
- <spot x="-200" y="-420">
- <text x="34" y="122">Do number three!</text>
+ <spot x="0" y="-600">
+ <text x="34" y="122">Spot number 4!</text>
<circle x="36" y="125" r="12"/>
</spot>
</presentation>
--- trunk/playground/office/zippl/zipplcontroler.cpp #1136236:1136237
@@ -30,6 +30,7 @@
if( res ) {
qDebug() << "Successfully read zippl in file!";
mSpotList = xmlReader.spotItems();
+
} else {
qDebug() << "Failed to read zippl in file!";
}
@@ -41,13 +42,11 @@
qDebug() << "Move to next spot, current spot no is " << mCurrSpotNo;
QGraphicsItem *currItem = 0;
- if( mCurrSpotNo < mSpotList.count() ) {
- currItem = mSpotList[mCurrSpotNo];
- mCurrSpotNo++;
- } else {
- currItem = mSpotList[0];
+
+ if( mCurrSpotNo >= mSpotList.count() ) {
mCurrSpotNo = 0;
}
+ currItem = mSpotList[mCurrSpotNo++];
centerOnItem( currItem );
}
@@ -73,11 +72,45 @@
if( !item ) {
qDebug() << "No current item found!";
} else {
+ qDebug() << "Centering on item " << item->data(ID).toInt();
+
qreal width = mGraphWidget->viewport()->width();
qreal height = mGraphWidget->viewport()->height();
+ qDebug() << "Viewport width and height: " << width << "x" << height;
QPointF viewPoint = item->scenePos();
- mGraphWidget->horizontalScrollBar()->setValue(int(viewPoint.x() - width / 2.0));
- mGraphWidget->verticalScrollBar()->setValue(int(viewPoint.y() - height / 2.0));
+ qDebug() << "ViewPoint: " << viewPoint.x() << "x" << viewPoint.y();
+
+
+ qDebug() << "== Animation! ==";
+ QPropertyAnimation *animHor = new QPropertyAnimation( \
mGraphWidget->horizontalScrollBar(), "value" ); + // Set up horizontal scroll \
animation + animHor->setDuration(1000);
+
+ int startValHor = mGraphWidget->horizontalScrollBar()->value();
+ int minimum = mGraphWidget->horizontalScrollBar()->minimum();
+ int maximum = mGraphWidget->horizontalScrollBar()->maximum();
+ int endValHor = viewPoint.x() - width / 2.0 + item->boundingRect().width()/2.0;
+
+ qDebug() << "Min/Max: " << minimum << "x" << maximum;
+ qDebug() << "Startvalue horizontal: " << startValHor;
+ qDebug() << "Item Bounding Rect: " << item->boundingRect();
+ qDebug() << "Endvalue horizontal: " << endValHor;
+
+ animHor->setStartValue( QVariant( startValHor ) );
+ animHor->setEndValue( QVariant(endValHor) );
+
+ QPropertyAnimation *animVer = new QPropertyAnimation( \
mGraphWidget->verticalScrollBar(), "value" ); + animVer->setDuration(1000);
+ animVer->setStartValue( QVariant( mGraphWidget->verticalScrollBar()->value()) );
+ int endValVer = viewPoint.y() - height/ 2.0 + item->boundingRect().height()/2.0;
+ animVer->setEndValue( QVariant( endValVer ) );
+
+
+ QParallelAnimationGroup *group = new QParallelAnimationGroup;
+ group->addAnimation( animHor );
+ group->addAnimation( animVer );
+
+ group->start();
}
}
--- trunk/playground/office/zippl/zipplxmlreader.cpp #1136236:1136237
@@ -6,7 +6,8 @@
#include "graphwidget.h"
ZipplXmlReader::ZipplXmlReader( GraphWidget *widget )
- :mGraphWidget( widget )
+ :mGraphWidget( widget ),
+ mMode( "production")
{
}
@@ -18,6 +19,7 @@
mCurrParent = 0;
QGraphicsScene *scene = mGraphWidget->scene();
+ int spotID = 0;
while (!atEnd()) {
readNext();
@@ -28,22 +30,25 @@
QString xStr = attributes().value("width").toString();
int x = xStr.toInt();
int dx = -(x/2);
+ // presentation mode: debug & presentation
+ QString mode = attributes().value("mode").toString();
+ if( !mode.isEmpty() ) mMode = mode;
QString yStr = attributes().value("height").toString();
int y = yStr.toInt();
int dy = -(y/2);
- qDebug() << "XY: " << x;
- qDebug() << "XY: " << y;
- qDebug() << "XY: " << dx;
- qDebug() << "XY: " << dy;
scene->setSceneRect( QRectF(dx, dy, x, y) );
}else if( name() == "spot" ) {
if( mCurrParent != 0 ) {
qDebug() << "Strange: Current Parent should be zero here!";
}
- mCurrParent = new QGraphicsRectItem( );
+ QGraphicsRectItem *rectItem = new QGraphicsRectItem( );
+ rectItem->setPen( QPen( QColor( 240, 240, 240 )));
+ mCurrParent = rectItem;
+ mCurrParent->setData( ID, QVariant( spotID++ ));
+
QString x = attributes().value("x").toString();
QString y = attributes().value("y").toString();
mCurrParent->setX( x.toInt() );
@@ -71,14 +76,14 @@
if( handleImg( scene ) ) {
}
-
-
}
-
} else if( isEndElement() ) {
qDebug( ) << "XML CLOSE: " << name().toString();
if( name() == "spot" ) {
-
+ QRectF rect = mCurrParent->childrenBoundingRect();
+ rect.setX(0);
+ rect.setY(0);
+ qgraphicsitem_cast<QGraphicsRectItem*>(mCurrParent)->setRect( rect);
mCurrParent = 0;
} else if( name() == "rect" ) {
qgraphicsitem_cast<QGraphicsRectItem*>(mCurrParent)->setRect( \
mCurrParent->childrenBoundingRect() ); @@ -126,7 +131,13 @@
}
+QString ZipplXmlReader::mode()
+{
+ return mMode;
+}
+
QList<QGraphicsItem*> ZipplXmlReader::spotItems()
{
return mSpots;
}
+
--- trunk/playground/office/zippl/zipplxmlreader.h #1136236:1136237
@@ -5,6 +5,8 @@
#include <QIODevice>
#include <QList>
+#define ID 0
+
class GraphWidget;
class ZipplXmlReader : public QXmlStreamReader
@@ -15,12 +17,14 @@
bool read( QIODevice * );
QList<QGraphicsItem*> spotItems();
+ QString mode();
private:
bool handleImg( QGraphicsScene* );
QGraphicsItem *mCurrParent;
GraphWidget *mGraphWidget;
QList<QGraphicsItem*> mSpots;
+ QString mMode;
};
#endif // ZIPPLXMLREADER_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic