Skip to content

Commit

Permalink
WIP Fix table item bg
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Nov 30, 2023
1 parent 2c2e706 commit 2027974
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 15 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/library/parsercsv.cpp
src/library/parserm3u.cpp
src/library/parserpls.cpp
src/library/playcountdelegate.cpp
src/library/playlisttablemodel.cpp
src/library/previewbuttondelegate.cpp
src/library/proxytrackmodel.cpp
Expand Down
30 changes: 15 additions & 15 deletions res/skins/LateNight/style_palemoon.qss
Original file line number Diff line number Diff line change
Expand Up @@ -1189,10 +1189,10 @@ WEffectChainPresetSelector,
WSearchLineEdit,
WTime,
#PreviewDeckTextBox, #PreviewTitle, #PreviewBPM,
WTrackTableView,
#LibraryBPMSpinBox,
#LibraryBPMButton::item,
WTrackTableView,
WTrackTableView::indicator,
#LibraryPlayedCheckbox::item,
WLibraryTextBrowser,
WLibrarySidebar,
#LibraryFeatureControls QLabel,
Expand Down Expand Up @@ -2549,15 +2549,11 @@ WLibrarySidebar {
WLibrarySidebar {
outline: none;
}
/* Prevent OS-style checkbox from being rendered underneath the custom style. */
WTrackTableView::item,
#LibraryBPMButton::item {
border: 0px;
}
/* Selected rows in Tree and Tracks table */
WLibrarySidebar::item:selected,
WTrackTableView::item:selected,
#LibraryBPMButton::item:selected {
#LibraryBPMButton::item:selected,
#LibraryPlayedCheckbox::item:selected {
color: #fff;
background-color: #2c454f;
}
Expand All @@ -2582,7 +2578,7 @@ WLibrarySidebar {
/* Use the native focus decoration */
/* This is for all cells including Played and Location */
WTrackTableView,
/* This is for the BPM cell */
/* This is for the BPM and play count cells */
WTrackTableView QCheckBox:focus {
outline: 1px solid #fff;
}
Expand All @@ -2603,6 +2599,11 @@ WLibrary QPlainTextEdit,
border: 1px solid #2c454f;
}

/* Prevent OS-style checkbox from being rendered underneath the custom style. */
#LibraryBPMButton::item,
#LibraryPlayedCheckbox::item {
border: 0px;
}
/* Entire BPM cell */
/* Lock icon at the left */
#LibraryBPMButton::indicator:checked {
Expand All @@ -2629,6 +2630,10 @@ WLibrary QPlainTextEdit,
#LibraryBPMSpinBox::down-button {
image: url(skin:../LateNight/palemoon/buttons/btn__lib_spinbox_down.svg) no-repeat center center;
}
/* Played checkbox */
#LibraryPlayedCheckbox::indicator:unchecked {
image: url(skin:../LateNight/palemoon/buttons/btn__lib_checkbox.svg);
}

/* Button in library "Preview" column */
#LibraryPreviewButton {
Expand Down Expand Up @@ -3070,14 +3075,9 @@ QPlainTextEdit QMenu::item:disabled {
image: url(skin:../LateNight/palemoon/buttons/btn__menu_checkbox.svg);
}

/* This is the only way to select the 'Played' checkbox.
Note that this also selects the BPM lock, so style that afterwards. */
WTrackTableView::indicator:unchecked {
image: url(skin:../LateNight/palemoon/buttons/btn__lib_checkbox.svg);
}
WLibrarySidebar QMenu::indicator:checked,
WTrackTableViewHeader QMenu::indicator:checked,
WTrackTableView::indicator:checked,
#LibraryPlayedCheckbox::indicator:checked,
WTrackMenu QMenu QCheckBox::indicator:checked,
WEffectChainPresetButton QMenu QCheckBox::indicator:checked {
image: url(skin:../LateNight/palemoon/buttons/btn__lib_checkmark_blue.svg);
Expand Down
3 changes: 3 additions & 0 deletions src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "library/dao/trackschema.h"
#include "library/locationdelegate.h"
#include "library/multilineeditdelegate.h"
#include "library/playcountdelegate.h"
#include "library/previewbuttondelegate.h"
#include "library/stardelegate.h"
#include "library/starrating.h"
Expand Down Expand Up @@ -399,6 +400,8 @@ QAbstractItemDelegate* BaseTrackTableModel::delegateForColumn(
return new StarDelegate(pTableView);
} else if (index == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM)) {
return new BPMDelegate(pTableView);
} else if (index == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_TIMESPLAYED)) {
return new PlayCountDelegate(pTableView);
} else if (PlayerManager::numPreviewDecks() > 0 &&
index == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW)) {
return new PreviewButtonDelegate(pTableView, index);
Expand Down
3 changes: 3 additions & 0 deletions src/library/bpmdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void BPMDelegate::paintItem(QPainter* painter,const QStyleOptionViewItem &option
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);

// xxx
paintItemBackground(painter, option, index);

if (m_pTableView != nullptr) {
QStyle* style = m_pTableView->style();
if (style != nullptr) {
Expand Down
58 changes: 58 additions & 0 deletions src/library/playcountdelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "library/playcountdelegate.h"

#include <QCheckBox>
#include <QPainter>
#include <QTableView>

#include "moc_playcountdelegate.cpp"

PlayCountDelegate::PlayCountDelegate(QTableView* pTableView)
: TableItemDelegate(pTableView),
m_pTableView(pTableView),
m_pCheckBox(new QCheckBox(m_pTableView)) {
m_pCheckBox->setObjectName("LibraryPlayedCheckbox");
// NOTE(rryan): Without ensurePolished the first render of the QTableView
// shows the checkbox unstyled. Not sure why -- but this fixes it.
m_pCheckBox->ensurePolished();
m_pCheckBox->hide();
}

PlayCountDelegate::~PlayCountDelegate() {
}

void PlayCountDelegate::paintItem(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const {
// NOTE(rryan): Qt has a built-in limitation that we cannot style multiple
// CheckState indicators in the same QAbstractItemView. The CSS rule
// QTableView::indicator:checked applies to all columns with a
// CheckState. This is a big pain if we want to use CheckState roles on two
// columns (i.e. the played column and the BPM column) with different
// styling. We typically want a lock icon for the BPM check-state and a
// check-box for the times-played column and may want more in the future.
//
// This workaround creates a hidden QComboBox named LibraryBPMButton. We use
// the parent QTableView's QStyle with the hidden QComboBox as the source of
// style rules to draw a CE_ItemViewItem.
//
// Here's how you would typically style the LibraryBPMButton:
// #LibraryBPMButton::indicator:checked {
// image: url(:/images/library/ic_library_locked.svg);
// }
// #LibraryBPMButton::indicator:unchecked {
// image: url(:/images/library/ic_library_unlocked.svg);
// }

QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);

// xxx
paintItemBackground(painter, option, index);

if (m_pTableView != nullptr) {
QStyle* style = m_pTableView->style();
if (style != nullptr) {
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, m_pCheckBox);
}
}
}
20 changes: 20 additions & 0 deletions src/library/playcountdelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "library/tableitemdelegate.h"

class QCheckBox;

class PlayCountDelegate : public TableItemDelegate {
Q_OBJECT
public:
explicit PlayCountDelegate(QTableView* pTableView);
virtual ~PlayCountDelegate();

void paintItem(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const override;

private:
QTableView* m_pTableView;
QCheckBox* m_pCheckBox;
};

0 comments on commit 2027974

Please sign in to comment.