From 440d458a2c2cd35b7d00065c6a7007db2ffa17fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 12 Oct 2016 22:05:24 +0200 Subject: [PATCH] Keyboard control in WLibrarySidebar improved --- .../features/analysis/analysisfeature.cpp | 8 +- src/library/features/autodj/autodjfeature.cpp | 2 +- .../maintenance/maintenancefeature.cpp | 3 +- .../features/recording/recordingfeature.cpp | 12 ++- src/library/libraryfeature.cpp | 6 +- src/library/libraryfeature.h | 15 ++- src/widget/wlibrarysidebar.cpp | 95 ++++++++++++++++++- src/widget/wlibrarysidebar.h | 2 + 8 files changed, 118 insertions(+), 25 deletions(-) diff --git a/src/library/features/analysis/analysisfeature.cpp b/src/library/features/analysis/analysisfeature.cpp index cd0a63975af..222dae67661 100644 --- a/src/library/features/analysis/analysisfeature.cpp +++ b/src/library/features/analysis/analysisfeature.cpp @@ -61,7 +61,7 @@ QString AnalysisFeature::getSettingsName() const { } QWidget* AnalysisFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, int paneId) { - WTrackTableView* pTable = createTableWidget(pKeyboard, paneId); + WTrackTableView* pTable = createTableWidget(paneId); pTable->loadTrackModel(getAnalysisTableModel()); connect(pTable->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), @@ -194,9 +194,11 @@ void AnalysisFeature::tableSelectionChanged(const QItemSelection&, bool AnalysisFeature::dropAccept(QList urls, QObject* pSource) { Q_UNUSED(pSource); - QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); + QList files = + DragAndDropHelper::supportedTracksFromUrls(urls, false, true); // Adds track, does not insert duplicates, handles unremoving logic. - QList trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true); + QList trackIds = + m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true); analyzeTracks(trackIds); return trackIds.size() > 0; } diff --git a/src/library/features/autodj/autodjfeature.cpp b/src/library/features/autodj/autodjfeature.cpp index 9834d1f2575..0b508fe073a 100644 --- a/src/library/features/autodj/autodjfeature.cpp +++ b/src/library/features/autodj/autodjfeature.cpp @@ -101,7 +101,7 @@ QString AutoDJFeature::getSettingsName() const { } QWidget* AutoDJFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, int paneId) { - WTrackTableView* pTrackTableView = createTableWidget(pKeyboard, paneId); + WTrackTableView* pTrackTableView = createTableWidget(paneId); pTrackTableView->loadTrackModel(m_pAutoDJProcessor->getTableModel()); connect(pTrackTableView->selectionModel(), diff --git a/src/library/features/maintenance/maintenancefeature.cpp b/src/library/features/maintenance/maintenancefeature.cpp index d4b8fe7fba4..5d42030d3b5 100644 --- a/src/library/features/maintenance/maintenancefeature.cpp +++ b/src/library/features/maintenance/maintenancefeature.cpp @@ -104,7 +104,8 @@ QWidget* MaintenanceFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyb QWidget* MaintenanceFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, int paneId) { - WTrackTableView* pTable = LibraryFeature::createTableWidget(pKeyboard, paneId); + Q_UNUSED(pKeyboard); + WTrackTableView* pTable = LibraryFeature::createTableWidget(paneId); return pTable; } diff --git a/src/library/features/recording/recordingfeature.cpp b/src/library/features/recording/recordingfeature.cpp index f9900ef68ac..9afb871d8c6 100644 --- a/src/library/features/recording/recordingfeature.cpp +++ b/src/library/features/recording/recordingfeature.cpp @@ -47,13 +47,16 @@ TreeItemModel* RecordingFeature::getChildModel() { return &m_childModel; } -QWidget* RecordingFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, int paneId) { - WTrackTableView* pTable = LibraryFeature::createTableWidget(pKeyboard, paneId); +QWidget* RecordingFeature::createPaneWidget( + KeyboardEventFilter* pKeyboard, int paneId) { + Q_UNUSED(pKeyboard); + WTrackTableView* pTable = LibraryFeature::createTableWidget(paneId); pTable->setSorting(false); return pTable; } -QWidget *RecordingFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) { +QWidget *RecordingFeature::createInnerSidebarWidget( + KeyboardEventFilter* pKeyboard) { m_pRecordingView = new DlgRecording(nullptr, m_pTrackCollection, m_pRecordingManager); @@ -79,7 +82,8 @@ void RecordingFeature::activate() { BrowseTableModel* RecordingFeature::getBrowseTableModel() { if (m_pBrowseModel.isNull()) { - m_pBrowseModel = new BrowseTableModel(this, m_pTrackCollection, m_pRecordingManager); + m_pBrowseModel = new BrowseTableModel( + this, m_pTrackCollection, m_pRecordingManager); } return m_pBrowseModel; diff --git a/src/library/libraryfeature.cpp b/src/library/libraryfeature.cpp index 3b52297d678..c09335854ac 100644 --- a/src/library/libraryfeature.cpp +++ b/src/library/libraryfeature.cpp @@ -69,7 +69,8 @@ bool LibraryFeature::dragMoveAcceptChild(const QModelIndex &, QUrl) { QWidget* LibraryFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, int paneId) { - return createTableWidget(pKeyboard, paneId); + Q_UNUSED(pKeyboard); + return createTableWidget(paneId); } QWidget *LibraryFeature::createSidebarWidget(KeyboardEventFilter* pKeyboard) { @@ -178,8 +179,7 @@ QList LibraryFeature::getSavedQueries() const { return m_savedDAO.getSavedQueries(this); } -WTrackTableView* LibraryFeature::createTableWidget(KeyboardEventFilter* pKeyboard, - int paneId) { +WTrackTableView* LibraryFeature::createTableWidget(int paneId) { WTrackTableView* pTrackTableView = new WTrackTableView(nullptr, m_pConfig, m_pTrackCollection, true); diff --git a/src/library/libraryfeature.h b/src/library/libraryfeature.h index 33f857708b2..6a4104f1331 100644 --- a/src/library/libraryfeature.h +++ b/src/library/libraryfeature.h @@ -51,12 +51,12 @@ class LibraryFeature : public QObject { QObject* /* pSource */) { return false; } - virtual bool dropAcceptChild(const QModelIndex& /* index */, - QList /* urls */, - QObject* /* pSource */); - virtual bool dragMoveAccept(QUrl /* url */); - virtual bool dragMoveAcceptChild(const QModelIndex& /* index */, - QUrl /* url */); + virtual bool dropAcceptChild(const QModelIndex& index, + QList urls, + QObject* pSource); + virtual bool dragMoveAccept(QUrl url); + virtual bool dragMoveAcceptChild(const QModelIndex& index, + QUrl url); // Reimplement this to register custom views with the library widget // at the right pane. @@ -131,8 +131,7 @@ class LibraryFeature : public QObject { } // Creates a table widget with no model - WTrackTableView* createTableWidget(KeyboardEventFilter* pKeyboard, - int paneId); + WTrackTableView* createTableWidget(int paneId); // Creates a WLibrarySidebar widget with the getChildModel() function as // model diff --git a/src/widget/wlibrarysidebar.cpp b/src/widget/wlibrarysidebar.cpp index e8d6e001f79..70b148fd523 100644 --- a/src/widget/wlibrarysidebar.cpp +++ b/src/widget/wlibrarysidebar.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "library/treeitemmodel.h" #include "util/dnd.h" @@ -198,13 +199,72 @@ void WLibrarySidebar::toggleSelectedItem() { } void WLibrarySidebar::keyPressEvent(QKeyEvent* event) { - if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { + qDebug() << "WLibrarySidebar::keyPressEvent" << event; + if (event == QKeySequence::Copy) { + event->ignore(); + } else if (event == QKeySequence::Paste) { + if (paste()) { + event->accept(); + } else { + event->ignore(); + } + } else if (event == QKeySequence::Cut) { + // TODO(XXX) allow delete by key but with a safety pop up + // or an undo feature + event->ignore(); + } else if (event == QKeySequence::SelectAll) { + selectAll(); + event->accept(); + } else if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && + event->modifiers() == Qt::NoModifier) { toggleSelectedItem(); - return; - } + event->accept(); + } else if (event == QKeySequence::Delete) { + // TODO(XXX) allow delete by key but with a safety pop up + // or an undo feature + event->ignore(); + } else { + // QTreeView::keyPressEvent(event) will consume all key events due to + // it's keyboardSearch feature. + // In Mixxx, we prefer that most keyboard mappings are working, so we + // pass only some basic keys to the base class + if (event->modifiers() == Qt::NoModifier) { + switch (event->key()) { + case Qt::Key_Down: + case Qt::Key_Up: + case Qt::Key_Left: + case Qt::Key_Right: + case Qt::Key_Home: + case Qt::Key_End: + case Qt::Key_PageUp: + case Qt::Key_PageDown: + case Qt::Key_Tab: + case Qt::Key_Backtab: + case Qt::Key_Space: + case Qt::Key_Select: + case Qt::Key_F2: + QTreeView::keyPressEvent(event); + break; - // Fall through to default handler. - QTreeView::keyPressEvent(event); + // Ignored even though used in default QT: + case Qt::Key_Asterisk: + case Qt::Key_Plus: + case Qt::Key_Minus: + default: + event->ignore(); + } + } else if (event->modifiers() == Qt::SHIFT) { + switch (event->key()) { + case Qt::Key_Tab: + QTreeView::keyPressEvent(event); + break; + default: + event->ignore(); + } + } else { + event->ignore(); + } + } } void WLibrarySidebar::selectIndex(const QModelIndex& index) { @@ -228,3 +288,28 @@ bool WLibrarySidebar::event(QEvent* pEvent) { void WLibrarySidebar::slotSetFont(const QFont& font) { setFont(font); } + +bool WLibrarySidebar::paste() { + qDebug() << "WTrackTableView::paste()" + << QApplication::clipboard()->mimeData()->formats(); + + QModelIndex destIndex; + QModelIndexList indexes = selectionModel()->selectedRows(); + if (indexes.size() > 0) { + destIndex = indexes.at(0); + } else { + destIndex = currentIndex(); + } + + TreeItemModel* pTreeModel = qobject_cast(model()); + if (!pTreeModel) { + return false; + } + + const QMimeData* pMimeData = QApplication::clipboard()->mimeData(); + if (!pMimeData->hasUrls()) { + return false; + } + + return pTreeModel->dropAccept(destIndex, pMimeData->urls(), nullptr); +} diff --git a/src/widget/wlibrarysidebar.h b/src/widget/wlibrarysidebar.h index 26e0852405b..8d79cc9ab2d 100644 --- a/src/widget/wlibrarysidebar.h +++ b/src/widget/wlibrarysidebar.h @@ -49,6 +49,8 @@ class WLibrarySidebar : public QTreeView, public WBaseWidget { bool event(QEvent* pEvent) override; private: + bool paste(); + QBasicTimer m_expandTimer; QModelIndex m_hoverIndex; };