Skip to content

Commit

Permalink
Keyboard control in WLibrarySidebar improved
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Oct 12, 2016
1 parent 877099d commit 440d458
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 25 deletions.
8 changes: 5 additions & 3 deletions src/library/features/analysis/analysisfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&)),
Expand Down Expand Up @@ -194,9 +194,11 @@ void AnalysisFeature::tableSelectionChanged(const QItemSelection&,

bool AnalysisFeature::dropAccept(QList<QUrl> urls, QObject* pSource) {
Q_UNUSED(pSource);
QList<QFileInfo> files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true);
QList<QFileInfo> files =
DragAndDropHelper::supportedTracksFromUrls(urls, false, true);
// Adds track, does not insert duplicates, handles unremoving logic.
QList<TrackId> trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true);
QList<TrackId> trackIds =
m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true);
analyzeTracks(trackIds);
return trackIds.size() > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/features/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion src/library/features/maintenance/maintenancefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 8 additions & 4 deletions src/library/features/recording/recordingfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/library/libraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -178,8 +179,7 @@ QList<SavedSearchQuery> 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);

Expand Down
15 changes: 7 additions & 8 deletions src/library/libraryfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class LibraryFeature : public QObject {
QObject* /* pSource */) {
return false;
}
virtual bool dropAcceptChild(const QModelIndex& /* index */,
QList<QUrl> /* urls */,
QObject* /* pSource */);
virtual bool dragMoveAccept(QUrl /* url */);
virtual bool dragMoveAcceptChild(const QModelIndex& /* index */,
QUrl /* url */);
virtual bool dropAcceptChild(const QModelIndex& index,
QList<QUrl> 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.
Expand Down Expand Up @@ -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
Expand Down
95 changes: 90 additions & 5 deletions src/widget/wlibrarysidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QMimeData>
#include <QPainter>
#include <QUrl>
#include <QClipboard>

#include "library/treeitemmodel.h"
#include "util/dnd.h"
Expand Down Expand Up @@ -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) {
Expand All @@ -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<TreeItemModel*>(model());
if (!pTreeModel) {
return false;
}

const QMimeData* pMimeData = QApplication::clipboard()->mimeData();
if (!pMimeData->hasUrls()) {
return false;
}

return pTreeModel->dropAccept(destIndex, pMimeData->urls(), nullptr);
}
2 changes: 2 additions & 0 deletions src/widget/wlibrarysidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class WLibrarySidebar : public QTreeView, public WBaseWidget {
bool event(QEvent* pEvent) override;

private:
bool paste();

QBasicTimer m_expandTimer;
QModelIndex m_hoverIndex;
};
Expand Down

0 comments on commit 440d458

Please sign in to comment.