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

Tracks: focus the editing field in the track properties that corresponds to the focused column #13841

Merged
merged 2 commits into from
Dec 18, 2024
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
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
Loading