[Qt-interest] Sleep

Mihail Naydenov mlists at ymail.com
Wed Apr 8 11:20:04 CEST 2009


http://www.boost.org/




________________________________
From: Parameshwari <paramr at tataelxsi.co.in>
To: Tim W <timpie.w at gmail.com>
Cc: qt-interest at trolltech.com
Sent: Wednesday, April 8, 2009 11:54:06 AM
Subject: Re: [Qt-interest] Sleep


Thanks 
Tim,But where can i get "#include <boost/function.hpp>" ,
"boost" location. Is that to be added a 
separate module? I am getting "error" in that.
 
Regards
 
 
-----Original Message-----
From: Tim W  [mailto:timpie.w at gmail.com]
Sent: Tuesday, April 07, 2009 7:59  PM
To: paramr at tataelxsi.co.in
Cc: qt-interest at trolltech.com
Subject: Re: [Qt-interest]  Sleep



On Tue, Apr 7, 2009 at 8:46 AM, Parameshwari <paramr at tataelxsi.co.in> wrote:

 
but i wanted to add a sleep  before resize option, So that i will get the slider effect.some one could  help in this.
 

Try not to suspend the gui thread.
I think you need something like this ...

//header
#include  <QObject>
#include <QSize>
#include  <boost/function.hpp>

class QTimeLine;

class  ResizeAnimation : public QObject
{
     Q_OBJECT
public:
    typedef boost::function<  void (int, int) > Resize;

    explicit  ResizeAnimation( QObject* const aParent );
    void  setResizeObject( const Resize& aResizableObject, const QSize&  aEndSize );

    public slots:
         void start();

        private  slots:
            void nextFrame(int  aFrame );

private:
    QTimeLine *const  m_timeLine;
    QSize m_size;   
     Resize m_resizable;   
};

//cpp
#include  "resizeanimation.h"
#include  <QTimeLine>

ResizeAnimation::ResizeAnimation( QObject* const  aParent ) 
: QObject(aParent),
  m_timeLine( new  QTimeLine( 2000, this )  ),
  m_size(),
  m_resizable()
{
     connect( m_timeLine, SIGNAL( frameChanged( int ) ),  SLOT(nextFrame(int)) );
    m_timeLine->setLoopCount( 5  );
}


void ResizeAnimation::setResizeObject( const Resize&  aResizableObject, const QSize& aEndSize  ) 
{ 
    m_resizable  =aResizableObject; 
    m_size =  aEndSize;
    m_timeLine->setFrameRange(0, qMax(  aEndSize.width(), aEndSize.height() ) );
}

void  ResizeAnimation::start() 
{  
     m_timeLine->start(); 
}

void  ResizeAnimation::nextFrame(int aFrame )
{
     if(!m_resizable)
    {
         m_resizable(qMin( aFrame, m_size.width() ), qMin( aFrame,  m_size.height() ));        
     }
}

//user code


#include  <QtGui/QApplication>
#include <QtGui/QWidget>
#include  <boost/lambda/bind.hpp>
#include <boost/ref.hpp>

using  namespace boost::lambda;
using namespace boost;


int main(int  argc, char *argv[])
{
    QApplication a(argc,  argv);
    QWidget widgetToResize;
     widgetToResize.resize( 0, 0 );
     widgetToResize.show();
    
     ResizeAnimation animation(0);
    void  (QWidget::*resize)( int, int ) = &QWidget::resize;
     animation.setResizeObject( bind(resize, &widgetToResize, _1, _2),  QSize( 500,500 ));
    animation.start();
     return a.exec();
}

 
    
Cheers,
Tim


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090408/071f40a1/attachment.html 


More information about the Qt-interest-old mailing list