Sunday, April 5, 2009

Qt4 CoverFlow and QThreadPool

My OpenMoko cannot stay without CoverFlow, so here some code. But I need a lightweight class that allows me to load all files in a directory or a list of files. Scanning directory with QDir entryList can take long time, and loading all the images can take much more, So what I need is a class that solve this problem internally.

I've choose the way of QRunnable and QThreadPool to solve this problem, so I've a class that execute QDir EntryList and another one that load an Image. When file is Ready (FileName, Path) a gray square is displayed and will be replaced by the Image once it is fully loaded and scaled. Using this method you can flow between files even if CPU and Disk are still loading to load images, this means No UI Freeze when CoverFlow starts.

Note 1: You can flow between images using Left and Right Key or Clicking with mouse at the Left or the Right of the Central one.
Note 2: If you want a CoverFlow with a great transition effect take a look at Ariya's PictureFlow.

The Source code Is Available Here: Qt4 CoverFlow Source Code.

2 comments:

  1. Checkout QDirIterator, it doesn't block while getting the list of all files like QDir::entryList does.

    ReplyDelete
  2. also checkout QImageReader, this class gives more control when reading image, can create a thumbnail only reading a part of the image.

    ReplyDelete