summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorronso0 <ronso0@mixxx.org>2020-11-18 01:24:41 +0100
committerronso0 <ronso0@mixxx.org>2020-11-24 23:35:32 +0100
commita735a490858460d5468af065204d72166202d9d8 (patch)
tree61a3a77879df43b7fcc52289addf8900e884ad58
parent0e76005084ae16063d57aedadd405f47d4c81a0b (diff)
CoverArtDelegate, ColorDelegate: draw a focus border, pick color from stylesheets (default: white)
-rw-r--r--res/skins/Deere/style.qss6
-rw-r--r--res/skins/LateNight/style_classic.qss6
-rw-r--r--res/skins/LateNight/style_palemoon.qss6
-rw-r--r--res/skins/Shade/style.qss6
-rw-r--r--res/skins/Shade/style_dark.qss6
-rw-r--r--res/skins/Tango/style.qss6
-rw-r--r--src/library/colordelegate.cpp33
-rw-r--r--src/library/coverartdelegate.cpp21
-rw-r--r--src/library/tableitemdelegate.cpp8
-rw-r--r--src/library/tableitemdelegate.h2
-rw-r--r--src/widget/wtracktableview.cpp4
-rw-r--r--src/widget/wtracktableview.h6
12 files changed, 97 insertions, 13 deletions
diff --git a/res/skins/Deere/style.qss b/res/skins/Deere/style.qss
index d2252f58ac..7d51440131 100644
--- a/res/skins/Deere/style.qss
+++ b/res/skins/Deere/style.qss
@@ -242,6 +242,12 @@
#LibraryContainer QTableView 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 {
+ qproperty-focusBorderColor: #D6D6D6;
+}
#LibraryContainer QTableView:focus,
#LibraryContainer QTreeView:focus,
diff --git a/res/skins/LateNight/style_classic.qss b/res/skins/LateNight/style_classic.qss
index 9613aaafb4..dfaf0b379b 100644
--- a/res/skins/LateNight/style_classic.qss
+++ b/res/skins/LateNight/style_classic.qss
@@ -1999,6 +1999,12 @@ WLibrary,
#LibraryContainer QTableView 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 {
+ qproperty-focusBorderColor: #fff;
+}
#LibraryContainer QTreeView {
show-decoration-selected: 0;
diff --git a/res/skins/LateNight/style_palemoon.qss b/res/skins/LateNight/style_palemoon.qss
index b1977ec290..2c5cc067d8 100644
--- a/res/skins/LateNight/style_palemoon.qss
+++ b/res/skins/LateNight/style_palemoon.qss
@@ -2470,6 +2470,12 @@ WColorPicker QPushButton[checked="true"] {
#LibraryContainer QTableView 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 {
+ qproperty-focusBorderColor: #fff;
+}
/* This is the only way to select the 'Played' checkbox.
Note that this also selects the BPM lock. */
diff --git a/res/skins/Shade/style.qss b/res/skins/Shade/style.qss
index 6718007399..601c0e5dc0 100644
--- a/res/skins/Shade/style.qss
+++ b/res/skins/Shade/style.qss
@@ -486,6 +486,12 @@ QTextBrowser {
#LibraryContainer QTableView QCheckBox:focus {
outline: 1px solid #c9c9c9;
}
+/* 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 {
+ qproperty-focusBorderColor: #c9c9c9;
+}
/* Table cell in edit mode */
WLibrary QLineEdit,
diff --git a/res/skins/Shade/style_dark.qss b/res/skins/Shade/style_dark.qss
index c32a731d2a..fdc1bd7764 100644
--- a/res/skins/Shade/style_dark.qss
+++ b/res/skins/Shade/style_dark.qss
@@ -162,6 +162,12 @@ WSearchLineEdit QToolButton:focus {
#LibraryContainer QTableView QCheckBox:focus {
outline: 1px solid #ccc;
}
+/* 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 {
+ qproperty-focusBorderColor: #ccc;
+}
/* Table cell in edit mode */
WLibrary QLineEdit,
diff --git a/res/skins/Tango/style.qss b/res/skins/Tango/style.qss
index 4d76d3f0a3..8b389a67d5 100644
--- a/res/skins/Tango/style.qss
+++ b/res/skins/Tango/style.qss
@@ -2457,6 +2457,12 @@ WTrackMenu QMenu::right-arrow {
#LibraryContainer QTableView 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 {
+ qproperty-focusBorderColor: #fff;
+}
/* Table cell in edit mode */
WLibrary QLineEdit,
diff --git a/src/library/colordelegate.cpp b/src/library/colordelegate.cpp
index f92018b0b9..f44250921c 100644
--- a/src/library/colordelegate.cpp
+++ b/src/library/colordelegate.cpp
@@ -12,7 +12,10 @@ ColorDelegate::ColorDelegate(QTableView* pTableView)
: TableItemDelegate(pTableView) {
}
-void ColorDelegate::paintItem(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
+void ColorDelegate::paintItem(
+ QPainter* painter,
+ const QStyleOptionViewItem& option,
+ const QModelIndex& index) const {
const auto color = mixxx::RgbColor::fromQVariant(index.data());
if (!color) {
@@ -20,15 +23,27 @@ void ColorDelegate::paintItem(QPainter* painter, const QStyleOptionViewItem& opt
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
}
- return;
+ } else {
+ painter->fillRect(option.rect, mixxx::RgbColor::toQColor(color));
}
- painter->fillRect(option.rect, mixxx::RgbColor::toQColor(color));
-
- // Paint transparent highlight if row is selected
- if (option.state & QStyle::State_Selected) {
- QColor highlightColor = option.palette.highlight().color();
- highlightColor.setAlpha(0x60);
- painter->fillRect(option.rect, highlightColor);
+ // Draw a border if the color cell has focus
+ if (option.state & QStyle::State_HasFocus) {
+ // This uses a color from the stylesheet:
+ // WTrackTableView {
+ // qproperty-focusBorderColor: red;
+ // }
+ QPen borderPen(
+ m_pFocusBorderColor,
+ 1,
+ Qt::SolidLine,
+ Qt::SquareCap);
+ painter->setPen(borderPen);
+ painter->setBrush(QBrush(Qt::transparent));
+ painter->drawRect(
+ option.rect.left(),
+ option.rect.top(),
+ option.rect.width() - 1,
+ option.rect.height() - 1);
}
}
diff --git a/src/library/coverartdelegate.cpp b/src/library/coverartdelegate.cpp
index 4ba9b54f0e..45da0004a7 100644
--- a/src/library/coverartdelegate.cpp
+++ b/src/library/coverartdelegate.cpp
@@ -141,7 +141,26 @@ void CoverArtDelegate::paintItem(
// Cache hit
pixmap.setDevicePixelRatio(scaleFactor);
painter->drawPixmap(option.rect.topLeft(), pixmap);
- return;
}
}
+
+ // Draw a border if the cover art cell has focus
+ if (option.state & QStyle::State_HasFocus) {
+ // This uses a color from the stylesheet:
+ // WTrackTableView {
+ // qproperty-focusBorderColor: red;
+ // }
+ QPen borderPen(
+ m_pFocusBorderColor,
+ 1,
+ Qt::SolidLine,
+ Qt::SquareCap);
+ painter->setPen(borderPen);
+ painter->setBrush(QBrush(Qt::transparent));
+ painter->drawRect(
+ option.rect.left(),
+ option.rect.top(),
+ option.rect.width() - 1,
+ option.rect.height() - 1);
+ }
}
diff --git a/src/library/tableitemdelegate.cpp b/src/library/tableitemdelegate.cpp
index 0176555ebf..191fc4fec9 100644
--- a/src/library/tableitemdelegate.cpp
+++ b/src/library/tableitemdelegate.cpp
@@ -1,15 +1,19 @@
#include "library/tableitemdelegate.h"
-#include <QTableView>
#include <QPainter>
+#include <QTableView>
#include "util/painterscope.h"
-
+#include "widget/wtracktableview.h"
TableItemDelegate::TableItemDelegate(QTableView* pTableView)
: QStyledItemDelegate(pTableView),
m_pTableView(pTableView) {
DEBUG_ASSERT(m_pTableView);
+ auto* pTrackTableView = qobject_cast<WTrackTableView*>(m_pTableView);
+ if (pTrackTableView) {
+ m_pFocusBorderColor = pTrackTableView->getFocusBorderColor();
+ }
}
void TableItemDelegate::paint(
diff --git a/src/library/tableitemdelegate.h b/src/library/tableitemdelegate.h
index 0ac0bdc387..a9cb54d796 100644
--- a/src/library/tableitemdelegate.h
+++ b/src/library/tableitemdelegate.h
@@ -28,6 +28,8 @@ class TableItemDelegate : public QStyledItemDelegate {
int columnWidth(const QModelIndex &index) const;
+ QColor m_pFocusBorderColor;
+
private:
QTableView* m_pTableView;
};
diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp
index 0c1bd930c4..ac5f102645 100644
--- a/src/widget/wtracktableview.cpp
+++ b/src/widget/wtracktableview.cpp
@@ -26,7 +26,8 @@
namespace {
const ConfigKey kConfigKeyAllowTrackLoadToPlayingDeck("[Controls]", "AllowTrackLoadToPlayingDeck");
-
+// Default color for the focus border of TableItemDelegates
+const QColor kDefaultFocusBorderColor = Qt::white;
}
WTrackTableView::WTrackTableView(QWidget* parent,
@@ -41,6 +42,7 @@ WTrackTableView::WTrackTableView(QWidget* parent,
m_pConfig(pConfig),
m_pTrackCollectionManager(pTrackCollectionManager),
m_backgroundColorOpacity(backgroundColorOpacity),
+ m_pFocusBorderColor(kDefaultFocusBorderColor),
m_sorting(sorting),
m_selectionChangedSinceLastGuiTick(true),
m_loadCachedOnly(false) {
diff --git a/src/widget/wtracktableview.h b/src/widget/wtracktableview.h
index 9e0ad84d4f..463a820863 100644
--- a/src/widget/wtracktableview.h
+++ b/src/widget/wtracktableview.h
@@ -50,6 +50,11 @@ class WTrackTableView : public WLibraryTableView {
return m_backgroundColorOpacity;
}
+ Q_PROPERTY(QColor focusBorderColor MEMBER m_pFocusBorderColor DESIGNABLE true);
+ QColor getFocusBorderColor() const {
+ return m_pFocusBorderColor;
+ }
+
public slots:
void loadTrackModel(QAbstractItemModel* model);
void slotMouseDoubleClicked(const QModelIndex &);
@@ -98,6 +103,7 @@ class WTrackTableView : public WLibraryTableView {
parented_ptr<WTrackMenu> m_pTrackMenu;
const double m_backgroundColorOpacity;
+ QColor m_pFocusBorderColor;
bool m_sorting;
// Control the delay to load a cover art.