Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coverart tootip if cover is not cached #12087

Merged
merged 5 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -550,17 +557,19 @@ QVariant BaseTrackTableModel::composeCoverArtToolTipHtml(
if (!coverInfo.hasImage()) {
return QPixmap();
}
m_toolTipIndex = index;
QPixmap pixmap = CoverArtCache::getCachedCover(
coverInfo,
absoluteHeightOfCoverartToolTip);
if (pixmap.isNull()) {
// 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();
//: Tooltip text on the cover art column shown when the cover is read from disk
return tr("Fetching image ...");
}
QByteArray data;
QBuffer buffer(&data);
Expand Down Expand Up @@ -1109,3 +1118,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});
}
7 changes: 7 additions & 0 deletions src/library/basetracktablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -276,5 +281,7 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {

TrackId m_previewDeckTrackId;

mutable QModelIndex m_toolTipIndex;

static int s_bpmColumnPrecision;
};
9 changes: 6 additions & 3 deletions src/sources/metadatasourcetaglib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/test/librarytest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "test/librarytest.h"

#include "library/coverartcache.h"
#include "library/library_prefs.h"
#include "track/track.h"

Expand Down Expand Up @@ -33,6 +34,7 @@ LibraryTest::LibraryTest()
: MixxxDbTest(kInMemoryDbConnection),
m_pTrackCollectionManager(newTrackCollectionManager(config(), dbConnectionPooler())),
m_keyNotationCO(mixxx::library::prefs::kKeyNotationConfigKey) {
CoverArtCache::createInstance();
}

TrackPointer LibraryTest::getOrAddTrackByLocation(
Expand Down
4 changes: 4 additions & 0 deletions src/test/playermanagertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -61,6 +62,9 @@ class PlayerManagerTest : public MixxxDbTest, SoundSourceProviderRegistration {
m_pSoundManager = std::make_shared<SoundManager>(m_pConfig, m_pEngine.get());
m_pControlIndicatorTimer = std::make_shared<mixxx::ControlIndicatorTimer>(nullptr);
m_pEngine->registerNonEngineChannelSoundIO(m_pSoundManager.get());

CoverArtCache::createInstance();

m_pPlayerManager = std::make_shared<PlayerManager>(m_pConfig,
m_pSoundManager.get(),
m_pEffectsManager.get(),
Expand Down
28 changes: 28 additions & 0 deletions src/widget/wlibrarytableview.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "widget/wlibrarytableview.h"

#include <QApplication>
#include <QFocusEvent>
#include <QFontMetrics>
#include <QHeaderView>
#include <QHelpEvent>
#include <QScrollBar>
#include <QToolTip>

#include "moc_wlibrarytableview.cpp"
#include "util/math.h"
Expand Down Expand Up @@ -389,3 +392,28 @@ QModelIndex WLibraryTableView::moveCursor(CursorAction cursorAction,

return QTableView::moveCursor(cursorAction, modifiers);
}

void WLibraryTableView::dataChanged(
const QModelIndex& topLeft,
const QModelIndex& bottomRight,
const QVector<int>& roles) {
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(globalPos);
if (pViewPort) {
QPoint viewPortPos = pViewPort->mapFromGlobal(globalPos);
if (indexAt(viewPortPos) == topLeft) {
QHelpEvent toolTipEvent(QEvent::ToolTip,
pViewPort->mapFromGlobal(globalPos),
globalPos);
viewportEvent(&toolTipEvent);
}
}
}
}
QAbstractItemView::dataChanged(topLeft, bottomRight, roles);
};
5 changes: 5 additions & 0 deletions src/widget/wlibrarytableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>& roles = QVector<int>()) override;

signals:
void loadTrack(TrackPointer pTrack);
void loadTrackToPlayer(TrackPointer pTrack, const QString& group, bool play = false);
Expand Down
Loading