| 28 | ModelContentDelegate::~ModelContentDelegate() = default; |
| 29 | |
| 30 | void ModelContentDelegate::paint(QPainter *painter, const QStyleOptionViewItem &origOption, const QModelIndex &index) const |
| 31 | { |
| 32 | Q_ASSERT(index.isValid()); |
| 33 | auto option = origOption; |
| 34 | initStyleOption(&option, index); |
| 35 | if (index.data(ModelContentProxyModel::DisabledRole).toBool()) |
| 36 | option.state = option.state & ~QStyle::State_Enabled; |
| 37 | |
| 38 | if (index.data(ModelContentProxyModel::SelectedRole).toBool()) { |
| 39 | // for non-selected cells |
| 40 | option.backgroundBrush = option.palette.highlight(); |
| 41 | option.backgroundBrush.setStyle(Qt::BDiagPattern); |
| 42 | |
| 43 | // TODO also render selection for currently selected cells |
| 44 | } |
| 45 | |
| 46 | if (index.data(ModelContentProxyModel::IsDisplayStringEmptyRole).toBool()) { |
| 47 | option.palette.setColor(QPalette::Text, option.palette.color(QPalette::Disabled, QPalette::Text)); |
| 48 | option.text = tr("<unnamed: row %1, column %2>").arg(index.row()).arg(index.column()); |
| 49 | } |
| 50 | |
| 51 | QStyle *style = QApplication::style(); |
| 52 | style->drawControl(QStyle::CE_ItemViewItem, &option, painter, nullptr); |
| 53 | } |