My blog has been moved to ariya.ofilabs.com.

Thursday, December 15, 2005

Buzz, or Shake My Window

Ctrl+G is a very well-known shortcut by Yahoo! Messenger users. It means buzz your contact. Essentially, the other side will get "Buzz!" message, along with sound effect (if enabled) and the shaking of the chat window. The last part is very interesting and obviously used to steal the attention. It is difficult to explain if you never have experienced it :-)

To buzz-enabling your Qt application, here is the code snippet taken from what I have implemented for KYIM long time ago:

void Mainwin::buzz()
{
  int xp = x();
  int yp = y();
  QTime t;

  t.start();
  for ( int i = 32; i > 0; )
  {
    QApplication::processEvents();
    if ( t.elapsed() >= 1 )
    {
      int delta = i >> 2;
      int dir = i & 3;
      int dx = ((dir==1)||(dir==2)) ? delta : -delta;
      int dy = (dir<2) ? delta : -delta;
      move( xp+dx, yp+dy );
      t.restart();
      i--;
    }
  }
  move( xp, yp );
}

Happy buzzing !

No comments: