Skip to content

Commit

Permalink
add KeyDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
danferns committed Jun 18, 2024
1 parent 7931a07 commit 50a9767
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/library/tabledelegates/bpmdelegate.cpp
src/library/tabledelegates/colordelegate.cpp
src/library/tabledelegates/coverartdelegate.cpp
src/library/tabledelegates/keydelegate.cpp
src/library/tabledelegates/locationdelegate.cpp
src/library/tabledelegates/multilineeditdelegate.cpp
src/library/tabledelegates/playcountdelegate.cpp
Expand Down
5 changes: 4 additions & 1 deletion src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "library/tabledelegates/bpmdelegate.h"
#include "library/tabledelegates/colordelegate.h"
#include "library/tabledelegates/coverartdelegate.h"
#include "library/tabledelegates/keydelegate.h"
#include "library/tabledelegates/locationdelegate.h"
#include "library/tabledelegates/multilineeditdelegate.h"
#include "library/tabledelegates/playcountdelegate.h"
Expand Down Expand Up @@ -121,7 +122,7 @@ void BaseTrackTableModel::setApplyPlayedTrackColor(bool apply) {
s_bApplyPlayedTrackColor = apply;
}

//static
// static
QStringList BaseTrackTableModel::defaultTableColumns() {
return kDefaultTableColumns;
}
Expand Down Expand Up @@ -506,6 +507,8 @@ QAbstractItemDelegate* BaseTrackTableModel::delegateForColumn(
this,
&BaseTrackTableModel::slotRefreshCoverRows);
return pCoverArtDelegate;
} else if (index == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY)) {
return new KeyDelegate(pTableView);
}
return nullptr;
}
Expand Down
37 changes: 37 additions & 0 deletions src/library/tabledelegates/keydelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "library/tabledelegates/keydelegate.h"

#include <qnamespace.h>

#include <QPainter>
#include <QStyle>
#include <QTableView>

#include "moc_keydelegate.cpp"
#include "util/color/rgbcolor.h"

KeyDelegate::KeyDelegate(QTableView* pTableView)
: TableItemDelegate(pTableView) {
}

void KeyDelegate::paintItem(
QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const {
const auto color = mixxx::RgbColor::fromQVariant(index.data());

if (color) {
painter->fillRect(option.rect, mixxx::RgbColor::toQColor(color));
} else {
// Filter out track color that is hidden
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
}
}

// Draw a border if the color cell has focus
if (option.state & QStyle::State_HasFocus) {
drawBorder(painter, m_focusBorderColor, option.rect);
}

// QStyledItemDelegate::paint(painter, option, index);
}
18 changes: 18 additions & 0 deletions src/library/tabledelegates/keydelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "library/tabledelegates/tableitemdelegate.h"

class QModelIndex;
class QPainter;
class QStyleOptionViewItem;

class KeyDelegate : public TableItemDelegate {
Q_OBJECT
public:
explicit KeyDelegate(QTableView* pTableView);

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

0 comments on commit 50a9767

Please # to comment.