Skip to content

Commit

Permalink
Merge pull request #13841 from ronso0/track-info-focus-clicked-table-…
Browse files Browse the repository at this point in the history
…item

Tracks: focus the editing field in the track properties that corresponds to the focused column
  • Loading branch information
daschuer authored Dec 18, 2024
2 parents f4630e4 + cb61192 commit a34760b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 18 deletions.
13 changes: 0 additions & 13 deletions src/library/dlgtrackinfo.ui
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,6 @@
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
Expand Down
26 changes: 26 additions & 0 deletions src/library/dlgtrackinfomulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ void DlgTrackInfoMulti::init() {
setupUi(this);
setWindowIcon(QIcon(MIXXX_ICON_PATH));

// Store tag edit widget pointers to allow focusing a specific widgets when
// this is opened by double-clicking a WTrackProperty label.
// Associate with property strings taken from library/dao/trackdao.h
m_propertyWidgets.insert("artist", txtArtist);
m_propertyWidgets.insert("title", txtTitle);
m_propertyWidgets.insert("titleInfo", txtTitle);
m_propertyWidgets.insert("album", txtAlbum);
m_propertyWidgets.insert("album_artist", txtAlbumArtist);
m_propertyWidgets.insert("composer", txtComposer);
m_propertyWidgets.insert("genre", txtGenre);
m_propertyWidgets.insert("year", txtYear);
m_propertyWidgets.insert("tracknumber", txtTrackNumber);
m_propertyWidgets.insert("key", txtKey);
m_propertyWidgets.insert("grouping", txtGrouping);
m_propertyWidgets.insert("comment", txtComment);

// QDialog buttons
connect(btnApply,
&QPushButton::clicked,
Expand Down Expand Up @@ -308,6 +324,16 @@ void DlgTrackInfoMulti::loadTracks(const QList<TrackPointer>& pTracks) {
connectTracksChanged();
}

void DlgTrackInfoMulti::focusField(const QString& property) {
if (property.isEmpty()) {
return;
}
auto it = m_propertyWidgets.constFind(property);
if (it != m_propertyWidgets.constEnd()) {
it.value()->setFocus();
}
}

void DlgTrackInfoMulti::updateFromTracks() {
const QSignalBlocker signalBlocker(this);

Expand Down
3 changes: 3 additions & 0 deletions src/library/dlgtrackinfomulti.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DlgTrackInfoMulti : public QDialog, public Ui::DlgTrackInfoMulti {
~DlgTrackInfoMulti() override = default;

void loadTracks(const QList<TrackPointer>& pTracks);
void focusField(const QString& property);

/// We need this to set the max width of the comment QComboBox which has
/// issues with long lines / multi-line content. See init() for details.
Expand Down Expand Up @@ -107,6 +108,8 @@ class DlgTrackInfoMulti : public QDialog, public Ui::DlgTrackInfoMulti {
QHash<TrackId, TrackPointer> m_pLoadedTracks;
QList<mixxx::TrackRecord> m_trackRecords;

QHash<QString, QWidget*> m_propertyWidgets;

parented_ptr<WCoverArtMenu> m_pWCoverArtMenu;
parented_ptr<WCoverArtLabel> m_pWCoverArtLabel;
parented_ptr<WStarRating> m_pWStarRating;
Expand Down
16 changes: 14 additions & 2 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2588,8 +2588,20 @@ void WTrackMenu::showDlgTrackInfo(const QString& property) {
return;
}
slotShowDlgTrackInfo();
if (m_pDlgTrackInfo->isVisible()) {
m_pDlgTrackInfo->focusField(property);
if (m_pTrackModel && getTrackCount() > 1) {
VERIFY_OR_DEBUG_ASSERT(m_pDlgTrackInfoMulti) {
return;
}
if (m_pDlgTrackInfoMulti->isVisible()) {
m_pDlgTrackInfoMulti->focusField(property);
}
} else {
VERIFY_OR_DEBUG_ASSERT(m_pDlgTrackInfo) {
return;
}
if (m_pDlgTrackInfo->isVisible()) {
m_pDlgTrackInfo->focusField(property);
}
}
}

Expand Down
19 changes: 16 additions & 3 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,10 +1079,23 @@ void WTrackTableView::keyPressEvent(QKeyEvent* event) {
if (indices.isEmpty()) {
return;
}
// TODO Also pass the index of the focused column so DlgTrackInfo/~Multi
// can focus the respective edit field.
m_pTrackMenu->loadTrackModelIndices(indices);
m_pTrackMenu->slotShowDlgTrackInfo();
// Pass the name of the focused column to DlgTrackInfo/~Multi
// so they can focus the respective edit field.
// We use the column of the current index (last focus cell), even
// it may not be part of the selection, we just assume it's in the
// desired column.
const auto currIdx = currentIndex();
if (currIdx.isValid()) {
const QString columnName = model()->headerData(
currIdx.column(),
Qt::Horizontal,
TrackModel::kHeaderNameRole)
.toString();
m_pTrackMenu->showDlgTrackInfo(columnName);
} else {
m_pTrackMenu->slotShowDlgTrackInfo();
}
}
return;
}
Expand Down

0 comments on commit a34760b

Please sign in to comment.