SHARE
TWEET

Untitled

a guest Oct 12th, 2015 6 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "buttonclickeffect.h"
  2.  
  3. ButtonClickEffect::ButtonClickEffect(QObject *parent) : QObject(parent)
  4. {
  5.     timer = new QTimer(this);
  6.  
  7.     QObject::connect(timer, SIGNAL(timeout()), this, SLOT(OnTick()));
  8. }
  9.  
  10. bool ButtonClickEffect::eventFilter(QObject *object, QEvent *event)
  11. {
  12.     QWidget *widget = (QWidget *)object;
  13.  
  14.     if(event->type() == QEvent::MouseButtonPress)
  15.     {
  16.         QMouseEvent *mouseEvent = (QMouseEvent *)event;
  17.  
  18.         if(mouseEvent->button() == Qt::LeftButton)
  19.         {
  20.             delta = 0.0f;
  21.  
  22.             timer->start(10);
  23.  
  24.             return true;
  25.         }
  26.     }
  27.     else if(event->type() == QEvent::Paint)
  28.     {
  29.         if(delta == -1.0f)
  30.         {
  31.             return false;
  32.         }
  33.  
  34.         QPainter painter(widget);
  35.  
  36.         if(delta == 0.0f)
  37.         {
  38.             delta = -1.0f;
  39.  
  40.             painter.eraseRect(widget->geometry());
  41.         }
  42.         else
  43.         {
  44.             painter.fillRect(widget->geometry(), QColor(200, 200, 200, 200 * (delta < 1.0f ? delta : 2.0f - delta)));
  45.         }
  46.  
  47.         return true;
  48.     }
  49.  
  50.     return false;
  51. }
  52.  
  53. void ButtonClickEffect::OnTick()
  54. {
  55.     delta += 0.1f;
  56.  
  57.     if(delta > 2.0f)
  58.     {
  59.         delta = 0.0f;
  60.  
  61.         timer->stop();
  62.     }
  63.  
  64.     QWidget *w = (QWidget *)parent();
  65.  
  66.     w->update();
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top