From 01ec86aeb04c137f2e9ad6648d8b0184e5ab5557 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 8 Mar 2020 11:17:13 +0100 Subject: [PATCH 01/10] library/basesqltablemodel: Use Track color for whole row --- src/library/basesqltablemodel.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/library/basesqltablemodel.cpp b/src/library/basesqltablemodel.cpp index 177c0452034..fcf79e203ce 100644 --- a/src/library/basesqltablemodel.cpp +++ b/src/library/basesqltablemodel.cpp @@ -706,10 +706,12 @@ int BaseSqlTableModel::fieldIndex(const QString& fieldName) const { QVariant BaseSqlTableModel::data(const QModelIndex& index, int role) const { //qDebug() << this << "data()"; - if (!index.isValid() || (role != Qt::DisplayRole && - role != Qt::EditRole && - role != Qt::CheckStateRole && - role != Qt::ToolTipRole)) { + if (!index.isValid() || ( + role != Qt::BackgroundRole && + role != Qt::DisplayRole && + role != Qt::EditRole && + role != Qt::CheckStateRole && + role != Qt::ToolTipRole)) { return QVariant(); } @@ -723,6 +725,18 @@ QVariant BaseSqlTableModel::data(const QModelIndex& index, int role) const { // Format the value based on whether we are in a tooltip, display, or edit // role switch (role) { + case Qt::BackgroundRole: { + QModelIndex colorIndex = index.sibling( + index.row(), + fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COLOR)); + QColor color = mixxx::RgbColor::toQColor( + mixxx::RgbColor::fromQVariant(getBaseValue(colorIndex, role))); + if (color.isValid()) { + color.setAlpha(32); // Make this 12.5% opaque + value = QBrush(color); + } + break; + } case Qt::ToolTipRole: if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COLOR)) { value = mixxx::RgbColor::toQString(mixxx::RgbColor::fromQVariant(value)); @@ -1050,7 +1064,8 @@ void BaseSqlTableModel::setTrackValueForColumn(TrackPointer pTrack, int column, QVariant BaseSqlTableModel::getBaseValue( const QModelIndex& index, int role) const { - if (role != Qt::DisplayRole && + if (role != Qt::BackgroundRole && + role != Qt::DisplayRole && role != Qt::ToolTipRole && role != Qt::EditRole) { return QVariant(); From bc91f4fce2cfd8c87c87e90a6750e10465a23e9b Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Mon, 9 Mar 2020 00:06:52 +0100 Subject: [PATCH 02/10] library/tableitemdelegate: Add free paintItemBackground function --- src/library/tableitemdelegate.cpp | 15 +++++++++++++++ src/library/tableitemdelegate.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/src/library/tableitemdelegate.cpp b/src/library/tableitemdelegate.cpp index 2bae8d1ced7..727d9309752 100644 --- a/src/library/tableitemdelegate.cpp +++ b/src/library/tableitemdelegate.cpp @@ -54,3 +54,18 @@ void TableItemDelegate::paint( int TableItemDelegate::columnWidth(const QModelIndex &index) const { return m_pTableView->columnWidth(index.column()); } + +void paintItemBackground( + QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index) { + // If the row is not selected, paint the desired background color before + // painting the delegate item + if (!option.showDecorationSelected || !(option.state & QStyle::State_Selected)) { + QVariant bgValue = index.data(Qt::BackgroundRole); + if (bgValue.isValid()) { + DEBUG_ASSERT(bgValue.canConvert()); + painter->fillRect(option.rect, qvariant_cast(bgValue)); + } + } +} diff --git a/src/library/tableitemdelegate.h b/src/library/tableitemdelegate.h index 11779659961..296ac544f9b 100644 --- a/src/library/tableitemdelegate.h +++ b/src/library/tableitemdelegate.h @@ -26,3 +26,8 @@ class TableItemDelegate : public QStyledItemDelegate { private: QTableView* m_pTableView; }; + +void paintItemBackground( + QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index); From bddc64c0a46d16ee304b978ba58eee1becaf221c Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 8 Mar 2020 12:49:30 +0100 Subject: [PATCH 03/10] library/stardelegate: Remove useless reimplementation of paint() --- src/library/stardelegate.cpp | 15 ++++----------- src/library/stardelegate.h | 3 --- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/library/stardelegate.cpp b/src/library/stardelegate.cpp index cbfa4f081b6..26b5bc8646a 100644 --- a/src/library/stardelegate.cpp +++ b/src/library/stardelegate.cpp @@ -30,17 +30,10 @@ StarDelegate::StarDelegate(QTableView* pTableView) connect(pTableView, &QTableView::entered, this, &StarDelegate::cellEntered); } -void StarDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const { - // let the editor do the painting if this cell is currently being edited - if (index == m_currentEditedCellIndex) { - return; - } - TableItemDelegate::paint(painter, option, index); -} - -void StarDelegate::paintItem(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const { +void StarDelegate::paintItem( + QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index) const { // let the editor do the painting if this cell is currently being edited if (index == m_currentEditedCellIndex) { return; diff --git a/src/library/stardelegate.h b/src/library/stardelegate.h index 2b35fc61bbd..999c65e2ffc 100644 --- a/src/library/stardelegate.h +++ b/src/library/stardelegate.h @@ -28,9 +28,6 @@ class StarDelegate : public TableItemDelegate { // reimplemented from QItemDelegate and is called whenever the view needs to // repaint an item - void paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const; - void paintItem(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; From 82128cc86a972302cd192b42d95222aa23bb0745 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 8 Mar 2020 12:52:30 +0100 Subject: [PATCH 04/10] library/stardelegate: Fix background color of StarDelegate --- src/library/stardelegate.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/library/stardelegate.cpp b/src/library/stardelegate.cpp index 26b5bc8646a..125a058076b 100644 --- a/src/library/stardelegate.cpp +++ b/src/library/stardelegate.cpp @@ -15,13 +15,14 @@ * * ***************************************************************************/ +#include "library/stardelegate.h" +#include #include -#include "library/tableitemdelegate.h" -#include "library/stardelegate.h" #include "library/stareditor.h" #include "library/starrating.h" +#include "library/tableitemdelegate.h" StarDelegate::StarDelegate(QTableView* pTableView) : TableItemDelegate(pTableView), @@ -39,6 +40,8 @@ void StarDelegate::paintItem( return; } + paintItemBackground(painter, option, index); + StarRating starRating = index.data().value(); starRating.paint(painter, option.rect); } From e5c0bfd30aae6d56495e899bd9e907623f51c60a Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 8 Mar 2020 12:46:23 +0100 Subject: [PATCH 05/10] library/coverartdelegate: Fix background color of CoverArtDelegate --- src/library/coverartdelegate.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/library/coverartdelegate.cpp b/src/library/coverartdelegate.cpp index 3e31c6cf8b6..9e6d56feda3 100644 --- a/src/library/coverartdelegate.cpp +++ b/src/library/coverartdelegate.cpp @@ -87,6 +87,8 @@ void CoverArtDelegate::slotCoverFound(const QObject* pRequestor, void CoverArtDelegate::paintItem(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { + paintItemBackground(painter, option, index); + CoverArtCache* pCache = CoverArtCache::instance(); if (pCache == NULL || m_iIdColumn == -1 || m_iCoverSourceColumn == -1 || m_iCoverTypeColumn == -1 || m_iCoverLocationColumn == -1 || From 71d34adb266b56d5292b676a0bb8fa5d6d03ff45 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 8 Mar 2020 12:46:54 +0100 Subject: [PATCH 06/10] library/locationdelegate: Fix background color of LocationDelegate --- src/library/locationdelegate.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/library/locationdelegate.cpp b/src/library/locationdelegate.cpp index e54c2698d70..bb197bdadcf 100644 --- a/src/library/locationdelegate.cpp +++ b/src/library/locationdelegate.cpp @@ -11,6 +11,8 @@ void LocationDelegate::paintItem( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + paintItemBackground(painter, option, index); + QString elidedText = option.fontMetrics.elidedText( index.data().toString(), Qt::ElideLeft, From a873f7f8dbe00388a3fea066e09894d3670108fe Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 8 Mar 2020 12:47:24 +0100 Subject: [PATCH 07/10] library/previewbuttondelegate: Fix background color of PreviewButtonDelegate --- src/library/previewbuttondelegate.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/library/previewbuttondelegate.cpp b/src/library/previewbuttondelegate.cpp index 21fb8352e2b..4584dd30090 100644 --- a/src/library/previewbuttondelegate.cpp +++ b/src/library/previewbuttondelegate.cpp @@ -85,6 +85,8 @@ void PreviewButtonDelegate::setModelData(QWidget* editor, void PreviewButtonDelegate::paintItem(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + paintItemBackground(painter, option, index); + // Let the editor paint in this case if (index == m_currentEditedCellIndex) { return; From 3e9678fda1c5293a72f77d32f9ef830d1e15b10b Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Mon, 9 Mar 2020 02:02:35 +0100 Subject: [PATCH 08/10] library/basesqltablemodel: Use constant for track color row opacity --- src/library/basesqltablemodel.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/library/basesqltablemodel.cpp b/src/library/basesqltablemodel.cpp index fcf79e203ce..455d4f718ba 100644 --- a/src/library/basesqltablemodel.cpp +++ b/src/library/basesqltablemodel.cpp @@ -40,6 +40,9 @@ const int kMaxSortColumns = 3; // Constant for getModelSetting(name) const QString COLUMNS_SORTING = QStringLiteral("ColumnsSorting"); +// Alpha value for row color background (range 0 - 255) +constexpr int kTrackColorRowBackgroundOpacity = 0x20; // 12.5% opacity + } // anonymous namespace BaseSqlTableModel::BaseSqlTableModel(QObject* pParent, @@ -732,7 +735,7 @@ QVariant BaseSqlTableModel::data(const QModelIndex& index, int role) const { QColor color = mixxx::RgbColor::toQColor( mixxx::RgbColor::fromQVariant(getBaseValue(colorIndex, role))); if (color.isValid()) { - color.setAlpha(32); // Make this 12.5% opaque + color.setAlpha(kTrackColorRowBackgroundOpacity); value = QBrush(color); } break; From c354d1c665a4f48cfba5cdaa9faace6a6ac0b500 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Tue, 10 Mar 2020 11:17:13 +0100 Subject: [PATCH 09/10] library/tableitemdelegate: Make paintItemBackground protected static --- src/library/tableitemdelegate.cpp | 2 +- src/library/tableitemdelegate.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/library/tableitemdelegate.cpp b/src/library/tableitemdelegate.cpp index 727d9309752..617b805d018 100644 --- a/src/library/tableitemdelegate.cpp +++ b/src/library/tableitemdelegate.cpp @@ -55,7 +55,7 @@ int TableItemDelegate::columnWidth(const QModelIndex &index) const { return m_pTableView->columnWidth(index.column()); } -void paintItemBackground( +void TableItemDelegate::paintItemBackground( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) { diff --git a/src/library/tableitemdelegate.h b/src/library/tableitemdelegate.h index 296ac544f9b..01f6fd23356 100644 --- a/src/library/tableitemdelegate.h +++ b/src/library/tableitemdelegate.h @@ -21,13 +21,13 @@ class TableItemDelegate : public QStyledItemDelegate { const QModelIndex &index) const = 0; protected: + static void paintItemBackground( + QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index); + int columnWidth(const QModelIndex &index) const; private: QTableView* m_pTableView; }; - -void paintItemBackground( - QPainter* painter, - const QStyleOptionViewItem& option, - const QModelIndex& index); From 5e966eee257a32fd2de762c6915a6aff6d83be46 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Tue, 10 Mar 2020 13:44:57 +0100 Subject: [PATCH 10/10] library/basesqltablemodel: Return empty QVariant for invalid colors --- src/library/basesqltablemodel.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/library/basesqltablemodel.cpp b/src/library/basesqltablemodel.cpp index 9ad136cbaed..a45fa51965b 100644 --- a/src/library/basesqltablemodel.cpp +++ b/src/library/basesqltablemodel.cpp @@ -737,6 +737,8 @@ QVariant BaseSqlTableModel::data(const QModelIndex& index, int role) const { if (color.isValid()) { color.setAlpha(kTrackColorRowBackgroundOpacity); value = QBrush(color); + } else { + value = QVariant(); } break; }