Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix preferred Color column width #12851

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ BaseTrackTableModel::BaseTrackTableModel(
TrackModel(cloneDatabase(pTrackCollectionManager), settingsNamespace),
m_pTrackCollectionManager(pTrackCollectionManager),
m_previewDeckGroup(PlayerManager::groupForPreviewDeck(0)),
m_backgroundColorOpacity(WLibrary::kDefaultTrackTableBackgroundColorOpacity) {
m_backgroundColorOpacity(WLibrary::kDefaultTrackTableBackgroundColorOpacity),
m_defaultColumnWidth(static_cast<int>(WTrackTableView::kDefaultColumnWidth)) {
connect(&pTrackCollectionManager->internalCollection()->getTrackDAO(),
&TrackDAO::forceModelUpdate,
this,
Expand Down Expand Up @@ -155,107 +156,108 @@ void BaseTrackTableModel::initHeaderProperties() {
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_ALBUM,
tr("Album"),
defaultColumnWidth() * 4);
m_defaultColumnWidth * 4);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_ALBUMARTIST,
tr("Album Artist"),
defaultColumnWidth() * 4);
m_defaultColumnWidth * 4);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_ARTIST,
tr("Artist"),
defaultColumnWidth() * 4);
m_defaultColumnWidth * 4);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_BITRATE,
tr("Bitrate"),
defaultColumnWidth());
m_defaultColumnWidth);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_BPM,
tr("BPM"),
defaultColumnWidth() * 2);
m_defaultColumnWidth * 2);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_CHANNELS,
tr("Channels"),
defaultColumnWidth() / 2);
m_defaultColumnWidth / 2);
// Note that this is also set in ColorDelegate to be used for its sizeHint()
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_COLOR,
tr("Color"),
defaultColumnWidth() / 2);
m_defaultColumnWidth / 2);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_COMMENT,
tr("Comment"),
defaultColumnWidth() * 6);
m_defaultColumnWidth * 6);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_COMPOSER,
tr("Composer"),
defaultColumnWidth() * 4);
m_defaultColumnWidth * 4);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_COVERART,
tr("Cover Art"),
defaultColumnWidth() / 2);
m_defaultColumnWidth / 2);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_DATETIMEADDED,
tr("Date Added"),
defaultColumnWidth() * 3);
m_defaultColumnWidth * 3);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_LAST_PLAYED_AT,
tr("Last Played"),
defaultColumnWidth() * 3);
m_defaultColumnWidth * 3);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_DURATION,
tr("Duration"),
defaultColumnWidth());
m_defaultColumnWidth);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_FILETYPE,
tr("Type"),
defaultColumnWidth());
m_defaultColumnWidth);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_GENRE,
tr("Genre"),
defaultColumnWidth() * 4);
m_defaultColumnWidth * 4);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_GROUPING,
tr("Grouping"),
defaultColumnWidth() * 4);
m_defaultColumnWidth * 4);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_KEY,
tr("Key"),
defaultColumnWidth());
m_defaultColumnWidth);
setHeaderProperties(
ColumnCache::COLUMN_TRACKLOCATIONSTABLE_LOCATION,
tr("Location"),
defaultColumnWidth() * 6);
m_defaultColumnWidth * 6);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW,
tr("Preview"),
defaultColumnWidth() / 2);
m_defaultColumnWidth / 2);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_RATING,
tr("Rating"),
defaultColumnWidth() * 2);
m_defaultColumnWidth * 2);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_REPLAYGAIN,
tr("ReplayGain"),
defaultColumnWidth() * 2);
m_defaultColumnWidth * 2);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_SAMPLERATE,
tr("Samplerate"),
defaultColumnWidth());
m_defaultColumnWidth);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_TIMESPLAYED,
tr("Played"),
defaultColumnWidth() * 2);
m_defaultColumnWidth * 2);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_TITLE,
tr("Title"),
defaultColumnWidth() * 4);
m_defaultColumnWidth * 4);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_TRACKNUMBER,
tr("Track #"),
defaultColumnWidth());
m_defaultColumnWidth);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_YEAR,
tr("Year"),
defaultColumnWidth());
m_defaultColumnWidth);
}

void BaseTrackTableModel::setHeaderProperties(
Expand Down Expand Up @@ -332,7 +334,7 @@ QVariant BaseTrackTableModel::headerData(
if (widthValue.isValid()) {
return widthValue;
} else {
return defaultColumnWidth();
return m_defaultColumnWidth;
}
}
case TrackModel::kHeaderNameRole: {
Expand Down
5 changes: 2 additions & 3 deletions src/library/basetracktablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {
static void setBpmColumnPrecision(int precision);

protected:
static constexpr int defaultColumnWidth() {
return 50;
}
static QStringList defaultTableColumns();

// Build a map from the column names to their indices
Expand Down Expand Up @@ -284,4 +281,6 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {
mutable QModelIndex m_toolTipIndex;

static int s_bpmColumnPrecision;

const int m_defaultColumnWidth;
};
8 changes: 7 additions & 1 deletion src/library/colordelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@

#include "moc_colordelegate.cpp"
#include "util/color/rgbcolor.h"
#include "widget/wtracktableview.h"

ColorDelegate::ColorDelegate(QTableView* pTableView)
: TableItemDelegate(pTableView) {
: TableItemDelegate(pTableView),
m_preferredWidth(static_cast<int>(WTrackTableView::kDefaultColumnWidth / 2)) {
}

QSize ColorDelegate::sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const {
return QSize(m_preferredWidth, 0);
}

void ColorDelegate::paintItem(
Expand Down
7 changes: 7 additions & 0 deletions src/library/colordelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const override;

// returns an item's preferred size
QSize sizeHint(const QStyleOptionViewItem&,

Check failure on line 20 in src/library/colordelegate.h

View workflow job for this annotation

GitHub Actions / clazy

'sizeHint' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]

Check failure on line 20 in src/library/colordelegate.h

View workflow job for this annotation

GitHub Actions / clazy

'sizeHint' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]

Check failure on line 20 in src/library/colordelegate.h

View workflow job for this annotation

GitHub Actions / clang-tidy

'sizeHint' overrides a member function but is not marked 'override' [clang-diagnostic-inconsistent-missing-override]

Check failure on line 20 in src/library/colordelegate.h

View workflow job for this annotation

GitHub Actions / clang-tidy

'sizeHint' overrides a member function but is not marked 'override' [clang-diagnostic-inconsistent-missing-override]
const QModelIndex&) const;

private:
int m_preferredWidth;
};
2 changes: 2 additions & 0 deletions src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class WTrackTableView : public WLibraryTableView {
return m_pFocusBorderColor;
}

static constexpr int kDefaultColumnWidth = 50;

signals:
void trackMenuVisible(bool visible);

Expand Down
Loading