Cleanups.

This commit is contained in:
2026-01-06 15:59:57 +01:00
parent 6c15d99119
commit 1a2d815634
20 changed files with 73 additions and 295 deletions

View File

@@ -181,54 +181,31 @@ QSize BCAnimatedDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
// 1. Standard-Zeichnen (Text, Hintergrund, Selection) durchführen
// Standard-Zeichnen (Text, Hintergrund, Selection) durchführen
QStyledItemDelegate::paint(painter, option, index);
//QPen pen(QColor(255, 165, 0)); // Orange
/*
if (index.row() == _highlightedRow && _opacity > 0.0)
{
painter->save();
qDebug() << " --- is highlight: " << index.row();
QColor highlightColor( 0xFF9800 );
highlightColor.setAlphaF(_opacity);
QPen pen(highlightColor, 3);
painter->setPen(pen);
painter->setBrush(Qt::NoBrush);
painter->drawRoundedRect(option.rect.adjusted(2, 2, -2, -2), 8, 8);
painter->restore();
}
*/
int row = index.row();
if (index.column() == 1 )
int col = index.column();
switch (col)
{
if( m_rowOpacities.contains(row))
{
paintHighlightRow(painter,option,index);
}
case 1:
if( m_rowOpacities.contains(row))
paintHighlightRow(painter,option,index);
break;
case 2:
if( row>-1 && row <= _valueList.size() )
paintSliderIndicator(painter,option,index);
default:
break;
}
}
/*
qreal opacity = m_rowOpacities.value(row);
if (opacity > 0.01)
{
painter->save();
painter->setOpacity(opacity);
painter->fillRect(option.rect, QColor(255, 140, 0, 120));
painter->restore();
}
*/
void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
painter->save();
@@ -239,33 +216,61 @@ void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOption
// Margin von 4px
QRect itemRect = option.rect.adjusted(3, 3, -3, -3);
// Border von 2px berücksichtigen (nach innen)
//QRect contentRect = itemRect.adjusted(2, 2, -2, -2);
// painter->fillRect(contentRect,Qt::green);
/*
// Hintergrund (weiß)
painter->setBrush(Qt::white);
painter->setPen(Qt::NoPen);
painter->drawRoundedRect(itemRect, 8, 8);
*/
// Border (2px solid #2196F3)
QPen borderPen( Qt::red, 1);
painter->setPen(borderPen);
painter->setBrush(Qt::NoBrush);
painter->drawRoundedRect(itemRect, 2, 2);
// Padding von 8px für den Content
//QRect textRect = contentRect.adjusted(8, 8, -8, -8);
/*
// Text zeichnen
painter->setPen(Qt::black); // oder option.palette.color(QPalette::Text)
QString text = index.data(Qt::DisplayRole).toString();
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
*/
painter->restore();
}
void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
const BCValue& valueX = *(_valueList[ index.row()].get());
int value = index.model()->data(index, Qt::DisplayRole).toInt();
// Hintergrund
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
} else if (index.row() % 2 == 1) {
painter->fillRect(option.rect, QColor(0xFAFAFA));
} else {
painter->fillRect(option.rect, Qt::white);
}
// Text und kleiner Slider-Indikator zeichnen
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
QRect textRect = option.rect.adjusted(8, 0, -120, 0);
QRect barRect = option.rect.adjusted(option.rect.width() - 115,
option.rect.height() / 2 - 2,
-8,
-option.rect.height() / 2 + 2);
// Text
painter->setPen(option.state & QStyle::State_Selected ?
option.palette.highlightedText().color() : Qt::black);
painter->drawText(textRect, Qt::AlignVCenter | Qt::AlignLeft,
QString::number(value));
// Mini Progress Bar
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0xE0E0E0));
painter->drawRoundedRect(barRect, 2, 2);
QRect fillRect = barRect;
fillRect.setWidth(barRect.width() * value / 100);
painter->setBrush(QColor(0x0078D4));
painter->drawRoundedRect(fillRect, 2, 2);
painter->restore();
}
void BCAnimatedDelegate::onHighlightRow(int row)
{