QtAwesomeAnim.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "QtAwesomeAnim.h"
  2. #include <cmath>
  3. #include <QPainter>
  4. #include <QRect>
  5. #include <QTimer>
  6. #include <QWidget>
  7. QtAwesomeAnimation::QtAwesomeAnimation(QWidget *parentWidget, int interval, int step)
  8. : parentWidgetRef_( parentWidget )
  9. , timer_( 0 )
  10. , interval_( interval )
  11. , step_( step )
  12. , angle_( 0.0f )
  13. {
  14. }
  15. void QtAwesomeAnimation::setup( QPainter &painter, const QRect &rect)
  16. {
  17. // first time set the timer
  18. if( !timer_ )
  19. {
  20. timer_ = new QTimer();
  21. connect(timer_,SIGNAL(timeout()), this, SLOT(update()) );
  22. timer_->start(interval_);
  23. }
  24. else
  25. {
  26. //timer, angle, self.step = self.info[self.parent_widget]
  27. float x_center = rect.width() * 0.5;
  28. float y_center = rect.height() * 0.5;
  29. painter.translate(x_center, y_center);
  30. painter.rotate(angle_);
  31. painter.translate(-x_center, -y_center);
  32. }
  33. }
  34. void QtAwesomeAnimation::update()
  35. {
  36. angle_ += step_;
  37. angle_ = std::fmod( angle_, 360);
  38. parentWidgetRef_->update();
  39. }