diff --git a/res/skins/Deere/style.qss b/res/skins/Deere/style.qss index d4a8650886a..7ccb32c83cb 100644 --- a/res/skins/Deere/style.qss +++ b/res/skins/Deere/style.qss @@ -247,11 +247,14 @@ WTrackTableView, WTrackTableView QCheckBox:focus { outline: 1px solid #D6D6D6; } -/* This uses a custom qproperty to set the focus border - for Color and Cover Art cells, 1px solid, sharp corners. - See src/library/tableitemdelegate.cpp */ WTrackTableView { + /* This uses a custom qproperty to set the focus border + for Color and Cover Art cells, 1px solid, sharp corners. + See src/library/tableitemdelegate.cpp */ qproperty-focusBorderColor: #D6D6D6; + /* This is the color used to paint the text of played tracks. + BaseTrackTableModel::data() uses this to override Qt::ForegroundRole (QBrush). */ + qproperty-playedInactiveColor: #555; } WTrackTableView:focus, diff --git a/res/skins/LateNight/style_classic.qss b/res/skins/LateNight/style_classic.qss index 4c801032391..399670ccdcf 100644 --- a/res/skins/LateNight/style_classic.qss +++ b/res/skins/LateNight/style_classic.qss @@ -2119,7 +2119,13 @@ WTrackTableView QCheckBox:focus { for Color and Cover Art cells, 1px solid, sharp corners. See src/library/tableitemdelegate.cpp */ WTrackTableView { + /* This uses a custom qproperty to set the focus border + for Color and Cover Art cells, 1px solid, sharp corners. + See src/library/tableitemdelegate.cpp */ qproperty-focusBorderColor: #fff; + /* This is the color used to paint the text of played tracks. + BaseTrackTableModel::data() uses this to override Qt::ForegroundRole (QBrush). */ + qproperty-playedInactiveColor: #555; } WLibrarySidebar { diff --git a/res/skins/LateNight/style_palemoon.qss b/res/skins/LateNight/style_palemoon.qss index 72c0fa1e5d8..6df668c7f35 100644 --- a/res/skins/LateNight/style_palemoon.qss +++ b/res/skins/LateNight/style_palemoon.qss @@ -2586,11 +2586,14 @@ WTrackTableView, WTrackTableView QCheckBox:focus { outline: 1px solid #fff; } -/* This uses a custom qproperty to set the focus border - for Color and Cover Art cells, 1px solid, sharp corners. - See src/library/tableitemdelegate.cpp */ WTrackTableView { + /* This uses a custom qproperty to set the focus border + for Color and Cover Art cells, 1px solid, sharp corners. + See src/library/tableitemdelegate.cpp */ qproperty-focusBorderColor: #fff; + /* This is the color used to paint the text of played tracks. + BaseTrackTableModel::data() uses this to override Qt::ForegroundRole (QBrush). */ + qproperty-playedInactiveColor: #555; } /* Table cell in edit mode */ diff --git a/res/skins/Shade/style.qss b/res/skins/Shade/style.qss index 7fbb6c1a0a1..6ed3034ae89 100644 --- a/res/skins/Shade/style.qss +++ b/res/skins/Shade/style.qss @@ -508,7 +508,13 @@ WTrackTableView QCheckBox:focus { for Color and Cover Art cells, 1px solid, sharp corners. See src/library/tableitemdelegate.cpp */ WTrackTableView { + /* This uses a custom qproperty to set the focus border + for Color and Cover Art cells, 1px solid, sharp corners. + See src/library/tableitemdelegate.cpp */ qproperty-focusBorderColor: #c9c9c9; + /* This is the color used to paint the text of played tracks. + BaseTrackTableModel::data() uses this to override Qt::ForegroundRole (QBrush). */ + qproperty-playedInactiveColor: #555; } /* Table cell in edit mode */ diff --git a/res/skins/Shade/style_dark.qss b/res/skins/Shade/style_dark.qss index f981c2ec60d..c3d3bf20591 100644 --- a/res/skins/Shade/style_dark.qss +++ b/res/skins/Shade/style_dark.qss @@ -195,7 +195,13 @@ WTrackTableView QCheckBox:focus { for Color and Cover Art cells, 1px solid, sharp corners. See src/library/tableitemdelegate.cpp */ WTrackTableView { + /* This uses a custom qproperty to set the focus border + for Color and Cover Art cells, 1px solid, sharp corners. + See src/library/tableitemdelegate.cpp */ qproperty-focusBorderColor: #ccc; + /* This is the color used to paint the text of played tracks. + BaseTrackTableModel::data() uses this to override Qt::ForegroundRole (QBrush). */ + qproperty-playedInactiveColor: #555; } /* Table cell in edit mode */ diff --git a/res/skins/Tango/style.qss b/res/skins/Tango/style.qss index f0ba9dea72a..81970c2b83c 100644 --- a/res/skins/Tango/style.qss +++ b/res/skins/Tango/style.qss @@ -2598,7 +2598,13 @@ WTrackTableView QCheckBox:focus { for Color and Cover Art cells, 1px solid, sharp corners. See src/library/tableitemdelegate.cpp */ WTrackTableView { + /* This uses a custom qproperty to set the focus border + for Color and Cover Art cells, 1px solid, sharp corners. + See src/library/tableitemdelegate.cpp */ qproperty-focusBorderColor: #fff; + /* This is the color used to paint the text of played tracks. + BaseTrackTableModel::data() uses this to override Qt::ForegroundRole (QBrush). */ + qproperty-playedInactiveColor: #555; } /* Table cell in edit mode */ diff --git a/src/library/basetracktablemodel.cpp b/src/library/basetracktablemodel.cpp index 575e2dd4028..dcd4e594dc1 100644 --- a/src/library/basetracktablemodel.cpp +++ b/src/library/basetracktablemodel.cpp @@ -124,7 +124,8 @@ BaseTrackTableModel::BaseTrackTableModel( TrackModel(cloneDatabase(pTrackCollectionManager), settingsNamespace), m_pTrackCollectionManager(pTrackCollectionManager), m_previewDeckGroup(PlayerManager::groupForPreviewDeck(0)), - m_backgroundColorOpacity(WLibrary::kDefaultTrackTableBackgroundColorOpacity) { + m_backgroundColorOpacity(WLibrary::kDefaultTrackTableBackgroundColorOpacity), + m_playedInactiveColor(QColor::fromRgb(WTrackTableView::kDefaultPlayedInactiveColorHex)) { connect(&pTrackCollectionManager->internalCollection()->getTrackDAO(), &TrackDAO::forceModelUpdate, this, @@ -395,6 +396,15 @@ QAbstractItemDelegate* BaseTrackTableModel::delegateForColumn( return nullptr; } m_backgroundColorOpacity = pTableView->getBackgroundColorOpacity(); + // This is the color used for the text of played tracks. + // data() uses this to compose the ForegroundRole QBrush if 'played' is checked. + m_playedInactiveColor = pTableView->getPlayedInactiveColor(); + connect(pTableView, + &WTrackTableView::playedInactiveColorChanged, + this, + [this](QColor col) { + m_playedInactiveColor = col; + }); if (index == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_RATING)) { return new StarDelegate(pTableView); } else if (index == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM)) { @@ -447,6 +457,16 @@ QVariant BaseTrackTableModel::data( DEBUG_ASSERT(m_backgroundColorOpacity <= 1.0); bgColor.setAlphaF(static_cast(m_backgroundColorOpacity)); return QBrush(bgColor); + } else if (role == Qt::ForegroundRole) { + // Custom text color for played tracks + auto playedRaw = rawSiblingValue( + index, + ColumnCache::COLUMN_LIBRARYTABLE_PLAYED); + if (!playedRaw.isNull() && + playedRaw.canConvert() && + playedRaw.toBool()) { + return QVariant::fromValue(m_playedInactiveColor); + } } // Only retrieve a value for supported roles diff --git a/src/library/basetracktablemodel.h b/src/library/basetracktablemodel.h index d8daf44ba22..0df6297109e 100644 --- a/src/library/basetracktablemodel.h +++ b/src/library/basetracktablemodel.h @@ -268,6 +268,7 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel { const QString m_previewDeckGroup; double m_backgroundColorOpacity; + QColor m_playedInactiveColor; ColumnCache m_columnCache; diff --git a/src/library/bpmdelegate.cpp b/src/library/bpmdelegate.cpp index c689a031293..f5102df2f7f 100644 --- a/src/library/bpmdelegate.cpp +++ b/src/library/bpmdelegate.cpp @@ -81,6 +81,28 @@ void BPMDelegate::paintItem(QPainter* painter,const QStyleOptionViewItem &option QStyleOptionViewItem opt = option; initStyleOption(&opt, index); + // The checkbox uses the QTableView's qss style, therefore it's not picking + // up the 'played' text color via ForegroundRole from BaseTrackTableModel::data(). + // Enforce it with an explicit stylesheet. Note: the stylesheet persists so + // we need to reset it to normal/highlighted. + QColor textColor; + auto dat = index.data(Qt::ForegroundRole); + if (dat.canConvert()) { + textColor = dat.value(); + } else { + if (option.state & QStyle::State_Selected) { + textColor = option.palette.color(QPalette::Normal, QPalette::HighlightedText); + } else { + textColor = option.palette.color(QPalette::Normal, QPalette::Text); + // qWarning() << " !! BPM col:" << textColor.name(QColor::HexRgb); + } + } + if (textColor.isValid()) { + m_pCheckBox->setStyleSheet(QStringLiteral( + "#LibraryBPMButton::item { color: %1; }") + .arg(textColor.name(QColor::HexRgb))); + } + QStyle* style = m_pTableView->style(); if (style != nullptr) { style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, m_pCheckBox); diff --git a/src/library/tableitemdelegate.cpp b/src/library/tableitemdelegate.cpp index c1c6ff4b187..f044e4a664c 100644 --- a/src/library/tableitemdelegate.cpp +++ b/src/library/tableitemdelegate.cpp @@ -48,7 +48,20 @@ void TableItemDelegate::paint( if (option.state & QStyle::State_Selected) { painter->setBrush(option.palette.color(cg, QPalette::HighlightedText)); } else { - painter->setBrush(option.palette.color(cg, QPalette::Text)); + // This gets the custom 'played' text color from BaseTrackTableModel + // depending on check state of the 'played' column. + // Note that we need to do this again in BPMDelegate which uses the + // style of the TableView. + auto playedColorData = index.data(Qt::ForegroundRole); + if (playedColorData.canConvert()) { + QColor playedColor = playedColorData.value(); + // for the star rating polygons + painter->setBrush(playedColor); + // for the 'location' text + painter->setPen(playedColor); + } else { + painter->setBrush(option.palette.color(cg, QPalette::Text)); + } } QStyle* style = m_pTableView->style(); diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index 2fcdfde7b68..0332b90fe4b 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -51,6 +51,7 @@ WTrackTableView::WTrackTableView(QWidget* parent, m_backgroundColorOpacity(backgroundColorOpacity), // Default color for the focus border of TableItemDelegates m_focusBorderColor(Qt::white), + m_playedInactiveColor(QColor::fromRgb(kDefaultPlayedInactiveColorHex)), m_sorting(sorting), m_selectionChangedSinceLastGuiTick(true), m_loadCachedOnly(false) { diff --git a/src/widget/wtracktableview.h b/src/widget/wtracktableview.h index 257a94441bb..a786f0d43c3 100644 --- a/src/widget/wtracktableview.h +++ b/src/widget/wtracktableview.h @@ -59,9 +59,21 @@ class WTrackTableView : public WLibraryTableView { return m_focusBorderColor; } + // Default color for played tracks' text color. #555555, bit darker than Qt::darkgray. + // BaseTrackTableModel uses this for the ForegroundRole of played tracks. + static constexpr uint kDefaultPlayedInactiveColorHex = 555555; + Q_PROPERTY(QColor playedInactiveColor + MEMBER m_playedInactiveColor + NOTIFY playedInactiveColorChanged + DESIGNABLE true); + QColor getPlayedInactiveColor() const { + return m_playedInactiveColor; + } + signals: void trackMenuVisible(bool visible); void focusBorderColorChanged(QColor col); + void playedInactiveColorChanged(QColor col); public slots: void loadTrackModel(QAbstractItemModel* model, bool restoreState = false); @@ -129,6 +141,7 @@ class WTrackTableView : public WLibraryTableView { const double m_backgroundColorOpacity; QColor m_focusBorderColor; + QColor m_playedInactiveColor; bool m_sorting; // Control the delay to load a cover art.