diff options
author | Be <be@mixxx.org> | 2020-04-19 03:57:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-19 03:57:50 -0500 |
commit | f1e13f93ad35dc1de34a6e8741f369cbb95bc71e (patch) | |
tree | fe75d53e8ee9300a41173fd45c0e2893cf1a7f57 /src/widget | |
parent | ed56ea0ed76afff014ad108ed491c07dc32ea219 (diff) | |
parent | 7bf740cdd4492134f78482f5e88b3430ff218758 (diff) |
Merge pull request #2541 from Holzhaus/track-colors-from-controller
Allow changing track colors from controller
Diffstat (limited to 'src/widget')
-rw-r--r-- | src/widget/wtracktableview.cpp | 97 | ||||
-rw-r--r-- | src/widget/wtracktableview.h | 2 |
2 files changed, 78 insertions, 21 deletions
diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index c50b6e56cf..c7c6742dcf 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -13,6 +13,7 @@ #include "library/trackcollection.h" #include "library/trackcollectionmanager.h" #include "mixer/playermanager.h" +#include "preferences/colorpalettesettings.h" #include "preferences/dialog/dlgpreflibrary.h" #include "sources/soundsourceproxy.h" #include "track/track.h" @@ -23,6 +24,12 @@ #include "widget/wtrackmenu.h" #include "widget/wtracktableviewheader.h" +namespace { + +const ConfigKey kConfigKeyAllowTrackLoadToPlayingDeck("[Controls]", "AllowTrackLoadToPlayingDeck"); + +} + WTrackTableView::WTrackTableView(QWidget* parent, UserSettingsPointer pConfig, TrackCollectionManager* pTrackCollectionManager, @@ -39,8 +46,7 @@ WTrackTableView::WTrackTableView(QWidget* parent, m_selectionChangedSinceLastGuiTick(true), m_loadCachedOnly(false) { // Connect slots and signals to make the world go 'round. - connect(this, &WTrackTableView::doubleClicked, - this, &WTrackTableView::slotMouseDoubleClicked); + connect(this, &WTrackTableView::doubleClicked, this, &WTrackTableView::slotMouseDoubleClicked); m_pCOTGuiTick = new ControlProxy("[Master]", "guiTick50ms", this); m_pCOTGuiTick->connectValueChanged(this, &WTrackTableView::slotGuiTick50ms); @@ -53,13 +59,17 @@ WTrackTableView::WTrackTableView(QWidget* parent, m_pSortOrder = new ControlProxy("[Library]", "sort_order", this); m_pSortOrder->connectValueChanged(this, &WTrackTableView::applySortingIfVisible); - connect(this, &WTrackTableView::scrollValueChanged, - this, &WTrackTableView::slotScrollValueChanged); + connect(this, + &WTrackTableView::scrollValueChanged, + this, + &WTrackTableView::slotScrollValueChanged); - QShortcut *setFocusShortcut = new QShortcut( - QKeySequence(tr("ESC", "Focus")), this); - connect(setFocusShortcut, &QShortcut::activated, - this, qOverload<>(&WTrackTableView::setFocus)); + QShortcut* setFocusShortcut = + new QShortcut(QKeySequence(tr("ESC", "Focus")), this); + connect(setFocusShortcut, + &QShortcut::activated, + this, + qOverload<>(&WTrackTableView::setFocus)); } WTrackTableView::~WTrackTableView() { @@ -84,8 +94,8 @@ void WTrackTableView::slotScrollValueChanged(int /*unused*/) { enableCachedOnly(); } -void WTrackTableView::selectionChanged(const QItemSelection& selected, - const QItemSelection& deselected) { +void WTrackTableView::selectionChanged( + const QItemSelection& selected, const QItemSelection& deselected) { m_selectionChangedSinceLastGuiTick = true; enableCachedOnly(); QTableView::selectionChanged(selected, deselected); @@ -96,7 +106,6 @@ void WTrackTableView::slotGuiTick50ms(double /*unused*/) { // we load un-cached cover arts as well. mixxx::Duration timeDelta = mixxx::Time::elapsed() - m_lastUserAction; if (m_loadCachedOnly && timeDelta > mixxx::Duration::fromMillis(100)) { - // Show the currently selected track in the large cover art view and // highlights crate and playlists. Doing this in selectionChanged // slows down scrolling performance so we wait until the user has @@ -127,7 +136,7 @@ void WTrackTableView::slotGuiTick50ms(double /*unused*/) { } // slot -void WTrackTableView::loadTrackModel(QAbstractItemModel *model) { +void WTrackTableView::loadTrackModel(QAbstractItemModel* model) { qDebug() << "WTrackTableView::loadTrackModel()" << model; TrackModel* trackModel = dynamic_cast<TrackModel*>(model); @@ -148,9 +157,10 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel *model) { if (getTrackModel() == trackModel) { // Re-sort the table even if the track model is the same. This triggers // a select() if the table is dirty. - doSortByColumn(horizontalHeader()->sortIndicatorSection(), horizontalHeader()->sortIndicatorOrder()); + doSortByColumn(horizontalHeader()->sortIndicatorSection(), + horizontalHeader()->sortIndicatorOrder()); return; - }else{ + } else { newModel = trackModel; saveVScrollBarPos(getTrackModel()); //saving current vertical bar position @@ -208,7 +218,8 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel *model) { // Initialize all column-specific things for (int i = 0; i < model->columnCount(); ++i) { // Setup delegates according to what the model tells us - QAbstractItemDelegate* delegate = trackModel->delegateForColumn(i, this); + QAbstractItemDelegate* delegate = + trackModel->delegateForColumn(i, this); // We need to delete the old delegates, since the docs say the view will // not take ownership of them. QAbstractItemDelegate* old_delegate = itemDelegateForColumn(i); @@ -227,7 +238,7 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel *model) { * key column by default unless the user brings it to front */ if (trackModel->isColumnHiddenByDefault(i) && - !header->hasPersistedHeaderState()) { + !header->hasPersistedHeaderState()) { //qDebug() << "Hiding column" << i; horizontalHeader()->hideSection(i); } @@ -238,8 +249,11 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel *model) { // But Qt::UniqueConnections do not work for lambdas, non-member functions // and functors; they only apply to connecting to member functions. // https://doc.qt.io/qt-5/qobject.html#connect - connect(horizontalHeader(), &QHeaderView::sortIndicatorChanged, - this, &WTrackTableView::slotSortingChanged, Qt::AutoConnection); + connect(horizontalHeader(), + &QHeaderView::sortIndicatorChanged, + this, + &WTrackTableView::slotSortingChanged, + Qt::AutoConnection); int sortColumn; Qt::SortOrder sortOrder; @@ -350,6 +364,48 @@ void WTrackTableView::slotMouseDoubleClicked(const QModelIndex& index) { } } +void WTrackTableView::assignPreviousTrackColor() { + QModelIndexList indices = selectionModel()->selectedRows(); + if (indices.size() <= 0) { + return; + } + + TrackModel* trackModel = getTrackModel(); + if (!trackModel) { + return; + } + + QModelIndex index = indices.at(0); + TrackPointer pTrack = trackModel->getTrack(index); + if (pTrack) { + ColorPaletteSettings colorPaletteSettings(m_pConfig); + ColorPalette colorPalette = colorPaletteSettings.getTrackColorPalette(); + mixxx::RgbColor::optional_t color = pTrack->getColor(); + pTrack->setColor(colorPalette.previousColor(color)); + } +} + +void WTrackTableView::assignNextTrackColor() { + QModelIndexList indices = selectionModel()->selectedRows(); + if (indices.size() <= 0) { + return; + } + + TrackModel* trackModel = getTrackModel(); + if (!trackModel) { + return; + } + + QModelIndex index = indices.at(0); + TrackPointer pTrack = trackModel->getTrack(index); + if (pTrack) { + ColorPaletteSettings colorPaletteSettings(m_pConfig); + ColorPalette colorPalette = colorPaletteSettings.getTrackColorPalette(); + mixxx::RgbColor::optional_t color = pTrack->getColor(); + pTrack->setColor(colorPalette.nextColor(color)); + } +} + void WTrackTableView::slotPurge() { QModelIndexList indices = selectionModel()->selectedRows(); if (indices.size() > 0) { @@ -771,9 +827,8 @@ void WTrackTableView::doSortByColumn(int headerSection, Qt::SortOrder sortOrder) QItemSelectionModel* currentSelection = selectionModel(); currentSelection->reset(); // remove current selection - QMap<int,int> selectedRows; + QMap<int, int> selectedRows; for (const auto& trackId : selectedTrackIds) { - // TODO(rryan) slowly fixing the issues with BaseSqlTableModel. This // code is broken for playlists because it assumes each trackid is in // the table once. This will erroneously select all instances of the @@ -790,7 +845,7 @@ void WTrackTableView::doSortByColumn(int headerSection, Qt::SortOrder sortOrder) } QModelIndex first; - QMapIterator<int,int> i(selectedRows); + QMapIterator<int, int> i(selectedRows); while (i.hasNext()) { i.next(); QModelIndex tl = itemModel->index(i.key(), 0); diff --git a/src/widget/wtracktableview.h b/src/widget/wtracktableview.h index 4ec2d68017..3d7a41dfd0 100644 --- a/src/widget/wtracktableview.h +++ b/src/widget/wtracktableview.h @@ -38,6 +38,8 @@ class WTrackTableView : public WLibraryTableView { void onShow() override; bool hasFocus() const override; void keyPressEvent(QKeyEvent* event) override; + void assignNextTrackColor() override; + void assignPreviousTrackColor() override; QList<TrackId> getSelectedTrackIds() const; void setSelectedTracks(const QList<TrackId>& tracks); void saveCurrentVScrollBarPos(); |