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

Saturday, December 31, 2005

1136073600

Good bye, 2005. Welcome to 2006!

Guess what the number means... :-P

Friday, December 30, 2005

qPrintable

In Qt application, outputting printf-like formatted debug message involving QString means using latin1 or utf8 such as:

QString name = "Willy Wonka";
int num = 5;
qDebug("My name is %s, I invite %d children", name.latin1(), num);

But in Qt 4.x, you can use qPrintable function:

QString str = "a chocolate factory";
qDebug("I have %s", qPrintable(str));

For non-formatted output, just use qDebug() as an output stream.

Friday, December 23, 2005

OpenMortal Combat

Remember the old good time with Mortal Kombat? Well, look no more! Why don't you try OpenMortal?

Installation is supereasy. In a standard box with SDL, that would only mean typical extract, configure, make and make install steps. Few minutes are all that you need. Mac OS X and Windows packages are also available.

OpenMortal is practically meant to be a parody, but nevertheless it is a good one and quite joyful to play. Don't expect the same touches and completeness as the original Mortal Kombat. Looking at what has been achieved so far, then it's simply amazing! The characters are for real, at least real persons whose movements are digitized and imported to the game. If you are willing to undertake the tedious steps, the you can also become a character. However, it's safe to say we would not see someone like Goro in the near future :-P

Network play is supported, but no AI means you can not play against the computer. Since that old Mortal Kombat could have such a simple (and dumb) AI in a ridiculously prehistoric machine by today's standard, I bet it's only a question of lack of contribution rather that difficulties. If you're a programmer looking for something for fun, this could be a nice holiday project indeed.

Oh, how I miss Fatality...

The Famous Cat

OK, finally I got my Schrödinger's Cat T-shirt (has nothing to do with this guy's encyclopedia). Unless you live under the rock, you would know what this shirt has different statement (about the life of the cat) on its front and back side. And if you don't live under the rock, you might want to know that this shirt can boost your charm, at least that what happened to Wil Wheaton.

Now I'm awaiting someone to make the Heisenberg version of the shirt, saying that "Schrödinger's Cat May Have Been There". That would be funny :-P

Wednesday, December 21, 2005

Language Autodetect

If you often compose mails with different languages and use spell checker quite often, GMail cleverly does not ask you in which language the mail is written, nor you need to specify one. You write in English, then English spell checker is used. You write in German, then German spell checker is used. Seems trivial, still I was happy when I realized this for the first time.

On related thing, GMail seems to use Sophos for its antivirus.

Monday, December 19, 2005

Pulsating Effect for QToolTip

About ten months ago, I played around with the idea of pulsating effect in QToolTip. Basically, the background color is changed quickly to series of some colors. See this Flash animation. The actual effect is of course much smoother than what is shown in this Flash demo.

Unfortunately that trick does not work anymore with the new Qt 4 as you can't change QToolTip's palette. However, I am able to get the solution: find the QTipLabel and then apply the same crime.

void MyWindow::beat()
{
  static QPointer<QLabel> tipLabel;
  static int index = 0;

  if(!tipLabel)
    foreach(QWidget *widget, QApplication::allWidgets())
      if(widget->inherits("QTipLabel"))
        tipLabel = qobject_cast<QLabel*>(widget);
 
  if(tipLabel)
  {
    int k = (index>7) ? 14-index : index;
    index += (index<14) ? 1 : -14;
    
    QColor c = QColor( 255, 128+k*16, k*20 );
    QPalette pal = tipLabel->palette();
    pal.setColor( QPalette::Background, c );
    tipLabel->setPalette( pal );
  }
 
  QTimer::singleShot(tipLabel? 100 : 1000, this, SLOT(beat()));
}

This is again a dirty hack, but it works as long as your program does not create its own QTipLabel and QToolTip implementation won't be radically changed.

if (party) CEO = false

I haven't read How to Become CEO yet, but looking at the excerpt, something is very interesting indeed:

There is no such thing as a business or office party. It is not a social gathering. It is business. Never party at an office party. It won't hurt you not to go at all. Don't offend people by criticizing the party or by publicly announcing your intentions. Simply don't go. Give polite excuses.

Sunday, December 18, 2005

Mission Impossible 3.0

Yes, Tom Cruise wants to catch up with the (amazing) 3.x series of KDE :-P

Mission: Impossible III will be out next summer. The teaser is already available, unfortunately nothing else has been revealed so far. Judging from the teaser, quite likely it will be the same like the last two: full of action and with boring plot. Frankly, I was quite disappointed that Ethan Hunt became more a 007-style agent, rather than one belongs to a group with astonishing teamwork skills. Let see what will happen to Ethan this time.

Trailer MI3

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 !

Wednesday, December 14, 2005

Arrow in Plastique QComboBox

If you try to find the dimension and position of the combobox arrow button, one of your chance is by using subControlRect of the style in use. Unfortunately, this can not work in Plastique style because this style does not return a correct QRect associated with the arrow's geometry, as evidence from the source code:

    case CC_ComboBox:
        switch (subControl) {
        case SC_ComboBoxArrow:
            rect = option->rect;
            break;

It simply gives back option->rect which is likely the widget's own rect(). Your program might believe that the arrow occupies the whole combobox.

Fortunately, thanks to the Trolls, this problem is gone with the upcoming Qt 4.1.

But just in case you still want to work with Qt 4.0 (and 4.0.1), then you have to implement hackish fix like this:

    QRect arrowRect = style()->subControlRect(QStyle::CC_ComboBox, 
        &opt, QStyle::SC_ComboBoxArrow, this);
    if( arrowRect == opt.rect )
    {
        // workaround for broken subControlRect
        int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
        arrowRect = QRect(width()-16-fw, height()-2*fw);
    }

Tuesday, December 13, 2005

Mostly Europe

According to Google Analytics, visitors to my blog are mostly from Europe:

Could it be because the majority of Planet KDE readers are KDE users? Will be interesting to see the result from Planet GNOME.

Monday, December 05, 2005

Virus from Aliens

Beware of the aliens, as they may send viruses: "...scientists searching the heavens for signals from extra-terrestrial civilisations are putting Earth's security at risk..."

Man, did these aliens watch Independence Day?

Friday, December 02, 2005

Scientific Example

A young English professor opened his first lecture for freshmen with a question, "Could anyone give an example of a sentence using the word learn, please?"

A student raised his hand and said, "I learn physics".

"Good", continued the professor, "but since you are now not in high school anymore, could you rather give a more interesting example? A more scientific one perhaps?"

The student thought for a few seconds. Then he came up with another example, "Albert Einstein learned physics".