Created
July 5, 2014 08:04
-
-
Save peterix/b2b8c5990eb5edf4856c to your computer and use it in GitHub Desktop.
A thumbnail thing :D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ThumbnailRunnable: public QRunnable | |
| { | |
| public: | |
| ThumbnailRunnable (QString path, SharedIconCache cache) | |
| { | |
| m_path = path; | |
| m_cache = cache; | |
| } | |
| void run() | |
| { | |
| QFileInfo info(m_path); | |
| if(info.isDir()) | |
| return; | |
| if((info.suffix().compare("png", Qt::CaseInsensitive) != 0)) | |
| return; | |
| int tries = 5; | |
| while(tries) | |
| { | |
| QImage image(m_path); | |
| if (image.isNull()) | |
| { | |
| QThread::sleep(500); | |
| tries--; | |
| continue; | |
| } | |
| QImage thumbnail = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation); | |
| QIcon icon(QPixmap::fromImage(thumbnail)); | |
| ((SharedIconCache &)m_cache)->add(m_path, icon); | |
| m_resultEmitter.emitResultsReady(m_path); | |
| return; | |
| } | |
| } | |
| QString m_path; | |
| SharedIconCache m_cache; | |
| ThumbnailingResult m_resultEmitter; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment