Style proxy.

Took 14 minutes

Took 6 minutes

Took 1 minute
This commit is contained in:
Lukas Brübach 2025-11-09 04:46:31 +01:00
parent 164c40234b
commit 8382bd4160
6 changed files with 133 additions and 73 deletions

View file

@ -2,6 +2,7 @@
#include "../../../client/settings/cache_settings.h"
#include "../../deck_loader/deck_loader.h"
#include "deck_list_style_proxy.h"
#include <QComboBox>
#include <QDockWidget>
@ -30,9 +31,13 @@ void DeckEditorDeckDockWidget::createDeckDock()
deckModel = new DeckListModel(this);
deckModel->setObjectName("deckModel");
connect(deckModel, &DeckListModel::deckHashChanged, this, &DeckEditorDeckDockWidget::updateHash);
DeckListStyleProxy *proxy = new DeckListStyleProxy(this);
proxy->setSourceModel(deckModel);
deckView = new QTreeView();
deckView->setObjectName("deckView");
deckView->setModel(deckModel);
deckView->setModel(proxy);
deckView->setUniformRowHeights(true);
deckView->setSortingEnabled(true);
deckView->sortByColumn(1, Qt::AscendingOrder);

View file

@ -0,0 +1,36 @@
#include "deck_list_style_proxy.h"
#include <QBrush>
#include <QColor>
#include <QFont>
#include <libcockatrice/models/deck_list/deck_list_model.h>
QVariant DeckListStyleProxy::data(const QModelIndex &index, int role) const
{
QVariant value = QIdentityProxyModel::data(index, role);
const bool isCard = QIdentityProxyModel::data(index, DeckRoles::IsCardRole).toBool();
if (role == Qt::FontRole && !isCard) {
QFont f;
f.setBold(true);
return f;
}
if (role == Qt::BackgroundRole) {
if (isCard) {
const bool legal = QIdentityProxyModel::data(index, DeckRoles::IsLegalRole).toBool();
int base = 255 - (index.row() % 2) * 30;
return legal ? QBrush(QColor(base, base, base)) : QBrush(QColor(255, base / 3, base / 3));
} else {
int depth = QIdentityProxyModel::data(index, DeckRoles::DepthRole).toInt();
int color = 90 + 60 * depth;
return QBrush(QColor(color, 255, color));
}
}
if (role == Qt::ForegroundRole)
return QBrush(QColor(0, 0, 0));
return value;
}

View file

@ -0,0 +1,15 @@
#ifndef COCKATRICE_DECK_LIST_STYLE_PROXY_H
#define COCKATRICE_DECK_LIST_STYLE_PROXY_H
#include <QIdentityProxyModel>
class DeckListStyleProxy : public QIdentityProxyModel
{
Q_OBJECT
public:
using QIdentityProxyModel::QIdentityProxyModel;
QVariant data(const QModelIndex &index, int role) const override;
};
#endif // COCKATRICE_DECK_LIST_STYLE_PROXY_H