Skip to content

Commit

Permalink
library: Get rid of special color constants and use NULL instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Feb 11, 2020
1 parent 2049f26 commit ed3eca7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/library/basesqltablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,8 @@ QVariant BaseSqlTableModel::data(const QModelIndex& index, int role) const {
} else if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_REPLAYGAIN)) {
value = mixxx::ReplayGain::ratioToString(value.toDouble());
} else if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COLOR)) {
QRgb rgb = QRgb(value.toUInt());
value = QVariant::fromValue(QColor(rgb));
mixxx::RgbColor::optional_t color = value.isNull() ? std::nullopt : mixxx::RgbColor::optional_t(mixxx::RgbColor(value.toUInt()));
value = toQVariant(color);
} // Otherwise, just use the column value.

break;
Expand Down
5 changes: 1 addition & 4 deletions src/library/basetrackcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace {

constexpr bool sDebug = false;

constexpr mixxx::RgbColor kDefaultTrackColor = mixxx::RgbColor(0x000000); // black

} // namespace

BaseTrackCache::BaseTrackCache(TrackCollection* pTrackCollection,
Expand Down Expand Up @@ -472,8 +470,7 @@ void BaseTrackCache::getTrackValueForColumn(TrackPointer pTrack,
} else if (fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) == column) {
trackValue.setValue(pTrack->isBpmLocked());
} else if (fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COLOR) == column) {
trackValue.setValue(toQVariant(
pTrack->getColor().value_or(kDefaultTrackColor)));
trackValue.setValue(toQVariant(pTrack->getColor()));
} else if (fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION) == column) {
trackValue.setValue(pTrack->getCoverInfo().coverLocation);
} else if (fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH) == column ||
Expand Down
24 changes: 8 additions & 16 deletions src/library/colordelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
#include "library/colordelegate.h"

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

#include "library/trackmodel.h"

namespace {
const QRgb hiddenTrackColor = 0xFF000000;
}
#include "util/color/rgbcolor.h"

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

void ColorDelegate::paintItem(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
VERIFY_OR_DEBUG_ASSERT(index.data().canConvert<QColor>()) {
return;
}

QColor color = qvariant_cast<QColor>(index.data());
VERIFY_OR_DEBUG_ASSERT(color.isValid()) {
return;
}

// Filter out track color that is hidden
if (color.rgb() == hiddenTrackColor) {
DEBUG_ASSERT(index.data().isValid());
if (index.data().isNull()) {
// Filter out track color that is hidden
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
}
return;
}

QColor color = mixxx::toQColor(mixxx::RgbColor(index.data().toUInt()));
qWarning() << "trackColor" << color;
painter->fillRect(option.rect, color);

// Paint transparent highlight if row is selected
Expand Down

0 comments on commit ed3eca7

Please sign in to comment.