Skip to content

Commit

Permalink
DlgTrackInfo/LeftRight: Conditionally enable/disable btnNext and btnPrev
Browse files Browse the repository at this point in the history
  • Loading branch information
cr7pt0gr4ph7 committed May 19, 2024
1 parent 64bd94a commit 7130149
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/library/dlgtrackinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,22 @@ void DlgTrackInfo::slotPrevDlgTagFetcher() {
loadPrevTrack();
}

QModelIndex DlgTrackInfo::getPrevNextTrack(bool next) {
return m_currentTrackIndex.sibling(
m_currentTrackIndex.row() + (next ? 1 : -1),
m_currentTrackIndex.column());
}

void DlgTrackInfo::loadNextTrack() {
auto nextRow = m_currentTrackIndex.sibling(
m_currentTrackIndex.row() + 1, m_currentTrackIndex.column());
auto nextRow = getPrevNextTrack(true);
if (nextRow.isValid()) {
loadTrack(nextRow);
emit next();
}
}

void DlgTrackInfo::loadPrevTrack() {
QModelIndex prevRow = m_currentTrackIndex.sibling(
m_currentTrackIndex.row() - 1, m_currentTrackIndex.column());
auto prevRow = getPrevNextTrack(false);
if (prevRow.isValid()) {
loadTrack(prevRow);
emit previous();
Expand Down Expand Up @@ -511,7 +515,11 @@ void DlgTrackInfo::loadTrack(const QModelIndex& index) {
return;
}
TrackPointer pTrack = m_pTrackModel->getTrack(index);

m_currentTrackIndex = index;
btnPrev->setEnabled(getPrevNextTrack(false).isValid());
btnNext->setEnabled(getPrevNextTrack(true).isValid());

loadTrackInternal(pTrack);
if (m_pDlgTagFetcher && m_pDlgTagFetcher->isVisible()) {
m_pDlgTagFetcher->loadTrack(m_currentTrackIndex);
Expand Down
1 change: 1 addition & 0 deletions src/library/dlgtrackinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
void slotReloadCoverArt();

private:
QModelIndex getPrevNextTrack(bool next);
void loadNextTrack();
void loadPrevTrack();
void loadTrackInternal(const TrackPointer& pTrack);
Expand Down

0 comments on commit 7130149

Please sign in to comment.