-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
100 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |