diff --git a/Makefile.common b/Makefile.common index c522edea25..44d9185717 100644 --- a/Makefile.common +++ b/Makefile.common @@ -338,9 +338,9 @@ OBJ += ui/drivers/ui_qt.o \ MOC_HEADERS += ui/drivers/ui_qt.h \ ui/drivers/qt/ui_qt_load_core_window.h -DEFINES += $(QT5CORE_CFLAGS) $(QT5GUI_CFLAGS) $(QT5WIDGETS_CFLAGS) -DHAVE_MAIN +DEFINES += $(QT5CORE_CFLAGS) $(QT5GUI_CFLAGS) $(QT5WIDGETS_CFLAGS) $(QT5CONCURRENT_CFLAGS) -DHAVE_MAIN #DEFINES += $(QT5WEBENGINE_CFLAGS) -LIBS += $(QT5CORE_LIBS) $(QT5GUI_LIBS) $(QT5WIDGETS_LIBS) +LIBS += $(QT5CORE_LIBS) $(QT5GUI_LIBS) $(QT5WIDGETS_LIBS) $(QT5CONCURRENT_LIBS) #LIBS += $(QT5WEBENGINE_LIBS) NEED_CXX_LINKER = 1 diff --git a/qb/config.libs.sh b/qb/config.libs.sh index e36974ceef..509dc480fb 100644 --- a/qb/config.libs.sh +++ b/qb/config.libs.sh @@ -276,14 +276,16 @@ if [ "$HAVE_QT" != 'no' ] && [ "$MOC_PATH" != 'none' ]; then check_pkgconf QT5CORE Qt5Core 5.2 check_pkgconf QT5GUI Qt5Gui 5.2 check_pkgconf QT5WIDGETS Qt5Widgets 5.2 + check_pkgconf QT5CONCURRENT Qt5Concurrent 5.2 #check_pkgconf QT5WEBENGINE Qt5WebEngine 5.4 check_val '' QT5CORE -lQt5Core QT5CORE check_val '' QT5GUI -lQt5Gui QT5GUI check_val '' QT5WIDGETS -lQt5Widgets QT5WIDGETS + check_val '' QT5CONCURRENT -lQt5Widgets QT5CONCURRENT #check_val '' QT5WEBENGINE -lQt5WebEngine QT5WEBENGINE - if [ "$HAVE_QT5CORE" = "no" ] || [ "$HAVE_QT5GUI" = "no" ] || [ "$HAVE_QT5WIDGETS" = "no" ]; then + if [ "$HAVE_QT5CORE" = "no" ] || [ "$HAVE_QT5GUI" = "no" ] || [ "$HAVE_QT5WIDGETS" = "no" ] || [ "$HAVE_QT5CONCURRENT" = "no" ]; then die : 'Notice: Not building Qt support, required libraries were not found.' HAVE_QT=no else diff --git a/ui/drivers/qt/ui_qt_window.cpp b/ui/drivers/qt/ui_qt_window.cpp index 1261950f71..be9edf4ca2 100644 --- a/ui/drivers/qt/ui_qt_window.cpp +++ b/ui/drivers/qt/ui_qt_window.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "../ui_qt.h" #include "ui_qt_load_core_window.h" @@ -101,6 +102,16 @@ static void scan_finished_handler(void *task_data, void *user_data, const char * } #endif +GridItem::GridItem() : + widget(NULL) + ,label(NULL) + ,hash() + ,image() + ,pixmap() + ,imageWatcher() +{ +} + TreeView::TreeView(QWidget *parent) : QTreeView(parent) { @@ -2753,6 +2764,29 @@ void MainWindow::removeGridItems() } } +void MainWindow::onDeferredImageLoaded() +{ + const QFutureWatcher *watcher = static_cast*>(sender()); + GridItem *item = watcher->result(); + + if (!item->image.isNull()) + item->label->setPixmap(QPixmap::fromImage(item->image)); +} + +void MainWindow::loadImageDeferred(GridItem *item, QString path) +{ + connect(&item->imageWatcher, SIGNAL(finished()), this, SLOT(onDeferredImageLoaded()), Qt::QueuedConnection); + item->imageWatcher.setFuture(QtConcurrent::run(this, &MainWindow::doDeferredImageLoad, item, path)); +} + +GridItem* MainWindow::doDeferredImageLoad(GridItem *item, QString path) +{ + /* this runs in another thread */ + item->image = QImage(path); + + return item; +} + void MainWindow::addPlaylistItemsToGrid(QString pathString) { QList > items = getPlaylistItems(pathString); @@ -2764,7 +2798,6 @@ void MainWindow::addPlaylistItemsToGrid(QString pathString) const QHash &hash = items.at(i); GridItem *item = new GridItem(); ThumbnailLabel *label = NULL; - QPixmap pixmap; QString thumbnailFileNameNoExt; QLabel *newLabel = NULL; @@ -2779,9 +2812,7 @@ void MainWindow::addPlaylistItemsToGrid(QString pathString) label = new ThumbnailLabel(item->widget); - pixmap = QPixmap(QString(settings->paths.directory_thumbnails) + "/" + hash.value("db_name") + "/" + THUMBNAIL_BOXART + "/" + thumbnailFileNameNoExt + ".png"); - - label->setPixmap(pixmap); + item->label = label; item->widget->layout()->addWidget(label); @@ -2793,6 +2824,8 @@ void MainWindow::addPlaylistItemsToGrid(QString pathString) m_gridLayout->addWidget(item->widget); m_gridItems.append(item); + + loadImageDeferred(item, QString(settings->paths.directory_thumbnails) + "/" + hash.value("db_name") + "/" + THUMBNAIL_BOXART + "/" + thumbnailFileNameNoExt + ".png"); } } diff --git a/ui/drivers/ui_qt.h b/ui/drivers/ui_qt.h index 725196ecb0..888c6ac2f3 100644 --- a/ui/drivers/ui_qt.h +++ b/ui/drivers/ui_qt.h @@ -28,6 +28,8 @@ #include #include #include +#include +#include extern "C" { #include @@ -58,12 +60,19 @@ class QScrollArea; class LoadCoreWindow; class MainWindow; class ThumbnailWidget; +class ThumbnailLabel; class FlowLayout; struct GridItem { + GridItem(); + ThumbnailWidget *widget; + ThumbnailLabel *label; QHash hash; + QImage image; + QPixmap pixmap; + QFutureWatcher imageWatcher; }; class ThumbnailWidget : public QWidget @@ -255,6 +264,7 @@ public: bool setCustomThemeFile(QString filePath); void setCustomThemeString(QString qss); const QString& customThemeString() const; + GridItem* doDeferredImageLoad(GridItem *item, QString path); signals: void thumbnailChanged(const QPixmap &pixmap); @@ -309,6 +319,7 @@ private slots: void onFileBrowserTreeContextMenuRequested(const QPoint &pos); void onPlaylistWidgetContextMenuRequested(const QPoint &pos); void onStopClicked(); + void onDeferredImageLoaded(); private: void setCurrentCoreLabel(); @@ -316,6 +327,7 @@ private: bool isCoreLoaded(); bool isContentLessCore(); void removeGridItems(); + void loadImageDeferred(GridItem *item, QString path); QList > getPlaylistItems(QString pathString); LoadCoreWindow *m_loadCoreWindow;