Added fake toggle switch.

This commit is contained in:
2026-03-31 18:18:37 +02:00
parent 5db2677d76
commit 075aadc665
6 changed files with 89 additions and 14 deletions

View File

@@ -116,11 +116,10 @@ void BCValueDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionVi
if( !bcValue.isBoolean())
{
editorRect = clipToSliderRect( option.rect );
}
else
{
editorRect = option.rect.adjusted(2,4,0,0);
editorRect = option.rect.adjusted(option.rect.width() - cTextBlockOffset,4,0,0);
}
editor->setGeometry(editorRect);
}
@@ -153,14 +152,11 @@ void BCValueDelegate::paint(QPainter *painter, const QStyleOptionViewItem& optio
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
const BCValue& bcValue = *(_valueList[ index.row()].get());
//qDebug() << " --- RO?: " << bcValue.label() << " Ro: " << bcValue.isReadOnly() << " Bool: " << bcValue.isBoolean() << ": " << index.flags();
const BCValue& bcValue = *(_valueList[ index.row()].get());
if( bcValue.isBoolean() )
{
paintBooleanValue( painter, opt, bcValue );
//opt.text = bcValue.rawValue() == 1 ? "Yes" : "No";
//painter->drawText( opt.rect, bcValue.rawValue() == 1 ? "Yes" : "No" );
paintBooleanValue( painter, opt, bcValue );
}
else
{
@@ -168,17 +164,20 @@ void BCValueDelegate::paint(QPainter *painter, const QStyleOptionViewItem& optio
QStyledItemDelegate::paint(painter, opt, index);
}
if( !bcValue.isReadOnly() )
{
// Wir zeichnen boolean Values an toggle switches
if( bcValue.isBoolean() )
paintPlainToggleSwitch(painter, opt, bcValue);
if (bcValue.isBoolean())
{
//paintPlainToggleSwitch(painter, opt, bcValue);
}
else
paintPlainSliderIndicator(painter, opt.rect, bcValue.calcMinMaxRatio() );
{
paintPlainSliderIndicator(painter, opt.rect, bcValue.calcMinMaxRatio());
}
}
if(_rowOpacities.contains(row))
paintHighlightRow(painter, opt,index.row());
@@ -190,7 +189,7 @@ void BCValueDelegate::paintBooleanValue( QPainter *painter, const QStyleOptionVi
QRect textRect = option.rect.adjusted( 2,0,0,0);
// 3. Den tatsächlichen Wert aus dem Model auslesen
QString text = bcValue.rawValue() == 1 ? "Yes" : "No";
QString text = bcValue.rawValue() == 1 ? BCTags::Yes : BCTags::No;
// 3. Die korrekte Textfarbe ermitteln (extrem wichtig für die UX!)
// Wenn die Zeile markiert ist (Selected), muss der Text meist weiß sein,
@@ -312,7 +311,7 @@ void BCValueDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionVie
void BCValueDelegate::paintPlainToggleSwitch(QPainter* painter, const QStyleOptionViewItem& option, const BCValue& bcValue) const
{
BCToggleSwitch::paintToggleIndicator(painter, option.rect, bcValue.isChecked(), 20, option.widget->palette());
}