forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mixxxdj#13390 from danferns/static_key_colors
feat: static color coding for key column
- Loading branch information
Showing
14 changed files
with
219 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "library/tabledelegates/keydelegate.h" | ||
|
||
#include <QPainter> | ||
#include <QStyle> | ||
#include <QTableView> | ||
|
||
#include "moc_keydelegate.cpp" | ||
#include "track/keyutils.h" | ||
|
||
void KeyDelegate::paintItem( | ||
QPainter* painter, | ||
const QStyleOptionViewItem& option, | ||
const QModelIndex& index) const { | ||
paintItemBackground(painter, option, index); | ||
|
||
mixxx::track::io::key::ChromaticKey key = | ||
index.data().value<mixxx::track::io::key::ChromaticKey>(); | ||
if (key != mixxx::track::io::key::INVALID) { | ||
// Display the key colors if enabled | ||
bool keyColorsEnabled = index.data(Qt::UserRole).value<bool>(); | ||
if (keyColorsEnabled) { | ||
const QColor keyColor = KeyUtils::keyToColor(key); | ||
if (keyColor.isValid()) { | ||
// Draw the colored rectangle next to the key label | ||
painter->fillRect( | ||
option.rect.x(), | ||
option.rect.y() + 2, | ||
4, // width | ||
option.rect.height() - 4, | ||
keyColor); | ||
} | ||
} | ||
|
||
// Display the key text with the user-provided notation | ||
int rectWidth = keyColorsEnabled ? 8 : 0; // 4px width + 4px right padding | ||
const QString keyText = KeyUtils::keyToString(key); | ||
QString elidedText = option.fontMetrics.elidedText( | ||
keyText, | ||
Qt::ElideLeft, | ||
columnWidth(index) - rectWidth); | ||
|
||
if (option.state & QStyle::State_Selected) { | ||
// This uses selection-color from stylesheet for the text pen: | ||
// #LibraryContainer QTableView { | ||
// selection-color: #fff; | ||
// } | ||
painter->setPen(QPen(option.palette.highlightedText().color())); | ||
} | ||
|
||
painter->drawText(option.rect.x() + rectWidth, | ||
option.rect.y(), | ||
option.rect.width() - rectWidth, | ||
option.rect.height(), | ||
Qt::AlignVCenter, | ||
elidedText); | ||
} | ||
|
||
// Draw a border if the key cell has focus | ||
if (option.state & QStyle::State_HasFocus) { | ||
drawBorder(painter, m_focusBorderColor, option.rect); | ||
} | ||
} |
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,22 @@ | ||
#pragma once | ||
|
||
#include <QObject> | ||
|
||
#include "library/tabledelegates/tableitemdelegate.h" | ||
|
||
class QModelIndex; | ||
class QPainter; | ||
class QStyleOptionViewItem; | ||
|
||
class KeyDelegate : public TableItemDelegate { | ||
Q_OBJECT | ||
public: | ||
explicit KeyDelegate(QTableView* pTableView) | ||
: TableItemDelegate(pTableView) { | ||
} | ||
|
||
void paintItem( | ||
QPainter* painter, | ||
const QStyleOptionViewItem& option, | ||
const QModelIndex& index) const override; | ||
}; |
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
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
Oops, something went wrong.