From 3de11e161709b8925a9f4e474fcae038203e6136 Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Mon, 4 Sep 2023 16:08:01 +0200 Subject: [PATCH 1/5] Improve log output. --- src/sources/metadatasourcetaglib.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/sources/metadatasourcetaglib.cpp b/src/sources/metadatasourcetaglib.cpp index 3893a42d8f7..69dc4d9bafd 100644 --- a/src/sources/metadatasourcetaglib.cpp +++ b/src/sources/metadatasourcetaglib.cpp @@ -91,14 +91,17 @@ MetadataSourceTagLib::importTrackMetadataAndCoverImage( kLogger.warning() << "Nothing to import" << "from file" << m_fileName - << "with type" << m_fileType; + << "of type" << m_fileType; return afterImport(ImportResult::Unavailable); } if (kLogger.traceEnabled()) { kLogger.trace() << "Importing" - << ((pTrackMetadata && pCoverImage) ? "track metadata and cover art" : (pTrackMetadata ? "track metadata" : "cover art")) + << ((pTrackMetadata && pCoverImage) + ? "track metadata and cover art" + : (pTrackMetadata ? "track metadata" + : "cover art")) << "from file" << m_fileName - << "with type" << m_fileType; + << "of type" << m_fileType; } // Rationale: If a file contains different types of tags only From c4e9f51271a7d17dc16f47f48ff510683b6b632f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Fri, 15 Sep 2023 16:47:04 +0200 Subject: [PATCH 2/5] Update cover tooltip after cover is cached. --- src/library/basetracktablemodel.cpp | 22 +++++++++++++++++++++- src/library/basetracktablemodel.h | 7 +++++++ src/test/librarytest.cpp | 2 ++ src/test/playermanagertest.cpp | 4 ++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/library/basetracktablemodel.cpp b/src/library/basetracktablemodel.cpp index 450eb5da5c1..081b1ac3036 100644 --- a/src/library/basetracktablemodel.cpp +++ b/src/library/basetracktablemodel.cpp @@ -133,6 +133,13 @@ BaseTrackTableModel::BaseTrackTableModel( &PlayerInfo::trackChanged, this, &BaseTrackTableModel::slotTrackChanged); + CoverArtCache* pCache = CoverArtCache::instance(); + if (pCache) { + connect(pCache, + &CoverArtCache::coverFound, + this, + &BaseTrackTableModel::slotCoverFound); + } } void BaseTrackTableModel::initTableColumnsAndHeaderProperties( @@ -550,6 +557,7 @@ QVariant BaseTrackTableModel::composeCoverArtToolTipHtml( if (!coverInfo.hasImage()) { return QPixmap(); } + m_toolTipIndex = index; QPixmap pixmap = CoverArtCache::getCachedCover( coverInfo, absoluteHeightOfCoverartToolTip); @@ -557,7 +565,7 @@ QVariant BaseTrackTableModel::composeCoverArtToolTipHtml( // Cache miss -> Don't show a tooltip, refresh cache // Height used for the width, in assumption that covers are squares CoverArtCache::requestUncachedCover( - nullptr, + this, coverInfo, absoluteHeightOfCoverartToolTip); return QVariant(); @@ -1109,3 +1117,15 @@ bool BaseTrackTableModel::updateTrackMood( return m_pTrackCollectionManager->updateTrackMood(pTrack, mood); } #endif // __EXTRA_METADATA__ + +void BaseTrackTableModel::slotCoverFound( + const QObject* pRequester, + const CoverInfo& coverInfo, + const QPixmap& pixmap) { + Q_UNUSED(pixmap); + if (pRequester != this || + getTrackLocation(m_toolTipIndex) != coverInfo.trackLocation) { + return; + } + emit dataChanged(m_toolTipIndex, m_toolTipIndex, {Qt::ToolTipRole}); +} diff --git a/src/library/basetracktablemodel.h b/src/library/basetracktablemodel.h index 70b4f1ae411..d8daf44ba22 100644 --- a/src/library/basetracktablemodel.h +++ b/src/library/basetracktablemodel.h @@ -244,6 +244,11 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel { void slotRefreshAllRows(); + void slotCoverFound( + const QObject* pRequester, + const CoverInfo& coverInfo, + const QPixmap& pixmap); + private: // Track models may reference tracks by an external id // TODO: TrackId should only be used for tracks from @@ -276,5 +281,7 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel { TrackId m_previewDeckTrackId; + mutable QModelIndex m_toolTipIndex; + static int s_bpmColumnPrecision; }; diff --git a/src/test/librarytest.cpp b/src/test/librarytest.cpp index c87a1387fc8..14ae1fc00e4 100644 --- a/src/test/librarytest.cpp +++ b/src/test/librarytest.cpp @@ -1,5 +1,6 @@ #include "test/librarytest.h" +#include "library/coverartcache.h" #include "library/library_prefs.h" #include "track/track.h" @@ -33,6 +34,7 @@ LibraryTest::LibraryTest() : MixxxDbTest(kInMemoryDbConnection), m_pTrackCollectionManager(newTrackCollectionManager(config(), dbConnectionPooler())), m_keyNotationCO(mixxx::library::prefs::kKeyNotationConfigKey) { + CoverArtCache::createInstance(); } TrackPointer LibraryTest::getOrAddTrackByLocation( diff --git a/src/test/playermanagertest.cpp b/src/test/playermanagertest.cpp index 0b3b227a18f..a4c4695d0b1 100644 --- a/src/test/playermanagertest.cpp +++ b/src/test/playermanagertest.cpp @@ -8,6 +8,7 @@ #include "engine/channels/enginedeck.h" #include "engine/enginebuffer.h" #include "engine/enginemixer.h" +#include "library/coverartcache.h" #include "library/library.h" #include "library/trackcollectionmanager.h" #include "mixer/basetrackplayer.h" @@ -61,6 +62,9 @@ class PlayerManagerTest : public MixxxDbTest, SoundSourceProviderRegistration { m_pSoundManager = std::make_shared(m_pConfig, m_pEngine.get()); m_pControlIndicatorTimer = std::make_shared(nullptr); m_pEngine->registerNonEngineChannelSoundIO(m_pSoundManager.get()); + + CoverArtCache::createInstance(); + m_pPlayerManager = std::make_shared(m_pConfig, m_pSoundManager.get(), m_pEffectsManager.get(), From eb23df97eac781466e5c701362fbd4fb487fd77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 19 Sep 2023 22:05:16 +0200 Subject: [PATCH 3/5] refresh tooltip --- src/library/basetracktablemodel.cpp | 2 +- src/widget/wlibrarytableview.cpp | 22 ++++++++++++++++++++++ src/widget/wlibrarytableview.h | 5 +++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/library/basetracktablemodel.cpp b/src/library/basetracktablemodel.cpp index 081b1ac3036..c57350458be 100644 --- a/src/library/basetracktablemodel.cpp +++ b/src/library/basetracktablemodel.cpp @@ -568,7 +568,7 @@ QVariant BaseTrackTableModel::composeCoverArtToolTipHtml( this, coverInfo, absoluteHeightOfCoverartToolTip); - return QVariant(); + return tr("Fetching image ..."); } QByteArray data; QBuffer buffer(&data); diff --git a/src/widget/wlibrarytableview.cpp b/src/widget/wlibrarytableview.cpp index f92e7c8efd6..bc097edbfaa 100644 --- a/src/widget/wlibrarytableview.cpp +++ b/src/widget/wlibrarytableview.cpp @@ -3,7 +3,9 @@ #include #include #include +#include #include +#include #include "moc_wlibrarytableview.cpp" #include "util/math.h" @@ -389,3 +391,23 @@ QModelIndex WLibraryTableView::moveCursor(CursorAction cursorAction, return QTableView::moveCursor(cursorAction, modifiers); } + +void WLibraryTableView::dataChanged( + const QModelIndex& topLeft, + const QModelIndex& bottomRight, + const QVector& roles) { + for (auto& role : roles) { + // If the tooltip is still visible update with the loaded cover. + if (role == Qt::ToolTipRole && QToolTip::isVisible()) { + QPoint globalPos = QCursor::pos(); + QWidget* pViewPort = QApplication::widgetAt(QCursor::pos()); + if (pViewPort) { + QHelpEvent toolTipEvent(QEvent::ToolTip, + pViewPort->mapFromGlobal(globalPos), + globalPos); + viewportEvent(&toolTipEvent); + } + } + } + QAbstractItemView::dataChanged(topLeft, bottomRight, roles); +}; diff --git a/src/widget/wlibrarytableview.h b/src/widget/wlibrarytableview.h index 7be8a461094..7e0e8351dd3 100644 --- a/src/widget/wlibrarytableview.h +++ b/src/widget/wlibrarytableview.h @@ -50,6 +50,11 @@ class WLibraryTableView : public QTableView, public virtual LibraryView { /// @param optional: index, otherwise row/column member vars are used void restoreCurrentIndex(const QModelIndex& index = QModelIndex()); + void dataChanged( + const QModelIndex& topLeft, + const QModelIndex& bottomRight, + const QVector& roles = QVector()) override; + signals: void loadTrack(TrackPointer pTrack); void loadTrackToPlayer(TrackPointer pTrack, const QString& group, bool play = false); From d8c49129107597b8a8f5209f09a4dbeb8d08f7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 15 Oct 2023 22:33:18 +0200 Subject: [PATCH 4/5] Add translator comment for coverart column tootip --- src/library/basetracktablemodel.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/library/basetracktablemodel.cpp b/src/library/basetracktablemodel.cpp index c57350458be..575e2dd4028 100644 --- a/src/library/basetracktablemodel.cpp +++ b/src/library/basetracktablemodel.cpp @@ -568,6 +568,7 @@ QVariant BaseTrackTableModel::composeCoverArtToolTipHtml( this, coverInfo, absoluteHeightOfCoverartToolTip); + //: Tooltip text on the cover art column shown when the cover is read from disk return tr("Fetching image ..."); } QByteArray data; From 6ba80e8891d5b75e74a5cbb96d89d8da34dc96aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Mon, 30 Oct 2023 15:07:00 +0100 Subject: [PATCH 5/5] Check if cursor is still on the tooltip index --- src/widget/wlibrarytableview.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/widget/wlibrarytableview.cpp b/src/widget/wlibrarytableview.cpp index bc097edbfaa..4964136f9d6 100644 --- a/src/widget/wlibrarytableview.cpp +++ b/src/widget/wlibrarytableview.cpp @@ -1,5 +1,6 @@ #include "widget/wlibrarytableview.h" +#include #include #include #include @@ -396,16 +397,21 @@ void WLibraryTableView::dataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector& roles) { - for (auto& role : roles) { - // If the tooltip is still visible update with the loaded cover. - if (role == Qt::ToolTipRole && QToolTip::isVisible()) { + for (const auto& role : roles) { + // Note: At this point the tooltip is already showing + // "Fetching image ..." or still in an effect progress. + // QToolTip::isVisible() is false for the later. + if (role == Qt::ToolTipRole) { QPoint globalPos = QCursor::pos(); - QWidget* pViewPort = QApplication::widgetAt(QCursor::pos()); + QWidget* pViewPort = QApplication::widgetAt(globalPos); if (pViewPort) { - QHelpEvent toolTipEvent(QEvent::ToolTip, - pViewPort->mapFromGlobal(globalPos), - globalPos); - viewportEvent(&toolTipEvent); + QPoint viewPortPos = pViewPort->mapFromGlobal(globalPos); + if (indexAt(viewPortPos) == topLeft) { + QHelpEvent toolTipEvent(QEvent::ToolTip, + pViewPort->mapFromGlobal(globalPos), + globalPos); + viewportEvent(&toolTipEvent); + } } } }