// Symbian Foundation Example Code
//
// This software is in the public domain. No copyright is claimed, and you
// may use it for any purpose without license from the Symbian Foundation.
// No warranty for any purpose is expressed or implied by the authors or
// the Symbian Foundation.
#include "graphicsviewdemo.h"
#include <QVBoxLayout>
#include <QPushButton>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsEllipseItem>
#include <QGraphicsRectItem>
#include <QGraphicsItemAnimation>
#include <QTimeLine>
#include <qmybutton.h>
GraphicsViewDemo
::GraphicsViewDemo(QWidget *parent
){
view
->setBackgroundBrush
( QPixmap( ":/images/qt-tile.png" ) );
layout->addWidget( view );
layout->addWidget( button );
connect( button, SIGNAL(clicked()), this, SLOT(animate()) );
m_ellipse
->setPen
( QPen(Qt
::darkRed) );
m_ellipse->setBrush( Qt::red );
QMyButton *m_rectangle = new QMyButton( 0, 0, 40, 40 ); // <----------------------- In this line
m_rectangle
->setPen
( QPen(Qt
::black) );
m_rectangle
->setBrush
( QBrush( QColor( 0,
200,
0,
200 ) ) );
scene->addItem( m_ellipse );
scene->addItem( m_rectangle );
connect(m_rectangle, SIGNAL(myPressSignal), this, SLOT(animate()));
view->setScene( scene );
}
void GraphicsViewDemo::animate()
{
timeLine->setFrameRange(0, 100);
ellipseAnimation->setItem(m_ellipse);
ellipseAnimation->setTimeLine(timeLine);
/* QGraphicsItemAnimation *rectAnimation = new QGraphicsItemAnimation();
rectAnimation->setItem(m_rectangle);
rectAnimation->setTimeLine(timeLine);
rectAnimation->setPosAt(2, QPointF(30, 30));*/
for (int i = 0; i <= 200; ++i)
{
ellipseAnimation->setRotationAt( i/200.0, 360.0 * i/200.0 );
//rectAnimation->setRotationAt( i/200.0, -720.0 * i/200.0 );
qreal s = i>100?(1.0-((i-100)/100.0)):(i/100.0);
//rectAnimation->setScaleAt( i/200.0, 1.0+s, 1.0+s );
}
connect( timeLine, SIGNAL(finished()), timeLine, SLOT(deleteLater()) );
connect( timeLine, SIGNAL(finished()), ellipseAnimation, SLOT(deleteLater()) );
//connect( timeLine, SIGNAL(finished()), rectAnimation, SLOT(deleteLater()) );
timeLine->start();
}
// Symbian Foundation Example Code
//
// This software is in the public domain. No copyright is claimed, and you
// may use it for any purpose without license from the Symbian Foundation.
// No warranty for any purpose is expressed or implied by the authors or
// the Symbian Foundation.
#include "graphicsviewdemo.h"
#include <QVBoxLayout>
#include <QPushButton>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsEllipseItem>
#include <QGraphicsRectItem>
#include <QGraphicsItemAnimation>
#include <QTimeLine>
#include <qmybutton.h>
GraphicsViewDemo::GraphicsViewDemo(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout( this );
QGraphicsView *view = new QGraphicsView();
view->setBackgroundBrush( QPixmap( ":/images/qt-tile.png" ) );
QPushButton *button = new QPushButton( tr("Animate") );
layout->addWidget( view );
layout->addWidget( button );
connect( button, SIGNAL(clicked()), this, SLOT(animate()) );
QGraphicsScene *scene = new QGraphicsScene( QRect( -50, -50, 100, 100 ) );
m_ellipse = new QGraphicsEllipseItem( 25, -10, 20, 20 );
m_ellipse->setPen( QPen(Qt::darkRed) );
m_ellipse->setBrush( Qt::red );
QMyButton *m_rectangle = new QMyButton( 0, 0, 40, 40 ); // <----------------------- In this line
m_rectangle->setPen( QPen(Qt::black) );
m_rectangle->setBrush( QBrush( QColor( 0, 200, 0, 200 ) ) );
scene->addItem( m_ellipse );
scene->addItem( m_rectangle );
connect(m_rectangle, SIGNAL(myPressSignal), this, SLOT(animate()));
view->setScene( scene );
}
void GraphicsViewDemo::animate()
{
QTimeLine *timeLine = new QTimeLine(3000);
timeLine->setFrameRange(0, 100);
QGraphicsItemAnimation *ellipseAnimation = new QGraphicsItemAnimation();
ellipseAnimation->setItem(m_ellipse);
ellipseAnimation->setTimeLine(timeLine);
/* QGraphicsItemAnimation *rectAnimation = new QGraphicsItemAnimation();
rectAnimation->setItem(m_rectangle);
rectAnimation->setTimeLine(timeLine);
rectAnimation->setPosAt(2, QPointF(30, 30));*/
for (int i = 0; i <= 200; ++i)
{
ellipseAnimation->setRotationAt( i/200.0, 360.0 * i/200.0 );
//rectAnimation->setRotationAt( i/200.0, -720.0 * i/200.0 );
qreal s = i>100?(1.0-((i-100)/100.0)):(i/100.0);
//rectAnimation->setScaleAt( i/200.0, 1.0+s, 1.0+s );
}
connect( timeLine, SIGNAL(finished()), timeLine, SLOT(deleteLater()) );
connect( timeLine, SIGNAL(finished()), ellipseAnimation, SLOT(deleteLater()) );
//connect( timeLine, SIGNAL(finished()), rectAnimation, SLOT(deleteLater()) );
timeLine->start();
}
To copy to clipboard, switch view to plain text mode
Bookmarks