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

WTrackMenu: add and display hotkeys #4348

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ void Library::bindLibraryWidget(
pLibraryWidget->getTrackTableBackgroundColorOpacity(),
true);
pTrackTableView->installEventFilter(pKeyboard);
pTrackTableView->setKeyboardConfig(pKeyboard->getKeyboardConfig());
connect(this,
&Library::showTrackModel,
pTrackTableView,
Expand Down
2 changes: 2 additions & 0 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
WTrackMenu::WTrackMenu(
QWidget* parent,
UserSettingsPointer pConfig,
const ConfigObject<ConfigValueKbd>* pKbdConfig,
Library* pLibrary,
Features flags,
TrackModel* trackModel)
: QMenu(parent),
m_pTrackModel(trackModel),
m_pConfig(pConfig),
m_pKbdConfig(pKbdConfig),
m_pLibrary(pLibrary),
m_bPlaylistMenuLoaded(false),
m_bCrateMenuLoaded(false),
Expand Down
3 changes: 3 additions & 0 deletions src/widget/wtrackmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "library/coverart.h"
#include "library/dao/playlistdao.h"
#include "library/trackprocessing.h"
#include "preferences/configobject.h"
#include "preferences/usersettings.h"
#include "track/beats.h"
#include "track/trackref.h"
Expand Down Expand Up @@ -57,6 +58,7 @@ class WTrackMenu : public QMenu {

WTrackMenu(QWidget* parent,
UserSettingsPointer pConfig,
const ConfigObject<ConfigValueKbd>* pKbdConfig,
Library* pLibrary,
Features flags = Feature::All,
TrackModel* trackModel = nullptr);
Expand Down Expand Up @@ -273,6 +275,7 @@ class WTrackMenu : public QMenu {
QAction* m_pClearAllMetadataAction{};

const UserSettingsPointer m_pConfig;
const ConfigObject<ConfigValueKbd>* m_pKbdConfig;
Library* const m_pLibrary;

std::unique_ptr<DlgTrackInfo> m_pDlgTrackInfo;
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wtrackproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ WTrackProperty::WTrackProperty(
m_group(group),
m_pConfig(pConfig),
m_pTrackMenu(make_parented<WTrackMenu>(
this, pConfig, pLibrary, kTrackMenuFeatures)) {
this, pConfig, nullptr, pLibrary, kTrackMenuFeatures)) {
setAcceptDrops(true);
}

Expand Down
14 changes: 14 additions & 0 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ WTrackTableView::WTrackTableView(QWidget* parent,
pConfig,
kVScrollBarPosConfigKey),
m_pConfig(pConfig),
m_pKbdConfig(nullptr),
m_pLibrary(pLibrary),
m_backgroundColorOpacity(backgroundColorOpacity),
m_pFocusBorderColor(kDefaultFocusBorderColor),
Expand Down Expand Up @@ -331,6 +332,10 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel* model) {
initTrackMenu();
}

void WTrackTableView::setKeyboardConfig(const ConfigObject<ConfigValueKbd>* kbdConfig) {
m_pKbdConfig = kbdConfig;
}

void WTrackTableView::initTrackMenu() {
auto* trackModel = getTrackModel();
DEBUG_ASSERT(trackModel);
Expand All @@ -341,6 +346,7 @@ void WTrackTableView::initTrackMenu() {

m_pTrackMenu = make_parented<WTrackMenu>(this,
m_pConfig,
m_pKbdConfig,
m_pLibrary,
WTrackMenu::Feature::All,
trackModel);
Expand Down Expand Up @@ -756,6 +762,14 @@ TrackModel* WTrackTableView::getTrackModel() const {

void WTrackTableView::keyPressEvent(QKeyEvent* event) {
if (event->key() == Qt::Key_Return) {
// Ctrl+Enter opens track properties dialog
if (event->modifiers() & Qt::ControlModifier) {
QModelIndexList indices = selectionModel()->selectedRows();
if (indices.length() == 1) {
m_pTrackMenu->loadTrackModelIndices(indices);
m_pTrackMenu->slotShowDlgTrackInfo();
}
}
// It is not a good idea if 'key_return'
// causes a track to load since we allow in-line editing
// of table items in general
Expand Down
2 changes: 2 additions & 0 deletions src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class WTrackTableView : public WLibraryTableView {

public slots:
void loadTrackModel(QAbstractItemModel* model);
void setKeyboardConfig(const ConfigObject<ConfigValueKbd>* kbdConfig);
void slotMouseDoubleClicked(const QModelIndex &);
void slotUnhide();
void slotPurge();
Expand Down Expand Up @@ -94,6 +95,7 @@ class WTrackTableView : public WLibraryTableView {
void initTrackMenu();

const UserSettingsPointer m_pConfig;
const ConfigObject<ConfigValueKbd>* m_pKbdConfig;
Library* const m_pLibrary;

// Context menu container
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wtracktext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ WTrackText::WTrackText(QWidget* pParent,
m_group(group),
m_pConfig(pConfig),
m_pTrackMenu(make_parented<WTrackMenu>(
this, pConfig, pLibrary, kTrackMenuFeatures)) {
this, pConfig, nullptr, pLibrary, kTrackMenuFeatures)) {
setAcceptDrops(true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/widget/wtrackwidgetgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ WTrackWidgetGroup::WTrackWidgetGroup(QWidget* pParent,
m_pConfig(pConfig),
m_trackColorAlpha(kDefaultTrackColorAlpha),
m_pTrackMenu(make_parented<WTrackMenu>(
this, pConfig, pLibrary, kTrackMenuFeatures)) {
this, pConfig, nullptr, pLibrary, kTrackMenuFeatures)) {
setAcceptDrops(true);
}

Expand Down