MyQGraphicsView.cpp
Go to the documentation of this file.
00001 #include "MyQGraphicsView.h"
00002 
00003 void MyQGraphicsView::wheelEvent ( QWheelEvent * event )
00004 {
00005     int numDegrees = event->delta() / 8;
00006     int numSteps = numDegrees / 15;  // see QWheelEvent documentation
00007     _numScheduledScalings += numSteps;
00008     if (_numScheduledScalings * numSteps < 0)  // if user moved the wheel in another direction, we reset previously scheduled scalings
00009         _numScheduledScalings = numSteps;
00010  
00011     QTimeLine *anim = new QTimeLine(350, this);
00012     anim->setUpdateInterval(50);
00013  
00014     connect(anim, SIGNAL(valueChanged(qreal)), SLOT(scalingTime(qreal)));
00015     connect(anim, SIGNAL(finished()), SLOT(animFinished()));
00016     anim->start();
00017 }
00018 
00019 void MyQGraphicsView::scalingTime(qreal x)
00020 {
00021     qreal factor = 1.0 + qreal(_numScheduledScalings) / 300.0;
00022     scale_factor *= factor;
00023 
00024   /*  if(scale_factor < 1.0)
00025         {
00026                 scale_factor /= factor;
00027                 if(_numScheduledScalings > 0)
00028                         _numScheduledScalings--;
00029                 else if(_numScheduledScalings <0)
00030                         _numScheduledScalings++;
00031         }
00032         else
00033         {*/             
00034                 scale(factor, factor);
00035         //}
00036 }
00037 
00038 void MyQGraphicsView::animFinished()
00039 {
00040     if (_numScheduledScalings > 0)
00041         _numScheduledScalings--;
00042     else
00043         _numScheduledScalings++;
00044     sender()->~QObject();
00045 }
00046 
00047 MyQGraphicsView::MyQGraphicsView(QWidget* widget): QGraphicsView (widget)
00048 {
00049         _numScheduledScalings = 0;
00050         scale_factor = 1.0;
00051 }


corobot_teleop
Author(s): Morgan Cormier/Gang Li/mcormier@coroware.com
autogenerated on Tue Jan 7 2014 11:39:41